Delete 'auto cancel' logic for discovery task and modify comments in discovery manager.
authorChaJiwon <jw_wonny.cha@samsung.com>
Fri, 2 Oct 2015 06:12:01 +0000 (15:12 +0900)
committerUze Choi <uzchoi@samsung.com>
Sat, 3 Oct 2015 04:15:56 +0000 (04:15 +0000)
- DiscoveryTask destructor is changed default destructor
- modify comments in RCSDiscoveryManager and RCSDiscoveryManagerImpl

Change-Id: I3acd4ebbd65404192ab4eabf277a8dcb94af1b06
Signed-off-by: ChaJiwon <jw_wonny.cha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3353
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-encapsulation/include/RCSDiscoveryManager.h
service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp
service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.cpp
service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.h

index 29fc919ab4a3c51c78e8ebdf26ff015fcbeba782..31feefcbeb4f3f6dc5825f77059ec94c10ed6cb4 100644 (file)
@@ -26,8 +26,8 @@
  *
  */
 
-#ifndef RCSDISCOVERYMANAGER_H
-#define RCSDISCOVERYMANAGER_H
+#ifndef RCS_DISCOVERYMANAGER_H_
+#define RCS_DISCOVERYMANAGER_H_
 
 #include <memory>
 #include <functional>
@@ -36,9 +36,8 @@ namespace OIC
 {
     namespace Service
     {
-        class RCSRemoteResourceObject;
         class RCSAddress;
-
+        class RCSRemoteResourceObject;
         /**
          * This class contains the resource discovery methods.
          *
@@ -46,143 +45,128 @@ namespace OIC
          */
         class RCSDiscoveryManager
         {
-            public:
+        public:
 
             /**
              * This class represents a discovery task.
              *
-             * @note A discovery task will be automatically canceled when destroyed.
              */
-                class DiscoveryTask
-                {
-                    public:
-                        typedef std::unique_ptr<DiscoveryTask> Ptr;
+            class DiscoveryTask
+            {
+            public:
+                typedef std::unique_ptr< DiscoveryTask > Ptr;
 
-                        ~DiscoveryTask();
+                ~DiscoveryTask() = default;
 
-                        DiscoveryTask(const DiscoveryTask&) = delete;
-                        DiscoveryTask(DiscoveryTask&&) = delete;
-                        DiscoveryTask& operator = (const DiscoveryTask&) const = delete;
-                        DiscoveryTask& operator = (DiscoveryTask&&) const = delete;
+                DiscoveryTask(const DiscoveryTask&) = delete;
+                DiscoveryTask(DiscoveryTask&&) = delete;
+                DiscoveryTask& operator =(const DiscoveryTask&) const = delete;
+                DiscoveryTask& operator =(DiscoveryTask&&) const = delete;
 
-                        /**
-                         * Cancel the task for discovery request. If cancel is called in duplicate, the request is ignored.
-                         */
-                        void cancel();
+                /**
+                 * It is cancelling the task of discovery.
+                 * If it is already canceled, the operation is ignored.
+                 */
+                void cancel();
 
-                        /**
-                         * Return a boolean value whether the discovery request is canceled or not.
-                         */
-                        bool isCanceled();
+                /**
+                 * Returns whether the discovery request is canceled or not.
+                 */
+                bool isCanceled();
 
-                    private:
-                        explicit DiscoveryTask(unsigned int);
+            private:
+                explicit DiscoveryTask(unsigned int);
 
-                    private:
-                        unsigned int m_id;
-                        friend class RCSDiscoveryManagerImpl;
-                };
+            private:
+                unsigned int m_id;
 
-            public:
+                friend class RCSDiscoveryManagerImpl;
+            };
 
-                /**
-                 * Typedef for callback of discoverResource APIs
-                 *
-                 * @see discoverResource
-                 */
-                typedef std::function< void(std::shared_ptr< RCSRemoteResourceObject >) >
-                                       ResourceDiscoveredCallback;
+        public:
 
-                /**
-                 * @return RCSDiscoveryManager instance.
-                 *
-                 */
-                static RCSDiscoveryManager* getInstance();
+            /**
+             * Typedef for callback of discoverResource APIs
+             *
+             * @see discoverResource
+             */
+            typedef std::function< void(std::shared_ptr< RCSRemoteResourceObject >)
+                    > ResourceDiscoveredCallback;
 
-                /**
-                 * Discovering the resource of interest, regardless of uri and resource type.
-                 * Find resource matching request periodically until returned resource is disappeared or destroyed.
-                 *
-                 * @return Returned object must be received.
-                 *
-                 * @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.
-                 *
-                 */
-                DiscoveryTask::Ptr discoverResource(const RCSAddress& address,
-                        ResourceDiscoveredCallback cb);
+            /**
+             * @return RCSDiscoveryManager instance.
+             *
+             */
+            static RCSDiscoveryManager* getInstance();
 
-                /**
-                 * Discovering the resource of Interest, regardless of resource type.
-                 * Find resource matching request periodically until returned resource is disappeared or destroyed.
-                 *
-                 * @return Returned object must be received.
-                 *
-                 * @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
-                 *
-                 */
-                DiscoveryTask::Ptr discoverResource(const RCSAddress& address,
-                        const std::string& relativeURI, ResourceDiscoveredCallback cb);
+            /**
+             * Discovers resources of interest, regardless of uri and resource type.
+             * It is Consistently discovering resources until the discovery task is canceled.
+             *
+             * @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.
+             *
+             */
+            DiscoveryTask::Ptr discoverResource(const RCSAddress& address,
+                    ResourceDiscoveredCallback cb);
 
-                /**
-                 * Discovering the resource of Interest by Resource type.
-                 * Find resource matching request periodically until returned resource is disappeared or destroyed.
-                 *
-                 * @return Returned object must be received.
-                 *
-                 * @param address          A RCSAddress object
-                 * @param resourceType     Resource 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
-                 *
-                 */
-                DiscoveryTask::Ptr discoverResourceByType(const RCSAddress& address,
-                        const std::string& resourceType, ResourceDiscoveredCallback cb);
+            /**
+             * Discovers resources of interest, regardless of resource type.
+             * It is Consistently discovering resources until the discovery task is canceled.
+             *
+             * @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.
+             *
+             */
+            DiscoveryTask::Ptr discoverResource(const RCSAddress& address,
+                    const std::string& relativeUri, ResourceDiscoveredCallback cb);
 
-                /**
-                 * Discovering the resource of Interest by Resource type with provided relativeURI.
-                 * Find resource matching request periodically until returned resource is disappeared or destroyed.
-                 *
-                 * @return Returned object must be received.
-                 *
-                 * @param address          A RCSAddress object
-                 * @param relativeURI      The relative uri of resource to be searched
-                 * @param resourceType     Resource 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
-                 *
-                 */
-                DiscoveryTask::Ptr discoverResourceByType(const RCSAddress& address,
-                        const std::string& relativeURI, const std::string& resourceType,
-                        ResourceDiscoveredCallback cb);
+            /**
+             * Discovers resources of interest by resource type.
+             * It is Consistently discovering resources until the discovery task is canceled.
+             *
+             * @param address          A RCSAddress object
+             * @param resourceType     Resource 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.
+             *
+             */
+            DiscoveryTask::Ptr discoverResourceByType(const RCSAddress& address,
+                    const std::string& resourceType, ResourceDiscoveredCallback cb);
 
-            private:
-                RCSDiscoveryManager() = default;
-                ~RCSDiscoveryManager()= default;
+            /**
+             * Discovers resources of interest by resource type with provided relativeUri.
+             * It is Consistently discovering resources until the discovery task is canceled.
+             *
+             * @param address          A RCSAddress object
+             * @param relativeUri      The relative uri of resource to be searched
+             * @param resourceType     Resource 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.
+             *
+             */
+            DiscoveryTask::Ptr discoverResourceByType(const RCSAddress& address,
+                    const std::string& relativeUri, const std::string& resourceType,
+                    ResourceDiscoveredCallback cb);
 
-                friend class DiscoveryTask;
+        private:
+            RCSDiscoveryManager() = default;
+            ~RCSDiscoveryManager() = default;
         };
     }
 }
index 62b16b7500c7f18f52bea9b450860f81d65d0986..328a964937c34633e211417f707057552a43e277 100755 (executable)
 #include "RCSDiscoveryManager.h"
 #include "RCSDiscoveryManagerImpl.h"
 
-#define TAG "RCSDiscoveryManager"
-
-namespace OIC {
-    namespace Service {
-
+namespace OIC
+{
+    namespace Service
+    {
         RCSDiscoveryManager::DiscoveryTask::DiscoveryTask(unsigned int id) :
-                m_id{ id }
+                m_id { id }
         {
         }
 
-        RCSDiscoveryManager::DiscoveryTask::~DiscoveryTask()
-        {
-            cancel();
-        }
-
         bool RCSDiscoveryManager::DiscoveryTask::isCanceled()
         {
             return RCSDiscoveryManagerImpl::getInstance()->isCanceled(m_id);
@@ -45,34 +39,40 @@ namespace OIC {
             RCSDiscoveryManagerImpl::getInstance()->cancel(m_id);
         }
 
-        RCSDiscoveryManager* RCSDiscoveryManager::getInstance() {
+        RCSDiscoveryManager* RCSDiscoveryManager::getInstance()
+        {
             static RCSDiscoveryManager instance;
             return &instance;
         }
 
-        std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> RCSDiscoveryManager::discoverResource
-        (const RCSAddress& address, ResourceDiscoveredCallback cb) {
-            return discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, "",
-                    std::move(cb));
+        RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManager::discoverResource(
+                const RCSAddress& address, ResourceDiscoveredCallback cb)
+        {
+            return discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, "", std::move(cb));
         }
 
-        std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> RCSDiscoveryManager::discoverResource
-        (const RCSAddress& address, const std::string& relativeURI, ResourceDiscoveredCallback cb) {
-            return discoverResourceByType(address, relativeURI, "", std::move(cb));
+        RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManager::discoverResource(
+                const RCSAddress& address, const std::string& relativeUri,
+                ResourceDiscoveredCallback cb)
+        {
+            return discoverResourceByType(address, relativeUri, "", std::move(cb));
         }
 
-        std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> RCSDiscoveryManager::discoverResourceByType(
-                const RCSAddress& address, const std::string& resourceType, ResourceDiscoveredCallback cb) {
-            return discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI,
-                    resourceType, std::move(cb));
+        RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManager::discoverResourceByType(
+                const RCSAddress& address, const std::string& resourceType,
+                ResourceDiscoveredCallback cb)
+        {
+            return discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, resourceType,
+                    std::move(cb));
         }
 
-        std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> RCSDiscoveryManager::discoverResourceByType(
-                const RCSAddress& address, const std::string& relativeURI,
-                const std::string& resourceType, ResourceDiscoveredCallback cb) {
-           return RCSDiscoveryManagerImpl::getInstance()->startDiscovery(address,
-                   relativeURI.empty() ? OC_RSRVD_WELL_KNOWN_URI : relativeURI,
-                   resourceType, std::move(cb));
+        RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManager::discoverResourceByType(
+                const RCSAddress& address, const std::string& relativeUri,
+                const std::string& resourceType, ResourceDiscoveredCallback cb)
+        {
+            return RCSDiscoveryManagerImpl::getInstance()->startDiscovery(address,
+                    relativeUri.empty() ? OC_RSRVD_WELL_KNOWN_URI : relativeUri, resourceType,
+                    std::move(cb));
         }
     }
 }
index 6dec04283d2fa8c0c8225f3883b50c039a22edce..70114ce4bb29de9abcff88bb7811eda2e237f1b0 100755 (executable)
@@ -17,8 +17,6 @@
 // limitations under the License.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include <limits>
-
 #include "RCSDiscoveryManagerImpl.h"
 
 #include "OCPlatform.h"
@@ -28,8 +26,7 @@
 
 namespace
 {
-    constexpr unsigned int LIMITNUMBER = std::numeric_limits<unsigned int>::max();
-    constexpr unsigned int INTERVALTIME = 60000;
+    constexpr unsigned int POLLING_INTERVAL_TIME = 60000;
 }
 
 namespace OIC
@@ -38,9 +35,9 @@ namespace OIC
     {
         RCSDiscoveryManagerImpl::RCSDiscoveryManagerImpl()
         {
-            srand(time(NULL));
+            srand (time(NULL));
             requestMulticastPresence();
-            m_timer.post(INTERVALTIME, std::bind(&RCSDiscoveryManagerImpl::onPolling, this));
+            m_timer.post(POLLING_INTERVAL_TIME, std::bind(&RCSDiscoveryManagerImpl::onPolling, this));
         }
 
         RCSDiscoveryManagerImpl* RCSDiscoveryManagerImpl::getInstance()
@@ -49,23 +46,23 @@ namespace OIC
             return &instance;
         }
 
-        void RCSDiscoveryManagerImpl::onResourceFound(std::shared_ptr< PrimitiveResource > resource,
-                    RCSDiscoveryManagerImpl::ID discoveryId,
-                    const RCSDiscoveryManager::ResourceDiscoveredCallback& discoverCB)
+        void RCSDiscoveryManagerImpl::onResourceFound(std::shared_ptr<PrimitiveResource> resource,
+                RCSDiscoveryManagerImpl::ID discoveryId,
+                const RCSDiscoveryManager::ResourceDiscoveredCallback& discoverCB)
         {
             {
-                std::lock_guard<std::mutex> lock(m_mutex);
+                std::lock_guard < std::mutex > lock(m_mutex);
                 auto it = m_discoveryMap.find(discoveryId);
 
-                if(it == m_discoveryMap.end()) return;
-                if(it->second.isKnownResource(resource)) return;
+                if (it == m_discoveryMap.end()) return;
+                if (it->second.isKnownResource(resource)) return;
             }
-            discoverCB(std::make_shared<RCSRemoteResourceObject>(resource));
+            discoverCB(std::make_shared < RCSRemoteResourceObject > (resource));
         }
 
-        RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManagerImpl::startDiscovery
-                (const RCSAddress& address, const std::string& relativeUri, const std::string& resourceType,
-                        RCSDiscoveryManager::ResourceDiscoveredCallback cb)
+        RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManagerImpl::startDiscovery(
+                const RCSAddress& address, const std::string& relativeUri,
+                const std::string& resourceType, RCSDiscoveryManager::ResourceDiscoveredCallback cb)
         {
             if (!cb)
             {
@@ -75,102 +72,107 @@ namespace OIC
             ID discoveryId = createId();
             auto discoverCb = std::bind(&RCSDiscoveryManagerImpl::onResourceFound, this,
                     std::placeholders::_1, discoveryId, std::move(cb));
-            DiscoveryRequestInfo discoveryItem(RCSAddressDetail::getDetail(address)->getAddress(), relativeUri,
-                    resourceType, std::move(discoverCb));
-            discoveryItem.discoverRequest();
+            DiscoveryRequestInfo discoveryInfo(RCSAddressDetail::getDetail(address)->getAddress(),
+                    relativeUri, resourceType, std::move(discoverCb));
+            discoveryInfo.discover();
 
-            std::lock_guard<std::mutex> lock(m_mutex);
-            m_discoveryMap.insert(std::make_pair(discoveryId, std::move(discoveryItem)));
+            {
+                std::lock_guard < std::mutex > lock(m_mutex);
+                m_discoveryMap.insert(std::make_pair(discoveryId, std::move(discoveryInfo)));
+            }
 
-            return std::unique_ptr<RCSDiscoveryManager::DiscoveryTask>(
+            return std::unique_ptr < RCSDiscoveryManager::DiscoveryTask> (
                     new RCSDiscoveryManager::DiscoveryTask(discoveryId));
         }
 
         void RCSDiscoveryManagerImpl::requestMulticastPresence()
         {
-            static constexpr char MULTICAST_PRESENCE_ADDRESS[] = "coap://" OC_MULTICAST_PREFIX;
+            constexpr char MULTICAST_PRESENCE_ADDRESS[] = "coap://" OC_MULTICAST_PREFIX;
             OCDoHandle presenceHandle;
-            subscribePresence(presenceHandle, MULTICAST_PRESENCE_ADDRESS, OCConnectivityType::CT_DEFAULT,
+            subscribePresence(presenceHandle, MULTICAST_PRESENCE_ADDRESS,
+                    OCConnectivityType::CT_DEFAULT,
                     std::move(std::bind(&RCSDiscoveryManagerImpl::onPresence, this,
-                            std::placeholders::_1, std::placeholders::_2,std::placeholders::_3)));
+                            std::placeholders::_1, std::placeholders::_2,
+                            std::placeholders::_3)));
         }
 
         void RCSDiscoveryManagerImpl::onPolling()
         {
-            std::lock_guard<std::mutex> lock(m_mutex);
+            std::lock_guard < std::mutex > lock(m_mutex);
 
-            for(const auto& it : m_discoveryMap)
+            for (const auto& it : m_discoveryMap)
             {
-                it.second.discoverRequest();
+                it.second.discover();
             }
-            m_timer.post(INTERVALTIME, std::bind(&RCSDiscoveryManagerImpl::onPolling, this));
+            m_timer.post(POLLING_INTERVAL_TIME, std::bind(&RCSDiscoveryManagerImpl::onPolling, this));
         }
 
-        void RCSDiscoveryManagerImpl::onPresence(OCStackResult ret,
-                const unsigned int /*seq*/, const std::string& address)
+        void RCSDiscoveryManagerImpl::onPresence(OCStackResult ret, const unsigned int /*seq*/,
+                const std::string& address)
         {
-            if(ret != OC_STACK_OK && ret != OC_STACK_RESOURCE_CREATED) return;
+            if (ret != OC_STACK_OK && ret != OC_STACK_RESOURCE_CREATED) return;
 
-            std::lock_guard<std::mutex> lock(m_mutex);
-            for(const auto& it : m_discoveryMap)
+            std::lock_guard < std::mutex > lock(m_mutex);
+            for (const auto& it : m_discoveryMap)
             {
-                if(it.second.isMatchingAddress(address))
+                if (it.second.isMatchingAddress(address))
                 {
-                    it.second.discoverRequest();
+                    it.second.discover();
                 }
             }
         }
 
         RCSDiscoveryManagerImpl::ID RCSDiscoveryManagerImpl::createId()
         {
-            std::lock_guard<std::mutex> lock(m_mutex);
-            static unsigned int s_uniqueId;
+            std::lock_guard < std::mutex > lock(m_mutex);
+            static ID s_uniqueId;
 
-            if(m_discoveryMap.size() >= LIMITNUMBER)
-            {
-                throw RCSException { "Discovery request is full!" };
-            }
             s_uniqueId++;
-            while(m_discoveryMap.find(s_uniqueId) != m_discoveryMap.end())
+            while (m_discoveryMap.find(s_uniqueId) != m_discoveryMap.end())
             {
                 s_uniqueId++;
             }
             return s_uniqueId;
         }
 
-        void RCSDiscoveryManagerImpl::cancel(unsigned int id)
+        void RCSDiscoveryManagerImpl::cancel(ID id)
         {
-            std::lock_guard<std::mutex> lock(m_mutex);
+            std::lock_guard < std::mutex > lock(m_mutex);
             m_discoveryMap.erase(id);
         }
 
-        bool RCSDiscoveryManagerImpl::isCanceled(unsigned int id)
+        bool RCSDiscoveryManagerImpl::isCanceled(ID id)
         {
-            std::lock_guard<std::mutex> lock(m_mutex);
+            std::lock_guard < std::mutex > lock(m_mutex);
             auto it = m_discoveryMap.find(id);
-            if(it == m_discoveryMap.end()) return true;
+            if (it == m_discoveryMap.end()) return true;
 
             return false;
         }
 
-        DiscoveryRequestInfo::DiscoveryRequestInfo(const std::string &address, const std::string &relativeUri,
-                const std::string &resourceType, DiscoverCallback cb) : m_address(address),
-                        m_relativeUri(relativeUri), m_resourceType(resourceType), m_discoverCB(cb) {}
+        DiscoveryRequestInfo::DiscoveryRequestInfo(const std::string &address,
+                const std::string &relativeUri, const std::string &resourceType,
+                DiscoverCallback cb) :
+                m_address(address), m_relativeUri(relativeUri), m_resourceType(resourceType),
+                m_discoverCb(std::move(cb))
+        {
+        }
 
-        void DiscoveryRequestInfo::discoverRequest() const
+        void DiscoveryRequestInfo::discover() const
         {
             OIC::Service::discoverResource(m_address, m_relativeUri + "?rt=" + m_resourceType,
-                    OCConnectivityType::CT_DEFAULT, m_discoverCB);
+                    OCConnectivityType::CT_DEFAULT, m_discoverCb);
         }
 
-        bool DiscoveryRequestInfo::isKnownResource(const std::shared_ptr<PrimitiveResource>& resource)
+        bool DiscoveryRequestInfo::isKnownResource(
+                const std::shared_ptr<PrimitiveResource>& resource)
         {
             std::string resourceId = resource->getSid() + resource->getUri();
 
             auto it = std::find(m_receivedIds.begin(), m_receivedIds.end(), resourceId);
 
-            if(it != m_receivedIds.end()) return true;
-            m_receivedIds.push_back(resourceId);
+            if (it != m_receivedIds.end()) return true;
+            m_receivedIds.insert(resourceId);
             return false;
         }
 
index 5f3dabc0021be1626b56ce79385745b9dcde917b..904a65487c093179c89db70f7d7f0bc0dc56424f 100644 (file)
@@ -31,9 +31,9 @@
 
 #include <memory>
 #include <functional>
-#include <list>
 #include <mutex>
 #include <unordered_map>
+#include <unordered_set>
 
 #include "RCSDiscoveryManager.h"
 #include "ExpiryTimer.h"
@@ -59,36 +59,26 @@ namespace OIC
                 DiscoveryRequestInfo(const std::string &, const std::string &,
                         const std::string &, DiscoverCallback);
 
+            public:
+                void discover() const;
+                bool isKnownResource(const std::shared_ptr<PrimitiveResource>&);
+                bool isMatchingAddress(const std::string&) const;
+
             private:
                 std::string m_address;
                 std::string m_relativeUri;
                 std::string m_resourceType;
-                std::list<std::string> m_receivedIds;
-                DiscoverCallback m_discoverCB;
-            public:
-                void discoverRequest() const;
-                bool isKnownResource(const std::shared_ptr<PrimitiveResource>&);
-                bool isMatchingAddress(const std::string&) const;
+                std::unordered_set<std::string> m_receivedIds;
+                DiscoverCallback m_discoverCb;
         };
 
-
         /**
          * The class contains the resource discovery and management requests methods.
          */
         class RCSDiscoveryManagerImpl
         {
-            static unsigned int s_uniqueId;
-
             public:
 
-                /*
-                 * Typedef for callback of requesting presence API
-                 *
-                 * @see requestMulticastPresence
-                 */
-                typedef std::function<void(OCStackResult, const unsigned int,
-                        const std::string&)> PresenceCallback;
-
                 /*
                  * Typedef for discovery request ID
                  *
@@ -98,13 +88,10 @@ namespace OIC
 
             public:
 
-                /*
-                 * @return Returns RCSDiscoveryManagerImpl instance.
-                 */
                 static RCSDiscoveryManagerImpl* getInstance();
 
                 /**
-                 * Starting discovery of resource
+                 * Start discovery of resource
                  *
                  * @return DiscoverTask pointer
                  *
@@ -115,13 +102,14 @@ namespace OIC
                  *
                  * @throws InvalidParameterException If cb is empty
                  *
-                 * @note If relativeURI is empty, will be discovered after be changed into "OC_RSRVD_WELL_KNOWN_URI"
+                 * @note If relativeURI is empty, will be discovered after be changed into
+                 * "OC_RSRVD_WELL_KNOWN_URI"
                  * @note If resourceType is empty, will be discovered all resources in network
                  *
                  * @see RCSAddress
                  * @see RCSDiscoveryManager
                  */
-                std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> startDiscovery(const RCSAddress& address,
+                RCSDiscoveryManager::DiscoveryTask::Ptr startDiscovery(const RCSAddress& address,
                         const std::string& relativeURI,const std::string& resourceType,
                         RCSDiscoveryManager::ResourceDiscoveredCallback cb);
 
@@ -133,12 +121,12 @@ namespace OIC
                 ~RCSDiscoveryManagerImpl() = default;
 
                 /**
-                 * Requesting presence by multicast
+                 * Request presence by multicast
                  */
                 void requestMulticastPresence();
 
                 /**
-                 * Checking duplicated callback and invoking callback when resource is discovered
+                 * Check duplicated callback and invoke callback when resource is discovered
                  *
                  * @param resource     A pointer of discovered resource
                  * @param discoverID   The ID of discovery request
@@ -150,21 +138,18 @@ namespace OIC
                         const RCSDiscoveryManager::ResourceDiscoveredCallback& cb);
 
                 /**
-                 * Discovering resource on all requests and posting timer when timer is expired
+                 * Discover resource on all requests and posting timer when timer is expired
                  */
                 void onPolling();
 
                 /**
-                 * Discovering resource on all requests when supporting presence function resource enter into network
-                 *
-                 * @param ret          Not used in this class
-                 * @param seq          Not used in this class
-                 * @param address      A address of supporting presence function resource
+                 * Discover resource on all requests when supporting presence function resource
+                 * enter into network
                  */
                 void onPresence(OCStackResult ret, const unsigned int seq, const std::string& address);
 
                 /**
-                 * Creating unique id
+                 * Create unique id
                  *
                  * @return Returns the id
                  */