23 #ifndef THRIFT_SERVER_TEMPLATE_H
24 #define THRIFT_SERVER_TEMPLATE_H
31 #include "thrift/ControlPort.h"
32 #include <thrift/concurrency/PlatformThreadFactory.h>
33 #include <thrift/concurrency/ThreadManager.h>
34 #include <thrift/server/TSimpleServer.h>
35 #include <thrift/server/TThreadPoolServer.h>
36 #include <thrift/transport/TBufferTransports.h>
37 #include <thrift/transport/TServerSocket.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)
67 : bufferSize(_bufferSize)
72 virtual ~TBufferedTransportFactory() {}
74 virtual boost::shared_ptr<thrift::transport::TTransport>
75 getTransport(boost::shared_ptr<thrift::transport::TTransport> trans)
77 return boost::shared_ptr<thrift::transport::TTransport>(
78 new thrift::transport::TBufferedTransport(trans, bufferSize));
82 unsigned int bufferSize;
86 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
90 d_handler(new TserverClass()),
91 d_processor(new GNURadio::ControlPortProcessor(d_handler)),
94 d_protocolFactory(new thrift::protocol::TBinaryProtocolFactory())
99 unsigned int port, nthreads, buffersize;
100 std::string thrift_config_file =
103 if (thrift_config_file.length() > 0) {
123 d_serverTransport.reset(
new thrift::transport::TServerSocket(port));
125 d_transportFactory.reset(
126 new thrift_server_template::TBufferedTransportFactory(buffersize));
132 new thrift::server::TSimpleServer(
133 d_processor, d_serverTransport, d_transportFactory, d_protocolFactory));
136 boost::shared_ptr<thrift::concurrency::ThreadManager> threadManager(
137 thrift::concurrency::ThreadManager::newSimpleThreadManager(nthreads));
139 threadManager->threadFactory(
140 boost::shared_ptr<thrift::concurrency::PlatformThreadFactory>(
141 new thrift::concurrency::PlatformThreadFactory()));
143 threadManager->start();
146 new thrift::server::TThreadPoolServer(d_processor,
154 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
159 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
164 return d_handler.get();