1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "SoftSensorBundleActivator.h"
22 #include "DiscomfortIndexSensorResource.h"
26 SoftSensorBundleActivator *bundle;
28 SoftSensorBundleActivator::SoftSensorBundleActivator()
30 m_pResourceContainer = nullptr;
33 SoftSensorBundleActivator::~SoftSensorBundleActivator()
35 m_pResourceContainer = nullptr;
38 void SoftSensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
41 m_pResourceContainer = resourceContainer;
42 m_bundleId = bundleId;
44 std::vector<resourceInfo> resourceConfig;
46 resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
48 for (vector<resourceInfo>::iterator itor = resourceConfig.begin();
49 itor != resourceConfig.end(); itor++)
51 createResource(*itor);
55 void SoftSensorBundleActivator::deactivateBundle()
57 std::vector<BundleResource *>::iterator itor;
58 for (itor = m_vecResources.begin(); itor != m_vecResources.end();)
60 destroyResource(*itor);
64 void SoftSensorBundleActivator::createResource(resourceInfo resourceInfo)
66 if (resourceInfo.resourceType == "oic.softsensor")
68 static int discomfortIndexSensorCount = 1;
70 // create DISensor resource
71 DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource();
73 newResource->m_bundleId = m_bundleId;
75 std::string indexCount;//string which will contain the indexCount
76 stringstream convert; // stringstream used for the conversion
77 convert << discomfortIndexSensorCount++;//add the value of Number to the characters in the stream
78 indexCount = convert.str();//set indexCount to the content of the stream
80 newResource->m_uri = "/softsensor/discomfortIndex/" + indexCount;
82 newResource->m_resourceType = resourceInfo.resourceType;
83 newResource->m_mapResourceProperty = resourceInfo.resourceProperty;
85 newResource->initAttributes();
87 m_pResourceContainer->registerResource(newResource);
88 m_vecResources.push_back(newResource);
92 void SoftSensorBundleActivator::destroyResource(BundleResource *resource)
94 std::vector <BundleResource *>::iterator itor;
96 itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
98 if (itor != m_vecResources.end())
100 m_pResourceContainer->unregisterResource(resource);
101 m_vecResources.erase(itor);
105 extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
106 std::string bundleId)
108 bundle = new SoftSensorBundleActivator();
109 bundle->activateBundle(resourceContainer, bundleId);
112 extern "C" void externalDeactivateBundle()
114 bundle->deactivateBundle();
118 extern "C" void externalCreateResource(resourceInfo resourceInfo)
120 bundle->createResource(resourceInfo);
123 extern "C" void externalDestroyResource(BundleResource *pBundleResource)
125 bundle->destroyResource(pBundleResource);