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_RESOURCE_UPDATE_AUTOMATION_H_
22 #define SIMULATOR_RESOURCE_UPDATE_AUTOMATION_H_
24 #include "simulator_resource_model.h"
25 #include "simulator_error_codes.h"
27 class SimulatorResourceServer;
29 enum class AutomationType
35 typedef std::function<void (const std::string &, const int)> updateCompleteCallback;
37 class AttributeUpdateAutomation
40 AttributeUpdateAutomation(SimulatorResourceServer *resource,
41 const std::string &attrName, updateCompleteCallback callback, int automationId,
42 std::function<void (const int)> finishedCallback, AutomationType type = AutomationType::NORMAL,
44 SimulatorResult start();
48 void updateAttribute();
49 void setAttributeValue();
51 SimulatorResourceServer *m_resource;
52 std::string m_attrName;
53 AutomationType m_type;
56 std::thread *m_thread;
59 SimulatorResourceModel::Attribute m_attribute;
60 updateCompleteCallback m_callback;
61 std::function<void (const int)> m_finishedCallback;
64 typedef std::shared_ptr<AttributeUpdateAutomation> AttributeUpdateAutomationPtr;
66 class ResourceUpdateAutomation
69 ResourceUpdateAutomation(SimulatorResourceServer *resource, updateCompleteCallback callback,
70 int automationId, std::function<void (const int)> finishedCallback,
71 AutomationType type = AutomationType::NORMAL, int interval = -1);
72 SimulatorResult start();
74 void finished(int id);
77 void updateAttribute();
78 void setAttributeValue();
80 SimulatorResourceServer *m_resource;
81 AutomationType m_type;
84 std::thread *m_thread;
86 SimulatorResourceModel m_resModel;
87 std::map<int, AttributeUpdateAutomationPtr> m_attrUpdationList;
88 updateCompleteCallback m_callback;
89 std::function<void (const int)> m_finishedCallback;
92 typedef std::shared_ptr<ResourceUpdateAutomation> ResourceUpdateAutomationPtr;
94 class UpdateAutomationManager
97 UpdateAutomationManager();
98 SimulatorResult startResourceAutomation(SimulatorResourceServer *resource,
99 int &id, updateCompleteCallback callback,
100 AutomationType type = AutomationType::NORMAL, int interval = -1);
101 SimulatorResult startAttributeAutomation(SimulatorResourceServer *resource,
102 const std::string &attrName, int &id, updateCompleteCallback callback,
103 AutomationType type = AutomationType::NORMAL, int interval = -1);
104 std::vector<int> getResourceAutomationIds();
105 std::vector<int> getAttributeAutomationIds();
106 void stop(int automationId);
108 void automationFinished(int id);
111 std::map<int, ResourceUpdateAutomationPtr> m_resourceUpdationList;
112 std::map<int, AttributeUpdateAutomationPtr> m_attrUpdationList;
117 typedef std::shared_ptr<UpdateAutomationManager> UpdateAutomationManagerPtr;
119 #endif //SIMULATOR_RESOURCE_UPDATE_AUTOMATION_H_