Add method of Things-Manager.
[platform/upstream/iotivity.git] / service / things-manager / sdk / src / ThingsManager.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /// @file    ThingsManager.cpp
22
23 #include "ThingsManager.h"
24 #include "GroupManager.h"
25 #include "GroupSynchronization.h"
26 #include "ThingsConfiguration.h"
27 #include "ThingsDiagnostics.h"
28 #include <algorithm>
29 #include <thread>
30
31 using namespace OC;
32 namespace OIC
33 {
34
35     GroupManager *g_groupManager;
36     GroupSynchronization *g_groupSync = NULL;
37     ThingsConfiguration *g_thingsConf = NULL;
38     ThingsDiagnostics *g_thingsDiag = NULL;
39
40     ThingsManager::ThingsManager(void)
41     {
42         g_groupManager = new GroupManager();
43         g_groupSync = GroupSynchronization::getInstance();
44         g_thingsConf = ThingsConfiguration::getInstance();
45         g_thingsDiag = ThingsDiagnostics::getInstance();
46         g_thingsConf->setGroupManager(g_groupManager);
47         g_thingsDiag->setGroupManager(g_groupManager);
48     }
49
50     /**
51      * Virtual destructor
52      */
53     ThingsManager::~ThingsManager(void)
54     {
55         delete g_groupManager;
56         g_groupSync->deleteInstance();
57         g_thingsConf->deleteInstance();
58         g_thingsDiag->deleteInstance();
59     }
60
61     OCStackResult ThingsManager::findCandidateResources(std::vector< std::string > resourceTypes,
62             std::function< void(std::vector< std::shared_ptr< OCResource > >) > callback,
63             int waitsec)
64     {
65         OCStackResult result = g_groupManager->findCandidateResources(resourceTypes, callback,
66                 waitsec);
67
68         return result;
69     }
70
71     OCStackResult ThingsManager::subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
72             std::function< void(std::string, OCStackResult) > callback)
73     {
74         OCStackResult result = g_groupManager->subscribeCollectionPresence(resource, callback);
75
76         return result;
77     }
78
79     OCStackResult ThingsManager::bindResourceToGroup(OCResourceHandle& childHandle, std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle)
80     {
81         OCStackResult result = g_groupManager->bindResourceToGroup(childHandle,resource,collectionHandle);
82
83         return result;
84     }
85
86     OCStackResult ThingsManager::findGroup(std::vector< std::string > collectionResourceTypes,
87             FindCallback callback)
88     {
89         OCStackResult result = g_groupSync->findGroup(collectionResourceTypes, callback);
90
91         return result;
92     }
93
94     OCStackResult ThingsManager::createGroup(std::string collectionResourceType)
95     {
96         OCStackResult result = g_groupSync->createGroup(collectionResourceType);
97
98         return result;
99     }
100
101     OCStackResult ThingsManager::joinGroup(std::string collectionResourceType,
102             OCResourceHandle resourceHandle)
103     {
104         OCStackResult result = g_groupSync->joinGroup(collectionResourceType, resourceHandle);
105
106         return result;
107     }
108
109     OCStackResult ThingsManager::joinGroup(const std::shared_ptr< OCResource > resource,
110             OCResourceHandle resourceHandle)
111     {
112         OCStackResult result = g_groupSync->joinGroup(resource, resourceHandle);
113
114         return result;
115     }
116
117     OCStackResult ThingsManager::leaveGroup(std::string collectionResourceType,
118             OCResourceHandle resourceHandle)
119     {
120         OCStackResult result = g_groupSync->leaveGroup(collectionResourceType, resourceHandle);
121
122         return result;
123     }
124
125     void ThingsManager::deleteGroup(std::string collectionResourceType)
126     {
127         g_groupSync->deleteGroup(collectionResourceType);
128     }
129
130     std::map< std::string, OCResourceHandle > ThingsManager::getGroupList()
131     {
132         return g_groupSync->getGroupList();
133     }
134
135     OCStackResult ThingsManager::updateConfigurations(std::shared_ptr< OCResource > resource,
136             std::map< ConfigurationName, ConfigurationValue > configurations,
137             ConfigurationCallback callback)
138     {
139         return g_thingsConf->updateConfigurations(resource, configurations, callback);
140     }
141     OCStackResult ThingsManager::getConfigurations(std::shared_ptr< OCResource > resource,
142             std::vector< ConfigurationName > configurations, ConfigurationCallback callback)
143     {
144         return g_thingsConf->getConfigurations(resource, configurations, callback);
145     }
146     std::string ThingsManager::getListOfSupportedConfigurationUnits()
147     {
148         return g_thingsConf->getListOfSupportedConfigurationUnits();
149     }
150
151     OCStackResult ThingsManager::doBootstrap(ConfigurationCallback callback)
152     {
153         return g_thingsConf->doBootstrap(callback);
154     }
155
156     OCStackResult ThingsManager::reboot(std::shared_ptr< OCResource > resource,
157             ConfigurationCallback callback)
158     {
159         return g_thingsDiag->reboot(resource, callback);
160     }
161     OCStackResult ThingsManager::factoryReset(std::shared_ptr< OCResource > resource,
162             ConfigurationCallback callback)
163     {
164         return g_thingsDiag->factoryReset(resource, callback);
165     }
166
167     std::string ThingsManager::getStringFromActionSet(const ActionSet *newActionSet)
168     {
169         return g_groupManager->getStringFromActionSet(newActionSet);
170     }
171     ActionSet* ThingsManager::getActionSetfromString(std::string desc)
172     {
173         return g_groupManager->getActionSetfromString(desc);
174     }
175     OCStackResult ThingsManager::addActionSet(std::shared_ptr< OCResource > resource,
176             const ActionSet* newActionSet, PutCallback cb)
177     {
178         return g_groupManager->addActionSet(resource, newActionSet, cb);
179     }
180     OCStackResult ThingsManager::executeActionSet(std::shared_ptr< OCResource > resource,
181             std::string actionsetName, PostCallback cb)
182     {
183         return g_groupManager->executeActionSet(resource, actionsetName, cb);
184     }
185     OCStackResult ThingsManager::getActionSet(std::shared_ptr< OCResource > resource,
186             std::string actionsetName, GetCallback cb)
187     {
188         return g_groupManager->getActionSet(resource, actionsetName, cb);
189     }
190     OCStackResult ThingsManager::deleteActionSet(std::shared_ptr< OCResource > resource,
191             std::string actionsetName, PostCallback cb)
192     {
193         return g_groupManager->deleteActionSet(resource, actionsetName, cb);
194     }
195 }