[IOT-1095] Add request parameters to attribute handlers
authorInga Stotland <inga.stotland@intel.com>
Thu, 12 May 2016 20:34:37 +0000 (13:34 -0700)
committerMarkus Jung <markus.jung85@gmail.com>
Fri, 20 May 2016 07:12:18 +0000 (07:12 +0000)
API change: allow passing query parameters to attribute GET/SET handlers.

Change-Id: Ib3d294a4901f066409a837f03db16a94791fd8f8
Signed-off-by: Inga Stotland <inga.stotland@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8121
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Markus Jung <markus.jung85@gmail.com>
14 files changed:
service/resource-container/android/resource-container/src/main/jni/JniBundleResource.cpp
service/resource-container/android/resource-container/src/main/jni/JniBundleResource.h
service/resource-container/bundle-api/include/BundleResource.h
service/resource-container/bundle-api/include/ProtocolBridgeResource.h
service/resource-container/bundle-api/include/SoftSensorResource.h
service/resource-container/examples/BMISensorBundle/include/BMISensorResource.h
service/resource-container/examples/BMISensorBundle/src/BMISensorResource.cpp
service/resource-container/examples/DiscomfortIndexSensorBundle/include/DiscomfortIndexSensorResource.h
service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp
service/resource-container/examples/HueSampleBundle/include/HueLight.h
service/resource-container/examples/HueSampleBundle/src/HueLight.cpp
service/resource-container/src/ResourceContainerImpl.cpp
service/resource-container/unittests/ResourceContainerTest.cpp
service/resource-container/unittests/TestBundle/include/TestBundleActivator.h

index 1bed71c..ddabc5f 100644 (file)
@@ -194,7 +194,9 @@ void JniBundleResource::handleSetAttributeRequest(const std::string &attributeNa
 }
 
 
-void JniBundleResource::handleSetAttributesRequest(const RCSResourceAttributes &attrs){
+void JniBundleResource::handleSetAttributesRequest(const RCSResourceAttributes &attrs,
+        const std::map< std::string, std::string > &queryParams)
+{
     LOGD("handleSetAttributesRequest called %d", attrs.size());
 
     //m_env->CallObjectMethod(m_bundleResource, m_attributeSetRequestHandler, attrName, val);
@@ -222,7 +224,8 @@ void JniBundleResource::handleSetAttributesRequest(const RCSResourceAttributes &
     }
 }
 
-RCSResourceAttributes JniBundleResource::handleGetAttributesRequest()
+RCSResourceAttributes JniBundleResource::handleGetAttributesRequest(const
+        std::map< std::string, std::string > &queryParams)
 {
     LOGD("handleGetAttributesRequest");
 
index 7530db2..9464b06 100644 (file)
@@ -54,9 +54,11 @@ namespace OIC
 
             RCSResourceAttributes::Value handleGetAttributeRequest(const std::string& key);
 
-            virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs);
+            virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs,
+                                                    const std::map< std::string, std::string > &queryParams);
 
-            virtual RCSResourceAttributes handleGetAttributesRequest();
+            virtual RCSResourceAttributes handleGetAttributesRequest(const
+                         std::map< std::string, std::string > &queryParams);
 
             /**
             * SoftSensor logic. Has to be provided by the soft sensor developer.
index 23e9f85..d24e9b4 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "NotificationReceiver.h"
 #include "RCSResourceAttributes.h"
+#include "RCSRequest.h"
 
 namespace OIC
 {
@@ -168,9 +169,12 @@ namespace OIC
                 * The implementor of the function can decide weather to notify OIC clients
                 * about the changed state or not.
                 *
+                * @param queryParams Request parameters
+                *
                 * @return All attributes
                 */
-                virtual RCSResourceAttributes handleGetAttributesRequest() = 0;
+                virtual RCSResourceAttributes handleGetAttributesRequest(const
+                        std::map< std::string, std::string > &queryParams) = 0;
 
                 /**
                 * This function should be implemented by the according bundle resource
@@ -185,10 +189,12 @@ namespace OIC
                 * about the changed state or not.
                 *
                 * @param attrs Attributes to set
+                * @param queryParams Request parameters
                 *
                 * @return void
                 */
-                virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs) = 0;
+                virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs,
+                                                        const std::map< std::string, std::string > &queryParams) = 0;
             private:
 
                 void sendNotification(NotificationReceiver *notficiationRecevier, std::string uri);
index 8ec6b87..bc846e4 100644 (file)
@@ -65,9 +65,12 @@ namespace OIC
                 * The implementor of the function can decide weather to notify OIC clients
                 * about the changed state or not.
                 *
+                * @param queryParams Request parameters
+                *
                 * @return Value of all attributes
                 */
-                virtual RCSResourceAttributes handleGetAttributesRequest() = 0;
+                virtual RCSResourceAttributes handleGetAttributesRequest(const
+                        std::map< std::string, std::string > &queryParams) = 0;
 
                 /**
                 * This function should be implemented by the according bundle resource
@@ -82,10 +85,12 @@ namespace OIC
                 * about the changed state or not.
                 *
                 * @param attrs Attributes to set
+                * @param queryParams Request parameters
                 *
                 * @return void
                 */
-                virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs) = 0;
+                virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs,
+                                                        const std::map< std::string, std::string > &queryParams) = 0;
         };
     }
 }
index c48e72a..3cabeaa 100644 (file)
@@ -62,9 +62,12 @@ namespace OIC
                 * The implementor of the function can decide weather to notify OIC clients
                 * about the changed state or not.
                 *
+                * @param queryParams Request parameters
+                *
                 * @return Value of all attributes
                 */
-                virtual RCSResourceAttributes handleGetAttributesRequest() = 0;
+                virtual RCSResourceAttributes handleGetAttributesRequest(const
+                        std::map< std::string, std::string > &queryParams) = 0;
 
                 /**
                 * This function should be implemented by the according bundle resource
@@ -79,10 +82,12 @@ namespace OIC
                 * about the changed state or not.
                 *
                 * @param attrs Attributes to set
+                * @param queryParams Request parameters
                 *
                 * @return void
                 */
-                virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs) = 0;
+                virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs,
+                                                        const std::map< std::string, std::string > &queryParams) = 0;
 
                 /**
                 * SoftSensor logic. Has to be provided by the soft sensor developer.
index dcdca42..a5bc7c7 100644 (file)
@@ -35,9 +35,11 @@ class BMISensorResource : public SoftSensorResource
         BMISensorResource& operator=( const BMISensorResource& rhs )=delete;
         ~BMISensorResource();
 
-        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs);
+        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs,
+                                                const std::map< std::string, std::string > &queryParams);
 
-        virtual RCSResourceAttributes handleGetAttributesRequest();
+        virtual RCSResourceAttributes handleGetAttributesRequest(const
+                std::map< std::string, std::string > &queryParams);
 
         virtual void executeLogic();
 
index a9ae815..e9e79de 100644 (file)
@@ -32,12 +32,14 @@ BMISensorResource::~BMISensorResource()
 }
 
 void BMISensorResource::handleSetAttributesRequest(
-    const RCSResourceAttributes &value)
+    const RCSResourceAttributes &value,
+    const std::map< std::string, std::string > &queryParams)
 {
     BundleResource::setAttributes(value);
 }
 
-RCSResourceAttributes BMISensorResource::handleGetAttributesRequest()
+RCSResourceAttributes BMISensorResource::handleGetAttributesRequest(const
+        std::map< std::string, std::string > &queryParams)
 {
     return BundleResource::getAttributes();
 }
index 17edfcb..ddcd181 100644 (file)
@@ -35,9 +35,11 @@ class DiscomfortIndexSensorResource : public SoftSensorResource
         DiscomfortIndexSensorResource(const DiscomfortIndexSensorResource &other)=delete;
         DiscomfortIndexSensorResource& operator=( const DiscomfortIndexSensorResource& rhs )=delete;
 
-        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs);
+        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs,
+                                                const std::map< std::string, std::string > &queryParams);
 
-        virtual RCSResourceAttributes handleGetAttributesRequest();
+        virtual RCSResourceAttributes handleGetAttributesRequest(const
+                std::map< std::string, std::string > &queryParams);
 
         virtual void executeLogic();
 
index 4817ae9..05980ab 100644 (file)
@@ -35,12 +35,14 @@ DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource()
 }
 
 void DiscomfortIndexSensorResource::handleSetAttributesRequest(
-    const RCSResourceAttributes &value)
+    const RCSResourceAttributes &value,
+    const std::map< std::string, std::string > &queryParams)
 {
     BundleResource::setAttributes(value);
 }
 
-RCSResourceAttributes DiscomfortIndexSensorResource::handleGetAttributesRequest()
+RCSResourceAttributes DiscomfortIndexSensorResource::handleGetAttributesRequest(
+    const std::map< std::string, std::string > &queryParams)
 {
     return BundleResource::getAttributes();
 }
index 1aa0835..11fce9c 100644 (file)
@@ -40,10 +40,11 @@ namespace OIC
 
                 virtual void initAttributes();
 
-                virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs);
-
-                virtual RCSResourceAttributes handleGetAttributesRequest();
+                virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs,
+                                                        const std::map< std::string, std::string > &queryParams);
 
+                virtual RCSResourceAttributes handleGetAttributesRequest(const
+                        std::map< std::string, std::string > &queryParams);
 
             private:
                 std::string m_address;
index ba77414..9a3f81d 100644 (file)
@@ -49,14 +49,16 @@ void HueLight::initAttributes()
     BundleResource::setAttribute("color", 0, false);
 }
 
-RCSResourceAttributes HueLight::handleGetAttributesRequest()
+RCSResourceAttributes HueLight::handleGetAttributesRequest(
+    const std::map< std::string, std::string > &queryParams)
 {
     cout << "HueLight::handleGetAttributesRequest" << endl;
     // TODO read from HueLight and update attribute data
     return BundleResource::getAttributes();
 }
 
-void HueLight::handleSetAttributesRequest(const RCSResourceAttributes &value)
+void HueLight::handleSetAttributesRequest(const RCSResourceAttributes &value,
+                                          const std::map< std::string, std::string > &queryParams)
 {
     cout << "HueLight::handleSetAttributesRequest" << std::endl;
 
index 5042f0c..93be5f9 100644 (file)
@@ -405,6 +405,8 @@ namespace OIC
         {
             RCSResourceAttributes attr;
             std::string strResourceUri = request.getResourceUri();
+            const std::map< std::string, std::string > &queryParams  = request.getQueryParams();
+
             OIC_LOG_V(INFO, CONTAINER_TAG, "Container get request for %s",strResourceUri.c_str());
 
             if (m_mapServers.find(strResourceUri) != m_mapServers.end()
@@ -412,9 +414,9 @@ namespace OIC
             {
                 if (m_mapResources[strResourceUri])
                 {
-                    auto getFunction = [this, &attr, &strResourceUri]()
+                    auto getFunction = [this, &attr, &strResourceUri, queryParams]()
                     {
-                        attr = m_mapResources[strResourceUri]->handleGetAttributesRequest();
+                        attr = m_mapResources[strResourceUri]->handleGetAttributesRequest(queryParams);
                     };
                     boost::thread getThread(getFunction);
                     getThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
@@ -432,6 +434,7 @@ namespace OIC
             RCSResourceAttributes attr;
             std::list<std::string> lstAttributes;
             std::string strResourceUri = request.getResourceUri();
+            const std::map< std::string, std::string > &queryParams  = request.getQueryParams();
 
             OIC_LOG_V(INFO, CONTAINER_TAG, "Container set request for %s, %zu attributes",strResourceUri.c_str(), attributes.size());
 
@@ -440,7 +443,7 @@ namespace OIC
             {
                 if (m_mapResources[strResourceUri])
                 {
-                    auto setFunction = [this, &lstAttributes, &strResourceUri, &attributes, &attr]()
+                    auto setFunction = [this, &lstAttributes, &strResourceUri, &attributes, &attr, queryParams]()
                     {
                         lstAttributes = m_mapResources[strResourceUri]->getAttributeNames();
 
@@ -455,7 +458,7 @@ namespace OIC
                         }
 
                         OIC_LOG_V(INFO, CONTAINER_TAG, "Calling handleSetAttributeRequest");
-                        m_mapResources[strResourceUri]->handleSetAttributesRequest(attr);
+                        m_mapResources[strResourceUri]->handleSetAttributesRequest(attr, queryParams);
                     };
                     boost::thread setThread(setFunction);
                     setThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
index 7d00a9b..eb4849a 100644 (file)
@@ -100,12 +100,14 @@ class TestBundleResource: public BundleResource
     public:
         virtual void initAttributes() { }
 
-        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attr)
+        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attr,
+                                                const std::map< std::string, std::string > &queryParams)
         {
             BundleResource::setAttributes(attr);
         }
 
-        virtual RCSResourceAttributes handleGetAttributesRequest()
+        virtual RCSResourceAttributes handleGetAttributesRequest(const
+                std::map< std::string, std::string > &queryParams)
         {
             return BundleResource::getAttributes();
         }
@@ -121,12 +123,14 @@ class TestBundleResourceWithAttrs: public BundleResource
             setAttribute("attrib3", RCSResourceAttributes::Value(true));
         }
 
-        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attr)
+        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attr,
+                                                const std::map< std::string, std::string > &queryParams)
         {
             BundleResource::setAttributes(attr);
         }
 
-        virtual RCSResourceAttributes handleGetAttributesRequest()
+        virtual RCSResourceAttributes handleGetAttributesRequest(const
+                std::map< std::string, std::string > &queryParams)
         {
             return BundleResource::getAttributes();
         }
@@ -141,12 +145,14 @@ class TestSoftSensorResource: public SoftSensorResource
             SoftSensorResource::initAttributes();
         }
 
-        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attr)
+        virtual void handleSetAttributesRequest(const RCSResourceAttributes &attr,
+                                                const std::map< std::string, std::string > &queryParams)
         {
             BundleResource::setAttributes(attr);
         }
 
-        virtual RCSResourceAttributes handleGetAttributesRequest()
+        virtual RCSResourceAttributes handleGetAttributesRequest(const
+                 std::map< std::string, std::string > &queryParams)
         {
             return BundleResource::getAttributes();
         }
@@ -195,6 +201,7 @@ TEST_F(ResourceContainerTest, TestBundleResource)
     testResource.getAttributeNames();
 
     RCSResourceAttributes fullAttributes;
+    const std::map< std::string, std::string > queryParams = {};
 
     fullAttributes["attrib1"] = "test";
     fullAttributes["attrib2"] = 1;
@@ -208,11 +215,11 @@ TEST_F(ResourceContainerTest, TestBundleResource)
     fullAttributes["attrib2"] = 2;
     fullAttributes["attrib3"] = false;
 
-    testResource.handleSetAttributesRequest(fullAttributes);
+    testResource.handleSetAttributesRequest(fullAttributes, queryParams);
 
     EXPECT_EQ((unsigned int) 3, testResource.getAttributeNames().size());
 
-    EXPECT_EQ((unsigned int) 3, testResource.handleGetAttributesRequest().size());
+    EXPECT_EQ((unsigned int) 3, testResource.handleGetAttributesRequest(queryParams).size());
     std::string testString = "test";
     testResource.setAttribute("attrib1", RCSResourceAttributes::Value(testString), false);
 
index dd91058..4f39b21 100644 (file)
@@ -52,13 +52,15 @@ class TestBundleResource : public BundleResource
     public:
         void initAttributes() { };
 
-        RCSResourceAttributes handleGetAttributesRequest()
+        RCSResourceAttributes handleGetAttributesRequest(
+            const std::map< std::string, std::string > &queryParams)
         {
             return BundleResource::getAttributes();
         }
 
         void handleSetAttributesRequest(
-            const RCSResourceAttributes &value)
+            const RCSResourceAttributes &value,
+            const std::map< std::string, std::string > &queryParams)
         {
             BundleResource::setAttributes(value);
         }