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 GroupSynchronizatin.h
23 /// @brief This file contains the declaration of classes and its members related to GroupSynchronization.
25 #ifndef __OC_GROUPSYNCHRONIZATION__
26 #define __OC_GROUPSYNCHRONIZATION__
32 #include "OCPlatform.h"
37 class GroupSynchronization
41 std::map<std::string, OCResourceHandle> collectionResourceHandleList; // collection resource handle list
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
46 std::vector<OCResourceHandle> deviceResourceHandleList; // these cannot be removed.
47 OCResourceHandle deviceResourceHandle;
49 OCResourceHandle collectionResourceHandle; // collection handle
50 std::shared_ptr< OCResource> remoteCollectionResource;
52 std::map<OCResourceHandle, std::vector<OCResourceHandle>> childResourceHandleList;
54 FindCallback findCallback;
55 std::vector<std::shared_ptr< OCResource >> foundGroupResourceList;
57 std::mutex foundGroupMutex;
58 std::mutex groupSyncMutex;
60 std::shared_ptr<OCResourceRequest> resourceRequest; // this is used for slow response
62 static GroupSynchronization* groupSyncnstance;
65 GroupSynchronization ()
67 collectionResourceHandleList.clear();
68 groupSyncResourceHandleList.clear();
69 groupSyncResourceList.clear();
70 foundGroupResourceList.clear();
71 deviceResourceHandleList.clear();
73 deviceResourceHandle = NULL;
74 remoteCollectionResource = NULL;
78 ~GroupSynchronization ()
80 std::map<std::string, OCResourceHandle>::iterator handleIt;
81 for (handleIt = collectionResourceHandleList.begin(); handleIt != collectionResourceHandleList.end(); ++handleIt)
83 deleteGroup (handleIt->first);
90 static GroupSynchronization* getInstance ();
91 void deleteInstance();
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);
100 std::map<std::string, OCResourceHandle> getGroupList ();
104 OCEntityHandlerResult groupEntityHandler(const std::shared_ptr<OCResourceRequest> request);
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*/);
113 void checkFindGroup (void);
114 bool IsSameGroup (std::shared_ptr< OCResource > resource);
115 void saveGroup (std::shared_ptr< OCResource > resource);
117 void debugGroupSync (void);
121 #endif // __OC_GROUPSYNCHRONIZATION__