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> 47 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
55 TserverBase* i_impl();
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;
93 template <
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,
166 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
171 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
176 return d_handler.get();
thrift_server_template(TImplClass *_this)
Definition: thrift_server_template.h:94
TserverBase * i_impl()
Definition: thrift_server_template.h:172
Definition: thrift_server_template.h:48
~thrift_server_template()
Definition: thrift_server_template.h:167
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:86
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
log4cpp::Category * logger_ptr
GR_LOG macrosThese macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros are: LOG_DEBU...
Definition: logger.h:71
static prefs * singleton()