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