GNU Radio 3.5.3.1 C++ API
gr_message.h
Go to the documentation of this file.
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_core_api.h>
26 #include <gr_types.h>
27 #include <string>
28 
29 class gr_message;
31 
32 /*!
33  * \brief public constructor for gr_message
34  */
36 gr_make_message(long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0);
37 
39 gr_make_message_from_string(const std::string s, long type = 0, double arg1 = 0, double arg2 = 0);
40 
41 /*!
42  * \brief Message class.
43  *
44  * \ingroup misc
45  * The ideas and method names for adjustable message length were
46  * lifted from the click modular router "Packet" class.
47  */
49  gr_message_sptr d_next; // link field for msg queue
50  long d_type; // type of the message
51  double d_arg1; // optional arg1
52  double d_arg2; // optional arg2
53 
54  unsigned char *d_buf_start; // start of allocated buffer
55  unsigned char *d_msg_start; // where the msg starts
56  unsigned char *d_msg_end; // one beyond end of msg
57  unsigned char *d_buf_end; // one beyond end of allocated buffer
58 
59  gr_message (long type, double arg1, double arg2, size_t length);
60 
62  gr_make_message (long type, double arg1, double arg2, size_t length);
63 
65  gr_make_message_from_string (const std::string s, long type, double arg1, double arg2);
66 
67  friend class gr_msg_queue;
68 
69  unsigned char *buf_data() const { return d_buf_start; }
70  size_t buf_len() const { return d_buf_end - d_buf_start; }
71 
72 public:
73  ~gr_message ();
74 
75  long type() const { return d_type; }
76  double arg1() const { return d_arg1; }
77  double arg2() const { return d_arg2; }
78 
79  void set_type(long type) { d_type = type; }
80  void set_arg1(double arg1) { d_arg1 = arg1; }
81  void set_arg2(double arg2) { d_arg2 = arg2; }
82 
83  unsigned char *msg() const { return d_msg_start; }
84  size_t length() const { return d_msg_end - d_msg_start; }
85  std::string to_string() const;
86 
87 };
88 
90 
91 #endif /* INCLUDED_GR_MESSAGE_H */