[Resource-Encapsulation] Splitted Resource Client to 2 files
authorJay Sharma <jay.sharma@samsung.com>
Sun, 26 Jul 2015 11:33:52 +0000 (17:03 +0530)
committerUze Choi <uzchoi@samsung.com>
Sun, 26 Jul 2015 13:53:30 +0000 (13:53 +0000)
- RCSDiscoveryManager and RCSRemoteResourceObject

Change-Id: Iccf1aae4100eba313127fad33dd2adb8bb6bec64
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1914
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
12 files changed:
service/notification-manager/NotificationManager/src/HostingObject.h
service/notification-manager/NotificationManager/src/RequestObject.h
service/notification-manager/NotificationManager/src/ResourceHosting.cpp
service/notification-manager/NotificationManager/src/ResourceHosting.h
service/resource-encapsulation/SConscript
service/resource-encapsulation/examples/linux/SampleResourceClient.cpp
service/resource-encapsulation/include/RCSDiscoveryManager.h [new file with mode: 0644]
service/resource-encapsulation/include/RCSRemoteResourceObject.h [moved from service/resource-encapsulation/include/ResourceClient.h with 87% similarity]
service/resource-encapsulation/include/RCSResourceAttributes.h
service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp [new file with mode: 0644]
service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp [moved from service/resource-encapsulation/src/ResourceClient.cpp with 59% similarity]
service/resource-encapsulation/unittests/ResourceClient_Test.cpp

index efdd0f9..af05c30 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef RH_HOSTINGOBJECT_H_
 #define RH_HOSTINGOBJECT_H_
 
-#include "ResourceClient.h"
+#include "RCSRemoteResourceObject.h"
 #include "RCSResourceObject.h"
 #include "RequestObject.h"
 #include "ResourceBroker.h"
@@ -39,7 +39,7 @@ class HostingObject
 {
 private:
     typedef std::shared_ptr<RCSResourceObject> ResourceObjectPtr;
-    typedef std::shared_ptr<RemoteResourceObject> RemoteObjectPtr;
+    typedef std::shared_ptr<RCSRemoteResourceObject> RemoteObjectPtr;
     typedef std::shared_ptr<RequestObject> RequestObjectPtr;
     typedef std::shared_ptr<PrimitiveResource> PrimiteveResourcePtr;
 
index 073faa2..b15ead9 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef RH_REQUESTOBJECT_H_
 #define RH_REQUESTOBJECT_H_
 
-#include "ResourceClient.h"
+#include "RCSRemoteResourceObject.h"
 #include "RCSResourceObject.h"
 
 namespace OIC
@@ -32,7 +32,7 @@ namespace Service
 class RequestObject
 {
 public:
-    typedef std::shared_ptr<RemoteResourceObject> RemoteObjectPtr;
+    typedef std::shared_ptr<RCSRemoteResourceObject> RemoteObjectPtr;
 
     enum class RequestMethod
     {
index d6e20f7..3ce8fe3 100755 (executable)
@@ -22,6 +22,7 @@
 
 #include "PresenceSubscriber.h"
 #include "OCPlatform.h"
+#include "RCSDiscoveryManager.h"
 
 namespace OIC
 {
@@ -106,7 +107,7 @@ void ResourceHosting::initializeResourceHosting()
     pDiscoveryCB = std::bind(&ResourceHosting::discoverHandler, this,
             std::placeholders::_1);
 
-    discoveryManager = DiscoveryManager::getInstance();
+    discoveryManager = RCSDiscoveryManager::getInstance();
 }
 
 void ResourceHosting::requestMulticastPresence()
index 8a4a00e..f4f9ff6 100644 (file)
@@ -30,7 +30,6 @@
 #include <atomic>
 
 #include "octypes.h"
-#include "ResourceClient.h"
 #include "RCSAddress.h"
 #include "PresenceSubscriber.h"
 #include "HostingObject.h"
@@ -41,17 +40,18 @@ namespace OIC
 namespace Service
 {
 
+class RCSDiscoveryManager;
 class ResourceHosting
 {
 private:
     typedef std::shared_ptr<HostingObject> HostingObjectPtr;
-    typedef std::shared_ptr<RemoteResourceObject> RemoteObjectPtr;
+    typedef std::shared_ptr<RCSRemoteResourceObject> RemoteObjectPtr;
     typedef std::shared_ptr<PrimitiveResource> PrimiteveResourcePtr;
 
     typedef std::function<
             void(OCStackResult, const unsigned int, const std::string&)> SubscribeCallback;
     typedef std::function<
-            void(std::shared_ptr<RemoteResourceObject>)> DiscoveryCallback;
+            void(std::shared_ptr<RCSRemoteResourceObject>)> DiscoveryCallback;
     typedef std::function<void()> DestroyedCallback;
 
 public:
@@ -74,7 +74,7 @@ private:
 
     std::list<HostingObjectPtr> hostingObjectList;
 
-    DiscoveryManager * discoveryManager;
+    RCSDiscoveryManager * discoveryManager;
     PresenceSubscriber presenceHandle;
 
     SubscribeCallback pPresenceCB;
index d7275f5..dfd93a7 100644 (file)
@@ -76,7 +76,7 @@ resourceClient_env.AppendUnique(LIBS = ['dl'])
 ######################################################################
 BROKER_SRC_DIR = 'src/resourceBroker/src/'
 CACHE_SRC_DIR = 'src/resourceCache/src/'
-RESOURCECLIENT_DIR = 'src/'
+RESOURCECLIENT_DIR = 'src/resourceClient/'
 client_src = [
         BROKER_SRC_DIR + 'DeviceAssociation.cpp',
         BROKER_SRC_DIR + 'DevicePresence.cpp',
@@ -84,7 +84,8 @@ client_src = [
         BROKER_SRC_DIR + 'ResourceBroker.cpp',
         CACHE_SRC_DIR + 'DataCache.cpp',
         CACHE_SRC_DIR + 'ResourceCacheManager.cpp',
-        RESOURCECLIENT_DIR + 'ResourceClient.cpp'
+        RESOURCECLIENT_DIR + 'RCSDiscoveryManager.cpp',
+       RESOURCECLIENT_DIR + 'RCSRemoteResourceObject.cpp'
                ]
 ResourceClientsdk = resourceClient_env.StaticLibrary('rcs_client', client_src)
 resourceClient_env.InstallTarget(ResourceClientsdk , 'librcs_client')
index cc23b16..8307f08 100644 (file)
@@ -1,6 +1,7 @@
 #include<iostream>
 
-#include "ResourceClient.h"
+#include "RCSDiscoveryManager.h"
+#include "RCSRemoteResourceObject.h"
 #include "RCSResourceAttributes.h"
 #include "OCPlatform.h"
 #include "RCSAddress.h"
@@ -9,13 +10,13 @@ using namespace std;
 using namespace OC;
 using namespace OIC::Service;
 
-std::shared_ptr<RemoteResourceObject>  resource;
+std::shared_ptr<RCSRemoteResourceObject>  resource;
 RCSResourceAttributes resourceAttributes;
 bool startCachingFlag;
 bool isReady;
 
 //callback function for discoverResource()
-void OnResourceDiscovered(std::shared_ptr<RemoteResourceObject> foundResource)
+void OnResourceDiscovered(std::shared_ptr<RCSRemoteResourceObject> foundResource)
 {
 
     cout << "\nOnResourceDiscovered callback" << std::endl;
@@ -112,7 +113,7 @@ void OnRemoteAttributesSetCallback(const RCSResourceAttributes &atttribute)
 int main()
 {
 
-    DiscoveryManager *discoveryManagerInstance =  DiscoveryManager::getInstance();
+    RCSDiscoveryManager *discoveryManagerInstance =  RCSDiscoveryManager::getInstance();
     bool cachingFlag = false;
 
     //configuring the platform
diff --git a/service/resource-encapsulation/include/RCSDiscoveryManager.h b/service/resource-encapsulation/include/RCSDiscoveryManager.h
new file mode 100644 (file)
index 0000000..2967d36
--- /dev/null
@@ -0,0 +1,93 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains the RCSDiscoveryManager class which provide API to discover the Resource in the network
+ *
+ */
+
+#ifndef RCS_DISCOVERYMANAGER_H_
+#define RCS_DISCOVERYMANAGER_H_
+
+#include "RCSRemoteResourceObject.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+
+        /*
+        * Forward Declaration of RCSAddress Class
+        */
+        class RCSAddress;
+
+        /**
+             * @class   RCSDiscoveryManager
+             * @brief   This class contains the resource discovery method.
+             *
+             */
+        class RCSDiscoveryManager
+        {
+            public:
+
+                /**
+                 *  Typedef for callback of discoverResource API
+                 */
+                typedef std::function< void( std::shared_ptr< RCSRemoteResourceObject>) >
+                OnResourceDiscoveredCallback;
+
+                /**
+                * API for getting RCSDiscoveryManager instance.
+                *
+                * @return RCSDiscoveryManager - Instance of RCSDiscoveryManager class
+                */
+                static RCSDiscoveryManager *getInstance();
+
+                /**
+                * API for discovering the resource of Interest.
+                *
+                * @param address - RCSAddress object
+                * @param resourceURI - uri of resource to be searched
+                * @param cb - callback to obtain discovered resource
+                *
+                * @throw InvalidParameterException : This API throws the InvalidParameterException if any of
+                *                                                         the parameter is invalid.
+                * @RCSAddress
+                */
+                void discoverResource(const RCSAddress &address, const std::string &resourceURI,
+                                      OnResourceDiscoveredCallback cb);
+            private:
+
+                /**
+                 * Constructor for RCSDiscoveryManager.
+                */
+                RCSDiscoveryManager() = default;
+
+                /**
+                * Destructor for RCSDiscoveryManager.
+                */
+                ~RCSDiscoveryManager() = default;
+
+        };
+    }
+}
+#endif //RCS_DISCOVERYMANAGER_H_
\ No newline at end of file
  *
  * This file contains the Resource Client APIs provided to the developers.
  * It is a common API layer for the Resource Broker and Resource Cache module of Resource
- * Encapsulation layer.
+ * Manipulation layer.
  */
 
-#ifndef RESOURCE_CLIENT_H_
-#define RESOURCE_CLIENT_H_
+#ifndef RCS_RemoteResourceObject_H
+#define RCS_RemoteResourceObject_H
 
 #include<vector>
 #include "RCSResourceAttributes.h"
@@ -36,7 +36,6 @@ namespace OIC
 {
     namespace Service
     {
-
         /**
         * Cache State enum specify the state of the Cache.
         */
@@ -65,9 +64,8 @@ namespace OIC
         * Forward Declaration of Classes
         */
         class RCSException;
-        class RemoteResourceObject;
+        class RCSRemoteResourceObject;
         class PrimitiveResource;
-        class RCSAddress;
 
         /**
          * @class  BadRequestException
@@ -91,26 +89,26 @@ namespace OIC
         {
             public:
                 InvalidParameterException(const std::string &what) : RCSException { what } {}
-                InvalidParameterException(std::string &&what) : RCSException{ std::move(what) } {}
+                InvalidParameterException(std::string &&what) : RCSException { std::move(what) } {}
         };
 
         /**
-         * @class   RemoteResourceObject
+         * @class   RCSRemoteResourceObject
          * @brief   This class is an interaction point between Resource
-         *              and the developers. Developer will get the RemoteResourceObject by calling the
-         *              discoverResource() API of "DiscoveryManager" class.
+         *              and the developers. Developer will get the RCSRemoteResourceObject by calling the
+         *              discoverResource() API of "RCSDiscoveryManager" class.
          *
          * @see DiscoveryManager
          *
          */
-        class RemoteResourceObject
+        class RCSRemoteResourceObject
         {
             public:
 
                 /**
-                 * Constructor for RemoteResourceObject
+                 * Constructor for RCSRemoteResourceObject
                 */
-                RemoteResourceObject(std::shared_ptr<PrimitiveResource>  pResource);
+                RCSRemoteResourceObject(std::shared_ptr<PrimitiveResource>  pResource);
 
                 /**
                  *  Typedef for callback of startMonitoring API
@@ -416,57 +414,7 @@ namespace OIC
                 *  Broker  identification number.
                 */
                 BrokerID m_brokerId;
-
-        };
-
-        /**
-         * @class   DiscoveryManager
-         * @brief   This class contains the resource discovery method.
-         *
-         */
-        class DiscoveryManager
-        {
-            public:
-
-                /**
-                 *  Typedef for callback of discoverResource API
-                 */
-                typedef std::function< void( std::shared_ptr< RemoteResourceObject>) >
-                OnResourceDiscoveredCallback;
-
-                /**
-                * API for getting DiscoveryManager instance.
-                *
-                * @return DiscoveryManager - Instance of DiscoveryManager class
-                */
-                static DiscoveryManager *getInstance();
-
-                /**
-                * API for discovering the resource of Interest.
-                *
-                * @param address - RCSAddress object
-                * @param resourceURI - uri of resource to be searched
-                * @param cb - callback to obtain discovered resource
-                *
-                * @throw InvalidParameterException : This API throws the InvalidParameterException if any of
-                *                                                         the parameter is invalid.
-                * @RCSAddress
-                */
-                void discoverResource(const RCSAddress &address, const std::string &resourceURI,
-                                      OnResourceDiscoveredCallback cb);
-            private:
-
-                /**
-                 * Constructor for DiscoveryManager.
-                */
-                DiscoveryManager() = default;
-
-                /**
-                * Destructor for DiscoveryManager.
-                */
-                ~DiscoveryManager() = default;
-
         };
     }
 }
-#endif //RESOURCE_CLIENT_H_
+#endif //RCS_RemoteResourceObject_H
index 5558e81..2c0464c 100644 (file)
@@ -18,8 +18,8 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#ifndef RES_MANIPULATION_RESOURCEATTRIBUTES_H
-#define RES_MANIPULATION_RESOURCEATTRIBUTES_H
+#ifndef RES_ENCAPSULATION_RESOURCEATTRIBUTES_H
+#define RES_ENCAPSULATION_RESOURCEATTRIBUTES_H
 
 // To avoid conflict using different boost::variant configuration with OC.
 // It causes compile errors.
@@ -785,4 +785,4 @@ namespace OIC
     }
 }
 
-#endif // RES_MANIPULATION_RESOURCEATTRIBUTES_H
+#endif // RES_ENCAPSULATION_RESOURCEATTRIBUTES_H
diff --git a/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp b/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp
new file mode 100644 (file)
index 0000000..986ae2b
--- /dev/null
@@ -0,0 +1,94 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "RCSDiscoveryManager.h"
+#include "PrimitiveResource.h"
+#include "logger.h"
+
+#define CLIENT_W_TAG  PCF("RCSDiscoveryManager")
+
+using namespace OIC::Service;
+
+namespace
+{
+    void findCallback(std::shared_ptr<PrimitiveResource> primitiveResource,
+                      RCSDiscoveryManager::OnResourceDiscoveredCallback OnResourceDiscovered )
+    {
+        OC_LOG(DEBUG, CLIENT_W_TAG, "findCallback entry");
+        if (nullptr == primitiveResource)
+        {
+            OC_LOG(ERROR, CLIENT_W_TAG, "findCallback::primitiveResource NULL Parameter");
+            return ;
+        }
+
+        std::shared_ptr< RCSRemoteResourceObject>  primitiveClientResource =
+            std::shared_ptr< RCSRemoteResourceObject>(new RCSRemoteResourceObject(primitiveResource));
+
+        OnResourceDiscovered(primitiveClientResource); //passing PrimitiveClientResource to application
+
+        OC_LOG(DEBUG, CLIENT_W_TAG, "findcb exit");
+    }
+}
+
+namespace OIC
+{
+    namespace Service
+    {
+        RCSDiscoveryManager *RCSDiscoveryManager:: getInstance()
+        {
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSDiscoveryManager:: getInstance entry");
+            static RCSDiscoveryManager *s_instance;
+            static std::mutex s_mutex;
+            if (!s_instance)
+            {
+                std::lock_guard<std::mutex> lock(s_mutex);
+                if (!s_instance)
+                {
+                    s_instance = new RCSDiscoveryManager();
+                }
+            }
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSDiscoveryManager:: getInstance exit");
+            return s_instance;
+        }
+
+        void RCSDiscoveryManager::discoverResource(const RCSAddress &address,
+                const std::string &resourceURI,
+                OnResourceDiscoveredCallback cb)
+        {
+
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSDiscoveryManager::discoverResource entry");
+            if ( resourceURI.empty() )
+            {
+                OC_LOG(ERROR, CLIENT_W_TAG, "discoverResource NULL resourceURI");
+                throw InvalidParameterException { "discoverResource NULL resourceURI'" };
+            }
+            else if ( !cb )
+            {
+                OC_LOG(ERROR, CLIENT_W_TAG, "discoverResource NULL Callback");
+                throw InvalidParameterException { "discoverResource NULL Callback'" };
+            }
+            OIC::Service::discoverResource(address, resourceURI, std::bind(findCallback,
+                                           std::placeholders::_1,
+                                           cb));
+
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSDiscoveryManager::discoverResource exit");
+        }
+    }
+}
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#include "ResourceClient.h"
+#include "RCSRemoteResourceObject.h"
 #include "ResourceBroker.h"
 #include "ResourceCacheManager.h"
 
-#define CLIENT_W_TAG  PCF("ResourceClient")
+#define CLIENT_W_TAG  PCF("RCSRemoteResourceObject")
 
 using namespace OIC::Service;
 
@@ -95,7 +95,7 @@ namespace
     }
 
     OCStackResult hostingCallback(BROKER_STATE state,
-                                  RemoteResourceObject::ResourceStateChangedCallback onResourceStateChanged)
+                                  RCSRemoteResourceObject::ResourceStateChangedCallback onResourceStateChanged)
     {
         OC_LOG(DEBUG, CLIENT_W_TAG, "hostingCallback entry");
 
@@ -108,86 +108,65 @@ namespace
 
     OCStackResult cachingCallback(std::shared_ptr<PrimitiveResource> resource,
                                   const RCSResourceAttributes &data,
-                                  RemoteResourceObject::CacheUpdatedCallback onCacheUpdated)
+                                  RCSRemoteResourceObject::CacheUpdatedCallback onCacheUpdated)
     {
         OC_LOG(DEBUG, CLIENT_W_TAG, "cachingCallback entry");
 
-        onCacheUpdated(data); //passing RCSResourceAttributes to application
+        onCacheUpdated(data); //passing ResourceAttributes to application
 
         OC_LOG(DEBUG, CLIENT_W_TAG, "cachingCallback exit");
         return OC_STACK_OK;
     }
 
     void setCallback(const HeaderOptions &header, const ResponseStatement &response, int n,
-                     RemoteResourceObject::RemoteAttributesSetCallback onRemoteAttributesSet)
+                     RCSRemoteResourceObject::RemoteAttributesSetCallback onRemoteAttributesSet)
     {
         OC_LOG(DEBUG, CLIENT_W_TAG, "setCallback entry");
 
         const RCSResourceAttributes &attributes = response.getAttributes();
-        onRemoteAttributesSet(attributes); //passing RCSResourceAttributes to application
+        onRemoteAttributesSet(attributes); //passing ResourceAttributes to application
 
         OC_LOG(DEBUG, CLIENT_W_TAG, "setCallback exit");
     }
 
     void getCallback(const HeaderOptions &headerOption, const ResponseStatement &response, int n,
-                     RemoteResourceObject::RemoteAttributesReceivedCallback onRemoteAttributesReceived)
+                     RCSRemoteResourceObject::RemoteAttributesReceivedCallback onRemoteAttributesReceived)
     {
         OC_LOG(DEBUG, CLIENT_W_TAG, "getCallback entry");
 
         const RCSResourceAttributes &attributes = response.getAttributes();
-        onRemoteAttributesReceived(attributes); //passing RCSResourceAttributes to application
+        onRemoteAttributesReceived(attributes); //passing ResourceAttributes to application
 
         OC_LOG(DEBUG, CLIENT_W_TAG, "getCallback exit");
     }
-
-    void findCallback(std::shared_ptr<PrimitiveResource> primitiveResource,
-                      DiscoveryManager::OnResourceDiscoveredCallback OnResourceDiscovered )
-    {
-        OC_LOG(DEBUG, CLIENT_W_TAG, "findCallback entry");
-
-        if (nullptr == primitiveResource)
-        {
-            OC_LOG(ERROR, CLIENT_W_TAG, "findCallback::primitiveResource NULL Parameter");
-            return ;
-        }
-
-        std::shared_ptr< RemoteResourceObject>  primitiveClientResource =
-            std::shared_ptr< RemoteResourceObject>(new RemoteResourceObject(primitiveResource));
-
-        OnResourceDiscovered(primitiveClientResource); //passing PrimitiveClientResource to application
-
-        OC_LOG(DEBUG, CLIENT_W_TAG, "findcb exit");
-    }
-
 }
 
-//*******************************Primitive Client Resource*************************************
+//******************************* RCSRemoteResourceObject *************************************
 
 namespace OIC
 {
     namespace Service
     {
-
-        RemoteResourceObject:: RemoteResourceObject(std::shared_ptr<PrimitiveResource>  pResource) :
+        RCSRemoteResourceObject:: RCSRemoteResourceObject(std::shared_ptr<PrimitiveResource>  pResource) :
             m_monitoringFlag(false), m_cachingFlag(false),  m_observableFlag(pResource->isObservable()),
             m_primitiveResource(pResource), m_cacheId(0), m_brokerId(0) {}
 
-        bool RemoteResourceObject::isMonitoring() const
+        bool RCSRemoteResourceObject::isMonitoring() const
         {
             return m_monitoringFlag;
         }
 
-        bool RemoteResourceObject::isCaching() const
+        bool RCSRemoteResourceObject::isCaching() const
         {
             return m_cachingFlag;
         }
 
-        void RemoteResourceObject::startMonitoring(ResourceStateChangedCallback cb)
+        void RCSRemoteResourceObject::startMonitoring(ResourceStateChangedCallback cb)
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startMonitoring entry");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::startMonitoring entry");
             if (true == m_monitoringFlag)
             {
-                OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startMonitoring : Already started");
+                OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::startMonitoring : Already started");
             }
             else
             {
@@ -204,12 +183,12 @@ namespace OIC
                     throw InvalidParameterException {exception.what()};
                 }
             }
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startMonitoring exit");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::startMonitoring exit");
         }
 
-        void RemoteResourceObject::stopMonitoring()
+        void RCSRemoteResourceObject::stopMonitoring()
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopMonitoring entry");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::stopMonitoring entry");
             if (true == m_monitoringFlag)
             {
                 try
@@ -219,62 +198,62 @@ namespace OIC
                 }
                 catch (std::exception &exception)
                 {
-                    OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopMonitoring InvalidParameterException");
+                    OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::stopMonitoring InvalidParameterException");
                 }
             }
             else
             {
-                OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject:: stopMonitoring : already terminated");
+                OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject:: stopMonitoring : already terminated");
             }
 
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopMonitoring exit");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::stopMonitoring exit");
         }
 
-        ResourceState RemoteResourceObject::getState() const
+        ResourceState RCSRemoteResourceObject::getState() const
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, " RemoteResourceObject::getState entry");
+            OC_LOG(DEBUG, CLIENT_W_TAG, " RCSRemoteResourceObject::getState entry");
             try
             {
                 BROKER_STATE brokerState = ResourceBroker::getInstance()->getResourceState(m_primitiveResource);
-                OC_LOG(DEBUG, CLIENT_W_TAG, " RemoteResourceObject::getState exit");
+                OC_LOG(DEBUG, CLIENT_W_TAG, " RCSRemoteResourceObject::getState exit");
                 return getResourceStateFromBrokerState(brokerState);
             }
             catch (std::exception &exception)
             {
-                OC_LOG(DEBUG, CLIENT_W_TAG, " RemoteResourceObject::getState InvalidParameterException");
+                OC_LOG(DEBUG, CLIENT_W_TAG, " RCSRemoteResourceObject::getState InvalidParameterException");
                 throw BadRequestException { "[getState] Get Resource Source State from Broker Error " };
             }
         }
 
-        void RemoteResourceObject::startCaching()
+        void RCSRemoteResourceObject::startCaching()
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching entry");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::startCaching entry");
             if (true == m_cachingFlag)
             {
-                OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching : already Started");
+                OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::startCaching : already Started");
             }
             else
             {
                 try
                 {
-                  CacheID cacheId = ResourceCacheManager::getInstance()->requestResourceCache(m_primitiveResource,
+                    CacheID cacheId = ResourceCacheManager::getInstance()->requestResourceCache(m_primitiveResource,
                                       NULL, REPORT_FREQUENCY::NONE,  0);
 
                     m_cacheId = cacheId;
                     m_cachingFlag = true;
-                    OC_LOG_V(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching CACHE ID %d", cacheId);
+                    OC_LOG_V(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::startCaching CACHE ID %d", cacheId);
                 }
                 catch (std::exception &exception)
                 {
-                    OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching InvalidParameterException");
+                    OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::startCaching InvalidParameterException");
                 }
             }
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching exit");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::startCaching exit");
         }
 
-        void RemoteResourceObject::startCaching(CacheUpdatedCallback cb)
+        void RCSRemoteResourceObject::startCaching(CacheUpdatedCallback cb)
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching entry");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::startCaching entry");
             if (!cb)
             {
                 throw InvalidParameterException {"startCaching : Callback is NULL" };
@@ -305,9 +284,9 @@ namespace OIC
             }
         }
 
-        void RemoteResourceObject::stopCaching()
+        void RCSRemoteResourceObject::stopCaching()
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopCaching entry");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::stopCaching entry");
 
             if (true == m_cachingFlag)
             {
@@ -318,38 +297,38 @@ namespace OIC
                 }
                 catch (std::exception &exception)
                 {
-                    OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopCaching InvalidParameterException");
+                    OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::stopCaching InvalidParameterException");
                 }
             }
             else
             {
-                OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject:: Caching already terminated");
+                OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject:: Caching already terminated");
             }
 
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::stopCaching exit");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::stopCaching exit");
         }
 
-        CacheState  RemoteResourceObject::getResourceCacheState()
+        CacheState  RCSRemoteResourceObject::getResourceCacheState()
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getResourceCacheState entry");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::getResourceCacheState entry");
             try
             {
                 CACHE_STATE cacheState = ResourceCacheManager::getInstance()->getResourceCacheState(
                                              m_primitiveResource);
-                OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getResourceCacheState exit");
+                OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::getResourceCacheState exit");
                 return getCacheState(cacheState);
             }
             catch (std::exception &exception)
             {
                 OC_LOG(DEBUG, CLIENT_W_TAG,
-                       "RemoteResourceObject::getResourceCacheState InvalidParameterException");
+                       "RCSRemoteResourceObject::getResourceCacheState InvalidParameterException");
                 throw BadRequestException { "[getResourceCacheState] Caching not started" };
             }
         }
 
-        void RemoteResourceObject::refreshCache()
+        void RCSRemoteResourceObject::refreshCache()
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::refreshCache entry");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::refreshCache entry");
             try
             {
 
@@ -358,14 +337,14 @@ namespace OIC
             }
             catch (std::exception &exception)
             {
-                OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::refreshCache InvalidParameterException");
+                OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::refreshCache InvalidParameterException");
             }
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::refreshCache exit");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject::refreshCache exit");
         }
 
-        RCSResourceAttributes RemoteResourceObject:: getCachedAttributes() const
+        RCSResourceAttributes RCSRemoteResourceObject:: getCachedAttributes() const
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject :: getCachedAttributes ");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject :: getCachedAttributes ");
             try
             {
                 return ResourceCacheManager::getInstance()->getCachedData(m_primitiveResource);
@@ -376,43 +355,43 @@ namespace OIC
             }
         }
 
-        RCSResourceAttributes::Value  RemoteResourceObject:: getCachedAttribute( const std::string &key)
+        RCSResourceAttributes::Value  RCSRemoteResourceObject:: getCachedAttribute( const std::string &key)
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject :: getCachedAttribute entry");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject :: getCachedAttribute entry");
             try
             {
                 RCSResourceAttributes  Cachedattributes = ResourceCacheManager::getInstance()->getCachedData(
-                        m_primitiveResource);
+                            m_primitiveResource);
                 return Cachedattributes[key];
             }
             catch (std::exception &exception)
             {
                 throw BadRequestException { "[getCachedAttribute]  Caching not started" };
             }
-            OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject :: getCachedAttribute exit");
+            OC_LOG(DEBUG, CLIENT_W_TAG, "RCSRemoteResourceObject :: getCachedAttribute exit");
         }
 
-        std::string RemoteResourceObject::getUri() const
+        std::string RCSRemoteResourceObject::getUri() const
         {
             return m_primitiveResource->getUri();
         }
 
-        std::string RemoteResourceObject::getAddress() const
+        std::string RCSRemoteResourceObject::getAddress() const
         {
             return m_primitiveResource->getHost();
         }
 
-        std::vector < std::string > RemoteResourceObject::getTypes() const
+        std::vector < std::string > RCSRemoteResourceObject::getTypes() const
         {
             return m_primitiveResource->getTypes();
         }
 
-        std::vector < std::string > RemoteResourceObject::getInterfaces() const
+        std::vector < std::string > RCSRemoteResourceObject::getInterfaces() const
         {
             return m_primitiveResource->getInterfaces();
         }
 
-        void RemoteResourceObject::getRemoteAttributes(RemoteAttributesReceivedCallback cb)
+        void RCSRemoteResourceObject::getRemoteAttributes(RemoteAttributesReceivedCallback cb)
         {
             OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getRemoteAttributes entry");
             if (!cb)
@@ -427,7 +406,7 @@ namespace OIC
             OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getRemoteAttributes exit");
         }
 
-        void RemoteResourceObject::setRemoteAttributes(const RCSResourceAttributes &attribute,
+        void RCSRemoteResourceObject::setRemoteAttributes(const RCSResourceAttributes &attribute,
                 RemoteAttributesSetCallback cb)
         {
             OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::setRemoteAttributes entry");
@@ -443,51 +422,10 @@ namespace OIC
             OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::setRemoteAttributes exit");
         }
 
-        bool RemoteResourceObject::isObservable() const
-        {
-            return m_observableFlag;
-        }
-
-//*******************************Discovery Manager****************************************
 
-        DiscoveryManager *DiscoveryManager:: getInstance()
+        bool RCSRemoteResourceObject::isObservable() const
         {
-            OC_LOG(DEBUG, CLIENT_W_TAG, "DiscoveryManager:: getInstance entry");
-            static DiscoveryManager *s_instance;
-            static std::mutex s_mutex;
-            if (!s_instance)
-            {
-                std::lock_guard<std::mutex> lock(s_mutex);
-                if (!s_instance)
-                {
-                    s_instance = new DiscoveryManager();
-                }
-            }
-            OC_LOG(DEBUG, CLIENT_W_TAG, "DiscoveryManager:: getInstance exit");
-            return s_instance;
-        }
-
-        void DiscoveryManager::discoverResource(const RCSAddress &address, const std::string &resourceURI,
-                                                OnResourceDiscoveredCallback cb)
-        {
-
-            OC_LOG(DEBUG, CLIENT_W_TAG, "DiscoveryManager::discoverResource entry");
-
-            if ( resourceURI.empty() )
-            {
-                OC_LOG(ERROR, CLIENT_W_TAG, "discoverResource NULL resourceURI");
-                throw InvalidParameterException { "discoverResource NULL resourceURI'" };
-            }
-            else if ( !cb )
-            {
-                OC_LOG(ERROR, CLIENT_W_TAG, "discoverResource NULL Callback");
-                throw InvalidParameterException { "discoverResource NULL Callback'" };
-            }
-            OIC::Service::discoverResource(address, resourceURI, std::bind(findCallback,
-                                           std::placeholders::_1,
-                                           cb));
-
-            OC_LOG(DEBUG, CLIENT_W_TAG, "DiscoveryManager::discoverResource exit");
+            return m_observableFlag;
         }
     }
 }
index e66f286..430f5e6 100644 (file)
@@ -1,7 +1,8 @@
 #define private public
 #include <gtest/gtest.h>
 #include <iostream>
-#include "ResourceClient.h"
+#include "RCSDiscoveryManager.h"
+#include "RCSRemoteResourceObject.h"
 #include "RCSResourceObject.h"
 #include "OCPlatform.h"
 #include "RCSAddress.h"
@@ -15,8 +16,8 @@ using namespace OC;
 
 bool cbresult = false;
 std::string uri = "/oic/res?rt=Resource.Hosting";
-std::shared_ptr<RemoteResourceObject> object;
-DiscoveryManager *manager = DiscoveryManager::getInstance();
+std::shared_ptr<RCSRemoteResourceObject> object;
+RCSDiscoveryManager*manager = RCSDiscoveryManager::getInstance();
 ResourceState receivedResourceState;
 RCSResourceAttributes receivedResourceAttributes;
 RCSResourceObject::Ptr server;
@@ -46,7 +47,7 @@ void onRemoteAttrReceived(const RCSResourceAttributes &attributes)
     receivedResourceAttributes = attributes;
 }
 
-void onResourceDiscoveredCallback(std::shared_ptr<RemoteResourceObject> receivedObject)
+void onResourceDiscoveredCallback(std::shared_ptr<RCSRemoteResourceObject> receivedObject)
 {
     std::cout << "Resource discovered" << std::endl;
     object = receivedObject;
@@ -74,7 +75,7 @@ void OnRemoteAttributesSetCallback(const RCSResourceAttributes &attributes)
 TEST(ResourceClientTest, testDiscoverResourcePass)
 {
     createResource();
-    DiscoveryManager *instance = DiscoveryManager::getInstance();
+    RCSDiscoveryManager *instance = RCSDiscoveryManager::getInstance();
     cbresult = false;
     RCSAddress rcsAddress = RCSAddress::multicast();
     instance->discoverResource(rcsAddress, uri , &onResourceDiscoveredCallback);
@@ -126,7 +127,7 @@ TEST(ResourceClientTest, testIsMonitoring)
 {
     createResource();
     RCSAddress rcsAddress = RCSAddress::multicast();
-    manager->DiscoveryManager::discoverResource(rcsAddress, uri , &onResourceDiscoveredCallback);
+    manager->RCSDiscoveryManager::discoverResource(rcsAddress, uri , &onResourceDiscoveredCallback);
     sleep(1);
     destroyResource();
     EXPECT_FALSE(object->isMonitoring());
@@ -320,7 +321,7 @@ TEST(ResourceClientTest, testGetCachedAttribute)
 TEST(ResourceClientTest, testGetInstance)
 {
     createResource();
-    DiscoveryManager *instance = DiscoveryManager::getInstance();
+    RCSDiscoveryManager *instance = RCSDiscoveryManager::getInstance();
     EXPECT_TRUE(instance != NULL);
     destroyResource();
 }
@@ -329,7 +330,7 @@ TEST(ResourceClientTest, testGetInstance)
 TEST(ResourceClientTest, testDiscoverResourceEmptyResource)
 {
     createResource();
-    DiscoveryManager *instance = DiscoveryManager::getInstance();
+    RCSDiscoveryManager *instance = RCSDiscoveryManager::getInstance();
     RCSAddress rcsAddress = RCSAddress::multicast();
     EXPECT_THROW(instance->discoverResource(rcsAddress, "", &onResourceDiscoveredCallback),
                  InvalidParameterException);
@@ -340,7 +341,7 @@ TEST(ResourceClientTest, testDiscoverResourceEmptyResource)
 TEST(ResourceClientTest, testDiscoverResourceEmptyCallback)
 {
     createResource();
-    DiscoveryManager *instance = DiscoveryManager::getInstance();
+    RCSDiscoveryManager *instance = RCSDiscoveryManager::getInstance();
     RCSAddress rcsAddress = RCSAddress::multicast();
     EXPECT_THROW(instance->discoverResource(rcsAddress, uri , NULL), InvalidParameterException);
     destroyResource();