Use `URI` all caps in documentation
[iotivity.git] / service / simulator / src / server / simulator_resource_factory.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 #ifndef SIMULATOR_RESOURCE_FACTORY_H_
22 #define SIMULATOR_RESOURCE_FACTORY_H_
23
24 #include "simulator_single_resource.h"
25 #include "simulator_collection_resource.h"
26 #include "RamlParser.h"
27
28 namespace RAML
29 {
30     class RamlResource;
31     class Properties;
32     class JsonSchema;
33     class RamlParser;
34 }
35
36 class SimulatorResourceFactory
37 {
38     public:
39         /**
40          * API for getting singleton instance of SimulatorClient class.
41          *
42          * @return Singleton instance of SimulatorClient class.
43          *
44          */
45         static SimulatorResourceFactory *getInstance();
46
47         /**
48          * API to create resource based on the given RAML file.
49          *
50          * @param configPath - RAML file path.
51          *
52          * @return SimulatorResource shared object created using RAML file.
53          */
54         std::shared_ptr<SimulatorResource> createResource(const std::string &configPath);
55
56         /**
57          * API to create resource based on the given RAML file.
58          *
59          * @param configPath - RAML file path.
60          *
61          * @return SimulatorResource shared object created using RAML file.
62          */
63         std::vector<std::shared_ptr<SimulatorResource> > createResource(
64             const std::string &configPath, unsigned int count);
65
66         /**
67          * API to create simple resource.
68          *
69          * @param name - Name of resource.
70          * @param uri - URI of resource.
71          * @param resourceType - ResourceType of resource.
72          *
73          * @return SimulatorSimpleResource.
74          */
75         std::shared_ptr<SimulatorSingleResource> createSingleResource(
76             const std::string &name, const std::string &uri, const std::string &resourceType);
77
78         /**
79          * API to create collection resource.
80          *
81          * @param name - Name of collection resource.
82          * @param uri - URI of resource.
83          * @param resourceType - ResourceType of collection resource.
84          *
85          * @return SimulatorCollectionResource.
86          */
87         std::shared_ptr<SimulatorCollectionResource> createCollectionResource(
88             const std::string &name, const std::string &uri, const std::string &resourceType);
89
90     private:
91         std::shared_ptr<SimulatorResource> buildResource(
92             const std::shared_ptr<RAML::RamlResource> &ramlResource);
93
94         void addInterfaceFromQueryParameter(
95             std::vector<std::string> queryParamValue, std::vector<std::string> &interfaceTypes);
96
97         SimulatorResourceFactory() = default;
98         SimulatorResourceFactory(const SimulatorResourceFactory &) = delete;
99         SimulatorResourceFactory &operator=(const SimulatorResourceFactory &) = delete;
100         SimulatorResourceFactory(SimulatorResourceFactory &&) = delete;
101         SimulatorResourceFactory &operator=(SimulatorResourceFactory && ) = delete;
102 };
103
104 class ResourceURIFactory
105 {
106     public:
107         /**
108          * API for getting singleton instance of SimulatorClient class.
109          *
110          * @return Singleton instance of SimulatorClient class.
111          *
112          */
113         static ResourceURIFactory *getInstance();
114
115         /**
116          * API to construct unique URI from the given base @uri.
117          *
118          * @param uri - Base URI to be used to construct unique URI.
119          *
120          * @return Unique URI.
121          */
122         std::string makeUniqueURI(const std::string &uri);
123
124     private:
125         ResourceURIFactory();
126         ResourceURIFactory(const ResourceURIFactory &) = delete;
127         ResourceURIFactory &operator=(const ResourceURIFactory &) = delete;
128         ResourceURIFactory(ResourceURIFactory &&) = delete;
129         ResourceURIFactory &operator=(ResourceURIFactory && ) = delete;
130
131         bool isUnique(const std::string &uri);
132         void updateUri(const std::string &uri);
133
134         unsigned int m_id;
135         std::mutex m_lock;
136         std::map<std::string, bool> m_uriList;
137 };
138
139 #endif