CARMA C++
ClockMaster.h
Go to the documentation of this file.
1 
9 #ifndef CARMA_CLOCK_CLOCKMASTER_H
10 #define CARMA_CLOCK_CLOCKMASTER_H
11 
12 // Carma includes
13 #include "carma/corba/corba.h"
14 #include "carma/canbus/Master.h"
15 #include "carma/clock/Clock.h"
16 #include "carma/util/UserException.h"
17 
18 #include <memory>
19 #include <pthread.h>
20 
21 namespace carma {
22 namespace clock {
23 
32  public:
33 
45  ClockMaster( bool enableAutowriter,
46  double autoWriteDelayInS );
47 
57  ClockMaster( int modulBusNo,
58  int slotNo,
59  double autoWriteDelayInS );
60 
68  ClockMaster( int modulBusNo,
69  double autoWriteDelayInS );
70 
74  virtual ~ClockMaster();
75 
81  bool isDone();
82 
83  // Control routines (see IDL for documentation).
84  carma::clock::ClockControl_ptr GlobalClock();
85  carma::clock::ClockControl_ptr Clock();
86  void reset();
87  void softReset();
88  void quit();
89 
90  protected:
91 
101  void updateStatus();
102 
103  private:
104 
105  // Copying and assignment are not allowed
106  ClockMaster(const ClockMaster &);
107  ClockMaster &operator=(const ClockMaster &);
108 
109  // Helper routines to consolidate initialization among 3 constructors.
110  void initialize();
111  void addDevices();
112 
113  // Consolidate removal of devices - used on destruction.
114  void removeDevices();
115 
116  // Run thread entry point. Entry points are needed in order to assure
117  // that the actual run method is not subject to the c-style linkage
118  // rules (static) that are required of the pthread entry point.
119  static void *runThreadEntry(void *arg);
120 
121  // Redefine run such that it is private. Since the carmaClockHost app
122  // is a CORBA server, it will block on runOrb - thus we call run in
123  // a seperate thread in the ClockMaster constructor to get the CANbus
124  // side of things moving independently.
125  void run();
126 
127  // Keep the run thread id around so that we can properly destroy the
128  // thread upon destruction.
129  pthread_t runThreadId_;
130 
131  // Node 0 'Global control' device objects. (Aren't added to Master
132  // device map via addDevice).
133  std::auto_ptr< carma::clock::Clock > clock_;
134  std::auto_ptr< carma::clock::Clock > globalClock_;
135 
136  carma::clock::ClockControl_ptr clockControlPtr_;
137  carma::clock::ClockControl_ptr globalClockControlPtr_;
138 
139  std::string hostname_;
140  std::auto_ptr< carma::monitor::MasterClockSubsystem > mon_;
141 
142  // Are we emulating the underlying Janz hardware?
143  const bool emulate_;
144 
145  // DEBUG
146  pthread_mutex_t doneMutex_;
147  bool done_;
148 
149  }; // End ClockMaster class
150 }; // End clock namespace
151 }; // End carma namespace
152 #endif
Carma Master Clock CAN Master class.
Definition: ClockMaster.h:31
void updateStatus()
Update the status of the Clock CAN Master.
Declaration of carma::canbus::Master class.
virtual ~ClockMaster()
Destructor.
ClockMaster(bool enableAutowriter, double autoWriteDelayInS)
Default constructor for emulation.
bool isDone()
Query to see if the System::quit() method has been invoked.
Carma Canbus Master class.
Definition: Master.h:110
The Clock class is an instantiation of the carma::canbus::Device class for the Master Clock...
Definition: Clock.h:41