Implementation of APIs for managing resource list and callback
[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 <vector>
32 #include "simulator_resource_server.h"
33 #include "simulator_remote_resource.h"
34 #include "simulator_error_codes.h"
35 #include "simulator_logger.h"
36
37 /**
38  * @class   SimulatorManager
39  *
40  * @brief   This class provides a set of methods for platform configuration,
41  *              and creation/deletion of resources.
42  *
43  */
44 class SimulatorManager
45 {
46     public:
47         static SimulatorManager *getInstance();
48
49         /**
50          * This method is called for creating a single resource from RAML configuration file.
51          *
52          * @param configPath - RAML configuration file path.
53          * @param callback - Callback method for receive notifications when resource model changes.
54          *
55          * @return SimulatorResourceServerPtr - Shared pointer of SimulatorResourceServer on success, otherwise NULL.
56          */
57         SimulatorResourceServerPtr createResource(const std::string &configPath,
58                 SimulatorResourceServer::ResourceModelChangedCB callback);
59
60         /**
61          * This method is called for creating a collection of resources from RAML configuration file.
62          *
63          * @param configPath - RAML configuration file path.
64          * @param count - Number of resource to be created.
65          * @param callback - Callback method for receive notifications when resource model changes.
66          *
67          * @return SimulatorResourceServerPtr - A vector of Shared pointers of SimulatorResourceServer Objects.
68          */
69         std::vector<SimulatorResourceServerPtr> createResource(const std::string &configPath,
70                 const int count,
71                 SimulatorResourceServer::ResourceModelChangedCB callback);
72
73         /**
74          * This method is called for obtaining a list of created resources.
75          *
76          * @return SimulatorResourceServerPtr - A vector of Shared pointers of SimulatorResourceServer Objects.
77          */
78         std::vector<SimulatorResourceServerPtr> getResources(const std::string &resourceType = "");
79
80         /**
81           * This method is called for deleting a single resource.
82           *
83           * @param resource - Shared pointer of the SimulatorResourceServer to be deleted.
84           *
85           * @return SimulatorResult
86           */
87         SimulatorResult deleteResource(SimulatorResourceServerPtr &resource);
88
89         /**
90           * This method is called for deleting multiple resources.
91           * If this method is called without any parameter, then all resources will be deleted.
92           * If thie method is called with a specific resourcetype as a parameter, then all the resources
93           * of that particular type will be deleted.
94           *
95           * @param resourceType - Resource type of the resource
96           *
97           * @return SimulatorResult
98           */
99         SimulatorResult deleteResources(const std::string &resourceType = "");
100
101         /**
102          * API for discovering resources of a particular resource type.
103          * Callback is called when a resource is found.
104          *
105          * @param resourceType - required resource type
106          * @param callback - Returns SimulatorRemoteResource.
107          *
108          * @return SimulatorResult - return value of this API.
109          *                         It returns SIMULATOR_SUCCESS if success.
110          *
111          * NOTE: SimulatorResult is defined in simulator_error_codes.h.
112          */
113         SimulatorResult findResource(const std::string &resourceType, ResourceFindCallback callback);
114
115         /**
116          * API for getting list of already found resources.
117          *
118          * @param resourceType - resource type
119          *
120          * @return List of SimulatorRemoteResource
121          *
122          */
123         std::vector<SimulatorRemoteResourcePtr> getFoundResources(
124             const std::string resourceType = "");
125
126         /**
127          * API for setting logger target for receiving the log messages.
128          *
129          * @param logger - ILogger interface for handling the log messages.
130          *
131          */
132         void setLogger(std::shared_ptr<ILogger> logger);
133
134         /**
135          * API for setting console as logger target.
136          *
137          * @return true if console set as logger target,
138          *         otherwise false.
139          *
140          */
141         bool setDefaultConsoleLogger();
142
143         /**
144          * API for setting file as logger target.
145          *
146          * @param path - File to which log messages to be saved.
147          *
148          * @return true if console set as logger target,
149          *         otherwise false.
150          *
151          */
152         bool setDefaultFileLogger(std::string &path);
153
154     private:
155         SimulatorManager();
156         ~SimulatorManager() = default;
157 };
158
159 #endif