GNU Radio 3.6.5 C++ API

gr_udp_source.h

Go to the documentation of this file.
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_SOURCE_H
00024 #define INCLUDED_GR_UDP_SOURCE_H
00025 
00026 #include <gr_core_api.h>
00027 #include <gr_sync_block.h>
00028 #include <gruel/thread.h>
00029 
00030 class gr_udp_source;
00031 typedef boost::shared_ptr<gr_udp_source> gr_udp_source_sptr;
00032 
00033 GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host,
00034                                       unsigned short port,
00035                                       int payload_size=1472,
00036                                       bool eof=true, bool wait=true);
00037 
00038 /*!
00039  * \brief Read stream from an UDP socket.
00040  * \ingroup source_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; can be
00044  *                     NULL, None, or "0.0.0.0" to allow reading from any
00045  *                     interface on the host
00046  * \param port         The port number on which to receive data; use 0 to
00047  *                     have the system assign an unused port number
00048  * \param payload_size UDP payload size by default set to 1472 =
00049  *                     (1500 MTU - (8 byte UDP header) - (20 byte IP header))
00050  * \param eof          Interpret zero-length packet as EOF (default: true)
00051  * \param wait         Wait for data if not immediately available
00052  *                     (default: true)
00053  *
00054 */
00055 
00056 class GR_CORE_API gr_udp_source : public gr_sync_block
00057 {
00058   friend GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize,
00059                                                const char *host,
00060                                                unsigned short port,
00061                                                int payload_size,
00062                                                bool eof, bool wait);
00063 
00064  private:
00065   size_t        d_itemsize;
00066   int           d_payload_size;  // maximum transmission unit (packet length)
00067   bool          d_eof;           // zero-length packet is EOF
00068   bool          d_wait;          // wait if data if not immediately available
00069   int           d_socket;        // handle to socket
00070   char *d_temp_buff;    // hold buffer between calls
00071   ssize_t d_residual;   // hold information about number of bytes stored in the temp buffer
00072   size_t d_temp_offset; // point to temp buffer location offset
00073 
00074  protected:
00075   /*!
00076    * \brief UDP Source Constructor
00077    *
00078    * \param itemsize     The size (in bytes) of the item datatype
00079    * \param host         The name or IP address of the receiving host; can be
00080    *                     NULL, None, or "0.0.0.0" to allow reading from any
00081    *                     interface on the host
00082    * \param port         The port number on which to receive data; use 0 to
00083    *                     have the system assign an unused port number
00084    * \param payload_size UDP payload size by default set to 1472 =
00085    *                     (1500 MTU - (8 byte UDP header) - (20 byte IP header))
00086    * \param eof          Interpret zero-length packet as EOF (default: true)
00087    * \param wait         Wait for data if not immediately available
00088    *                     (default: true)
00089    */
00090   gr_udp_source(size_t itemsize, const char *host, unsigned short port,
00091                 int payload_size, bool eof, bool wait);
00092 
00093  public:
00094   ~gr_udp_source();
00095 
00096   /*! \brief return the PAYLOAD_SIZE of the socket */
00097   int payload_size() { return d_payload_size; }
00098 
00099   /*! \brief return the port number of the socket */
00100   int get_port();
00101 
00102   // should we export anything else?
00103 
00104   int work(int noutput_items,
00105            gr_vector_const_void_star &input_items,
00106            gr_vector_void_star &output_items);
00107 };
00108 
00109 
00110 #endif /* INCLUDED_GR_UDP_SOURCE_H */