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