Skip to content

Commit

Permalink
Merge pull request #306 from pahnjy/develop
Browse files Browse the repository at this point in the history
Device Subscription에 따른 로직 변경 #291
  • Loading branch information
pahnjy authored Dec 20, 2016
2 parents a6298bf + 709e125 commit e74a388
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ public String deviceExecute(String deviceId,String deviceCommand, String session
session.insertSessionData(DefaultSession.DEVICE_RESULT, DefaultSession.CONTROL_EXECUTION);
sessionStore.updateSession(session);

/*
if(device.checkStatus(deviceCommand)){
return "same device state to is.";
}
*/

// Device 제어 요청 보냄.
ResultMessage resultMessage = deviceControlProxy.deviceControlRequest(contextAddress.getServerAddress(ContextAddress.SI_SERVER) + AddressStore.SI_CONTOL_URI,deviceControlMessage);
Expand All @@ -137,9 +139,7 @@ public String deviceExecute(String deviceId,String deviceCommand, String session
/**
* Device Subscription 데이터 저장
*/
if(response.equals(ClientProfile.RESPONSE_SUCCESS_ONEM2MCODE)){
saveDeviceSubscriptionData(deviceControlMessage.get_commandId(), deviceControlMessage.getCon());
}
saveDeviceSubscriptionData(deviceControlMessage.get_commandId(), deviceControlMessage.getCon(), response);

/*
디바이스 해제는 Controller에서 상태 업데이트 후 해제.
Expand Down Expand Up @@ -229,8 +229,12 @@ public void deviceUpdate(DeviceStatusData deviceStatusData) {
logger.debug(LogPrint.LogMethodNamePrint() + "Device Data Update");
device.setDeviceStatus(deviceStatusData.getCon());
deviceStore.update(device);
deviceSubscriptionRelease(deviceUri + (ClientProfile.actionDeviceCommand(device.getDeviceUri()) ? ClientProfile.SI_CONTAINER_ACTION : ClientProfile.SI_CONTAINER_POWER) + ClientProfile.SI_CONTAINER_STATUS);
deviceSubscriptionStore.delete(deviceSubscriptionObject.get_id());
/**
* Device Subscription 해제 요청
*/
String response = deviceSubscriptionRelease(deviceUri + (ClientProfile.actionDeviceCommand(device.getDeviceUri()) ? ClientProfile.SI_CONTAINER_ACTION : ClientProfile.SI_CONTAINER_POWER) + ClientProfile.SI_CONTAINER_STATUS);
deviceSubscriptionObject.setReleaseResult(response);
deviceSubscriptionStore.update(deviceSubscriptionObject);
} else {
logger.debug(LogPrint.LogMethodNamePrint() + "The state or command of the device is different.");
}
Expand Down Expand Up @@ -310,8 +314,8 @@ public String getOnem2mDeviceUri(String uri){
return uri.substring(0, stringlength);
}

public void saveDeviceSubscriptionData(String deviceUri, String commandId){
deviceSubscriptionStore.create(new DeviceSubscriptionObject(deviceUri, commandId));
public void saveDeviceSubscriptionData(String deviceUri, String commandId, String result){
deviceSubscriptionStore.create(new DeviceSubscriptionObject(deviceUri, commandId, result));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public interface DeviceSubscriptionStore {
void create(DeviceSubscriptionObject deviceSubscriptionObject);
DeviceSubscriptionObject retrieve(String commandId);
void delete(String commandId);

void update(DeviceSubscriptionObject deviceSubscriptionObject);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ public void delete(String commandId) {
logger.debug("Command ID = " + commandId);
deviceSubscriptionRepository.delete(commandId);
}

@Override
public void update(DeviceSubscriptionObject deviceSubscriptionObject) {
logger.debug("Device = " + deviceSubscriptionObject.toString());
deviceSubscriptionRepository.save(deviceSubscriptionObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@ public class DeviceSubscriptionObject {

private String deviceStatus;

private String subscriptionResult;

private String releaseResult;

public DeviceSubscriptionObject() {
}

public DeviceSubscriptionObject(String _commandId, String deviceStatus) {
public DeviceSubscriptionObject(String _commandId, String deviceStatus, String subscriptionResult) {
this._commandId = _commandId;
this.deviceStatus = deviceStatus;
this.subscriptionResult = subscriptionResult;
}

public DeviceSubscriptionObject(String _id, String _commandId, String deviceStatus) {
public DeviceSubscriptionObject(String _id, String _commandId, String deviceStatus, String subscriptionResult, String releaseResult) {
this._id = _id;
this._commandId = _commandId;
this.deviceStatus = deviceStatus;
this.subscriptionResult = subscriptionResult;
this.releaseResult = releaseResult;
}

public String get_commandId() {
Expand All @@ -53,6 +60,22 @@ public void set_id(String _id) {
this._id = _id;
}

public String getSubscriptionResult() {
return subscriptionResult;
}

public void setSubscriptionResult(String subscriptionResult) {
this.subscriptionResult = subscriptionResult;
}

public String getReleaseResult() {
return releaseResult;
}

public void setReleaseResult(String releaseResult) {
this.releaseResult = releaseResult;
}

@Override
public String toString() {
return "DeviceSubscriptionObject{" +
Expand Down

0 comments on commit e74a388

Please sign in to comment.