1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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 ******************************************************************/
22 * @file simulator_single_resource.h
24 * @brief This file provides a class and API to access simulated resource and to perfrom auto
25 * update operations on simulated resource.
28 #ifndef SIMULATOR_SINGLE_RESOURCE_H_
29 #define SIMULATOR_SINGLE_RESOURCE_H_
31 #include "simulator_resource.h"
33 enum class AutoUpdateType
40 * @class SimulatorSingleResource
41 * @brief This class provides a set of APIs for handling simulated resource.
43 class SimulatorSingleResource : public SimulatorResource
48 * Callback method for receiving notifications when resource/attribute value updation
51 * @param uri - URI of resource.
52 * @param id - Update automation identifier.
54 typedef std::function<void (const std::string &uri, const int id)>
55 AutoUpdateCompleteCallback;
58 * API to get attribute from resource's resource model.
60 * @param attrName - Attribute's name.
61 * @param attribute - A attribute of resource's resource model.
63 * @return bool - true on success, otherwise false.
65 virtual bool getAttribute(const std::string &attrName,
66 SimulatorResourceAttribute &attribute) = 0;
69 * API to get attribute from resource's resource model.
71 * @param attrName - Attribute's name.
72 * @param attribute - A attribute of resource's resource model.
74 * @return bool - true on success, otherwise false.
76 virtual std::map<std::string, SimulatorResourceAttribute> getAttributes() = 0;
79 * API to add a new attribute to the resource model.
81 * @param attribute - Attribute to be add to model.
82 * @param notify - If value is true then notification will be send to observers on success.
83 * This flag is set to true by default.
85 * NOTE: API throws @SimulatorException exceptions on failure.
87 virtual bool addAttribute(const SimulatorResourceAttribute &attribute,
88 bool notify = true) = 0;
91 * API to remove an attribute from the resource model.
93 * @param attrName - Name of the attribute to be removed.
94 * @param notify - If value is true then notification will be send to observers on success.
95 * This flag is set to true by default.
97 * @return bool - true on success, otherwise false.
99 virtual bool removeAttribute(const std::string &attrName, bool notify = true) = 0;
102 * API to update the value of an attribute.
104 * @param attrName - Name of the attribute.
105 * @param value - Value of the attribute.
106 * @param notify - If value is true then notification will be send to observers on success.
107 * This flag is set to true by default.
109 template <typename T>
110 bool updateAttributeValue(const std::string &attrName, const T &value, bool notify = true)
112 SimulatorResourceAttribute attribute(attrName);
113 attribute.setValue(value);
114 return updateAttributeValue(attribute, notify);
118 * API to update the value of an attribute.
120 * @param attribute - A resource model attribute.
121 * @param notify - If value is true then notification will be send to observers on success.
122 * This flag is set to true by default.
124 * @return bool - true on success, otherwise false.
126 virtual bool updateAttributeValue(const SimulatorResourceAttribute &attribute,
127 bool notify = true) = 0;
130 * API to start the attribute value update automation for all attributes.
131 * Values for the attributes will be selected from their allowed range
132 * and the updated resource model will be notified to all the observers of the resource.
134 * @param type - Automation type.
135 * @param updateInterval - Time in milliseconds to be set as interval between updating
137 * @param callback - Callback to get notifiy when update automation is finished.
139 * @return ID representing update automation session.
140 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
142 virtual int startResourceUpdation(AutoUpdateType type, int updateInterval,
143 AutoUpdateCompleteCallback callback) = 0;
146 * This method is used to start the attribute value update automation for
147 * specific attribute. Values for the attribute will be selected from its allowed range
148 * and the updated resource model will be notified to all the observers of the resource.
150 * @param attrName - Name of the attribute to be automated.
151 * @param type - Automation type.
152 * @param updateInterval - Time in milliseconds to be set as interval between updating
154 * @param callback - Callback to get notifiy when update automation is finished.
156 * @return ID representing update automation session.
157 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
159 virtual int startAttributeUpdation(const std::string &attrName, AutoUpdateType type,
160 int updateInterval, AutoUpdateCompleteCallback callback) = 0;
163 * API to get the Ids of all ongoing resource update automation .
165 * @return vector of resource automation ids.
167 virtual std::vector<int> getResourceUpdations() = 0;
170 * API to get the Ids of all ongoing attribute update automation .
172 * @return vector of attribute automation ids.
174 virtual std::vector<int> getAttributeUpdations() = 0;
177 * API to stop the resource/attribute automation.
179 * @param id - Identifier for automation.
181 virtual void stopUpdation(int id) = 0;
184 typedef std::shared_ptr<SimulatorSingleResource> SimulatorSingleResourceSP;