message.h

00001 
00002 /***************************************************************************
00003  *  message.h - BlackBoard message
00004  *
00005  *  Created: Sun Oct 08 00:08:10 2006
00006  *  Copyright  2006-2010  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __INTERFACE_MESSAGE_H_
00025 #define __INTERFACE_MESSAGE_H_
00026 
00027 #include <interface/field_iterator.h>
00028 #include <interface/types.h>
00029 #include <core/utils/refcount.h>
00030 
00031 #define __INTERFACE_MESSAGE_TYPE_SIZE 32
00032 
00033 namespace fawkes {
00034 #if 0 /* just to make Emacs auto-indent happy */
00035 }
00036 #endif
00037 
00038 class Mutex;
00039 class Interface;
00040 class InterfaceFieldIterator;
00041 class Time;
00042 
00043 class Message : public RefCount
00044 {
00045  friend class Interface;
00046  public:
00047   Message(const char *type);
00048   Message(const Message *mesg);
00049   Message(const Message &mesg);
00050   virtual ~Message();
00051 
00052   Message &         operator=  (const Message & m);
00053 
00054   unsigned int      id() const;
00055   void              set_id(unsigned int message_id);
00056   void              mark_enqueued();
00057   bool              enqueued() const;
00058   const Time *      time_enqueued() const;
00059 
00060   unsigned int      sender_id() const;
00061   const char *      sender_thread_name() const;
00062   Interface *       interface() const;
00063   const char *      type() const;
00064 
00065   InterfaceFieldIterator     fields();
00066   InterfaceFieldIterator     fields_end();
00067 
00068   unsigned int      num_fields() const;
00069 
00070   const void *      datachunk() const;
00071   unsigned int      datasize() const;
00072 
00073   unsigned int      hops() const;
00074   void              set_hops(unsigned int hops);
00075 
00076   void              set_from_chunk(const void *chunk);
00077 
00078   unsigned int      recipient() const;
00079 
00080   virtual Message * clone() const;
00081 
00082   /** Check if message has desired type.
00083    * @return true, if message has desired type, false otherwise
00084    */
00085   template <class MessageType>
00086     bool           is_of_type();
00087 
00088  private: // fields
00089   unsigned int  __message_id;
00090   unsigned int  __hops;
00091   bool          __enqueued;
00092   Time         *__time_enqueued;
00093 
00094   unsigned int  recipient_interface_mem_serial;  
00095   unsigned int  sender_interface_instance_serial;  
00096 
00097   char          *_type;
00098   char          *_sender_thread_name;
00099   unsigned int   _sender_id;
00100 
00101   Interface     *_transmit_via_iface;
00102 
00103   interface_fieldinfo_t  *__fieldinfo_list;
00104 
00105   unsigned int __num_fields;
00106 
00107  private: // methods
00108   void              set_interface(Interface *iface);
00109 
00110  protected:
00111   void add_fieldinfo(interface_fieldtype_t type, const char *name,
00112                      size_t length, void *value, const char *enumtype = 0);
00113 
00114   void         *data_ptr;
00115   unsigned int  data_size;
00116 
00117   /** Timestamp data, must be present and first entries for each interface
00118    * data structs! This leans on timeval struct. */
00119   typedef struct {
00120     int64_t timestamp_sec;      /**< time in seconds since Unix epoch */
00121     int64_t timestamp_usec;     /**< additional time microseconds */
00122   } message_data_ts_t;
00123   message_data_ts_t  *data_ts;  /**< data timestamp aliasing pointer */
00124 };
00125 
00126 template <class MessageType>
00127 bool
00128 Message::is_of_type()
00129 {
00130   return (dynamic_cast<MessageType *>(this) != 0);
00131 }
00132 
00133 
00134 } // end namespace fawkes
00135 
00136 #endif

Generated on Tue Feb 22 13:32:24 2011 for Fawkes API by  doxygen 1.4.7