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();
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,
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);
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();
82 SimulatorResource::Type m_type;
85 std::string m_resourceType;
86 std::vector<std::string> m_interfaces;
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;
96 OCResourceProperty m_property;
97 OCResourceHandle m_resourceHandle;
100 typedef std::shared_ptr<SimulatorSingleResourceImpl> SimulatorSingleResourceImplSP;