11 #ifndef THRIFT_SERVER_TEMPLATE_H
12 #define THRIFT_SERVER_TEMPLATE_H
20 #include "thrift/ControlPort.h"
21 #ifdef THRIFT_HAS_THREADFACTORY_H
22 #include <thrift/concurrency/ThreadFactory.h>
24 #include <thrift/concurrency/PlatformThreadFactory.h>
26 #include <thrift/concurrency/ThreadManager.h>
27 #include <thrift/server/TSimpleServer.h>
28 #include <thrift/server/TThreadPoolServer.h>
29 #include <thrift/transport/TBufferTransports.h>
30 #include <thrift/transport/TServerSocket.h>
34 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
42 TserverBase* i_impl();
46 std::shared_ptr<TserverClass> d_handler;
47 std::shared_ptr<thrift::TProcessor> d_processor;
48 std::shared_ptr<thrift::transport::TServerTransport> d_serverTransport;
49 std::shared_ptr<thrift::transport::TTransportFactory> d_transportFactory;
50 std::shared_ptr<thrift::protocol::TProtocolFactory> d_protocolFactory;
56 class TBufferedTransportFactory :
public thrift::transport::TTransportFactory
59 TBufferedTransportFactory(
const unsigned int _bufferSize)
60 : bufferSize(_bufferSize)
65 virtual ~TBufferedTransportFactory() {}
67 virtual std::shared_ptr<thrift::transport::TTransport>
68 getTransport(std::shared_ptr<thrift::transport::TTransport> trans)
70 return std::shared_ptr<thrift::transport::TTransport>(
71 new thrift::transport::TBufferedTransport(trans, bufferSize));
75 unsigned int bufferSize;
79 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
83 d_handler(new TserverClass()),
84 d_processor(new GNURadio::ControlPortProcessor(d_handler)),
87 d_protocolFactory(new thrift::protocol::TBinaryProtocolFactory())
92 unsigned int port, nthreads, buffersize;
93 std::string thrift_config_file =
96 if (thrift_config_file.length() > 0) {
116 d_serverTransport.reset(
new thrift::transport::TServerSocket(port));
118 d_transportFactory.reset(
119 new thrift_server_template::TBufferedTransportFactory(buffersize));
125 new thrift::server::TSimpleServer(
126 d_processor, d_serverTransport, d_transportFactory, d_protocolFactory));
129 std::shared_ptr<thrift::concurrency::ThreadManager> threadManager(
130 thrift::concurrency::ThreadManager::newSimpleThreadManager(nthreads));
132 #ifdef THRIFT_HAS_THREADFACTORY_H
133 threadManager->threadFactory(std::shared_ptr<thrift::concurrency::ThreadFactory>(
134 new thrift::concurrency::ThreadFactory()));
136 threadManager->threadFactory(
137 std::shared_ptr<thrift::concurrency::PlatformThreadFactory>(
138 new thrift::concurrency::PlatformThreadFactory()));
141 threadManager->start();
144 new thrift::server::TThreadPoolServer(d_processor,
152 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
157 template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
162 return d_handler.get();