LRAUV  revA
PCaller.h
Go to the documentation of this file.
1 
9 #ifndef PCALLER_H_
10 #define PCALLER_H_
11 
12 #include <pthread.h>
13 #include <signal.h>
14 
15 #include "component/Behavior.h"
16 #include "logger/Logger.h"
17 #include "utils/FlexArray.h"
18 #include "utils/Mutex.h"
19 
28 class PCaller
29 {
30 public:
31 
32  PCaller( bool idleThread, Logger & logger );
33 
34  virtual ~PCaller();
35 
36  typedef enum
37  {
46 
47  bool pInitialize( Component & component )
48  {
49  return pCall( component, BLOCK_INITIALIZE, NULL );
50  }
51 
52  bool pExecute( Component & component )
53  {
54  return pCall( component, BLOCK_EXECUTE, NULL );
55  }
56 
57  bool pExecuteIfUnsatisfied( Behavior & component, bool & satisfied )
58  {
59  return pCall( component, BLOCK_EXECUTE_IF_UNSATISFIED, &satisfied );
60  }
61 
62  bool pUninitialize( Component & component )
63  {
64  return pCall( component, BLOCK_UNINITIALIZE, NULL );
65  }
66 
67 private:
69  {
72  bool *returnValue_;
73  };
74  bool startThread();
75  void stopThread();
76  bool pCall( Component & component, PCallOperationType operation, bool *returnValue );
77  static void ShowInfo( Component* component, int signal, int errno, int code, size_t addr, size_t backtraceCount, char **backtraceStrings );
78  void containedWait();
79  void ownerWait();
80  void yieldToContained();
81  void yieldToOwner();
82  static const char *PCallOperationToChars( const PCallOperationType operation );
83  static void *PThreadRun( void *pCaller );
88  pthread_t containedThread_;
89  pthread_t ownerThread_;
90  pthread_t runningThread_;
93  pthread_attr_t threadAttributes_;
96  bool idle_;
98  {
99  public:
100  Initializer();
101  };
103  static void RegisterDefaultSignals( void );
104  static void DefaultSignalHandler( int signal, siginfo_t *sigIngo, void *context );
105  static const char *SignalMessage( int signal, int code );
107 
108 private:
109  // Note that the copy constructor below is private and not given a body.
110  // Any attempt to call it will return a compiler error.
111  PCaller( const PCaller& old ); // disallow copy constructor
112 
113 };
114 
115 #endif /*PCALLER_H_*/
Client-side interface for injecting log data into the log queue.
Definition: Logger.h:30
Component * currentComponent_
Definition: PCaller.h:91
bool threadRunning_
Definition: PCaller.h:94
void containedWait()
The entry point for the protected thread.
Definition: PCaller.cpp:261
virtual ~PCaller()
Destructor.
Definition: PCaller.cpp:118
pthread_t containedThread_
Definition: PCaller.h:88
void stopThread()
Definition: PCaller.cpp:105
Logger & logger_
Definition: PCaller.h:84
void ownerWait()
Wait for another thread to activate this thread.
Definition: PCaller.cpp:242
Definition: PCaller.h:68
Definition: PCaller.h:40
Definition: PCaller.h:39
ThreadCondition threadCondition_
Definition: PCaller.h:87
A simple pthread Mutex abstraction.
Definition: Mutex.h:20
void yieldToOwner()
Just yield execution to the waiting owner thread.
Definition: PCaller.cpp:295
Behavior is the abstract base class for components that implement mission behaviors and commands...
Definition: Behavior.h:32
static void ShowInfo(Component *component, int signal, int errno, int code, size_t addr, size_t backtraceCount, char **backtraceStrings)
Definition: PCaller.cpp:203
PCaller(bool idleThread, Logger &logger)
Constructor.
Definition: PCaller.cpp:36
Mutex threadConditionMutex_
Definition: PCaller.h:86
Mutex pCallMutex_
Definition: PCaller.h:85
pthread_t ownerThread_
Definition: PCaller.h:89
Contains the FlexArrayBase and FlexArray class declarations.
Contains the Behavior class definition.
Component * component_
Definition: PCaller.h:70
bool * returnValue_
Definition: PCaller.h:72
PCallOperation currentOperation_
Definition: PCaller.h:92
static void * PThreadRun(void *pCaller)
Definition: PCaller.cpp:333
Definition: PCaller.h:97
Definition: PCaller.h:44
static const char * PCallOperationToChars(const PCallOperationType operation)
Definition: PCaller.cpp:310
bool threadDone_
Definition: PCaller.h:95
Definition: PCaller.h:38
Initializer()
The actual static intialization code Sets up signal handling.
Definition: PCaller.cpp:28
Abstract Base class for software components.
Definition: Component.h:53
static void RegisterDefaultSignals(void)
Definition: PCaller.cpp:394
bool idle_
Definition: PCaller.h:96
bool pExecute(Component &component)
Definition: PCaller.h:52
static FlexArray< PCaller * > PCallers_
Definition: PCaller.h:106
Contains the Mutex, ThreadCondition, and MutexLocker class declarations.
bool pInitialize(Component &component)
Definition: PCaller.h:47
bool pExecuteIfUnsatisfied(Behavior &component, bool &satisfied)
Definition: PCaller.h:57
static void DefaultSignalHandler(int signal, siginfo_t *sigIngo, void *context)
Definition: PCaller.cpp:428
Contains the Logger class definition.
pthread_attr_t threadAttributes_
Definition: PCaller.h:93
bool startThread()
Definition: PCaller.cpp:68
static const char * SignalMessage(int signal, int code)
Definition: PCaller.cpp:465
void yieldToContained()
Just yield execution to the waiting contained thread.
Definition: PCaller.cpp:279
PCallOperationType
Definition: PCaller.h:36
bool pUninitialize(Component &component)
Definition: PCaller.h:62
A simple pthread thread condition wrapper.
Definition: Mutex.h:53
bool pCall(Component &component, PCallOperationType operation, bool *returnValue)
Executes the specified method of this component with signal catching Returns true on normal run termi...
Definition: PCaller.cpp:140
Definition: PCaller.h:42
PCallOperationType operation_
Definition: PCaller.h:71
pthread_t runningThread_
Definition: PCaller.h:90
Protected Caller.
Definition: PCaller.h:28
Definition: PCaller.h:43
static Initializer Initializer_
Runs static intialization code.
Definition: PCaller.h:102