Added Simulator Resource Model Support to read collection resource.
[platform/upstream/iotivity.git] / service / simulator / src / server / simulator_single_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_SINGLE_RESOURCE_IMPL_H_
22 #define SIMULATOR_SINGLE_RESOURCE_IMPL_H_
23
24 #include "simulator_single_resource.h"
25 #include "resource_update_automation_mngr.h"
26
27 class SimulatorResourceFactory;
28 class SimulatorSingleResourceImpl : public SimulatorSingleResource
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         void setInterface(const std::vector<std::string> &interfaces);
39         void setName(const std::string &name);
40         void setURI(const std::string &uri);
41         void setResourceType(const std::string &resourceType);
42         void addInterface(std::string interfaceType);
43         void setObservable(bool state);
44         void setObserverCallback(ObserverCallback callback);
45         bool isObservable();
46         bool isStarted();
47         void start();
48         void stop();
49         std::vector<ObserverInfo> getObserversList();
50         void notify(int id);
51         void notifyAll();
52
53         bool getAttribute(const std::string &attrName,
54                           SimulatorResourceModel::Attribute &attribute);
55         void addAttribute(const SimulatorResourceModel::Attribute &attribute, bool notify = true);
56         bool getAttributeProperty(const std::string &attrName,
57                                   SimulatorResourceModel::AttributeProperty &property);
58         bool setAttributeProperty(const std::string &attrName,
59                                   const SimulatorResourceModel::AttributeProperty &property);
60         bool updateAttributeValue(const SimulatorResourceModel::Attribute &attribute,
61                                   bool notify = true);
62         bool removeAttribute(const std::string &attrName, bool notify = true);
63         SimulatorResourceModel getResourceModel();
64         void setModelChangeCallback(ResourceModelChangedCallback callback);
65         int startResourceUpdation(AutomationType type, int updateInterval,
66                                   updateCompleteCallback callback);
67         int startAttributeUpdation(const std::string &attrName, AutomationType type,
68                                    int updateInterval, updateCompleteCallback callback);
69         std::vector<int> getResourceUpdationIds();
70         std::vector<int> getAttributeUpdationIds();
71         void stopUpdation(const int id);
72         void setResourceModel(const SimulatorResourceModel &resModel);
73         void notifyApp();
74
75     private:
76         SimulatorSingleResourceImpl();
77         OCEntityHandlerResult handleRequests(std::shared_ptr<OC::OCResourceRequest> request);
78         std::shared_ptr<OC::OCResourceResponse> requestOnBaseLineInterface(
79             std::shared_ptr<OC::OCResourceRequest> request);
80         void resourceModified();
81
82         SimulatorResource::Type m_type;
83         std::string m_name;
84         std::string m_uri;
85         std::string m_resourceType;
86         std::vector<std::string> m_interfaces;
87
88         std::recursive_mutex m_objectLock;
89         std::mutex m_modelLock;
90         SimulatorResourceModel m_resModel;
91         ResourceModelChangedCallback m_modelCallback;
92         ObserverCallback m_observeCallback;
93         UpdateAutomationMngr m_updateAutomationMgr;
94         std::vector<ObserverInfo> m_observersList;
95
96         OCResourceProperty m_property;
97         OCResourceHandle m_resourceHandle;
98 };
99
100 typedef std::shared_ptr<SimulatorSingleResourceImpl> SimulatorSingleResourceImplSP;
101
102 #endif