Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
65  InterfaceFieldIterator fields();
66  InterfaceFieldIterator fields_end();
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
128 Message::is_of_type()
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
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:43
Interface field info list.
Definition: types.h:51
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:119
A class for handling time.
Definition: time.h:91
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
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
int64_t timestamp_usec
additional time microseconds
Definition: message.h:121
Reference counting base class.
Definition: refcount.h:32
int64_t timestamp_sec
time in seconds since Unix epoch
Definition: message.h:120
interface_fieldtype_t
Interface field type.
Definition: types.h:33