Fawkes API  Fawkes Development Version
message.h
1 
2 /***************************************************************************
3  * message.h - BlackBoard message
4  *
5  * Created: Sun Oct 08 00:08:10 2006
6  * Copyright 2006-2010 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __INTERFACE_MESSAGE_H_
25 #define __INTERFACE_MESSAGE_H_
26 
27 #include <interface/field_iterator.h>
28 #include <interface/types.h>
29 #include <core/utils/refcount.h>
30 
31 #define __INTERFACE_MESSAGE_TYPE_SIZE 32
32 
33 namespace fawkes {
34 #if 0 /* just to make Emacs auto-indent happy */
35 }
36 #endif
37 
38 class Mutex;
39 class Interface;
40 class InterfaceFieldIterator;
41 class Time;
42 
43 class Message : public RefCount
44 {
45  friend class Interface;
46  public:
47  Message(const char *type);
48  Message(const Message *mesg);
49  Message(const Message &mesg);
50  virtual ~Message();
51 
52  Message & operator= (const Message & m);
53 
54  unsigned int id() const;
55  void set_id(unsigned int message_id);
56  void mark_enqueued();
57  bool enqueued() const;
58  const Time * time_enqueued() const;
59 
60  unsigned int sender_id() const;
61  const char * sender_thread_name() const;
62  Interface * interface() const;
63  const char * type() const;
64 
67 
68  unsigned int num_fields() const;
69 
70  const void * datachunk() const;
71  unsigned int datasize() const;
72 
73  unsigned int hops() const;
74  void set_hops(unsigned int hops);
75 
76  void set_from_chunk(const void *chunk);
77 
78  unsigned int recipient() const;
79 
80  virtual Message * clone() const;
81 
82  /** Check if message has desired type.
83  * @return true, if message has desired type, false otherwise
84  */
85  template <class MessageType>
86  bool is_of_type();
87 
88  private: // fields
89  unsigned int __message_id;
90  unsigned int __hops;
91  bool __enqueued;
92  Time *__time_enqueued;
93 
94  unsigned int recipient_interface_mem_serial;
95  unsigned int sender_interface_instance_serial;
96 
97  char *_type;
98  char *_sender_thread_name;
99  unsigned int _sender_id;
100 
101  Interface *_transmit_via_iface;
102 
103  interface_fieldinfo_t *__fieldinfo_list;
104 
105  unsigned int __num_fields;
106 
107  private: // methods
108  void set_interface(Interface *iface);
109 
110  protected:
111  void add_fieldinfo(interface_fieldtype_t type, const char *name,
112  size_t length, void *value, const char *enumtype = 0);
113 
114  void *data_ptr;
115  unsigned int data_size;
116 
117  /** Timestamp data, must be present and first entries for each interface
118  * data structs! This leans on timeval struct. */
119  typedef struct {
120  int64_t timestamp_sec; /**< time in seconds since Unix epoch */
121  int64_t timestamp_usec; /**< additional time microseconds */
123  message_data_ts_t *data_ts; /**< data timestamp aliasing pointer */
124 };
125 
126 template <class MessageType>
127 bool
129 {
130  return (dynamic_cast<MessageType *>(this) != 0);
131 }
132 
133 
134 } // end namespace fawkes
135 
136 #endif
Interface field iterator.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:114
virtual Message * clone() const
Clone this message.
Definition: message.cpp:419
bool enqueued() const
Check is message has been enqueued.
Definition: message.cpp:251
unsigned int hops() const
Get number of hops.
Definition: message.cpp:207
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:43
void mark_enqueued()
Mark message as being enqueued.
Definition: message.cpp:235
Interface field info list.
Definition: types.h:51
const char * type() const
Get message type.
Definition: message.cpp:378
Fawkes library namespace.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:119
unsigned int recipient() const
Get recipient memory serial.
Definition: message.cpp:275
A class for handling time.
Definition: time.h:91
unsigned int datasize() const
Get size of data.
Definition: message.cpp:295
unsigned int id() const
Get message ID.
Definition: message.cpp:197
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
InterfaceFieldIterator fields_end()
Invalid iterator.
Definition: message.cpp:398
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:123
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:115
Message(const char *type)
Constructor.
Definition: message.cpp:67
unsigned int num_fields() const
Get the number of fields in the message.
Definition: message.cpp:408
virtual ~Message()
Destructor.
Definition: message.cpp:178
const char * sender_thread_name() const
Get sender of message.
Definition: message.cpp:335
void set_from_chunk(const void *chunk)
Set from raw data chunk.
Definition: message.cpp:307
unsigned int sender_id() const
Get ID of sender.
Definition: message.cpp:345
int64_t timestamp_usec
additional time microseconds
Definition: message.h:121
Reference counting base class.
Definition: refcount.h:32
Interface * interface() const
Get transmitting interface.
Definition: message.cpp:368
InterfaceFieldIterator fields()
Get iterator over all fields of this interface instance.
Definition: message.cpp:388
bool is_of_type()
Check if message has desired type.
Definition: message.h:128
const Time * time_enqueued() const
Get time when message was enqueued.
Definition: message.cpp:265
int64_t timestamp_sec
time in seconds since Unix epoch
Definition: message.h:120
const void * datachunk() const
Get pointer to data.
Definition: message.cpp:285
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0)
Add an entry to the info list.
Definition: message.cpp:435
void set_hops(unsigned int hops)
Set number of hops.
Definition: message.cpp:227
interface_fieldtype_t
Interface field type.
Definition: types.h:33
Message & operator=(const Message &m)
Assign this message to given message.
Definition: message.cpp:320
void set_id(unsigned int message_id)
Set message ID.
Definition: message.cpp:217