Imported Upstream version 3.2.2
[debian/gnuradio] / mblock / src / include / mblock / message.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006,2007,2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 #ifndef INCLUDED_MB_MESSAGE_H
22 #define INCLUDED_MB_MESSAGE_H
23
24 #include <mblock/common.h>
25 #include <iosfwd>
26
27 #define MB_MESSAGE_LOCAL_ALLOCATOR 0    // define to 0 or 1
28
29 class mb_message;
30 typedef boost::shared_ptr<mb_message> mb_message_sptr;
31
32 /*!
33  * \brief construct a message and return boost::shared_ptr
34  *
35  * \param signal        identifier of the message
36  * \param data          the data to be operated on
37  * \param metadata      information about the data
38  * \param priority      urgency
39  */
40 mb_message_sptr
41 mb_make_message(pmt_t signal,
42                 pmt_t data = PMT_NIL,
43                 pmt_t metadata = PMT_NIL,
44                 mb_pri_t priority = MB_PRI_DEFAULT);
45
46 class mb_message {
47   mb_message_sptr d_next;               // link field for msg queue
48   pmt_t           d_signal;
49   pmt_t           d_data;
50   pmt_t           d_metadata;
51   mb_pri_t        d_priority;
52   pmt_t           d_port_id;            // name of port msg was rcvd on (symbol)
53
54   friend class mb_msg_queue;
55
56   friend mb_message_sptr
57   mb_make_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority);
58
59   // private constructor
60   mb_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority);
61
62 public:
63   ~mb_message();
64
65   pmt_t signal() const { return d_signal; }
66   pmt_t data() const { return d_data; }
67   pmt_t metadata() const { return d_metadata; }
68   mb_pri_t priority() const { return d_priority; }
69   pmt_t port_id() const { return d_port_id; }
70
71   void set_port_id(pmt_t port_id){ d_port_id = port_id; }
72
73 #if (MB_MESSAGE_LOCAL_ALLOCATOR)
74   void *operator new(size_t);
75   void operator delete(void *, size_t);
76 #endif
77 };
78
79 std::ostream& operator<<(std::ostream& os, const mb_message &msg);
80
81 inline
82 std::ostream& operator<<(std::ostream& os, const mb_message_sptr msg)
83 {
84   os << *(msg.get());
85   return os;
86 }
87
88 #endif /* INCLUDED_MB_MESSAGE_H */