GNU Radio 3.7.1 C++ API
udp_source.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_SOURCE_H
00024 #define INCLUDED_GR_UDP_SOURCE_H
00025 
00026 #include <gnuradio/blocks/api.h>
00027 #include <gnuradio/sync_block.h>
00028 
00029 namespace gr {
00030   namespace blocks {
00031 
00032     /*!
00033      * \brief Read stream from an UDP socket.
00034      * \ingroup networking_tools_blk
00035      */
00036     class BLOCKS_API udp_source : virtual public sync_block
00037     {
00038     public:
00039       // gr::blocks::udp_source::sptr
00040       typedef boost::shared_ptr<udp_source> sptr;
00041 
00042       /*!
00043        * \brief UDP Source 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; can be
00047        *                     NULL, None, or "0.0.0.0" to allow reading from any
00048        *                     interface on the host
00049        * \param port         The port number on which to receive data; use 0 to
00050        *                     have the system assign an unused port number
00051        * \param payload_size UDP payload size by default set to 1472 =
00052        *                     (1500 MTU - (8 byte UDP header) - (20 byte IP header))
00053        * \param eof          Interpret zero-length packet as EOF (default: true)
00054        */
00055       static sptr make(size_t itemsize,
00056                        const std::string &host, int port,
00057                        int payload_size=1472,
00058                        bool eof=true);
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 Cut the connection if we have one set up.
00071        */
00072       virtual void disconnect() = 0;
00073 
00074       /*! \brief return the PAYLOAD_SIZE of the socket */
00075       virtual int payload_size() = 0;
00076 
00077       /*! \brief return the port number of the socket */
00078       virtual int get_port() = 0;
00079     };
00080 
00081   } /* namespace blocks */
00082 } /* namespace gr */
00083 
00084 #endif /* INCLUDED_GR_UDP_SOURCE_H */