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_manager.h
24 * @brief This file contains the declaration of SimulatorManager class which has the methods
25 * for configuring the platform and creation/deletion of resources.
28 #ifndef SIMULATOR_MANAGER_H_
29 #define SIMULATOR_MANAGER_H_
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"
40 typedef std::function<void(const std::string &hostUri, DeviceInfo &deviceInfo)> DeviceInfoCallback;
41 typedef std::function<void(const std::string &hostUri, PlatformInfo &platformInfo)>
45 * @class SimulatorManager
47 * @brief This class provides a set of methods for platform configuration,
48 * and creation/deletion of resources.
51 class SimulatorManager
54 static SimulatorManager *getInstance();
57 * This method is for simulating/creating a resource based on the input data provided from
60 * @param configPath - RAML configuration file path.
62 * @return SimulatorResource shared object representing simulated/created resource.
64 * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
65 * @SimulatorException if any other error occured.
67 std::shared_ptr<SimulatorResource> createResource(const std::string &configPath);
70 * This method is for creating multiple resources of same type based on the input data
71 * provided from RAML file.
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.
77 * @return vector of SimulatorResource shared objects representing simulated/created
80 * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
81 * @SimulatorException if any other error occured.
83 std::vector<std::shared_ptr<SimulatorResource>> createResource(
84 const std::string &configPath, unsigned int count);
87 * This method is for creating single type resource.
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.
94 * @return shared object of @SimulatorSingleResource.
96 * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
97 * @SimulatorException if any other error occured.
99 std::shared_ptr<SimulatorSingleResource> createSingleResource(
100 const std::string &name, const std::string &uri, const std::string &resourceType);
103 * This method is for creating collection type resource.
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.
110 * @return shared object of @SimulatorCollectionResource.
112 * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
113 * @SimulatorException if any other error occured.
115 std::shared_ptr<SimulatorCollectionResource> createCollectionResource(
116 const std::string &name, const std::string &uri, const std::string &resourceType);
119 * API for discovering all type of resources.
120 * Discovered resources will be notified through the callback set using @callback parameter.
122 * @param callback - Method of type @ResourceFindCallback through which discoverd resources
125 * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
126 * @SimulatorException if any other error occured.
128 void findResource(ResourceFindCallback callback);
131 * API for discovering resources of a particular resource type.
132 * Discovered resources will be notified through the callback set using @callback parameter.
134 * @param resourceType - Type of resource to be searched for
135 * @param callback - Method of type @ResourceFindCallback through which discoverd resources
138 * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
139 * @SimulatorException if any other error occured.
141 void findResource(const std::string &resourceType, ResourceFindCallback callback);
144 * API for getting device information from remote device.
145 * Received device information will be notified through the callback set using
146 * @callback parameter.
148 * @param callback - Method of type @DeviceInfoCallback through which device information
151 * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
153 void getDeviceInfo(const std::string &host, DeviceInfoCallback callback);
156 * API for registering device information with stack.
158 * @param deviceName - Device name to be registered.
160 * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
162 void setDeviceInfo(const std::string &deviceName);
165 * API for getting platform information from remote device.
166 * Received platform information will be notified through the callback set using
167 * @callback parameter.
169 * @param callback - Method of type @PlatformInfoCallback through which platform
170 * information will be notified.
172 * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
174 void getPlatformInfo(const std::string &host, PlatformInfoCallback callback);
177 * API for registering platform information with stack.
179 * @param platformInfo - PlatformInfo contains all platform related information.
181 * NOTE: API throws @SimulatorException on error.
183 void setPlatformInfo(PlatformInfo &platformInfo);
186 * API for setting logger target for receiving the log messages.
188 * @param logger - ILogger interface for handling the log messages.
191 void setLogger(const std::shared_ptr<ILogger> &logger);
194 * API for setting console as logger target.
196 * @return true if console set as logger target,
200 bool setConsoleLogger();
203 * API for setting file as logger target.
205 * @param path - File to which log messages to be saved.
207 * @return true if console set as logger target,
211 bool setFileLogger(const std::string &path);
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;