Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / things-manager / sdk / src / GroupManager.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 /**
22  * @file
23  *
24  * This file contains the declaration of classes and its members related to
25  * GroupManager.
26  */
27
28 #ifndef __OC_GROUPMANAGER__
29 #define __OC_GROUPMANAGER__
30
31 #include <string>
32 #include <vector>
33 #include <map>
34 #include <cstdlib>
35 #include <ActionSet.h>
36 #include "OCPlatform.h"
37 #include "OCApi.h"
38
39 using namespace OC;
40
41 namespace OIC
42 {
43 typedef std::function< void(std::vector< std::shared_ptr< OCResource > >) > CandidateCallback;
44 typedef std::function< void(std::string, OCStackResult) > CollectionPresenceCallback;
45
46 typedef std::function< void(const HeaderOptions&, const OCRepresentation&, const int) > GetCallback;
47 typedef std::function< void(const HeaderOptions&, const OCRepresentation&, const int) > PostCallback;
48 typedef std::function< void(const HeaderOptions&, const OCRepresentation&, const int) > PutCallback;
49
50 class GroupManager
51 {
52 public:
53     /**
54      * Constructor for GroupManager. Constructs a new GroupManager
55      */
56     GroupManager(void);
57
58     /**
59      * Virtual destructor
60      */
61     ~GroupManager(void);
62
63     /**
64      * API for candidate resources discovery.
65      * Callback only call when all resource types found.
66      *
67      * @param resourceTypes - required resource types(called "candidate")
68      * @param candidateCallback - callback. OCResource vector.
69      *
70      * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
71      *
72      * NOTE: OCStackResult is defined in ocstack.h.
73      */
74     OCStackResult findCandidateResources(std::vector< std::string > resourceTypes,
75             CandidateCallback callback, int waitsec = -1);
76
77     /**
78      * API for Collection member's state subscribe.
79      *
80      * NOTE: NOT IMPLEMENT YET
81      */
82     OCStackResult subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
83             CollectionPresenceCallback);
84
85     OCStackResult bindResourceToGroup(OCResourceHandle& childHandle,
86             std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle);
87
88 private:
89
90     void onFoundResource(std::shared_ptr< OCResource > resource, int waitsec);
91     void findPreparedRequest(std::map< std::vector< std::string >, CandidateCallback > &request);
92     void lazyCallback(int second);
93
94     void onGetForPresence(const HeaderOptions& headerOptions, const OCRepresentation& rep,
95             const int eCode, CollectionPresenceCallback callback);
96     void checkCollectionRepresentation(const OCRepresentation& rep,
97             CollectionPresenceCallback callback);
98     void collectionPresenceHandler(OCStackResult result, const unsigned int nonce,
99             const std::string& hostAddress, std::string host, std::string uri);
100
101     /**
102      *   API for Collection(Group) action.
103      */
104
105 public:
106     std::string getStringFromActionSet(const ActionSet *newActionSet);
107     ActionSet* getActionSetfromString(std::string desc);
108
109     OCStackResult addActionSet(std::shared_ptr< OCResource > resource,
110             const ActionSet* newActionSet, PutCallback cb);
111     OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
112             std::string actionsetName, PostCallback cb);
113     OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
114             std::string actionsetName, long int delay, PostCallback cb);
115     OCStackResult cancelActionSet(std::shared_ptr< OCResource > resource,
116             std::string actionsetName, PostCallback cb);
117     OCStackResult getActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
118             PostCallback cb);
119     OCStackResult deleteActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
120             PostCallback);
121 };
122 }
123 #endif  /* __OC_GROUPMANAGER__*/