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 2, 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., 59 Temple Place - Suite 330, 00020 * Boston, MA 02111-1307, USA. 00021 */ 00022 #ifndef INCLUDED_GR_MESSAGE_H 00023 #define INCLUDED_GR_MESSAGE_H 00024 00025 #include <gr_types.h> 00026 00027 class gr_message; 00028 typedef boost::shared_ptr<gr_message> gr_message_sptr; 00029 00033 gr_message_sptr 00034 gr_make_message (long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0); 00035 00042 class gr_message { 00043 gr_message_sptr d_next; // link field for msg queue 00044 long d_type; // type of the message 00045 double d_arg1; // optional arg1 00046 double d_arg2; // optional arg2 00047 00048 // mimic Linux sk_buff 00049 unsigned char *d_head; // start of allocated buffer 00050 unsigned char *d_data; // where the packet starts 00051 unsigned char *d_tail; // one beyond end of packet 00052 unsigned char *d_end; // one beyond end of allocated buffer 00053 00054 gr_message (long type, double arg1, double arg2, size_t length); 00055 00056 friend gr_message_sptr 00057 gr_make_message (long type, double arg1, double arg2, size_t length); 00058 friend class gr_msg_queue; 00059 00060 public: 00061 ~gr_message (); 00062 00063 long type () const { return d_type; } 00064 double arg1 () const { return d_arg1; } 00065 double arg2 () const { return d_arg2; } 00066 00067 void set_type (long type) { d_type = type; } 00068 void set_arg1 (double arg1) { d_arg1 = arg1; } 00069 void set_arg2 (double arg2) { d_arg2 = arg2; } 00070 00071 unsigned char *data () const { return d_data; } 00072 unsigned char *end_data () const { return d_tail; } 00073 size_t length () const { return d_tail - d_data; } 00074 size_t headroom () const { return d_data - d_head; } 00075 size_t tailroom () const { return d_end - d_tail; } 00076 unsigned char *buffer_data() const { return d_head; } 00077 size_t buffer_length() const { return d_end - d_head; } 00078 00079 // void push (size_t nb); // Add more space before message. 00080 void pull (size_t nb); // Get rid of initial bytes. 00081 // void put (size_t nb); // Add bytes to end of message. 00082 void take (size_t nb); // Delete bytes from end of message. 00083 }; 00084 00085 long gr_message_ncurrently_allocated (); 00086 00087 #endif /* INCLUDED_GR_MESSAGE_H */