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