Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / inc / simulator_manager.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 /**
22   * @file   simulator_manager.h
23   *
24   * @brief   This file contains the declaration of SimulatorManager class which has the methods
25   *              for configuring the platform and creation/deletion of resources.
26   */
27
28 #ifndef SIMULATOR_MANAGER_H_
29 #define SIMULATOR_MANAGER_H_
30
31 #include "simulator_client_types.h"
32 #include "simulator_device_info.h"
33 #include "simulator_platform_info.h"
34 #include "simulator_single_resource.h"
35 #include "simulator_collection_resource.h"
36 #include "simulator_remote_resource.h"
37 #include "simulator_exceptions.h"
38 #include "simulator_logger.h"
39
40 typedef std::function<void(const std::string &hostUri, DeviceInfo &deviceInfo)> DeviceInfoCallback;
41 typedef std::function<void(const std::string &hostUri, PlatformInfo &platformInfo)>
42 PlatformInfoCallback;
43
44 /**
45  * @class   SimulatorManager
46  *
47  * @brief   This class provides a set of methods for platform configuration,
48  *              and creation/deletion of resources.
49  *
50  */
51 class SimulatorManager
52 {
53     public:
54         static SimulatorManager *getInstance();
55
56         /**
57          * This method is for simulating/creating a resource based on the input data provided from
58          * RAML file.
59          *
60          * @param configPath - RAML configuration file path.
61          *
62          * @return SimulatorResource shared object representing simulated/created resource.
63          *
64          *  NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
65           * @SimulatorException if any other error occured.
66          */
67         std::shared_ptr<SimulatorResource> createResource(const std::string &configPath);
68
69         /**
70          * This method is for creating multiple resources of same type based on the input data
71          * provided from RAML file.
72          *
73          * @param configPath - RAML configuration file path.
74          * @param count - Number of resource to be created.
75          * @param callback - Callback method for receiving notifications when resource model changes.
76          *
77          * @return vector of SimulatorResource shared objects representing simulated/created
78          * resources.
79          *
80          * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
81          * @SimulatorException if any other error occured.
82          */
83         std::vector<std::shared_ptr<SimulatorResource>> createResource(
84                     const std::string &configPath, unsigned int count);
85
86         /**
87          * This method is for creating single type resource.
88          *
89          * @param name - Name of resource to be set if resource created successfully.
90          * @param uri - URI on which resource to be created.
91          * @param resourceType - Resource type of resource to be set if resource
92          * created successfully.
93          *
94          * @return shared object of @SimulatorSingleResource.
95          *
96          * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
97          * @SimulatorException if any other error occured.
98          */
99         std::shared_ptr<SimulatorSingleResource> createSingleResource(
100             const std::string &name, const std::string &uri, const std::string &resourceType);
101
102         /**
103          * This method is for creating collection type resource.
104          *
105          * @param name - Name of resource to be set if resource created successfully.
106          * @param uri - URI on which resource to be created.
107          * @param resourceType - Resource type of resource to be set if resource
108          * created successfully.
109          *
110          * @return shared object of @SimulatorCollectionResource.
111          *
112          * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
113          * @SimulatorException if any other error occured.
114          */
115         std::shared_ptr<SimulatorCollectionResource> createCollectionResource(
116             const std::string &name, const std::string &uri, const std::string &resourceType);
117
118         /**
119          * API for discovering all type of resources.
120          * Discovered resources will be notified through the callback set using @callback parameter.
121          *
122          * @param callback - Method of type @ResourceFindCallback through which discoverd resources
123          *                                   will be notified.
124          *
125          * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
126          * @SimulatorException if any other error occured.
127          */
128         void findResource(ResourceFindCallback callback);
129
130         /**
131          * API for discovering resources of a particular resource type.
132          * Discovered resources will be notified through the callback set using @callback parameter.
133          *
134          * @param resourceType - Type of resource to be searched for
135          * @param callback - Method of type @ResourceFindCallback through which discoverd resources
136          *                                   will be notified.
137          *
138          * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
139          * @SimulatorException if any other error occured.
140          */
141         void findResource(const std::string &resourceType, ResourceFindCallback callback);
142
143         /**
144          * API for getting device information from remote device.
145          * Received device information will be notified through the callback set using
146          * @callback parameter.
147          *
148          * @param callback - Method of type @DeviceInfoCallback through which device information
149          *                                   will be notified.
150          *
151          * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
152          */
153         void getDeviceInfo(const std::string &host, DeviceInfoCallback callback);
154
155         /**
156          * API for registering device information with stack.
157          *
158          * @param deviceName - Device name to be registered.
159          *
160          * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
161          */
162         void setDeviceInfo(const std::string &deviceName);
163
164         /**
165          * API for getting platform information from remote device.
166          * Received platform information will be notified through the callback set using
167          * @callback parameter.
168          *
169          * @param callback - Method of type @PlatformInfoCallback through which platform
170          *                                   information will be notified.
171          *
172          * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
173          */
174         void getPlatformInfo(const std::string &host, PlatformInfoCallback callback);
175
176         /**
177          * API for registering platform information with stack.
178          *
179          * @param platformInfo - PlatformInfo contains all platform related information.
180          *
181          * NOTE: API throws @SimulatorException on error.
182          */
183         void setPlatformInfo(PlatformInfo &platformInfo);
184
185         /**
186          * API for setting logger target for receiving the log messages.
187          *
188          * @param logger - ILogger interface for handling the log messages.
189          *
190          */
191         void setLogger(const std::shared_ptr<ILogger> &logger);
192
193         /**
194          * API for setting console as logger target.
195          *
196          * @return true if console set as logger target,
197          *         otherwise false.
198          *
199          */
200         bool setConsoleLogger();
201
202         /**
203          * API for setting file as logger target.
204          *
205          * @param path - File to which log messages to be saved.
206          *
207          * @return true if console set as logger target,
208          *         otherwise false.
209          *
210          */
211         bool setFileLogger(const std::string &path);
212
213     private:
214         SimulatorManager();
215         ~SimulatorManager() = default;
216         SimulatorManager(const SimulatorManager &) = delete;
217         SimulatorManager &operator=(const SimulatorManager &) = delete;
218         SimulatorManager(const SimulatorManager &&) = delete;
219         SimulatorManager &operator=(const SimulatorManager && ) = delete;
220 };
221
222 #endif