Modifying version number for building on tizen 3.0
[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::findGroup(std::vector< std::string > collectionResourceTypes,
80             FindCallback callback)
81     {
82         OCStackResult result = g_groupSync->findGroup(collectionResourceTypes, callback);
83
84         return result;
85     }
86
87     OCStackResult ThingsManager::createGroup(std::string collectionResourceType)
88     {
89         OCStackResult result = g_groupSync->createGroup(collectionResourceType);
90
91         return result;
92     }
93
94     OCStackResult ThingsManager::joinGroup(std::string collectionResourceType,
95             OCResourceHandle resourceHandle)
96     {
97         OCStackResult result = g_groupSync->joinGroup(collectionResourceType, resourceHandle);
98
99         return result;
100     }
101
102     OCStackResult ThingsManager::joinGroup(const std::shared_ptr< OCResource > resource,
103             OCResourceHandle resourceHandle)
104     {
105         OCStackResult result = g_groupSync->joinGroup(resource, resourceHandle);
106
107         return result;
108     }
109
110     OCStackResult ThingsManager::leaveGroup(std::string collectionResourceType,
111             OCResourceHandle resourceHandle)
112     {
113         OCStackResult result = g_groupSync->leaveGroup(collectionResourceType, resourceHandle);
114
115         return result;
116     }
117
118     void ThingsManager::deleteGroup(std::string collectionResourceType)
119     {
120         g_groupSync->deleteGroup(collectionResourceType);
121     }
122
123     std::map< std::string, OCResourceHandle > ThingsManager::getGroupList()
124     {
125         return g_groupSync->getGroupList();
126     }
127
128     OCStackResult ThingsManager::updateConfigurations(std::shared_ptr< OCResource > resource,
129             std::map< ConfigurationName, ConfigurationValue > configurations,
130             ConfigurationCallback callback)
131     {
132         return g_thingsConf->updateConfigurations(resource, configurations, callback);
133     }
134     OCStackResult ThingsManager::getConfigurations(std::shared_ptr< OCResource > resource,
135             std::vector< ConfigurationName > configurations, ConfigurationCallback callback)
136     {
137         return g_thingsConf->getConfigurations(resource, configurations, callback);
138     }
139     std::string ThingsManager::getListOfSupportedConfigurationUnits()
140     {
141         return g_thingsConf->getListOfSupportedConfigurationUnits();
142     }
143
144     OCStackResult ThingsManager::doBootstrap(ConfigurationCallback callback)
145     {
146         return g_thingsConf->doBootstrap(callback);
147     }
148
149     OCStackResult ThingsManager::reboot(std::shared_ptr< OCResource > resource,
150             ConfigurationCallback callback)
151     {
152         return g_thingsDiag->reboot(resource, callback);
153     }
154     OCStackResult ThingsManager::factoryReset(std::shared_ptr< OCResource > resource,
155             ConfigurationCallback callback)
156     {
157         return g_thingsDiag->factoryReset(resource, callback);
158     }
159
160     std::string ThingsManager::getStringFromActionSet(const ActionSet *newActionSet)
161     {
162         return g_groupManager->getStringFromActionSet(newActionSet);
163     }
164     ActionSet* ThingsManager::getActionSetfromString(std::string desc)
165     {
166         return g_groupManager->getActionSetfromString(desc);
167     }
168     OCStackResult ThingsManager::addActionSet(std::shared_ptr< OCResource > resource,
169             const ActionSet* newActionSet, PutCallback cb)
170     {
171         return g_groupManager->addActionSet(resource, newActionSet, cb);
172     }
173     OCStackResult ThingsManager::executeActionSet(std::shared_ptr< OCResource > resource,
174             std::string actionsetName, PostCallback cb)
175     {
176         return g_groupManager->executeActionSet(resource, actionsetName, cb);
177     }
178     OCStackResult ThingsManager::getActionSet(std::shared_ptr< OCResource > resource,
179             std::string actionsetName, GetCallback cb)
180     {
181         return g_groupManager->getActionSet(resource, actionsetName, cb);
182     }
183     OCStackResult ThingsManager::deleteActionSet(std::shared_ptr< OCResource > resource,
184             std::string actionsetName, PostCallback cb)
185     {
186         return g_groupManager->deleteActionSet(resource, actionsetName, cb);
187     }
188 }