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"
24 SoftSensorBundleActivator *bundle;
26 SoftSensorBundleActivator::SoftSensorBundleActivator()
30 SoftSensorBundleActivator::~SoftSensorBundleActivator()
34 void SoftSensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
37 std::cout << "SoftSensorSampleBundle::activateBundle called" << std::endl;
39 m_pResourceContainer = resourceContainer;
40 m_bundleId = bundleId;
42 vector<resourceInfo> resourceConfig;
44 resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
46 for (vector<resourceInfo>::iterator itor = resourceConfig.begin();
47 itor != resourceConfig.end(); itor++)
49 createResource(*itor);
53 void SoftSensorBundleActivator::deactivateBundle()
55 std::cout << "SoftSensorSampleBundle::deactivateBundle called" << std::endl;
57 for (std::vector<BundleResource *>::iterator itor = m_vecResources.begin();
58 itor != m_vecResources.end(); itor++)
60 destroyResource(*itor);
63 m_vecResources.clear();
66 void SoftSensorBundleActivator::createResource(resourceInfo resourceInfo)
68 std::cout << "SoftSensorSampleBundle::createResource called" << std::endl;
70 static int discomfortIndexSensorCount = 1;
72 std::vector< std::map< std::string, std::string > >::iterator itor_vec;
73 std::map< std::string, std::string >::iterator itor_map;
74 std::vector <std::string> inputs;
76 for (itor_vec = resourceInfo.resourceProperty["input"].begin();
77 itor_vec != resourceInfo.resourceProperty["input"].end(); itor_vec++)
79 for (itor_map = (*itor_vec).begin(); itor_map != (*itor_vec).end(); itor_map++)
81 inputs.push_back(itor_map->second);
84 std::cout << "SoftSensorSampleBundle::creating new discomfort index sensor " << std::endl;
85 // create DISensor resource
86 DiscomfortIndexSensorResource *newResource = new DiscomfortIndexSensorResource(inputs);
88 newResource->m_uri = "/softsensor/discomfortIndex/" + std::to_string(
89 discomfortIndexSensorCount++);
90 newResource->m_resourceType = resourceInfo.resourceType;
91 newResource->m_mapResourceProperty = resourceInfo.resourceProperty;
93 // setting input Attributes count
94 newResource->inputCount = newResource->m_mapResourceProperty["input"].size();
96 m_pResourceContainer->registerResource(newResource);
97 m_vecResources.push_back(newResource);
100 void SoftSensorBundleActivator::destroyResource(BundleResource *resource)
102 std::cout << "SoftSensorSampleBundle::destroyResource called" << std::endl;
104 std::vector <BundleResource *>::iterator itor;
106 itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
108 if (itor != m_vecResources.end())
110 m_pResourceContainer->unregisterResource(resource);
114 /*std::cout << "Clearing up memory.\n";*/
117 extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
118 std::string bundleId)
120 bundle = new SoftSensorBundleActivator();
121 bundle->activateBundle(resourceContainer, bundleId);
124 extern "C" void externalDeactivateBundle()
126 bundle->deactivateBundle();