Displaying and editing the complex value types for attributes.
[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_server_types.h"
32 #include "simulator_client_types.h"
33 #include "simulator_device_info.h"
34 #include "simulator_platform_info.h"
35 #include "simulator_single_resource.h"
36 #include "simulator_collection_resource.h"
37 #include "simulator_remote_resource.h"
38 #include "simulator_exceptions.h"
39 #include "simulator_logger.h"
40
41 typedef std::function<void(DeviceInfo &deviceInfo)> DeviceInfoCallback;
42 typedef std::function<void(PlatformInfo &platformInfo)> 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         std::shared_ptr<SimulatorSingleResource> createSingleResource(
87             const std::string &name, const std::string &uri, const std::string &resourceType);
88
89         std::shared_ptr<SimulatorCollectionResource> createCollectionResource(
90             const std::string &name, const std::string &uri, const std::string &resourceType);
91
92         /**
93          * API for discovering all type of resources.
94          * Discovered resources will be notified through the callback set using @callback parameter.
95          *
96          * @param callback - Method of type @ResourceFindCallback through which discoverd resources
97          *                                   will be notified.
98          *
99          * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
100          * @SimulatorException if any other error occured.
101          */
102         void findResource(ResourceFindCallback callback);
103
104         /**
105          * API for discovering resources of a particular resource type.
106          * Discovered resources will be notified through the callback set using @callback parameter.
107          *
108          * @param resourceType - Type of resource to be searched for
109          * @param callback - Method of type @ResourceFindCallback through which discoverd resources
110          *                                   will be notified.
111          *
112          * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
113          * @SimulatorException if any other error occured.
114          */
115         void findResource(const std::string &resourceType, ResourceFindCallback callback);
116
117         /**
118          * API for getting device information from remote device.
119          * Received device information will be notified through the callback set using
120          * @callback parameter.
121          *
122          * @param callback - Method of type @DeviceInfoCallback through which device information
123          *                                   will be notified.
124          *
125          * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
126          */
127         void getDeviceInfo(const std::string &host, DeviceInfoCallback callback);
128
129         /**
130          * API for registering device information with stack.
131          *
132          * @param deviceName - Device name to be registered.
133          *
134          * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
135          */
136         void setDeviceInfo(const std::string &deviceName);
137
138         /**
139          * API for getting platform information from remote device.
140          * Received platform information will be notified through the callback set using
141          * @callback parameter.
142          *
143          * @param callback - Method of type @PlatformInfoCallback through which platform
144          *                                   information will be notified.
145          *
146          * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
147          */
148         void getPlatformInfo(const std::string &host, PlatformInfoCallback callback);
149
150         /**
151          * API for registering platform information with stack.
152          *
153          * @param platformInfo - PlatformInfo contains all platform related information.
154          *
155          * NOTE: API throws @SimulatorException on error.
156          */
157         void setPlatformInfo(PlatformInfo &platformInfo);
158
159         /**
160          * API for setting logger target for receiving the log messages.
161          *
162          * @param logger - ILogger interface for handling the log messages.
163          *
164          */
165         void setLogger(const std::shared_ptr<ILogger> &logger);
166
167         /**
168          * API for setting console as logger target.
169          *
170          * @return true if console set as logger target,
171          *         otherwise false.
172          *
173          */
174         bool setConsoleLogger();
175
176         /**
177          * API for setting file as logger target.
178          *
179          * @param path - File to which log messages to be saved.
180          *
181          * @return true if console set as logger target,
182          *         otherwise false.
183          *
184          */
185         bool setFileLogger(const std::string &path);
186
187     private:
188         SimulatorManager();
189         ~SimulatorManager() = default;
190         SimulatorManager(const SimulatorManager &) = delete;
191         SimulatorManager &operator=(const SimulatorManager &) = delete;
192         SimulatorManager(const SimulatorManager &&) = delete;
193         SimulatorManager &operator=(const SimulatorManager && ) = delete;
194 };
195
196 #endif