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 "DISensorBundleActivator.h"
25 #include "DiscomfortIndexSensorResource.h"
27 DISensorBundleActivator *bundle;
29 DISensorBundleActivator::DISensorBundleActivator()
31 m_pResourceContainer = nullptr;
34 DISensorBundleActivator::~DISensorBundleActivator()
36 m_pResourceContainer = nullptr;
39 void DISensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
42 m_pResourceContainer = resourceContainer;
43 m_bundleId = bundleId;
45 std::vector<resourceInfo> resourceConfig;
47 resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
49 for (vector<resourceInfo>::iterator itor = resourceConfig.begin();
50 itor != resourceConfig.end(); itor++)
52 createResource(*itor);
56 void DISensorBundleActivator::deactivateBundle()
58 std::vector< BundleResource::Ptr >::iterator itor;
59 for (itor = m_vecResources.begin(); itor != m_vecResources.end();)
61 destroyResource(*itor);
65 void DISensorBundleActivator::createResource(resourceInfo resourceInfo)
67 if (resourceInfo.resourceType == "oic.r.sensor")
69 static int discomfortIndexSensorCount = 1;
71 // create DISensor resource
72 BundleResource::Ptr newResource = std::make_shared< DiscomfortIndexSensorResource >();
74 newResource->m_bundleId = m_bundleId;
76 std::string indexCount;//string which will contain the indexCount
77 stringstream convert; // stringstream used for the conversion
78 convert << discomfortIndexSensorCount++;//add the value of Number to the characters in the stream
79 indexCount = convert.str();//set indexCount to the content of the stream
81 newResource->m_uri = "/softsensor/discomfortIndex/" + indexCount;
83 newResource->m_resourceType = resourceInfo.resourceType;
84 newResource->m_mapResourceProperty = resourceInfo.resourceProperty;
86 newResource->initAttributes();
88 m_pResourceContainer->registerResource(newResource);
89 m_vecResources.push_back(newResource);
93 void DISensorBundleActivator::destroyResource(BundleResource::Ptr resource)
95 std::vector< BundleResource::Ptr >::iterator itor;
97 itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
99 if (itor != m_vecResources.end())
101 m_pResourceContainer->unregisterResource(resource);
102 m_vecResources.erase(itor);
106 extern "C" void disensor_externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
107 std::string bundleId)
109 bundle = new DISensorBundleActivator();
110 bundle->activateBundle(resourceContainer, bundleId);
113 extern "C" void disensor_externalDeactivateBundle()
115 bundle->deactivateBundle();
119 extern "C" void disensor_externalCreateResource(resourceInfo resourceInfo)
121 bundle->createResource(resourceInfo);
124 extern "C" void disensor_externalDestroyResource(BundleResource::Ptr pBundleResource)
126 bundle->destroyResource(pBundleResource);