Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
EventTranslator.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_EventTranslator_h_ 00003 #define INCLUDED_EventTranslator_h_ 00004 00005 #include "Shared/SharedQueue.h" 00006 #include "Events/EventTrapper.h" 00007 00008 //! EventTranslator receives events from EventRouters in non-Main processes and adds them into a SharedQueue for Main to pick up 00009 /*! The SharedQueue which the processes should set up and then pass to this object 00010 * is defined by TranslatorSharedQueue_t - it allows 100 entries totalling 3KB of space. 00011 * You can modify the type to change the capacity, but if you're making that many events that 00012 * between Main's calls to translateEvents() you might want to rethink a few things... 00013 * 00014 * EventTranslator only handles LocomotionEvent, VisionObjectEvent, and TextMsgEvent subtypes for 00015 * the moment. Anything else is only handled as an EventBase class. (so extra fields aren't 00016 * going to be stored) It's easy to add more types if you need to send them from other 00017 * processes (that's the whole point of this class!) 00018 * 00019 * Reason for doing it this way: Avoids OPENR message lag time (4-8ms in our testing), also 00020 * avoids problems with RTTI stored in classes from different processes. */ 00021 class EventTranslator : public EventTrapper { 00022 public: 00023 //!constructor 00024 EventTranslator() : queue(NULL) {} 00025 00026 //!Use this type to set up the shared queue between processes 00027 typedef SharedQueue<3*1024,100> Queue_t; 00028 00029 //!an ID is inserted before the event data in the queue so we can tell which subclass it is 00030 /*!(quickly, could look at the creator code which is stored, but that's a text string)*/ 00031 enum TypeID_t { EventBase_ID, LocomotionEvent_ID, VisionObjectEvent_ID, TextMsgEvent_ID }; 00032 00033 //!sets the SharedQueue which should be used 00034 void setQueue(Queue_t * q) { queue=q; } 00035 00036 //!called by the event router when something in this process sends an event 00037 virtual bool trapEvent(const EventBase& event); 00038 00039 //!called by trapEvent to do all the work, needed so MotionCommands can enqueue directly 00040 static void enqueue(const EventBase& event, Queue_t * q); 00041 00042 //!called by non-MotionCommands to enqueue an event 00043 void enqueue(const EventBase& event) { enqueue(event,queue); } 00044 00045 //!called whenever Main gets some processor time to check for events from other processes 00046 void translateEvents(); 00047 00048 protected: 00049 //!called by translateEvents for each event to be sent 00050 static void sendEvent(const void* buf, unsigned int size); 00051 00052 //!pointer to queue of events to be sent 00053 Queue_t * queue; 00054 00055 private: 00056 EventTranslator(const EventTranslator&); //!< don't call 00057 EventTranslator operator=(const EventTranslator&); //!< don't call 00058 }; 00059 00060 /*! @file 00061 * @brief Describes EventTranslator, which receives events from EventRouters in non-Main processes and adds them into a SharedQueue for Main to pick up 00062 * @author ejt (Creator) 00063 * 00064 * $Author: ejt $ 00065 * $Name: tekkotsu-2_2_1 $ 00066 * $Revision: 1.5 $ 00067 * $State: Exp $ 00068 * $Date: 2004/09/16 18:35:12 $ 00069 */ 00070 00071 #endif |
Tekkotsu v2.2.1 |
Generated Tue Nov 23 16:36:38 2004 by Doxygen 1.3.9.1 |