23 #ifndef THRIFT_SERVER_TEMPLATE_H 24 #define THRIFT_SERVER_TEMPLATE_H 31 #include <thrift/server/TSimpleServer.h> 32 #include <thrift/server/TThreadPoolServer.h> 33 #include <thrift/concurrency/ThreadManager.h> 34 #include <thrift/concurrency/PlatformThreadFactory.h> 35 #include <thrift/transport/TServerSocket.h> 36 #include <thrift/transport/TBufferTransports.h> 37 #include "thrift/ControlPort.h" 41 template<
typename TserverBase,
typename TserverClass,
typename TImplClass>
49 TserverBase* i_impl();
53 boost::shared_ptr<TserverClass> d_handler;
54 boost::shared_ptr<thrift::TProcessor> d_processor;
55 boost::shared_ptr<thrift::transport::TServerTransport> d_serverTransport;
56 boost::shared_ptr<thrift::transport::TTransportFactory> d_transportFactory;
57 boost::shared_ptr<thrift::protocol::TProtocolFactory> d_protocolFactory;
63 class TBufferedTransportFactory :
public thrift::transport::TTransportFactory
66 TBufferedTransportFactory(
const unsigned int _bufferSize) : bufferSize(_bufferSize) {;}
68 virtual ~TBufferedTransportFactory() {}
70 virtual boost::shared_ptr<thrift::transport::TTransport> getTransport(
71 boost::shared_ptr<thrift::transport::TTransport> trans)
73 return boost::shared_ptr<thrift::transport::TTransport>
74 (
new thrift::transport::TBufferedTransport(trans, bufferSize));
77 unsigned int bufferSize;
81 template<
typename TserverBase,
typename TserverClass,
typename TImplClass>
84 d_handler(new TserverClass()),
85 d_processor(new GNURadio::ControlPortProcessor(d_handler)),
88 d_protocolFactory(new thrift::protocol::TBinaryProtocolFactory())
93 unsigned int port, nthreads, buffersize;
96 if(thrift_config_file.length() > 0) {
103 port =
static_cast<unsigned int> 107 nthreads =
static_cast<unsigned int> 111 buffersize =
static_cast<unsigned int> 116 d_serverTransport.reset(
new thrift::transport::TServerSocket(port));
118 d_transportFactory.reset(
new thrift_server_template::TBufferedTransportFactory(buffersize));
124 (
new thrift::server::TSimpleServer(d_processor, d_serverTransport,
125 d_transportFactory, d_protocolFactory));
129 boost::shared_ptr<thrift::concurrency::ThreadManager> threadManager
130 (thrift::concurrency::ThreadManager::newSimpleThreadManager(nthreads));
132 threadManager->threadFactory
133 (boost::shared_ptr<thrift::concurrency::PlatformThreadFactory>
134 (
new thrift::concurrency::PlatformThreadFactory()));
136 threadManager->start();
139 (
new thrift::server::TThreadPoolServer(d_processor, d_serverTransport,
140 d_transportFactory, d_protocolFactory,
145 template<
typename TserverBase,
typename TserverClass,
typename TImplClass>
150 template<
typename TserverBase,
typename TserverClass,
typename TImplClass>
155 return d_handler.get();
thrift_server_template(TImplClass *_this)
Definition: thrift_server_template.h:82
TserverBase * i_impl()
Definition: thrift_server_template.h:151
Definition: thrift_server_template.h:42
~thrift_server_template()
Definition: thrift_server_template.h:146
static const unsigned int d_default_num_thrift_threads
Definition: thrift_application_base.h:143
void * logger_ptr
Definition: logger.h:696
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. ...
Base class for a Thrift application with a singleton with instance function thrift_application_base::...
Definition: thrift_application_base.h:79
void add_config_file(const std::string &configfile)
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string name)
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.
Definition: thrift_application_base.h:39
static const unsigned int d_default_thrift_port
Definition: thrift_application_base.h:136
static prefs * singleton()
static const unsigned int d_default_thrift_buffer_size
Definition: thrift_application_base.h:149