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 resource_manager.h
24 * @brief This file provides a class for a set of APIs relating to resource management
25 * in the Service Provider side.
28 #ifndef RESOURCE_MANAGER_H_
29 #define RESOURCE_MANAGER_H_
35 #include "simulator_resource_server.h"
36 #include "simulator_resource_creator.h"
37 #include "simulator_error_codes.h"
40 * @class ResourceManager
41 * @brief This class provides a set of functions for managing the resource(s) in the Service Provider Module.
47 * This method is used to create/obtain the singleton instance of ResourceManager.
49 * @return ResourceManager - Singleton instance of ResourceManager.
51 static ResourceManager *getInstance(void);
54 * This method is called for creating a single resource from the configuration file.
56 * @param configPath - RAML configuration file path.
57 * @param callback - Callback method for receive notifications when resource model changes.
59 * @return SimulatorResourceServerPtr - Shared pointer of SimulatorResourceServer on success, otherwise NULL.
61 SimulatorResourceServerPtr createResource(const std::string &configPath,
62 SimulatorResourceServer::ResourceModelChangedCB callback);
65 * This method is called for creating a collection of resources from the configuration file.
67 * @param configPath - RAML configuration file path.
68 * @param count - Number of resource to be created.
69 * @param callback - Callback method for receive notifications when resource model changes.
71 * @return SimulatorResourceServerPtr - A vector of Shared pointers of SimulatorResourceServer Objects.
73 std::vector<SimulatorResourceServerPtr> createResource(const std::string &configPath,
75 SimulatorResourceServer::ResourceModelChangedCB callback);
78 * This method is called for obtaining a list of created resources.
80 * @return SimulatorResourceServerPtr - A vector of Shared pointers of SimulatorResourceServer Objects.
82 std::vector<SimulatorResourceServerPtr> getResources(const std::string &resourceType = "");
85 * This method is called for deleting a single resource.
87 * @param resource - Shared pointer of the SimulatorResourceServer to be deleted.
89 * @return SimulatorResult
91 SimulatorResult deleteResource(SimulatorResourceServerPtr &resource);
94 * This method is called for deleting multiple resources.
95 * If this method is called without any parameter, then all resources will be deleted.
96 * If thie method is called with a specific resourcetype as a parameter, then all the resources
97 * of that particular type will be deleted.
99 * @param resourceType - Resource type of the resource
101 * @return SimulatorResult
103 SimulatorResult deleteResources(const std::string &resourceType = "");
107 * This method is called for obtaining a unique URI when creating multiple resources using createResource API.
108 * It appends a unique key to the given URI.
109 * Example: If input is "/a/light", then the output will be "/a/light/simulator/0" for the first resource
110 * and "/a/light/simulator/1" for the second resource and so on.
112 * @param uri - URI of the resource
114 * @return Unique URI for the resource
116 std::string getURI(std::string uri);
121 SimulatorResourceCreator *m_resourceCreator;
125 * This multi-level map organizes the resources in the form of ResourceType as the key
126 * and a set of resources of that resourceType as the value.
127 * The value is another map which has the ResourceURI as the key and the shared pointer
128 * of the SimulatorResourceServer object as the value.
130 std::map<std::string, std::map<std::string, SimulatorResourceServerPtr>> m_resourceList;
131 std::recursive_mutex m_listMutex;