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 "HueSampleBundleActivator.h"
27 using namespace OIC::Service;
29 HueSampleBundleActivator *bundle;
31 HueSampleBundleActivator::HueSampleBundleActivator()
35 HueSampleBundleActivator::~HueSampleBundleActivator()
39 void HueSampleBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
42 std::cout << "HueSampleBundle::activateBundle called" << std::endl;
44 m_pResourceContainer = resourceContainer;
45 m_bundleId = bundleId;
46 m_connector = new HueConnector();
48 vector< resourceInfo > resourceConfig;
50 resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig);
52 for (vector< resourceInfo >::iterator itor = resourceConfig.begin();
53 itor != resourceConfig.end(); itor++)
55 createResource(*itor);
59 void HueSampleBundleActivator::deactivateBundle()
61 std::cout << "HueSampleBundle::deactivateBundle called" << std::endl;
63 for (std::vector< BundleResource * >::iterator itor = m_vecResources.begin();
64 itor != m_vecResources.end(); itor++)
66 destroyResource(*itor);
70 void HueSampleBundleActivator::createResource(resourceInfo resourceInfo)
72 std::cout << "HueSampleBundle::createResource called" << std::endl;
74 if (resourceInfo.resourceType == "oic.light.control")
76 static int lightCount = 1;
77 HueLight* hueLight = new HueLight(m_connector, resourceInfo.address);
78 resourceInfo.uri = "/hue/light/" + std::to_string(lightCount++);
79 std::cout << "Registering resource " << resourceInfo.uri << std::endl;
80 hueLight->m_uri = resourceInfo.uri;
81 hueLight->m_resourceType = resourceInfo.resourceType;
82 hueLight->m_name = resourceInfo.name;
84 m_pResourceContainer->registerResource(hueLight);
85 m_vecResources.push_back(hueLight);
89 void HueSampleBundleActivator::destroyResource(BundleResource *resource)
91 std::cout << "HueSampleBundle::destroyResource called" << resource->m_uri << std::endl;
93 std::vector< BundleResource * >::iterator itor;
95 itor = std::find(m_vecResources.begin(), m_vecResources.end(), resource);
97 if (itor != m_vecResources.end())
99 m_pResourceContainer->unregisterResource(resource);
103 /*std::cout << "Clearing up memory.\n";
105 if (itor != m_vecResources.end())
106 m_vecResources.erase(itor);*/
114 extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
115 std::string bundleId)
117 bundle = new HueSampleBundleActivator();
118 bundle->activateBundle(resourceContainer, bundleId);
121 extern "C" void externalDeactivateBundle()
123 bundle->deactivateBundle();