gr_udp_source.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007,2008 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_sync_block.h>
00027 #include <omnithread.h>
00028 #if defined(HAVE_SOCKET)
00029 #include <sys/socket.h>
00030 #include <arpa/inet.h>
00031 #elif defined(HAVE_WINDOWS_H)
00032 #include <winsock2.h>
00033 #include <windows.h>
00034 #endif
00035 #if defined(HAVE_NETINET_IN_H)
00036 #include <netinet/in.h>
00037 #endif
00038 
00039 class gr_udp_source;
00040 typedef boost::shared_ptr<gr_udp_source> gr_udp_source_sptr;
00041 
00042 gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, 
00043                                       unsigned short port_src, int payload_size=1472);
00044 
00058 class gr_udp_source : public gr_sync_block
00059 {
00060   friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, 
00061                                                unsigned short port_src, int payload_size);
00062 
00063  private:
00064   size_t        d_itemsize;
00065   bool          d_updated;
00066   omni_mutex    d_mutex;
00067 
00068   int            d_payload_size;  // maximum transmission unit (packet length)
00069   int            d_socket;        // handle to socket
00070   int            d_socket_rcv;    // handle to socket retuned in the accept call
00071   struct in_addr d_ip_src;        // store the source IP address to use
00072   unsigned short d_port_src;      // the port number to open for connections to this service
00073   struct sockaddr_in    d_sockaddr_src;  // store the source sockaddr data (formatted IP address and port number)
00074   char *d_temp_buff;    // hold buffer between calls
00075   ssize_t d_residual;   // hold information about number of bytes stored in the temp buffer
00076   size_t d_temp_offset; // point to temp buffer location offset
00077 
00078  protected:
00089   gr_udp_source(size_t itemsize, const char *src, unsigned short port_src, int payload_size);
00090 
00091  public:
00092   ~gr_udp_source();
00093 
00100   bool open();
00101 
00107   void close();
00108 
00110   int payload_size() { return d_payload_size; }
00111 
00112   // should we export anything else?
00113 
00114   int work(int noutput_items,
00115            gr_vector_const_void_star &input_items,
00116            gr_vector_void_star &output_items);
00117 };
00118 
00119 
00120 #endif /* INCLUDED_GR_UDP_SOURCE_H */

Generated on Thu Mar 5 09:01:12 2009 for GNU Radio 3.1.3 by  doxygen 1.5.8