Explorar el Código

IBridgeService Interfaces are added and modfied. Broadcasting Observe response was modified after Posting/Putting or normal Observing. Post/Put Interface APIs was tested.

Trishia hace 4 años
padre
commit
c214b21023

+ 13 - 2
app/src/main/aidl/org/iotivity/bridge/homeserver/IBridgeService.aidl

@@ -62,7 +62,7 @@ interface IBridgeService {
     boolean requestGetProperties(in String device_uuid, in String resource_uri) ;
 
     /**
-     * request Posting/Putting the value of properties to the remote OCF device
+     * request Posting the value of properties to the remote OCF device
      * @param device_uuid unique identity of ocf device (eg. 15ba3c25-8cdd-41f8-6f9e-fe49105dce0a)
      * @param resource_uri uri of ocf resource (eg. /a/light)
      * @param prop_data the property values of the resource (eg. { "power" : true, "level" : 100 }
@@ -72,6 +72,17 @@ interface IBridgeService {
      */
     boolean requestPostProperties(in String device_uuid, in String resource_uri, in String prop_data) ;
 
+    /**
+     * request Putting the value of properties to the remote OCF device
+     * @param device_uuid unique identity of ocf device (eg. 15ba3c25-8cdd-41f8-6f9e-fe49105dce0a)
+     * @param resource_uri uri of ocf resource (eg. /a/light)
+     * @param prop_data the property values of the resource (eg. { "power" : true, "level" : 100 }
+     * @return
+     *   - true : function call success,
+     *   - false : function call fail
+     */
+    boolean requestPutProperties(String device_uuid, String resource_uri, String prop_data);
+
     /**
      * request Observing all properties of the resource to the remote OCF device
      * @param device_uuid unique identity of ocf device (eg. 15ba3c25-8cdd-41f8-6f9e-fe49105dce0a)
@@ -108,6 +119,6 @@ interface IBridgeService {
      *   - true : function call success,
      *   - false : function call fail
      */
-    boolean requestStopObserveDeviceAllResources(in String device_uuid) ;
+    boolean requestStopObserveDeviceSpecificResources(in String device_uuid) ;
 
 }

+ 6 - 1
app/src/main/java/org/iotivity/bridge/homeserver/BridgeService.java

@@ -191,6 +191,11 @@ public class BridgeService extends IntentService {
             return doPostDeviceResource(device_uuid, resource_uri, prop_data);
         }
 
+        @Override
+        public boolean requestPutProperties(String device_uuid, String resource_uri, String prop_data) throws RemoteException {
+            return doPutDeviceResource(device_uuid, resource_uri, prop_data);
+        }
+
         @Override
         public boolean requestObserveResource(String device_uuid, String resource_uri) throws RemoteException {
             return doObserveResource(device_uuid, resource_uri) ;
@@ -207,7 +212,7 @@ public class BridgeService extends IntentService {
         }
 
         @Override
-        public boolean requestStopObserveDeviceAllResources(String device_uuid) throws RemoteException {
+        public boolean requestStopObserveDeviceSpecificResources(String device_uuid) throws RemoteException {
             return stopObserveDeviceSpecificResources(device_uuid);
         }
 

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

@@ -57,9 +57,9 @@ public class GetResponseHandler implements OCResponseHandler {
         }
 
         // for test
-        //service.doPostDeviceResource(Utils.getDIFromAnchor(resource.getAnchor()),
-        //        resource.getUri(), json);
-        //service.doPutDeviceResource(Utils.getDIFromAnchor(resource.getAnchor()),
-        //        resource.getUri(), json);
+        service.doPostDeviceResource(Utils.getDIFromAnchor(resource.getAnchor()),
+                resource.getUri(), json);
+        service.doPutDeviceResource(Utils.getDIFromAnchor(resource.getAnchor()),
+                resource.getUri(), json);
     }
 }

+ 8 - 1
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/ObserveResponseHandler.java

@@ -22,12 +22,19 @@ public class ObserveResponseHandler implements OCResponseHandler {
 
     private BridgeService service;
     private OcRemoteResource resource ;
+    private BridgeService.ResponseType res_type = BridgeService.ResponseType.OBSERVE ;
 
     public ObserveResponseHandler(BridgeService service, OcRemoteResource resource) {
         this.service = service;
         this.resource = resource;
     }
 
+    public ObserveResponseHandler(BridgeService service, OcRemoteResource resource, BridgeService.ResponseType res_type) {
+        this.service = service;
+        this.resource = resource;
+        this.res_type = res_type;
+    }
+
     @Override
     public void handler(OCClientResponse response) {
 
@@ -46,7 +53,7 @@ public class ObserveResponseHandler implements OCResponseHandler {
             result.put("id", resource.getAnchor() + resource.getUri());
             result.put("di", Utils.getDIFromAnchor(resource.getAnchor()));
             result.put("uri", resource.getUri());
-            result.put("res_type", BridgeService.ResponseType.OBSERVE.name());
+            result.put("res_type", res_type.name());
             result.put("res_data", props);
 
             String result_str = result.toString().replace("\\", "");

+ 6 - 2
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/PostResponseHandler.java

@@ -37,6 +37,10 @@ public class PostResponseHandler implements OCResponseHandler {
             return;
         }
 
+        /* TODO : check if it needs for broadcast POST/PUT Result
+         *  because Requesting Post call's result was already returned in Interface API call
+         *  (eg. public boolean requestPostProperties(String device_uuid, String resource_uri, String prop_data))
+         *
         try {
 
             JSONObject result = new JSONObject();
@@ -50,10 +54,10 @@ public class PostResponseHandler implements OCResponseHandler {
 
         } catch (JSONException ex) {
             Log.e(TAG, "JSON Error : ", ex);
-        }
+        } */
 
         // Observe the response of Post Request
-        ObserveResponseHandler observerLight = new ObserveResponseHandler(service, resource);
+        ObserveResponseHandler observerLight = new ObserveResponseHandler(service, resource, BridgeService.ResponseType.POST);
         OcUtils.doObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, observerLight, OCQos.LOW_QOS);
 
         // Stop Observe right after Observe

+ 7 - 2
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/PutResponseHandler.java

@@ -33,6 +33,10 @@ public class PutResponseHandler implements OCResponseHandler {
             return;
         }
 
+        /* TODO : check if it needs for broadcast POST/PUT Result
+         *  because Requesting Post call's result was already returned in Interface API call
+         *  (eg. public boolean requestPostProperties(String device_uuid, String resource_uri, String prop_data))
+         *
         try {
 
             JSONObject result = new JSONObject();
@@ -47,13 +51,14 @@ public class PutResponseHandler implements OCResponseHandler {
         } catch (JSONException ex) {
             Log.e(TAG, "JSON Error : ", ex);
         }
+        */
 
         // Observe the response of Post Request
-        ObserveResponseHandler observerLight = new ObserveResponseHandler(service, resource);
+        ObserveResponseHandler observerLight = new ObserveResponseHandler(service, resource, BridgeService.ResponseType.PUT);
         OcUtils.doObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, observerLight, OCQos.LOW_QOS);
 
         // Stop Observe right after Observe
-        OcUtils.stopObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()));
+        // OcUtils.stopObserve(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()));
 
         // Stop trigger register. It will be stop Observe after some secs
         //StopObserveTriggerHandler stopObserve = new StopObserveTriggerHandler(resource);

+ 0 - 13
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/ResponseParsingHelper.java

@@ -172,17 +172,4 @@ public class ResponseParsingHelper {
         return props ;
     }
 
-    static public String parseClientResponse(OCClientResponse response, BridgeService service, String data) {
-
-        try {
-            OCRepresentation rep = response.getPayload();
-            OCRep.toJSON(rep, true);
-
-
-        }catch (Exception ex) {
-
-        }
-
-        return null ;
-    }
 }

+ 8 - 16
app/src/main/java/org/iotivity/bridge/homeserver/handler/server/PostLightRequestHandler.java

@@ -2,6 +2,7 @@ package org.iotivity.bridge.homeserver.handler.server;
 
 import android.util.Log;
 
+import org.iotivity.OCRepresentation;
 import org.iotivity.OCRequest;
 import org.iotivity.OCRequestHandler;
 import org.iotivity.OCStatus;
@@ -30,26 +31,17 @@ public class PostLightRequestHandler implements OCRequestHandler {
 
         service.msg("Post "+request.getResource().getUri()+" Request Received.");
 
-        OcRepresentation rep = new OcRepresentation(request.getRequestPayload());
+        OCRepresentation rep = request.getRequestPayload();
         while (rep != null) {
-            try {
-                if (Light.SWITCH_KEY.equalsIgnoreCase(rep.getKey())) {
-                    light.setSwitchOn(rep.getBoolean(Light.SWITCH_KEY));
-                    service.msg("\t\t" + Light.SWITCH_KEY + ": " + light.isSwitchOn());
-                }
-            } catch (OcCborException e) {
-                // ignore -- no switch value
+            if (Light.SWITCH_KEY.equalsIgnoreCase(rep.getName())) {
+                light.setSwitchOn(rep.getValue().getBool());
+                service.msg("\t\t" + Light.SWITCH_KEY + ": " + light.isSwitchOn());
             }
 
-            try {
-                if (Light.DIMMING_SETTING_KEY.equalsIgnoreCase(rep.getKey())) {
-                    light.setDimmingLevel((int) rep.getLong(Light.DIMMING_SETTING_KEY));
-                    service.msg("\t\t" + Light.DIMMING_SETTING_KEY + ": " + light.getDimmingLevel());
-                }
-            } catch (OcCborException e) {
-                // ignore -- no dimming value
+            if (Light.DIMMING_SETTING_KEY.equalsIgnoreCase(rep.getName())) {
+                light.setDimmingLevel((int) rep.getValue().getInteger());
+                service.msg("\t\t" + Light.DIMMING_SETTING_KEY + ": " + light.getDimmingLevel());
             }
-
             rep = rep.getNext();
         }