Fix handler setters of RcsResourceObject of resource-encapsulation android api.
authorcoderhyme <jhyo.kim@samsung.com>
Tue, 22 Sep 2015 07:36:48 +0000 (00:36 -0700)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 22 Sep 2015 11:09:30 +0000 (11:09 +0000)
Handler setters should accept null to erase one set earlier.
It is to make apis consistent between c++ and android.

Additionally an issue caused by using old exception class name is fixed.

Change-Id: I273755b6d2ab48a489d1829aa932b2f675332db6
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2915
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-encapsulation/android/service/src/main/java/org/iotivity/service/server/RcsResourceObject.java
service/resource-encapsulation/android/service/src/main/jni/JniRcsResourceObject.cpp
service/resource-encapsulation/examples/linux/NestedAttributeClient.cpp
service/resource-encapsulation/examples/linux/SampleResourceClient.cpp

index 7586113..383ce13 100644 (file)
@@ -529,15 +529,11 @@ public final class RcsResourceObject extends RcsObject {
      *
      * @throws RcsException
      *             If the object is destroyed.
-     * @throws NullPointerException
-     *             If handler is null.
-     *
      */
     public void setGetRequestHandler(GetRequestHandler handler)
             throws RcsException {
         assertAlive();
 
-        if (handler == null) throw new NullPointerException("handler is null.");
         nativeSetGetRequestHandler(handler);
     }
 
@@ -549,16 +545,12 @@ public final class RcsResourceObject extends RcsObject {
      *
      * @throws RcsException
      *             If the object is destroyed.
-     * @throws NullPointerException
-     *             If handler is null.
      *
      */
     public void setSetRequestHandler(SetRequestHandler handler)
             throws RcsException {
         assertAlive();
 
-        if (handler == null) throw new NullPointerException("handler is null.");
-
         nativeSetSetRequestHandler(handler);
     }
 
index f38d309..4354032 100644 (file)
@@ -540,8 +540,15 @@ Java_org_iotivity_service_server_RcsResourceObject_nativeSetGetRequestHandler
     auto res = getResource(env, obj);
     VERIFY_NO_EXC(env);
 
-    res->setGetRequestHandler(std::bind(onGetRequest, std::placeholders::_1, std::placeholders::_2,
-            JavaGlobalRef{ env, listenerObj }));
+    if (listenerObj)
+    {
+        res->setGetRequestHandler(std::bind(onGetRequest, std::placeholders::_1, std::placeholders::_2,
+                JavaGlobalRef{ env, listenerObj }));
+    }
+    else
+    {
+        res->setGetRequestHandler({ });
+    }
 }
 
 JNIEXPORT void JNICALL
@@ -553,8 +560,15 @@ Java_org_iotivity_service_server_RcsResourceObject_nativeSetSetRequestHandler
     auto res = getResource(env, obj);
     VERIFY_NO_EXC(env);
 
-    res->setSetRequestHandler(std::bind(onSetRequest, std::placeholders::_1, std::placeholders::_2,
-           JavaGlobalRef{ env, listenerObj }));
+    if (listenerObj)
+    {
+        res->setSetRequestHandler(std::bind(onSetRequest, std::placeholders::_1,
+                std::placeholders::_2, JavaGlobalRef{ env, listenerObj }));
+    }
+    else
+    {
+        res->setSetRequestHandler({ });
+    }
 }
 
 JNIEXPORT void JNICALL
index 2e888f8..73a417a 100644 (file)
@@ -299,9 +299,9 @@ bool discoverResource()
         RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
                 relativetUri, resourceType, &onResourceDiscovered);
     }
-    catch(PlatformException e)
+    catch(const RCSPlatformException& e)
     {
-         std::cout << "Platform Exception while calling discoverResourceByType" << std::endl;
+         std::cout << e.what() << std::endl;
     }
     std::unique_lock<std::mutex> lck(mtx);
     cond.wait_for(lck, std::chrono::seconds(2));
index 0020c79..1f9db08 100644 (file)
@@ -435,29 +435,17 @@ void discoverResource()
 
     std::cin >> addressInput;
 
-    if (addressInput == multicastAdd)
+    try
     {
-        try
-        {
-            discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
-                            relativeUri, resourceType, &onResourceDiscovered);
-        }
-        catch (PlatformException e)
-        {
-            std::cout << "Platform Exception while calling discoverResourceByType" << std::endl;
-        }
+        RCSAddress targetAddress = addressInput == multicastAdd ? RCSAddress::multicast() :
+                RCSAddress::unicast(addressInput);
+
+        discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(
+                targetAddress, relativeUri, resourceType, &onResourceDiscovered);
     }
-    else
+    catch (const RCSPlatformException& e)
     {
-        try
-        {
-            discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::unicast
-                            (addressInput), relativeUri, resourceType, &onResourceDiscovered);
-        }
-        catch (PlatformException e)
-        {
-            std::cout << "Platform Exception while calling discoverResourceByType" << std::endl;
-        }
+        std::cout << e.what() << std::endl;
     }
 }