Collection resource not notifying its updated model when child resource is added...
[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 setPutErrorResponseModel(const SimulatorResourceModel &resModel);
76         void setPostErrorResponseModel(const SimulatorResourceModel &resModel);
77         void notifyApp();
78         void notifyApp(SimulatorResourceModel &resModel);
79
80     private:
81         SimulatorSingleResourceImpl();
82         OCEntityHandlerResult handleRequests(std::shared_ptr<OC::OCResourceRequest> request);
83         std::shared_ptr<OC::OCResourceResponse> requestOnBaseLineInterface(
84             std::shared_ptr<OC::OCResourceRequest> request);
85         void resourceModified();
86         bool updateResourceModel(OC::OCRepresentation &ocRep, SimulatorResourceModel &resModel);
87
88         SimulatorResource::Type m_type;
89         std::string m_name;
90         std::string m_uri;
91         std::string m_resourceType;
92         std::vector<std::string> m_interfaces;
93
94         std::recursive_mutex m_objectLock;
95         std::mutex m_modelLock;
96         SimulatorResourceModel m_resModel;
97         SimulatorResourceModel m_putErrorResModel;
98         SimulatorResourceModel m_postErrorResModel;
99         ResourceModelChangedCallback m_modelCallback;
100         ObserverCallback m_observeCallback;
101         UpdateAutomationMngr m_updateAutomationMgr;
102         std::vector<ObserverInfo> m_observersList;
103
104         OCResourceProperty m_property;
105         OCResourceHandle m_resourceHandle;
106 };
107
108 typedef std::shared_ptr<SimulatorSingleResourceImpl> SimulatorSingleResourceImplSP;
109
110 #endif