All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.thrift_cpp.include.tls_provider.body.vm Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
#parse("thrift_cpp/include/cxx_schema_include.vm")
#parse("thrift_cpp/include/service_decorator.include.vm")
#parse("thrift_cpp/include/cxx.helper.vm")
#set( $output_basename = ${thrift_tlsprovider.sampleType})
#set( $output_filename = "${output_basename}.${source_type}")
$codewriter.setCurrentCxxFilename("stub",$output_filename)
$header_begin
/**
 * $GENERAED_BY
* template: $template
* @author guyadong * */ #if( $source_type == "cpp" ) \#include \#include \#include \#include \#include "${output_basename}.h" using namespace apache::thrift; using namespace apache::thrift::protocol; using namespace apache::thrift::transport; using namespace $thrift_ns; static thread_local std::shared_ptr tls_provider_socket; static thread_local std::shared_ptr tls_provider_transport; static thread_local std::shared_ptr tls_provider_protocol; static thread_local std::shared_ptr<${thrift_client.type}> tls_provider_client; static void tlsclear(){ tls_provider_socket = nullptr; tls_provider_transport = nullptr; tls_provider_protocol = nullptr; tls_provider_client = nullptr; } #else \#include "${thrift_clientproviderif.sampleType}.h" #end #pkg_namespace_begin($interfaceClass.package.name) #set($typeClass = ${output_basename}) #if( $source_type == "h" ) /** * 基于线程局部变量(thread local storage)实现 ${thrift_clientproviderif.type} 接口 */ class ${typeClass} : virtual public ${thrift_clientproviderif.sampleType} { private: #end void ${service_method_prefix}makeClient() const$method_declare_suffix #if( $source_type == "cpp" ) { if( nullptr != tls_provider_socket && (tls_provider_socket->getHost()!=host || tls_provider_socket->getPort()!=port)) { tlsclear(); } if (nullptr == tls_provider_socket) { tls_provider_socket = std::make_shared(host, port); if (connTimeout > 0) { tls_provider_socket->setConnTimeout(connTimeout); } if (sendTimeout > 0) { tls_provider_socket->setSendTimeout(sendTimeout); } if (recvTimeout > 0) { tls_provider_socket->setRecvTimeout(recvTimeout); } } if (nullptr == tls_provider_transport) { tls_provider_transport = std::shared_ptr(new TBufferedTransport(tls_provider_socket)); } if (nullptr == tls_provider_protocol) { tls_provider_protocol = std::shared_ptr(new TBinaryProtocol(tls_provider_transport)); } if (nullptr == tls_provider_client) { tls_provider_client = std::make_shared<${thrift_client.type}>(tls_provider_protocol); } } #end## if $source_type $public_modifier // constructor // 根据主机和端口号创建实例 ${service_method_prefix}${typeClass}(const std::string & host, int port)$method_declare_suffix #if( $source_type == "cpp" ) : ${thrift_clientproviderif.sampleType}(host, port) { } #end // destructor ${virtual_modifier}${service_method_prefix}~${typeClass}()$method_declare_suffix #if( $source_type == "cpp" ) { } #end // 重新指定主机和端口号 ${virtual_modifier}void ${service_method_prefix}resetClient(const std::string & host, int port)$method_declare_suffix #if( $source_type == "cpp" ) { ${thrift_clientproviderif.sampleType}::resetClient(host, port); tlsclear(); } #end ${virtual_modifier}${thrift_client.type} & ${service_method_prefix}get() const$method_declare_suffix #if( $source_type == "cpp" ) { makeClient(); return *tls_provider_client; } #end ${virtual_modifier}::apache::thrift::transport::TTransport & ${service_method_prefix}getTransport() const $method_declare_suffix #if( $source_type == "cpp" ) { get(); return *tls_provider_transport; } #end #if( $source_type == "h" ) }; /** class ${typeClass} */ #end #pkg_namespace_end() $header_end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy