modify BundleResource template api for handling attributes update
authorMinji Park <minjii.park@samsung.com>
Thu, 24 Sep 2015 08:18:03 +0000 (17:18 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 25 Sep 2015 04:22:29 +0000 (04:22 +0000)
- remove set,get request handle apis for handling single attribute in bundle resource template to make template simple
- reorder the apis
- modify samples due to the change of resource template apis
- modify bundle resource to make container and bundle use shared pointer

Change-Id: I7b87ffc2e405aedd290a13b3b392063d785f8814
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3027
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
24 files changed:
service/resource-encapsulation/src/resourceContainer/bundle-api/include/BundleActivator.h
service/resource-encapsulation/src/resourceContainer/bundle-api/include/BundleResource.h
service/resource-encapsulation/src/resourceContainer/bundle-api/include/ProtocolBridgeResource.h
service/resource-encapsulation/src/resourceContainer/bundle-api/include/ResourceContainerBundleAPI.h
service/resource-encapsulation/src/resourceContainer/bundle-api/include/SoftSensorResource.h
service/resource-encapsulation/src/resourceContainer/examples/BMISensorBundle/include/BMISensorBundleActivator.h
service/resource-encapsulation/src/resourceContainer/examples/BMISensorBundle/include/BMISensorResource.h
service/resource-encapsulation/src/resourceContainer/examples/BMISensorBundle/src/BMISensorBundleActivator.cpp
service/resource-encapsulation/src/resourceContainer/examples/BMISensorBundle/src/BMISensorResource.cpp
service/resource-encapsulation/src/resourceContainer/examples/DiscomfortIndexSensorBundle/include/DISensorBundleActivator.h
service/resource-encapsulation/src/resourceContainer/examples/DiscomfortIndexSensorBundle/include/DiscomfortIndexSensorResource.h
service/resource-encapsulation/src/resourceContainer/examples/DiscomfortIndexSensorBundle/src/DISensorBundleActivator.cpp
service/resource-encapsulation/src/resourceContainer/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp
service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/include/HueLight.h
service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/include/HueSampleBundleActivator.h
service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueLight.cpp
service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp
service/resource-encapsulation/src/resourceContainer/include/BundleInfoInternal.h
service/resource-encapsulation/src/resourceContainer/include/ResourceContainerImpl.h
service/resource-encapsulation/src/resourceContainer/src/BundleResource.cpp
service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp
service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTest.cpp
service/resource-encapsulation/src/resourceContainer/unittests/TestBundle/include/TestBundleActivator.h
service/resource-encapsulation/src/resourceContainer/unittests/TestBundle/src/TestBundleActivator.cpp

index 5551d8e..ddc79ca 100644 (file)
@@ -85,7 +85,7 @@ namespace OIC
                 *
                 * @return void
                 */
-                virtual void destroyResource(BundleResource *pBundleResource) = 0;
+                virtual void destroyResource(BundleResource::Ptr pBundleResource) = 0;
         };
     }
 }
index 82fdbed..960b146 100644 (file)
@@ -25,6 +25,7 @@
 #include <string>
 #include <map>
 #include <vector>
+#include <memory>
 
 #include "NotificationReceiver.h"
 #include "RCSResourceAttributes.h"
@@ -43,6 +44,7 @@ namespace OIC
         class BundleResource
         {
             public:
+                typedef std::shared_ptr< BundleResource > Ptr;
 
                 /**
                 * Constructor for BundleResource
@@ -70,7 +72,7 @@ namespace OIC
 
                 /**
                 * Register notification receiver(resource container) to notify for the
-                * changes of attributes
+                *     changes of attributes
                 *
                 * @param pNotiReceiver Notification Receiver to get notification from
                 * bundle resource
@@ -96,7 +98,7 @@ namespace OIC
                 void setAttributes(RCSResourceAttributes &attrs);
 
                 /**
-                * Execute the logic of bundle to get the value of attribute
+                * Return the value of an attribute
                 *
                 * @param key Key of attribute to get
                 *
@@ -116,91 +118,54 @@ namespace OIC
                 * @return void
                 */
                 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value,
-                        bool notify);
+                                  bool notify);
 
                 /**
-                   * Sets the value of an attribute
-                   *
-                   * @param key Name of attribute to set
-                   *
-                   * @param value Value of attribute to set
-                   *
-                   * @return void
-                   */
+                * Sets the value of an attribute
+                *
+                * @param key Name of attribute to set
+                *
+                * @param value Value of attribute to set
+                *
+                * @return void
+                */
                 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value);
 
                 /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * and write either on soft sensor values or external bridged devices.
-                  *
-                  * The call of this method could for example trigger a HTTP PUT request on
-                  * an external APIs. This method is responsible to update the resource internal
-                  * data and call the setAttribute method.
-                  *
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to set
-                  *
-                  * @param attrs Attributes to set
-                  *
-                  * @return void
-                  */
-                virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs);
-
-                /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * and write either on soft sensor values or external bridged devices.
-                  *
-                  * The call of this method could for example trigger a HTTP PUT request on
-                  * an external APIs. This method is responsible to update the resource internal
-                  * data and call the setAttribute method.
-                  *
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to set
-                  *
-                  * @param value Value of attribute to set
-                  *
-                  * @return void
-                  */
-                virtual void handleSetAttributeRequest(const std::string &key,
-                        RCSResourceAttributes::Value &&value);
+                * This function should be implemented by the according bundle resource
+                * and execute the according business logic (e.g., light switch or sensor resource)
+                * to retrieve a sensor value. If a new sensor value is retrieved, the
+                * setAttribute data should be called to update the value.
+                * The implementor of the function can decide weather to notify OIC clients
+                * about the changed state or not.
+                *
+                * @param key Name of attribute to get
+                *
+                *
+                * @return All attributes
+                */
+                virtual RCSResourceAttributes &handleGetAttributesRequest() = 0;
 
                 /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * to retrieve a sensor value. If a new sensor value is retrieved, the
-                  * setAttribute data should be called to update the value.
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to get
-                  *
-                  *
-                  * @return Value of the attribute
-                  */
-                virtual RCSResourceAttributes::Value handleGetAttributeRequest(
-                        const std::string &key);
-
+                * This function should be implemented by the according bundle resource
+                * and execute the according business logic (e.g., light switch or sensor resource)
+                * and write either on soft sensor values or external bridged devices.
+                *
+                * The call of this method could for example trigger a HTTP PUT request on
+                * an external APIs. This method is responsible to update the resource internal
+                * data and call the setAttribute method.
+                *
+                * The implementor of the function can decide weather to notify OIC clients
+                * about the changed state or not.
+                *
+                * @param key Name of attribute to set
+                *
+                * @param attrs Attributes to set
+                *
+                * @return void
+                */
+                virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs) = 0;
 
-                /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * to retrieve a sensor value. If a new sensor value is retrieved, the
-                  * setAttribute data should be called to update the value.
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to get
-                  *
-                  *
-                  * @return All attributes
-                  */
-                virtual RCSResourceAttributes& handleGetAttributesRequest();
 
             public:
                 std::string m_bundleId;
index 9c441aa..c420c27 100644 (file)
@@ -58,76 +58,39 @@ namespace OIC
                 virtual void initAttributes() = 0;
 
                 /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * and write either on soft sensor values or external bridged devices.
-                  *
-                  * The call of this method could for example trigger a HTTP PUT request on
-                  * an external APIs. This method is responsible to update the resource internal
-                  * data and call the setAttribute method.
-                  *
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to set
-                  *
-                  * @param attrs Attributes to set
-                  *
-                  * @return void
-                  */
-                virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs) = 0;
-
-                /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * and write either on soft sensor values or external bridged devices.
-                  *
-                  * The call of this method could for example trigger a HTTP PUT request on
-                  * an external APIs. This method is responsible to update the resource internal
-                  * data and call the setAttribute method.
-                  *
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to set
-                  *
-                  * @param value Value of attribute to set
-                  *
-                  * @return void
-                  */
-                virtual void handleSetAttributeRequest(const std::string &key,
-                        RCSResourceAttributes::Value &&value) = 0;
-
-                /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * to retrieve a sensor value. If a new sensor value is retrieved, the
-                  * setAttribute data should be called to update the value.
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to get
-                  *
-                  *
-                  * @return Attribute value
-                  */
-                virtual RCSResourceAttributes::Value handleGetAttributeRequest(
-                        const std::string &key) = 0;
+                * This function should be implemented by the according bundle resource
+                * and execute the according business logic (e.g., light switch or sensor resource)
+                * to retrieve a sensor value. If a new sensor value is retrieved, the
+                * setAttribute data should be called to update the value.
+                * The implementor of the function can decide weather to notify OIC clients
+                * about the changed state or not.
+                *
+                * @param key Name of attribute to get
+                *
+                *
+                * @return Value of all attributes
+                */
+                virtual RCSResourceAttributes &handleGetAttributesRequest() = 0;
 
                 /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * to retrieve a sensor value. If a new sensor value is retrieved, the
-                  * setAttribute data should be called to update the value.
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to get
-                  *
-                  *
-                  * @return Value of all attributes
-                  */
-                virtual RCSResourceAttributes& handleGetAttributesRequest() = 0;
+                * This function should be implemented by the according bundle resource
+                * and execute the according business logic (e.g., light switch or sensor resource)
+                * and write either on soft sensor values or external bridged devices.
+                *
+                * The call of this method could for example trigger a HTTP PUT request on
+                * an external APIs. This method is responsible to update the resource internal
+                * data and call the setAttribute method.
+                *
+                * The implementor of the function can decide weather to notify OIC clients
+                * about the changed state or not.
+                *
+                * @param key Name of attribute to set
+                *
+                * @param attrs Attributes to set
+                *
+                * @return void
+                */
+                virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs) = 0;
         };
     }
 }
index 2f4a676..a804b33 100644 (file)
@@ -56,7 +56,7 @@ namespace OIC
                 *
                 * @return void
                 */
-                virtual void registerResource(BundleResource *resource) = 0;
+                virtual void registerResource(BundleResource::Ptr resource) = 0;
 
                 /**
                 * Unregister bundle resource from the container
@@ -66,7 +66,7 @@ namespace OIC
                 *
                 * @return void
                 */
-                virtual void unregisterResource(BundleResource *resource) = 0;
+                virtual void unregisterResource(BundleResource::Ptr resource) = 0;
 
                 /**
                 * Get Configuration data of certain bundle
index 6722383..90b01a0 100644 (file)
@@ -55,76 +55,39 @@ namespace OIC
                 virtual void initAttributes();
 
                 /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * and write either on soft sensor values or external bridged devices.
-                  *
-                  * The call of this method could for example trigger a HTTP PUT request on
-                  * an external APIs. This method is responsible to update the resource internal
-                  * data and call the setAttribute method.
-                  *
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to set
-                  *
-                  * @param attrs Attributes to set
-                  *
-                  * @return void
-                  */
-                virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs) = 0;
-
-                /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * and write either on soft sensor values or external bridged devices.
-                  *
-                  * The call of this method could for example trigger a HTTP PUT request on
-                  * an external APIs. This method is responsible to update the resource internal
-                  * data and call the setAttribute method.
-                  *
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to set
-                  *
-                  * @param value Value of attribute to set
-                  *
-                  * @return void
-                  */
-                virtual void handleSetAttributeRequest(const std::string &key,
-                        RCSResourceAttributes::Value &&value) = 0;
-
-                /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * to retrieve a sensor value. If a new sensor value is retrieved, the
-                  * setAttribute data should be called to update the value.
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to get
-                  *
-                  *
-                  * @return Attribute value
-                  */
-                virtual RCSResourceAttributes::Value handleGetAttributeRequest(
-                        const std::string &key) = 0;
+                * This function should be implemented by the according bundle resource
+                * and execute the according business logic (e.g., light switch or sensor resource)
+                * to retrieve a sensor value. If a new sensor value is retrieved, the
+                * setAttribute data should be called to update the value.
+                * The implementor of the function can decide weather to notify OIC clients
+                * about the changed state or not.
+                *
+                * @param key Name of attribute to get
+                *
+                *
+                * @return Value of all attributes
+                */
+                virtual RCSResourceAttributes &handleGetAttributesRequest() = 0;
 
                 /**
-                  * This function should be implemented by the according bundle resource
-                  * and execute the according business logic (e.g., light switch or sensor resource)
-                  * to retrieve a sensor value. If a new sensor value is retrieved, the
-                  * setAttribute data should be called to update the value.
-                  * The implementor of the function can decide weather to notify OIC clients
-                  * about the changed state or not.
-                  *
-                  * @param key Name of attribute to get
-                  *
-                  *
-                  * @return Value of all attributes
-                  */
-                virtual RCSResourceAttributes& handleGetAttributesRequest() = 0;
+                * This function should be implemented by the according bundle resource
+                * and execute the according business logic (e.g., light switch or sensor resource)
+                * and write either on soft sensor values or external bridged devices.
+                *
+                * The call of this method could for example trigger a HTTP PUT request on
+                * an external APIs. This method is responsible to update the resource internal
+                * data and call the setAttribute method.
+                *
+                * The implementor of the function can decide weather to notify OIC clients
+                * about the changed state or not.
+                *
+                * @param key Name of attribute to set
+                *
+                * @param attrs Attributes to set
+                *
+                * @return void
+                */
+                virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs) = 0;
 
                 /**
                 * SoftSensor logic. Has to be provided by the soft sensor developer.
@@ -134,8 +97,20 @@ namespace OIC
                 */
                 virtual void executeLogic() = 0;
 
+                /**
+                * Callback from the client module in the container.
+                * This function will be called if input data from remote resources are updated.
+                * SoftSensor resource can get a vector of input data from multiple input resources
+                *    which have attributeName that softsensor needs to execute its logic.
+                *
+                * @param attributeName Attribute key of input data
+                *
+                * @param values Vector of input data value
+                *
+                * @return void
+                */
                 virtual void onUpdatedInputResource(const std::string attributeName,
-                                             std::vector<RCSResourceAttributes::Value> values) = 0;
+                                                    std::vector<RCSResourceAttributes::Value> values) = 0;
 
 
             public:
index 6843263..3ba3fcd 100644 (file)
@@ -37,11 +37,11 @@ class BMISensorBundleActivator : public BundleActivator
         void deactivateBundle();
 
         void createResource(resourceInfo resourceInfo);
-        void destroyResource(BundleResource *pBundleResource);
+        void destroyResource(BundleResource::Ptr pBundleResource);
 
         std::string m_bundleId;
         ResourceContainerBundleAPI *m_pResourceContainer;
-        std::vector<BundleResource *> m_vecResources;
+        std::vector< BundleResource::Ptr > m_vecResources;
 };
 
 #endif /* BMISENSOR_BUNDLE_ACTIVATOR_H_ */
index 553a489..c35facf 100644 (file)
@@ -33,20 +33,16 @@ class BMISensorResource : public SoftSensorResource
         BMISensorResource();
         ~BMISensorResource();
 
-        virtual RCSResourceAttributes::Value handleGetAttributeRequest(const std::string &key);
-
-        virtual void handleSetAttributeRequest(const std::string &key,
-                RCSResourceAttributes::Value &&value);
-
-        virtual RCSResourceAttributes& handleGetAttributesRequest();
-
         virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs);
 
+        virtual RCSResourceAttributes &handleGetAttributesRequest();
+
         virtual void executeLogic();
 
         virtual void onUpdatedInputResource(const std::string attributeName,
                                             std::vector<RCSResourceAttributes::Value> values);
 
+
     private:
         BMISensor *m_pBMISensor;
         std::map<std::string, std::string> m_mapInputData;
index b9b3946..b54622b 100644 (file)
@@ -56,7 +56,7 @@ void BMISensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resour
 
 void BMISensorBundleActivator::deactivateBundle()
 {
-    std::vector<BundleResource *>::iterator itor;
+    std::vector< BundleResource::Ptr >::iterator itor;
     for (itor = m_vecResources.begin(); itor != m_vecResources.end();)
     {
         destroyResource(*itor);
@@ -70,7 +70,7 @@ void BMISensorBundleActivator::createResource(resourceInfo resourceInfo)
         static int BMISensorCount = 1;
 
         // create BMISensor resource
-        BMISensorResource *newResource = new BMISensorResource();
+        BundleResource::Ptr newResource = std::make_shared< BMISensorResource >();
 
         newResource->m_bundleId = m_bundleId;
         std::string indexCount;//string which will contain the indexCount
@@ -89,9 +89,9 @@ void BMISensorBundleActivator::createResource(resourceInfo resourceInfo)
     }
 }
 
-void BMISensorBundleActivator::destroyResource(BundleResource *resource)
+void BMISensorBundleActivator::destroyResource(BundleResource::Ptr resource)
 {
-    std::vector <BundleResource *>::iterator itor;
+    std::vector< BundleResource::Ptr >::iterator itor;
 
     itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
 
@@ -120,7 +120,7 @@ extern "C" void bmisensor_externalCreateResource(resourceInfo resourceInfo)
     bundle->createResource(resourceInfo);
 }
 
-extern "C" void bmisensor_externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void bmisensor_externalDestroyResource(BundleResource::Ptr pBundleResource)
 {
     bundle->destroyResource(pBundleResource);
 }
index 206a50b..9bfe09f 100644 (file)
@@ -31,29 +31,17 @@ BMISensorResource::~BMISensorResource()
     delete m_pBMISensor;
 }
 
-RCSResourceAttributes::Value BMISensorResource::handleGetAttributeRequest(const std::string &key)
-{
-    return BundleResource::getAttribute(key);
-}
-
-void BMISensorResource::handleSetAttributeRequest(const std::string &key,
-                                     RCSResourceAttributes::Value &&value)
+void BMISensorResource::handleSetAttributesRequest(
+    RCSResourceAttributes &value)
 {
-    BundleResource::setAttribute(key, std::move(value));
+    BundleResource::setAttributes(value);
 }
 
-RCSResourceAttributesBMISensorResource::handleGetAttributesRequest()
+RCSResourceAttributes &BMISensorResource::handleGetAttributesRequest()
 {
     return BundleResource::getAttributes();
 }
 
-void BMISensorResource::handleSetAttributesRequest(
-                                     RCSResourceAttributes &value)
-{
-    BundleResource::setAttributes(value);
-}
-
-
 void BMISensorResource::executeLogic()
 {
     std::string strBMIResult;
@@ -75,4 +63,4 @@ void BMISensorResource::onUpdatedInputResource(const std::string attributeName,
         m_mapInputData.insert(std::make_pair("height", values.back().toString()));
 
     executeLogic();
-}
+}
\ No newline at end of file
index 1d29da7..36e67ca 100644 (file)
@@ -37,11 +37,11 @@ class DISensorBundleActivator : public BundleActivator
         void deactivateBundle();
 
         void createResource(resourceInfo resourceInfo);
-        void destroyResource(BundleResource *pBundleResource);
+        void destroyResource(BundleResource::Ptr pBundleResource);
 
         std::string m_bundleId;
         ResourceContainerBundleAPI *m_pResourceContainer;
-        std::vector<BundleResource *> m_vecResources;
+        std::vector< BundleResource::Ptr > m_vecResources;
 };
 
 #endif /* DISENSOR_BUNDLE_ACTIVATOR_H_ */
index 65469f8..6780715 100644 (file)
@@ -33,20 +33,16 @@ class DiscomfortIndexSensorResource : public SoftSensorResource
         DiscomfortIndexSensorResource();
         ~DiscomfortIndexSensorResource();
 
-        virtual RCSResourceAttributes::Value handleGetAttributeRequest(const std::string &key);
-
-        virtual void handleSetAttributeRequest(const std::string &key,
-                RCSResourceAttributes::Value &&value);
-
-        virtual RCSResourceAttributes& handleGetAttributesRequest();
-
         virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs);
 
+        virtual RCSResourceAttributes &handleGetAttributesRequest();
+
         virtual void executeLogic();
 
         virtual void onUpdatedInputResource(const std::string attributeName,
                                             std::vector<RCSResourceAttributes::Value> values);
 
+
     private:
         DiscomfortIndexSensor *m_pDiscomfortIndexSensor;
         std::map<std::string, std::string> m_mapInputData;
index fd10d70..147e3c4 100644 (file)
@@ -55,7 +55,7 @@ void DISensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resourc
 
 void DISensorBundleActivator::deactivateBundle()
 {
-    std::vector<BundleResource *>::iterator itor;
+    std::vector< BundleResource::Ptr >::iterator itor;
     for (itor = m_vecResources.begin(); itor != m_vecResources.end();)
     {
         destroyResource(*itor);
@@ -69,7 +69,7 @@ void DISensorBundleActivator::createResource(resourceInfo resourceInfo)
         static int discomfortIndexSensorCount = 1;
 
         // create DISensor resource
-        DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource();
+        BundleResource::Ptr newResource = std::make_shared< DiscomfortIndexSensorResource >();
 
         newResource->m_bundleId = m_bundleId;
 
@@ -90,9 +90,9 @@ void DISensorBundleActivator::createResource(resourceInfo resourceInfo)
     }
 }
 
-void DISensorBundleActivator::destroyResource(BundleResource *resource)
+void DISensorBundleActivator::destroyResource(BundleResource::Ptr resource)
 {
-    std::vector <BundleResource *>::iterator itor;
+    std::vector< BundleResource::Ptr >::iterator itor;
 
     itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
 
@@ -121,7 +121,7 @@ extern "C" void disensor_externalCreateResource(resourceInfo resourceInfo)
     bundle->createResource(resourceInfo);
 }
 
-extern "C" void disensor_externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void disensor_externalDestroyResource(BundleResource::Ptr pBundleResource)
 {
     bundle->destroyResource(pBundleResource);
 }
index b5337f6..bc65a4e 100644 (file)
@@ -34,28 +34,17 @@ DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource()
     delete m_pDiscomfortIndexSensor;
 }
 
-RCSResourceAttributes::Value DiscomfortIndexSensorResource::handleGetAttributeRequest(
-        const std::string &key)
-{
-    return BundleResource::getAttribute(key);
-}
-
-void DiscomfortIndexSensorResource::handleSetAttributeRequest(const std::string &key,
-                                     RCSResourceAttributes::Value &&value)
+void DiscomfortIndexSensorResource::handleSetAttributesRequest(
+    RCSResourceAttributes &value)
 {
-    BundleResource::setAttribute(key, std::move(value));
+    BundleResource::setAttributes(value);
 }
 
-RCSResourceAttributesDiscomfortIndexSensorResource::handleGetAttributesRequest()
+RCSResourceAttributes &DiscomfortIndexSensorResource::handleGetAttributesRequest()
 {
     return BundleResource::getAttributes();
 }
 
-void DiscomfortIndexSensorResource::handleSetAttributesRequest(
-                                     RCSResourceAttributes &value)
-{
-    BundleResource::setAttributes(value);
-}
 void DiscomfortIndexSensorResource::executeLogic()
 {
     std::string strDiscomfortIndex;
@@ -101,4 +90,4 @@ void DiscomfortIndexSensorResource::onUpdatedInputResource(const std::string att
     {
         executeLogic();
     }
-}
+}
\ No newline at end of file
index a433098..40c4aa0 100644 (file)
@@ -42,13 +42,8 @@ namespace OIC
 
                 virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs);
 
-                virtual void handleSetAttributeRequest(const std::string &key,
-                        RCSResourceAttributes::Value &&value);
+                virtual RCSResourceAttributes &handleGetAttributesRequest();
 
-                virtual RCSResourceAttributes::Value handleGetAttributeRequest(
-                        const std::string &key);
-
-                virtual RCSResourceAttributes& handleGetAttributesRequest();
 
             private:
                 std::string m_address;
index c62f367..9b16ac8 100644 (file)
@@ -43,11 +43,11 @@ namespace OIC
                 void deactivateBundle();
 
                 void createResource(resourceInfo resourceInfo);
-                void destroyResource(BundleResource *pBundleResource);
+                void destroyResource(BundleResource::Ptr pBundleResource);
 
                 std::string m_bundleId;
                 ResourceContainerBundleAPI *m_pResourceContainer;
-                std::vector< BundleResource * > m_vecResources;
+                std::vector< BundleResource::Ptr > m_vecResources;
             private:
                 HueConnector *m_connector;
         };
index 4cb223a..6490685 100644 (file)
@@ -44,57 +44,46 @@ HueLight::~HueLight()
 
 void HueLight::initAttributes()
 {
-
     BundleResource::setAttribute("on-off", false);
     BundleResource::setAttribute("dim", 0);
     BundleResource::setAttribute("color", 0);
 }
 
-RCSResourceAttributes::Value HueLight::handleGetAttributeRequest(const std::string &key)
-{
-    cout << "HueLight::getAttribute called for " << key <<  " called" << endl;
-    // TODO read from HueLight and update attribute data
-    return BundleResource::getAttribute(key);
-}
-
-RCSResourceAttributes& HueLight::handleGetAttributesRequest()
+RCSResourceAttributes &HueLight::handleGetAttributesRequest()
 {
-    cout << "HueLight::getAttributes" << endl;
+    cout << "HueLight::handleGetAttributesRequest" << endl;
     // TODO read from HueLight and update attribute data
     return BundleResource::getAttributes();
 }
 
-void HueLight::handleSetAttributeRequest(const std::string &attributeName, RCSResourceAttributes::Value &&value)
+void HueLight::handleSetAttributesRequest(RCSResourceAttributes &value)
 {
-    cout << "HueLight::setAttribute setting " << attributeName << " to " << value.toString() <<
-         std::endl;
+    cout << "HueLight::handleSetAttributesRequest" << std::endl;
 
-    if (attributeName == "on-off")
-    {
-        m_connector->transmit(this->m_address + "/state", "{\"on\":" + value.toString() + "}");
-    }
-
-    if (attributeName == "dim")
-    {
-        // needs conversion * 2.5
-        m_connector->transmit(this->m_address + "/state", "{\"bri\":" + value.toString() + "}");
-    }
+    // TODO construct single write
 
-    if (attributeName == "color")
+    for (RCSResourceAttributes::iterator it = value.begin(); it != value.end(); it++)
     {
-        // needs conversion *650
-        m_connector->transmit(this->m_address + "/state", "{\"hue\":" + value.toString()   + "}");
+        std::string attributeName = it->key();
+        RCSResourceAttributes::Value attrValue = it->value();
+
+        if (attributeName == "on-off")
+        {
+            m_connector->transmit(this->m_address + "/state", "{\"on\":" + attrValue.toString() + "}");
+        }
+
+        if (attributeName == "dim")
+        {
+            // needs conversion * 2.5
+            m_connector->transmit(this->m_address + "/state", "{\"bri\":" + attrValue.toString() + "}");
+        }
+
+        if (attributeName == "color")
+        {
+            // needs conversion *650
+            m_connector->transmit(this->m_address + "/state", "{\"hue\":" + attrValue.toString() + "}");
+        }
     }
 
-    BundleResource::setAttribute(attributeName, std::move(value));
-}
-
-void HueLight::handleSetAttributesRequest(RCSResourceAttributes &value)
-{
-    cout << "HueLight::setAttributes "<< std::endl;
-
-    // TODO construct single write
-
     BundleResource::setAttributes(value);
-}
-
+}
\ No newline at end of file
index a7348f0..2cb696f 100644 (file)
@@ -63,7 +63,7 @@ void HueSampleBundleActivator::deactivateBundle()
 {
     std::cout << "HueSampleBundle::deactivateBundle called" << std::endl;
 
-    std::vector<BundleResource *>::iterator itor;
+    std::vector< BundleResource::Ptr >::iterator itor;
     for (itor = m_vecResources.begin(); itor != m_vecResources.end();)
     {
         destroyResource(*itor);
@@ -78,7 +78,7 @@ void HueSampleBundleActivator::createResource(resourceInfo resourceInfo)
     if (resourceInfo.resourceType == "oic.r.light")
     {
         static int lightCount = 1;
-        HueLight *hueLight = new HueLight(m_connector, resourceInfo.address);
+        BundleResource::Ptr hueLight = std::make_shared< HueLight >(m_connector, resourceInfo.address);
         resourceInfo.uri = "/hue/light/" + std::to_string(lightCount++);
         std::cout << "Registering resource " << resourceInfo.uri << std::endl;
         hueLight->m_bundleId = m_bundleId;
@@ -91,11 +91,11 @@ void HueSampleBundleActivator::createResource(resourceInfo resourceInfo)
     }
 }
 
-void HueSampleBundleActivator::destroyResource(BundleResource *pBundleResource)
+void HueSampleBundleActivator::destroyResource(BundleResource::Ptr pBundleResource)
 {
     std::cout << "HueSampleBundle::destroyResource called" << pBundleResource->m_uri << std::endl;
 
-    std::vector< BundleResource * >::iterator itor;
+    std::vector< BundleResource::Ptr >::iterator itor;
 
     itor = std::find(m_vecResources.begin(), m_vecResources.end(), pBundleResource);
 
@@ -124,7 +124,7 @@ extern "C" void huesample_externalCreateResource(resourceInfo resourceInfo)
     bundle->createResource(resourceInfo);
 }
 
-extern "C" void huesample_externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void huesample_externalDestroyResource(BundleResource::Ptr pBundleResource)
 {
     bundle->destroyResource(pBundleResource);
 }
index e34c2e3..13337bf 100644 (file)
@@ -26,7 +26,7 @@
 #include "ResourceContainerBundleAPI.h"
 
 #if (JAVA_SUPPORT)
-    #include "jni.h"
+#include "jni.h"
 #endif
 
 using namespace std;
@@ -39,7 +39,7 @@ namespace OIC
         typedef void activator_t(ResourceContainerBundleAPI *, std::string bundleId);
         typedef void deactivator_t(void);
         typedef void resourceCreator_t(resourceInfo resourceInfo);
-        typedef void resourceDestroyer_t(BundleResource *pBundleResource);
+        typedef void resourceDestroyer_t(BundleResource::Ptr pBundleResource);
 
         class BundleInfoInternal: public RCSBundleInfo
         {
index 93cdf4d..5dbcc32 100644 (file)
@@ -65,8 +65,8 @@ namespace OIC
                 void unregisterBundleSo(const std::string &id);
 
                 // methods from ResourceContainerBundleAPI
-                void registerResource(BundleResource *resource);
-                void unregisterResource(BundleResource *resource);
+                void registerResource(BundleResource::Ptr resource);
+                void unregisterResource(BundleResource::Ptr resource);
 
                 void getBundleConfiguration(const std::string &bundleId, configInfo *configOutput);
                 void getResourceConfiguration(const std::string &bundleId,
@@ -107,7 +107,7 @@ namespace OIC
             private:
                 map< std::string, BundleInfoInternal * > m_bundles; // <bundleID, bundleInfo>
                 map< std::string, RCSResourceObject::Ptr > m_mapServers; //<uri, serverPtr>
-                map< std::string, BundleResource * > m_mapResources; //<uri, resourcePtr>
+                map< std::string, BundleResource::Ptr > m_mapResources; //<uri, resourcePtr>
                 map< std::string, list< string > > m_mapBundleResources; //<bundleID, vector<uri>>
                 map< std::string, list< DiscoverResourceUnit::Ptr > > m_mapDiscoverResourceUnits;
                 //<uri, DiscoverUnit>
index 0344e68..93c255f 100644 (file)
@@ -64,12 +64,15 @@ namespace OIC
         {
             for (RCSResourceAttributes::iterator it = attrs.begin(); it != attrs.end(); ++it)
             {
+                OC_LOG_V(INFO, CONTAINER_TAG, "set attribute \(%s)'",
+                         std::string(it->key() + "\', with " + it->value().toString()).c_str());
+
                 m_resourceAttributes[it->key()] = it->value();
             }
         }
 
         void BundleResource::setAttribute(const std::string &key,
-                RCSResourceAttributes::Value &&value, bool notify)
+                                          RCSResourceAttributes::Value &&value, bool notify)
         {
             OC_LOG_V(INFO, CONTAINER_TAG, "set attribute \(%s)'", std::string(key + "\', with " +
                      value.toString()).c_str());
@@ -80,7 +83,8 @@ namespace OIC
                 m_pNotiReceiver->onNotificationReceived(m_uri);
         }
 
-        void BundleResource::setAttribute(const std::string &key, RCSResourceAttributes::Value &&value){
+        void BundleResource::setAttribute(const std::string &key, RCSResourceAttributes::Value &&value)
+        {
             setAttribute(key, std::move(value), true);
         }
 
@@ -90,25 +94,5 @@ namespace OIC
 
             return m_resourceAttributes.at(key);
         }
-
-        RCSResourceAttributes::Value BundleResource::handleGetAttributeRequest(const std::string &key)
-        {
-            return BundleResource::getAttribute(key);
-        }
-
-        void BundleResource::handleSetAttributeRequest(const std::string &key, RCSResourceAttributes::Value &&value)
-        {
-            BundleResource::setAttribute(key, std::move(value));
-        }
-
-        RCSResourceAttributes& BundleResource::handleGetAttributesRequest()
-        {
-            return BundleResource::getAttributes();
-        }
-
-        void BundleResource::handleSetAttributesRequest(RCSResourceAttributes &value)
-        {
-            BundleResource::setAttributes(value);
-        }
     }
 }
index c935508..cc761ab 100644 (file)
@@ -256,14 +256,14 @@ namespace OIC
             }
         }
 
-        void ResourceContainerImpl::registerResource(BundleResource *resource)
+        void ResourceContainerImpl::registerResource(BundleResource::Ptr resource)
         {
             string strUri = resource->m_uri;
             string strResourceType = resource->m_resourceType;
             RCSResourceObject::Ptr server = nullptr;
 
-            OC_LOG_V(INFO, CONTAINER_TAG, "Registration of resource (%s)" , std::string(strUri + ", " +
-                     strResourceType).c_str());
+            OC_LOG_V(INFO, CONTAINER_TAG, "Registration of resource (%s)" ,
+                     std::string(strUri + ", " + strResourceType).c_str());
 
             registrationLock.lock();
             if (m_mapResources.find(strUri) == m_mapResources.end())
@@ -304,7 +304,7 @@ namespace OIC
             registrationLock.unlock();
         }
 
-        void ResourceContainerImpl::unregisterResource(BundleResource *resource)
+        void ResourceContainerImpl::unregisterResource(BundleResource::Ptr resource)
         {
             string strUri = resource->m_uri;
             string strResourceType = resource->m_resourceType;
@@ -358,7 +358,7 @@ namespace OIC
                 {
                     auto getFunction = [this, &attr, &strResourceUri]()
                     {
-                        attr = m_mapResources[strResourceUri]->getAttributes();
+                        attr = m_mapResources[strResourceUri]->handleGetAttributesRequest();
                     };
                     boost::thread getThread(getFunction);
                     getThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
@@ -713,7 +713,7 @@ namespace OIC
                             DiscoverResourceUnit::DiscoverResourceInfo(uri, type,
                                     attributeName),
                             std::bind(&SoftSensorResource::onUpdatedInputResource,
-                                      (SoftSensorResource *) foundOutputResource->second,
+                                      std::static_pointer_cast< SoftSensorResource > (foundOutputResource->second),
                                       std::placeholders::_1, std::placeholders::_2));
 
                         auto foundDiscoverResource = m_mapDiscoverResourceUnits.find(
index b37d384..d867888 100644 (file)
@@ -76,23 +76,17 @@ void getCurrentPath(std::string *pPath)
 class TestBundleResource: public BundleResource
 {
     public:
-        string getAttribute(string attributeName)
-        {
-            (void)attributeName;
-            return "test";
-        }
-        ;
-        void setAttribute(string attributeName, string value)
+        virtual void initAttributes() { }
+
+        virtual void handleSetAttributesRequest(RCSResourceAttributes &attr)
         {
-            (void)attributeName;
-            (void)value;
+            BundleResource::setAttributes(attr);
         }
-        ;
-        void initAttributes()
+
+        virtual RCSResourceAttributes &handleGetAttributesRequest()
         {
-            BundleResource::setAttribute("attri", "test");
+            return BundleResource::getAttributes();
         }
-        ;
 };
 
 class ResourceContainerTest: public TestWithMock
@@ -269,7 +263,7 @@ class ResourceContainerBundleAPITest: public TestWithMock
     public:
         RCSResourceObject *m_pResourceObject;
         ResourceContainerBundleAPI *m_pResourceContainer;
-        TestBundleResource *m_pBundleResource;
+        BundleResource::Ptr m_pBundleResource;
         std::string m_strConfigPath;
 
     protected:
@@ -283,7 +277,7 @@ class ResourceContainerBundleAPITest: public TestWithMock
             m_strConfigPath.append("/");
             m_strConfigPath.append(CONFIG_FILE);
 
-            m_pBundleResource = new TestBundleResource();
+            m_pBundleResource = std::make_shared< TestBundleResource >();
             m_pBundleResource->m_bundleId = "oic.bundle.test";
             m_pBundleResource->m_uri = "/test_resource";
             m_pBundleResource->m_resourceType = "container.test";
@@ -292,7 +286,7 @@ class ResourceContainerBundleAPITest: public TestWithMock
 
 TEST_F(ResourceContainerBundleAPITest, ResourceServerCreatedWhenRegisterResourceCalled)
 {
-    m_pBundleResource = new TestBundleResource();
+    m_pBundleResource = std::make_shared< TestBundleResource >();
     m_pBundleResource->m_bundleId = "oic.bundle.test";
     m_pBundleResource->m_uri = "/test_resource/test";
     m_pBundleResource->m_resourceType = "container.test";
index 69f3729..0bbbf9c 100644 (file)
@@ -39,11 +39,11 @@ class TestBundleActivator : public BundleActivator
         void deactivateBundle();
 
         void createResource(resourceInfo resourceInfo);
-        void destroyResource(BundleResource *pBundleResource);
+        void destroyResource(BundleResource::Ptr pBundleResource);
 
         ResourceContainerBundleAPI *m_pResourceContainer;
         std::string m_bundleId;
-        BundleResource *m_pTestResource;
+        BundleResource::Ptr m_pTestResource;
 };
 
 /*Fake bundle resource class for testing*/
@@ -52,28 +52,16 @@ class TestBundleResource : public BundleResource
     public:
         void initAttributes() { };
 
-        RCSResourceAttributes::Value handleGetAttributeRequest(
-                const std::string &key)
-        {
-            return BundleResource::getAttribute(key);
-        }
-
-        void handleSetAttributeRequest(const std::string &key,
-                                             RCSResourceAttributes::Value &&value)
-        {
-            BundleResource::setAttribute(key, std::move(value));
-        }
-
-        RCSResourceAttributes& handleGetAttributesRequest()
+        RCSResourceAttributes &handleGetAttributesRequest()
         {
             return BundleResource::getAttributes();
         }
 
         void handleSetAttributesRequest(
-                                             RCSResourceAttributes &value)
+            RCSResourceAttributes &value)
         {
             BundleResource::setAttributes(value);
         }
 };
 
-#endif /* TESTBUNDLE_H_ */
+#endif /* TESTBUNDLE_H_ */
\ No newline at end of file
index 8d5c965..57d267f 100644 (file)
@@ -52,7 +52,7 @@ void TestBundleActivator::createResource(resourceInfo resourceInfo)
 {
     std::cout << "TestBundleActivator::createResource .. " << std::endl;
 
-    TestBundleResource *m_pTestResource = new TestBundleResource();
+    m_pTestResource = std::make_shared< TestBundleResource >();
 
     m_pTestResource->m_bundleId = m_bundleId;
     m_pTestResource->m_uri = resourceInfo.uri;
@@ -61,7 +61,7 @@ void TestBundleActivator::createResource(resourceInfo resourceInfo)
     m_pResourceContainer->registerResource(m_pTestResource);
 }
 
-void TestBundleActivator::destroyResource(BundleResource *pBundleResource)
+void TestBundleActivator::destroyResource(BundleResource::Ptr pBundleResource)
 {
     std::cout << "TestBundleActivator::destroyResource .. " << std::endl;
 
@@ -69,7 +69,7 @@ void TestBundleActivator::destroyResource(BundleResource *pBundleResource)
 }
 
 extern "C" void test_externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
-                                       std::string bundleId)
+        std::string bundleId)
 {
     bundle = new TestBundleActivator();
     bundle->activateBundle(resourceContainer, bundleId);
@@ -86,7 +86,7 @@ extern "C" void test_externalCreateResource(resourceInfo resourceInfo)
     bundle->createResource(resourceInfo);
 }
 
-extern "C" void test_externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void test_externalDestroyResource(BundleResource::Ptr pBundleResource)
 {
     bundle->destroyResource(pBundleResource);
 }