GNU Radio 3.7.1 C++ API
message.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2005,2013 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_H
00024 #define INCLUDED_GR_MESSAGE_H
00025 
00026 #include <gnuradio/api.h>
00027 #include <gnuradio/types.h>
00028 #include <string>
00029 
00030 namespace gr {
00031 
00032   /*!
00033    * \brief Message class.
00034    *
00035    * \ingroup misc
00036    * The ideas and method names for adjustable message length were
00037    * lifted from the click modular router "Packet" class.
00038    */
00039   class GR_RUNTIME_API message
00040   {
00041   public:
00042     typedef boost::shared_ptr<message> sptr;
00043 
00044   private:
00045     sptr         d_next;        // link field for msg queue
00046     long         d_type;        // type of the message
00047     double       d_arg1;        // optional arg1
00048     double       d_arg2;        // optional arg2
00049 
00050     unsigned char *d_buf_start; // start of allocated buffer
00051     unsigned char *d_msg_start; // where the msg starts
00052     unsigned char *d_msg_end;   // one beyond end of msg
00053     unsigned char *d_buf_end;   // one beyond end of allocated buffer
00054 
00055     message(long type, double arg1, double arg2, size_t length);
00056 
00057     friend class msg_queue;
00058 
00059     unsigned char *buf_data() const { return d_buf_start; }
00060     size_t buf_len() const { return d_buf_end - d_buf_start; }
00061 
00062   public:
00063     /*!
00064      * \brief public constructor for message
00065      */
00066     static sptr make(long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0);
00067 
00068     static sptr make_from_string(const std::string s, long type = 0,
00069                                  double arg1 = 0, double arg2 = 0);
00070 
00071 
00072     ~message();
00073 
00074     long type() const   { return d_type; }
00075     double arg1() const { return d_arg1; }
00076     double arg2() const { return d_arg2; }
00077 
00078     void set_type(long type)   { d_type = type; }
00079     void set_arg1(double arg1) { d_arg1 = arg1; }
00080     void set_arg2(double arg2) { d_arg2 = arg2; }
00081 
00082     unsigned char *msg() const { return d_msg_start; }
00083     size_t length() const { return d_msg_end - d_msg_start; }
00084     std::string to_string() const;
00085   };
00086 
00087   GR_RUNTIME_API long message_ncurrently_allocated();
00088 
00089 } /* namespace gr */
00090 
00091 #endif /* INCLUDED_GR_MESSAGE_H */