GNU Radio 3.6.5 C++ API

gr_message_debug.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2005,2012 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_GR_MESSAGE_DEBUG_H
00024 #define INCLUDED_GR_MESSAGE_DEBUG_H
00025 
00026 #include <gr_core_api.h>
00027 #include <gr_block.h>
00028 #include <gr_message.h>
00029 #include <gr_msg_queue.h>
00030 #include <gruel/thread.h>
00031 
00032 class gr_message_debug;
00033 typedef boost::shared_ptr<gr_message_debug> gr_message_debug_sptr;
00034 
00035 GR_CORE_API gr_message_debug_sptr gr_make_message_debug();
00036 
00037 /*!
00038  * \brief Print received messages to stdout
00039  * \ingroup sink_blk
00040  */
00041 class GR_CORE_API gr_message_debug : public gr_block
00042 {
00043  private:
00044   friend GR_CORE_API gr_message_debug_sptr
00045   gr_make_message_debug();
00046 
00047   /*!
00048    * \brief Messages received in this port are printed to stdout.
00049    *
00050    * This port receives messages from the scheduler's message handling
00051    * mechanism and prints it to stdout. This message handler function
00052    * is only meant to be used by the scheduler to handle messages
00053    * posted to port 'print'.
00054    *
00055    * \param msg A pmt message passed from the scheduler's message handling.
00056    */
00057   void print(pmt::pmt_t msg);
00058 
00059   /*!
00060    * \brief PDU formatted messages received in this port are printed to stdout.
00061    *
00062    * This port receives messages from the scheduler's message handling
00063    * mechanism and prints it to stdout. This message handler function
00064    * is only meant to be used by the scheduler to handle messages
00065    * posted to port 'print'.
00066    *
00067    * \param pdu A PDU message passed from the scheduler's message handling.
00068    */
00069   void print_pdu(pmt::pmt_t pdu);
00070 
00071   /*!
00072    * \brief Messages received in this port are stored in a vector.
00073    *
00074    * This port receives messages from the scheduler's message handling
00075    * mechanism and stores it in a vector. Messages can be retrieved
00076    * later using the 'get_message' function. This message handler
00077    * function is only meant to be used by the scheduler to handle
00078    * messages posted to port 'store'.
00079    *
00080    * \param msg A pmt message passed from the scheduler's message handling.
00081    */
00082   void store(pmt::pmt_t msg);
00083 
00084   gruel::mutex d_mutex;
00085   std::vector<pmt::pmt_t> d_messages;
00086 
00087  protected:
00088   gr_message_debug ();
00089 
00090  public:
00091   ~gr_message_debug ();
00092 
00093   /*! 
00094    * \brief Reports the number of messages received by this block.
00095    */
00096   int num_messages();
00097 
00098   /*!
00099    * \brief Get a message (as a PMT) from the message vector at index \p i.
00100    *
00101    * Messages passed to the 'store' port will be stored in a
00102    * vector. This function retrieves those messages by index. They are
00103    * index in order of when they were received (all messages are just
00104    * pushed onto the back of a vector). This is mostly useful in
00105    * debugging message passing graphs and in QA code.
00106    *
00107    * \param i The index in the vector for the message to retrieve.
00108    *
00109    * \return a message at index \p i as a pmt_t.
00110    */
00111   pmt::pmt_t get_message(int i);
00112 };
00113 
00114 #endif /* INCLUDED_GR_MESSAGE_DEBUG_H */