[Resource Encapsulation] Updated Discover API of Resource Client for RCSAddress
authorJay Sharma <jay.sharma@samsung.com>
Sun, 26 Jul 2015 08:12:39 +0000 (13:42 +0530)
committerUze Choi <uzchoi@samsung.com>
Sun, 26 Jul 2015 09:38:37 +0000 (09:38 +0000)
- updated Resource Client, sample, UnittestCases
- added more Exception to Resource Client

Change-Id: Ib91934b372efe23f7a657152a63a9dd7aa5d06ce
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1905
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification-manager/NotificationManager/src/ResourceHosting.cpp
service/notification-manager/NotificationManager/src/ResourceHosting.h
service/resource-encapsulation/examples/linux/SampleResourceClient.cpp
service/resource-encapsulation/include/ResourceClient.h
service/resource-encapsulation/src/ResourceClient.cpp
service/resource-encapsulation/unittests/ResourceClient_Test.cpp

index 2e77d8b..d6e20f7 100755 (executable)
@@ -184,8 +184,8 @@ void ResourceHosting::requestDiscovery(std::string address)
 {
     std::string host = address;
     std::string uri = OC_RSRVD_WELL_KNOWN_URI + std::string("?rt=") + HOSTING_RESOURSE_TYPE;
-    OCConnectivityType type = OCConnectivityType::CT_DEFAULT;
-    discoveryManager->discoverResource(host, uri, type, pDiscoveryCB);
+    RCSAddress rcsAddress = RCSAddress::unicast(host);
+    discoveryManager->discoverResource(rcsAddress, uri, pDiscoveryCB);
 }
 
 void ResourceHosting::discoverHandler(RemoteObjectPtr remoteResource)
index c0fd62c..8a4a00e 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "octypes.h"
 #include "ResourceClient.h"
+#include "RCSAddress.h"
 #include "PresenceSubscriber.h"
 #include "HostingObject.h"
 #include "PrimitiveResource.h"
index 32225c2..cc23b16 100644 (file)
@@ -3,6 +3,7 @@
 #include "ResourceClient.h"
 #include "RCSResourceAttributes.h"
 #include "OCPlatform.h"
+#include "RCSAddress.h"
 
 using namespace std;
 using namespace OC;
@@ -128,9 +129,14 @@ int main()
 
     try
     {
+
         uri = OC_RSRVD_WELL_KNOWN_URI + uri + "?rt=" + rt;
+
+        //getting the object of RCSAddress for multicast discovery
+        RCSAddress rcsAddress = RCSAddress::multicast();
+
         //discover the resource in the network
-        discoveryManagerInstance->discoverResource(address, uri , CT_DEFAULT, &OnResourceDiscovered);
+        discoveryManagerInstance->discoverResource(rcsAddress, uri , &OnResourceDiscovered);
     }
     catch (InvalidParameterException e)
     {
index ecc505e..dd02bb6 100644 (file)
@@ -67,6 +67,7 @@ namespace OIC
         class RCSException;
         class RemoteResourceObject;
         class PrimitiveResource;
+        class RCSAddress;
 
         /**
          * @class  BadRequestException
@@ -207,6 +208,8 @@ namespace OIC
                  *
                  * @return ResourceState - current state of the resource.
                  *
+                 * @throw BadRequestException
+                 *
                  * @see ResourceState
                  */
                 ResourceState getState() const ;
@@ -236,6 +239,8 @@ namespace OIC
                  *
                  * @param cb - callback to get updated resourceAttributes.
                  *
+                 * @throw InvalidParameterException
+                 *
                  * @see CacheUpdatedCallback
                  *
                  * NOTE: Developer can call this API any number of time. Developer should
@@ -250,6 +255,8 @@ namespace OIC
                  *
                  * @return CacheState - Current state of the Cache.
                  *
+                 * @throw BadRequestException
+                 *
                  * @see CacheState
                  *
                  */
@@ -319,6 +326,9 @@ namespace OIC
                 * @details This API send a get request to the resource of interest and provides the attributes
                 *               to the caller in the RemoteAttributesReceivedCallback.
                 *
+                *
+                * @throw InvalidParameterException
+                *
                 * @see RCSResourceAttributes::Value
                 */
                 void getRemoteAttributes(RemoteAttributesReceivedCallback cb);
@@ -332,6 +342,8 @@ namespace OIC
                 * @param attributes - resourceAttributes data to set
                 * @param cb - callback on setting resourceAttributes data.
                 *
+                * @throw InvalidParameterException
+                *
                 */
                 void setRemoteAttributes(const RCSResourceAttributes &attributes, RemoteAttributesSetCallback cb);
 
@@ -432,19 +444,16 @@ namespace OIC
                 /**
                 * API for discovering the resource of Interest.
                 *
-                * @param host - host of the Resource
+                * @param address - RCSAddress object
                 * @param resourceURI - uri of resource to be searched
-                * @param connectivityType - connection type
                 * @param cb - callback to obtain discovered resource
                 *
                 * @throw InvalidParameterException : This API throws the InvalidParameterException if any of
                 *                                                         the parameter is invalid.
-                *
+                * @RCSAddress
                 */
-                void discoverResource(std::string host, std::string resourceURI,
-                                      OCConnectivityType connectivityType,
+                void discoverResource(const RCSAddress &address, const std::string &resourceURI,
                                       OnResourceDiscoveredCallback cb);
-
             private:
 
                 /**
index 9d7f933..dff1923 100644 (file)
@@ -275,25 +275,32 @@ namespace OIC
         void RemoteResourceObject::startCaching(CacheUpdatedCallback cb)
         {
             OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching entry");
-            if (true == m_cachingFlag)
+            if (!cb)
             {
-                OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching : already Started");
+                throw InvalidParameterException {"startCaching : Callback is NULL" };
             }
             else
             {
-                try
+                if (true == m_cachingFlag)
                 {
-                  CacheID cacheId = ResourceCacheManager::getInstance()->requestResourceCache(m_primitiveResource,
-                                      std::bind(cachingCallback, std::placeholders::_1, std::placeholders::_2, cb),
-                                      REPORT_FREQUENCY::UPTODATE,  0);
-
-                    m_cacheId = cacheId;
-                    m_cachingFlag = true;
-                    OC_LOG_V(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching CACHE ID %d", cacheId);
+                    OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching : already Started");
                 }
-                catch (std::exception &exception)
+                else
                 {
-                    throw InvalidParameterException {"startCaching : Callback is NULL" };
+                    try
+                    {
+                        CacheID cacheId = ResourceCacheManager::getInstance()->requestResourceCache(m_primitiveResource,
+                                          std::bind(cachingCallback, std::placeholders::_1, std::placeholders::_2, cb),
+                                          REPORT_FREQUENCY::UPTODATE,  0);
+
+                        m_cacheId = cacheId;
+                        m_cachingFlag = true;
+                        OC_LOG_V(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching CACHE ID %d", cacheId);
+                    }
+                    catch (std::exception &exception)
+                    {
+                        throw InvalidParameterException {"startCaching : error" };
+                    }
                 }
             }
         }
@@ -408,10 +415,15 @@ namespace OIC
         void RemoteResourceObject::getRemoteAttributes(RemoteAttributesReceivedCallback cb)
         {
             OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getRemoteAttributes entry");
-
-            m_primitiveResource->requestGet(std::bind(getCallback, std::placeholders::_1,
-                                            std::placeholders::_2, std::placeholders::_3, cb));
-
+            if (!cb)
+            {
+                throw InvalidParameterException {"getRemoteAttributes : Callback is NULL" };
+            }
+            else
+            {
+                m_primitiveResource->requestGet(std::bind(getCallback, std::placeholders::_1,
+                                                std::placeholders::_2, std::placeholders::_3, cb));
+            }
             OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getRemoteAttributes exit");
         }
 
@@ -419,10 +431,15 @@ namespace OIC
                 RemoteAttributesSetCallback cb)
         {
             OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::setRemoteAttributes entry");
-
-            m_primitiveResource->requestSet(attribute, std::bind(setCallback, std::placeholders::_1,
-                                            std::placeholders::_2, std::placeholders::_3, cb));
-
+            if (!cb)
+            {
+                throw InvalidParameterException {"setRemoteAttributes : Callback is NULL" };
+            }
+            else
+            {
+                m_primitiveResource->requestSet(attribute, std::bind(setCallback, std::placeholders::_1,
+                                                std::placeholders::_2, std::placeholders::_3, cb));
+            }
             OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::setRemoteAttributes exit");
         }
 
@@ -450,8 +467,7 @@ namespace OIC
             return s_instance;
         }
 
-        void DiscoveryManager::discoverResource(std::string host, std::string resourceURI,
-                                                OCConnectivityType connectivityType,
+        void DiscoveryManager::discoverResource(const RCSAddress &address, const std::string &resourceURI,
                                                 OnResourceDiscoveredCallback cb)
         {
 
@@ -467,7 +483,7 @@ namespace OIC
                 OC_LOG(ERROR, CLIENT_W_TAG, "discoverResource NULL Callback");
                 throw InvalidParameterException { "discoverResource NULL Callback'" };
             }
-            OIC::Service::discoverResource(host, resourceURI, connectivityType, std::bind(findCallback,
+            OIC::Service::discoverResource(address, resourceURI, std::bind(findCallback,
                                            std::placeholders::_1,
                                            cb));
 
index e80c9df..e66f286 100644 (file)
@@ -4,6 +4,7 @@
 #include "ResourceClient.h"
 #include "RCSResourceObject.h"
 #include "OCPlatform.h"
+#include "RCSAddress.h"
 
 #define RESOURCEURI "/a/TemperatureSensor"
 #define RESOURCETYPE "Resource.Hosting"
@@ -75,8 +76,8 @@ TEST(ResourceClientTest, testDiscoverResourcePass)
     createResource();
     DiscoveryManager *instance = DiscoveryManager::getInstance();
     cbresult = false;
-
-    instance->discoverResource("", uri, CT_DEFAULT, &onResourceDiscoveredCallback);
+    RCSAddress rcsAddress = RCSAddress::multicast();
+    instance->discoverResource(rcsAddress, uri , &onResourceDiscoveredCallback);
     sleep(2);
     EXPECT_TRUE(object != NULL);
     destroyResource();
@@ -124,7 +125,8 @@ TEST(ResourceClientTest, testSetRemoteAttributesPass)
 TEST(ResourceClientTest, testIsMonitoring)
 {
     createResource();
-    manager->DiscoveryManager::discoverResource("", uri, CT_DEFAULT, &onResourceDiscoveredCallback);
+    RCSAddress rcsAddress = RCSAddress::multicast();
+    manager->DiscoveryManager::discoverResource(rcsAddress, uri , &onResourceDiscoveredCallback);
     sleep(1);
     destroyResource();
     EXPECT_FALSE(object->isMonitoring());
@@ -328,7 +330,8 @@ TEST(ResourceClientTest, testDiscoverResourceEmptyResource)
 {
     createResource();
     DiscoveryManager *instance = DiscoveryManager::getInstance();
-    EXPECT_THROW(instance->discoverResource("", "", CT_DEFAULT, &onResourceDiscoveredCallback),
+    RCSAddress rcsAddress = RCSAddress::multicast();
+    EXPECT_THROW(instance->discoverResource(rcsAddress, "", &onResourceDiscoveredCallback),
                  InvalidParameterException);
     destroyResource();
 }
@@ -338,7 +341,8 @@ TEST(ResourceClientTest, testDiscoverResourceEmptyCallback)
 {
     createResource();
     DiscoveryManager *instance = DiscoveryManager::getInstance();
-    EXPECT_THROW(instance->discoverResource("", uri, CT_DEFAULT, NULL), InvalidParameterException);
+    RCSAddress rcsAddress = RCSAddress::multicast();
+    EXPECT_THROW(instance->discoverResource(rcsAddress, uri , NULL), InvalidParameterException);
     destroyResource();
     object->stopMonitoring();
 }