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_resource.h
24 * @brief This file provides a abstract class SimulatorResource, for representing simulated resource.
27 #ifndef SIMULATOR_RESOURCE_H_
28 #define SIMULATOR_RESOURCE_H_
30 #include "simulator_uncopyable.h"
31 #include "simulator_resource_model.h"
32 #include "simulator_exceptions.h"
34 enum class ObservationStatus
48 * @class SimulatorResource
49 * @brief Abstract class represents simulated resource.
51 class SimulatorResource : private UnCopyable
61 * Callback method for receiving notifications when resource representation model changes.
63 * @param uri - URI of resource whose representation model got changed.
64 * @param resModel - Resource model.
66 typedef std::function<void (const std::string &uri, const SimulatorResourceModel &resModel)>
67 ResourceModelUpdateCallback;
70 * Callback method for receiving notifications when observer is registered/unregistered
73 * @param uri - Resource URI
74 * @param state - OBSERVE_REGISTER if observer is registered, otherwise OBSERVE_UNREGISTER.
75 * @param observerInfo - Information about observer.
77 typedef std::function<void (const std::string &uri, ObservationStatus state,
78 const ObserverInfo &observerInfo)> ObserverCallback;
81 * API to get the type which indicates whether resource is single or collection resource.
83 * @return Type of resource.
85 virtual bool isCollection() const;
88 * API to get the type which indicates whether resource is single or collection resource.
90 * @return Type of resource.
92 virtual SimulatorResource::Type getType() const;
95 * API to get the name of the resource.
97 * @return Resource name.
99 virtual std::string getName() const;
102 * API to get the resource URI.
104 * @return Resource URI.
106 virtual std::string getURI() const;
109 * API to get the resource type.
111 * @return Resource type.
113 virtual std::string getResourceType() const;
116 * API to get the interfaces resource is bound with.
118 * @return Interface type.
120 virtual std::vector<std::string> getInterface() const;
123 * API to get the observable state of resource.
125 * @return bool - true if resource is observable, otherwise false.
127 virtual bool isObservable() const = 0;
130 * API to get the discoverable state of resource.
132 * @return bool - true if resource is discoverable, otherwise false.
134 virtual bool isDiscoverable() const = 0;
137 * API to get the start state of resource.
139 * @return bool - true if resource is started, otherwise false.
141 virtual bool isStarted() const = 0;
144 * API to set the name of the resource.
146 * @param name - Name to be set.
148 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
150 virtual void setName(const std::string &name) = 0;
153 * API to set the resource URI.
155 * @param uri - URI to be set.
157 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
159 virtual void setURI(const std::string &uri) = 0;
162 * API to set the resource type.
164 * @param resourceType - resource type string.
166 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
168 virtual void setResourceType(const std::string &resourceType) = 0;
171 * API to set interface to resource.
173 * @param interfaceType - interface to be set.
175 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
177 virtual void setInterface(const std::string &interfaceType) = 0;
180 * API to set list of interfaces to resource.
182 * @param interfaceTypes - interfaces to be set.
184 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
186 virtual void setInterface(const std::vector<std::string> &interfaceTypes) = 0;
189 * API to add interface type for resource.
191 * @param interfaceType - interface to be added for resource.
193 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
195 virtual void addInterface(const std::string &interfaceType) = 0;
198 * API to make the resource observable or non-observable.
200 * @param state - true for resource to be observable, otherwise false.
202 * NOTE: API throws @SimulatorException exceptions.
204 virtual void setObservable(bool state) = 0;
207 * API to make the resource discoverable or non-discoverable.
209 * @param state - true for resource to be discoverable, otherwise false.
211 * NOTE: API throws @SimulatorException exceptions.
213 virtual void setDiscoverable(bool state) = 0;
216 * API to set the callback for receiving the notifications when
217 * observer is registered or unregistered with resource.
219 * @param callback - Callback to be set for receiving the notifications.
221 virtual void setObserverCallback(ObserverCallback callback) = 0;
224 * API to set the callback for receiving the notifications when the
225 * resource's representation model changes.
227 * @param callback - Callback to be set for receiving the notifications.
229 virtual void setModelChangeCallback(ResourceModelUpdateCallback callback) = 0;
232 * API to start the resource.
234 * NOTE: API throws @SimulatorException exception.
236 virtual void start() = 0;
239 * API to stop the resource.
241 * NOTE: API throws @SimulatorException exception.
243 virtual void stop() = 0;
246 * API to get SimulatorResourceModel of resource.
248 * @return Resource model of the resource.
250 virtual SimulatorResourceModel getResourceModel() = 0;
253 * API to get observers which are registered with resource.
255 * @return vector of ObserverInfo.
257 virtual std::vector<ObserverInfo> getObservers() const = 0;
260 * API to notify resource's representation to specific observer.
262 * @param observerID - ID of observer.
264 * NOTE: API throws @SimulatorException exception.
266 virtual void notify(int observerID) = 0;
269 * API to notify resource's representation to all registered observers.
271 * NOTE: API throws @SimulatorException exception.
273 virtual void notifyAll() = 0;
276 SimulatorResource::Type m_type;
279 std::string m_resourceType;
280 std::vector<std::string> m_interfaces;
283 typedef std::shared_ptr<SimulatorResource> SimulatorResourceSP;