virtual void initAttributes() = 0;
/**
- * Register notification receiver(resource container) to notify for the changes of attributes
+ * Register notification receiver(resource container) to notify for the
+ * changes of attributes
*
- * @param pNotiReceiver Notification Receiver to get notification from bundle resource
+ * @param pNotiReceiver Notification Receiver to get notification from
+ * bundle resource
*
* @return void
*/
*
* @return Attributes of the resource
*/
- virtual RCSResourceAttributes &getAttributes();
+ RCSResourceAttributes &getAttributes();
/**
* Set attributes of the resource
*
* @return void
*/
- virtual void setAttributes(RCSResourceAttributes &attrs);
+ void setAttributes(RCSResourceAttributes &attrs);
/**
* Execute the logic of bundle to get the value of attribute
*
* @return Value of the attribute
*/
- virtual RCSResourceAttributes::Value getAttribute(const std::string &key);
+ RCSResourceAttributes::Value getAttribute(const std::string &key);
/**
- * Execute the logic of bundle to set the value of attribute
+ * Sets the value of an attribute
*
* @param key Name of attribute to set
*
* @param value Value of attribute to set
*
+ * @param notify Flag to indicate if OIC clients should be notified about an update
+ *
* @return void
*/
- virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&value);
+ void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value,
+ bool notify);
+
+ /**
+ * 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 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)
+ * 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;
std::string m_name, m_uri, m_resourceType, m_address;
- std::map< std::string, std::vector< std::map< std::string, std::string > > > m_mapResourceProperty;
+ std::map< std::string,
+ std::vector< std::map< std::string, std::string > > > m_mapResourceProperty;
private:
NotificationReceiver *m_pNotiReceiver;
}
}
-#endif
\ No newline at end of file
+#endif
virtual void initAttributes() = 0;
/**
- * Return all attributes of the resource
- *
- * @return Attributes of the resource
- */
- virtual RCSResourceAttributes &getAttributes();
+ * 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;
/**
- * Set attributes of the resource
- *
- * @param attrs Attributes to set
- *
- * @return void
- */
- virtual void setAttributes(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) = 0;
/**
- * Execute the logic of bundle to get the value of attribute
- *
- * @param key Key of attribute to get
- *
- * @return Value of the attribute
- */
- virtual RCSResourceAttributes::Value getAttribute(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 Attribute value
+ */
+ virtual RCSResourceAttributes::Value handleGetAttributeRequest(
+ const std::string &key) = 0;
/**
- * Execute the logic of bundle to set the value of attribute
- *
- * @param key Name of attribute to set
- *
- * @param value Value of attribute to set
- *
- * @return void
- */
- virtual void setAttribute(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 Value of all attributes
+ */
+ virtual RCSResourceAttributes& handleGetAttributesRequest() = 0;
};
}
}
-#endif
\ No newline at end of file
+#endif
virtual void initAttributes();
/**
- * Return all attributes of the resource
- *
- * @return RCSResourceAttributes Attributes of the resource
- */
- virtual RCSResourceAttributes &getAttributes();
+ * 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;
/**
- * Set attributes of the resource
- *
- * @param attrs Attributes to set
- *
- * @return void
- */
- virtual void setAttributes(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) = 0;
/**
- * Execute the logic of bundle to get the value of attribute
- *
- * @param key Key of attribute to get
- *
- * @return Value of the attribute
- */
- virtual RCSResourceAttributes::Value getAttribute(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 Attribute value
+ */
+ virtual RCSResourceAttributes::Value handleGetAttributeRequest(
+ const std::string &key) = 0;
/**
- * Execute the logic of bundle to set the value of attribute
- *
- * @param key Name of attribute to set
- *
- * @param value Value of attribute to set
- *
- * @return void
- */
- virtual void setAttribute(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 Value of all attributes
+ */
+ virtual RCSResourceAttributes& handleGetAttributesRequest() = 0;
/**
* SoftSensor logic. Has to be provided by the soft sensor developer.
virtual void executeLogic() = 0;
virtual void onUpdatedInputResource(const std::string attributeName,
- std::vector<RCSResourceAttributes::Value> values) = 0;
+ std::vector<RCSResourceAttributes::Value> values) = 0;
public:
}
}
-#endif
\ No newline at end of file
+#endif
BMISensorResource();
~BMISensorResource();
- virtual RCSResourceAttributes::Value getAttribute(const std::string &key);
- virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&value);
+ 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 void executeLogic();
delete m_pBMISensor;
}
-RCSResourceAttributes::Value BMISensorResource::getAttribute(const std::string &key)
+RCSResourceAttributes::Value BMISensorResource::handleGetAttributeRequest(const std::string &key)
{
return BundleResource::getAttribute(key);
}
-void BMISensorResource::setAttribute(std::string key,
+void BMISensorResource::handleSetAttributeRequest(const std::string &key,
RCSResourceAttributes::Value &&value)
{
BundleResource::setAttribute(key, std::move(value));
}
+RCSResourceAttributes& BMISensorResource::handleGetAttributesRequest()
+{
+ return BundleResource::getAttributes();
+}
+
+void BMISensorResource::handleSetAttributesRequest(
+ RCSResourceAttributes &value)
+{
+ BundleResource::setAttributes(value);
+}
+
+
void BMISensorResource::executeLogic()
{
std::string strBMIResult;
m_mapInputData.insert(std::make_pair("height", values.back().toString()));
executeLogic();
-}
\ No newline at end of file
+}
DiscomfortIndexSensorResource();
~DiscomfortIndexSensorResource();
- virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&value);
- virtual RCSResourceAttributes::Value getAttribute(const std::string &key);
+ 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 void executeLogic();
delete m_pDiscomfortIndexSensor;
}
-void DiscomfortIndexSensorResource::setAttribute(std::string key,
- RCSResourceAttributes::Value &&value)
+RCSResourceAttributes::Value DiscomfortIndexSensorResource::handleGetAttributeRequest(
+ const std::string &key)
+{
+ return BundleResource::getAttribute(key);
+}
+
+void DiscomfortIndexSensorResource::handleSetAttributeRequest(const std::string &key,
+ RCSResourceAttributes::Value &&value)
{
BundleResource::setAttribute(key, std::move(value));
}
-RCSResourceAttributes::Value DiscomfortIndexSensorResource::getAttribute(const std::string &key)
+RCSResourceAttributes& DiscomfortIndexSensorResource::handleGetAttributesRequest()
{
- return BundleResource::getAttribute(key);
+ return BundleResource::getAttributes();
}
+void DiscomfortIndexSensorResource::handleSetAttributesRequest(
+ RCSResourceAttributes &value)
+{
+ BundleResource::setAttributes(value);
+}
void DiscomfortIndexSensorResource::executeLogic()
{
std::string strDiscomfortIndex;
{
executeLogic();
}
-}
\ No newline at end of file
+}
virtual void initAttributes();
- virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&);
- virtual RCSResourceAttributes::Value getAttribute(const std::string &key);
+ virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs);
+
+ virtual void handleSetAttributeRequest(const std::string &key,
+ RCSResourceAttributes::Value &&value);
+
+ virtual RCSResourceAttributes::Value handleGetAttributeRequest(
+ const std::string &key);
+
+ virtual RCSResourceAttributes& handleGetAttributesRequest();
private:
std::string m_address;
BundleResource::setAttribute("color", 0);
}
-RCSResourceAttributes::Value HueLight::getAttribute(const std::string &key)
+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);
}
-void HueLight::setAttribute(std::string attributeName, RCSResourceAttributes::Value &&value)
+RCSResourceAttributes& HueLight::handleGetAttributesRequest()
+{
+ cout << "HueLight::getAttributes" << endl;
+ // TODO read from HueLight and update attribute data
+ return BundleResource::getAttributes();
+}
+
+void HueLight::handleSetAttributeRequest(const std::string &attributeName, RCSResourceAttributes::Value &&value)
{
cout << "HueLight::setAttribute setting " << attributeName << " to " << value.toString() <<
std::endl;
BundleResource::setAttribute(attributeName, std::move(value));
}
+void HueLight::handleSetAttributesRequest(RCSResourceAttributes &value)
+{
+ cout << "HueLight::setAttributes "<< std::endl;
+
+ // TODO construct single write
+
+ BundleResource::setAttributes(value);
+}
+
}
}
- void BundleResource::setAttribute(std::string key, RCSResourceAttributes::Value &&value)
+ void BundleResource::setAttribute(const std::string &key,
+ RCSResourceAttributes::Value &&value, bool notify)
{
OC_LOG_V(INFO, CONTAINER_TAG, "set attribute \(%s)'", std::string(key + "\', with " +
value.toString()).c_str());
m_resourceAttributes[key] = value;
- if (m_pNotiReceiver)
+ if (notify && m_pNotiReceiver)
m_pNotiReceiver->onNotificationReceived(m_uri);
}
+ void BundleResource::setAttribute(const std::string &key, RCSResourceAttributes::Value &&value){
+ setAttribute(key, std::move(value), true);
+ }
+
RCSResourceAttributes::Value BundleResource::getAttribute(const std::string &key)
{
OC_LOG_V(INFO, CONTAINER_TAG, "get attribute \'(%s)" , std::string(key + "\'").c_str());
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);
+ }
}
-}
\ No newline at end of file
+}
{
}
-
- RCSResourceAttributes &ProtocolBridgeResource::getAttributes()
- {
- // execute implemented logic to get attribute, and update bundle resource attribute data
- RCSResourceAttributes attr;
- for (std::string attrName : getAttributeNames())
- {
- attr[attrName] = getAttribute(attrName);
- }
- BundleResource::setAttributes(attr);
-
- return BundleResource::getAttributes();
- }
-
- void ProtocolBridgeResource::setAttributes(RCSResourceAttributes &attrs)
- {
- // execute implemented logic to set attribute
- for (RCSResourceAttributes::iterator it = attrs.begin(); it != attrs.end(); ++it)
- {
- setAttribute(it->key(), std::move(it->value()));
- }
- }
}
}
}
}
- m_mapResources[strResourceUri]->setAttributes(attr);
+ m_mapResources[strResourceUri]->handleSetAttributesRequest(attr);
};
boost::thread setThread(setFunction);
setThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
itor != m_mapResourceProperty[SS_RESOURCE_OUTPUT].end(); itor++)
BundleResource::setAttribute((*itor)[SS_RESOURCE_OUTPUTNAME], nullptr);
}
-
- RCSResourceAttributes &SoftSensorResource::getAttributes()
- {
- // execute implemented logic to get attribute, and update bundle resource attribute data
- RCSResourceAttributes attr;
- for (std::string attrName : getAttributeNames())
- {
- attr[attrName] = getAttribute(attrName);
- }
- BundleResource::setAttributes(attr);
-
- return BundleResource::getAttributes();
- }
-
- void SoftSensorResource::setAttributes(RCSResourceAttributes &attrs)
- {
- // execute implemented logic to set attribute
- for (RCSResourceAttributes::iterator it = attrs.begin(); it != attrs.end(); ++it)
- {
- setAttribute(it->key(), std::move(it->value()));
- }
- }
}
}
{
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()
+ {
+ return BundleResource::getAttributes();
+ }
+
+ void handleSetAttributesRequest(
+ RCSResourceAttributes &value)
+ {
+ BundleResource::setAttributes(value);
+ }
};
#endif /* TESTBUNDLE_H_ */