Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / src / service-provider / resource_update_automation.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 RESOURCE_UPDATE_AUTOMATION_H_
22 #define RESOURCE_UPDATE_AUTOMATION_H_
23
24 #include "simulator_resource_server.h"
25 #include <thread>
26
27 class AttributeUpdateAutomation
28 {
29     public:
30         AttributeUpdateAutomation(int id, SimulatorResourceServer *resource,
31                                   const std::string &attrName, AutomationType type, int interval,
32                                   updateCompleteCallback callback,
33                                   std::function<void (const int)> finishedCallback);
34
35         void start();
36
37         void stop();
38
39     private:
40         void updateAttribute();
41         void setAttributeValue();
42
43         SimulatorResourceServer *m_resource;
44         std::string m_attrName;
45         AutomationType m_type;
46         int m_id;
47         bool m_stopRequested;
48         int m_updateInterval;
49         SimulatorResourceModel::Attribute m_attribute;
50         updateCompleteCallback m_callback;
51         std::function<void (const int)> m_finishedCallback;
52         std::thread *m_thread;
53 };
54
55 typedef std::shared_ptr<AttributeUpdateAutomation> AttributeUpdateAutomationSP;
56
57 class ResourceUpdateAutomation
58 {
59     public:
60         ResourceUpdateAutomation(int id, SimulatorResourceServer *resource,
61                                  AutomationType type, int interval,
62                                  updateCompleteCallback callback,
63                                  std::function<void (const int)> finishedCallback);
64
65         void start();
66
67         void stop();
68
69         void finished(int id);
70
71     private:
72         SimulatorResourceServer *m_resource;
73         AutomationType m_type;
74         int m_id;
75         int m_updateInterval;
76         SimulatorResourceModel m_resModel;
77         std::map<int, AttributeUpdateAutomationSP> m_attrUpdationList;
78         updateCompleteCallback m_callback;
79         std::function<void (const int)> m_finishedCallback;
80 };
81
82 typedef std::shared_ptr<ResourceUpdateAutomation> ResourceUpdateAutomationSP;
83
84 #endif