1 //******************************************************************
3 // Copyright 2015 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 #ifndef BUNDLERESOURCE_H_
22 #define BUNDLERESOURCE_H_
32 #include "NotificationReceiver.h"
33 #include "RCSResourceAttributes.h"
34 #include "RCSRequest.h"
42 * @class BundleResource
43 * @brief This class represents Basic bundle resource template
44 * to be registered in the container and make resource server
50 typedef std::shared_ptr< BundleResource > Ptr;
53 * Constructor for BundleResource
58 * Virtual destructor for BundleResource
60 virtual ~BundleResource();
63 * Return the list of attribute names of the resource
65 * @return List of the attribute names
67 std::list<std::string> getAttributeNames();
70 * Initialize attributes of the resource
74 virtual void initAttributes() = 0;
77 * Register notification receiver(resource container) to notify for the
78 * changes of attributes
80 * @param pNotiReceiver Notification Receiver to get notification from
85 void registerObserver(NotificationReceiver* pNotiReceiver);
88 * Return all attributes of the resource
90 * @return Attributes of the resource
92 const RCSResourceAttributes getAttributes();
95 * Set attributes of the resource
97 * @param attrs Attributes to set
101 void setAttributes(const RCSResourceAttributes &attrs);
103 void setAttributes(const RCSResourceAttributes &attrs, bool notify);
106 * Return the value of an attribute
108 * @param key Key of attribute to get
110 * @return Value of the attribute
112 RCSResourceAttributes::Value getAttribute(const std::string &key);
115 * Sets the value of an attribute
117 * @param key Name of attribute to set
119 * @param value Value of attribute to set
121 * @param notify Flag to indicate if OIC clients should be notified about an update
125 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value,
129 * Sets the value of an attribute
131 * @param key Name of attribute to set
133 * @param value Value of attribute to set
135 * @param notify Flag to indicate if OIC clients should be notified about an update
139 void setAttribute(const std::string &key, RCSResourceAttributes::Value &value,
143 * Sets the value of an attribute
145 * @param key Name of attribute to set
147 * @param value Value of attribute to set
151 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value);
154 * Sets the value of an attribute
156 * @param key Name of attribute to set
158 * @param value Value of attribute to set
162 void setAttribute(const std::string &key, RCSResourceAttributes::Value &value);
165 * This function should be implemented by the according bundle resource
166 * and execute the according business logic (e.g., light switch or sensor resource)
167 * to retrieve a sensor value. If a new sensor value is retrieved, the
168 * setAttribute data should be called to update the value.
169 * The implementor of the function can decide weather to notify OIC clients
170 * about the changed state or not.
172 * @param queryParams Request parameters
174 * @return All attributes
176 virtual RCSResourceAttributes handleGetAttributesRequest(const
177 std::map< std::string, std::string > &queryParams) = 0;
180 * This function should be implemented by the according bundle resource
181 * and execute the according business logic (e.g., light switch or sensor resource)
182 * and write either on soft sensor values or external bridged devices.
184 * The call of this method could for example trigger a HTTP PUT request on
185 * an external APIs. This method is responsible to update the resource internal
186 * data and call the setAttribute method.
188 * The implementor of the function can decide weather to notify OIC clients
189 * about the changed state or not.
191 * @param attrs Attributes to set
192 * @param queryParams Request parameters
196 virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs,
197 const std::map< std::string, std::string > &queryParams) = 0;
200 void sendNotification(NotificationReceiver *notficiationRecevier, std::string uri);
203 std::string m_bundleId;
204 std::string m_name, m_uri, m_resourceType, m_interface, m_address;
205 std::map< std::string,
206 std::vector< std::map< std::string, std::string > > > m_mapResourceProperty;
209 NotificationReceiver* m_pNotiReceiver;
210 RCSResourceAttributes m_resourceAttributes;
211 std::mutex m_resourceAttributes_mutex;