23#ifndef THRIFT_SERVER_TEMPLATE_H
24#define THRIFT_SERVER_TEMPLATE_H
33#include "thrift/ControlPort.h"
34#ifdef THRIFT_HAS_THREADFACTORY_H
35#include <thrift/concurrency/ThreadFactory.h>
37#include <thrift/concurrency/PlatformThreadFactory.h>
39#include <thrift/concurrency/ThreadManager.h>
40#include <thrift/server/TSimpleServer.h>
41#include <thrift/server/TThreadPoolServer.h>
42#include <thrift/transport/TBufferTransports.h>
43#include <thrift/transport/TServerSocket.h>
47template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
60 typename gr::rpc_sptr<TserverClass>::t d_handler;
61 gr::rpc_sptr<thrift::TProcessor>::t d_processor;
62 gr::rpc_sptr<thrift::transport::TServerTransport>::t d_serverTransport;
63 gr::rpc_sptr<thrift::transport::TTransportFactory>::t d_transportFactory;
64 gr::rpc_sptr<thrift::protocol::TProtocolFactory>::t d_protocolFactory;
70 class TBufferedTransportFactory :
public thrift::transport::TTransportFactory
73 TBufferedTransportFactory(
const unsigned int _bufferSize)
74 : bufferSize(_bufferSize)
79 virtual ~TBufferedTransportFactory() {}
81 virtual gr::rpc_sptr<thrift::transport::TTransport>::t
82 getTransport(gr::rpc_sptr<thrift::transport::TTransport>::t trans)
84 return gr::rpc_sptr<thrift::transport::TTransport>::t(
85 new thrift::transport::TBufferedTransport(trans, bufferSize));
89 unsigned int bufferSize;
93template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
97 d_handler(new TserverClass()),
98 d_processor(new GNURadio::ControlPortProcessor(d_handler)),
100 d_transportFactory(),
101 d_protocolFactory(new
thrift::protocol::TBinaryProtocolFactory())
106 unsigned int port, nthreads, buffersize;
107 std::string thrift_config_file =
110 if (thrift_config_file.length() > 0) {
130 d_serverTransport.reset(
new thrift::transport::TServerSocket(port));
132 d_transportFactory.reset(
133 new thrift_server_template::TBufferedTransportFactory(buffersize));
139 new thrift::server::TSimpleServer(
140 d_processor, d_serverTransport, d_transportFactory, d_protocolFactory));
143 gr::rpc_sptr<thrift::concurrency::ThreadManager>::t threadManager(
144 thrift::concurrency::ThreadManager::newSimpleThreadManager(nthreads));
146#ifdef THRIFT_HAS_THREADFACTORY_H
147 threadManager->threadFactory(gr::rpc_sptr<thrift::concurrency::ThreadFactory>::t(
148 new thrift::concurrency::ThreadFactory()));
150 threadManager->threadFactory(
151 gr::rpc_sptr<thrift::concurrency::PlatformThreadFactory>::t(
152 new thrift::concurrency::PlatformThreadFactory()));
155 threadManager->start();
158 new thrift::server::TThreadPoolServer(d_processor,
166template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
171template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
176 return d_handler.get();
virtual const std::string get_string(const std::string §ion, const std::string &option, const std::string &default_val)
If option exists return associated value; else default_val.
virtual long get_long(const std::string §ion, const std::string &option, long default_val)
If option exists and value can be converted to long, return it; else default_val.
void add_config_file(const std::string &configfile)
static prefs * singleton()
static const unsigned int d_default_thrift_buffer_size
Definition thrift_application_base.h:156
thrift_application_base(TImplClass *_app)
Definition thrift_application_base.h:201
boost::scoped_ptr< apache::thrift::server::TServer > d_thriftserver
Definition thrift_application_base.h:129
static const unsigned int d_default_num_thrift_threads
Definition thrift_application_base.h:150
static const unsigned int d_default_thrift_port
Definition thrift_application_base.h:143
TserverBase * i_impl()
Definition thrift_server_template.h:172
~thrift_server_template()
Definition thrift_server_template.h:167
thrift_server_template(TImplClass *_this)
Definition thrift_server_template.h:94
Definition thrift_application_base.h:40
Definition thrift_application_base.h:39
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string name)
log4cpp::Category * logger_ptr
GR_LOG macros.
Definition logger.h:71