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 "BMISensorBundleActivator.h"
25 #include "BMISensorResource.h"
28 BMISensorBundleActivator *bundle;
30 BMISensorBundleActivator::BMISensorBundleActivator()
32 m_pResourceContainer = nullptr;
35 BMISensorBundleActivator::~BMISensorBundleActivator()
37 m_pResourceContainer = nullptr;
40 void BMISensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
43 m_pResourceContainer = resourceContainer;
44 m_bundleId = bundleId;
46 std::vector<resourceInfo> resourceConfig;
48 resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
50 for (vector<resourceInfo>::iterator itor = resourceConfig.begin();
51 itor != resourceConfig.end(); itor++)
53 createResource(*itor);
57 void BMISensorBundleActivator::deactivateBundle()
59 std::vector< BundleResource::Ptr >::iterator itor;
60 for (itor = m_vecResources.begin(); itor != m_vecResources.end();)
62 destroyResource(*itor);
66 void BMISensorBundleActivator::createResource(resourceInfo resourceInfo)
68 if (resourceInfo.resourceType == "oic.r.sensor")
70 static int BMISensorCount = 1;
72 // create BMISensor resource
73 BundleResource::Ptr newResource = std::make_shared< BMISensorResource >();
75 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 << BMISensorCount++;//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/BMIsensor/" + 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 BMISensorBundleActivator::destroyResource(BundleResource::Ptr resource)
94 std::vector< BundleResource::Ptr >::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 bmisensor_externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
106 std::string bundleId)
108 bundle = new BMISensorBundleActivator();
109 bundle->activateBundle(resourceContainer, bundleId);
112 extern "C" void bmisensor_externalDeactivateBundle()
114 bundle->deactivateBundle();
118 extern "C" void bmisensor_externalCreateResource(resourceInfo resourceInfo)
120 bundle->createResource(resourceInfo);
123 extern "C" void bmisensor_externalDestroyResource(BundleResource::Ptr pBundleResource)
125 bundle->destroyResource(pBundleResource);