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"
41 * @class BundleResource
42 * @brief This class represents Basic bundle resource template
43 * to be registered in the container and make resource server
49 typedef std::shared_ptr< BundleResource > Ptr;
52 * Constructor for BundleResource
57 * Virtual destructor for BundleResource
59 virtual ~BundleResource();
62 * Return the list of attribute names of the resource
64 * @return List of the attribute names
66 std::list<std::string> getAttributeNames();
69 * Initialize attributes of the resource
73 virtual void initAttributes() = 0;
76 * Register notification receiver(resource container) to notify for the
77 * changes of attributes
79 * @param pNotiReceiver Notification Receiver to get notification from
84 void registerObserver(NotificationReceiver* pNotiReceiver);
87 * Return all attributes of the resource
89 * @return Attributes of the resource
91 const RCSResourceAttributes getAttributes();
94 * Set attributes of the resource
96 * @param attrs Attributes to set
100 void setAttributes(const RCSResourceAttributes &attrs);
102 void setAttributes(const RCSResourceAttributes &attrs, bool notify);
105 * Return the value of an attribute
107 * @param key Key of attribute to get
109 * @return Value of the attribute
111 RCSResourceAttributes::Value getAttribute(const std::string &key);
114 * Sets the value of an attribute
116 * @param key Name of attribute to set
118 * @param value Value of attribute to set
120 * @param notify Flag to indicate if OIC clients should be notified about an update
124 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value,
128 * Sets the value of an attribute
130 * @param key Name of attribute to set
132 * @param value Value of attribute to set
134 * @param notify Flag to indicate if OIC clients should be notified about an update
138 void setAttribute(const std::string &key, RCSResourceAttributes::Value &value,
142 * Sets the value of an attribute
144 * @param key Name of attribute to set
146 * @param value Value of attribute to set
150 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value);
153 * Sets the value of an attribute
155 * @param key Name of attribute to set
157 * @param value Value of attribute to set
161 void setAttribute(const std::string &key, RCSResourceAttributes::Value &value);
164 * This function should be implemented by the according bundle resource
165 * and execute the according business logic (e.g., light switch or sensor resource)
166 * to retrieve a sensor value. If a new sensor value is retrieved, the
167 * setAttribute data should be called to update the value.
168 * The implementor of the function can decide weather to notify OIC clients
169 * about the changed state or not.
171 * @return All attributes
173 virtual RCSResourceAttributes handleGetAttributesRequest() = 0;
176 * This function should be implemented by the according bundle resource
177 * and execute the according business logic (e.g., light switch or sensor resource)
178 * and write either on soft sensor values or external bridged devices.
180 * The call of this method could for example trigger a HTTP PUT request on
181 * an external APIs. This method is responsible to update the resource internal
182 * data and call the setAttribute method.
184 * The implementor of the function can decide weather to notify OIC clients
185 * about the changed state or not.
187 * @param attrs Attributes to set
191 virtual void handleSetAttributesRequest(const RCSResourceAttributes &attrs) = 0;
194 void sendNotification(NotificationReceiver *notficiationRecevier, std::string uri);
197 std::string m_bundleId;
198 std::string m_name, m_uri, m_resourceType, m_interface, m_address;
199 std::map< std::string,
200 std::vector< std::map< std::string, std::string > > > m_mapResourceProperty;
203 NotificationReceiver* m_pNotiReceiver;
204 RCSResourceAttributes m_resourceAttributes;
205 std::mutex m_resourceAttributes_mutex;