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 binary copy
00013  *  of values */
00014 class WorldStateSerializerBehavior : public BehaviorBase {
00015 public:
00016   WorldStateSerializerBehavior(); //!< constructor
00017 
00018   virtual void DoStart(); //!< starts listening for sensor update events
00019   virtual void DoStop(); //!< stops listening for events
00020   virtual void processEvent(const EventBase& e); //!< core functionality - performs serialization, sends to sockets
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   virtual std::string getDescription() const { return getClassDescription(); }
00027 
00028 protected:
00029   //! writes @a value to @a dst and advances @a dst
00030   template<class T>
00031   inline static void encode(char **dst, const T& value) {
00032     memcpy(*dst, &value, sizeof(T));
00033     // it'd be nice to use network byte order, but we'll save the aibo extra work
00034     //hostToNetwork(*dst, (char *)&value, sizeof(T));
00035     (*dst) += sizeof(T);
00036   }
00037 
00038   //! writes @a length bytes from @a src to @a dst
00039   template<class T>
00040   inline static void encode(char **dst, const T * src, int num) {
00041     memcpy(*dst, src, num*sizeof(T));
00042     (*dst) += num*sizeof(T);
00043   }
00044 
00045   Socket *wsJoints; //!< socket for sending current joint data
00046   Socket *wsPIDs; //!< socket for sending current PID info
00047 
00048 private:
00049   WorldStateSerializerBehavior(const WorldStateSerializerBehavior&); //!< don't call
00050   WorldStateSerializerBehavior& operator= (const WorldStateSerializerBehavior&); //!< don't call
00051 };
00052 
00053 /*! @file
00054  * @brief Describes WorldStateSerializerBehavior, which copies WorldState into a buffer for transmission over the network
00055  * @author alokl (Creator)
00056  *
00057  * $Author: ejt $
00058  * $Name: tekkotsu-2_2_1 $
00059  * $Revision: 1.3 $
00060  * $State: Exp $
00061  * $Date: 2004/11/11 01:45:36 $
00062  */
00063 
00064 #endif

Tekkotsu v2.2.1
Generated Tue Nov 23 16:36:42 2004 by Doxygen 1.3.9.1