gr-baz Package

baz_udp_sink.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2007,2008,2009,2010,2013 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
11 *
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#if (!defined(INCLUDED_GR_UDP_SINK_H) && !defined(IN_GR_BAZ)) || (!defined(INCLUDED_BAZ_UDP_SINK_H) && defined(IN_GR_BAZ))
24#ifdef IN_GR_BAZ
25#define INCLUDED_BAZ_UDP_SINK_H
26#else
27#define INCLUDED_GR_UDP_SINK_H
28#endif // IN_GR_BAZ
29
30#include <gnuradio/sync_block.h>
31#include <gnuradio/thread/thread.h>
32
33#ifdef IN_GR_BAZ
34#define UDP_SINK_NAME baz_udp_sink
35#define UDP_SINK_MAKER baz_make_udp_sink
36#define UDP_SINK_SPTR baz_udp_sink_sptr
37#else
38#define UDP_SINK_NAME gr_udp_sink
39#define UDP_SINK_MAKER gr_make_udp_sink
40#define UDP_SINK_SPTR gr_udp_sink_sptr
41#endif // IN_GR_BAZ
42
43#ifndef _TO_STR
44#define _TO_STR(x) #x
45#endif // _TO_STR
46#define UDP_SINK_STRING _TO_STR(UDP_SINK_NAME)
47
48#include <gnuradio/sync_block.h>
49#include <gnuradio/msg_queue.h>
50#include <gnuradio/thread/thread.h>
51
52 class BAZ_API UDP_SINK_NAME;
53 typedef boost::shared_ptr<UDP_SINK_NAME> UDP_SINK_SPTR;
54
55 BAZ_API UDP_SINK_SPTR
56 UDP_SINK_MAKER (size_t itemsize,
57 const char *host, unsigned short port,
58 int payload_size=1472, bool eof=true, bool bor=false);
59
60/*!
61 * \brief Write stream to an UDP socket.
62 * \ingroup sink_blk
63 *
64 * \param itemsize The size (in bytes) of the item datatype
65 * \param host The name or IP address of the receiving host; use
66 * NULL or None for no connection
67 * \param port Destination port to connect to on receiving host
68 * \param payload_size UDP payload size by default set to 1472 =
69 * (1500 MTU - (8 byte UDP header) - (20 byte IP header))
70 * \param eof Send zero-length packet on disconnect
71 */
72
73 class BAZ_API UDP_SINK_NAME : public gr::sync_block
74{
75 friend BAZ_API UDP_SINK_SPTR UDP_SINK_MAKER (size_t itemsize,
76 const char *host,
77 unsigned short port,
78 int payload_size, bool eof, bool bor);
79 private:
80 size_t d_itemsize;
81
82 int d_payload_size; // maximum transmission unit (packet length)
83 bool d_eof; // send zero-length packet on disconnect
84 int d_socket; // handle to socket
85 bool d_connected; // are we connected?
86 gr::thread::mutex d_mutex; // protects d_socket and d_connected
87 bool d_bor;
88 unsigned short d_bor_counter;
89 bool d_bor_first;
90 unsigned char* d_bor_packet;
91 int d_residual;
92 int d_offset;
93 int d_data_length;
94 gr::msg_queue::sptr d_status_queue;
95
96 protected:
97 /*!
98 * \brief UDP Sink Constructor
99 *
100 * \param itemsize The size (in bytes) of the item datatype
101 * \param host The name or IP address of the receiving host; use
102 * NULL or None for no connection
103 * \param port Destination port to connect to on receiving host
104 * \param payload_size UDP payload size by default set to
105 * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header))
106 * \param eof Send zero-length packet on disconnect
107 * \param bor Enable BorIP encapsulation
108 */
109 UDP_SINK_NAME (size_t itemsize,
110 const char *host, unsigned short port,
111 int payload_size, bool eof, bool bor);
112
113 bool create();
114 void allocate();
115 void destroy();
116
117 public:
118 ~UDP_SINK_NAME ();
119
120 /*! \brief return the PAYLOAD_SIZE of the socket */
121 int payload_size() { return d_payload_size; }
122
123 /*! \brief Change the connection to a new destination
124 *
125 * \param host The name or IP address of the receiving host; use
126 * NULL or None to break the connection without closing
127 * \param port Destination port to connect to on receiving host
128 *
129 * Calls disconnect() to terminate any current connection first.
130 */
131 void connect( const char *host, unsigned short port );
132
133 /*! \brief Send zero-length packet (if eof is requested) then stop sending
134 *
135 * Zero-byte packets can be interpreted as EOF by gr_udp_source. Note that
136 * disconnect occurs automatically when the sink is destroyed, but not when
137 * its top_block stops.*/
138 void disconnect();
139
140 void set_borip(bool enable);
141 void set_payload_size(int payload_size);
142 void set_status_msgq(gr::msg_queue::sptr queue);
143
144 int work (int noutput_items,
145 gr_vector_const_void_star &input_items,
146 gr_vector_void_star &output_items);
147};
148
149#endif /* INCLUDED_GR_UDP_SINK_H */
BAZ_API
#define BAZ_API
Definition: api.h:19
UDP_SINK_SPTR
boost::shared_ptr< UDP_SINK_NAME > UDP_SINK_SPTR
Definition: baz_udp_sink.h:53
UDP_SINK_SPTR
#define UDP_SINK_SPTR
Definition: baz_udp_sink.h:40
UDP_SINK_MAKER
#define UDP_SINK_MAKER
Definition: baz_udp_sink.h:39
UDP_SINK_NAME
Write stream to an UDP socket.
Definition: baz_udp_sink.h:74
UDP_SINK_NAME::set_status_msgq
void set_status_msgq(gr::msg_queue::sptr queue)
UDP_SINK_NAME::set_borip
void set_borip(bool enable)
UDP_SINK_NAME::payload_size
int payload_size()
return the PAYLOAD_SIZE of the socket
Definition: baz_udp_sink.h:121
UDP_SINK_NAME::connect
void connect(const char *host, unsigned short port)
Change the connection to a new destination.
UDP_SINK_NAME::set_payload_size
void set_payload_size(int payload_size)
UDP_SINK_NAME::disconnect
void disconnect()
Send zero-length packet (if eof is requested) then stop sending.
UDP_SINK_NAME::create
bool create()
UDP_SINK_NAME::destroy
void destroy()
UDP_SINK_NAME::allocate
void allocate()
UDP_SINK_NAME::UDP_SINK_MAKER
friend BAZ_API UDP_SINK_SPTR UDP_SINK_MAKER(size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof, bool bor)
UDP_SINK_NAME::~UDP_SINK_NAME
~UDP_SINK_NAME()
UDP_SINK_NAME::work
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
UDP_SINK_NAME::UDP_SINK_NAME
UDP_SINK_NAME(size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof, bool bor)
UDP Sink Constructor.