gr-baz Package
baz_tcp_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#ifndef INCLUDED_BAZ_TCP_SINK_H
24#define INCLUDED_BAZ_TCP_SINK_H
25
26#include <gnuradio/sync_block.h>
27#include <gnuradio/thread/thread.h>
28
29#include <gnuradio/sync_block.h>
30#include <gnuradio/msg_queue.h>
31#include <gnuradio/thread/thread.h>
32
34typedef boost::shared_ptr<baz_tcp_sink> baz_tcp_sink_sptr;
35
36BAZ_API baz_tcp_sink_sptr baz_make_tcp_sink (size_t itemsize, const char *host, unsigned short port, bool blocking = true, bool auto_reconnect = false, bool verbose = false);
37
38/*!
39 * \brief Write stream to an TCP socket.
40 * \ingroup sink_blk
41 *
42 * \param itemsize The size (in bytes) of the item datatype
43 * \param host The name or IP address of the receiving host; use
44 * NULL or None for no connection
45 * \param port Destination port to connect to on receiving host
46 */
47
48class BAZ_API baz_tcp_sink : public gr::sync_block
49{
50private:
51 friend BAZ_API baz_tcp_sink_sptr baz_make_tcp_sink (size_t itemsize, const char *host, unsigned short port, bool blocking, bool auto_reconnect, bool verbose);
52 size_t d_itemsize;
53
54 int d_socket; // handle to socket
55 bool d_connected; // are we connected?
56 gr::thread::mutex d_mutex; // protects d_socket and d_connected
57 gr::msg_queue::sptr d_status_queue;
58 bool d_blocking;
59 bool d_auto_reconnect;
60 bool d_verbose;
61 std::string d_last_host;
62 unsigned short d_last_port;
63
64protected:
65 /*!
66 * \brief TCP Sink Constructor
67 *
68 * \param itemsize The size (in bytes) of the item datatype
69 * \param host The name or IP address of the receiving host; use
70 * NULL or None for no connection
71 * \param port Destination port to connect to on receiving host
72 */
73 baz_tcp_sink (size_t itemsize, const char *host, unsigned short port, bool blocking, bool auto_reconnect, bool verbose);
74
75 bool create();
76 void allocate();
77 void destroy();
79
80public:
82
83 /*! \brief Change the connection to a new destination
84 *
85 * \param host The name or IP address of the receiving host; use
86 * NULL or None to break the connection without closing
87 * \param port Destination port to connect to on receiving host
88 *
89 * Calls disconnect() to terminate any current connection first.
90 */
91 bool connect( const char *host, unsigned short port );
92
93 /*! \brief Send zero-length packet (if eof is requested) then stop sending
94 *
95 * Zero-byte packets can be interpreted as EOF by gr_udp_source. Note that
96 * disconnect occurs automatically when the sink is destroyed, but not when
97 * its top_block stops.*/
98 void disconnect();
99
100 void set_status_msgq(gr::msg_queue::sptr queue);
101
102 int send_data(int type, const char* data, int length);
103
104 int work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
105};
106
107#endif /* INCLUDED_BAZ_TCP_SINK_H */
#define BAZ_API
Definition: api.h:19
BAZ_API baz_tcp_sink_sptr baz_make_tcp_sink(size_t itemsize, const char *host, unsigned short port, bool blocking=true, bool auto_reconnect=false, bool verbose=false)
Write stream to an TCP socket.
Definition: baz_tcp_sink.h:49
bool connect(const char *host, unsigned short port)
Change the connection to a new destination.
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
void _disconnect()
void disconnect()
Send zero-length packet (if eof is requested) then stop sending.
void destroy()
friend BAZ_API baz_tcp_sink_sptr baz_make_tcp_sink(size_t itemsize, const char *host, unsigned short port, bool blocking, bool auto_reconnect, bool verbose)
baz_tcp_sink(size_t itemsize, const char *host, unsigned short port, bool blocking, bool auto_reconnect, bool verbose)
TCP Sink Constructor.
void set_status_msgq(gr::msg_queue::sptr queue)
int send_data(int type, const char *data, int length)
void allocate()