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 ******************************************************************/
21 #ifndef SIMULATOR_RESOURCE_FACTORY_H_
22 #define SIMULATOR_RESOURCE_FACTORY_H_
24 #include "simulator_single_resource.h"
25 #include "simulator_collection_resource.h"
26 #include "RamlParser.h"
35 class SimulatorResourceFactory
39 * API for getting singleton instance of SimulatorClient class.
41 * @return Singleton instance of SimulatorClient class.
44 static SimulatorResourceFactory *getInstance();
47 * API to create resource based on the given RAML file.
49 * @param configPath - RAML file path.
51 * @return SimulatorResource shared object created using RAML file.
53 std::shared_ptr<SimulatorResource> createResource(const std::string &configPath);
56 * API to create resource based on the given RAML file.
58 * @param configPath - RAML file path.
60 * @return SimulatorResource shared object created using RAML file.
62 std::vector<std::shared_ptr<SimulatorResource> > createResource(
63 const std::string &configPath, unsigned int count);
66 * API to create simple resource.
68 * @param name - Name of resource.
69 * @param uri - URI of resource.
70 * @param resourceType - ResourceType of resource.
72 * @return SimulatorSimpleResource.
74 std::shared_ptr<SimulatorSingleResource> createSingleResource(
75 const std::string &name, const std::string &uri, const std::string &resourceType);
78 * API to create collection resource.
80 * @param name - Name of collection resource.
81 * @param uri - URI of resource.
82 * @param resourceType - ResourceType of collection resource.
84 * @return SimulatorCollectionResource.
86 std::shared_ptr<SimulatorCollectionResource> createCollectionResource(
87 const std::string &name, const std::string &uri, const std::string &resourceType);
90 SimulatorResourceModel::Attribute buildAttribute(
91 std::shared_ptr<RAML::Properties> propertyElement);
92 SimulatorResourceModel buildResourceModel(std::shared_ptr<RAML::Items> item);
93 SimulatorResourceModel buildModelFromResponseBody(
94 RAML::RequestResponseBodyPtr responseBody, std::string &resourceType,
95 std::vector<std::string> &interfaceType);
96 RAML::RequestResponseBodyPtr getRAMLResponseBody(
97 std::shared_ptr<RAML::RamlResource> ramlResource, RAML::ActionType type, std::string responseCode);
98 std::shared_ptr<SimulatorResource> buildResource(
99 std::shared_ptr<RAML::RamlResource> ramlResource);
101 SimulatorResourceFactory() = default;
102 SimulatorResourceFactory(const SimulatorResourceFactory &) = delete;
103 SimulatorResourceFactory &operator=(const SimulatorResourceFactory &) = delete;
104 SimulatorResourceFactory(SimulatorResourceFactory &&) = delete;
105 SimulatorResourceFactory &operator=(SimulatorResourceFactory && ) = delete;
108 class ResourceURIFactory
112 * API for getting singleton instance of SimulatorClient class.
114 * @return Singleton instance of SimulatorClient class.
117 static ResourceURIFactory *getInstance();
120 * API to construct unique URI from the given base @uri.
122 * @param uri - Base uri to be used to construct unique uri.
124 * @return Unique uri.
126 std::string constructURI(const std::string &uri);
129 ResourceURIFactory();
130 ResourceURIFactory(const ResourceURIFactory &) = delete;
131 ResourceURIFactory &operator=(const ResourceURIFactory &) = delete;
132 ResourceURIFactory(ResourceURIFactory &&) = delete;
133 ResourceURIFactory &operator=(ResourceURIFactory && ) = delete;
135 bool isUnique(const std::string &uri);
136 void updateUri(const std::string &uri);
140 std::map<std::string, bool> m_uriList;