23 #ifndef THRIFT_SERVER_TEMPLATE_H
24 #define THRIFT_SERVER_TEMPLATE_H
32 #include <thrift/server/TSimpleServer.h>
33 #include <thrift/server/TThreadPoolServer.h>
34 #include <thrift/concurrency/ThreadManager.h>
35 #include <thrift/concurrency/PlatformThreadFactory.h>
36 #include <thrift/transport/TServerSocket.h>
37 #include <thrift/transport/TBufferTransports.h>
38 #include "thrift/ControlPort.h"
42 template<
typename TserverBase,
typename TserverClass,
typename TImplClass>
50 TserverBase* i_impl();
54 boost::shared_ptr<TserverClass> d_handler;
55 boost::shared_ptr<thrift::TProcessor> d_processor;
56 boost::shared_ptr<thrift::transport::TServerTransport> d_serverTransport;
57 boost::shared_ptr<thrift::transport::TTransportFactory> d_transportFactory;
58 boost::shared_ptr<thrift::protocol::TProtocolFactory> d_protocolFactory;
64 class TBufferedTransportFactory :
public thrift::transport::TTransportFactory
67 TBufferedTransportFactory(
const unsigned int _bufferSize) : bufferSize(_bufferSize) {;}
69 virtual ~TBufferedTransportFactory() {}
71 virtual boost::shared_ptr<thrift::transport::TTransport> getTransport(
72 boost::shared_ptr<thrift::transport::TTransport> trans)
74 return boost::shared_ptr<thrift::transport::TTransport>
75 (
new thrift::transport::TBufferedTransport(trans, bufferSize));
78 unsigned int bufferSize;
82 template<
typename TserverBase,
typename TserverClass,
typename TImplClass>
85 d_handler(new TserverClass()),
86 d_processor(new GNURadio::ControlPortProcessor(d_handler)),
89 d_protocolFactory(new thrift::protocol::TBinaryProtocolFactory())
94 unsigned int port, nthreads, buffersize;
97 if(thrift_config_file.length() > 0) {
104 port =
static_cast<unsigned int>
108 nthreads =
static_cast<unsigned int>
112 buffersize =
static_cast<unsigned int>
117 d_serverTransport.reset(
new thrift::transport::TServerSocket(port));
119 d_transportFactory.reset(
new thrift_server_template::TBufferedTransportFactory(buffersize));
125 (
new thrift::server::TSimpleServer(d_processor, d_serverTransport,
126 d_transportFactory, d_protocolFactory));
130 boost::shared_ptr<thrift::concurrency::ThreadManager> threadManager
131 (thrift::concurrency::ThreadManager::newSimpleThreadManager(nthreads));
133 threadManager->threadFactory
134 (boost::shared_ptr<thrift::concurrency::PlatformThreadFactory>
135 (
new thrift::concurrency::PlatformThreadFactory()));
137 threadManager->start();
140 (
new thrift::server::TThreadPoolServer(d_processor, d_serverTransport,
141 d_transportFactory, d_protocolFactory,
146 template<
typename TserverBase,
typename TserverClass,
typename TImplClass>
151 template<
typename TserverBase,
typename TserverClass,
typename TImplClass>
156 return d_handler.get();
thrift_server_template(TImplClass *_this)
Definition: thrift_server_template.h:83
TserverBase * i_impl()
Definition: thrift_server_template.h:152
Definition: thrift_server_template.h:43
~thrift_server_template()
Definition: thrift_server_template.h:147
static const unsigned int d_default_num_thrift_threads
Definition: thrift_application_base.h:143
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
log4cpp::Category * logger_ptr
GR_LOG macrosThese macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros are: LOG_DEBU...
Definition: logger.h:149
static prefs * singleton()
static const unsigned int d_default_thrift_buffer_size
Definition: thrift_application_base.h:149