GNU Radio 3.7.3 C++ API
message.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005,2013 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 
23 #ifndef INCLUDED_GR_MESSAGE_H
24 #define INCLUDED_GR_MESSAGE_H
25 
26 #include <gnuradio/api.h>
27 #include <gnuradio/types.h>
28 #include <string>
29 
30 namespace gr {
31 
32  /*!
33  * \brief Message class.
34  *
35  * \ingroup misc
36  * The ideas and method names for adjustable message length were
37  * lifted from the click modular router "Packet" class.
38  */
40  {
41  public:
43 
44  private:
45  sptr d_next; // link field for msg queue
46  long d_type; // type of the message
47  double d_arg1; // optional arg1
48  double d_arg2; // optional arg2
49 
50  unsigned char *d_buf_start; // start of allocated buffer
51  unsigned char *d_msg_start; // where the msg starts
52  unsigned char *d_msg_end; // one beyond end of msg
53  unsigned char *d_buf_end; // one beyond end of allocated buffer
54 
55  message(long type, double arg1, double arg2, size_t length);
56 
57  friend class msg_queue;
58 
59  unsigned char *buf_data() const { return d_buf_start; }
60  size_t buf_len() const { return d_buf_end - d_buf_start; }
61 
62  public:
63  /*!
64  * \brief public constructor for message
65  */
66  static sptr make(long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0);
67 
68  static sptr make_from_string(const std::string s, long type = 0,
69  double arg1 = 0, double arg2 = 0);
70 
71 
72  ~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 
88 
89 } /* namespace gr */
90 
91 #endif /* INCLUDED_GR_MESSAGE_H */
size_t length() const
Definition: message.h:83
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
GR_RUNTIME_API long message_ncurrently_allocated()
thread-safe message queue
Definition: msg_queue.h:36
void set_type(long type)
Definition: message.h:78
PMT_API size_t length(const pmt_t &v)
Return the number of elements in v.
unsigned char * msg() const
Definition: message.h:82
void set_arg2(double arg2)
Definition: message.h:80
double arg2() const
Definition: message.h:76
long type() const
Definition: message.h:74
boost::shared_ptr< message > sptr
Definition: message.h:42
void set_arg1(double arg1)
Definition: message.h:79
double arg1() const
Definition: message.h:75
Message class.
Definition: message.h:39