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>
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();
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.
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.
static prefs * singleton()
void add_config_file(const std::string &configfile)
Base class for a Thrift application with a singleton with instance function thrift_application_base::...
Definition: thrift_application_base.h:76
Definition: thrift_server_template.h:36
TserverBase * i_impl()
Definition: thrift_server_template.h:158
~thrift_server_template()
Definition: thrift_server_template.h:153
thrift_server_template(TImplClass *_this)
Definition: thrift_server_template.h:80
Definition: thrift_application_base.h:28
std::shared_ptr< logger > logger_ptr
Definition: logger.h:250
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string &name)