Add namespace to PresenceSubscriber
authorcoderhyme <jhyo.kim@samsung.com>
Fri, 12 Jun 2015 06:38:07 +0000 (15:38 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 17 Jun 2015 08:25:16 +0000 (08:25 +0000)
Change-Id: Ibb774d6ec49996ef4d0e8234ee39b556566ac311
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1298
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/basis/common/primitiveResource/include/PresenceSubscriber.h
service/basis/common/primitiveResource/src/PresenceSubscriber.cpp

index 121f760..8733309 100644 (file)
 
 #include <octypes.h>
 
-typedef std::function< void(OCStackResult, const unsigned int, const std::string&) > SubscribeCallback;
-
-class PresenceSubscriber
+namespace OIC
 {
-public:
-    PresenceSubscriber();
+    namespace Service
+    {
+
+        typedef std::function< void(OCStackResult, const unsigned int, const std::string&) > SubscribeCallback;
+
+        class PresenceSubscriber
+        {
+        public:
+            PresenceSubscriber();
+
+            PresenceSubscriber(PresenceSubscriber&&);
 
-    PresenceSubscriber(PresenceSubscriber&&);
+            /**
+             * @throw PlatformException
+             */
+            PresenceSubscriber(const std::string& host, OCConnectivityType connectivityType,
+                    SubscribeCallback presenceHandler);
 
-    /**
-     * @throw PlatformException
-     */
-    PresenceSubscriber(const std::string& host, OCConnectivityType connectivityType,
-            SubscribeCallback presenceHandler);
+            /**
+             * @throw PlatformException
+             */
+            PresenceSubscriber(const std::string& host, const std::string& resourceType,
+                    OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
 
-    /**
-     * @throw PlatformException
-     */
-    PresenceSubscriber(const std::string& host, const std::string& resourceType,
-            OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
+            ~PresenceSubscriber();
 
-    ~PresenceSubscriber();
+            PresenceSubscriber& operator=(PresenceSubscriber&&);
 
-    PresenceSubscriber& operator=(PresenceSubscriber&&);
+            /**
+             * @throw PlatformException
+             */
+            void unsubscribe();
 
-    /**
-     * @throw PlatformException
-     */
-    void unsubscribe();
+            bool isSubscribing() const;
 
-    bool isSubscribing() const;
+        private:
+            OCDoHandle m_handle;
+        };
 
-private:
-    OCDoHandle m_handle;
-};
+        /**
+         * @throw PlatformException
+         */
+        void subscribePresence(OCDoHandle& handle, const std::string& host,
+                OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
 
-/**
- * @throw PlatformException
- */
-void subscribePresence(OCDoHandle& handle, const std::string& host,
-        OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
+        /**
        * @throw PlatformException
        */
+        void subscribePresence(OCDoHandle& handle, const std::string& host, const std::string& resourceType,
+                OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
 
-/**
- * @throw PlatformException
- */
-void subscribePresence(OCDoHandle& handle, const std::string& host, const std::string& resourceType,
-        OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
+        void unsubscribePresence(OCDoHandle handle);
 
-void unsubscribePresence(OCDoHandle handle);
+    }
+}
 
 #endif // __PRESENCESUBSCRIBER_H
index 58e9f8c..b14fa7a 100644 (file)
 
 #include <PresenceSubscriber.h>
 
-#include <PrimitiveException.h>
+#include <internal/AssertUtils.h>
 
 #include <OCPlatform.h>
 
-void subscribePresence(OCDoHandle& handle, const std::string& host,
-        OCConnectivityType connectivityType, SubscribeCallback presenceHandler)
+namespace OIC
 {
-    OCStackResult result = OC::OCPlatform::subscribePresence(handle, host, connectivityType, presenceHandler);
-
-    if (result != OC_STACK_OK)
+    namespace Service
     {
-        throw PlatformException(result);
-    }
-}
 
-void subscribePresence(OCDoHandle& handle, const std::string& host,
-        const std::string& resourceType, OCConnectivityType connectivityType,
-        SubscribeCallback presenceHandler)
-{
-    OCStackResult result = OC::OCPlatform::subscribePresence(handle, host, resourceType,
-            connectivityType, presenceHandler);
+        void subscribePresence(OCDoHandle& handle, const std::string& host,
+                OCConnectivityType connectivityType, SubscribeCallback presenceHandler)
+        {
+            OCStackResult result = OC::OCPlatform::subscribePresence(handle, host, connectivityType, presenceHandler);
 
-    if (result != OC_STACK_OK)
-    {
-        throw PlatformException(result);
-    }
-}
+            expectOCStackResultOK(result);
+        }
 
-void unsubscribePresence(OCDoHandle handle)
-{
-    OCStackResult result = OC::OCPlatform::unsubscribePresence(handle);
+        void subscribePresence(OCDoHandle& handle, const std::string& host,
+                const std::string& resourceType, OCConnectivityType connectivityType,
+                SubscribeCallback presenceHandler)
+        {
+            OCStackResult result = OC::OCPlatform::subscribePresence(handle, host, resourceType,
+                    connectivityType, presenceHandler);
 
-    if (result != OC_STACK_OK)
-    {
-        throw PlatformException(result);
-    }
-}
+            expectOCStackResultOK(result);
+        }
 
+        void unsubscribePresence(OCDoHandle handle)
+        {
+            expectOCStackResultOK(OC::OCPlatform::unsubscribePresence(handle));
+        }
 
-PresenceSubscriber::PresenceSubscriber() :
-    m_handle{ nullptr }
-{
-}
 
-PresenceSubscriber::PresenceSubscriber(PresenceSubscriber&& from) :
-    m_handle{ nullptr }
-{
-    std::swap(m_handle, from.m_handle);
-}
+        PresenceSubscriber::PresenceSubscriber() :
+            m_handle{ nullptr }
+        {
+        }
 
-PresenceSubscriber::PresenceSubscriber(const std::string& host,
-        OCConnectivityType connectivityType, SubscribeCallback presenceHandler) :
-        m_handle{ nullptr }
-{
-    subscribePresence(m_handle, host, connectivityType, presenceHandler);
-}
+        PresenceSubscriber::PresenceSubscriber(PresenceSubscriber&& from) :
+            m_handle{ nullptr }
+        {
+            std::swap(m_handle, from.m_handle);
+        }
 
-PresenceSubscriber::PresenceSubscriber(const std::string& host, const std::string& resourceType,
-        OCConnectivityType connectivityType, SubscribeCallback presenceHandler) :
-        m_handle{ nullptr }
-{
-    subscribePresence(m_handle, host, resourceType, connectivityType, presenceHandler);
-}
+        PresenceSubscriber::PresenceSubscriber(const std::string& host,
+                OCConnectivityType connectivityType, SubscribeCallback presenceHandler) :
+                m_handle{ nullptr }
+        {
+            subscribePresence(m_handle, host, connectivityType, presenceHandler);
+        }
 
-PresenceSubscriber::~PresenceSubscriber()
-{
-    if (m_handle)
-    {
-        try
+        PresenceSubscriber::PresenceSubscriber(const std::string& host, const std::string& resourceType,
+                OCConnectivityType connectivityType, SubscribeCallback presenceHandler) :
+                m_handle{ nullptr }
         {
-            unsubscribe();
+            subscribePresence(m_handle, host, resourceType, connectivityType, presenceHandler);
         }
-        catch (...)
+
+        PresenceSubscriber::~PresenceSubscriber()
         {
+            if (m_handle)
+            {
+                try
+                {
+                    unsubscribe();
+                }
+                catch (...)
+                {
+                }
+            }
         }
-    }
-}
 
-PresenceSubscriber& PresenceSubscriber::operator=(PresenceSubscriber&& from)
-{
-    unsubscribe();
-    std::swap(m_handle, from.m_handle);
-    return *this;
-}
+        PresenceSubscriber& PresenceSubscriber::operator=(PresenceSubscriber&& from)
+        {
+            unsubscribe();
+            std::swap(m_handle, from.m_handle);
+            return *this;
+        }
 
-void PresenceSubscriber::unsubscribe()
-{
-    if (m_handle == nullptr) return;
+        void PresenceSubscriber::unsubscribe()
+        {
+            if (m_handle == nullptr) return;
 
-    unsubscribePresence(m_handle);
+            unsubscribePresence(m_handle);
 
-    m_handle = nullptr;
-}
+            m_handle = nullptr;
+        }
 
-bool PresenceSubscriber::isSubscribing() const
-{
-    return m_handle != nullptr;
+        bool PresenceSubscriber::isSubscribing() const
+        {
+            return m_handle != nullptr;
+        }
+
+    }
 }