Replace expectOCStackResultOK with invokeOCFunc which is safer
authorcoderhyme <jhyo.kim@samsung.com>
Wed, 1 Jul 2015 01:44:36 +0000 (10:44 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 2 Jul 2015 09:02:41 +0000 (09:02 +0000)
Add new methods to primitiveServeResource(removeAttribute and setAttribute with rval ref key)

Change-Id: I796599584fab56dfef697140b819069e3a9612b7
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1464
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-manipulation/modules/common/primitiveResource/src/PresenceSubscriber.cpp
service/resource-manipulation/modules/serverBuilder/include/PrimitiveServerResource.h
service/resource-manipulation/modules/serverBuilder/src/PrimitiveServerResource.cpp

index 99b52e9..2b35cb6 100644 (file)
@@ -32,25 +32,27 @@ namespace OIC
         void subscribePresence(OCDoHandle& handle, const std::string& host,
                 OCConnectivityType connectivityType, SubscribeCallback presenceHandler)
         {
-            OCStackResult result = OC::OCPlatform::subscribePresence(
-                    handle, host, connectivityType, presenceHandler);
+            using SubscribePresence = OCStackResult (*)(OC::OCPlatform::OCPresenceHandle&,
+                    const std::string&, OCConnectivityType, SubscribeCallback);
 
-            expectOCStackResultOK(result);
+            invokeOCFunc(static_cast<SubscribePresence>(OC::OCPlatform::subscribePresence),
+                    handle, host, connectivityType, presenceHandler);
         }
 
         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);
+            using SubscribePresence = OCStackResult (*)(OC::OCPlatform::OCPresenceHandle&,
+                    const std::string&, const std::string&, OCConnectivityType, SubscribeCallback);
 
-            expectOCStackResultOK(result);
+            invokeOCFunc(static_cast<SubscribePresence>(OC::OCPlatform::subscribePresence),
+                    handle, host, resourceType, connectivityType, presenceHandler);
         }
 
         void unsubscribePresence(OCDoHandle handle)
         {
-            expectOCStackResultOK(OC::OCPlatform::unsubscribePresence(handle));
+            invokeOCFunc(OC::OCPlatform::unsubscribePresence, handle);
         }
 
 
index e2b49ce..ae1f1b9 100644 (file)
@@ -111,10 +111,17 @@ namespace OIC
             virtual ~PrimitiveServerResource();
 
             template< typename T >
-            void setAttribute(const std::string& key, const T &value)
+            void setAttribute(const std::string& key, T&& value)
             {
                 WeakGuard lock(*this);
-                m_resourceAttributes[key] = value;
+                m_resourceAttributes[key] = std::forward<T>(value);
+            }
+
+            template< typename T >
+            void setAttribute(std::string&& key, T&& value)
+            {
+                WeakGuard lock(*this);
+                m_resourceAttributes[std::move(key)] = std::forward<T>(value);
             }
 
             template< typename T >
@@ -124,6 +131,8 @@ namespace OIC
                 return m_resourceAttributes.at(key).get< T >();
             }
 
+            bool removeAttribute(const std::string& key);
+
             bool hasAttribute(const std::string& key) const;
 
             ResourceAttributes& getAttributes();
index dfc89b3..c8a0e70 100644 (file)
@@ -112,7 +112,8 @@ namespace OIC
 
         PrimitiveServerResource::Builder::Builder(const std::string& uri, const std::string& type,
                 const std::string& interface) :
-                m_uri{ uri }, m_type{ type }, m_interface{ interface }, m_properties{ 0 }
+                m_uri{ uri }, m_type{ type }, m_interface{ interface },
+                m_properties{ OC_DISCOVERABLE | OC_OBSERVABLE }
         {
         }
 
@@ -156,9 +157,11 @@ namespace OIC
 
             try
             {
-                expectOCStackResultOK(
-                        OC::OCPlatform::registerResource(handle, m_uri, m_type, m_interface,
-                                entityHandler, m_properties));
+                using RegisterResource = OCStackResult (*)(OCResourceHandle&, std::string&,
+                        const std::string&, const std::string&, OC::EntityHandler, uint8_t);
+
+                invokeOCFunc(static_cast<RegisterResource>(OC::OCPlatform::registerResource),
+                        handle, m_uri, m_type, m_interface, entityHandler, m_properties);
             }
             catch (OC::OCException& e)
             {
@@ -186,6 +189,12 @@ namespace OIC
             }
         }
 
+        bool PrimitiveServerResource::removeAttribute(const std::string& key)
+        {
+            WeakGuard lock(*this);
+            return m_resourceAttributes.erase(key);
+        }
+
         bool PrimitiveServerResource::hasAttribute(const std::string& key) const
         {
             WeakGuard lock(*this);
@@ -234,7 +243,10 @@ namespace OIC
 
         void PrimitiveServerResource::notify() const
         {
-            expectOCStackResultOK(OC::OCPlatform::notifyAllObservers(m_resourceHandle));
+            using NotifyAllObservers = OCStackResult (*)(OCResourceHandle);
+
+            invokeOCFunc(static_cast<NotifyAllObservers>(OC::OCPlatform::notifyAllObservers),
+                    m_resourceHandle);
         }
 
         OCEntityHandlerResult PrimitiveServerResource::entityHandler(