1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
21 #ifndef SIMULATOR_SINGLE_RESOURCE_IMPL_H_
22 #define SIMULATOR_SINGLE_RESOURCE_IMPL_H_
24 #include "simulator_single_resource.h"
25 #include "resource_update_automation_mngr.h"
27 class SimulatorResourceFactory;
28 class SimulatorSingleResourceImpl : public SimulatorSingleResource
31 friend class SimulatorResourceFactory;
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);
49 std::vector<ObserverInfo> getObserversList();
52 void notify(int id, SimulatorResourceModel &resModel);
53 void notifyAll(SimulatorResourceModel &resModel);
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,
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);
78 void notifyApp(SimulatorResourceModel &resModel);
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);
88 SimulatorResource::Type m_type;
91 std::string m_resourceType;
92 std::vector<std::string> m_interfaces;
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;
104 OCResourceProperty m_property;
105 OCResourceHandle m_resourceHandle;
108 typedef std::shared_ptr<SimulatorSingleResourceImpl> SimulatorSingleResourceImplSP;