Pārlūkot izejas kodu

DeviceSpecificResourceObserve logic after Discovering was deleted because it has an issue related to callback routine duplication between observe and notification.

Trishia 4 gadi atpakaļ
vecāks
revīzija
c9db45aa94

BIN
app/libs/iotivity-lite.jar


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

@@ -53,7 +53,7 @@ public class BridgeServer {
     private static final String TAG = BridgeServer.class.getSimpleName();
 
     // Virtual OCF Device's unique identifier such as uuid, MEID, serial number, mac address
-    public static final String LIGHT_UUID = "2b32e152-3756-4fb6-b3f2-d8db7aafe39f";
+    public static final String LIGHT_UUID = "2b32e152-3756-4fb6-b3f2-d8db7aafe39f" ;
     public static final String LIGHT2_UUID = "645b5166-3efb-4021-6ba0-4db90d434838";
     public static final String CLIENT_UUID = "f2f0109f-ef7d-496a-9676-d3d87b38e52f";
 
@@ -348,7 +348,7 @@ public class BridgeServer {
         device.addOCResource(resource);
     }
 
-    public void addLightVirtualOCFServer(String virtual_di, String devicename, String econame) {
+    public boolean addLightVirtualOCFServer(String virtual_di, String devicename, String econame) {
 
         // Add Virtual Device for Light
         OCUuid uuid = OCUuidUtil.stringToUuid(virtual_di) ;
@@ -446,8 +446,11 @@ public class BridgeServer {
                 // Add Light OCF Device IDD
                 byte[] idd_bytes = getFileBytes("idds/virtual_ocf_device_light_IDD.cbor"); // example : "virtual_ocf_device_light_IDD.cbor"
                 OCIntrospection.setIntrospectionData(vod_index, idd_bytes);
+
+                return true ;
             }
         }
+        return false ;
     }
 
     public void addVirtualOCFClient(String device_uuid, String devicename, String econame) {
@@ -504,7 +507,7 @@ public class BridgeServer {
 
     public boolean addOrUpdateVirtualOCFDeviceProperties (String device_sn, String uri, String props) {
         VirtualOCFDevice device = getVirtualOCFDevice(device_sn);
-        if(device != null) {
+        if(device != null && props!=null) {
             device.addProperties(uri, props);
             return true ;
         }

+ 40 - 0
app/src/main/java/org/iotivity/bridge/homeserver/BridgeServerActivity.java

@@ -93,6 +93,8 @@ public class BridgeServerActivity extends AppCompatActivity {
         return bridgeServer ;
     }
 
+    private int incremental_vod_index = 0 ;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -481,6 +483,42 @@ public class BridgeServerActivity extends AppCompatActivity {
                 confirmDialog.show();
                 return true;
             }
+            case R.id.action_inc_vos:
+            {
+                incremental_vod_index++;
+
+                AlertDialog.Builder confirmBridgeDialogBuilder = new AlertDialog.Builder(BridgeServerActivity.this);
+                confirmBridgeDialogBuilder.setTitle(getString(R.string.incVOS));
+                confirmBridgeDialogBuilder.setMessage(getString(R.string.incVOSMessage).replace("?", String.valueOf(incremental_vod_index)));
+
+                confirmBridgeDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+                        if(bridgeServer!=null) {
+
+                            String hexId = Integer.toHexString(incremental_vod_index);
+                            String incUUID = BridgeServer.LIGHT2_UUID.substring(0, BridgeServer.LIGHT2_UUID.length() - hexId.length()) + hexId.toLowerCase();
+                            Log.d(TAG, "hexId = "+hexId+", incUUID = " + incUUID);
+                            boolean ret = bridgeServer.addLightVirtualOCFServer(incUUID, "Light Switch " + incremental_vod_index , "ocf");
+                            if(ret) {
+                                Toast.makeText(BridgeServerActivity.this,
+                                        getString(R.string.incVOSOkMessage).replace("?", String.valueOf(incremental_vod_index))
+                                        , Toast.LENGTH_LONG).show();
+                            }
+                        }
+                    }
+                });
+
+                confirmBridgeDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+                    }
+                });
+
+                Dialog confirmDialog = confirmBridgeDialogBuilder.create();
+                confirmDialog.show();
+                return true;
+            }
             case R.id.action_add_voc:
             {
                 AlertDialog.Builder confirmBridgeDialogBuilder = new AlertDialog.Builder(BridgeServerActivity.this);
@@ -735,6 +773,8 @@ public class BridgeServerActivity extends AppCompatActivity {
                 return true;
 
             }
+            case R.id.action_exit :
+                onBackPressed();
             default :
                 return super.onOptionsItemSelected(item) ;
         }

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

@@ -105,7 +105,7 @@ public class BridgeService extends IntentService {
     }
 
     public static final int PAIRWISED_DISCOVERY_PEROID = 90 ;
-    public static final int LIGHTCONTROL_DISCOVERY_PEROID = 180 ;
+    public static final int LIGHTCONTROL_DISCOVERY_PEROID = 60 ;
 
     @Override
     public void onCreate() {
@@ -673,8 +673,14 @@ public class BridgeService extends IntentService {
                             // doGetProperties with Light Control Service
                             String prev_props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource.getResourceUri());
                             String properies = lightControlBinder.doGetResourceProperties(device_sn, resource.getResourceUri());
+                            /*Log.d(TAG, "doGetLightControlResources() : device_sn = " + device_sn +", Uri = "
+                                    + resource.getResourceUri()+", properies = " + properies);*/
                             bridgeServer.addOrUpdateVirtualOCFDeviceProperties(device_sn, resource.getResourceUri(), properies);
 
+                            String after_props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource.getResourceUri());
+                            /*Log.d(TAG, "doGetLightControlResources() : device_sn = " + device_sn +", Uri = "
+                                    + resource.getResourceUri()+", after properies = " + after_props);*/
+
                             /*Log.d(TAG,"(1) prev_props : " +prev_props + ", cur_props : " +properies );
                             // TODO : need to check // notify to Observers for changed properties's value
                             if(!bridgeServer.compareVirtualOCFDeviceProperties(device_sn, resource.getResourceUri(), properies)) {
@@ -719,7 +725,7 @@ public class BridgeService extends IntentService {
     }
 
     public void broadcastResult(int result_code, String result_data) {
-        mHandler.sendMessage(mHandler.obtainMessage(MSG_RESULT,result_code, 0, result_data));
+        mHandler.sendMessage(mHandler.obtainMessage(MSG_RESULT, result_code, 0, result_data));
     }
 
     private final Handler mHandler = new Handler() {
@@ -879,7 +885,7 @@ public class BridgeService extends IntentService {
             }
         }, 10, PAIRWISED_DISCOVERY_PEROID, TimeUnit.SECONDS); // 180 sec interval after 10sec delay
 
-        executorPairwised.scheduleAtFixedRate(new Runnable() {
+        /*executorPairwised.scheduleAtFixedRate(new Runnable() {
             @Override
             public void run() {
 
@@ -887,7 +893,7 @@ public class BridgeService extends IntentService {
                 Log.d(TAG, "getAllDiscoveredDevices() : "+getAllDiscoveredDevices());
 
             }
-        }, 20, PAIRWISED_DISCOVERY_PEROID, TimeUnit.SECONDS); // 180 sec interval after 10sec delay
+        }, 20, PAIRWISED_DISCOVERY_PEROID, TimeUnit.SECONDS); // 180 sec interval after 10sec delay*/
     }
 
     public void stopScheduledTaskForPairwised() {

+ 2 - 2
app/src/main/java/org/iotivity/bridge/homeserver/handler/FactoryPresetsHandler.java

@@ -31,8 +31,8 @@ public class FactoryPresetsHandler implements OCFactoryPresetsHandler {
     public void handler(long deviceIndex) {
         Log.d(TAG, "inside the FactoryPresetsHandler, deviceIndex  = " + deviceIndex);
 
-        if(deviceIndex == Bridge.BRIDGE_INDEX)
-            setPKISecurityMfgCert(deviceIndex);
+        //if(deviceIndex == Bridge.BRIDGE_INDEX)
+        //TODO :  setPKISecurityMfgCert(deviceIndex);
     }
 
     private void setPKISecurityMfgCert(long deviceIndex) {

+ 9 - 6
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/DeviceDiscoveryHandler.java

@@ -29,9 +29,7 @@ public class DeviceDiscoveryHandler implements OcDeviceDiscoveryHandler {
     public void discoveredDevice(final OcRemoteDevice remoteDevice) {
         Log.d(TAG, "Remote Device Discovery Handler: " + OCUuidUtil.uuidToString(remoteDevice.getDeviceId()) + ", " + remoteDevice.getName());
 
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
+
                 /* Only pairwised devices except Bridge itself and OBT will be added in the pairwised device list */
                 if(!OCUuidUtil.isEqual(remoteDevice.getDeviceId(), self_di) && !Utils.isObt(remoteDevice)) {
 
@@ -42,7 +40,13 @@ public class DeviceDiscoveryHandler implements OcDeviceDiscoveryHandler {
 
                         //Log.d(TAG, "getDeviceSpecificResources: " + service.doGetDeviceSpecificResources(OCUuidUtil.uuidToString(remoteDevice.getDeviceId())));
                         //Log.d(TAG, "StopObserveAll : " + service.stopObserveDeviceSpecificResources(OCUuidUtil.uuidToString(remoteDevice.getDeviceId())));
-                        Log.d(TAG, "ObserveAll : " + service.doObserveDeviceSpecificResources(OCUuidUtil.uuidToString(remoteDevice.getDeviceId())));
+
+                        /*new Thread(new Runnable() {
+                            @Override
+                            public void run() {
+                                Log.d(TAG, "ObserveAll : " + service.doObserveDeviceSpecificResources(OCUuidUtil.uuidToString(remoteDevice.getDeviceId())));
+                            }
+                        }).start();*/
                     }
 
                     /* check if the device is accessible via coaps get /oic/d or not
@@ -57,8 +61,7 @@ public class DeviceDiscoveryHandler implements OcDeviceDiscoveryHandler {
                     }
                     */
                 }
-            }
-        }).start();
+
 
     }
 }

+ 8 - 2
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/GetResponseHandler.java

@@ -50,8 +50,14 @@ public class GetResponseHandler implements OCResponseHandler {
             sb.append("\"res_data\":" + json);
             sb.append("}");
 
-            String result_str = sb.toString().replace("\\", "");
-            service.broadcastResult(BridgeService.ResultType.OK.ordinal(), result_str);
+            final String result_str = sb.toString().replace("\\", "");
+            Log.d(TAG, "GET "+resource.getUri()+" Response : result = " + result_str);
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    service.broadcastResult(BridgeService.ResultType.OK.ordinal(), result_str);
+                }
+            }).start();
 
         } catch (Exception ex) {
             Log.e(TAG, "JSON Error : ", ex);

+ 9 - 3
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/ObserveResponseHandler.java

@@ -53,12 +53,18 @@ public class ObserveResponseHandler implements OCResponseHandler {
             sb.append("\"id\":\"" + resource.getAnchor() + resource.getUri() + "\",");
             sb.append("\"di\":\"" + Utils.getDIFromAnchor(resource.getAnchor()) + "\",");
             sb.append("\"uri\":\"" + resource.getUri() + "\",");
-            sb.append("\"res_type\":\"" + BridgeService.ResponseType.GET.name() + "\",");
+            sb.append("\"res_type\":\"" + res_type + "\",");
             sb.append("\"res_data\":" + json);
             sb.append("}");
 
-            String result_str = sb.toString().replace("\\", "");
-            service.broadcastResult(BridgeService.ResultType.OK.ordinal(), result_str);
+            final String result_str = sb.toString().replace("\\", "");
+            Log.d(TAG, "OBSERVE "+resource.getUri()+" Response : result = " + result_str);
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    service.broadcastResult(BridgeService.ResultType.OK.ordinal(), result_str);
+                }
+            }).start();
 
         } catch (Exception ex) {
             Log.e(TAG, "JSON Error : ", ex);

+ 10 - 6
app/src/main/java/org/iotivity/bridge/homeserver/handler/server/GetRequestHandler.java

@@ -42,9 +42,12 @@ public class GetRequestHandler implements OCRequestHandler {
         String device_uuid = OCUuidUtil.uuidToString(uuid);
         String resource_uri = request.getResource().getUri();
 
-        service.msg("Get "+resource_uri+" of "+device_uuid+"("+device.getDeviceName()+") Request Received.");
+        Log.d(TAG, "Get "+resource_uri+" of "+device_uuid+"("+device.getDeviceName()+") Request Received.");
+        //service.msg("Get "+resource_uri+" of "+device_uuid+"("+device.getDeviceName()+") Request Received.");
         String properies = service.doGetLightControlResource(device_index, device_uuid, resource_uri);
-        device.addProperties(resource_uri, properies);
+        if(properies!=null) {
+            device.addProperties(resource_uri, properies);
+        }
 
         OcCborEncoder root = OcCborEncoder.createOcCborEncoder(OcCborEncoder.EncoderType.ROOT);
         switch (interfaces) {
@@ -67,7 +70,7 @@ public class GetRequestHandler implements OCRequestHandler {
                         String key = e.nextElement();
                         Object value = properties.get(key);
                         //Log.d(TAG, "Properties key="+key+", value="+value+", value instance="+ value.getClass().getCanonicalName());
-                        service.msg("\t\t" + key + ": " + value);
+                        Log.d(TAG, "\t\t" + key + ": " + value);
                         if(value instanceof Boolean) {
                             root.setBoolean(key, (boolean)value);
                         } else if(value instanceof String) {
@@ -86,9 +89,10 @@ public class GetRequestHandler implements OCRequestHandler {
                 break;
         }
         root.done();
-        service.msg("Get "+request.getResource().getUri()+" Response Sent.");
-        service.printLine();
-
         OcUtils.sendResponse(request, OCStatus.OC_STATUS_OK);
+
+        Log.d(TAG, "Get "+request.getResource().getUri()+" Response Sent.");
+        //service.msg("Get "+request.getResource().getUri()+" Response Sent.");
+        //service.printLine();
     }
 }

BIN
app/src/main/jniLibs/arm64-v8a/libiotivity-lite-jni.so


BIN
app/src/main/jniLibs/armeabi-v7a/libiotivity-lite-jni.so


BIN
app/src/main/jniLibs/x86/libiotivity-lite-jni.so


BIN
app/src/main/jniLibs/x86_64/libiotivity-lite-jni.so


+ 11 - 0
app/src/main/res/menu/actionbar_actions.xml

@@ -22,6 +22,11 @@
             android:title="@string/addVOS"
             app:showAsAction="never"/>
 
+        <item
+            android:id="@+id/action_inc_vos"
+            android:title="@string/incVOS"
+            app:showAsAction="never"/>
+
         <item
             android:id="@+id/action_add_voc"
             android:title="@string/addVOC"
@@ -67,4 +72,10 @@
                     android:icon="@drawable/ic_search_white_48dp"
                     android:title="Search"
                     app:showAsAction="ifRoom"/>-->
+
+    <item
+        android:id="@+id/action_exit"
+        android:icon="@android:drawable/ic_lock_power_off"
+        android:title="Exit"
+        app:showAsAction="ifRoom"/>
 </menu>

+ 4 - 0
app/src/main/res/values/strings.xml

@@ -25,6 +25,10 @@
     <string name="addVOSMessage">Note: Virtual OCF Server(Light Switch) will be added to operate CTT as a first VOD.</string>
     <string name="addVOSOkMessage">Virtual OCF Server(Light Switch) was added successfully.</string>
 
+    <string name="incVOS">Add Multiple Virtual OCF Server</string>
+    <string name="incVOSMessage">Note: Virtual OCF Server(Light Switch ?) will be added to operate CTT as a first VOD.</string>
+    <string name="incVOSOkMessage">Virtual OCF Server(Light Switch ?) was added successfully.</string>
+
     <string name="addVOC">Add Virtual OCF Client</string>
     <string name="addVOCMessage">Note: Virtual OCF Client will be added to operate CTT as a second VOD.</string>
     <string name="addVOCOkMessage">Virtual OCF Client was added successfully.</string>