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"
25 SoftSensorBundleActivator *bundle;
27 SoftSensorBundleActivator::SoftSensorBundleActivator()
29 m_pResourceContainer = nullptr;
32 SoftSensorBundleActivator::~SoftSensorBundleActivator()
34 m_pResourceContainer = nullptr;
37 void SoftSensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
40 m_pResourceContainer = resourceContainer;
41 m_bundleId = bundleId;
43 std::vector<resourceInfo> resourceConfig;
45 resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
47 for (vector<resourceInfo>::iterator itor = resourceConfig.begin();
48 itor != resourceConfig.end(); itor++)
50 createResource(*itor);
54 void SoftSensorBundleActivator::deactivateBundle()
56 std::vector<BundleResource *>::iterator itor;
57 for (itor = m_vecResources.begin(); itor != m_vecResources.end();)
59 destroyResource(*itor);
63 void SoftSensorBundleActivator::createResource(resourceInfo resourceInfo)
65 if (resourceInfo.resourceType == "oic.softsensor")
67 static int discomfortIndexSensorCount = 1;
69 // create DISensor resource
70 DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource();
72 newResource->m_bundleId = m_bundleId;
73 newResource->m_uri = "/softsensor/discomfortIndex/" + std::to_string(
74 discomfortIndexSensorCount++);
75 newResource->m_resourceType = resourceInfo.resourceType;
76 newResource->m_mapResourceProperty = resourceInfo.resourceProperty;
78 newResource->initAttributes();
80 m_pResourceContainer->registerResource(newResource);
81 m_vecResources.push_back(newResource);
85 void SoftSensorBundleActivator::destroyResource(BundleResource *resource)
87 std::vector <BundleResource *>::iterator itor;
89 itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
91 if (itor != m_vecResources.end())
93 m_pResourceContainer->unregisterResource(resource);
94 m_vecResources.erase(itor);
98 extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
101 bundle = new SoftSensorBundleActivator();
102 bundle->activateBundle(resourceContainer, bundleId);
105 extern "C" void externalDeactivateBundle()
107 bundle->deactivateBundle();
111 extern "C" void externalCreateResource(resourceInfo resourceInfo)
113 bundle->createResource(resourceInfo);
116 extern "C" void externalDestroyResource(BundleResource *pBundleResource)
118 bundle->destroyResource(pBundleResource);