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