Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
sim.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_sim_h_ 00003 #define INCLUDED_sim_h_ 00004 00005 #include "Events/EventTranslator.h" 00006 #include "IPC/MessageQueue.h" 00007 #include "SharedGlobals.h" 00008 #include "IPC/SharedObject.h" 00009 #include "IPC/Thread.h" 00010 #include "Wireless/Wireless.h" 00011 #include "Shared/ProjectInterface.h" 00012 #include <vector> 00013 #include <termios.h> 00014 class SimConfig; 00015 00016 class sim { 00017 template<typename T> friend struct PrimaryThread; 00018 friend int main(int argc, const char* argv[]); 00019 public: 00020 sim(); 00021 bool processCommandLine(int argc, const char* argv[]); 00022 bool run(); 00023 ~sim(); 00024 00025 typedef MessageQueue<500> EventQueue_t; 00026 typedef MessageQueue<50> MotionCommandQueue_t; 00027 typedef MessageQueue<50> SoundPlayQueue_t; 00028 typedef MessageQueue<1> CameraQueue_t; 00029 typedef MessageQueue<1> SensorQueue_t; 00030 typedef MessageQueue<1> TimerWakeup_t; 00031 typedef MessageQueue<1> MotionWakeup_t; 00032 typedef MessageQueue<ProcessID::NumProcesses+1> StatusRequest_t; 00033 typedef MessageQueue<1> MotionOutput_t; 00034 typedef MessageQueue<50> MotionOutputPIDs_t; 00035 00036 static SimConfig config; 00037 static IPCEventTranslator * etrans; 00038 static std::vector<std::string> cmdlineArgs; 00039 00040 protected: 00041 static unsigned int measure_usleep_cost(); 00042 void wait_child(); 00043 static void wait_runlevel(SharedGlobals::runlevel_t level); 00044 template<class T> static void manage_process(); 00045 template<class T> static bool fork_process(); 00046 00047 static ProcessID::ProcessID_t getProcessID(); //!< ProcessID hook to use the thread group as the process ID 00048 static void setProcessID(ProcessID::ProcessID_t id); //!< ProcessID hook to set the thread group as the process ID 00049 00050 static std::vector<Thread*> primaries; 00051 00052 //! provides warning regarding configuration settings 00053 class ConfigErrorCheck : public plist::PrimitiveListener { 00054 public: 00055 ConfigErrorCheck(); 00056 ~ConfigErrorCheck(); 00057 virtual void plistValueChanged(const plist::PrimitiveBase& pl); 00058 void holdMultiprocess(); 00059 protected: 00060 bool holdMPValue; 00061 }; 00062 static ConfigErrorCheck cfgCheck; 00063 00064 static unsigned int sim_get_time() { return globals?globals->get_time():0; } 00065 static float sim_getTimeScale() { return globals?globals->getTimeScale():0; } 00066 00067 static int getTermFD(); 00068 static void handle_signal(int sig); 00069 static void handle_exit(); 00070 static void badExitCleanup(); 00071 00072 SharedObject<SemaphoreManager> mutexSemMgr; 00073 SharedObject<SharedGlobals> glob; 00074 SharedObject<ipc_setup_t> subj; 00075 static bool original; 00076 static const char * const usage; 00077 static pid_t child; 00078 static bool showRunlevels; 00079 static termios ttyMode; 00080 unsigned int srandSeed; 00081 int zigSeed1; 00082 int zigSeed2; 00083 }; 00084 00085 class WirelessThread : public Thread { 00086 public: 00087 //! constructor 00088 WirelessThread() : Thread() {} 00089 //! destructor -- stop thread 00090 virtual ~WirelessThread() { 00091 if(isStarted()) { 00092 stop(); 00093 join(); 00094 } 00095 } 00096 virtual unsigned int runloop() { 00097 // initial setup done by wireless's own constructor 00098 wireless->pollTest(NULL); // by passing NULL, we wait indefinitely, so no need to usleep in the Thread code 00099 wireless->pollProcess(); 00100 wireless->pollSetup(); // reinitialize for next test 00101 return 0; //no sleep time because pollTest blocks 00102 } 00103 virtual Thread& stop() { 00104 Thread::stop(); 00105 wireless->wakeup(); 00106 return *this; 00107 } 00108 }; 00109 00110 00111 /*! @file 00112 * @brief 00113 * @author ejt (Creator) 00114 */ 00115 00116 #endif |
Tekkotsu Hardware Abstraction Layer 5.1CVS |
Generated Mon May 9 05:01:39 2016 by Doxygen 1.6.3 |