2
0

2 Commits ec8df30fe5 ... c34773a3ab

Autor SHA1 Mensagem Data
  Trishia c34773a3ab LightControlService Bindig issue was solved. 4 anos atrás
  Trishia fee7376923 ocf.2.0.5 of icv info was changed to ocf2.2.0 for Bridge, VODs. 4 anos atrás

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

@@ -282,7 +282,7 @@ public class BridgeServer {
         OCUuid uuid = OCUuidUtil.stringToUuid(virtual_di);
         OCUuid uuid = OCUuidUtil.stringToUuid(virtual_di);
         int vod_index = OCBridge.addVirtualDevice(uuid.getId(),
         int vod_index = OCBridge.addVirtualDevice(uuid.getId(),
                 eco_name, "/oic/d", device_type,  // "oic.d.virtual" automatically added by internal api implements
                 eco_name, "/oic/d", device_type,  // "oic.d.virtual" automatically added by internal api implements
-                device_name, "ocf.2.0.5", "ocf.res.1.3.0,ocf.sh.1.3.0");
+                device_name, "ocf.2.2.0", "ocf.res.1.3.0,ocf.sh.1.3.0");
 
 
         if (vod_index != 0) {
         if (vod_index != 0) {
             Log.d(TAG, "VOD Index = " + vod_index + ", VOD Count = " + OCBridge.getVirtualDeviceCount());
             Log.d(TAG, "VOD Index = " + vod_index + ", VOD Count = " + OCBridge.getVirtualDeviceCount());
@@ -349,7 +349,7 @@ public class BridgeServer {
         OCUuid uuid = OCUuidUtil.stringToUuid(virtual_di) ;
         OCUuid uuid = OCUuidUtil.stringToUuid(virtual_di) ;
         int vod_index = OCBridge.addVirtualDevice(uuid.getId(),
         int vod_index = OCBridge.addVirtualDevice(uuid.getId(),
                 econame, "/oic/d", "oic.d.light",  // "oic.d.virtual" automatically added by internal api implements
                 econame, "/oic/d", "oic.d.light",  // "oic.d.virtual" automatically added by internal api implements
-                devicename, "ocf.2.0.5", "ocf.res.1.3.0,ocf.sh.1.3.0");
+                devicename, "ocf.2.2.0", "ocf.res.1.3.0,ocf.sh.1.3.0");
 
 
         if (vod_index != 0) {
         if (vod_index != 0) {
             Log.d(TAG, "VOD Index = "+ vod_index + ", VOD Count = " + OCBridge.getVirtualDeviceCount());
             Log.d(TAG, "VOD Index = "+ vod_index + ", VOD Count = " + OCBridge.getVirtualDeviceCount());
@@ -451,7 +451,7 @@ public class BridgeServer {
         OCUuid uuid = OCUuidUtil.stringToUuid(device_uuid) ;
         OCUuid uuid = OCUuidUtil.stringToUuid(device_uuid) ;
         int vod_index = OCBridge.addVirtualDevice(uuid.getId(),
         int vod_index = OCBridge.addVirtualDevice(uuid.getId(),
                 econame, "/oic/d", "oic.d.virtualclient",  // "oic.d.virtual" automatically added by internal api implements
                 econame, "/oic/d", "oic.d.virtualclient",  // "oic.d.virtual" automatically added by internal api implements
-                devicename, "ocf.2.0.5", "ocf.res.1.3.0,ocf.sh.1.3.0");
+                devicename, "ocf.2.2.0", "ocf.res.1.3.0,ocf.sh.1.3.0");
 
 
         if(vod_index != 0) {
         if(vod_index != 0) {
             OCDeviceInfo dev_info = OCCoreRes.getDeviceInfo(vod_index);
             OCDeviceInfo dev_info = OCCoreRes.getDeviceInfo(vod_index);

+ 38 - 34
app/src/main/java/org/iotivity/bridge/homeserver/BridgeService.java

@@ -131,7 +131,7 @@ public class BridgeService extends IntentService {
         if (IBridgeService.class.getName().equals(intent.getAction())) {
         if (IBridgeService.class.getName().equals(intent.getAction())) {
             return rBinder; // return Remote Binder
             return rBinder; // return Remote Binder
         } else if (ILightControlService.class.getName().equals(intent.getAction())) {
         } else if (ILightControlService.class.getName().equals(intent.getAction())) {
-            return lightBinder; // return Remote Binder
+            return null ;//lightBinder; // return Remote Binder
         }
         }
         return lBinder; // return Local Binder
         return lBinder; // return Local Binder
     }
     }
@@ -304,7 +304,7 @@ public class BridgeService extends IntentService {
     private LightControlServiceConnection lightConn = new LightControlServiceConnection();
     private LightControlServiceConnection lightConn = new LightControlServiceConnection();
     public void bindLightControlService() {
     public void bindLightControlService() {
 
 
-        Log.d(TAG, "SecheduledTaskInit : bindLightControlService() called.");
+        Log.d(TAG, "ScheduledTaskInit : bindLightControlService() called.");
 
 
         // Light Control Service Remote Bind
         // Light Control Service Remote Bind
         Intent lIntent = new Intent();
         Intent lIntent = new Intent();
@@ -341,26 +341,23 @@ public class BridgeService extends IntentService {
         public void onServiceConnected(ComponentName name, IBinder service) {
         public void onServiceConnected(ComponentName name, IBinder service) {
 
 
             Log.d(TAG, "onServiceConnected ComponentName=" + name + ", IBinder=" + service.toString());
             Log.d(TAG, "onServiceConnected ComponentName=" + name + ", IBinder=" + service.toString());
-            if (service instanceof ILightControlService.Stub) {
+            try {
+                lightControlBinder = ILightControlService.Stub.asInterface(service);
+                lightControlBinder.registerLightControlServiceCallback(lightCallback);
 
 
-                try {
-                    lightControlBinder = ILightControlService.Stub.asInterface(service);
-                    lightControlBinder.registerLightControlServiceCallback(lightCallback);
-
-                    // Discover All Light Control Devices
-                    discoverAllLightControlDevices();
-
-                } catch (RemoteException ex) {
-                    Log.e(TAG, "Register Callback", ex);
-                    // In this case the service has crashed before we could even
-                    // do anything with it; we can count on soon being
-                    // disconnected (and then reconnected if it can be restarted)
-                    // so there is no need to do anything here.
-                }
+                // Discover All Light Control Devices
+                discoverAllLightControlDevices();
 
 
-                msg( "Light Control Remote Service Connected");
-                printLine();
+            } catch (RemoteException ex) {
+                Log.e(TAG, "Register Callback", ex);
+                // In this case the service has crashed before we could even
+                // do anything with it; we can count on soon being
+                // disconnected (and then reconnected if it can be restarted)
+                // so there is no need to do anything here.
             }
             }
+
+            msg( "Light Control Remote Service Connected");
+            printLine();
         }
         }
 
 
         @Override
         @Override
@@ -417,7 +414,7 @@ public class BridgeService extends IntentService {
     /**
     /**
      * The ILightControlService is defined through IDL
      * The ILightControlService is defined through IDL
      */
      */
-    private final ILightControlServiceImpl lightBinder = new ILightControlServiceImpl() ;
+    /*private final ILightControlServiceImpl lightBinder = new ILightControlServiceImpl() ;
     class ILightControlServiceImpl extends ILightControlService.Stub {
     class ILightControlServiceImpl extends ILightControlService.Stub {
 
 
         final RemoteCallbackList<ILightControlServiceCallback> callbacks
         final RemoteCallbackList<ILightControlServiceCallback> callbacks
@@ -531,7 +528,7 @@ public class BridgeService extends IntentService {
             }
             }
             callbacks.finishBroadcast();
             callbacks.finishBroadcast();
         }
         }
-    };
+    };*/
 
 
     public String doGetLightControlResource(long device_index, String device_id, String resource_uri) {
     public String doGetLightControlResource(long device_index, String device_id, String resource_uri) {
         try {
         try {
@@ -539,7 +536,8 @@ public class BridgeService extends IntentService {
             String device_sn = OCUuidUtil.uuidToString(piid); // same with vod_id(Virtual Device Id) of VirtualOCFDevice
             String device_sn = OCUuidUtil.uuidToString(piid); // same with vod_id(Virtual Device Id) of VirtualOCFDevice
 
 
             // doGetProperties with Light Control Service
             // doGetProperties with Light Control Service
-            String properties = lightBinder.doGetResourceProperties(device_sn, resource_uri);
+            if(lightControlBinder==null) return null ;
+            String properties = lightControlBinder.doGetResourceProperties(device_sn, resource_uri);
             return properties ;
             return properties ;
         } catch (RemoteException e) {
         } catch (RemoteException e) {
             Log.e(TAG, "Light Control Service Remote Error : ", e);
             Log.e(TAG, "Light Control Service Remote Error : ", e);
@@ -549,8 +547,10 @@ public class BridgeService extends IntentService {
 
 
     public void discoverAllLightControlDevices() {
     public void discoverAllLightControlDevices() {
 
 
-        Log.d(TAG, "SecheduledTaskInit : doRetrieveLightControlAllDevices() called.");
         try {
         try {
+            if(lightControlBinder==null) return ;
+
+            Log.d(TAG, "ScheduledTaskInit : doRetrieveLightControlAllDevices() called.");
             String devices = lightControlBinder.retrieveAllDevices();
             String devices = lightControlBinder.retrieveAllDevices();
             Log.d(TAG, "Light Control retrieveAllDevices() : "+ devices);
             Log.d(TAG, "Light Control retrieveAllDevices() : "+ devices);
             if(devices != null) {
             if(devices != null) {
@@ -646,7 +646,7 @@ public class BridgeService extends IntentService {
                     }
                     }
                 }
                 }
             }
             }
-        } catch (RemoteException | JSONException ex) {
+        } catch (Exception ex) {
             Log.e(TAG, "Register Callback", ex);
             Log.e(TAG, "Register Callback", ex);
             // In this case the service has crashed before we could even
             // In this case the service has crashed before we could even
             // do anything with it; we can count on soon being
             // do anything with it; we can count on soon being
@@ -657,8 +657,9 @@ public class BridgeService extends IntentService {
 
 
     public void doGetLightControlResources() {
     public void doGetLightControlResources() {
 
 
-        Log.d(TAG, "SecheduledTaskInit : doGetLightControlResources() called.");
-        if(bridgeServer != null && lightBinder != null) {
+        if(bridgeServer != null && lightControlBinder != null) {
+            Log.d(TAG, "ScheduledTaskInit : doGetLightControlResources() called.");
+
             ArrayList<VirtualOCFDevice> vods = bridgeServer.getVirtualOCFDeviceList();
             ArrayList<VirtualOCFDevice> vods = bridgeServer.getVirtualOCFDeviceList();
             for (VirtualOCFDevice vod : vods) {
             for (VirtualOCFDevice vod : vods) {
                 if (vod.getEcoName().equals(LightControlServiceConnection.ECO_NAME) && vod.isDiscovered()
                 if (vod.getEcoName().equals(LightControlServiceConnection.ECO_NAME) && vod.isDiscovered()
@@ -668,7 +669,7 @@ public class BridgeService extends IntentService {
                         try {
                         try {
                             // doGetProperties with Light Control Service
                             // doGetProperties with Light Control Service
                             String prev_props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource.getResourceUri());
                             String prev_props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource.getResourceUri());
-                            String properies = lightBinder.doGetResourceProperties(device_sn, resource.getResourceUri());
+                            String properies = lightControlBinder.doGetResourceProperties(device_sn, resource.getResourceUri());
                             bridgeServer.addOrUpdateVirtualOCFDeviceProperties(device_sn, resource.getResourceUri(), properies);
                             bridgeServer.addOrUpdateVirtualOCFDeviceProperties(device_sn, resource.getResourceUri(), properies);
 
 
                             /*Log.d(TAG,"(1) prev_props : " +prev_props + ", cur_props : " +properies );
                             /*Log.d(TAG,"(1) prev_props : " +prev_props + ", cur_props : " +properies );
@@ -696,8 +697,10 @@ public class BridgeService extends IntentService {
             OCUuid piid = OCCoreRes.getDeviceInfo(device_index).getPiid();
             OCUuid piid = OCCoreRes.getDeviceInfo(device_index).getPiid();
             String device_sn = OCUuidUtil.uuidToString(piid); // same with vod_id(Virtual Device Id) of VirtualOCFDevice
             String device_sn = OCUuidUtil.uuidToString(piid); // same with vod_id(Virtual Device Id) of VirtualOCFDevice
 
 
-            Log.d(TAG, "doPostLightControlResource() called.");
-            lightBinder.doPostResourceProperties(device_sn, resource_uri, prop_data);
+            if(lightControlBinder!=null) {
+                Log.d(TAG, "doPostLightControlResource() called.");
+                lightControlBinder.doPostResourceProperties(device_sn, resource_uri, prop_data);
+            }
 
 
         } catch (RemoteException e) {
         } catch (RemoteException e) {
             Log.e(TAG, "Light Control Service Remote Error : ", e);
             Log.e(TAG, "Light Control Service Remote Error : ", e);
@@ -733,7 +736,7 @@ public class BridgeService extends IntentService {
                     rBinder.broadcastResultToClients(msg.arg1, (String)msg.obj);
                     rBinder.broadcastResultToClients(msg.arg1, (String)msg.obj);
                 } break ;
                 } break ;
                 case MSG_LIGHT_RESULT: {
                 case MSG_LIGHT_RESULT: {
-                    lightBinder.broadcastResultToClients(msg.arg1, (String)msg.obj);
+                    //lightBinder.broadcastResultToClients(msg.arg1, (String)msg.obj);
                 } break ;
                 } break ;
                 default:
                 default:
                     super.handleMessage(msg);
                     super.handleMessage(msg);
@@ -883,21 +886,22 @@ public class BridgeService extends IntentService {
          * executorService.schedule(Classname::someTask, delayInSeconds, TimeUnit.SECONDS);                 // once after a delay
          * executorService.schedule(Classname::someTask, delayInSeconds, TimeUnit.SECONDS);                 // once after a delay
          * executorService.scheduleAtFixedRate(Classname::someTask, 0, delayInSeconds, TimeUnit.SECONDS);   // at fixed time interval
          * executorService.scheduleAtFixedRate(Classname::someTask, 0, delayInSeconds, TimeUnit.SECONDS);   // at fixed time interval
          */
          */
-        if(executorLightControl != null && executorLightControl.isShutdown() == false ) { executorLightControl.shutdown();}
+        if(executorLightControl != null && executorLightControl.isShutdown() == false ) {
+            executorLightControl.shutdown();
+        }
         executorLightControl = Executors.newSingleThreadScheduledExecutor();
         executorLightControl = Executors.newSingleThreadScheduledExecutor();
         executorLightControl.scheduleAtFixedRate(new Runnable() {
         executorLightControl.scheduleAtFixedRate(new Runnable() {
             @Override
             @Override
             public void run() {
             public void run() {
                 // Getting Properites of Light Control Service for resource monitoring
                 // Getting Properites of Light Control Service for resource monitoring
-                Log.d(TAG, "LightControl ScheduledTask per 180sec was called.");
+                Log.d(TAG, "LightControl ScheduledTask per 30sec was called.");
                 if(lightControlBinder==null) {
                 if(lightControlBinder==null) {
                     bindLightControlService();
                     bindLightControlService();
                 }
                 }
                 discoverAllLightControlDevices();
                 discoverAllLightControlDevices();
                 doGetLightControlResources();
                 doGetLightControlResources();
             }
             }
-        }, 30, 180, TimeUnit.SECONDS); // 180sec interval after 30sec delay
-
+        }, 30, 30, TimeUnit.SECONDS); // 180sec interval after 30sec delay
     }
     }
 
 
     public void stopScheduledTaskForLightControl() {
     public void stopScheduledTaskForLightControl() {

+ 1 - 1
app/src/main/java/org/iotivity/bridge/homeserver/handler/BridgeInitHandler.java

@@ -43,7 +43,7 @@ public class BridgeInitHandler implements OCMainInitHandler {
         int ret = ocPlatform.platformInit(Bridge.PLATFORM_MFG_NAME);
         int ret = ocPlatform.platformInit(Bridge.PLATFORM_MFG_NAME);
         if (ret >= 0) {
         if (ret >= 0) {
             // Create the devices and add them to the platform
             // Create the devices and add them to the platform
-            ret = OCBridge.addBridgeDevice(bridge.getName(), "ocf.2.0.5", "ocf.res.1.3.0,ocf.sh.1.3.0");
+            ret = OCBridge.addBridgeDevice(bridge.getName(), "ocf.2.2.0", "ocf.res.1.3.0,ocf.sh.1.3.0");
         } else {
         } else {
             Log.e(TAG, "Error in platformInit, return value = " + ret);
             Log.e(TAG, "Error in platformInit, return value = " + ret);
         }
         }