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_
30 #include "NotificationReceiver.h"
31 #include "RCSResourceAttributes.h"
39 * @class BundleResource
40 * @brief This class represents Basic bundle resource template
41 * to be registered in the container and make resource server
47 typedef std::shared_ptr< BundleResource > Ptr;
50 * Constructor for BundleResource
55 * Virtual destructor for BundleResource
57 virtual ~BundleResource();
60 * Return the list of attribute names of the resource
62 * @return List of the attribute names
64 std::list<std::string> getAttributeNames();
67 * Initialize attributes of the resource
71 virtual void initAttributes() = 0;
74 * Register notification receiver(resource container) to notify for the
75 * changes of attributes
77 * @param pNotiReceiver Notification Receiver to get notification from
82 void registerObserver(NotificationReceiver *pNotiReceiver);
85 * Return all attributes of the resource
87 * @return Attributes of the resource
89 RCSResourceAttributes &getAttributes();
92 * Set attributes of the resource
94 * @param attrs Attributes to set
98 void setAttributes(RCSResourceAttributes &attrs);
101 * Return the value of an attribute
103 * @param key Key of attribute to get
105 * @return Value of the attribute
107 RCSResourceAttributes::Value getAttribute(const std::string &key);
110 * Sets the value of an attribute
112 * @param key Name of attribute to set
114 * @param value Value of attribute to set
116 * @param notify Flag to indicate if OIC clients should be notified about an update
120 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value,
124 * Sets the value of an attribute
126 * @param key Name of attribute to set
128 * @param value Value of attribute to set
132 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value);
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.
142 * @param key Name of attribute to get
145 * @return All attributes
147 virtual RCSResourceAttributes &handleGetAttributesRequest() = 0;
150 * This function should be implemented by the according bundle resource
151 * and execute the according business logic (e.g., light switch or sensor resource)
152 * and write either on soft sensor values or external bridged devices.
154 * The call of this method could for example trigger a HTTP PUT request on
155 * an external APIs. This method is responsible to update the resource internal
156 * data and call the setAttribute method.
158 * The implementor of the function can decide weather to notify OIC clients
159 * about the changed state or not.
161 * @param key Name of attribute to set
163 * @param attrs Attributes to set
167 virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs) = 0;
171 std::string m_bundleId;
172 std::string m_name, m_uri, m_resourceType, m_address;
173 std::map< std::string,
174 std::vector< std::map< std::string, std::string > > > m_mapResourceProperty;
177 NotificationReceiver *m_pNotiReceiver;
178 RCSResourceAttributes m_resourceAttributes;