/src/opendnp3/cpp/lib/src/master/MasterTasks.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_MASTERTASKS_H |
21 | | #define OPENDNP3_MASTERTASKS_H |
22 | | |
23 | | #include "master/IMasterScheduler.h" |
24 | | |
25 | | #include "opendnp3/master/IMasterApplication.h" |
26 | | #include "opendnp3/master/ISOEHandler.h" |
27 | | #include "opendnp3/master/MasterParams.h" |
28 | | |
29 | | #include <vector> |
30 | | |
31 | | namespace opendnp3 |
32 | | { |
33 | | |
34 | | class MasterTasks |
35 | | { |
36 | | |
37 | | public: |
38 | | MasterTasks(const MasterParams& params, |
39 | | const Logger& logger, |
40 | | IMasterApplication& application, |
41 | | std::shared_ptr<ISOEHandler> SOEHandler); |
42 | | |
43 | | void Initialize(IMasterScheduler& scheduler, IMasterTaskRunner& runner); |
44 | | |
45 | | bool DemandTimeSync(); |
46 | | bool DemandEventScan(); |
47 | | bool DemandIntegrity(); |
48 | | |
49 | | void OnRestartDetected(); |
50 | | |
51 | | void BindTask(const std::shared_ptr<IMasterTask>& task); |
52 | | |
53 | | const std::shared_ptr<TaskContext> context; |
54 | | |
55 | | private: |
56 | | bool Demand(const std::shared_ptr<IMasterTask>& task) |
57 | 9.72k | { |
58 | 9.72k | if (task) |
59 | 7.95k | { |
60 | 7.95k | task->SetMinExpiration(); |
61 | 7.95k | return true; |
62 | 7.95k | } |
63 | 1.77k | else |
64 | 1.77k | { |
65 | 1.77k | return false; |
66 | 1.77k | } |
67 | 9.72k | } |
68 | | |
69 | | inline static TaskBehavior RetryBehavior(const MasterParams& params) |
70 | 18.4k | { |
71 | 18.4k | return TaskBehavior::SingleImmediateExecutionWithRetry(params.taskRetryPeriod, params.maxTaskRetryPeriod); |
72 | 18.4k | } |
73 | | |
74 | | const std::shared_ptr<IMasterTask> clearRestart; |
75 | | const std::shared_ptr<IMasterTask> assignClass; |
76 | | const std::shared_ptr<IMasterTask> startupIntegrity; |
77 | | const std::shared_ptr<IMasterTask> eventScan; |
78 | | const std::shared_ptr<IMasterTask> disableUnsol; |
79 | | const std::shared_ptr<IMasterTask> enableUnsol; |
80 | | const std::shared_ptr<IMasterTask> timeSynchronization; |
81 | | |
82 | | static std::shared_ptr<IMasterTask> GetTimeSyncTask(const std::shared_ptr<TaskContext>& context, |
83 | | TimeSyncMode mode, |
84 | | const Logger& logger, |
85 | | IMasterApplication& application); |
86 | | static std::shared_ptr<IMasterTask> GetEnableUnsolTask(const std::shared_ptr<TaskContext>& context, |
87 | | const MasterParams& params, |
88 | | const Logger& logger, |
89 | | IMasterApplication& application); |
90 | | static std::shared_ptr<IMasterTask> GetDisableUnsolTask(const std::shared_ptr<TaskContext>& context, |
91 | | const MasterParams& params, |
92 | | const Logger& logger, |
93 | | IMasterApplication& application); |
94 | | |
95 | | std::vector<std::shared_ptr<IMasterTask>> boundTasks; |
96 | | }; |
97 | | |
98 | | } // namespace opendnp3 |
99 | | |
100 | | #endif |