1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* -*- c++ -*- */
/*
* Copyright 2015 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include <gnuradio/rpcserver_thrift.h>
#include <gnuradio/rpcserver_booter_thrift.h>
#include <boost/asio/ip/host_name.hpp>
namespace {
static const char* const CONTROL_PORT_CLASS("thrift");
static const unsigned int ETHERNET_HEADER_SIZE(14);
static const unsigned int IP_HEADER_SIZE(20);
static const unsigned int TCP_HEADER_SIZE(32);
static const unsigned int ETHERNET_TYPICAL_MTU(1500);
static const unsigned int ALRIGHT_DEFAULT_BUFFER_SIZE(
ETHERNET_TYPICAL_MTU - ETHERNET_HEADER_SIZE - IP_HEADER_SIZE - TCP_HEADER_SIZE);
};
/*!
* \brief A booter implementation for a Thrift application class.
*/
rpcserver_booter_thrift::rpcserver_booter_thrift() :
thrift_server_template<rpcserver_base,
rpcserver_thrift,
rpcserver_booter_thrift,
boost::shared_ptr<GNURadio::ControlPortIf> >(this),
d_type(std::string(CONTROL_PORT_CLASS))
{;}
rpcserver_booter_thrift::~rpcserver_booter_thrift()
{;}
rpcserver_base*
rpcserver_booter_thrift::i()
{
return thrift_server_template<rpcserver_base, rpcserver_thrift,
rpcserver_booter_thrift,
GNURadio::ControlPortIf>::i();
}
/*!
* \brief Returns the endpoint string for the application
*/
const std::vector<std::string>
rpcserver_booter_thrift::endpoints()
{
return thrift_server_template<rpcserver_base, rpcserver_thrift,
rpcserver_booter_thrift,
GNURadio::ControlPortIf>::endpoints();
}
// Specialized thrift_application_base attributes and functions
// for this rpcserver_booter instance.
template<class rpcserver_base, class rpcserver_booter_thrift>
const unsigned int thrift_application_base<rpcserver_base, rpcserver_booter_thrift>::d_default_max_init_attempts(100U);
template<class rpcserver_base, class rpcserver_booter_thrift>
const unsigned int thrift_application_base<rpcserver_base, rpcserver_booter_thrift>::d_default_thrift_port(0U);
template<class rpcserver_base, class rpcserver_booter_thrift>
const unsigned int thrift_application_base<rpcserver_base, rpcserver_booter_thrift>::d_default_num_thrift_threads(10U);
template<class rpcserver_base, class rpcserver_booter_thrift>
const unsigned int thrift_application_base<rpcserver_base, rpcserver_booter_thrift>::d_default_thrift_buffer_size(
ALRIGHT_DEFAULT_BUFFER_SIZE);
template<class rpcserver_base, class rpcserver_booter_thrift>
std::auto_ptr<thrift_application_base_impl>
thrift_application_base<rpcserver_base, rpcserver_booter_thrift>::p_impl(
new thrift_application_base_impl());
template<class rpcserver_base, class rpcserver_booter_thrift>
thrift_application_base<rpcserver_base, rpcserver_booter_thrift>::~thrift_application_base()
{
GR_LOG_DEBUG(d_debug_logger, "thrift_application_base: shutdown");
if(d_thirft_is_running) {
d_thriftserver->stop();
d_thirft_is_running = false;
}
}
template<class rpcserver_base, class rpcserver_booter_thrift>
void thrift_application_base<rpcserver_base, rpcserver_booter_thrift>::start_thrift()
{
d_thriftserver->serve();
}
template<class rpcserver_base, typename rpcserver_booter_thrift>
bool thrift_application_base<rpcserver_base, rpcserver_booter_thrift>::application_started()
{
if (d_thirft_is_running) return true;
bool result(false);
// Define the endpoint.
apache::thrift::transport::TServerTransport *thetransport =
d_thriftserver->getServerTransport().get();
// Determine the specified endpoint port number, or the port number selected by bind() if
int used_port = ((apache::thrift::transport::TServerSocket*)thetransport)->getPort();
if (used_port > 0) {
// Determine the hostname of this host
const std::string boost_hostname(boost::asio::ip::host_name());
std::string endpoint = boost::str(boost::format("-h %1% -p %2%") % boost_hostname % used_port);
//std::cout << "Thrift endpoint: " << endpoint << " boost hostname: " << boost_hostname << std::endl;
set_endpoint(endpoint);
GR_LOG_INFO(d_logger, "Apache Thrift: " + endpoint);
d_thirft_is_running = true;
result = true;
}
return result;
}
|