1 //******************************************************************
3 // Copyright 2014 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26 #include "ThingsManager.h"
27 #include "GroupManager.h"
28 #include "GroupSynchronization.h"
29 #include "ThingsConfiguration.h"
30 #include "ThingsDiagnostics.h"
38 GroupManager *g_groupManager;
39 GroupSynchronization *g_groupSync = NULL;
40 ThingsConfiguration *g_thingsConf = NULL;
41 ThingsDiagnostics *g_thingsDiag = NULL;
43 ThingsManager::ThingsManager(void)
45 g_groupManager = new GroupManager();
46 g_groupSync = GroupSynchronization::getInstance();
47 g_thingsConf = ThingsConfiguration::getInstance();
48 g_thingsDiag = ThingsDiagnostics::getInstance();
49 g_thingsConf->setGroupManager(g_groupManager);
50 g_thingsDiag->setGroupManager(g_groupManager);
56 ThingsManager::~ThingsManager(void)
58 delete g_groupManager;
59 g_groupSync->deleteInstance();
60 g_thingsConf->deleteInstance();
61 g_thingsDiag->deleteInstance();
64 OCStackResult ThingsManager::findCandidateResources(std::vector< std::string > resourceTypes,
65 std::function< void(std::vector< std::shared_ptr< OCResource > >) > callback,
68 OCStackResult result = g_groupManager->findCandidateResources(resourceTypes, callback,
74 OCStackResult ThingsManager::subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
75 std::function< void(std::string, OCStackResult) > callback)
77 OCStackResult result = g_groupManager->subscribeCollectionPresence(resource, callback);
82 OCStackResult ThingsManager::bindResourceToGroup(OCResourceHandle& childHandle, std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle)
84 OCStackResult result = g_groupManager->bindResourceToGroup(childHandle,resource,collectionHandle);
89 OCStackResult ThingsManager::findGroup(std::vector< std::string > collectionResourceTypes,
90 FindCallback callback)
92 OCStackResult result = g_groupSync->findGroup(collectionResourceTypes, callback);
97 OCStackResult ThingsManager::createGroup(std::string collectionResourceType)
99 OCStackResult result = g_groupSync->createGroup(collectionResourceType);
104 OCStackResult ThingsManager::joinGroup(std::string collectionResourceType,
105 OCResourceHandle resourceHandle)
107 OCStackResult result = g_groupSync->joinGroup(collectionResourceType, resourceHandle);
112 OCStackResult ThingsManager::joinGroup(const std::shared_ptr< OCResource > resource,
113 OCResourceHandle resourceHandle)
115 OCStackResult result = g_groupSync->joinGroup(resource, resourceHandle);
120 OCStackResult ThingsManager::leaveGroup(std::string collectionResourceType,
121 OCResourceHandle resourceHandle)
123 OCStackResult result = g_groupSync->leaveGroup(collectionResourceType, resourceHandle);
128 OCStackResult ThingsManager::leaveGroup(const std::shared_ptr< OCResource > resource,
129 std::string collectionResourceType,
130 OCResourceHandle resourceHandle)
132 return g_groupSync->leaveGroup(resource, collectionResourceType, resourceHandle);
135 void ThingsManager::deleteGroup(std::string collectionResourceType)
137 g_groupSync->deleteGroup(collectionResourceType);
140 std::map< std::string, OCResourceHandle > ThingsManager::getGroupList()
142 return g_groupSync->getGroupList();
145 OCStackResult ThingsManager::updateConfigurations(std::shared_ptr< OCResource > resource,
146 std::map< ConfigurationName, ConfigurationValue > configurations,
147 ConfigurationCallback callback)
149 return g_thingsConf->updateConfigurations(resource, configurations, callback);
151 OCStackResult ThingsManager::getConfigurations(std::shared_ptr< OCResource > resource,
152 std::vector< ConfigurationName > configurations, ConfigurationCallback callback)
154 return g_thingsConf->getConfigurations(resource, configurations, callback);
156 std::string ThingsManager::getListOfSupportedConfigurationUnits()
158 return g_thingsConf->getListOfSupportedConfigurationUnits();
161 OCStackResult ThingsManager::doBootstrap(ConfigurationCallback callback)
163 return g_thingsConf->doBootstrap(callback);
166 OCStackResult ThingsManager::reboot(std::shared_ptr< OCResource > resource,
167 ConfigurationCallback callback)
169 return g_thingsDiag->reboot(resource, callback);
171 OCStackResult ThingsManager::factoryReset(std::shared_ptr< OCResource > resource,
172 ConfigurationCallback callback)
174 return g_thingsDiag->factoryReset(resource, callback);
177 std::string ThingsManager::getStringFromActionSet(const ActionSet *newActionSet)
179 return g_groupManager->getStringFromActionSet(newActionSet);
181 ActionSet* ThingsManager::getActionSetfromString(std::string desc)
183 return g_groupManager->getActionSetfromString(desc);
185 OCStackResult ThingsManager::addActionSet(std::shared_ptr< OCResource > resource,
186 const ActionSet* newActionSet, PutCallback cb)
188 return g_groupManager->addActionSet(resource, newActionSet, cb);
190 OCStackResult ThingsManager::executeActionSet(std::shared_ptr< OCResource > resource,
191 std::string actionsetName, PostCallback cb)
193 return g_groupManager->executeActionSet(resource, actionsetName, cb);
195 OCStackResult ThingsManager::executeActionSet(std::shared_ptr< OCResource > resource,
196 std::string actionsetName, long int delay, PostCallback cb)
198 return g_groupManager->executeActionSet(resource, actionsetName, delay, cb);
200 OCStackResult ThingsManager::cancelActionSet(std::shared_ptr< OCResource > resource,
201 std::string actionsetName, PostCallback cb)
203 return g_groupManager->cancelActionSet(resource, actionsetName, cb);
205 OCStackResult ThingsManager::getActionSet(std::shared_ptr< OCResource > resource,
206 std::string actionsetName, GetCallback cb)
208 return g_groupManager->getActionSet(resource, actionsetName, cb);
210 OCStackResult ThingsManager::deleteActionSet(std::shared_ptr< OCResource > resource,
211 std::string actionsetName, PostCallback cb)
213 return g_groupManager->deleteActionSet(resource, actionsetName, cb);