diff options
author | Tom Rondeau <tom@trondeau.com> | 2015-03-02 13:49:27 -0500 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2015-04-02 15:38:57 -0700 |
commit | a0afbb52d456a93c58a693d52500a200358e6bd3 (patch) | |
tree | b3c26a9e280057229a80b05c2cb5f835b0f9ef5c | |
parent | 7bdd6effd7b6b36ea8d86cb57329a20874fb3290 (diff) |
controlport: Adds ability to configure Thrift through a config file
Checks GNU Radio's preference files for [ControlPort] config option to point to a file name. That file is the same prefs structure with [Thrift] and key value pairs such as "port = 9090" to set config specific to Thrift.
6 files changed, 54 insertions, 7 deletions
diff --git a/gnuradio-runtime/include/gnuradio/thrift_application_base.h b/gnuradio-runtime/include/gnuradio/thrift_application_base.h index 120e7e9839..a2fc926da4 100644 --- a/gnuradio-runtime/include/gnuradio/thrift_application_base.h +++ b/gnuradio-runtime/include/gnuradio/thrift_application_base.h @@ -74,6 +74,7 @@ protected: apache::thrift::server::TServer* d_thriftserver; + static const unsigned int d_default_thrift_port; static const unsigned int d_default_num_thrift_threads; private: diff --git a/gnuradio-runtime/include/gnuradio/thrift_server_template.h b/gnuradio-runtime/include/gnuradio/thrift_server_template.h index 31c1316c63..57316582ed 100644 --- a/gnuradio-runtime/include/gnuradio/thrift_server_template.h +++ b/gnuradio-runtime/include/gnuradio/thrift_server_template.h @@ -23,6 +23,7 @@ #ifndef THRIFT_SERVER_TEMPLATE_H #define THRIFT_SERVER_TEMPLATE_H +#include <gnuradio/prefs.h> #include <gnuradio/rpcserver_thrift.h> #include <gnuradio/thrift_application_base.h> #include <iostream> @@ -97,31 +98,49 @@ thrift_server_template<TserverBase, TserverClass, TImplClass, TThriftClass>::thr { //std::cerr << "thrift_server_template: ctor" << std::endl; + unsigned int port, nthreads, buffersize; + std::string thrift_config_file = gr::prefs::singleton()->get_string("ControlPort", "config", ""); + + if(thrift_config_file.length() > 0) { + gr::prefs::singleton()->add_config_file(thrift_config_file); + port = static_cast<unsigned int>(gr::prefs::singleton()->get_long("thrift", "port", + thrift_application_base<TserverBase, TImplClass>::d_default_thrift_port)); + nthreads = static_cast<unsigned int>(gr::prefs::singleton()->get_long("thrift", "nthreads", + thrift_application_base<TserverBase, TImplClass>::d_default_num_thrift_threads)); + buffersize = static_cast<unsigned int>(gr::prefs::singleton()->get_long("thrift", "buffersize", + ALRIGHT_DEFAULT_BUFFER_SIZE)); + } + else { + port = thrift_application_base<TserverBase, TImplClass>::d_default_thrift_port; + nthreads = thrift_application_base<TserverBase, TImplClass>::d_default_num_thrift_threads; + buffersize = ALRIGHT_DEFAULT_BUFFER_SIZE; + } + boost::shared_ptr<TserverClass> handler(new TserverClass()); boost::shared_ptr<thrift::TProcessor> processor(new GNURadio::ControlPortProcessor(handler)); boost::shared_ptr<thrift::transport::TServerTransport> - serverTransport(new thrift::transport::TServerSocket(9090)); + serverTransport(new thrift::transport::TServerSocket(port)); boost::shared_ptr<thrift::transport::TTransportFactory> - transportFactory(new thrift_server_template::TBufferedTransportFactory()); + transportFactory(new thrift_server_template::TBufferedTransportFactory(buffersize)); boost::shared_ptr<thrift::protocol::TProtocolFactory> protocolFactory(new thrift::protocol::TBinaryProtocolFactory()); - if(thrift_application_base<TserverBase, TImplClass>::d_default_num_thrift_threads <= 1) { + + if(nthreads <= 1) { // "Thrift: Single-threaded server" thrift_application_base<TserverBase, TImplClass>::d_thriftserver = new thrift::server::TSimpleServer(processor, serverTransport, transportFactory, protocolFactory); } else { - // std::cout << "Thrift Multi-threaded server : " << d_default_num_thrift_threads << std::endl; + // std::cout << "Thrift Multi-threaded server : " << nthreads << std::endl; boost::shared_ptr<thrift::concurrency::ThreadManager> threadManager - (thrift::concurrency::ThreadManager::newSimpleThreadManager - (thrift_application_base<TserverBase, TImplClass>::d_default_num_thrift_threads)); + (thrift::concurrency::ThreadManager::newSimpleThreadManager(nthreads)); boost::shared_ptr<thrift::concurrency::PlatformThreadFactory> threadFactory (boost::shared_ptr<thrift::concurrency::PlatformThreadFactory> diff --git a/gnuradio-runtime/lib/controlport/CMakeLists.txt b/gnuradio-runtime/lib/controlport/CMakeLists.txt index 72d032121b..30b0671cf3 100644 --- a/gnuradio-runtime/lib/controlport/CMakeLists.txt +++ b/gnuradio-runtime/lib/controlport/CMakeLists.txt @@ -73,6 +73,14 @@ list(APPEND gnuradio_runtime_libs ${THRIFT_LIBRARIES} ) +# Add install rule to move example Thrift configuration file into +# $prefix/etc/gnuradio +install( + FILES ${CMAKE_CURRENT_SOURCE_DIR}/thrift/thrift.conf.example + DESTINATION ${SYSCONFDIR}/${CMAKE_PROJECT_NAME} + COMPONENT "runtime_runtime" +) + endif(THRIFT_FOUND) endif(ENABLE_CTRLPORT_THRIFT) diff --git a/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc b/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc index 2d1ac52934..a2b3e54aec 100644 --- a/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc +++ b/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc @@ -58,6 +58,9 @@ rpcserver_booter_thrift::endpoints() } template<typename TserverBase, typename TserverClass> +const unsigned int thrift_application_base<TserverBase, TserverClass>::d_default_thrift_port(9090U); + +template<typename TserverBase, typename TserverClass> const unsigned int thrift_application_base<TserverBase, TserverClass>::d_default_num_thrift_threads(10U); template<typename TserverBase, typename TserverClass> diff --git a/gnuradio-runtime/lib/controlport/thrift/thrift.conf.example b/gnuradio-runtime/lib/controlport/thrift/thrift.conf.example new file mode 100644 index 0000000000..71cc506249 --- /dev/null +++ b/gnuradio-runtime/lib/controlport/thrift/thrift.conf.example @@ -0,0 +1,4 @@ +[thrift] +port = 9090 +nthreads = 2 +buffersize = 1434 diff --git a/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnectionThrift.py b/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnectionThrift.py index f086b85834..f662a66c90 100644 --- a/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnectionThrift.py +++ b/gnuradio-runtime/python/gnuradio/ctrlport/RPCConnectionThrift.py @@ -26,6 +26,7 @@ from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from gnuradio.ctrlport.GNURadio import ControlPort from gnuradio.ctrlport import RPCConnection +from gnuradio import gr import sys class ThriftRadioClient: @@ -64,8 +65,19 @@ class RPCConnectionThrift(RPCConnection.RPCConnection): self.BaseTypes = ttypes.BaseTypes self.KnobBase = ttypes.KnobBase + # If not set by the user, get the port number from the thrift + # config file, if one is set. Defaults to 9090 otherwise. if port is None: - port = 9090 + p = gr.prefs() + thrift_config_file = p.get_string("ControlPort", "config", ""); + if(len(thrift_config_file) > 0): + p.add_config_file(thrift_config_file) + port = p.get_long("thrift", "port", 9090) + else: + port = 9090 + else: + port = int(port) + super(RPCConnectionThrift, self).__init__(method='thrift', port=port, host=host) self.newConnection(host, port) |