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();