Collection resource support in plugin UI.
[platform/upstream/iotivity.git] / service / simulator / inc / simulator_resource.h
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 #ifndef SIMULATOR_RESOURCE_H_
22 #define SIMULATOR_RESOURCE_H_
23
24 #include "simulator_server_types.h"
25 #include "simulator_resource_model.h"
26 #include "simulator_uncopyable.h"
27 #include "simulator_exceptions.h"
28
29 class SimulatorResource : public UnCopyable
30 {
31     public:
32         enum class Type
33         {
34             SINGLE_RESOURCE,
35             COLLECTION_RESOURCE
36         };
37
38         /**
39          * Callback method for receiving notifications when resource representation model changes.
40          *
41          * @param uri - URI of resource whose representation model got changed.
42          * @param resModel - Resource model.
43          */
44         typedef std::function<void (const std::string &uri, SimulatorResourceModel &resModel)>
45         ResourceModelChangedCallback;
46
47         /**
48          * Callback method for receiving notifications when observer is registered/unregistered
49          * with resource.
50          *
51          * @param uri - Resource URI
52          * @param state - OBSERVE_REGISTER if observer is registered, otherwise OBSERVE_UNREGISTER.
53          * @param observerInfo - Information about observer.
54          */
55         typedef std::function<void (const std::string &uri, ObservationStatus state, const ObserverInfo &observerInfo)>
56         ObserverCallback;
57
58         /**
59          * API to get the name of the resource.
60          *
61          * @return Resource name.
62          */
63         virtual std::string getName() const = 0;
64
65         /**
66          * API to get the type which indicates whether resource is single or collection resource.
67          *
68          * @return Type of resource.
69          */
70         virtual SimulatorResource::Type getType() const = 0;
71
72         /**
73          * API to get the resource URI.
74          *
75          * @return Resource URI.
76          */
77         virtual std::string getURI() const = 0;
78
79         /**
80          * API to get the resource type.
81          *
82          * @return Resource type.
83          */
84         virtual std::string getResourceType() const = 0;
85
86         /**
87          * API to get the interfaces resource is bound with.
88          *
89          * @return Interface type.
90          */
91         virtual std::vector<std::string> getInterface() const = 0;
92
93         /**
94          * API to get the observable state of resource.
95          *
96          * @return bool - true if resource is observable, otherwise false.
97          */
98         virtual bool isObservable() = 0;
99
100         /**
101          * API to get the start state of resource.
102          *
103          * @return bool - true if resource is started, otherwise false.
104          */
105         virtual bool isStarted() = 0;
106
107         /**
108          * API to get SimulatorResourceModel of resource.
109          *
110          * @return Resource model of the resource.
111          */
112         virtual SimulatorResourceModel getResourceModel() = 0;
113
114         /**
115          * API to set the name of the resource.
116          *
117          * @param name - Name to be set.
118          *
119          * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
120          */
121         virtual void setName(const std::string &name) = 0;
122
123         /**
124          * API to set the resource URI.
125          *
126          * @param uri - URI to be set.
127          *
128          * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
129          */
130         virtual void setURI(const std::string &uri) = 0;
131
132         /**
133          * API to set the resource type.
134          *
135          * @param resourceType - resource type string.
136          *
137          * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
138          */
139         virtual void setResourceType(const std::string &resourceType) = 0;
140
141         /**
142          * API to add interface type for resource.
143          *
144          * @param interfaceType - interface to be added for resource.
145          *
146          * NOTE: API throws @InvalidArgsException, @SimulatorException exceptions.
147          */
148         virtual void addInterface(std::string interfaceType) = 0;
149
150         /**
151          * API to make the resource observable or not.
152          *
153          * @param state - true make the resource observable, otherwise non-observable.
154          *
155          * NOTE: API throws @SimulatorException exceptions.
156          */
157         virtual void setObservable(bool state) = 0;
158
159         /**
160          * API to set the callback for receiving the notifications when
161          * observer is registered or unregistered with resource.
162          *
163          * @param callback - Callback to be set for receiving the notifications.
164          */
165         virtual void setObserverCallback(ObserverCallback callback) = 0;
166
167         /**
168          * API to set the callback for receiving the notifications when the
169          * resource model changes.
170          *
171          * @param callback - Callback to be set for receiving the notifications.
172          */
173         virtual void setModelChangeCallback(ResourceModelChangedCallback callback) = 0;
174
175         /**
176          * API to start the resource.
177          *
178          * NOTE: API throws @SimulatorException exception.
179          */
180         virtual void start() = 0;
181
182         /**
183          * API to stop the resource.
184          *
185          * NOTE: API throws @SimulatorException exception.
186          */
187         virtual void stop() = 0;
188
189         /**
190          * API to get observers which are registered with resource.
191          *
192          * @return vector of ObserverInfo.
193          */
194         virtual std::vector<ObserverInfo> getObserversList() = 0;
195
196         /**
197          * API to notify current resource model to specific observer.
198          *
199          * @param id - Observer ID to notify.
200          *
201          * NOTE: API throws @SimulatorException exception.
202          */
203         virtual void notify(int id) = 0;
204
205         /**
206          * API to notify all registered observers.
207          *
208          * NOTE: API throws @SimulatorException exception.
209          */
210         virtual void notifyAll() = 0;
211 };
212
213 typedef std::shared_ptr<SimulatorResource> SimulatorResourceSP;
214
215 #endif