summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/include/gnuradio/thrift_server_template.h
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-runtime/include/gnuradio/thrift_server_template.h')
-rw-r--r--gnuradio-runtime/include/gnuradio/thrift_server_template.h87
1 files changed, 40 insertions, 47 deletions
diff --git a/gnuradio-runtime/include/gnuradio/thrift_server_template.h b/gnuradio-runtime/include/gnuradio/thrift_server_template.h
index 1e9059d920..b8f5448fdc 100644
--- a/gnuradio-runtime/include/gnuradio/thrift_server_template.h
+++ b/gnuradio-runtime/include/gnuradio/thrift_server_template.h
@@ -39,7 +39,7 @@
using namespace apache;
-template<typename TserverBase, typename TserverClass, typename TImplClass, typename TThriftClass>
+template<typename TserverBase, typename TserverClass, typename TImplClass>
class thrift_server_template : public thrift_application_base<TserverBase, TImplClass>
{
public:
@@ -50,9 +50,12 @@ protected:
TserverBase* i_impl();
friend class thrift_application_base<TserverBase, TImplClass>;
- TserverBase* d_server;
-
private:
+ boost::shared_ptr<TserverClass> d_handler;
+ boost::shared_ptr<thrift::TProcessor> d_processor;
+ boost::shared_ptr<thrift::transport::TServerTransport> d_serverTransport;
+ boost::shared_ptr<thrift::transport::TTransportFactory> d_transportFactory;
+ boost::shared_ptr<thrift::protocol::TProtocolFactory> d_protocolFactory;
/**
* Custom TransportFactory that allows you to override the default Thrift buffer size
* of 512 bytes.
@@ -76,9 +79,14 @@ private:
};
};
-template<typename TserverBase, typename TserverClass, typename TImplClass, typename TThriftClass>
-thrift_server_template<TserverBase, TserverClass, TImplClass, TThriftClass>::thrift_server_template
-(TImplClass* _this) : thrift_application_base<TserverBase, TImplClass>(_this)
+template<typename TserverBase, typename TserverClass, typename TImplClass>
+thrift_server_template<TserverBase, TserverClass, TImplClass>::thrift_server_template
+(TImplClass* _this) : thrift_application_base<TserverBase, TImplClass>(_this),
+d_handler(new TserverClass()),
+d_processor(new GNURadio::ControlPortProcessor(d_handler)),
+d_serverTransport(),
+d_transportFactory(),
+d_protocolFactory(new thrift::protocol::TBinaryProtocolFactory())
{
gr::logger_ptr logger, debug_logger;
gr::configure_default_loggers(logger, debug_logger, "controlport");
@@ -87,74 +95,59 @@ thrift_server_template<TserverBase, TserverClass, TImplClass, TThriftClass>::thr
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);
+ gr::prefs::singleton()->add_config_file(thrift_config_file);
}
// Collect configuration options from the Thrift config file;
// defaults if the config file doesn't exist or list the specific
// options.
port = static_cast<unsigned int>(gr::prefs::singleton()->get_long("thrift", "port",
- thrift_application_base<TserverBase, TImplClass>::d_default_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));
+ thrift_application_base<TserverBase, TImplClass>::d_default_num_thrift_threads));
buffersize = static_cast<unsigned int>(gr::prefs::singleton()->get_long("thrift", "buffersize",
- thrift_application_base<TserverBase, TImplClass>::d_default_thrift_buffer_size));
-
- boost::shared_ptr<TserverClass> handler(new TserverClass());
-
- boost::shared_ptr<thrift::TProcessor>
- processor(new GNURadio::ControlPortProcessor(handler));
+ thrift_application_base<TserverBase, TImplClass>::d_default_thrift_buffer_size));
- boost::shared_ptr<thrift::transport::TServerTransport>
- serverTransport(new thrift::transport::TServerSocket(port));
+ d_serverTransport.reset(new thrift::transport::TServerSocket(port));
- boost::shared_ptr<thrift::transport::TTransportFactory>
- transportFactory(new thrift_server_template::TBufferedTransportFactory(buffersize));
-
- boost::shared_ptr<thrift::protocol::TProtocolFactory>
- protocolFactory(new thrift::protocol::TBinaryProtocolFactory());
+ d_transportFactory.reset(new thrift_server_template::TBufferedTransportFactory(buffersize));
if(nthreads <= 1) {
- // "Thrift: Single-threaded server"
- //std::cout << "Thrift Single-threaded server" << std::endl;
- thrift_application_base<TserverBase, TImplClass>::d_thriftserver.reset(
- new thrift::server::TSimpleServer(processor, serverTransport,
- transportFactory, protocolFactory));
+ // "Thrift: Single-threaded server"
+ //std::cout << "Thrift Single-threaded server" << std::endl;
+ thrift_application_base<TserverBase, TImplClass>::d_thriftserver.reset(
+ new thrift::server::TSimpleServer(d_processor, d_serverTransport, d_transportFactory, d_protocolFactory));
}
else {
- //std::cout << "Thrift Multi-threaded server : " << nthreads << std::endl;
- boost::shared_ptr<thrift::concurrency::ThreadManager> threadManager
- (thrift::concurrency::ThreadManager::newSimpleThreadManager(nthreads));
-
- boost::shared_ptr<thrift::concurrency::PlatformThreadFactory> threadFactory
- (boost::shared_ptr<thrift::concurrency::PlatformThreadFactory>
- (new thrift::concurrency::PlatformThreadFactory()));
+ //std::cout << "Thrift Multi-threaded server : " << d_nthreads << std::endl;
+ boost::shared_ptr<thrift::concurrency::ThreadManager> threadManager(
+ thrift::concurrency::ThreadManager::newSimpleThreadManager(nthreads));
- threadManager->threadFactory(threadFactory);
+ threadManager->threadFactory(
+ boost::shared_ptr<thrift::concurrency::PlatformThreadFactory>(
+ new thrift::concurrency::PlatformThreadFactory()));
- threadManager->start();
+ threadManager->start();
- thrift_application_base<TserverBase, TImplClass>::d_thriftserver.reset(
- new thrift::server::TThreadPoolServer(processor, serverTransport,
- transportFactory, protocolFactory,
- threadManager));
+ thrift_application_base<TserverBase, TImplClass>::d_thriftserver.reset(
+ new thrift::server::TThreadPoolServer(d_processor, d_serverTransport,
+ d_transportFactory, d_protocolFactory,
+ threadManager));
}
-
- d_server = handler.get();
}
-template<typename TserverBase, typename TserverClass, typename TImplClass, typename TThriftClass>
-thrift_server_template<TserverBase, TserverClass,TImplClass, TThriftClass>::~thrift_server_template()
+template<typename TserverBase, typename TserverClass, typename TImplClass>
+thrift_server_template<TserverBase, TserverClass,TImplClass>::~thrift_server_template()
{
}
-template<typename TserverBase, typename TserverClass, typename TImplClass, typename TThriftClass>
-TserverBase* thrift_server_template<TserverBase, TserverClass, TImplClass, TThriftClass>::i_impl()
+template<typename TserverBase, typename TserverClass, typename TImplClass>
+TserverBase* thrift_server_template<TserverBase, TserverClass, TImplClass>::i_impl()
{
//std::cerr << "thrift_server_template: i_impl" << std::endl;
- return d_server;
+ return d_handler.get();
}
#endif /* THRIFT_SERVER_TEMPLATE_H */