/**
* Return the list of attribute names of the resource
*
- * @return std::list - return list of the attribute names
+ * @return List of the attribute names
*/
std::list<std::string> getAttributeNames();
/**
* 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 all attributes of the resource
*
- * @return RCSResourceAttributes - attributes of the resource
+ * @return Attributes of the resource
*/
virtual RCSResourceAttributes &getAttributes();
/**
- * Execute the logic of bundle to set the value of attribute
- *
- * @param key - name of attribute to set
+ * Set attributes of the resource
*
- * @param value - value of attribute to set
+ * @param attrs Attributes to set
*
* @return void
*/
- virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&value);
+ virtual void setAttributes(RCSResourceAttributes &attrs);
/**
* Execute the logic of bundle to get the value of attribute
*
- * @param key - key of attribute to get
+ * @param key Key of attribute to get
*
- * @return RCSResourceAttributes::Value - return value of the attribute
+ * @return Value of the attribute
*/
virtual RCSResourceAttributes::Value getAttribute(const std::string &key);
+ /**
+ * 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);
public:
std::string m_bundleId;
private:
NotificationReceiver *m_pNotiReceiver;
RCSResourceAttributes m_resourceAttributes;
-
};
}
}
-#endif
+#endif
\ No newline at end of file
virtual ~ProtocolBridgeResource();
/**
- * Return all attributes of the resource
+ * Initialize attributes of the resource
*
- * @return RCSResourceAttributes - attributes of the resource
+ * @return void
*/
- virtual RCSResourceAttributes &getAttributes() = 0;
+ virtual void initAttributes() = 0;
/**
- * Execute the logic of bundle to set the value of attribute
+ * Return all attributes of the resource
*
- * @param key - name of attribute to set
+ * @return Attributes of the resource
+ */
+ virtual RCSResourceAttributes &getAttributes();
+
+ /**
+ * Set attributes of the resource
*
- * @param value - value of attribute to set
+ * @param attrs Attributes to set
*
* @return void
*/
- virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&value) = 0;
+ virtual void setAttributes(RCSResourceAttributes &attrs);
/**
* Execute the logic of bundle to get the value of attribute
*
- * @param key - key of attribute to get
+ * @param key Key of attribute to get
*
- * @return RCSResourceAttributes::Value - return value of the attribute
+ * @return Value of the attribute
*/
virtual RCSResourceAttributes::Value getAttribute(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;
};
}
}
-#endif
+#endif
\ No newline at end of file
/**
* Return all attributes of the resource
*
- * @return RCSResourceAttributes - attributes of the resource
+ * @return RCSResourceAttributes Attributes of the resource
*/
virtual RCSResourceAttributes &getAttributes();
/**
- * Execute the logic of bundle to set the value of attribute
- *
- * @param key - name of attribute to set
+ * Set attributes of the resource
*
- * @param value - value of attribute to set
+ * @param attrs Attributes to set
*
* @return void
*/
- virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&value);
+ virtual void setAttributes(RCSResourceAttributes &attrs);
/**
* Execute the logic of bundle to get the value of attribute
*
- * @param key - key of attribute to get
+ * @param key Key of attribute to get
+ *
+ * @return Value of the attribute
+ */
+ virtual RCSResourceAttributes::Value getAttribute(const std::string &key) = 0;
+
+ /**
+ * Execute the logic of bundle to set the value of attribute
+ *
+ * @param key Name of attribute to set
*
- * @return RCSResourceAttributes::Value - return value of the attribute
+ * @param value Value of attribute to set
+ *
+ * @return void
*/
- virtual RCSResourceAttributes::Value getAttribute(const std::string &key);
+ virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&value) = 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
+#endif
\ No newline at end of file
BMISensorResource();
~BMISensorResource();
- void initAttributes();
- virtual RCSResourceAttributes &getAttributes();
virtual RCSResourceAttributes::Value getAttribute(const std::string &key);
virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&value);
delete m_pBMISensor;
}
-void BMISensorResource::initAttributes()
-{
- SoftSensorResource::initAttributes();
-}
-
-RCSResourceAttributes &BMISensorResource::getAttributes()
-{
- return SoftSensorResource::getAttributes();
-}
-
RCSResourceAttributes::Value BMISensorResource::getAttribute(const std::string &key)
{
- return SoftSensorResource::getAttribute(key);
+ return BundleResource::getAttribute(key);
}
void BMISensorResource::setAttribute(std::string key,
RCSResourceAttributes::Value &&value)
{
- SoftSensorResource::setAttribute(key, std::move(value));
+ BundleResource::setAttribute(key, std::move(value));
}
void BMISensorResource::executeLogic()
DiscomfortIndexSensorResource();
~DiscomfortIndexSensorResource();
- void initAttributes();
- virtual RCSResourceAttributes &getAttributes();
virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&value);
virtual RCSResourceAttributes::Value getAttribute(const std::string &key);
delete m_pDiscomfortIndexSensor;
}
-void DiscomfortIndexSensorResource::initAttributes()
-{
- SoftSensorResource::initAttributes();
-}
-
-RCSResourceAttributes &DiscomfortIndexSensorResource::getAttributes()
-{
- return SoftSensorResource::getAttributes();
-}
-
void DiscomfortIndexSensorResource::setAttribute(std::string key,
RCSResourceAttributes::Value &&value)
{
- SoftSensorResource::setAttribute(key, std::move(value));
+ BundleResource::setAttribute(key, std::move(value));
}
RCSResourceAttributes::Value DiscomfortIndexSensorResource::getAttribute(const std::string &key)
{
- return SoftSensorResource::getAttribute(key);
+ return BundleResource::getAttribute(key);
}
void DiscomfortIndexSensorResource::executeLogic()
class HueLight: public ProtocolBridgeResource
{
- public:
- HueLight();
- HueLight(HueConnector* connector, std::string address);
- virtual ~HueLight();
- virtual void initAttributes();
- virtual RCSResourceAttributes& getAttributes();
-
- virtual void setAttribute(std::string key, RCSResourceAttributes::Value&&);
-
- virtual RCSResourceAttributes::Value getAttribute(const std::string& key);
- private:
- std::string m_address;
- HueConnector* m_connector;
- };}
+ public:
+ HueLight();
+ HueLight(HueConnector *connector, std::string address);
+ virtual ~HueLight();
+
+ virtual void initAttributes();
+
+ virtual void setAttribute(std::string key, RCSResourceAttributes::Value &&);
+ virtual RCSResourceAttributes::Value getAttribute(const std::string &key);
+
+ private:
+ std::string m_address;
+ HueConnector *m_connector;
+ };
+ }
}
#endif /* HUEGATEWAYCLIENT_H_ */
BundleResource::setAttribute("color", 0);
}
-RCSResourceAttributes &HueLight::getAttributes()
-{
- return BundleResource::getAttributes();
-}
-
RCSResourceAttributes::Value HueLight::getAttribute(const std::string &key)
{
cout << "HueLight::getAttribute called for " << key << " called" << endl;
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "BundleResource.h"
-#include "Configuration.h"
+
#include <list>
#include <string.h>
+#include "InternalTypes.h"
+
+
namespace OIC
{
namespace Service
m_pNotiReceiver = pNotiReceiver;
}
- std::list< string > BundleResource::getAttributeNames()
+ std::list< std::string > BundleResource::getAttributeNames()
{
- std::list< string > ret;
+ std::list< std::string > ret;
for (RCSResourceAttributes::iterator it = m_resourceAttributes.begin();
it != m_resourceAttributes.end(); ++it)
{
return m_resourceAttributes;
}
+ void BundleResource::setAttributes(RCSResourceAttributes &attrs)
+ {
+ for (RCSResourceAttributes::iterator it = attrs.begin(); it != attrs.end(); ++it)
+ {
+ m_resourceAttributes[it->key()] = it->value();
+ }
+ }
+
void BundleResource::setAttribute(std::string key, RCSResourceAttributes::Value &&value)
{
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("set attribute \'" + key + "\', with " +
+ value.toString()).c_str());
+
m_resourceAttributes[key] = value;
if (m_pNotiReceiver)
RCSResourceAttributes::Value BundleResource::getAttribute(const std::string &key)
{
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("get attribute \'" + key + "\'").c_str());
+
return m_resourceAttributes.at(key);
}
-
}
}
\ No newline at end of file
using namespace OIC::Service;
-namespace OIC{
- namespace Service{
+namespace OIC
+{
+ namespace Service
+ {
ProtocolBridgeResource::ProtocolBridgeResource()
{
{
}
+
+ 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()));
+ }
+ }
}
}
}
RCSGetResponse ResourceContainerImpl::getRequestHandler(const RCSRequest &request,
- const RCSResourceAttributes &attributes)
+ const RCSResourceAttributes &)
{
- (void) attributes;
+ OCEntityHandlerResult result = OC_EH_ERROR;
+
RCSResourceAttributes attr;
+ std::string strResourceUri = request.getResourceUri();
- if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
- && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
+ if (m_mapServers.find(strResourceUri) != m_mapServers.end()
+ && m_mapResources.find(strResourceUri) != m_mapResources.end())
{
- auto getFunction = [this, &attr, &request] ()
+ if (m_mapResources[strResourceUri])
{
- for (string attrName : m_mapResources[request.getResourceUri()]->getAttributeNames())
+ auto getFunction = [this, &attr, &strResourceUri]()
{
- attr[attrName] = m_mapResources[request.getResourceUri()]->getAttribute(attrName);
- }
- };
- boost::thread getThread(getFunction);
- getThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
+ attr = m_mapResources[strResourceUri]->getAttributes();
+ };
+ boost::thread getThread(getFunction);
+ getThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
+
+ result = OC_EH_OK;
+ }
}
- return RCSGetResponse::create(attr);
+ return RCSGetResponse::create(attr, result, 200);
}
RCSSetResponse ResourceContainerImpl::setRequestHandler(const RCSRequest &request,
const RCSResourceAttributes &attributes)
{
- RCSResourceAttributes attr = attributes;
+ OCEntityHandlerResult result = OC_EH_ERROR;
+
+ RCSResourceAttributes attr;
+ std::list<std::string> lstAttributes;
+ std::string strResourceUri = request.getResourceUri();
- if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
- && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
+ if (m_mapServers.find(strResourceUri) != m_mapServers.end()
+ && m_mapResources.find(strResourceUri) != m_mapResources.end())
{
- auto setFunction = [this, &attr, &request] ()
+ if (m_mapResources[strResourceUri])
{
- for (string attrName : m_mapResources[request.getResourceUri()]->getAttributeNames())
+ auto setFunction = [this, &lstAttributes, &strResourceUri, &attributes, &attr]()
{
- if (!attr[attrName].toString().empty())
+ lstAttributes = m_mapResources[strResourceUri]->getAttributeNames();
+
+ for (RCSResourceAttributes::const_iterator itor = attributes.begin();
+ itor != attributes.end(); itor++)
{
- m_mapResources[request.getResourceUri()]->setAttribute(attrName,
- attr[attrName].toString());
+ if (std::find(lstAttributes.begin(), lstAttributes.end(), itor->key())
+ != lstAttributes.end())
+ {
+ attr[itor->key()] = itor->value();
+ }
}
- }
- };
- boost::thread setThread(setFunction);
- setThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
+
+ m_mapResources[strResourceUri]->setAttributes(attr);
+ };
+ boost::thread setThread(setFunction);
+ setThread.timed_join(boost::posix_time::seconds(BUNDLE_SET_GET_WAIT_SEC));
+
+ result = OC_EH_OK;
+ }
}
- return RCSSetResponse::create(attr);
+ return RCSSetResponse::create(attr, result, 200);
}
void ResourceContainerImpl::onNotificationReceived(const std::string &strResourceUri)
{
- OC_LOG_V(INFO, CONTAINER_TAG, std::string("onNotificationReceived\n\tnotification from "
- + strResourceUri + ".").c_str());
+ OC_LOG_V(INFO, CONTAINER_TAG, std::string("notification from " + strResourceUri + ".").c_str());
if (m_mapServers.find(strResourceUri) != m_mapServers.end())
{
RCSResourceAttributes &SoftSensorResource::getAttributes()
{
- return BundleResource::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);
- void SoftSensorResource::setAttribute(std::string key, RCSResourceAttributes::Value &&value)
- {
- BundleResource::setAttribute(key, std::move(value));
+ return BundleResource::getAttributes();
}
- RCSResourceAttributes::Value SoftSensorResource::getAttribute(const std::string &key)
+ void SoftSensorResource::setAttributes(RCSResourceAttributes &attrs)
{
- return BundleResource::getAttribute(key);
+ // execute implemented logic to set attribute
+ for (RCSResourceAttributes::iterator it = attrs.begin(); it != attrs.end(); ++it)
+ {
+ setAttribute(it->key(), std::move(it->value()));
+ }
}
}
}