Merge branch 'master' into simulator
[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         void notify(int id, SimulatorResourceModel &resModel);
53         void notifyAll(SimulatorResourceModel &resModel);
54
55         bool getAttribute(const std::string &attrName,
56                           SimulatorResourceModel::Attribute &attribute);
57         void addAttribute(const SimulatorResourceModel::Attribute &attribute, bool notify = true);
58         bool getAttributeProperty(const std::string &attrName,
59                                   SimulatorResourceModel::AttributeProperty &property);
60         bool setAttributeProperty(const std::string &attrName,
61                                   const SimulatorResourceModel::AttributeProperty &property);
62         bool updateAttributeValue(const SimulatorResourceModel::Attribute &attribute,
63                                   bool notify = true);
64         bool removeAttribute(const std::string &attrName, bool notify = true);
65         SimulatorResourceModel getResourceModel();
66         void setModelChangeCallback(ResourceModelChangedCallback callback);
67         int startResourceUpdation(AutomationType type, int updateInterval,
68                                   updateCompleteCallback callback);
69         int startAttributeUpdation(const std::string &attrName, AutomationType type,
70                                    int updateInterval, updateCompleteCallback callback);
71         std::vector<int> getResourceUpdationIds();
72         std::vector<int> getAttributeUpdationIds();
73         void stopUpdation(const int id);
74         void setResourceModel(const SimulatorResourceModel &resModel);
75         void notifyApp();
76         void notifyApp(SimulatorResourceModel &resModel);
77
78     private:
79         SimulatorSingleResourceImpl();
80         OCEntityHandlerResult handleRequests(std::shared_ptr<OC::OCResourceRequest> request);
81         std::shared_ptr<OC::OCResourceResponse> requestOnBaseLineInterface(
82             std::shared_ptr<OC::OCResourceRequest> request);
83         void resourceModified();
84         bool updateResourceModel(OC::OCRepresentation &ocRep, SimulatorResourceModel &resModel);
85
86         SimulatorResource::Type m_type;
87         std::string m_name;
88         std::string m_uri;
89         std::string m_resourceType;
90         std::vector<std::string> m_interfaces;
91
92         std::recursive_mutex m_objectLock;
93         std::mutex m_modelLock;
94         SimulatorResourceModel m_resModel;
95         ResourceModelChangedCallback m_modelCallback;
96         ObserverCallback m_observeCallback;
97         UpdateAutomationMngr m_updateAutomationMgr;
98         std::vector<ObserverInfo> m_observersList;
99
100         OCResourceProperty m_property;
101         OCResourceHandle m_resourceHandle;
102 };
103
104 typedef std::shared_ptr<SimulatorSingleResourceImpl> SimulatorSingleResourceImplSP;
105
106 #endif