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 ******************************************************************/
21 #ifndef SIMULATOR_RESOURCE_H_
22 #define SIMULATOR_RESOURCE_H_
24 #include "simulator_server_types.h"
25 #include "simulator_resource_model.h"
26 #include "simulator_uncopyable.h"
27 #include "simulator_exceptions.h"
29 class SimulatorResource : public UnCopyable
39 * Callback method for receiving notifications when resource representation model changes.
41 * @param uri - URI of resource whose representation model got changed.
42 * @param resModel - Resource model.
44 typedef std::function<void (const std::string &uri, SimulatorResourceModel &resModel)>
45 ResourceModelChangedCallback;
48 * Callback method for receiving notifications when observer is registered/unregistered
51 * @param uri - Resource URI
52 * @param state - OBSERVE_REGISTER if observer is registered, otherwise OBSERVE_UNREGISTER.
53 * @param observerInfo - Information about observer.
55 typedef std::function<void (const std::string &uri, ObservationStatus state, const ObserverInfo &observerInfo)>
59 * API to get the name of the resource.
61 * @return Resource name.
63 virtual std::string getName() const = 0;
66 * API to get the type which indicates whether resource is single or collection resource.
68 * @return Type of resource.
70 virtual SimulatorResource::Type getType() const = 0;
73 * API to get the resource URI.
75 * @return Resource URI.
77 virtual std::string getURI() const = 0;
80 * API to get the resource type.
82 * @return Resource type.
84 virtual std::string getResourceType() const = 0;
87 * API to get the interfaces resource is bound with.
89 * @return Interface type.
91 virtual std::vector<std::string> getInterface() const = 0;
94 * API to get the observable state of resource.
96 * @return bool - true if resource is observable, otherwise false.
98 virtual bool isObservable() = 0;
101 * API to get the start state of resource.
103 * @return bool - true if resource is started, otherwise false.
105 virtual bool isStarted() = 0;
108 * API to get SimulatorResourceModel of resource.
110 * @return Resource model of the resource.
112 virtual SimulatorResourceModel getResourceModel() = 0;
115 * API to set the name of the resource.
117 * @param name - Name to be set.
119 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
121 virtual void setName(const std::string &name) = 0;
124 * API to set the resource URI.
126 * @param uri - URI to be set.
128 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
130 virtual void setURI(const std::string &uri) = 0;
133 * API to set the resource type.
135 * @param resourceType - resource type string.
137 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
139 virtual void setResourceType(const std::string &resourceType) = 0;
142 * API to add interface type for resource.
144 * @param interfaceType - interface to be added for resource.
146 * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
148 virtual void addInterface(std::string interfaceType) = 0;
151 * API to make the resource observable or not.
153 * @param state - true make the resource observable, otherwise non-observable.
155 * NOTE: API throws @SimulatorException exceptions.
157 virtual void setObservable(bool state) = 0;
160 * API to set the callback for receiving the notifications when
161 * observer is registered or unregistered with resource.
163 * @param callback - Callback to be set for receiving the notifications.
165 virtual void setObserverCallback(ObserverCallback callback) = 0;
168 * API to set the callback for receiving the notifications when the
169 * resource model changes.
171 * @param callback - Callback to be set for receiving the notifications.
173 virtual void setModelChangeCallback(ResourceModelChangedCallback callback) = 0;
176 * API to start the resource.
178 * NOTE: API throws @SimulatorException exception.
180 virtual void start() = 0;
183 * API to stop the resource.
185 * NOTE: API throws @SimulatorException exception.
187 virtual void stop() = 0;
190 * API to get observers which are registered with resource.
192 * @return vector of ObserverInfo.
194 virtual std::vector<ObserverInfo> getObserversList() = 0;
197 * API to notify current resource model to specific observer.
199 * @param id - Observer ID to notify.
201 * NOTE: API throws @SimulatorException exception.
203 virtual void notify(int id) = 0;
206 * API to notify all registered observers.
208 * NOTE: API throws @SimulatorException exception.
210 virtual void notifyAll() = 0;
213 typedef std::shared_ptr<SimulatorResource> SimulatorResourceSP;