1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 /// @file GroupSynchronization.h
23 /// @brief This file contains the declaration of classes and
24 ///its members related to GroupSynchronization.
26 #ifndef __OC_GROUPSYNCHRONIZATION__
27 #define __OC_GROUPSYNCHRONIZATION__
33 #include "OCPlatform.h"
40 class GroupSynchronization
44 std::map< std::string, OCResourceHandle > collectionResourceHandleList;
45 // collection resource handle list
46 std::map< OCResourceHandle, std::vector< OCResourceHandle > > childResourceHandleList;
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
53 std::vector< OCResourceHandle > deviceResourceHandleList; // these cannot be removed.
54 OCResourceHandle deviceResourceHandle;
56 OCResourceHandle collectionResourceHandle; // collection handle
57 std::shared_ptr< OCResource > remoteCollectionResource;
59 FindCallback findCallback;
61 std::vector< std::shared_ptr< OCResource > > foundGroupResourceList;
63 std::mutex foundGroupMutex;
64 // std::mutex groupSyncMutex;
66 std::shared_ptr< OCResourceRequest > resourceRequest; // this is used for slow response
68 static GroupSynchronization* groupSyncnstance;
70 GroupSynchronization()
72 collectionResourceHandleList.clear();
73 childResourceHandleList.clear();
74 groupSyncResourceHandleList.clear();
75 groupSyncResourceList.clear();
76 deviceResourceHandleList.clear();
78 deviceResourceHandle = NULL;
79 collectionResourceHandle = NULL;
80 remoteCollectionResource = NULL;
85 ~GroupSynchronization()
87 std::map< std::string, OCResourceHandle >::iterator handleIt;
88 for (handleIt = collectionResourceHandleList.begin();
89 handleIt != collectionResourceHandleList.end(); ++handleIt)
91 deleteGroup(handleIt->first);
98 static GroupSynchronization* getInstance();
99 void deleteInstance();
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);
112 std::map< std::string, OCResourceHandle > getGroupList();
116 OCEntityHandlerResult groupEntityHandler(
117 const std::shared_ptr< OCResourceRequest > request);
119 void onFindGroup(std::shared_ptr< OCResource > resource);
120 void onJoinGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep,
122 void onFindResource(std::shared_ptr< OCResource > resource);
123 void onGetJoinedRemoteChild(const HeaderOptions& headerOptions, const OCRepresentation& rep,
125 void onLeaveGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep,
127 // void onSubscribePresence (OCStackResult result,
128 // const unsigned int nonce/*, std::string resourceType, std::string host*/);
130 void checkFindGroup(void);
131 bool IsSameGroup(std::shared_ptr< OCResource > resource);
132 void saveGroup(std::shared_ptr< OCResource > resource);
134 void debugGroupSync(void);
138 #endif // __OC_GROUPSYNCHRONIZATION__