SConscript('common/SConscript')
#SConscript('resourceBroker/SConscript')
#SConscript('resourceCache/SConscript')
-#SConscript('resourceContainer/SConscript')
SConscript('serverBuilder/SConscript')
+SConscript('resourceContainer/SConscript')
#SConscript('sdk/SConscript')
CPPPATH = [
env.get('SRC_DIR')+'/extlibs',
'include',
- 'src'
+ 'src',
+ '../serverBuilder/include',
+ '../common/primitiveResource/include'
])
if target_os not in ['windows', 'winrt']:
if target_os == 'android':
resource_container_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
resource_container_env.PrependUnique(LIBS = ['gnustl_shared', 'compatibility', 'log'])
-
+
+#resource_container_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+resource_container_env.PrependUnique(LIBS = ['ServerBuilder', 'ServiceCommon', 'oc','octbstack', 'oc_logger', 'oc_logger_core', 'connectivity_abstraction', 'coap'])
resource_container_env.AppendUnique(LIBS = ['dl'])
######################################################################
# Build Container Test
######################################################################
containertest_env = resource_container_env.Clone();
-containertest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-containertest_env.PrependUnique(LIBS = ['oc', 'oc_logger_core', 'oc_logger'])
+#containertest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
# Copy test configuration
Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE"))
#include <vector>
#include <map>
-struct SensorData
-{
- std::string sensorName;
- std::vector< std::map<std::string, std::string> > data;
-};
+// temp
+#include "BundleResource.h"
+#include "SoftSensorResource.h"
namespace DiscomfortIndexSensorName
{
public:
DiscomfortIndexSensor();
- int runLogic(std::vector< SensorData > &sensorData);
- DIResult getInput(std::vector< SensorData > &contextDataList, InValue *data);
+ int runLogic(std::vector< RC::SoftSensorResource::SensorData > &sensorData);
+ DIResult getInput(std::vector< RC::SoftSensorResource::SensorData > &contextDataList,
+ InValue *data);
DIResult makeDiscomfortIndex(InValue *data);
- SensorData setOutput(int property_count, InValue *data);
+ RC::SoftSensorResource::SensorData setOutput(int property_count, InValue *data);
+
+ RC::SoftSensorResource::SensorData m_output;
};
};
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef DISCOMFORTINDEXSENSORRESOURCE_H_
+#define DISCOMFORTINDEXSENSORRESOURCE_H_
+
+#include "BundleResource.h"
+#include "DiscomfortIndexSensor.h"
+
+using namespace DiscomfortIndexSensorName;
+using namespace RC;
+
+class DiscomfortIndexSensorResource : public SoftSensorResource
+{
+ public:
+ DiscomfortIndexSensorResource();
+ ~DiscomfortIndexSensorResource();
+
+ void onGetRequest(std::map <std::string, std::string> *attributes);
+ void onSetRequest(std::map <std::string, std::string> attributes);
+
+ void onInputDataReceived(std::vector <SensorData> inputs);
+
+ private:
+ DiscomfortIndexSensor *m_pDiscomfortIndexSensor;
+};
+
+#endif
#ifndef SAMPLEBUNDLE_H_
#define SAMPLEBUNDLE_H_
+#include <algorithm>
#include <vector>
#include "ResourceContainerBundleAPI.h"
#include "BundleActivator.h"
+#include "BundleResource.h"
using namespace RC;
SampleBundle();
~SampleBundle();
- void activateBundle(ResourceContainerBundleAPI* resourceContainer);
+ void activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId);
void deactivateBundle();
- void createResource();
- void destroyResource();
+ void createResource(Configuration::resourceInfo);
+ void destroyResource(BundleResource *);
- ResourceContainerBundleAPI* m_ResourceContainer;
- std::vector<Resource *> m_vecResources;
-};
-
-
-class SampleBundleResource: public Resource
-{
- public:
- SampleBundleResource();
- ~SampleBundleResource();
+ std::string m_bundleId;
+ ResourceContainerBundleAPI *m_pResourceContainer;
+ std::vector<BundleResource *> m_vecResources;
};
#endif /* SAMPLEBUNDLE_H_ */
/**
* This file contains the exported symbol.
*/
-#include <stdlib.h>
-#include <map>
-#include <string>
-#include <sstream>
-#include <iostream>
-
#include "DiscomfortIndexSensor.h"
#include "SysTimer.h"
m_result.m_discomfortIndex = "";
}
-int DiscomfortIndexSensor::runLogic(std::vector< SensorData > &sensorData)
+int DiscomfortIndexSensor::runLogic(std::vector< RC::SoftSensorResource::SensorData > &sensorData)
{
std::cout << "[DiscomfortIndexSensor] DiscomfortIndexSensor::" << __func__ << " is called."
<< std::endl;
return -1;
}
- //g_pSoftSensorCore->pushResults(setOutput(4, m_DI));
+ m_output = setOutput(4, m_DI);
return 0;
}
/**
* Get Input data (temperature, humidity) using resource Client of Iotivity base.
*/
-DIResult DiscomfortIndexSensor::getInput(std::vector< SensorData > &sensorData, InValue *data)
+DIResult DiscomfortIndexSensor::getInput(std::vector< RC::SoftSensorResource::SensorData >
+ &sensorData, InValue *data)
{
- //int result_flag = 0;
- //int contextSize = 0;
-
- //if ((contextSize = sensorData.size()) == 0)
- //{
- // std::cout << "Physical Context data is not exist." << std::endl;
- // return ERROR;
- //}
-
- //for (int i = 0; i < contextSize; i++)
- //{
- // for (int k = 0; k < PHYSICAL_EA; k++)
- // {
- // if (sensorData[i].sensorName == s_PHYSICAL_SOFTSENSORs[k].m_thingName)
- // {
- // std::vector < std::map< std::string, std::string > > lVector =
- // sensorData[i].data;
- // int requiredInputNum = s_PHYSICAL_SOFTSENSORs[k].m_inputNum;
- // char **pchar = (char **) (s_PHYSICAL_SOFTSENSORs[k].m_pInputStruct);
- // if (requiredInputNum == 0)
- // {
- // std::cout << "No input List." << std::endl;
- // return ERROR;
- // }
-
- // for (unsigned int j = 0; j < lVector.size(); j++)
- // {
- // std::string name = lVector[j]["name"];
-
- // if (name.compare(*pchar) == 0)
- // {
- // data->m_temperature = lVector[j]["value"];
- // requiredInputNum--;
- // }
- // else if (name.compare(*(++pchar)) == 0)
- // {
- // data->m_humidity = lVector[j]["value"];
- // requiredInputNum--;
- // }
- // }
-
- // if (requiredInputNum == 0)
- // {
- // data++;
- // result_flag++;
- // }
- // break;
- // } // if
- // } // for
- //}
-
- //if (result_flag == PHYSICAL_EA)
- //{
- // std::cout << "Success : getInput()" << std::endl;
- // return SUCCESS;
- //}
-
- //return ERROR;
+ int result_flag = 0;
+ int contextSize = 0;
+
+ if ((contextSize = sensorData.size()) == 0)
+ {
+ std::cout << "Physical Context data is not exist." << std::endl;
+ return ERROR;
+ }
+
+ for (int i = 0; i < contextSize; i++)
+ {
+ for (int k = 0; k < PHYSICAL_EA; k++)
+ {
+ if (sensorData[i].sensorName == s_PHYSICAL_SOFTSENSORs[k].m_thingName)
+ {
+ std::vector < std::map< std::string, std::string > > lVector =
+ sensorData[i].data;
+ int requiredInputNum = s_PHYSICAL_SOFTSENSORs[k].m_inputNum;
+ char **pchar = (char **) (s_PHYSICAL_SOFTSENSORs[k].m_pInputStruct);
+ if (requiredInputNum == 0)
+ {
+ std::cout << "No input List." << std::endl;
+ return ERROR;
+ }
+
+ for (unsigned int j = 0; j < lVector.size(); j++)
+ {
+ std::string name = lVector[j]["name"];
+
+ if (name.compare(*pchar) == 0)
+ {
+ data->m_temperature = lVector[j]["value"];
+ requiredInputNum--;
+ }
+ else if (name.compare(*(++pchar)) == 0)
+ {
+ data->m_humidity = lVector[j]["value"];
+ requiredInputNum--;
+ }
+ }
+
+ if (requiredInputNum == 0)
+ {
+ data++;
+ result_flag++;
+ }
+ break;
+ } // if
+ } // for
+ }
+
+ if (result_flag == PHYSICAL_EA)
+ {
+ std::cout << "Success : getInput()" << std::endl;
+ return SUCCESS;
+ }
+
+ return ERROR;
}
/**
return SUCCESS;
}
-SensorData DiscomfortIndexSensor::setOutput(int property_count, InValue *data)
+RC::SoftSensorResource::SensorData DiscomfortIndexSensor::setOutput(int property_count,
+ InValue *data)
{
- //SensorData out;
+ RC::SoftSensorResource::SensorData out;
- //std::map < std::string, std::string > output_property;
+ std::map < std::string, std::string > output_property;
- //out.sensorName = SENSOR_NAME;
+ out.sensorName = SENSOR_NAME;
- //output_property.insert(std::make_pair("name", "timestamp"));
- //output_property.insert(std::make_pair("type", "string"));
- //output_property.insert(std::make_pair("value", m_result.m_timestamp));
+ output_property.insert(std::make_pair("name", "timestamp"));
+ output_property.insert(std::make_pair("type", "string"));
+ output_property.insert(std::make_pair("value", m_result.m_timestamp));
- //out.data.push_back(output_property);
+ out.data.push_back(output_property);
- //output_property.clear();
- //output_property.insert(std::make_pair("name", "temperature"));
- //output_property.insert(std::make_pair("type", "string"));
- //output_property.insert(std::make_pair("value", m_result.m_temperature));
+ output_property.clear();
+ output_property.insert(std::make_pair("name", "temperature"));
+ output_property.insert(std::make_pair("type", "string"));
+ output_property.insert(std::make_pair("value", m_result.m_temperature));
- //out.data.push_back(output_property);
+ out.data.push_back(output_property);
- //output_property.clear();
- //output_property.insert(std::make_pair("name", "humidity"));
- //output_property.insert(std::make_pair("type", "string"));
- //output_property.insert(std::make_pair("value", m_result.m_humidity));
+ output_property.clear();
+ output_property.insert(std::make_pair("name", "humidity"));
+ output_property.insert(std::make_pair("type", "string"));
+ output_property.insert(std::make_pair("value", m_result.m_humidity));
- //out.data.push_back(output_property);
+ out.data.push_back(output_property);
- //output_property.clear();
- //output_property.insert(std::make_pair("name", "discomfortIndex"));
- //output_property.insert(std::make_pair("type", "int"));
- //output_property.insert(std::make_pair("value", m_result.m_discomfortIndex));
+ output_property.clear();
+ output_property.insert(std::make_pair("name", "discomfortIndex"));
+ output_property.insert(std::make_pair("type", "int"));
+ output_property.insert(std::make_pair("value", m_result.m_discomfortIndex));
- //out.data.push_back(output_property);
+ out.data.push_back(output_property);
- //return out;
+ return out;
}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "DiscomfortIndexSensorResource.h"
+
+DiscomfortIndexSensorResource::DiscomfortIndexSensorResource()
+{
+ m_pDiscomfortIndexSensor = new DiscomfortIndexSensor();
+
+ m_mapAttributes.insert(std::pair<string, string>("temperature", "23"));
+ m_mapAttributes.insert(std::pair<string, string>("humidity", "40"));
+ m_mapAttributes.insert(std::pair<string, string>("discomfortIndex", "5"));
+
+}
+
+DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource()
+{
+ delete m_pDiscomfortIndexSensor;
+}
+
+void DiscomfortIndexSensorResource::onGetRequest(std::map <std::string, std::string> *attributes)
+{
+ // TODO : make m_outputs into m_mapAttributes format
+ *attributes = m_mapAttributes;
+}
+
+void DiscomfortIndexSensorResource::onSetRequest(std::map <std::string, std::string> attributes)
+{
+}
+
+void DiscomfortIndexSensorResource::onInputDataReceived(std::vector <SensorData> inputs)
+{
+ m_vecInputs = inputs;
+ m_pDiscomfortIndexSensor->runLogic(m_vecInputs);
+}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "SampleBundle.h"
-#include "ResourceContainerBundleAPI.h"
-#include "Configuration.h"
-
+#include "DiscomfortIndexSensorResource.h"
using namespace RC;
{
}
-void SampleBundle::activateBundle(ResourceContainerBundleAPI* resourceContainer)
+void SampleBundle::activateBundle(ResourceContainerBundleAPI *resourceContainer,
+ std::string bundleId)
{
std::cout << "SampleBundle::activateBundle called" << std::endl;
- m_ResourceContainer = resourceContainer;
+ m_pResourceContainer = resourceContainer;
+ m_bundleId = bundleId;
- // parse configuration, instantiate resource and register resources
- Configuration::configInfo config;
- // m_ResourceContainer->getConfiguration(ConfigKey::CONFIG_RESOURCES, "oic.bundle.sample", &config);
+ vector<Configuration::resourceInfo> resourceConfig;
- std::cout << "Resource Information" << std::endl;
- // for (int i = 0; i < configParam.size(); i++)
- //{
- // for (map <string, string>::iterator itor = configParam[i].begin(); itor != configParam[i].end();
- // itor++)
- //
- // cout << "key : " << itor->first << " | value : " << itor->second << endl;
- // }
+ resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
- // createResource();
+ for (vector<Configuration::resourceInfo>::iterator itor = resourceConfig.begin();
+ itor != resourceConfig.end(); itor++)
+ {
+ createResource(*itor);
+ }
}
void SampleBundle::deactivateBundle()
{
std::cout << "SampleBundle::deactivateBundle called" << std::endl;
- // unregister resources
+
+ for (std::vector<BundleResource *>::iterator itor = m_vecResources.begin();
+ itor != m_vecResources.end(); itor++)
+ {
+ destroyResource(*itor);
+ }
}
-void SampleBundle::createResource()
+// TODO : has to be updated for setting the info
+void SampleBundle::createResource(Configuration::resourceInfo resourceInfo)
{
- //std::cout << "SampleBundle::createResource called" << std::endl;
- //SampleBundleResource *newResource = new SampleBundleResource();
- //m_vecResources.push_back(newResource);
- //std::cout << "resourceContainer.registerResource()" << std::endl;
+ std::cout << "SampleBundle::createResource called" << std::endl;
+
+ DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource();
+ newResource->setResourceInfo(resourceInfo);
+
+ m_pResourceContainer->registerResource(newResource);
+
+ m_vecResources.push_back(newResource);
}
-void SampleBundle::destroyResource()
+void SampleBundle::destroyResource(BundleResource *resource)
{
- //std::cout << "SampleBundle::destroyResource called" << std::endl;
- //std::cout << "resourceContainer.unregisterResource()" << std::endl;
+ std::cout << "SampleBundle::destroyResource called" << std::endl;
+
+ std::vector <BundleResource *>::iterator itor;
+
+ itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
+
+ if (itor != m_vecResources.end())
+ m_vecResources.erase(itor);
+
+ // check
+ //delete resource;
+
+ m_pResourceContainer->unregisterResource(resource);
}
-extern "C" void externalActivateBundle(ResourceContainerBundleAPI* resourceContainer)
+extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
+ std::string bundleId)
{
bundle = new SampleBundle();
- bundle->activateBundle(resourceContainer);
+ bundle->activateBundle(resourceContainer, bundleId);
}
extern "C" void externalDeactivateBundle()
class BundleActivator
{
- public:
- BundleActivator();
- virtual ~BundleActivator();
- virtual void activateBundle(ResourceContainerBundleAPI* resourceContainer);
- virtual void deactivateBundle();
+ public:
+ BundleActivator();
+ virtual ~BundleActivator();
+ virtual void activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId);
+ virtual void deactivateBundle();
};
}
namespace RC
{
- typedef void activator_t(ResourceContainerBundleAPI *);
+ typedef void activator_t(ResourceContainerBundleAPI *, std::string bundleId);
typedef void deactivator_t(void);
class BundleInfoInternal: public BundleInfo
{
- public:
- BundleInfoInternal();
- BundleInfoInternal(BundleInfo* info);
- virtual ~BundleInfoInternal();
- void setID(string id);
- string getID();
- void setPath(string path);
- string getPath();
- void setVersion(string version);
- string getVersion();
+ public:
+ BundleInfoInternal();
+ BundleInfoInternal(BundleInfo *info);
+ virtual ~BundleInfoInternal();
+ void setID(string id);
+ string getID();
+ void setPath(string path);
+ string getPath();
+ void setVersion(string version);
+ string getVersion();
- void setLoaded(bool loaded);
- bool isLoaded();
- void setActivated(bool activated);
- bool isActivated();
- int getId();
- void setId(int id);
+ void setLoaded(bool loaded);
+ bool isLoaded();
+ void setActivated(bool activated);
+ bool isActivated();
+ int getId();
+ void setId(int id);
- void setBundleActivator(activator_t*);
- activator_t* getBundleActivator();
+ void setBundleActivator(activator_t *);
+ activator_t *getBundleActivator();
- void setBundleDeactivator(deactivator_t*);
- deactivator_t* getBundleDeactivator();
+ void setBundleDeactivator(deactivator_t *);
+ deactivator_t *getBundleDeactivator();
- void setBundleHandle(void*);
- void* getBundleHandle();
+ void setBundleHandle(void *);
+ void *getBundleHandle();
- private:
- bool m_loaded, m_activated;
- int m_id;
- activator_t* m_activator;
- deactivator_t* m_deactivator;
- void* m_bundleHandle;
+ private:
+ bool m_loaded, m_activated;
+ int m_id;
+ activator_t *m_activator;
+ deactivator_t *m_deactivator;
+ void *m_bundleHandle;
};
}
#ifndef BUNDLERESOURCE_H_
#define BUNDLERESOURCE_H_
+#include "Configuration.h"
#include <map>
#include <string>
BundleResource();
virtual ~BundleResource();
- virtual void onGetRequest() = 0;
- virtual void onSetRequest() = 0;
+ virtual void onGetRequest(std::map <std::string, std::string> *attributes) = 0;
+ virtual void onSetRequest(std::map <std::string, std::string> attributes) = 0;
- std::map <std::string, std::string> m_mapAttributes;
- };
+ Configuration::resourceInfo getResourceInfo();
+ void setResourceInfo(Configuration::resourceInfo resourceInfo);
- class SoftSensorResource : public BundleResource
- {
public:
- SoftSensorResource();
- virtual ~SoftSensorResource();
-
- virtual void runLogic() = 0;
-
- std::map <std::string, std::string> m_mapInputs;
+ std::map <std::string, std::string> m_mapAttributes;
+ Configuration::resourceInfo m_resourceInfo;
};
+
}
#endif
#include <string.h>
#include <fstream>
+#include "rapidxml/rapidxml.hpp"
+#include "rapidxml/rapidxml_print.hpp"
+
#include "ResourceContainer.h"
#include "BundleInfo.h"
{
-class Configuration
-{
- public:
- typedef vector<std::map <std::string, std::string>> configInfo;
- struct resourceInfo
- {
- std::string name;
- std::string uri;
- std::string resourceType;
- std::map < std::string, std::vector< std::map< std::string, std::string > > > resourceProperty;
- };
+ class Configuration
+ {
+ public:
+ typedef vector<std::map <std::string, std::string>> configInfo;
+ struct resourceInfo
+ {
+ std::string name;
+ std::string uri;
+ std::string resourceType;
+ std::map < std::string, std::vector< std::map< std::string, std::string > > > resourceProperty;
+ };
- Configuration();
- ~Configuration();
+ Configuration();
+ ~Configuration();
- Configuration(string configFile);
+ Configuration(string configFile);
- void getCommonConfiguration(configInfo *configOutput);
- void getBundleConfiguration(std::string bundleId, configInfo *configOutput);
- void getResourceConfiguration(std::string bundleId, std::vector<resourceInfo> *configOutput);
- void getConfiguredBundles(configInfo *configOutput);
+ void getCommonConfiguration(configInfo *configOutput);
+ void getBundleConfiguration(std::string bundleId, configInfo *configOutput);
+ void getResourceConfiguration(std::string bundleId, std::vector<resourceInfo> *configOutput);
+ void getConfiguredBundles(configInfo *configOutput);
- private:
- void getConfigDocument(std::string pathConfigFile, std::string *pConfigData);
- void getCurrentPath(std::string *path);
+ private:
+ void getConfigDocument(std::string pathConfigFile, std::string *pConfigData);
+ void getCurrentPath(std::string *path);
- string m_pathConfigFile, m_configFile;
-};
+ string m_pathConfigFile, m_configFile;
+ };
}
#endif
#include "BundleInfo.h"
-#include "rapidxml/rapidxml.hpp"
-#include "rapidxml/rapidxml_print.hpp"
-
using namespace std;
namespace RC
class ResourceContainer
{
- public:
- ResourceContainer();
- virtual ~ResourceContainer();
- virtual void init() = 0;
- virtual void init(string configFile) = 0;
- virtual void registerBundle(BundleInfo* bundleinfo) = 0;
- virtual void unregisterBundle(BundleInfo* bundleinfo) = 0;
- virtual void unregisterBundle(int id) = 0;
- virtual void activateBundle(int id) = 0;
- virtual void deactivateBundle(int id) = 0;
- virtual void activateBundleByName(string name) = 0;
- virtual void deactivateBundleByName(string id) = 0;
- virtual void activateBundle(BundleInfo* bundleInfo) = 0;
- virtual void deactivateBundle(BundleInfo* bundleInfo) = 0;
- virtual vector< Resource * > listBundleResources(string id) = 0;
+ public:
+ ResourceContainer();
+ virtual ~ResourceContainer();
+ virtual void init() = 0;
+ virtual void init(string configFile) = 0;
+ virtual void registerBundle(BundleInfo *bundleinfo) = 0;
+ virtual void unregisterBundle(BundleInfo *bundleinfo) = 0;
+ virtual void unregisterBundle(int id) = 0;
+ virtual void activateBundle(int id) = 0;
+ virtual void deactivateBundle(int id) = 0;
+ virtual void activateBundleByName(string name) = 0;
+ virtual void deactivateBundleByName(string id) = 0;
+ virtual void activateBundle(BundleInfo *bundleInfo) = 0;
+ virtual void deactivateBundle(BundleInfo *bundleInfo) = 0;
+ virtual vector< Resource * > listBundleResources(string id) = 0;
- static ResourceContainer* getInstance();
+ static ResourceContainer *getInstance();
};
}
#include "ResourceContainer.h"
#include "BundleInfo.h"
#include "Configuration.h"
+#include "BundleResource.h"
using namespace RC;
typedef std::map <std::string, std::string> configInfo;
ResourceContainerBundleAPI();
virtual ~ResourceContainerBundleAPI();
- virtual void registerResource(Resource *resource) = 0;
- virtual void unregisterResource(Resource *resource) = 0;
- void getCommonConfiguration(configInfo *configOutput);
- void getBundleConfiguration(std::string bundleId, configInfo *configOutput);
- void getResourceConfiguration(std::string bundleId, std::vector<resourceInfo> *configOutput);
+ virtual void registerResource(BundleResource *resource) = 0;
+ virtual void unregisterResource(BundleResource *resource) = 0;
+ virtual void getCommonConfiguration(configInfo *configOutput) = 0;
+ virtual void getBundleConfiguration(std::string bundleId, configInfo *configOutput) = 0;
+ virtual void getResourceConfiguration(std::string bundleId,
+ std::vector<resourceInfo> *configOutput) = 0;
static ResourceContainerBundleAPI *getInstance();
};
class ResourceContainerImpl: public ResourceContainer, public ResourceContainerBundleAPI
{
- public:
- ResourceContainerImpl();
- virtual ~ResourceContainerImpl();
+ public:
+ ResourceContainerImpl();
+ virtual ~ResourceContainerImpl();
- // methods from ResourceContainer
- void init();
- void init(string configFile);
- void activateBundle(int id);
- void deactivateBundle(int id);
- void activateBundleByName(string name);
- void deactivateBundleByName(string id);
- void activateBundle(BundleInfo* bundleInfo);
- void deactivateBundle(BundleInfo* bundleInfo);
- vector< Resource* > listBundleResources(string id);
+ // methods from ResourceContainer
+ void init();
+ void init(string configFile);
+ void activateBundle(int id);
+ void deactivateBundle(int id);
+ void activateBundleByName(string name);
+ void deactivateBundleByName(string id);
+ void activateBundle(BundleInfo *bundleInfo);
+ void deactivateBundle(BundleInfo *bundleInfo);
+ vector< Resource * > listBundleResources(string id);
- // methods from ResourceContainerBundleAPI
- void registerBundle(BundleInfo* bundleinfo);
- void unregisterBundle(BundleInfo* bundleinfo);
- void unregisterBundle(int id);
- void registerResource(Resource* resource);
- void unregisterResource(Resource* resource);
+ // methods from ResourceContainerBundleAPI
+ void registerBundle(BundleInfo *bundleinfo);
+ void unregisterBundle(BundleInfo *bundleinfo);
+ void unregisterBundle(int id);
+ void registerResource(BundleResource *resource);
+ void unregisterResource(BundleResource *resource);
- static ResourceContainerImpl* getImplInstance();
+ void getCommonConfiguration(configInfo *configOutput);
+ void getBundleConfiguration(std::string bundleId, configInfo *configOutput);
+ void getResourceConfiguration(std::string bundleId, std::vector<resourceInfo> *configOutput);
- private:
- vector<BundleInfoInternal* > m_bundles;
- string m_configFile;
- Configuration m_config;
+ static ResourceContainerImpl *getImplInstance();
+
+ private:
+ vector<BundleInfoInternal * > m_bundles;
+ string m_configFile;
+ Configuration *m_config;
};
}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef SOFTSENSORRESOURCE_H_
+#define SOFTSENSORRESOURCE_H_
+
+#include "BundleResource.h"
+#include <map>
+#include <string>
+
+namespace RC
+{
+
+ class SoftSensorResource : public BundleResource
+ {
+ public:
+ // TODO : definition of SensorData definition should be changed
+ struct SensorData
+ {
+ std::string sensorName;
+ std::vector< std::map<std::string, std::string> > data;
+ };
+
+ SoftSensorResource();
+ virtual ~SoftSensorResource();
+
+ virtual void onInputDataReceived(std::vector <SensorData> inputs) = 0;
+
+ int inputCount;
+ std::vector < SensorData > m_vecInputs;
+ SensorData m_outputs;
+ };
+}
+
+#endif
using namespace RC;
-namespace RC{
+namespace RC
+{
BundleActivator::BundleActivator()
{
}
- void BundleActivator::activateBundle(ResourceContainerBundleAPI* resourceContainer)
+ void BundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
+ std::string bundleId)
{
}
}
- BundleInfo* BundleInfo::createBundleInfo()
+ BundleInfo *BundleInfo::createBundleInfo()
{
- BundleInfoInternal* newBundleInfo = new BundleInfoInternal();
+ BundleInfoInternal *newBundleInfo = new BundleInfoInternal();
return newBundleInfo;
}
}
m_id = id;
}
- void BundleInfoInternal::setBundleActivator(activator_t* activator)
+ void BundleInfoInternal::setBundleActivator(activator_t *activator)
{
m_activator = activator;
}
- activator_t* BundleInfoInternal::getBundleActivator()
+ activator_t *BundleInfoInternal::getBundleActivator()
{
return m_activator;
}
- void BundleInfoInternal::setBundleDeactivator(deactivator_t* deactivator)
+ void BundleInfoInternal::setBundleDeactivator(deactivator_t *deactivator)
{
m_deactivator = deactivator;
}
- deactivator_t* BundleInfoInternal::getBundleDeactivator()
+ deactivator_t *BundleInfoInternal::getBundleDeactivator()
{
return m_deactivator;
}
- void BundleInfoInternal::setBundleHandle(void* handle)
+ void BundleInfoInternal::setBundleHandle(void *handle)
{
m_bundleHandle = handle;
}
- void* BundleInfoInternal::getBundleHandle()
+ void *BundleInfoInternal::getBundleHandle()
{
return m_bundleHandle;
}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "BundleResource.h"
+#include "Configuration.h"
+
+
+
+BundleResource::BundleResource()
+{
+
+}
+
+BundleResource::~BundleResource()
+{
+
+}
+
+Configuration::resourceInfo BundleResource::getResourceInfo()
+{
+ return m_resourceInfo;
+}
+
+void BundleResource::setResourceInfo(Configuration::resourceInfo resourceInfo)
+{
+ m_resourceInfo = resourceInfo;
+}
+
Configuration::~Configuration()
{}
-Configuration::Configuration(string configFile){
+Configuration::Configuration(string configFile)
+{
m_configFile = configFile;
getCurrentPath(&m_pathConfigFile);
m_pathConfigFile.append("/");
}
}
-void Configuration::getConfiguredBundles(configInfo* configOutput){
+void Configuration::getConfiguredBundles(configInfo *configOutput)
+{
string strConfigData;
rapidxml::xml_document< char > xmlDoc;
- rapidxml::xml_node< char > *root;
rapidxml::xml_node< char > *bundle;
rapidxml::xml_node< char > *subItem;
//cout << "Bundle: " << bundle->name() << endl;
for (subItem = bundle->first_node(); subItem; subItem = subItem->next_sibling())
{
- strKey = subItem->name();
- strValue = subItem->value();
- if(strlen(subItem->value()) > 0){
- bundleMap.insert(std::make_pair(trim_both(strKey), trim_both(strValue)));
- //cout << strKey << " " << strValue << endl;
+ strKey = subItem->name();
+ strValue = subItem->value();
+ if (strlen(subItem->value()) > 0)
+ {
+ bundleMap.insert(std::make_pair(trim_both(strKey), trim_both(strValue)));
+ //cout << strKey << " " << strValue << endl;
- }
+ }
}
configOutput->push_back(bundleMap);
}
using OC::oc_log_stream;
/* Annother way to create a context: */
-auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream>&
+auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
{
static OC::oc_log_stream ols(oc_make_ostream_logger);
static boost::iostreams::stream<OC::oc_log_stream> os(ols);
info_logger() << "Starting container test." << std::flush;
- /*BundleInfo* bundleInfo = BundleInfo::createBundleInfo();
- bundleInfo->setPath(
- "/home/iotivity/development/iotivity-mj/out/linux/x86/release/libSampleBundle.so");
- bundleInfo->setVersion("1.0");
- bundleInfo->setName("Sample Bundle");*/
-
- ResourceContainer* container = ResourceContainer::getInstance();
+ ResourceContainer *container = ResourceContainer::getInstance();
container->init("examples/ResourceContainerConfig.xml");
- //container->registerBundle(bundleInfo);
- //container->activateBundle(bundleInfo);
- //container->deactivateBundle(bundleInfo);
- //container->unregisterBundle(bundleInfo);
-
- //bundleInfo.path = "/";
- //bundleInfo.version = "1.0";
+ while (1)
+ {
+ ;
+ }
}
}
- ResourceContainer* ResourceContainer::getInstance()
+ ResourceContainer *ResourceContainer::getInstance()
{
- return (ResourceContainer*) ResourceContainerImpl::getImplInstance();
+ return (ResourceContainer *)ResourceContainerImpl::getImplInstance();
}
}
#include "ResourceContainer.h"
#include "BundleInfoInternal.h"
#include "logger.h"
+#include "PrimitiveRequest.h"
+#include "PrimitiveResponse.h"
+#include "PrimitiveServerResource.h"
+
#include <dlfcn.h>
#include <unistd.h>
using OC::oc_log_stream;
-auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream>&
+/* Annother way to create a context: */
+auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
{
static OC::oc_log_stream ols(oc_make_ostream_logger);
static boost::iostreams::stream<OC::oc_log_stream> os(ols);
return os;
};
-auto error_logger = []() -> boost::iostreams::stream<OC::oc_log_stream>&
+/* Annother way to create a context: */
+auto error_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
{
static OC::oc_log_stream ols(oc_make_ostream_logger);
static boost::iostreams::stream<OC::oc_log_stream> os(ols);
void ResourceContainerImpl::init(string configFile)
{
- Configuration config(configFile);
+ m_config = new Configuration(configFile);
Configuration::configInfo bundles;
- config.getConfiguredBundles(&bundles);
- for(int i = 0; i < bundles.size(); i++){
- BundleInfo* bundleInfo = BundleInfo::createBundleInfo();
+ m_config->getConfiguredBundles(&bundles);
+ for (int i = 0; i < bundles.size(); i++)
+ {
+ BundleInfo *bundleInfo = BundleInfo::createBundleInfo();
bundleInfo->setPath(bundles[i]["path"]);
bundleInfo->setVersion(bundles[i]["version"]);
bundleInfo->setID(bundles[i]["id"]);
}
// loads the bundle
- void ResourceContainerImpl::registerBundle(BundleInfo* bundleInfo)
+ void ResourceContainerImpl::registerBundle(BundleInfo *bundleInfo)
{
info_logger() << "Registering bundle: " << bundleInfo->getPath() << endl;
- m_bundles.push_back((BundleInfoInternal*) bundleInfo);
- ((BundleInfoInternal*) bundleInfo)->setId(m_bundles.size() - 1);
+ m_bundles.push_back((BundleInfoInternal *) bundleInfo);
+ ((BundleInfoInternal *) bundleInfo)->setId(m_bundles.size() - 1);
- const char* error;
+ char *error;
- activator_t* bundleActivator = NULL;
- deactivator_t* bundleDeactivator = NULL;
+ activator_t *bundleActivator = NULL;
+ deactivator_t *bundleDeactivator = NULL;
//sstream << bundleInfo.path << std::ends;
if (bundleHandle != NULL)
{
- bundleActivator = (activator_t*) dlsym(bundleHandle, "externalActivateBundle");
- bundleDeactivator = (deactivator_t*) dlsym(bundleHandle, "externalDeactivateBundle");
+ bundleActivator = (activator_t *) dlsym(bundleHandle, "externalActivateBundle");
+ bundleDeactivator = (deactivator_t *) dlsym(bundleHandle, "externalDeactivateBundle");
if ((error = dlerror()) != NULL)
{
error_logger() << error << endl;
}
else
{
- ((BundleInfoInternal*) bundleInfo)->setBundleActivator(bundleActivator);
- ((BundleInfoInternal*) bundleInfo)->setBundleDeactivator(bundleDeactivator);
- ((BundleInfoInternal*) bundleInfo)->setLoaded(true);
- ((BundleInfoInternal*) bundleInfo)->setBundleHandle(bundleHandle);
+ ((BundleInfoInternal *) bundleInfo)->setBundleActivator(bundleActivator);
+ ((BundleInfoInternal *) bundleInfo)->setBundleDeactivator(bundleDeactivator);
+ ((BundleInfoInternal *) bundleInfo)->setLoaded(true);
+ ((BundleInfoInternal *) bundleInfo)->setBundleHandle(bundleHandle);
}
}
else
void ResourceContainerImpl::activateBundle(int id)
{
- activator_t* bundleActivator = m_bundles[id]->getBundleActivator();
+ activator_t *bundleActivator = m_bundles[id]->getBundleActivator();
info_logger() << "Activating bundle: " << m_bundles[id]->getID() << ", "
- << m_bundles[id]->getId() << endl;
+ << m_bundles[id]->getId() << endl;
if (bundleActivator != NULL)
{
- bundleActivator(this);
+ bundleActivator(this, m_bundles[id]->getID());
m_bundles[id]->setActivated(true);
}
else
}
}
- void ResourceContainerImpl::activateBundle(BundleInfo* bundleInfo)
+ void ResourceContainerImpl::activateBundle(BundleInfo *bundleInfo)
{
- if (((BundleInfoInternal*) bundleInfo)->isLoaded())
+ if (((BundleInfoInternal *) bundleInfo)->isLoaded())
{
activateBundle(bundleInfo->getId());
}
}
- void ResourceContainerImpl::deactivateBundle(BundleInfo* bundleInfo)
+ void ResourceContainerImpl::deactivateBundle(BundleInfo *bundleInfo)
{
- if (((BundleInfoInternal*) bundleInfo)->isActivated())
+ if (((BundleInfoInternal *) bundleInfo)->isActivated())
{
deactivateBundle(bundleInfo->getId());
}
void ResourceContainerImpl::deactivateBundle(int id)
{
- deactivator_t* bundleDeactivator = m_bundles[id]->getBundleDeactivator();
+ deactivator_t *bundleDeactivator = m_bundles[id]->getBundleDeactivator();
info_logger() << "De-activating bundle: " << m_bundles[id]->getID() << ", "
- << m_bundles[id]->getId() << endl;
+ << m_bundles[id]->getId() << endl;
if (bundleDeactivator != NULL)
{
}
- vector< Resource* > ResourceContainerImpl::listBundleResources(string id)
+ vector< Resource * > ResourceContainerImpl::listBundleResources(string id)
{
- vector< Resource* > ret;
+ vector< Resource * > ret;
return ret;
}
- void ResourceContainerImpl::registerResource(Resource* resource)
+ void ResourceContainerImpl::registerResource(BundleResource *resource)
{
+ cout << "Register resource called.\n";
+ PrimitiveServerResource::Ptr server =
+ PrimitiveServerResource::Builder("/softSensors/discomfortIndex/1",
+ "core.softSensor",
+ "DEFAULT_INTERFACE").setObservable(false).setDiscoverable(true).create();
+
+ for (auto i : resource->m_mapAttributes)
+ {
+ cout << "Setting attribute " << i.first.c_str() << endl;
+ server->setAttribute(i.first.c_str(), i.second.c_str());
+ }
}
- void ResourceContainerImpl::unregisterResource(Resource* resource)
+ void ResourceContainerImpl::unregisterResource(BundleResource *resource)
{
}
- void ResourceContainerImpl::unregisterBundle(BundleInfo* bundleInfo){
- if (((BundleInfoInternal*) bundleInfo)->isLoaded() && !((BundleInfoInternal*) bundleInfo)->isActivated())
+ void ResourceContainerImpl::unregisterBundle(BundleInfo *bundleInfo)
+ {
+ if (((BundleInfoInternal *) bundleInfo)->isLoaded()
+ && !((BundleInfoInternal *) bundleInfo)->isActivated())
{
unregisterBundle(bundleInfo->getId());
}
}
- void ResourceContainerImpl::unregisterBundle(int id){
- void* bundleHandle = m_bundles[id]->getBundleHandle();
+ void ResourceContainerImpl::unregisterBundle(int id)
+ {
+ void *bundleHandle = m_bundles[id]->getBundleHandle();
info_logger() << "Unregister bundle: " << m_bundles[id]->getID() << ", "
- << m_bundles[id]->getId() << endl;
- const char* error;
+ << m_bundles[id]->getId() << endl;
+ char *error;
dlclose(bundleHandle);
if ((error = dlerror()) != NULL)
{
}
}
- ResourceContainerImpl* ResourceContainerImpl::getImplInstance()
+ ResourceContainerImpl *ResourceContainerImpl::getImplInstance()
{
- ResourceContainerImpl* ret = new ResourceContainerImpl();
+ ResourceContainerImpl *ret = new ResourceContainerImpl();
return ret;
}
+
+ void ResourceContainerImpl::getCommonConfiguration(configInfo *configOutput)
+ {
+ m_config->getCommonConfiguration((Configuration::configInfo *) configOutput);
+ }
+
+ void ResourceContainerImpl::getBundleConfiguration(std::string bundleId, configInfo *configOutput)
+ {
+ m_config->getBundleConfiguration(bundleId, (Configuration::configInfo *) configOutput);
+ }
+
+ void ResourceContainerImpl::getResourceConfiguration(std::string bundleId,
+ std::vector<resourceInfo> *configOutput)
+ {
+ m_config->getResourceConfiguration(bundleId, configOutput);
+ }
}
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "SoftSensorResource.h"
+
+using namespace RC;
+SoftSensorResource::SoftSensorResource()
+{
+
+}
+
+SoftSensorResource::~SoftSensorResource()
+{
+
+}
+
+