C++ TargetRTS
Loading...
Searching...
No Matches
RTController.h
1/*
2 * Licensed Materials - Property of HCL and/or IBM
3 * Copyright HCL Technologies Ltd. 2016, 2021. All Rights Reserved.
4 * Copyright IBM Corporation 1999, 2016. All Rights Reserved.
5 *
6 * U.S. Government Users Restricted Rights - Use, duplication or
7 * disclosure restricted by GSA ADP Schedule.
8 */
9
10#ifndef __RTController_h__
11#define __RTController_h__ included
12
13#ifdef PRAGMA
14#pragma interface
15#endif
16
17#ifndef __RTJob_h__
18#include <RTJob.h>
19#endif
20
21#ifndef __RTMessageQ_h__
22#include <RTMessageQ.h>
23#endif
24
25#ifndef __RTPriority_h__
26#include <RTPriority.h>
27#endif
28
29#ifndef __RTResourceMgr_h__
30#include <RTResourceMgr.h>
31#endif
32
33#if RTS_COUNT && ! defined( __RTCounts_h__ )
34#include <RTCounts.h>
35#endif
36
37class RTActor;
38struct RTActorClass;
40class RTDaemonInfo;
41class RTDebugger;
42class RTEventInfo;
43class RTSyncObject;
44class RTTimerNode;
45
46typedef void ( RTActor:: * RTActorFunction )( void );
47
55class RTController : public RTJob
56{
57private:
58 friend class RTMessage;
59 friend class RTProtocol;
60
61 const char * _name;
62
63#if OTRTSDEBUG != DEBUG_NONE
64 friend class RTDebugger;
65
66 RTDebugger * _debugger;
67 RTController * _prev;
68 RTController * _next;
69
70 enum
71 {
72 detached, // execution is independent of the debugger
73 execSystem, // executing in system code (between chains)
74 waitBegin, // awaiting permission to begin executing a chain
75 waitDone, // executing in system code (in a chain)
76 execUser, // executing in user code (in a chain)
77 waitContinue // awaiting permission to continue executing a chain
78 } _state;
79#endif // OTRTSDEBUG != DEBUG_NONE
80
81public:
82 RTController( RTDebugger * debug,
83 const char * name );
84 virtual ~RTController( void );
85
86 enum Primitive
87 {
88 CommDefer,
89 CommDeliver,
90 CommInvoke,
91 CommPurge,
92 CommRecall,
93 CommRecallAll,
94 CommReply,
95 CommSend,
96 ExceptionRaise,
97 FrameDeport,
98 FrameDestroy,
99 FrameImport,
100 FrameIncarnate,
101 LayerBind,
102 LayerRegisterSAP,
103 LayerDeregisterSAP,
104 LayerRegisterSPP,
105 LayerDeregisterSPP,
106 LayerResize,
107 LayerResizeSAP,
108 LayerResizeSPP,
109 RegisterLayer,
110 TimerCancel,
111 TimerInform,
112
113 SystemService
114 };
115
116 enum Error
117 {
118 ok,
119
120 // code triggered by
121 // ==== ============
122
123 alreadyDeferred, // CommDefer
124 badActor, // FrameDeport FrameDestroy FrameImport
125 badClass, // CommDeliver CommInvoke CommReply CommSend FrameImport FrameIncarnate
126 badId, // TimerCancel
127 badIndex, // FrameIncarnate CommInvoke CommSend
128 badInterface, // FrameImport FrameIncarnate
129 badOperation, // LayerDeregister LayerRegister, RegisterLayer, LayerResize{,SAP,SPP}
130 badRef, // FrameImport FrameIncarnate
131 badSignal, // CommInvoke CommReply CommSend
132 badValue, // LayerResize{,SAP,SPP}
133 deferInvoke, // CommDefer CommInvoke
134 dereg, // LayerDeregister
135 imported, // FrameDestroy FrameIncarnate
136 noConnect, // CommInvoke CommReply TimerInform
137 noFreePorts, // FrameImport
138 noMem, // all
139 noReply, // CommInvoke
140 notImported, // FrameDeport FrameImport
141 notOptional, // FrameDestroy
142 notOwner, // FrameDeport FrameDestroy FrameImport FrameIncarnate
143 prio, // CommReply CommSend TimerInform
144 protocolSignal, // FrameImport FrameIncarnate LayerBind
145 protocolType, // FrameImport FrameIncarnate LayerBind
146 recursiveInvoke, // CommInvoke
147 refFull, // FrameImport FrameIncarnate
148 reg, // LayerRegister
149 replRef, // FrameImport
150 smallInterface, // FrameImport FrameIncarnate
151 tooManySAPs, // (nothing)
152 xRtsInvoke // CommInvoke
153 };
154
155#if RTS_COMPATIBLE <= 520
156 typedef Error rtsErrors; // for backwards compatibility
157#endif
158
159 Error canPlugIn( const RTActorClass *,
160 const RTComponentDescriptor * );
161
162private:
163 Error errorNumber;
164
165public:
171 RTS_INLINE Error getError( void ) const;
172
178 const char * strerror( void ) const;
179
184 void perror( const char * s = "error" );
185
186#if OTRTSDEBUG == DEBUG_NONE
187 RTS_INLINE
188#endif
189
198 void setError( Error error,
199 Primitive primitive,
200 const void * info,
201 const void * detail);
202
203#if OTRTSDEBUG < DEBUG_VERBOSE
204 RTS_INLINE
205#endif
206 void trace( Primitive, const void *, const void * );
207#if OBSERVABLE
208 void breakPoint( RTActor *, RTEventInfo * );
209 void evtMsgQueue( void );
210
214 void getMessages( const RTDaemonInfo & daemonInfo );
215#endif
216
221 virtual const char * name( void ) const override;
222
227 virtual void kill( void ) override;
228
232 virtual void printStats( void ) const;
233
237 void abort( void );
238
242 RTS_INLINE RTDebugger * debugger( void );
243
244 void destroy( RTActor * actor, RTActor * owner );
245
246 int send( RTActor * receiver,
247 int controlSignal,
248 const void * data,
249 const RTObject_class * type,
250 int priority );
251
252 RTS_INLINE void receive( RTMessage *, RTController * sender );
253
254 // Receive a copy of the message
255 RTS_INLINE int receiveMsgCopy(const RTMessage*, RTController * sender);
256
257#if USE_THREADS
258 void peer_receive( RTMessage * );
259#endif
260
261 void requeueMsg( RTMessage *, int front );
262
263 RTS_INLINE RTMessage * newMsg( void );
264 RTS_INLINE void freeMsg( RTMessage * );
265
266 RTTimerNode * newTimerNode( void );
267 void freeTimerNode( RTTimerNode * node );
268
269protected:
270 // public to implementation
271
272 // values returned by dispatch
273 enum
274 {
275 OneDelivered,
276#if OTRTSDEBUG != DEBUG_NONE
277 PermissionDenied,
278#endif
279 NoneToDeliver
280 };
281
282 int dispatch( int priorityLimit );
283 void awaitResponse( void );
284 virtual void waitForEvents( void ) = 0;
285#if USE_THREADS
286 virtual void wakeup( void );
287#endif
288
289#if USE_THREADS
290 RTSyncObject * _sync;
291#endif
292
293private:
294 static const unsigned char topPriority[ 1 << OTRTS_NUMPRIO ];
295
296 RTMessageQ internalQ[ OTRTS_NUMPRIO ];
297
298#if USE_THREADS
299 RTMessageQ incomingQ[ OTRTS_NUMPRIO ];
300#endif
301
302 short internalBits;
303#if USE_THREADS
304 short incomingBits;
305#endif
306
307 RTMessage * freeList;
308 unsigned freeListSize;
309
310 RTTimerNode * freeTimerList;
311 unsigned freeTimerListSize;
312
313 // invoke reply messages are stored here
314 RTMessage * replyBuffer;
315
316#if ! DEFER_IN_ACTOR
317 RTMessageQ deferredQ; // Deferred Messages Queue
318#endif
319
320 void filterMessages( RTActor * receiver, RTQFilter & );
321#if USE_THREADS
322 void acceptIncoming( void );
323#endif
324
325 static RTResourceMgr resourceMgr;
326
327public:
328 RTS_INLINE RTMessage * getReplyBuffer( void );
329 RTS_INLINE RTMessage * setReplyBuffer( RTMessage * );
330 RTS_INLINE void restoreReplyBuffer( RTMessage * );
335 virtual void registerLayer( RTActor * , RTActorFunction,
336 RTActorFunction, RTActorFunction );
337
338#if RTS_COUNT
339 void countActorDestroy ( void );
340 void countActorIncarnate ( void );
341 void countMessageTransfer( RTMessage * );
342 void countPortDestroy ( int );
343 void countPortIncarnate ( int );
344 void countTimerCancel ( void );
345 void countTimerExpire ( void );
346 void countTimerStart ( void );
347
348protected:
349 RTCounts counts;
350#else
351 RTS_INLINE void countActorDestroy ( void );
352 RTS_INLINE void countActorIncarnate ( void );
353 RTS_INLINE void countMessageTransfer( RTMessage * );
354 RTS_INLINE void countPortDestroy ( int );
355 RTS_INLINE void countPortIncarnate ( int );
356 RTS_INLINE void countTimerCancel ( void );
357 RTS_INLINE void countTimerExpire ( void );
358 RTS_INLINE void countTimerStart ( void );
359#endif
360
361private:
362 // unavailable methods
363 RTController( const RTController & );
364 RTController & operator=( const RTController & );
365}; //lint !e1712
366
367#if RTS_INLINES
368#include <RTController.inl>
369#endif
370
371#endif // __RTController_h__
An instance of this class represents a capsule instance.
Definition: RTActor.h:44
A controller manages a group of capsule instances that all run in the same physical thread (i....
Definition: RTController.h:56
void setError(Error error, Primitive primitive, const void *info, const void *detail)
Set the most recent error for the controller's thread.
virtual void kill(void) override
Kill this controller.
void abort(void)
Abort the application.
virtual void registerLayer(RTActor *, RTActorFunction, RTActorFunction, RTActorFunction)
Register a custom actor object (i.e.
virtual const char * name(void) const override
Get the name of the controller, which is the name of its physical thread (as defined in the transform...
const char * strerror(void) const
Get an error message for the most recent error that occurred in the controller's thread.
virtual void printStats(void) const
Print various statistics to stdout about what has happened in the RT application (e....
RTDebugger * debugger(void)
Get the debugger associated with this controller, if any.
Definition: RTController.inl:50
void getMessages(const RTDaemonInfo &daemonInfo)
Report all incoming messages satisfying actorPath in daemonInfo.
Error getError(void) const
Get the most recent error that occurred in the controller's thread.
Definition: RTController.inl:29
void perror(const char *s="error")
Print an error message to stderr.
Definition: RTCounts.h:22
Definition: RTDaemonInfo.h:24
Definition: RTDebugger.h:58
Definition: RTEventInfo.h:26
An object associated with a thread which captures its current state and implements its behavior.
Definition: RTJob.h:43
Represents a message used for communication between capsule instances.
Definition: RTMessage.h:33
Represents a message queue.
Definition: RTMessageQ.h:27
Represents a general capsule port typed by a protocol which determines the set of events that can be ...
Definition: RTProtocol.h:50
Definition: RTQFilter.h:24
Definition: RTResourceMgr.h:28
Definition: RTTimerNode.h:47
A type descriptor providing information about the external characteristics of a capsule.
Definition: RTActorClass.h:36
This structure describes a capsule part (a.k.a.
Definition: RTComponentDescriptor.h:33
A type descriptor providing information about a type.
Definition: RTObject_class.h:64