Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_message.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005 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
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 #ifndef INCLUDED_GR_MESSAGE_H
23 #define INCLUDED_GR_MESSAGE_H
24
25 #include <gr_types.h>
26 #include <string>
27
28 class gr_message;
29 typedef boost::shared_ptr<gr_message> gr_message_sptr;
30
31 /*!
32  * \brief public constructor for gr_message
33  */
34 gr_message_sptr 
35 gr_make_message(long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0);
36
37 gr_message_sptr
38 gr_make_message_from_string(const std::string s, long type = 0, double arg1 = 0, double arg2 = 0);
39
40 /*!
41  * \brief Message class.
42  *
43  * \ingroup misc
44  * The ideas and method names for adjustable message length were
45  * lifted from the click modular router "Packet" class.
46  */
47 class gr_message {
48   gr_message_sptr d_next;       // link field for msg queue
49   long            d_type;       // type of the message
50   double          d_arg1;       // optional arg1
51   double          d_arg2;       // optional arg2
52
53   unsigned char  *d_buf_start;  // start of allocated buffer
54   unsigned char  *d_msg_start;  // where the msg starts
55   unsigned char  *d_msg_end;    // one beyond end of msg
56   unsigned char  *d_buf_end;    // one beyond end of allocated buffer
57   
58   gr_message (long type, double arg1, double arg2, size_t length);
59
60   friend gr_message_sptr
61     gr_make_message (long type, double arg1, double arg2, size_t length);
62
63   friend gr_message_sptr
64     gr_make_message_from_string (const std::string s, long type, double arg1, double arg2);
65
66   friend class gr_msg_queue;
67
68   unsigned char *buf_data() const  { return d_buf_start; }
69   size_t buf_len() const           { return d_buf_end - d_buf_start; }
70
71 public:
72   ~gr_message ();
73
74   long type() const   { return d_type; }
75   double arg1() const { return d_arg1; }
76   double arg2() const { return d_arg2; }
77
78   void set_type(long type)   { d_type = type; }
79   void set_arg1(double arg1) { d_arg1 = arg1; }
80   void set_arg2(double arg2) { d_arg2 = arg2; }
81
82   unsigned char *msg() const { return d_msg_start; }
83   size_t length() const      { return d_msg_end - d_msg_start; }
84   std::string to_string() const;
85
86 };
87
88 long gr_message_ncurrently_allocated ();
89
90 #endif /* INCLUDED_GR_MESSAGE_H */