5315edda6c4cf68cf49b32dc174ea4829edab4f9
[platform/upstream/iotivity.git] / service / resource-container / bundle-api / include / BundleResource.h
1 //******************************************************************
2 //
3 // Copyright 2015 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 #ifndef BUNDLERESOURCE_H_
22 #define BUNDLERESOURCE_H_
23
24 #include <list>
25 #include <string>
26 #include <map>
27 #include <vector>
28 #include <memory>
29
30 #include "NotificationReceiver.h"
31 #include "RCSResourceAttributes.h"
32
33 namespace OIC
34 {
35     namespace Service
36     {
37
38         /**
39         * @class    BundleResource
40         * @brief    This class represents Basic bundle resource template
41         *               to be registered in the container and make resource server
42         *
43         */
44         class BundleResource
45         {
46             public:
47                 typedef std::shared_ptr< BundleResource > Ptr;
48
49                 /**
50                 * Constructor for BundleResource
51                 */
52                 BundleResource();
53
54                 /**
55                 * Virtual destructor for BundleResource
56                 */
57                 virtual ~BundleResource();
58
59                 /**
60                 * Return the list of attribute names of the resource
61                 *
62                 * @return List of the attribute names
63                 */
64                 std::list<std::string> getAttributeNames();
65
66                 /**
67                 * Initialize attributes of the resource
68                 *
69                 * @return void
70                 */
71                 virtual void initAttributes() = 0;
72
73                 /**
74                 * Register notification receiver(resource container) to notify for the
75                 *     changes of attributes
76                 *
77                 * @param pNotiReceiver Notification Receiver to get notification from
78                 * bundle resource
79                 *
80                 * @return void
81                 */
82                 void registerObserver(NotificationReceiver *pNotiReceiver);
83
84                 /**
85                 * Return all attributes of the resource
86                 *
87                 * @return Attributes of the resource
88                 */
89                 RCSResourceAttributes &getAttributes();
90
91                 /**
92                 * Set attributes of the resource
93                 *
94                 * @param attrs Attributes to set
95                 *
96                 * @return void
97                 */
98                 void setAttributes(RCSResourceAttributes &attrs);
99
100                 /**
101                 * Return the value of an attribute
102                 *
103                 * @param key Key of attribute to get
104                 *
105                 * @return Value of the attribute
106                 */
107                 RCSResourceAttributes::Value getAttribute(const std::string &key);
108
109                 /**
110                 * Sets the value of an attribute
111                 *
112                 * @param key Name of attribute to set
113                 *
114                 * @param value Value of attribute to set
115                 *
116                 * @param notify Flag to indicate if OIC clients should be notified about an update
117                 *
118                 * @return void
119                 */
120                 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value,
121                                   bool notify);
122
123                 /**
124                 * Sets the value of an attribute
125                 *
126                 * @param key Name of attribute to set
127                 *
128                 * @param value Value of attribute to set
129                 *
130                 * @return void
131                 */
132                 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value);
133
134                 /**
135                 * This function should be implemented by the according bundle resource
136                 * and execute the according business logic (e.g., light switch or sensor resource)
137                 * to retrieve a sensor value. If a new sensor value is retrieved, the
138                 * setAttribute data should be called to update the value.
139                 * The implementor of the function can decide weather to notify OIC clients
140                 * about the changed state or not.
141                 *
142                 * @return All attributes
143                 */
144                 virtual RCSResourceAttributes &handleGetAttributesRequest() = 0;
145
146                 /**
147                 * This function should be implemented by the according bundle resource
148                 * and execute the according business logic (e.g., light switch or sensor resource)
149                 * and write either on soft sensor values or external bridged devices.
150                 *
151                 * The call of this method could for example trigger a HTTP PUT request on
152                 * an external APIs. This method is responsible to update the resource internal
153                 * data and call the setAttribute method.
154                 *
155                 * The implementor of the function can decide weather to notify OIC clients
156                 * about the changed state or not.
157                 *
158                 * @param attrs Attributes to set
159                 *
160                 * @return void
161                 */
162                 virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs) = 0;
163
164
165             public:
166                 std::string m_bundleId;
167                 std::string m_name, m_uri, m_resourceType, m_address;
168                 std::map< std::string,
169                     std::vector< std::map< std::string, std::string > > > m_mapResourceProperty;
170
171             private:
172                 NotificationReceiver *m_pNotiReceiver;
173                 RCSResourceAttributes m_resourceAttributes;
174         };
175     }
176 }
177
178 #endif