/src/opendnp3/cpp/lib/src/master/CommandTask.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2013-2022 Step Function I/O, LLC |
3 | | * |
4 | | * Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O |
5 | | * LLC (https://stepfunc.io) under one or more contributor license agreements. |
6 | | * See the NOTICE file distributed with this work for additional information |
7 | | * regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license |
8 | | * this file to you under the Apache License, Version 2.0 (the "License"); you |
9 | | * may not use this file except in compliance with the License. You may obtain |
10 | | * a copy of the License at: |
11 | | * |
12 | | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | | * |
14 | | * Unless required by applicable law or agreed to in writing, software |
15 | | * distributed under the License is distributed on an "AS IS" BASIS, |
16 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 | | * See the License for the specific language governing permissions and |
18 | | * limitations under the License. |
19 | | */ |
20 | | #ifndef OPENDNP3_COMMANDTASK_H |
21 | | #define OPENDNP3_COMMANDTASK_H |
22 | | |
23 | | #include "master/IMasterTask.h" |
24 | | #include "master/TaskPriority.h" |
25 | | |
26 | | #include "opendnp3/gen/FunctionCode.h" |
27 | | #include "opendnp3/gen/IndexQualifierMode.h" |
28 | | #include "opendnp3/logging/Logger.h" |
29 | | #include "opendnp3/master/CommandSet.h" |
30 | | #include "opendnp3/master/ICommandProcessor.h" |
31 | | #include "opendnp3/master/ITaskCallback.h" |
32 | | |
33 | | #include <assert.h> |
34 | | |
35 | | #include <deque> |
36 | | #include <memory> |
37 | | |
38 | | namespace opendnp3 |
39 | | { |
40 | | |
41 | | // Base class with machinery for performing command operations |
42 | | class CommandTask : public IMasterTask |
43 | | { |
44 | | |
45 | | public: |
46 | | CommandTask(const std::shared_ptr<TaskContext>& context, |
47 | | CommandSet&& commands, |
48 | | IndexQualifierMode mode, |
49 | | IMasterApplication& app, |
50 | | CommandResultCallbackT callback, |
51 | | const Timestamp& startExpiration, |
52 | | const TaskConfig& config, |
53 | | const Logger& logger); |
54 | | |
55 | | static std::shared_ptr<IMasterTask> CreateDirectOperate(const std::shared_ptr<TaskContext>& context, |
56 | | CommandSet&& set, |
57 | | IndexQualifierMode mode, |
58 | | IMasterApplication& app, |
59 | | const CommandResultCallbackT& callback, |
60 | | const Timestamp& startExpiration, |
61 | | const TaskConfig& config, |
62 | | Logger logger); |
63 | | static std::shared_ptr<IMasterTask> CreateSelectAndOperate(const std::shared_ptr<TaskContext>& context, |
64 | | CommandSet&& set, |
65 | | IndexQualifierMode mode, |
66 | | IMasterApplication& app, |
67 | | const CommandResultCallbackT& callback, |
68 | | const Timestamp& startExpiration, |
69 | | const TaskConfig& config, |
70 | | Logger logger); |
71 | | |
72 | | virtual char const* Name() const override final |
73 | 0 | { |
74 | 0 | return "Command Task"; |
75 | 0 | } |
76 | | |
77 | | virtual int Priority() const override final |
78 | 0 | { |
79 | 0 | return priority::COMMAND; |
80 | 0 | } |
81 | | |
82 | | virtual bool BlocksLowerPriority() const override final |
83 | 0 | { |
84 | 0 | return false; |
85 | 0 | } |
86 | | |
87 | | virtual bool IsRecurring() const override final |
88 | 0 | { |
89 | 0 | return false; |
90 | 0 | } |
91 | | |
92 | | virtual bool BuildRequest(APDURequest& request, uint8_t seq) override final; |
93 | | |
94 | | private: |
95 | | virtual bool IsEnabled() const override final |
96 | 0 | { |
97 | 0 | return true; |
98 | 0 | } |
99 | | |
100 | | virtual MasterTaskType GetTaskType() const override final |
101 | 0 | { |
102 | 0 | return MasterTaskType::USER_TASK; |
103 | 0 | } |
104 | | |
105 | | virtual void Initialize() override final; |
106 | | |
107 | | virtual ResponseResult ProcessResponse(const APDUResponseHeader& header, |
108 | | const ser4cpp::rseq_t& objects) override final; |
109 | | |
110 | | virtual void OnTaskComplete(TaskCompletion result, Timestamp now) override final; |
111 | | |
112 | | ResponseResult ProcessResponse(const ser4cpp::rseq_t& objects); |
113 | | |
114 | | void LoadSelectAndOperate(); |
115 | | void LoadDirectOperate(); |
116 | | |
117 | | std::deque<FunctionCode> functionCodes; |
118 | | |
119 | | CommandStatus statusResult; |
120 | | const CommandResultCallbackT commandCallback; |
121 | | CommandSet commands; |
122 | | const IndexQualifierMode mode; |
123 | | }; |
124 | | |
125 | | } // namespace opendnp3 |
126 | | |
127 | | #endif |