Removed execute permissions from non-executable files.
[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 ///  @brief
23
24 #include "ThingsManager.h"
25 #include "GroupManager.h"
26 #include "GroupSynchronization.h"
27 #include "ThingsConfiguration.h"
28 #include "ThingsDiagnostics.h"
29 #include <algorithm>
30 #include <thread>
31
32
33 using namespace OC;
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
62
63 OCStackResult ThingsManager::findCandidateResources(std::vector< std::string > resourceTypes,
64         std::function< void(std::vector< std::shared_ptr< OCResource > >) >  callback, int waitsec)
65 {
66     OCStackResult result = g_groupManager->findCandidateResources(resourceTypes,callback,waitsec);
67
68     return result;
69 }
70
71 OCStackResult ThingsManager::subscribeCollectionPresence(std::shared_ptr< OCResource > resource, std::function< void(std::string, OCStackResult) >  callback)
72 {
73     OCStackResult result = g_groupManager->subscribeCollectionPresence(resource,callback);
74
75     return result;
76 }
77
78 OCStackResult ThingsManager::findGroup (std::vector<std::string> collectionResourceTypes, FindCallback resourceHandler)
79 {
80         OCStackResult result = g_groupSync->findGroup(collectionResourceTypes, resourceHandler);
81
82         return result;
83 }
84
85 OCStackResult ThingsManager::createGroup (std::string collectionResourceType)
86 {
87         OCStackResult result = g_groupSync->createGroup(collectionResourceType);
88
89         return result;
90 }
91
92 OCStackResult ThingsManager::joinGroup (std::string collectionResourceType, OCResourceHandle resourceHandle)
93 {
94         OCStackResult result = g_groupSync->joinGroup(collectionResourceType, resourceHandle);
95
96         return result;
97 }
98
99 OCStackResult ThingsManager::joinGroup (const std::shared_ptr<OCResource> resource, OCResourceHandle resourceHandle)
100 {
101         OCStackResult result = g_groupSync->joinGroup(resource, resourceHandle);
102
103         return result;
104 }
105
106 OCStackResult ThingsManager::leaveGroup (std::string collectionResourceType, OCResourceHandle resourceHandle)
107 {
108         OCStackResult result = g_groupSync->leaveGroup(collectionResourceType, resourceHandle);
109
110         return result;
111 }
112
113 void ThingsManager::deleteGroup (std::string collectionResourceType)
114 {
115         g_groupSync->deleteGroup(collectionResourceType);
116 }
117
118 std::map<std::string, OCResourceHandle> ThingsManager::getGroupList ()
119 {
120         return g_groupSync->getGroupList();
121 }
122
123 OCStackResult ThingsManager::updateConfigurations(std::shared_ptr< OCResource > resource, std::map<ConfigurationName, ConfigurationValue> configurations, ConfigurationCallback callback)
124 {
125     return g_thingsConf->updateConfigurations(resource, configurations, callback);
126 }
127 OCStackResult ThingsManager::getConfigurations(std::shared_ptr< OCResource > resource, std::vector<ConfigurationName> configurations, ConfigurationCallback callback)
128 {
129     return g_thingsConf->getConfigurations( resource,  configurations, callback);
130 }
131 std::string ThingsManager::getListOfSupportedConfigurationUnits()
132 {
133     return g_thingsConf->getListOfSupportedConfigurationUnits();
134 }
135
136 OCStackResult ThingsManager::doBootstrap(ConfigurationCallback callback)
137 {
138     return g_thingsConf->doBootstrap(callback);
139 }
140
141
142 OCStackResult ThingsManager::reboot(std::shared_ptr< OCResource > resource, ConfigurationCallback callback)
143 {
144     return g_thingsDiag->reboot( resource, callback);
145 }
146 OCStackResult ThingsManager::factoryReset(std::shared_ptr< OCResource > resource, ConfigurationCallback callback)
147 {
148     return g_thingsDiag->factoryReset(  resource,  callback);
149 }
150
151
152
153 std::string ThingsManager::getStringFromActionSet(const ActionSet *newActionSet)
154 {
155     return g_groupManager->getStringFromActionSet(newActionSet);
156 }
157 ActionSet* ThingsManager::getActionSetfromString(std::string desc)
158 {
159    return g_groupManager->getActionSetfromString(desc);
160 }
161 OCStackResult ThingsManager::addActionSet(std::shared_ptr< OCResource > resource, const ActionSet* newActionSet, PutCallback cb)
162 {
163     return g_groupManager->addActionSet(resource, newActionSet, cb);
164 }
165 OCStackResult ThingsManager::executeActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName, PostCallback cb)
166 {
167     return g_groupManager->executeActionSet(resource, actionsetName, cb);
168 }
169 OCStackResult ThingsManager::getActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName, GetCallback cb)
170 {
171     return g_groupManager->getActionSet(resource, actionsetName, cb);
172 }
173 OCStackResult ThingsManager::deleteActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName, PostCallback cb)
174 {
175     return g_groupManager->deleteActionSet(resource, actionsetName, cb);
176 }