From d99518e71b54793449ef7a7c5477396f200950bd Mon Sep 17 00:00:00 2001 From: Inga Stotland Date: Thu, 12 May 2016 13:34:37 -0700 Subject: [PATCH] [IOT-1095] Add request parameters to attribute handlers API change: allow passing query parameters to attribute GET/SET handlers. Change-Id: Ib3d294a4901f066409a837f03db16a94791fd8f8 Signed-off-by: Inga Stotland Reviewed-on: https://gerrit.iotivity.org/gerrit/8121 Tested-by: jenkins-iotivity Reviewed-by: Markus Jung --- .../src/main/jni/JniBundleResource.cpp | 7 +++++-- .../src/main/jni/JniBundleResource.h | 6 ++++-- .../bundle-api/include/BundleResource.h | 10 ++++++++-- .../bundle-api/include/ProtocolBridgeResource.h | 9 +++++++-- .../bundle-api/include/SoftSensorResource.h | 9 +++++++-- .../BMISensorBundle/include/BMISensorResource.h | 6 ++++-- .../BMISensorBundle/src/BMISensorResource.cpp | 6 ++++-- .../include/DiscomfortIndexSensorResource.h | 6 ++++-- .../src/DiscomfortIndexSensorResource.cpp | 6 ++++-- .../examples/HueSampleBundle/include/HueLight.h | 7 ++++--- .../examples/HueSampleBundle/src/HueLight.cpp | 6 ++++-- .../src/ResourceContainerImpl.cpp | 11 +++++++---- .../unittests/ResourceContainerTest.cpp | 23 ++++++++++++++-------- .../TestBundle/include/TestBundleActivator.h | 6 ++++-- 14 files changed, 81 insertions(+), 37 deletions(-) diff --git a/service/resource-container/android/resource-container/src/main/jni/JniBundleResource.cpp b/service/resource-container/android/resource-container/src/main/jni/JniBundleResource.cpp index 1bed71c..ddabc5f 100644 --- a/service/resource-container/android/resource-container/src/main/jni/JniBundleResource.cpp +++ b/service/resource-container/android/resource-container/src/main/jni/JniBundleResource.cpp @@ -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"); diff --git a/service/resource-container/android/resource-container/src/main/jni/JniBundleResource.h b/service/resource-container/android/resource-container/src/main/jni/JniBundleResource.h index 7530db2..9464b06 100644 --- a/service/resource-container/android/resource-container/src/main/jni/JniBundleResource.h +++ b/service/resource-container/android/resource-container/src/main/jni/JniBundleResource.h @@ -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. diff --git a/service/resource-container/bundle-api/include/BundleResource.h b/service/resource-container/bundle-api/include/BundleResource.h index 23e9f85..d24e9b4 100644 --- a/service/resource-container/bundle-api/include/BundleResource.h +++ b/service/resource-container/bundle-api/include/BundleResource.h @@ -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); diff --git a/service/resource-container/bundle-api/include/ProtocolBridgeResource.h b/service/resource-container/bundle-api/include/ProtocolBridgeResource.h index 8ec6b87..bc846e4 100644 --- a/service/resource-container/bundle-api/include/ProtocolBridgeResource.h +++ b/service/resource-container/bundle-api/include/ProtocolBridgeResource.h @@ -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; }; } } diff --git a/service/resource-container/bundle-api/include/SoftSensorResource.h b/service/resource-container/bundle-api/include/SoftSensorResource.h index c48e72a..3cabeaa 100644 --- a/service/resource-container/bundle-api/include/SoftSensorResource.h +++ b/service/resource-container/bundle-api/include/SoftSensorResource.h @@ -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. diff --git a/service/resource-container/examples/BMISensorBundle/include/BMISensorResource.h b/service/resource-container/examples/BMISensorBundle/include/BMISensorResource.h index dcdca42..a5bc7c7 100644 --- a/service/resource-container/examples/BMISensorBundle/include/BMISensorResource.h +++ b/service/resource-container/examples/BMISensorBundle/include/BMISensorResource.h @@ -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(); diff --git a/service/resource-container/examples/BMISensorBundle/src/BMISensorResource.cpp b/service/resource-container/examples/BMISensorBundle/src/BMISensorResource.cpp index a9ae815..e9e79de 100644 --- a/service/resource-container/examples/BMISensorBundle/src/BMISensorResource.cpp +++ b/service/resource-container/examples/BMISensorBundle/src/BMISensorResource.cpp @@ -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(); } diff --git a/service/resource-container/examples/DiscomfortIndexSensorBundle/include/DiscomfortIndexSensorResource.h b/service/resource-container/examples/DiscomfortIndexSensorBundle/include/DiscomfortIndexSensorResource.h index 17edfcb..ddcd181 100644 --- a/service/resource-container/examples/DiscomfortIndexSensorBundle/include/DiscomfortIndexSensorResource.h +++ b/service/resource-container/examples/DiscomfortIndexSensorBundle/include/DiscomfortIndexSensorResource.h @@ -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(); diff --git a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp index 4817ae9..05980ab 100644 --- a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp +++ b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp @@ -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(); } diff --git a/service/resource-container/examples/HueSampleBundle/include/HueLight.h b/service/resource-container/examples/HueSampleBundle/include/HueLight.h index 1aa0835..11fce9c 100644 --- a/service/resource-container/examples/HueSampleBundle/include/HueLight.h +++ b/service/resource-container/examples/HueSampleBundle/include/HueLight.h @@ -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; diff --git a/service/resource-container/examples/HueSampleBundle/src/HueLight.cpp b/service/resource-container/examples/HueSampleBundle/src/HueLight.cpp index ba77414..9a3f81d 100644 --- a/service/resource-container/examples/HueSampleBundle/src/HueLight.cpp +++ b/service/resource-container/examples/HueSampleBundle/src/HueLight.cpp @@ -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; diff --git a/service/resource-container/src/ResourceContainerImpl.cpp b/service/resource-container/src/ResourceContainerImpl.cpp index 5042f0c..93be5f9 100644 --- a/service/resource-container/src/ResourceContainerImpl.cpp +++ b/service/resource-container/src/ResourceContainerImpl.cpp @@ -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 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)); diff --git a/service/resource-container/unittests/ResourceContainerTest.cpp b/service/resource-container/unittests/ResourceContainerTest.cpp index 7d00a9b..eb4849a 100644 --- a/service/resource-container/unittests/ResourceContainerTest.cpp +++ b/service/resource-container/unittests/ResourceContainerTest.cpp @@ -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); diff --git a/service/resource-container/unittests/TestBundle/include/TestBundleActivator.h b/service/resource-container/unittests/TestBundle/include/TestBundleActivator.h index dd91058..4f39b21 100644 --- a/service/resource-container/unittests/TestBundle/include/TestBundleActivator.h +++ b/service/resource-container/unittests/TestBundle/include/TestBundleActivator.h @@ -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); } -- 2.7.4