|
@@ -172,22 +172,22 @@ public class BridgeService extends IntentService {
|
|
|
|
|
|
@Override
|
|
|
public String retrieveAllDevices() throws RemoteException {
|
|
|
- return getAllPairwisedDevice();
|
|
|
+ return getAllDiscoveredDevices();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String retrieveAllResources(String device_uuid) throws RemoteException {
|
|
|
- return getAllResources(device_uuid);
|
|
|
+ return getDeviceResources(device_uuid);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean requestGetProperties(String device_uuid, String resource_uri) throws RemoteException {
|
|
|
- return doGetDeviceResourceRequest(device_uuid, resource_uri) ;
|
|
|
+ return doGetDeviceResource(device_uuid, resource_uri) ;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean requestPostProperties(String device_uuid, String resource_uri, String prop_data) throws RemoteException {
|
|
|
- return doPostDeviceResourceRequest(device_uuid, resource_uri, prop_data);
|
|
|
+ return doPostDeviceResource(device_uuid, resource_uri, prop_data);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -319,7 +319,7 @@ public class BridgeService extends IntentService {
|
|
|
@Override
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
|
|
- Log.d(TAG, "onStartCommand() intent=" + intent.getAction());
|
|
|
+ Log.d(TAG, "onStartCommand() intent=" + (intent!=null? intent.getAction() : null));
|
|
|
serviceIntent = intent ;
|
|
|
|
|
|
initializeNotification();
|
|
@@ -339,10 +339,6 @@ public class BridgeService extends IntentService {
|
|
|
// Unregister all callbacks.
|
|
|
rBinder.killCallbacks();
|
|
|
|
|
|
- // Remove the next pending message to increment the counter, stopping
|
|
|
- // the increment loop.
|
|
|
- //mHandler.removeMessages(MSG_REPORT);
|
|
|
-
|
|
|
// Bridge Service and Application Process Kill
|
|
|
// android.os.Process.killProcess(Process.myPid());
|
|
|
// or below action
|
|
@@ -424,7 +420,7 @@ public class BridgeService extends IntentService {
|
|
|
public void run() {
|
|
|
if(bridgeServer!=null) bridgeServer.loadPairwisedDeviceUUIDs();
|
|
|
|
|
|
- Log.d(TAG, "Before Discovery : " + getAllPairwisedDevice());
|
|
|
+ Log.d(TAG, "Before Discovery : " + getAllDiscoveredDevices());
|
|
|
clearPairwisedDevices();
|
|
|
OCUuid bridge_di = OCCoreRes.getDeviceId(Bridge.BRIDGE_INDEX);
|
|
|
if (!OcUtils.discoverAllDevices(new DeviceDiscoveryHandler(getService(), bridge_di))) {
|
|
@@ -480,7 +476,7 @@ public class BridgeService extends IntentService {
|
|
|
return null ;
|
|
|
}
|
|
|
|
|
|
- public String getAllPairwisedDevice() {
|
|
|
+ public String getAllDiscoveredDevices() {
|
|
|
if(bridgeServer!=null) {
|
|
|
ArrayList<OcRemoteDevice> devices = bridgeServer.getPairwisedDevices();
|
|
|
try {
|
|
@@ -494,7 +490,7 @@ public class BridgeService extends IntentService {
|
|
|
obj.put("dmv", device.getDataModelVersion());
|
|
|
array.put(obj);
|
|
|
}
|
|
|
- return array.toString();
|
|
|
+ return array.toString().replace("\\", "");
|
|
|
} catch (JSONException ex) {
|
|
|
Log.e(TAG, "JSON Error : ", ex);
|
|
|
}
|
|
@@ -502,9 +498,9 @@ public class BridgeService extends IntentService {
|
|
|
return null ;
|
|
|
}
|
|
|
|
|
|
- public String getAllResources(String device_id) {
|
|
|
+ public String getDeviceResources(String device_uuid) {
|
|
|
if(bridgeServer!=null) {
|
|
|
- OcRemoteDevice device = bridgeServer.getPairwisedDevice(device_id);
|
|
|
+ OcRemoteDevice device = bridgeServer.getPairwisedDevice(device_uuid);
|
|
|
OcRemoteResource[] resources = device.getResources();
|
|
|
try {
|
|
|
JSONArray array = new JSONArray();
|
|
@@ -520,7 +516,7 @@ public class BridgeService extends IntentService {
|
|
|
array.put(obj);
|
|
|
}
|
|
|
}
|
|
|
- return array.toString();
|
|
|
+ return array.toString().replace("\\", "");
|
|
|
} catch (JSONException ex) {
|
|
|
Log.e(TAG, "JSON Error : ", ex);
|
|
|
}
|
|
@@ -528,32 +524,49 @@ public class BridgeService extends IntentService {
|
|
|
return null ;
|
|
|
}
|
|
|
|
|
|
- public boolean doGetDeviceResourceRequest(String device_id, String resource_uri) {
|
|
|
+ public boolean doGetDeviceResource(String device_uuid, String resource_uri) {
|
|
|
if(bridgeServer!=null) {
|
|
|
- OcRemoteDevice device = bridgeServer.getPairwisedDevice(device_id);
|
|
|
- OcRemoteResource[] resources = device.getResources();
|
|
|
- for (OcRemoteResource resource : resources) {
|
|
|
- if(resource.getUri().equals(resource_uri)) {
|
|
|
+
|
|
|
+ OcRemoteResource resource = bridgeServer.getPairwisedResource(device_uuid, resource_uri);
|
|
|
+ if(resource==null) return false ;
|
|
|
+
|
|
|
+ GetResponseHandler responseHandler = new GetResponseHandler(getService(), resource);
|
|
|
+ if(OcUtils.doGet(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()),
|
|
|
+ null, responseHandler, OCQos.LOW_QOS)) {
|
|
|
+ return true ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false ;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean doGetDeviceSpecificResources(String device_uuid) {
|
|
|
+ OcRemoteDevice remoteDevice = findPairwisedRemoteDevice(device_uuid);
|
|
|
+ if (remoteDevice == null) return false ;
|
|
|
+
|
|
|
+ int count = 0 ;
|
|
|
+ for(OcRemoteResource resource : remoteDevice.getResources()) {
|
|
|
+ if(Utils.isDeviceSpecificResource(resource.getTypes())) {
|
|
|
GetResponseHandler responseHandler = new GetResponseHandler(getService(), resource);
|
|
|
if(OcUtils.doGet(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()),
|
|
|
null, responseHandler, OCQos.LOW_QOS)) {
|
|
|
- return true ;
|
|
|
+ count++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- return false ;
|
|
|
+
|
|
|
+ if(count > 0 ) return true ;
|
|
|
+ else return false ;
|
|
|
}
|
|
|
|
|
|
- public boolean doPostDeviceResourceRequest(String device_id, String resource_uri, String prop_data) {
|
|
|
+ public boolean doPostDeviceResource(String device_uuid, String resource_uri, String prop_data) {
|
|
|
|
|
|
if(bridgeServer!=null) {
|
|
|
|
|
|
- OcRemoteResource resource = bridgeServer.getPairwisedResource(device_id, resource_uri);
|
|
|
+ OcRemoteResource resource = bridgeServer.getPairwisedResource(device_uuid, resource_uri);
|
|
|
if(resource==null) return false ;
|
|
|
|
|
|
PostResponseHandler postLight = new PostResponseHandler(getService(), resource);
|
|
|
- if (OcUtils.initPut(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, postLight, OCQos.LOW_QOS)) {
|
|
|
+ if (OcUtils.initPost(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, postLight, OCQos.LOW_QOS)) {
|
|
|
|
|
|
try {
|
|
|
JSONObject json = new JSONObject(prop_data);
|
|
@@ -609,19 +622,21 @@ public class BridgeService extends IntentService {
|
|
|
OcRemoteDevice remoteDevice = findPairwisedRemoteDevice(device_uuid);
|
|
|
if (remoteDevice == null) return false ;
|
|
|
|
|
|
- /* TODO : Observe Register for only device specfic resources until shutdown.
|
|
|
+ /* TODO : Observe only device specfic resources until shutdown or until stop Observe.
|
|
|
* This may cause too many observing to the device
|
|
|
- * To avoid this issue, I think Resource Observing list should be managed in BridgeService. */
|
|
|
- int countObserver = 0 ;
|
|
|
+ * To avoid this issue, I think Resource Observing list should be managed in BridgeService
|
|
|
+ * or stop Observing before Observing */
|
|
|
+ int count = 0 ;
|
|
|
for(OcRemoteResource resource : remoteDevice.getResources()) {
|
|
|
if(Utils.isDeviceSpecificResource(resource.getTypes())) {
|
|
|
ObserveResponseHandler observerHandler = new ObserveResponseHandler(getService(), resource);
|
|
|
- OcUtils.doObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, observerHandler, OCQos.LOW_QOS);
|
|
|
- countObserver++;
|
|
|
+ if(OcUtils.doObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, observerHandler, OCQos.LOW_QOS)) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(countObserver > 0 ) return true ;
|
|
|
+ if(count > 0 ) return true ;
|
|
|
else return false ;
|
|
|
}
|
|
|
|
|
@@ -633,8 +648,9 @@ public class BridgeService extends IntentService {
|
|
|
for(OcRemoteResource resource : remoteDevice.getResources()) {
|
|
|
if(resource.getUri().equals(resource_uri)) {
|
|
|
ObserveResponseHandler observerHandler = new ObserveResponseHandler(getService(), resource);
|
|
|
- OcUtils.doObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, observerHandler, OCQos.LOW_QOS);
|
|
|
- return true ;
|
|
|
+ if(OcUtils.doObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, observerHandler, OCQos.LOW_QOS)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return false ;
|
|
@@ -645,15 +661,16 @@ public class BridgeService extends IntentService {
|
|
|
OcRemoteDevice remoteDevice = findPairwisedRemoteDevice(device_uuid);
|
|
|
if (remoteDevice == null) return false ;
|
|
|
|
|
|
- int countObserver = 0 ;
|
|
|
+ int count = 0 ;
|
|
|
for(OcRemoteResource resource : remoteDevice.getResources()) {
|
|
|
if(Utils.isDeviceSpecificResource(resource.getTypes())) {
|
|
|
- OcUtils.stopObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()));
|
|
|
- countObserver++ ;
|
|
|
+ if(OcUtils.stopObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()))) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(countObserver > 0 ) return true ;
|
|
|
+ if(count > 0 ) return true ;
|
|
|
else return false ;
|
|
|
}
|
|
|
|
|
@@ -664,8 +681,9 @@ public class BridgeService extends IntentService {
|
|
|
|
|
|
for(OcRemoteResource resource : remoteDevice.getResources()) {
|
|
|
if (resource.getUri().equals(resource_uri)) {
|
|
|
- OcUtils.stopObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()));
|
|
|
- return true ;
|
|
|
+ if(OcUtils.stopObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return false ;
|