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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the declaration of classes and its members related to
25 * GroupSynchronization.
28 #ifndef __OC_GROUPSYNCHRONIZATION__
29 #define __OC_GROUPSYNCHRONIZATION__
35 #include "OCPlatform.h"
42 class GroupSynchronization
46 std::map< std::string, OCResourceHandle > collectionResourceHandleList;
47 // collection resource handle list
48 std::map< OCResourceHandle, std::vector< OCResourceHandle > > childResourceHandleList;
50 std::map< std::string, OCResourceHandle > groupSyncResourceHandleList;
51 // group sync resource handle list
52 std::map< std::string, std::shared_ptr< OCResource > > groupSyncResourceList;
53 // remote group sync resource list
55 std::vector< OCResourceHandle > deviceResourceHandleList; // these cannot be removed.
56 OCResourceHandle deviceResourceHandle;
58 OCResourceHandle collectionResourceHandle; // collection handle
59 std::shared_ptr< OCResource > remoteCollectionResource;
61 FindCallback findCallback;
63 std::vector< std::shared_ptr< OCResource > > foundGroupResourceList;
65 std::mutex foundGroupMutex;
66 // std::mutex groupSyncMutex;
68 std::shared_ptr< OCResourceRequest > resourceRequest; // this is used for slow response
70 static GroupSynchronization* groupSyncnstance;
71 static bool bIsFinding;
73 GroupSynchronization()
75 collectionResourceHandleList.clear();
76 childResourceHandleList.clear();
77 groupSyncResourceHandleList.clear();
78 groupSyncResourceList.clear();
79 deviceResourceHandleList.clear();
81 deviceResourceHandle = NULL;
82 collectionResourceHandle = NULL;
83 remoteCollectionResource = NULL;
88 ~GroupSynchronization()
90 std::map< std::string, OCResourceHandle >::iterator handleIt;
91 for (handleIt = collectionResourceHandleList.begin();
92 handleIt != collectionResourceHandleList.end(); ++handleIt)
94 deleteGroup(handleIt->first);
101 static GroupSynchronization* getInstance();
102 void deleteInstance();
104 OCStackResult findGroup(std::vector< std::string > collectionResourceTypes,
105 FindCallback callback);
106 OCStackResult createGroup(std::string collectionResourceType);
107 OCStackResult joinGroup(std::string collectionResourceTyps,
108 OCResourceHandle resourceHandle);
109 OCStackResult joinGroup(const std::shared_ptr< OCResource > resource,
110 OCResourceHandle resourceHandle);
111 OCStackResult leaveGroup(std::string collectionResourceType,
112 OCResourceHandle resourceHandle);
113 void deleteGroup(std::string collectionResourceType);
115 std::map< std::string, OCResourceHandle > getGroupList();
119 OCEntityHandlerResult groupEntityHandler(
120 const std::shared_ptr< OCResourceRequest > request);
122 void onFindGroup(std::shared_ptr< OCResource > resource);
123 void onJoinGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep,
125 void onFindResource(std::shared_ptr< OCResource > resource);
126 void onGetJoinedRemoteChild(const HeaderOptions& headerOptions, const OCRepresentation& rep,
128 void onLeaveGroup(const HeaderOptions& headerOptions, const OCRepresentation& rep,
130 // void onSubscribePresence (OCStackResult result,
131 // const unsigned int nonce/*, std::string resourceType, std::string host*/);
133 void checkFindGroup(void);
134 bool IsSameGroup(std::shared_ptr< OCResource > resource);
135 void saveGroup(std::shared_ptr< OCResource > resource);
137 void debugGroupSync(void);
141 #endif // __OC_GROUPSYNCHRONIZATION__