[Resource Encapsulation] Updated DiscoverResource APIs
authorJay Sharma <jay.sharma@samsung.com>
Sun, 16 Aug 2015 13:52:51 +0000 (19:22 +0530)
committerUze Choi <uzchoi@samsung.com>
Mon, 17 Aug 2015 10:28:24 +0000 (10:28 +0000)
- Updated RCSDiscoveryManager class
- Updated Linux Sample App
- Updated UnitTestCase

Change-Id: Iaaf72b85335df2507543ccc16de6c094d4c1fe1f
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2158
Reviewed-by: JungHo Kim <jhyo.kim@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification-manager/NotificationManager/src/ResourceHosting.cpp
service/resource-encapsulation/examples/linux/SampleResourceClient.cpp
service/resource-encapsulation/include/RCSDiscoveryManager.h
service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp
service/resource-encapsulation/unittests/ResourceClientTest.cpp

index b41bfe9..a85a853 100644 (file)
@@ -184,9 +184,9 @@ void ResourceHosting::requestMulticastDiscovery()
 void ResourceHosting::requestDiscovery(std::string address)
 {
     std::string host = address;
-    std::string uri = OC_RSRVD_WELL_KNOWN_URI + std::string("?rt=") + HOSTING_RESOURSE_TYPE;
     RCSAddress rcsAddress = RCSAddress::unicast(host);
-    discoveryManager->discoverResource(rcsAddress, uri, pDiscoveryCB);
+    discoveryManager->discoverResourceByType(rcsAddress, OC_RSRVD_WELL_KNOWN_URI,
+            HOSTING_RESOURSE_TYPE, pDiscoveryCB);
 }
 
 void ResourceHosting::discoverHandler(RemoteObjectPtr remoteResource)
index 316042e..b905977 100644 (file)
@@ -39,8 +39,8 @@ constexpr int QUIT_INPUT = 3;
 std::shared_ptr<RCSRemoteResourceObject>  resource;
 
 const std::string defaultKey = "Temperature";
-const std::string resourceType = "?rt=core.TemperatureSensor";
-const std::string targetUri = OC_RSRVD_WELL_KNOWN_URI + resourceType;
+const std::string resourceType = "core.TemperatureSensor";
+const std::string relativetUri = OC_RSRVD_WELL_KNOWN_URI;
 
 std::mutex mtx;
 std::condition_variable cond;
@@ -397,8 +397,8 @@ bool discoverResource()
 {
     std::cout << "Wait 2 seconds until discovered." << std::endl;
 
-    RCSDiscoveryManager::getInstance()->discoverResource(RCSAddress::multicast(), targetUri,
-                                                         &onResourceDiscovered);
+    RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
+            relativetUri, resourceType, &onResourceDiscovered);
 
     std::unique_lock<std::mutex> lck(mtx);
     cond.wait_for(lck,std::chrono::seconds(2));
index 53ad2b1..2105647 100644 (file)
@@ -21,7 +21,7 @@
 /**
  * @file
  *
- * This file contains the RCSDiscoveryManager class which provide API to discover the Resource in the network
+ * This file contains the RCSDiscoveryManager class which provide APIs to discover the Resource in the network
  *
  */
 
@@ -35,54 +35,104 @@ namespace OIC
 {
     namespace Service
     {
-
         class RCSRemoteResourceObject;
         class RCSAddress;
 
         /**
-         * This class contains the resource discovery method.
+         * This class contains the resource discovery methods.
          *
          * @see RCSRemoteResourceObject
          */
         class RCSDiscoveryManager
         {
-        public:
+            public:
+
+                /**
+                 * Typedef for callback of discoverResource APIs
+                 *
+                 * @see discoverResource
+                 */
+                typedef std::function< void(std::shared_ptr< RCSRemoteResourceObject >) >
+                                       ResourceDiscoveredCallback;
+
+                /**
+                 * Returns RCSDiscoveryManager instance.
+                 *
+                 */
+                static RCSDiscoveryManager* getInstance();
+
+                /**
+                 * API for discovering the resource of Interest, regardless of URI and resource type
+                 *
+                 * @param address A RCSAddress object
+                 * @param cb A callback to obtain discovered resource
+                 *
+                 * @throws InvalidParameterException If cb is empty.
+                 *
+                 * @note The callback will be invoked in an internal thread.
+                 *
+                 * @see RCSAddress
+                 *
+                 */
+                void discoverResource(const RCSAddress& address, ResourceDiscoveredCallback cb);
 
-            /**
-             * Typedef for callback of discoverResource API
-             *
-             * @see discoverResource
-             */
-            typedef std::function< void(std::shared_ptr< RCSRemoteResourceObject >) >
-                ResourceDiscoveredCallback;
+                /**
+                 * API for discovering the resource of Interest, regardless of resource type
+                 *
+                 * @param address A RCSAddress object
+                 * @param relativeURI The relative uri of resource to be searched
+                 * @param cb A callback to obtain discovered resource
+                 *
+                 * @throws InvalidParameterException If cb is empty.
+                 *
+                 * @note The callback will be invoked in an internal thread.
+                 *
+                 * @see RCSAddress
+                 *
+                 */
+                void discoverResource(const RCSAddress& address, const std::string& relativeURI,
+                                      ResourceDiscoveredCallback cb);
 
-            /**
-             * Returns RCSDiscoveryManager instance.
-             *
-             */
-            static RCSDiscoveryManager* getInstance();
+                /**
+                 * API for discovering the resource of Interest by Resource type.
+                 *
+                 * @param address A RCSAddress object
+                 * @param resourceType Ressource Type
+                 * @param cb A callback to obtain discovered resource
+                 *
+                 * @throws InvalidParameterException If cb is empty.
+                 *
+                 * @note The callback will be invoked in an internal thread.
+                 *
+                 * @see RCSAddress
+                 *
+                 */
+                void discoverResourceByType(const RCSAddress& address, const std::string& resourceType,
+                                            ResourceDiscoveredCallback cb);
 
-            /**
-             * API for discovering the resource of Interest.
-             *
-             * @param address A RCSAddress object
-             * @param resourceURI The uri of resource to be searched
-             * @param cb A callback to obtain discovered resource
-             *
-             * @throws InvalidParameterException If cb is empty.
-             *
-             * @note The callback will be invoked in an internal thread.
-             *
-             * @see RCSAddress
-             *
-             */
-            void discoverResource(const RCSAddress& address, const std::string& resourceURI,
-                    ResourceDiscoveredCallback cb);
+                /**
+                 * API for discovering the resource of Interest by Resource type with provided relativeURI
+                 *
+                 * @param address A RCSAddress object
+                 * @param relativeURI The relative uri of resource to be searched
+                 * @param resourceType Ressource Type
+                 * @param cb A callback to obtain discovered resource
+                 *
+                 * @throws InvalidParameterException If cb is empty.
+                 *
+                 * @note The callback will be invoked in an internal thread.
+                 *
+                 * @see RCSAddress
+                 *
+                 */
+                void discoverResourceByType(const RCSAddress& address, const std::string& relativeURI,
+                                            const std::string& resourceType,
+                                            ResourceDiscoveredCallback cb);
 
-        private:
-            RCSDiscoveryManager() = default;
-            ~RCSDiscoveryManager() = default;
+            private:
 
+                RCSDiscoveryManager() = default;
+                ~RCSDiscoveryManager() = default;
         };
     }
 }
index c51b733..7e19d4d 100644 (file)
@@ -57,18 +57,39 @@ namespace OIC
         }
 
         void RCSDiscoveryManager::discoverResource(const RCSAddress& address,
-                const std::string& resourceURI, ResourceDiscoveredCallback cb)
+                ResourceDiscoveredCallback cb)
         {
-            SCOPE_LOG_F(DEBUG, TAG);
+            discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, "", std::move(cb));
+        }
+
+        void RCSDiscoveryManager::discoverResource(const RCSAddress& address,
+                const std::string& relativeURI, ResourceDiscoveredCallback cb)
+        {
+            discoverResourceByType(address, relativeURI, "", std::move(cb));
+        }
+
+        void RCSDiscoveryManager::discoverResourceByType(const RCSAddress& address,
+                const std::string& resourceType,
+                ResourceDiscoveredCallback cb)
+        {
+            discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, resourceType, std::move(cb));
+        }
 
+        void RCSDiscoveryManager::discoverResourceByType(const RCSAddress& address,
+                const std::string& relativeURI, const std::string& resourceType,
+                ResourceDiscoveredCallback cb)
+        {
             if (!cb)
             {
-                OC_LOG(ERROR, TAG, "discoverResource NULL Callback");
-                throw InvalidParameterException{ "discoverResource NULL Callback'" };
+                OC_LOG(ERROR, TAG, "discoverResourceByType NULL Callback");
+                throw InvalidParameterException { "discoverResourceByType NULL Callback'" };
             }
-
-            OIC::Service::discoverResource(address, resourceURI,
+            else
+            {
+                std::string resourceURI = relativeURI + "?rt=" + resourceType;
+                OIC::Service::discoverResource(address, resourceURI,
                     std::bind(findCallback, std::placeholders::_1, std::move(cb)));
+            }
         }
     }
 }
index c51d1a5..08b58cd 100644 (file)
@@ -102,10 +102,11 @@ private:
     {
         while (checkObject())
         {
-            RCSDiscoveryManager::getInstance()->discoverResource(RCSAddress::multicast(),
-                    "/oic/res?rt=Resource.Hosting", std::bind(resourceDiscovered, this, finished,
-                            std::placeholders::_1));
-
+            const std::string uri  = "/oic/res";
+            const std::string type = "Resource.Hosting";
+            RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
+                     uri, type, std::bind(resourceDiscovered, this, finished,
+                           std::placeholders::_1));
             Wait(1000);
         }
     }