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>
41template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
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;
86template <
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,
154template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
159template <
typename TserverBase,
typename TserverClass,
typename TImplClass>
164 return d_handler.get();
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.
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.
void add_config_file(const std::string &configfile)
static prefs * singleton()
Base class for a Thrift application with a singleton with instance function thrift_application_base::...
Definition: thrift_application_base.h:87
Definition: thrift_server_template.h:43
TserverBase * i_impl()
Definition: thrift_server_template.h:160
~thrift_server_template()
Definition: thrift_server_template.h:155
thrift_server_template(TImplClass *_this)
Definition: thrift_server_template.h:87
Definition: thrift_application_base.h:39
void * logger_ptr
Definition: logger.h:696
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string name)