GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
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  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_GR_MESSAGE_H
12 #define INCLUDED_GR_MESSAGE_H
13 
14 #include <gnuradio/api.h>
15 #include <gnuradio/types.h>
16 #include <string>
17 
18 namespace gr {
19 
20 /*!
21  * \brief Message class.
22  *
23  * \ingroup misc
24  * The ideas and method names for adjustable message length were
25  * lifted from the click modular router "Packet" class.
26  */
28 {
29 public:
30  typedef std::shared_ptr<message> sptr;
31 
32 private:
33  sptr d_next; // link field for msg queue
34  long d_type; // type of the message
35  double d_arg1; // optional arg1
36  double d_arg2; // optional arg2
37 
38  std::vector<unsigned char> d_buf;
39  unsigned char* d_msg_start; // where the msg starts
40  unsigned char* d_msg_end; // one beyond end of msg
41 
42  message(long type, double arg1, double arg2, size_t length);
43 
44  friend class msg_queue;
45 
46  unsigned char* buf_data() { return d_buf.data(); }
47  size_t buf_len() const { return d_buf.size(); }
48 
49 public:
50  /*!
51  * \brief public constructor for message
52  */
53  static sptr make(long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0);
54 
55  static sptr make_from_string(const std::string s,
56  long type = 0,
57  double arg1 = 0,
58  double arg2 = 0);
59 
60 
62 
63  long type() const { return d_type; }
64  double arg1() const { return d_arg1; }
65  double arg2() const { return d_arg2; }
66 
67  void set_type(long type) { d_type = type; }
68  void set_arg1(double arg1) { d_arg1 = arg1; }
69  void set_arg2(double arg2) { d_arg2 = arg2; }
70 
71  unsigned char* msg() const { return d_msg_start; }
72  size_t length() const { return d_msg_end - d_msg_start; }
73  std::string to_string() const;
74 };
75 
77 
78 } /* namespace gr */
79 
80 #endif /* INCLUDED_GR_MESSAGE_H */
Message class.
Definition: message.h:28
static sptr make_from_string(const std::string s, long type=0, double arg1=0, double arg2=0)
double arg1() const
Definition: message.h:64
static sptr make(long type=0, double arg1=0, double arg2=0, size_t length=0)
public constructor for message
size_t length() const
Definition: message.h:72
long type() const
Definition: message.h:63
void set_arg2(double arg2)
Definition: message.h:69
double arg2() const
Definition: message.h:65
unsigned char * msg() const
Definition: message.h:71
std::string to_string() const
void set_arg1(double arg1)
Definition: message.h:68
void set_type(long type)
Definition: message.h:67
std::shared_ptr< message > sptr
Definition: message.h:30
thread-safe message queue
Definition: msg_queue.h:25
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29
GR_RUNTIME_API long message_ncurrently_allocated()
PMT_API size_t length(const pmt_t &v)
Return the number of elements in v.