Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ProcessID.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_ProcessID_h_
00003 #define INCLUDED_ProcessID_h_
00004 
00005 #ifdef PLATFORM_APERIOS
00006 #  include "Shared/StackTrace.h"
00007 #endif
00008 
00009 //! holds information to identify currently running process
00010 /*!
00011  * Although the ProcessID_t enum specifies the maximum number of processes
00012  * in its NumProcesses value, this doesn't have to correspond to the actual
00013  * number of active processes.  If you want an element of dynamicism to launch
00014  * and/or close processes at runtime, simply increase the NumProcesses to a 
00015  * higher value so that space can be allocated for those processes in shared 
00016  * memory regions for things like attachment pointers or other per-process
00017  * data.
00018  *
00019  * Not all processes need to have a *named* id, they just need a unique id.
00020  */
00021 namespace ProcessID {
00022   //! Holds ID number for each process
00023   enum ProcessID_t {
00024     MainProcess,   //!< MainObj process
00025     MotionProcess, //!< MotoObj process
00026     SoundProcess,  //!< SoundPlay process
00027 #ifndef PLATFORM_APERIOS
00028     SimulatorProcess, //!< for interaction with OS and managing global environment
00029 #endif
00030     NumProcesses   //!< maximum number of 'friendly' processes -- see class docs
00031   };
00032   
00033   ProcessID_t getID();  //!< returns process's ID number, subject to overriding via setIDHooks()
00034   void setID(ProcessID_t id); //!< sets the ID during init (be careful you know what you're doing if you call this), subject to overriding via setIDHooks()
00035   
00036 #ifndef PLATFORM_APERIOS
00037   //! allows you to override the behavior of getID and setID -- pass NULL to use default behavior
00038   void setIDHooks(ProcessID_t (*customGetID)(), void (*customSetID)(ProcessID_t id)); 
00039 
00040   //! returns process's ID number from static global, the default behavior if setIDHooks was passed NULL
00041   ProcessID_t getUnhookedID();
00042   
00043   //! sets the ID into static global (be careful you know what you're doing if you call this), this is the default behavior if setIDHooks was passed NULL
00044   void setUnhookedID(ProcessID_t id);
00045 #endif
00046   
00047   //! returns a string version of the name of the process
00048   inline const char* getIDStr(ProcessID_t pid) {
00049     switch(pid) {
00050       case MainProcess: return "Main";
00051       case MotionProcess: return "Motion";
00052       case SoundProcess: return "Sound";
00053 #ifndef PLATFORM_APERIOS
00054       case SimulatorProcess: return "Simulator";
00055 #endif
00056       default: return "Invalid Process";
00057     }
00058   }
00059   
00060   //! returns a string version of the name of the current process
00061   inline const char* getIDStr() { return getIDStr(getID()); }
00062   
00063 #ifdef PLATFORM_APERIOS
00064   //! sets location of shared memory map from IDs to current entry point, this is required to be set up before any entry()'s
00065   /*! @param idmap array of StackFrame structures, one per #NumProcesses
00066    *  the idea is to have idmap stored in a shared memory region, so functions can tell which one they belong to */
00067   void setMap(stacktrace::StackFrame idmap[]);
00068   
00069   //! returns the stack frame which should be set to the entry point of the current function
00070   /*! this is only valid if it is called before any shared object processing is done */
00071   stacktrace::StackFrame* getMapFrame();
00072 #endif
00073 }
00074 
00075 /*! @file
00076  * @brief Defines ProcessID - simple little global for checking which process is currently running, kind of. (see ProcessID::getID() )
00077  * @author ejt (Creator)
00078  */
00079 
00080 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:49 2016 by Doxygen 1.6.3