瀏覽代碼

Notifying to observers was deleted on doGetLightControlResources of scheduledTask, just only used in onResultReceived() of ILightControlServiceCallback.

Trishia 4 年之前
父節點
當前提交
ffe70b4e48

+ 8 - 0
app/src/main/java/org/iotivity/bridge/homeserver/BridgeServer.java

@@ -481,6 +481,14 @@ public class BridgeServer {
         return null ;
     }
 
+    public boolean compareVirtualOCFDeviceProperties(String device_sn, String uri, String props) {
+        VirtualOCFDevice device = getVirtualOCFDevice(device_sn);
+        if(device != null) {
+            return device.compareProperties(uri, props);
+        }
+        return false ;
+    }
+
     public boolean existVirtualOCFDevice(String device_sn) {  // Virtual OCF ID (Serial Number or Piid)
         VirtualOCFDevice device = getVirtualOCFDevice(device_sn);
         if(device != null) {

+ 10 - 4
app/src/main/java/org/iotivity/bridge/homeserver/BridgeService.java

@@ -667,14 +667,20 @@ public class BridgeService extends IntentService {
                     for (OCFDevice.Resource resource : vod.getResources()) {
                         try {
                             // doGetProperties with Light Control Service
+                            String prev_props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource.getResourceUri());
                             String properies = lightBinder.doGetResourceProperties(device_sn, resource.getResourceUri());
                             bridgeServer.addOrUpdateVirtualOCFDeviceProperties(device_sn, resource.getResourceUri(), properies);
 
+                            /*Log.d(TAG,"(1) prev_props : " +prev_props + ", cur_props : " +properies );
                             // TODO : need to check // notify to Observers for changed properties's value
-                            OCResource ocResource = vod.getOCResource(resource.getResourceUri());
-                            if(ocResource != null) {
-                                OCMain.notifyObservers(ocResource);
-                            }
+                            if(!bridgeServer.compareVirtualOCFDeviceProperties(device_sn, resource.getResourceUri(), properies)) {
+                                Log.d(TAG,"(2) prev_props : " +prev_props + ", cur_props : " +properies );
+                                //bridgeServer.addOrUpdateVirtualOCFDeviceProperties(device_sn, resource.getResourceUri(), properies);
+                                OCResource ocResource = vod.getOCResource(resource.getResourceUri());
+                                if (ocResource != null) {
+                                    OCMain.notifyObservers(ocResource);
+                                }
+                            }*/
 
                         } catch (RemoteException e) {
                             Log.e(TAG, "Light Control Service Remote Error : ", e);

+ 19 - 0
app/src/main/java/org/iotivity/bridge/homeserver/model/OCFDevice.java

@@ -161,4 +161,23 @@ public class OCFDevice {
         return null ;
     }
 
+    public boolean compareProperties(String resource_uri, String properties) {
+        Resource resource = getResource(resource_uri);
+        Properties cur_props = resource.getProperties();
+        try {
+            JSONObject props = new JSONObject(properties);
+            Iterator<String> keys = props.keys();
+            while(keys.hasNext()) {
+                String key = keys.next() ;
+                Object value = props.get(key);
+
+                if(cur_props.get(key) == null || !cur_props.get(key).equals(value)) {
+                    return false ;
+                }
+            }
+        } catch (JSONException e) {
+            Log.e(TAG, "JSON Error :", e);
+        }
+        return true ;
+    }
 }