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
53class RTController : public RTJob
54{
55private:
56 friend class RTMessage;
57 friend class RTProtocol;
58
59 const char * _name;
60
61#if OTRTSDEBUG != DEBUG_NONE
62 friend class RTDebugger;
63
64 RTDebugger * _debugger;
65 RTController * _prev;
66 RTController * _next;
67
68 enum
69 {
70 detached, // execution is independent of the debugger
71 execSystem, // executing in system code (between chains)
72 waitBegin, // awaiting permission to begin executing a chain
73 waitDone, // executing in system code (in a chain)
74 execUser, // executing in user code (in a chain)
75 waitContinue // awaiting permission to continue executing a chain
76 } _state;
77#endif // OTRTSDEBUG != DEBUG_NONE
78
79public:
80 RTController( RTDebugger * debug,
81 const char * name );
82 virtual ~RTController( void );
83
84 enum Primitive
85 {
86 CommDefer,
87 CommDeliver,
88 CommInvoke,
89 CommPurge,
90 CommRecall,
91 CommRecallAll,
92 CommReply,
93 CommSend,
94 ExceptionRaise,
95 FrameDeport,
96 FrameDestroy,
97 FrameImport,
98 FrameIncarnate,
99 LayerBind,
100 LayerRegisterSAP,
101 LayerDeregisterSAP,
102 LayerRegisterSPP,
103 LayerDeregisterSPP,
104 LayerResize,
105 LayerResizeSAP,
106 LayerResizeSPP,
107 TimerCancel,
108 TimerInform,
109
110 SystemService
111 };
112
113 enum Error
114 {
115 ok,
116
117 // code triggered by
118 // ==== ============
119
120 alreadyDeferred, // CommDefer
121 badActor, // FrameDeport FrameDestroy FrameImport
122 badClass, // CommDeliver CommInvoke CommReply CommSend FrameImport FrameIncarnate
123 badId, // TimerCancel
124 badIndex, // FrameIncarnate CommInvoke CommSend
125 badInterface, // FrameImport FrameIncarnate
126 badOperation, // LayerDeregister LayerRegister LayerResize{,SAP,SPP}
127 badRef, // FrameImport FrameIncarnate
128 badSignal, // CommInvoke CommReply CommSend
129 badValue, // LayerResize{,SAP,SPP}
130 deferInvoke, // CommDefer CommInvoke
131 dereg, // LayerDeregister
132 imported, // FrameDestroy FrameIncarnate
133 noConnect, // CommInvoke CommReply TimerInform
134 noFreePorts, // FrameImport
135 noMem, // all
136 noReply, // CommInvoke
137 notImported, // FrameDeport FrameImport
138 notOptional, // FrameDestroy
139 notOwner, // FrameDeport FrameDestroy FrameImport FrameIncarnate
140 prio, // CommReply CommSend TimerInform
141 protocolSignal, // FrameImport FrameIncarnate LayerBind
142 protocolType, // FrameImport FrameIncarnate LayerBind
143 recursiveInvoke, // CommInvoke
144 refFull, // FrameImport FrameIncarnate
145 reg, // LayerRegister
146 replRef, // FrameImport
147 smallInterface, // FrameImport FrameIncarnate
148 tooManySAPs, // (nothing)
149 xRtsInvoke // CommInvoke
150 };
151
152#if RTS_COMPATIBLE <= 520
153 typedef Error rtsErrors; // for backwards compatibility
154#endif
155
156 Error canPlugIn( const RTActorClass *,
157 const RTComponentDescriptor * );
158
159private:
160 Error errorNumber;
161
162public:
168 RTS_INLINE Error getError( void ) const;
169
175 const char * strerror( void ) const;
176
181 void perror( const char * s = "error" );
182
183#if OTRTSDEBUG == DEBUG_NONE
184 RTS_INLINE
185#endif
186
195 void setError( Error error,
196 Primitive primitive,
197 const void * info,
198 const void * detail);
199
200#if OTRTSDEBUG < DEBUG_VERBOSE
201 RTS_INLINE
202#endif
203 void trace( Primitive, const void *, const void * );
204#if OBSERVABLE
205 void breakPoint( RTActor *, RTEventInfo * );
206 void evtMsgQueue( void );
207
211 void getMessages( const RTDaemonInfo & daemonInfo );
212#endif
213
218 virtual const char * name( void ) const override;
219
224 virtual void kill( void ) override;
225
229 virtual void printStats( void ) const;
230
234 void abort( void );
235
239 RTS_INLINE RTDebugger * debugger( void );
240
241 void destroy( RTActor * actor, RTActor * owner );
242
243 int send( RTActor * receiver,
244 int controlSignal,
245 const void * data,
246 const RTObject_class * type,
247 int priority );
248
249 RTS_INLINE void receive( RTMessage *, RTController * sender );
250
251 // Receive a copy of the message
252 RTS_INLINE int receiveMsgCopy(const RTMessage*, RTController * sender);
253
254#if USE_THREADS
255 void peer_receive( RTMessage * );
256#endif
257
258 void requeueMsg( RTMessage *, int front );
259
260 RTS_INLINE RTMessage * newMsg( void );
261 RTS_INLINE void freeMsg( RTMessage * );
262
263 RTTimerNode * newTimerNode( void );
264 void freeTimerNode( RTTimerNode * node );
265
266protected:
267 // public to implementation
268
269 // values returned by dispatch
270 enum
271 {
272 OneDelivered,
273#if OTRTSDEBUG != DEBUG_NONE
274 PermissionDenied,
275#endif
276 NoneToDeliver
277 };
278
279 int dispatch( int priorityLimit );
280 void awaitResponse( void );
281 virtual void waitForEvents( void ) = 0;
282#if USE_THREADS
283 virtual void wakeup( void );
284#endif
285
286#if USE_THREADS
287 RTSyncObject * _sync;
288#endif
289
290private:
291 static const unsigned char topPriority[ 1 << OTRTS_NUMPRIO ];
292
293 RTMessageQ internalQ[ OTRTS_NUMPRIO ];
294
295#if USE_THREADS
296 RTMessageQ incomingQ[ OTRTS_NUMPRIO ];
297#endif
298
299 short internalBits;
300#if USE_THREADS
301 short incomingBits;
302#endif
303
304 RTMessage * freeList;
305 unsigned freeListSize;
306
307 RTTimerNode * freeTimerList;
308 unsigned freeTimerListSize;
309
310 // invoke reply messages are stored here
311 RTMessage * replyBuffer;
312
313#if ! DEFER_IN_ACTOR
314 RTMessageQ deferredQ; // Deferred Messages Queue
315#endif
316
317 void filterMessages( RTActor * receiver, RTQFilter & );
318#if USE_THREADS
319 void acceptIncoming( void );
320#endif
321
322 static RTResourceMgr resourceMgr;
323
324public:
325 RTS_INLINE RTMessage * getReplyBuffer( void );
326 RTS_INLINE RTMessage * setReplyBuffer( RTMessage * );
327 RTS_INLINE void restoreReplyBuffer( RTMessage * );
328
329#if RTS_COUNT
330 void countActorDestroy ( void );
331 void countActorIncarnate ( void );
332 void countMessageTransfer( RTMessage * );
333 void countPortDestroy ( int );
334 void countPortIncarnate ( int );
335 void countTimerCancel ( void );
336 void countTimerExpire ( void );
337 void countTimerStart ( void );
338
339protected:
340 RTCounts counts;
341#else
342 RTS_INLINE void countActorDestroy ( void );
343 RTS_INLINE void countActorIncarnate ( void );
344 RTS_INLINE void countMessageTransfer( RTMessage * );
345 RTS_INLINE void countPortDestroy ( int );
346 RTS_INLINE void countPortIncarnate ( int );
347 RTS_INLINE void countTimerCancel ( void );
348 RTS_INLINE void countTimerExpire ( void );
349 RTS_INLINE void countTimerStart ( void );
350#endif
351
352private:
353 // unavailable methods
354 RTController( const RTController & );
355 RTController & operator=( const RTController & );
356}; //lint !e1712
357
358#if RTS_INLINES
359#include <RTController.inl>
360#endif
361
362#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:54
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 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