Removed execute permissions from non-executable files.
[platform/upstream/iotivity.git] / service / things-manager / sdk / src / GroupSynchronization.h
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   GroupSynchronizatin.h
22
23 /// @brief  This file contains the declaration of classes and its members related to GroupSynchronization.
24
25 #ifndef __OC_GROUPSYNCHRONIZATION__
26 #define __OC_GROUPSYNCHRONIZATION__
27
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <cstdlib>
32 #include "OCPlatform.h"
33 #include "OCApi.h"
34
35 using namespace OC;
36
37 class GroupSynchronization
38 {
39 private :
40
41     std::map<std::string, OCResourceHandle> collectionResourceHandleList;        // collection resource handle list
42
43     std::map<std::string, OCResourceHandle> groupSyncResourceHandleList;        // group sync resource handle list
44     std::map<std::string, std::shared_ptr< OCResource>> groupSyncResourceList;    // remote group sync resource list
45
46     std::vector<OCResourceHandle> deviceResourceHandleList;            // these cannot be removed.
47     OCResourceHandle deviceResourceHandle;
48
49     OCResourceHandle collectionResourceHandle;        // collection handle
50     std::shared_ptr< OCResource> remoteCollectionResource;
51
52     std::map<OCResourceHandle, std::vector<OCResourceHandle>> childResourceHandleList;
53
54     FindCallback findCallback;
55     std::vector<std::shared_ptr< OCResource >> foundGroupResourceList;
56
57     std::mutex foundGroupMutex;
58     std::mutex groupSyncMutex;
59
60     std::shared_ptr<OCResourceRequest> resourceRequest;        // this is used for slow response
61
62     static GroupSynchronization* groupSyncnstance;
63
64
65     GroupSynchronization ()
66     {
67         collectionResourceHandleList.clear();
68         groupSyncResourceHandleList.clear();
69         groupSyncResourceList.clear();
70         foundGroupResourceList.clear();
71         deviceResourceHandleList.clear();
72
73         deviceResourceHandle = NULL;
74         remoteCollectionResource = NULL;
75         findCallback = NULL;
76     };
77
78     ~GroupSynchronization ()
79     {
80         std::map<std::string, OCResourceHandle>::iterator handleIt;
81         for (handleIt = collectionResourceHandleList.begin(); handleIt != collectionResourceHandleList.end(); ++handleIt)
82         {
83             deleteGroup (handleIt->first);
84         }
85     };
86
87
88 public :
89
90     static GroupSynchronization* getInstance ();
91     void deleteInstance();
92
93     OCStackResult findGroup (std::vector <std::string> collectionResourceTypes, FindCallback resourceHandler);
94     OCStackResult createGroup (std::string collectionResourceType);
95     OCStackResult joinGroup (std::string collectionResourceTyps, OCResourceHandle resourceHandle);
96     OCStackResult joinGroup (const std::shared_ptr<OCResource> resource, OCResourceHandle resourceHandle);
97     OCStackResult leaveGroup (std::string collectionResourceType, OCResourceHandle resourceHandle);
98     void deleteGroup (std::string collectionResourceType);
99
100     std::map<std::string, OCResourceHandle> getGroupList ();
101
102 private : 
103
104     OCEntityHandlerResult groupEntityHandler(const std::shared_ptr<OCResourceRequest> request);
105
106     void onFindGroup(std::shared_ptr< OCResource > resource);
107     void onJoinGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
108     void onFindResource (std::shared_ptr<OCResource> resource);
109     void onGetJoinedRemoteChild(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
110     void onLeaveGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
111 //    void onSubscribePresence (OCStackResult result, const unsigned int nonce/*, std::string resourceType, std::string host*/);
112
113     void checkFindGroup (void);
114     bool IsSameGroup (std::shared_ptr< OCResource > resource);
115     void saveGroup (std::shared_ptr< OCResource > resource);
116
117     void debugGroupSync (void);
118
119 };
120
121 #endif    // __OC_GROUPSYNCHRONIZATION__