GNU Radio 3.6.5.1 C++ API
gr_message_debug.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005,2012 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_DEBUG_H
24 #define INCLUDED_GR_MESSAGE_DEBUG_H
25 
26 #include <gr_core_api.h>
27 #include <gr_block.h>
28 #include <gr_message.h>
29 #include <gr_msg_queue.h>
30 #include <gruel/thread.h>
31 
32 class gr_message_debug;
34 
36 
37 /*!
38  * \brief Print received messages to stdout
39  * \ingroup sink_blk
40  */
42 {
43  private:
46 
47  /*!
48  * \brief Messages received in this port are printed to stdout.
49  *
50  * This port receives messages from the scheduler's message handling
51  * mechanism and prints it to stdout. This message handler function
52  * is only meant to be used by the scheduler to handle messages
53  * posted to port 'print'.
54  *
55  * \param msg A pmt message passed from the scheduler's message handling.
56  */
57  void print(pmt::pmt_t msg);
58 
59  /*!
60  * \brief PDU formatted messages received in this port are printed to stdout.
61  *
62  * This port receives messages from the scheduler's message handling
63  * mechanism and prints it to stdout. This message handler function
64  * is only meant to be used by the scheduler to handle messages
65  * posted to port 'print'.
66  *
67  * \param pdu A PDU message passed from the scheduler's message handling.
68  */
69  void print_pdu(pmt::pmt_t pdu);
70 
71  /*!
72  * \brief Messages received in this port are stored in a vector.
73  *
74  * This port receives messages from the scheduler's message handling
75  * mechanism and stores it in a vector. Messages can be retrieved
76  * later using the 'get_message' function. This message handler
77  * function is only meant to be used by the scheduler to handle
78  * messages posted to port 'store'.
79  *
80  * \param msg A pmt message passed from the scheduler's message handling.
81  */
82  void store(pmt::pmt_t msg);
83 
84  gruel::mutex d_mutex;
85  std::vector<pmt::pmt_t> d_messages;
86 
87  protected:
89 
90  public:
91  ~gr_message_debug ();
92 
93  /*!
94  * \brief Reports the number of messages received by this block.
95  */
96  int num_messages();
97 
98  /*!
99  * \brief Get a message (as a PMT) from the message vector at index \p i.
100  *
101  * Messages passed to the 'store' port will be stored in a
102  * vector. This function retrieves those messages by index. They are
103  * index in order of when they were received (all messages are just
104  * pushed onto the back of a vector). This is mostly useful in
105  * debugging message passing graphs and in QA code.
106  *
107  * \param i The index in the vector for the message to retrieve.
108  *
109  * \return a message at index \p i as a pmt_t.
110  */
111  pmt::pmt_t get_message(int i);
112 };
113 
114 #endif /* INCLUDED_GR_MESSAGE_DEBUG_H */