GNU Radio 3.6.5 C++ API

udp_sink.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007-2010,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_UDP_SINK_H
00024 #define INCLUDED_GR_UDP_SINK_H
00025 
00026 #include <blocks/api.h>
00027 #include <gr_sync_block.h>
00028 
00029 namespace gr {
00030   namespace blocks {
00031 
00032     /*!
00033      * \brief Write stream to an UDP socket.
00034      * \ingroup networking_tools_blk
00035      */
00036     class BLOCKS_API udp_sink : virtual public gr_sync_block
00037     {
00038     public:
00039       // gr::blocks::udp_sink::sptr
00040       typedef boost::shared_ptr<udp_sink> sptr;
00041 
00042       /*!
00043        * \brief UDP Sink Constructor
00044        *
00045        * \param itemsize     The size (in bytes) of the item datatype
00046        * \param host         The name or IP address of the receiving host; use
00047        *                     NULL or None for no connection
00048        * \param port         Destination port to connect to on receiving host
00049        * \param payload_size UDP payload size by default set to
00050        *                     1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header))
00051        * \param eof          Send zero-length packet on disconnect
00052        */
00053       static sptr make(size_t itemsize,
00054                        const std::string &host, int port,
00055                        int payload_size=1472, bool eof=true);
00056 
00057       /*! \brief return the PAYLOAD_SIZE of the socket */
00058       virtual int payload_size() = 0;
00059 
00060       /*! \brief Change the connection to a new destination
00061        *
00062        * \param host         The name or IP address of the receiving host; use
00063        *                     NULL or None to break the connection without closing
00064        * \param port         Destination port to connect to on receiving host
00065        *
00066        * Calls disconnect() to terminate any current connection first.
00067        */
00068       virtual void connect(const std::string &host, int port) = 0;
00069 
00070       /*! \brief Send zero-length packet (if eof is requested) then stop sending
00071        *
00072        * Zero-byte packets can be interpreted as EOF by gr_udp_source.
00073        * Note that disconnect occurs automatically when the sink is
00074        * destroyed, but not when its top_block stops.*/
00075       virtual void disconnect() = 0;
00076     };
00077 
00078   } /* namespace blocks */
00079 } /* namespace gr */
00080 
00081 #endif /* INCLUDED_GR_UDP_SINK_H */