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 class SimConfig; 00014 00015 class sim { 00016 friend int main(int argc, const char* argv[]); 00017 public: 00018 sim(); 00019 bool processCommandLine(int argc, const char* argv[]); 00020 bool run(); 00021 ~sim(); 00022 00023 typedef MessageQueue<50> EventQueue_t; 00024 typedef MessageQueue<50> MotionCommandQueue_t; 00025 typedef MessageQueue<50> SoundPlayQueue_t; 00026 typedef MessageQueue<1> CameraQueue_t; 00027 typedef MessageQueue<1> SensorQueue_t; 00028 typedef MessageQueue<1> TimerWakeup_t; 00029 typedef MessageQueue<1> MotionWakeup_t; 00030 typedef MessageQueue<ProcessID::NumProcesses+1> StatusRequest_t; 00031 typedef MessageQueue<1> MotionOutput_t; 00032 00033 static SimConfig config; 00034 static IPCEventTranslator * etrans; 00035 static std::vector<std::string> cmdlineArgs; 00036 00037 protected: 00038 static unsigned int measure_usleep_cost(); 00039 static void wait_runlevel(SharedGlobals::runlevel_t level); 00040 template<class T> static void manage_process(); 00041 template<class T> static bool fork_process(); 00042 00043 static ProcessID::ProcessID_t getProcessID(); //!< ProcessID hook to use the thread group as the process ID 00044 static void setProcessID(ProcessID::ProcessID_t id); //!< ProcessID hook to set the thread group as the process ID 00045 00046 //! a wrapper for one of the 'major' processes, which would otherwise be forked as its own process if SimConfig::multiprocess was true 00047 template<typename T> 00048 class PrimaryThread : public Thread { 00049 public: 00050 PrimaryThread() : Thread() {} 00051 virtual void* run() { sim::manage_process<T>(); return NULL; } 00052 }; 00053 static std::vector<Thread*> primaries; 00054 00055 //! provides warning regarding configuration settings 00056 class ConfigErrorCheck : public plist::PrimitiveListener { 00057 public: 00058 ConfigErrorCheck(); 00059 ~ConfigErrorCheck(); 00060 virtual void plistValueChanged(const plist::PrimitiveBase& pl); 00061 void holdMultiprocess(); 00062 protected: 00063 bool holdMPValue; 00064 }; 00065 static ConfigErrorCheck cfgCheck; 00066 00067 static unsigned int sim_get_time() { return globals?globals->get_time():0; } 00068 static float sim_getTimeScale() { return globals?globals->getTimeScale():0; } 00069 00070 static void handle_signal(int sig); 00071 static void handle_exit(); 00072 00073 SharedObject<SemaphoreManager> mutexSemMgr; 00074 SharedObject<SharedGlobals> glob; 00075 SharedObject<ipc_setup_t> subj; 00076 static bool original; 00077 static const char * const usage; 00078 static pid_t child; 00079 }; 00080 00081 class WirelessThread : public Thread { 00082 public: 00083 //! constructor 00084 WirelessThread() : Thread() {} 00085 //! destructor -- stop thread 00086 virtual ~WirelessThread() { 00087 if(isStarted()) { 00088 stop(); 00089 join(); 00090 } 00091 } 00092 virtual unsigned int runloop() { 00093 // initial setup done by wireless's own constructor 00094 wireless->pollTest(NULL); // by passing NULL, we wait indefinitely, so no need to usleep in the Thread code 00095 wireless->pollProcess(); 00096 wireless->pollSetup(); // reinitialize for next test 00097 return 0; //no sleep time because pollTest blocks 00098 } 00099 virtual void stop() { 00100 Thread::stop(); 00101 wireless->wakeup(); 00102 } 00103 }; 00104 00105 00106 /*! @file 00107 * @brief 00108 * @author ejt (Creator) 00109 * 00110 * $Author: ejt $ 00111 * $Name: tekkotsu-4_0 $ 00112 * $Revision: 1.2 $ 00113 * $State: Exp $ 00114 * $Date: 2007/10/12 16:55:05 $ 00115 */ 00116 00117 #endif |
Tekkotsu Hardware Abstraction Layer 4.0 |
Generated Thu Nov 22 01:00:53 2007 by Doxygen 1.5.4 |