Homepage Demos Overview Downloads Tutorials Reference
Credits

WorldStateSerializerBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_WorldStateSerializer_h
00003 #define INCLUDED_WorldStateSerializer_h
00004 
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Shared/Config.h"
00007 
00008 class Socket;
00009 
00010 //! Copies WorldState into a buffer for transmission over the network
00011 /*! To determine the communication protocol, just look in the
00012  *  processEvent() function - it's pretty straightforward. */
00013 class WorldStateSerializerBehavior : public BehaviorBase {
00014 public:
00015   WorldStateSerializerBehavior(); //!< constructor
00016 
00017   virtual void DoStart(); //!< starts listening for sensor update events
00018   virtual void DoStop(); //!< stops listening for events
00019   virtual void processEvent(const EventBase& e); //!< core functionality - performs serialization, sends to sockets
00020   virtual std::string getName() const { return "World State Serializer"; }
00021   static std::string getClassDescription() {
00022     char tmp[80];
00023     sprintf(tmp,"Sends sensor information to port %d and current pid values to port %d",config->main.wsjoints_port,config->main.wspids_port);
00024     return tmp;
00025   }
00026 
00027 protected:
00028   //! writes @a value to @a dst and advances @a dst
00029   template<class T>
00030   inline static void encode(char **dst, const T& value) {
00031     memcpy(*dst, &value, sizeof(T));
00032     // it'd be nice to use network byte order, but we'll save the aibo extra work
00033     //hostToNetwork(*dst, (char *)&value, sizeof(T));
00034     (*dst) += sizeof(T);
00035   }
00036 
00037   //! writes @a length bytes from @a src to @a dst
00038   template<class T>
00039   inline static void encode(char **dst, const T * src, int num) {
00040     memcpy(*dst, src, num*sizeof(T));
00041     (*dst) += num*sizeof(T);
00042   }
00043 
00044   Socket *wsJoints; //!< socket for sending current joint data
00045   Socket *wsPIDs; //!< socket for sending current PID info
00046 
00047 private:
00048   WorldStateSerializerBehavior(const WorldStateSerializerBehavior&); //!< don't call
00049   WorldStateSerializerBehavior& operator= (const WorldStateSerializerBehavior&); //!< don't call
00050 };
00051 
00052 /*! @file
00053  * @brief Describes WorldStateSerializerBehavior, which copies WorldState into a buffer for transmission over the network
00054  * @author alokl (Creator)
00055  *
00056  * $Author: ejt $
00057  * $Name: tekkotsu-2_0 $
00058  * $Revision: 1.1 $
00059  * $State: Exp $
00060  * $Date: 2004/01/19 20:37:29 $
00061  */
00062 
00063 #endif

Tekkotsu v2.0
Generated Wed Jan 21 03:20:30 2004 by Doxygen 1.3.4