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 circularImport // FrameImport circularImport
154 };
155
156#if RTS_COMPATIBLE <= 520
157 typedef Error rtsErrors; // for backwards compatibility
158#endif
159
160 Error canPlugIn( const RTActorClass *,
161 const RTComponentDescriptor * );
162
163private:
164 Error errorNumber;
165
166public:
172 RTS_INLINE Error getError( void ) const;
173
179 const char * strerror( void ) const;
180
185 void perror( const char * s = "error" );
186
187#if OTRTSDEBUG == DEBUG_NONE
188 RTS_INLINE
189#endif
190
199 void setError( Error error,
200 Primitive primitive,
201 const void * info,
202 const void * detail);
203
204#if OTRTSDEBUG < DEBUG_VERBOSE
205 RTS_INLINE
206#endif
207 void trace( Primitive, const void *, const void * );
208#if OBSERVABLE
209 void breakPoint( RTActor *, RTEventInfo * );
210 void evtMsgQueue( void );
211
215 void getMessages( const RTDaemonInfo & daemonInfo );
216#endif
217
222 virtual const char * name( void ) const override;
223
228 virtual void kill( void ) override;
229
233 virtual void printStats( void ) const;
234
238 void abort( void );
239
243 RTS_INLINE RTDebugger * debugger( void );
244
245 void destroy( RTActor * actor, RTActor * owner );
246
247 int send( RTActor * receiver,
248 int controlSignal,
249 const void * data,
250 const RTObject_class * type,
251 int priority );
252
253 RTS_INLINE void receive( RTMessage *, RTController * sender );
254
255 // Receive a copy of the message
256 RTS_INLINE int receiveMsgCopy(const RTMessage*, RTController * sender);
257
258#if USE_THREADS
259 void peer_receive( RTMessage * );
260#endif
261
262 void requeueMsg( RTMessage *, int front );
263
264 RTS_INLINE RTMessage * newMsg( void );
265 RTS_INLINE void freeMsg( RTMessage * );
266
267 RTTimerNode * newTimerNode( void );
268 void freeTimerNode( RTTimerNode * node );
269
270protected:
271 // public to implementation
272
273 // values returned by dispatch
274 enum
275 {
276 OneDelivered,
277#if OTRTSDEBUG != DEBUG_NONE
278 PermissionDenied,
279#endif
280 NoneToDeliver
281 };
282
283 int dispatch( int priorityLimit );
284 void awaitResponse( void );
285 virtual void waitForEvents( void ) = 0;
286#if USE_THREADS
287 virtual void wakeup( void );
288#endif
289
290#if USE_THREADS
291 RTSyncObject * _sync;
292#endif
293
294private:
295 static const unsigned char topPriority[ 1 << OTRTS_NUMPRIO ];
296
297 RTMessageQ internalQ[ OTRTS_NUMPRIO ];
298
299#if USE_THREADS
300 RTMessageQ incomingQ[ OTRTS_NUMPRIO ];
301#endif
302
303 short internalBits;
304#if USE_THREADS
305 short incomingBits;
306#endif
307
308 RTMessage * freeList;
309 unsigned freeListSize;
310
311 RTTimerNode * freeTimerList;
312 unsigned freeTimerListSize;
313
314 // invoke reply messages are stored here
315 RTMessage * replyBuffer;
316
317#if ! DEFER_IN_ACTOR
318 RTMessageQ deferredQ; // Deferred Messages Queue
319#endif
320
321 void filterMessages( RTActor * receiver, RTQFilter & );
322#if USE_THREADS
323 void acceptIncoming( void );
324#endif
325
326 static RTResourceMgr resourceMgr;
327
328public:
329 RTS_INLINE RTMessage * getReplyBuffer( void );
330 RTS_INLINE RTMessage * setReplyBuffer( RTMessage * );
331 RTS_INLINE void restoreReplyBuffer( RTMessage * );
336 virtual void registerLayer( RTActor * , RTActorFunction,
337 RTActorFunction, RTActorFunction );
338
339#if RTS_COUNT
340 void countActorDestroy ( void );
341 void countActorIncarnate ( void );
342 void countMessageTransfer( RTMessage * );
343 void countPortDestroy ( int );
344 void countPortIncarnate ( int );
345 void countTimerCancel ( void );
346 void countTimerExpire ( void );
347 void countTimerStart ( void );
348
349protected:
350 RTCounts counts;
351#else
352 RTS_INLINE void countActorDestroy ( void );
353 RTS_INLINE void countActorIncarnate ( void );
354 RTS_INLINE void countMessageTransfer( RTMessage * );
355 RTS_INLINE void countPortDestroy ( int );
356 RTS_INLINE void countPortIncarnate ( int );
357 RTS_INLINE void countTimerCancel ( void );
358 RTS_INLINE void countTimerExpire ( void );
359 RTS_INLINE void countTimerStart ( void );
360#endif
361
362private:
363 // unavailable methods
364 RTController( const RTController & );
365 RTController & operator=( const RTController & );
366}; //lint !e1712
367
368#if RTS_INLINES
369#include <RTController.inl>
370#endif
371
372#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