GNU Radio 3.6.5 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2007,2008,2009,2010 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_UDP_SINK_H 00024 #define INCLUDED_GR_UDP_SINK_H 00025 00026 #include <gr_core_api.h> 00027 #include <gr_sync_block.h> 00028 #include <gruel/thread.h> 00029 00030 class gr_udp_sink; 00031 typedef boost::shared_ptr<gr_udp_sink> gr_udp_sink_sptr; 00032 00033 GR_CORE_API gr_udp_sink_sptr 00034 gr_make_udp_sink (size_t itemsize, 00035 const char *host, unsigned short port, 00036 int payload_size=1472, bool eof=true); 00037 00038 /*! 00039 * \brief Write stream to an UDP socket. 00040 * \ingroup sink_blk 00041 * 00042 * \param itemsize The size (in bytes) of the item datatype 00043 * \param host The name or IP address of the receiving host; use 00044 * NULL or None for no connection 00045 * \param port Destination port to connect to on receiving host 00046 * \param payload_size UDP payload size by default set to 1472 = 00047 * (1500 MTU - (8 byte UDP header) - (20 byte IP header)) 00048 * \param eof Send zero-length packet on disconnect 00049 */ 00050 00051 class GR_CORE_API gr_udp_sink : public gr_sync_block 00052 { 00053 friend GR_CORE_API gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, 00054 const char *host, 00055 unsigned short port, 00056 int payload_size, bool eof); 00057 private: 00058 size_t d_itemsize; 00059 00060 int d_payload_size; // maximum transmission unit (packet length) 00061 bool d_eof; // send zero-length packet on disconnect 00062 int d_socket; // handle to socket 00063 bool d_connected; // are we connected? 00064 gruel::mutex d_mutex; // protects d_socket and d_connected 00065 00066 protected: 00067 /*! 00068 * \brief UDP Sink Constructor 00069 * 00070 * \param itemsize The size (in bytes) of the item datatype 00071 * \param host The name or IP address of the receiving host; use 00072 * NULL or None for no connection 00073 * \param port Destination port to connect to on receiving host 00074 * \param payload_size UDP payload size by default set to 00075 * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) 00076 * \param eof Send zero-length packet on disconnect 00077 */ 00078 gr_udp_sink (size_t itemsize, 00079 const char *host, unsigned short port, 00080 int payload_size, bool eof); 00081 00082 public: 00083 ~gr_udp_sink (); 00084 00085 /*! \brief return the PAYLOAD_SIZE of the socket */ 00086 int payload_size() { return d_payload_size; } 00087 00088 /*! \brief Change the connection to a new destination 00089 * 00090 * \param host The name or IP address of the receiving host; use 00091 * NULL or None to break the connection without closing 00092 * \param port Destination port to connect to on receiving host 00093 * 00094 * Calls disconnect() to terminate any current connection first. 00095 */ 00096 void connect( const char *host, unsigned short port ); 00097 00098 /*! \brief Send zero-length packet (if eof is requested) then stop sending 00099 * 00100 * Zero-byte packets can be interpreted as EOF by gr_udp_source. Note that 00101 * disconnect occurs automatically when the sink is destroyed, but not when 00102 * its top_block stops.*/ 00103 void disconnect(); 00104 00105 // should we export anything else? 00106 00107 int work (int noutput_items, 00108 gr_vector_const_void_star &input_items, 00109 gr_vector_void_star &output_items); 00110 }; 00111 00112 #endif /* INCLUDED_GR_UDP_SINK_H */