ea31ac60f4c91d3f49d5140fcdacaaf30ed43743
[platform/upstream/iotivity.git] / service / simulator / src / server / simulator_collection_resource_impl.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_COLLECTION_RESOURCE_IMPL_H_
22 #define SIMULATOR_COLLECTION_RESOURCE_IMPL_H_
23
24 #include "simulator_collection_resource.h"
25 #include "RamlParser.h"
26
27 class SimulatorResourceFactory;
28 class SimulatorCollectionResourceImpl : public SimulatorCollectionResource
29 {
30     public:
31         friend class SimulatorResourceFactory;
32
33         std::string getName() const;
34         SimulatorResource::Type getType() const;
35         std::string getURI() const;
36         std::string getResourceType() const;
37         std::vector<std::string> getInterface() const;
38         bool isObservable();
39         bool isStarted();
40         SimulatorResourceModel getResourceModel();
41         void setInterface(const std::vector<std::string> &interfaces);
42         void setName(const std::string &name);
43         void setURI(const std::string &uri);
44         void setResourceType(const std::string &resourceType);
45         void addInterface(std::string interfaceType);
46         void setObservable(bool state);
47         void setObserverCallback(ObserverCallback callback);
48         void setModelChangeCallback(ResourceModelChangedCallback callback);
49         void start();
50         void stop();
51         std::vector<ObserverInfo> getObserversList();
52         void notify(int id);
53         void notifyAll();
54
55         std::vector<std::string> getSupportedResources();
56         void addChildResource(SimulatorResourceSP &resource);
57         void removeChildResource(SimulatorResourceSP &resource);
58         void removeChildResource(const std::string &uri);
59         std::vector<SimulatorResourceSP> getChildResources();
60
61         void setResourceModel(const SimulatorResourceModel &resModel);
62
63         void setActionType(std::map<RAML::ActionType, RAML::ActionPtr> &actionType);
64
65         RAML::ActionType getActionType(std::string requestType);
66
67     private:
68         SimulatorCollectionResourceImpl();
69
70         OCEntityHandlerResult handleRequests(std::shared_ptr<OC::OCResourceRequest> request);
71         std::shared_ptr<OC::OCResourceResponse> requestOnBaseLineInterface(
72             std::shared_ptr<OC::OCResourceRequest> request);
73         std::shared_ptr<OC::OCResourceResponse> requestOnLinkListInterface(
74             std::shared_ptr<OC::OCResourceRequest> request);
75         std::shared_ptr<OC::OCResourceResponse> requestOnBatchInterface(
76             std::shared_ptr<OC::OCResourceRequest> request);
77         void sendNotification(OC::ObservationIds &observers);
78         void addLink(SimulatorResourceSP &resource);
79         void removeLink(std::string uri);
80
81         SimulatorResource::Type m_type;
82         std::string m_name;
83         std::string m_uri;
84         std::string m_resourceType;
85         std::vector<std::string> m_interfaces;
86
87         std::mutex m_modelLock;
88         SimulatorResourceModel m_resModel;
89         std::recursive_mutex m_objectLock;
90         std::mutex m_childResourcesLock;
91         std::map<std::string, SimulatorResourceSP> m_childResources;
92         std::vector<std::string> m_supportedTypes;
93         std::vector<ObserverInfo> m_observersList;
94         ObserverCallback m_observeCallback;
95         ResourceModelChangedCallback m_modelCallback;
96         std::map<RAML::ActionType , RAML::ActionPtr> m_actionTypes;
97
98         OCResourceProperty m_property;
99         OCResourceHandle m_resourceHandle;
100 };
101
102 #endif