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_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"
41 typedef std::function<void(const std::string &hostUri, DeviceInfo &deviceInfo)> DeviceInfoCallback;
42 typedef std::function<void(const std::string &hostUri, PlatformInfo &platformInfo)> PlatformInfoCallback;
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);
86 std::shared_ptr<SimulatorSingleResource> createSingleResource(
87 const std::string &name, const std::string &uri, const std::string &resourceType);
89 std::shared_ptr<SimulatorCollectionResource> createCollectionResource(
90 const std::string &name, const std::string &uri, const std::string &resourceType);
93 * API for discovering all type of resources.
94 * Discovered resources will be notified through the callback set using @callback parameter.
96 * @param callback - Method of type @ResourceFindCallback through which discoverd resources
99 * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
100 * @SimulatorException if any other error occured.
102 void findResource(ResourceFindCallback callback);
105 * API for discovering resources of a particular resource type.
106 * Discovered resources will be notified through the callback set using @callback parameter.
108 * @param resourceType - Type of resource to be searched for
109 * @param callback - Method of type @ResourceFindCallback through which discoverd resources
112 * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
113 * @SimulatorException if any other error occured.
115 void findResource(const std::string &resourceType, ResourceFindCallback callback);
118 * API for getting device information from remote device.
119 * Received device information will be notified through the callback set using
120 * @callback parameter.
122 * @param callback - Method of type @DeviceInfoCallback through which device information
125 * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
127 void getDeviceInfo(const std::string &host, DeviceInfoCallback callback);
130 * API for registering device information with stack.
132 * @param deviceName - Device name to be registered.
134 * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
136 void setDeviceInfo(const std::string &deviceName);
139 * API for getting platform information from remote device.
140 * Received platform information will be notified through the callback set using
141 * @callback parameter.
143 * @param callback - Method of type @PlatformInfoCallback through which platform
144 * information will be notified.
146 * NOTE: API throws @InvalidArgsException and @SimulatorException on error.
148 void getPlatformInfo(const std::string &host, PlatformInfoCallback callback);
151 * API for registering platform information with stack.
153 * @param platformInfo - PlatformInfo contains all platform related information.
155 * NOTE: API throws @SimulatorException on error.
157 void setPlatformInfo(PlatformInfo &platformInfo);
160 * API for setting logger target for receiving the log messages.
162 * @param logger - ILogger interface for handling the log messages.
165 void setLogger(const std::shared_ptr<ILogger> &logger);
168 * API for setting console as logger target.
170 * @return true if console set as logger target,
174 bool setConsoleLogger();
177 * API for setting file as logger target.
179 * @param path - File to which log messages to be saved.
181 * @return true if console set as logger target,
185 bool setFileLogger(const std::string &path);
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;