@@ -30,6 +30,12 @@ int AssembleAction::addChild(Action *)
30
30
return -1 ;
31
31
}
32
32
33
+ int AssembleAction::addChildAs (Action *, const std::string &)
34
+ {
35
+ LogWarn (" %d:%s[%s] not implement this function" , id (), type ().c_str (), label ().c_str ());
36
+ return -1 ;
37
+ }
38
+
33
39
bool AssembleAction::setChild (Action *)
34
40
{
35
41
LogWarn (" %d:%s[%s] not implement this function" , id (), type ().c_str (), label ().c_str ());
@@ -48,5 +54,99 @@ void AssembleAction::onFinal()
48
54
final_cb_ ();
49
55
}
50
56
57
+ // ////////////////////////
58
+ // SerialAssembleAction
59
+ // ////////////////////////
60
+
61
+ bool SerialAssembleAction::startThisAction (Action *action)
62
+ {
63
+ if (action->start ()) {
64
+ curr_action_ = action;
65
+ return true ;
66
+ }
67
+
68
+ return false ;
69
+ }
70
+
71
+ void SerialAssembleAction::stopCurrAction ()
72
+ {
73
+ if (curr_action_ != nullptr ) {
74
+ curr_action_->stop ();
75
+ curr_action_ = nullptr ;
76
+ }
77
+ }
78
+
79
+ bool SerialAssembleAction::handleChildFinishEvent (ChildFinishFunc &&child_finish_func)
80
+ {
81
+ curr_action_ = nullptr ;
82
+
83
+ // ! 如果处于运行状态,则由派生类自行处理
84
+ if (state () == State::kRunning )
85
+ return false ;
86
+
87
+ // ! 如果处于暂停状态,则暂存结果
88
+ if (state () == State::kPause )
89
+ child_finish_func_ = std::move (child_finish_func);
90
+
91
+ // ! 其它状态,如已结束或停止,则不处理
92
+ return true ;
93
+ }
94
+
95
+ void SerialAssembleAction::onLastChildFinished (bool is_succ, const Reason &reason, const Trace &trace)
96
+ {
97
+ curr_action_ = nullptr ;
98
+
99
+ // ! 如果处于运行状态,则正常退出
100
+ if (state () == State::kRunning ) {
101
+ finish (is_succ, reason, trace);
102
+ return ;
103
+ }
104
+
105
+ // ! 如果处于暂停状态,则暂存结果
106
+ if (state () == State::kPause )
107
+ child_finish_func_ = [this , is_succ, reason, trace] { finish (is_succ, reason, trace); };
108
+
109
+ // ! 其它状态,如已结束或停止,则不处理
110
+ }
111
+
112
+ void SerialAssembleAction::onPause ()
113
+ {
114
+ if (curr_action_ != nullptr )
115
+ curr_action_->pause ();
116
+
117
+ AssembleAction::onPause ();
118
+ }
119
+
120
+ void SerialAssembleAction::onResume ()
121
+ {
122
+ AssembleAction::onResume ();
123
+
124
+ if (curr_action_ != nullptr ) {
125
+ curr_action_->resume ();
126
+
127
+ } else if (child_finish_func_) {
128
+ loop_.runNext (std::move (child_finish_func_));
129
+
130
+ } else {
131
+ LogWarn (" %d:%s[%s] can't resume" , id (), type ().c_str (), label ().c_str ());
132
+ }
133
+ }
134
+
135
+ void SerialAssembleAction::onStop ()
136
+ {
137
+ stopCurrAction ();
138
+ child_finish_func_ = nullptr ;
139
+
140
+ AssembleAction::onStop ();
141
+ }
142
+
143
+ void SerialAssembleAction::onReset ()
144
+ {
145
+ curr_action_ = nullptr ;
146
+ child_finish_func_ = nullptr ;
147
+
148
+ AssembleAction::onReset ();
149
+ }
150
+
51
151
}
52
152
}
0 commit comments