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

templates.thrift_cpp.erpc_proxy.perservice.interface_proxy_server.cpp.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_filename = "${schemainfo.programName}_proxy_server.cpp")
#set( $serviceMetadata = ${sourceinfo.thriftServiceMetadata})
###################
$codewriter.setCurrentCxxFilename($output_filename)
/**
 * eRPC代理服务实现(C++11) 
* C++11 compiler or VS2015 or above required
* $GENERAED_BY
*/ \#include \#include \#include \#include \#include \#include \#include "erpc_setup_server_tcp.h" \#include <${thrift_tlsprovider.sampleType}.h> \#include "${schemainfo.programName}_server.h" using namespace ::gdface; using namespace $cxxhelper.cxxNamespace($interfaceClass,true); std::shared_ptr<${thrift_clientproviderif.sampleType}> clientProvider; bool debug; // client运行参数配置基类 class ClientConfig { public: const int THRIFT_SERVICE_DEFAULT_PORT = $schemainfo.erpcForwardPort; const int PROXY_DEFAULT_PORT = $schemainfo.erpcProxyPort; const std::string DEFAULT_HOST = "localhost"; const std::string PARAM_THRIFT_SERVICE_HOST_NAME = "host"; const std::string PARAM_THRIFT_SERVICE_PORT_NAME = "port"; const std::string PARAM_PROXY_PORT_NAME = "proxy_port"; const std::string PARAM_DEBUG_NAME = "debug"; const std::string PARAM_CONCURRENCY_NAME = "concurrency"; const std::string PARAM_TIMEOUT_NAME = "timeout"; cmdline::parser cmdparam; std::string host; int port = THRIFT_SERVICE_DEFAULT_PORT; int proxyPort = PROXY_DEFAULT_PORT; bool debug = false; size_t concurrency = std::thread::hardware_concurrency(); uint32_t timeout = 0; ClientConfig() { cmdparam.add(PARAM_THRIFT_SERVICE_HOST_NAME, 0, "${schemainfo.programName} service host name", false, DEFAULT_HOST); cmdparam.add(PARAM_THRIFT_SERVICE_PORT_NAME, 0, "${schemainfo.programName} service port number", false, THRIFT_SERVICE_DEFAULT_PORT, cmdline::range(1, 65535)); cmdparam.add(PARAM_PROXY_PORT_NAME, 'p', "proxy port number", false, PROXY_DEFAULT_PORT, cmdline::range(1, 65535)); cmdparam.add(PARAM_DEBUG_NAME, 'd', "output debug message", false, false); cmdparam.add(PARAM_CONCURRENCY_NAME, 'c', "concurrency concurrent thread number for request", false, concurrency, cmdline::range(1, 65535)); cmdparam.add(PARAM_TIMEOUT_NAME, 't', "timeout(millisecond) for socket connecting,sending,receiving,use default value if zero", false, timeout, cmdline::range(1, 65535)); } void parse(int argc, char*argv[]) { auto program_name = get_file_name(argv[0]); cmdparam.set_program_name(program_name); cmdparam.parse_check(argc, argv); afterParse(); } protected: void afterParse() { host = cmdparam.get(PARAM_THRIFT_SERVICE_HOST_NAME); port = cmdparam.get(PARAM_THRIFT_SERVICE_PORT_NAME); proxyPort = cmdparam.get(PARAM_PROXY_PORT_NAME); debug = cmdparam.get(PARAM_DEBUG_NAME); concurrency = cmdparam.get(PARAM_CONCURRENCY_NAME); timeout = cmdparam.get(PARAM_TIMEOUT_NAME); } }; int main(int argc, char *argv[]) { std::cout << "====${schemainfo.programName} eRPC proxy service" << std::endl; ClientConfig param; param.parse(argc, argv); debug = param.debug; printf("====connect ${schemainfo.programName} service:%s:%d timeout %d(mills)\n", param.host.c_str(), param.port,param.timeout); printf("====debug flag:%d\n", debug); clientProvider = std::make_shared<${thrift_tlsprovider.sampleType}>(param.host, param.port); // 创建client端传输层对象(TCP) printf("====eRPC transport tcp init:proxy port:%d\n", param.proxyPort); auto transport = erpc_transport_server_tcp_init("127.0.0.1",param.proxyPort,param.timeout,param.timeout); /* init eRPC server environment */ /* MessageBufferFactory initialization */ erpc_mbf_t message_buffer_factory = erpc_mbf_dynamic_init(); /* eRPC server side initialization */ erpc_concurrency_server_init(transport, message_buffer_factory,param.concurrency); /* connect generated service into server, look into erpcdemo_server.h */ erpc_add_service_to_concurrency_server(create_${interfaceName}_service()); printf("====start ${interfaceName} proxy server\n"); /* run proxy server */ erpc_concurrency_server_run(); /* or erpc_server_poll(); */ /* 关闭socket */ erpc_transport_server_tcp_deinit(); return 0; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy