commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 21/50: controlport: Adds ability to configu


From: git
Subject: [Commit-gnuradio] [gnuradio] 21/50: controlport: Adds ability to configure Thrift through a config file
Date: Wed, 15 Apr 2015 21:07:54 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit a0afbb52d456a93c58a693d52500a200358e6bd3
Author: Tom Rondeau <address@hidden>
Date:   Mon Mar 2 13:49:27 2015 -0500

    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.
---
 .../include/gnuradio/thrift_application_base.h     |  1 +
 .../include/gnuradio/thrift_server_template.h      | 31 +++++++++++++++++-----
 gnuradio-runtime/lib/controlport/CMakeLists.txt    |  8 ++++++
 .../controlport/thrift/rpcserver_booter_thrift.cc  |  3 +++
 .../lib/controlport/thrift/thrift.conf.example     |  4 +++
 .../gnuradio/ctrlport/RPCConnectionThrift.py       | 14 +++++++++-
 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 120e7e9..a2fc926 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 31c1316..5731658 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 72d0321..30b0671 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 2d1ac52..a2b3e54 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 0000000..71cc506
--- /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 f086b85..f662a66 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)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]