OpenRTM-aist
2.1.0
Toggle main menu visibility
読み取り中…
検索中…
一致する文字列を見つけられません
StaticFSM.h
[詳解]
1
// -*- C++ -*-
16
17
#ifndef RTC_STATICFSM_H
18
#define RTC_STATICFSM_H
19
20
#include <
rtm/RTObject.h
>
21
#include <
rtm/Macho.h
>
22
#include <
rtm/RingBuffer.h
>
23
#include <
rtm/EventBase.h
>
24
65
66
70
#define FSM_TOPSTATE(TOP) \
71
struct TOP \
72
: public ::RTC::Link< TOP, ::Macho::TopBase< TOP > >
73
77
#define FSM_SUBSTATE(STATE, SUPERSTATE) \
78
struct STATE \
79
: public ::RTC::Link< STATE, SUPERSTATE >
80
84
#define FSM_STATE(S) \
85
public: \
86
using SELF = S; \
87
S(::Macho::_StateInstance & instance) \
88
: ::RTC::Link<S, SUPER>(instance) \
89
{ \
90
using MustDeriveFromLink = ::CheckSameType<::RTC::Link<S, SUPER>, \
91
LINK>::Check; \
92
static_assert(static_cast<MustDeriveFromLink*>(nullptr)==nullptr, \
93
"dummy assert for suppress warning"); \
94
} \
95
~S() override {} \
96
static const char * _state_name() { return #S; } \
97
Box & box() { return *static_cast<Box *>(_box()); } \
98
friend class ::_VS8_Bug_101615
99
100
#define FSM_INIT_VALUE(S) \
101
template<> \
102
const ::Macho::ID Macho::StateID<S>::value = ::Macho::Machine<typename S::TOP>::theStateCount++;
103
104
namespace
RTC
105
{
114
template
<
class
TOP>
115
class
Machine
116
:
public
Macho::Machine
<TOP>
117
{
118
public
:
119
Machine
(
RTC::RTObject_impl
* comp)
120
:
Macho
::
Machine
<TOP>(), rtComponent(comp)
121
{
122
}
123
~Machine
()
override
=
default
;
124
virtual
RingBuffer<EventBase*>
&
getBuffer
()
125
{
126
return
m_buffer;
127
}
128
virtual
void
run_event
()
129
{
130
while
(m_buffer.readable() > 0)
131
{
132
EventBase
* ebt = m_buffer.get();
133
(*ebt)();
134
m_buffer.advanceRptr();
135
delete
ebt;
136
}
137
}
138
139
private
:
140
Machine
(
const
Machine<TOP>
& other) =
delete
;
141
Machine<TOP>
& operator=(
const
Machine<TOP>
& other) =
delete
;
142
143
template
<
class
C,
class
P>
144
friend
class
Link
;
145
146
#ifdef MACHO_SNAPSHOTS
147
friend
class
Macho::Snapshot<TOP>;
148
#endif
149
template
<
class
T>
friend
class
Macho::StateID
;
150
151
RTObject_impl
* rtComponent;
152
RingBuffer<EventBase*>
m_buffer;
153
};
154
166
template
<
class
C,
class
P>
167
class
Link
168
:
public
Macho::Link
<C, P>
169
{
170
protected
:
171
Link
(
Macho::_StateInstance
& instance)
172
:
Macho
::
Link
<C, P>(instance),
rtComponent
(nullptr)
173
{
174
}
175
~Link
()
override
=
default
;
176
177
void
setrtc
()
178
{
179
if
(
rtComponent
!=
nullptr
) {
return
; }
180
const
RTC::Machine<typename P::TOP>
* machine =
181
dynamic_cast<
const
RTC::Machine<typename P::TOP>
*
>
(&P::machine());
182
if
(machine !=
nullptr
) {
rtComponent
= machine->rtComponent; }
183
}
184
public
:
185
using
LINK
=
Link<C, P>
;
186
187
void
entry
()
override
188
{
189
setrtc
();
190
if
(
rtComponent
==
nullptr
)
191
{
192
onEntry
();
193
}
194
else
195
{
196
rtComponent
->postOnFsmStateChange(C::_state_name(), RTC::RTC_OK);
197
rtComponent
->preOnFsmEntry(C::_state_name());
198
rtComponent
->postOnFsmEntry(C::_state_name(),
onEntry
());
199
}
200
}
201
void
init
()
override
202
{
203
setrtc
();
204
if
(
rtComponent
==
nullptr
)
205
{
206
onInit
();
207
}
208
else
209
{
210
rtComponent
->preOnFsmInit(C::_state_name());
211
rtComponent
->postOnFsmInit(C::_state_name(),
onInit
());
212
}
213
}
214
void
exit
()
override
215
{
216
setrtc
();
217
if
(
rtComponent
==
nullptr
)
218
{
219
onExit
();
220
}
221
else
222
{
223
rtComponent
->preOnFsmExit(C::_state_name());
224
rtComponent
->postOnFsmExit(C::_state_name(),
onExit
());
225
rtComponent
->preOnFsmStateChange(C::_state_name());
226
}
227
}
228
#if defined(__clang__)
229
#if defined(_WIN32) || defined(_WIN64)
230
#pragma clang diagnostic push
231
#pragma clang diagnostic ignored "-Wsuggest-override"
232
#endif
233
#pragma clang diagnostic push
234
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
235
#endif
236
#if defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__clang__)
237
#pragma GCC diagnostic push
238
#pragma GCC diagnostic ignored "-Wsuggest-override"
239
#endif
240
// We can't use 'override' insetd of 'virtual', becase these
241
// methods are used as TOP LEVEL SUPPER CLASS and SUB CLASS.
242
virtual
RTC::ReturnCode_t
onEntry
() {
return
RTC::RTC_OK; }
243
virtual
RTC::ReturnCode_t
onInit
() {
return
RTC::RTC_OK; }
244
virtual
RTC::ReturnCode_t
onExit
() {
return
RTC::RTC_OK; }
245
#if defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__clang__)
246
#pragma GCC diagnostic pop
247
#endif
248
#if defined(__clang__)
249
#pragma clang diagnostic pop
250
#if defined(_WIN32) || defined(_WIN64)
251
#pragma clang diagnostic pop
252
#endif
253
#endif
254
255
RTObject_impl
*
rtComponent
;
256
};
257
}
// namespace RTC
258
#endif
// RTC_STATICFSM_H
EventBase.h
Macho.h
RTObject.h
RT component base class
RingBuffer.h
Defautl Buffer class
Macho::Link
Definition
Macho.h:536
Macho::Machine
Definition
Macho.h:1656
Macho::Machine::Machine
Machine()
Definition
Macho.h:1676
Macho::StateID
Definition
Macho.h:626
Macho::_StateInstance
Definition
Macho.h:637
RTC::EventBase
Definition
EventBase.h:41
RTC::Link::rtComponent
RTObject_impl * rtComponent
Definition
StaticFSM.h:255
RTC::Link::onInit
virtual RTC::ReturnCode_t onInit()
Definition
StaticFSM.h:243
RTC::Link::Link
Link(Macho::_StateInstance &instance)
Definition
StaticFSM.h:171
RTC::Link::entry
void entry() override
Definition
StaticFSM.h:187
RTC::Link::init
void init() override
Definition
StaticFSM.h:201
RTC::Link::onExit
virtual RTC::ReturnCode_t onExit()
Definition
StaticFSM.h:244
RTC::Link::setrtc
void setrtc()
Definition
StaticFSM.h:177
RTC::Link::exit
void exit() override
Definition
StaticFSM.h:214
RTC::Link::LINK
Link< C, P > LINK
Definition
StaticFSM.h:185
RTC::Link::~Link
~Link() override=default
RTC::Link::onEntry
virtual RTC::ReturnCode_t onEntry()
Definition
StaticFSM.h:242
RTC::Machine
Definition
StaticFSM.h:117
RTC::Machine::~Machine
~Machine() override=default
RTC::Machine::Link
friend class Link
Definition
StaticFSM.h:144
RTC::Machine::Machine
Machine(RTC::RTObject_impl *comp)
Definition
StaticFSM.h:119
RTC::Machine::getBuffer
virtual RingBuffer< EventBase * > & getBuffer()
Definition
StaticFSM.h:124
RTC::Machine::run_event
virtual void run_event()
Definition
StaticFSM.h:128
RTC::RTObject_impl
RTコンポーネントクラス
Definition
RTObject.h:93
RTC::RingBuffer
リングバッファ実装クラス
Definition
RingBuffer.h:90
Macho
Definition
Macho.h:297
RTC
RTコンポーネント
構築:
1.17.0