- 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>
*
* @return void
*/
- virtual void destroyResource(BundleResource *pBundleResource) = 0;
+ virtual void destroyResource(BundleResource::Ptr pBundleResource) = 0;
};
}
}
#include <string>
#include <map>
#include <vector>
+#include <memory>
#include "NotificationReceiver.h"
#include "RCSResourceAttributes.h"
class BundleResource
{
public:
+ typedef std::shared_ptr< BundleResource > Ptr;
/**
* Constructor for BundleResource
/**
* 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
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
*
* @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;
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;
};
}
}
*
* @return void
*/
- virtual void registerResource(BundleResource *resource) = 0;
+ virtual void registerResource(BundleResource::Ptr resource) = 0;
/**
* Unregister bundle resource from the container
*
* @return void
*/
- virtual void unregisterResource(BundleResource *resource) = 0;
+ virtual void unregisterResource(BundleResource::Ptr resource) = 0;
/**
* Get Configuration data of certain bundle
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.
*/
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:
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_ */
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;
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);
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
}
}
-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);
bundle->createResource(resourceInfo);
}
-extern "C" void bmisensor_externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void bmisensor_externalDestroyResource(BundleResource::Ptr pBundleResource)
{
bundle->destroyResource(pBundleResource);
}
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);
}
-RCSResourceAttributes& BMISensorResource::handleGetAttributesRequest()
+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
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_ */
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;
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);
static int discomfortIndexSensorCount = 1;
// create DISensor resource
- DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource();
+ BundleResource::Ptr newResource = std::make_shared< DiscomfortIndexSensorResource >();
newResource->m_bundleId = m_bundleId;
}
}
-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);
bundle->createResource(resourceInfo);
}
-extern "C" void disensor_externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void disensor_externalDestroyResource(BundleResource::Ptr pBundleResource)
{
bundle->destroyResource(pBundleResource);
}
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);
}
-RCSResourceAttributes& DiscomfortIndexSensorResource::handleGetAttributesRequest()
+RCSResourceAttributes &DiscomfortIndexSensorResource::handleGetAttributesRequest()
{
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 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;
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;
};
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
{
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);
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;
}
}
-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);
bundle->createResource(resourceInfo);
}
-extern "C" void huesample_externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void huesample_externalDestroyResource(BundleResource::Ptr pBundleResource)
{
bundle->destroyResource(pBundleResource);
}
#include "ResourceContainerBundleAPI.h"
#if (JAVA_SUPPORT)
- #include "jni.h"
+#include "jni.h"
#endif
using namespace std;
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
{
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,
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>
{
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());
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);
}
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);
- }
}
}
}
}
- 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())
registrationLock.unlock();
}
- void ResourceContainerImpl::unregisterResource(BundleResource *resource)
+ void ResourceContainerImpl::unregisterResource(BundleResource::Ptr resource)
{
string strUri = resource->m_uri;
string strResourceType = resource->m_resourceType;
{
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));
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(
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
public:
RCSResourceObject *m_pResourceObject;
ResourceContainerBundleAPI *m_pResourceContainer;
- TestBundleResource *m_pBundleResource;
+ BundleResource::Ptr m_pBundleResource;
std::string m_strConfigPath;
protected:
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";
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";
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*/
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
{
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;
m_pResourceContainer->registerResource(m_pTestResource);
}
-void TestBundleActivator::destroyResource(BundleResource *pBundleResource)
+void TestBundleActivator::destroyResource(BundleResource::Ptr pBundleResource)
{
std::cout << "TestBundleActivator::destroyResource .. " << std::endl;
}
extern "C" void test_externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
- std::string bundleId)
+ std::string bundleId)
{
bundle = new TestBundleActivator();
bundle->activateBundle(resourceContainer, bundleId);
bundle->createResource(resourceInfo);
}
-extern "C" void test_externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void test_externalDestroyResource(BundleResource::Ptr pBundleResource)
{
bundle->destroyResource(pBundleResource);
}