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

templates.thrift_cpp.erpc_proxy.perservice.interface_proxy_impl.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}_server_impl.cpp")
#set( $serviceMetadata = ${sourceinfo.thriftServiceMetadata})
###########################
#define($use_pointer)#if(!${e.enum} && !${e.canPrimitive} && !${e.erpcType.protocolType.string})*#end#end
###########################
#define($return_or_void)##
#if(!$TOOL.isVoid($method.returnType)), ${sourceinfo.getThriftMethodMetadata($method).erpcReturnType.getCtype(false,true)} _return#end
#end
###################
#define($def_return_if_byref)
#if(!$TOOL.isVoid($method.returnType))
  #cxxStubType(${method.genericReturnType}) _r;
#end###if(!$TOOL.isVoid($method.returnType))
#end##define($def_return_if_byref)
###################
#define($init_return_if_novoid)
    _err_msg[0] = '\0';
#if(!$TOOL.isVoid($method.returnType))
#if(${methodMetadata.erpcReturnType.protocolType.string})
    _return[0] = '\0';
#elseif(${methodMetadata.erpcReturnType.protocolType.struct})
    init_${sourceinfo.getThriftMethodMetadata($method).erpcReturnType.ctype}(_return);
#elseif(${methodMetadata.erpcReturnType.protocolType.list})
    init_${sourceinfo.getThriftMethodMetadata($method).erpcReturnType.ctype}(_return);
#elseif(${methodMetadata.erpcReturnType.protocolType.binary})
    init_binary_t(_return);
#end
#end###if(!$TOOL.isVoid($method.returnType))
#end##define($init_return_if_novoid)
##########################
#define($service_return_param_i)##
#set($_ret = ${method.genericReturnType})
#if(!$TOOL.isVoid($_ret))##
#set($cxxType = ${cxxhelper.getCxxType($_ret)})
#if(${cxxType.needCast} || ${cxxType.uiType.canMove})_r##
#if($method.parameters.size() != 0),
#end#end##
#end##
#end
###################
#define($cast_return)
#if($TOOL.isVoid($method.returnType))
    if(debug){
      std::cout << "$!{portPrefix}${portName} NO return" << std::endl;
    }
#else
#if(${methodMetadata.erpcReturnType.protocolType.string})
    cast(_r,_return,#if($methodMetadata.maxSize > 0)$methodMetadata.maxSize#{else}DEFAULT_MAX_LENGTH#end);
    if(debug){
      std::cout << "$!{portPrefix}${portName} return :" << _return << std::endl;
    }
#else
    cast(_r,*_return);
    if(debug){
#if($method.returnType.primitive)
      std::cout << "$!{portPrefix}${portName} return :" << *_return << std::endl;
#else
      std::cout << "$!{portPrefix}${portName} return :" << _return << std::endl;
#end
    }
#end
#end
#end###define($cast_return)
###################
#define($service_method_return_i)##
#set($_ret = ${method.genericReturnType})
#if(!$TOOL.isVoid($_ret))##
#set($cxxType = ${cxxhelper.getCxxType($_ret)})
#if(!${cxxType.stubType.canMove} && !${cxxType.needCast})##
_r = ##
#end##
#end##
#end###define($service_method_return_i)
###################
#define($checknotnull)
    throw_if_null(_err_msg);
#if(!$TOOL.isVoid(${method.genericReturnType}))
    throw_if_null(_return);
#end
#end###define($checknotnull)
###################
$codewriter.setCurrentCxxFilename($output_filename)
/**
 * 基于 thrift stub 的 $interfaceName  接口eRPC代理实现(C++11) 
* C++11 compiler or VS2015 or above required
* $GENERAED_BY
*/ \#include \#include \#include \#include \#include \#include \#include <${thrift_tlsprovider.sampleType}.h> \#include "${schemainfo.programName}.h" \#include "${schemainfo.programName}_server.h" \#include "${schemainfo.programName}_erpc_cast.h" \#include "${schemainfo.programName}_erpc_output.h" \#include "${schemainfo.programName}_erpc_mem.h" using namespace net::gdface::utils; using namespace $cxxhelper.cxxNamespace($interfaceClass,true); extern std::shared_ptr<${thrift_clientproviderif.sampleType}> clientProvider; extern bool debug; static void fill_error_message(const std::exception *e,char *_output,size_t output_size) { if(_output && output_size > 0){ std::snprintf((char*)_output,output_size,"%s:%s",typeid(e).name(),e->what()); } if(debug){ std::printf("%s:%s\n",typeid(e).name(),e->what()); } } // 创建TTransport的RAII对象,用于自动执行open/close动作 static ::gdface::raii raii_transport(const std::shared_ptr<${thrift_clientproviderif.sampleType}>& provider) { return ::gdface::make_raii(provider->getTransport(), &::apache::thrift::transport::TTransport::close, &::apache::thrift::transport::TTransport::open); } #set($portPrefix = $schemainfo.portPrefix) #foreach ($method in $TOOL.sortByPortName($methods)) #set ($declaredExceptions = $TOOL.sortByName($method.genericExceptionTypeSet)) #set ($throwExceptions = $declaredExceptions) #set ($methodMetadata = ${sourceinfo.getThriftMethodMetadata($method)}) #set ($paramsMetadata = ${sourceinfo.getParameterMetadata($method)}) #set ($portName = "${method.name}${sourceinfo.methodSuffix($method)}") ErpcProxyReturnCode_t $!{portPrefix}${portName}(char * _err_msg$return_or_void## #join(${paramsMetadata} ', $e.renderParameter()' '')) { if(debug){ std::cout << "thread id:" << std::this_thread::get_id() << " "; #if($method.parameters.size() != 0) std::cout << "$!{portPrefix}${portName} input parameters:" << std::endl; #foreach($e in $paramsMetadata) #if($e.pointer && $e.erpcType.protocolType.string) if($e.name) { std::cout << "$e.name=[" << $e.name << "]" << std::endl; } else { std::cout << "$e.name=[]" << std::endl; } #else std::cout << "$e.name=[" << $e.name << "]" << std::endl; #end #end###foreach($e in $paramsMetadata) #else std::cout << "$!{portPrefix}${portName} NO input parameters" << std::endl; #end } $def_return_if_byref## try{ $checknotnull## $init_return_if_novoid## auto raii = raii_transport(clientProvider); ${service_method_return_i}clientProvider->get().${portName}($!{service_return_param_i}## #join(${paramsMetadata} ' cast($e.name,(#cxxStubType($e.erpcType.javaType) *)nullptr)' ', ')); $cast_return## return ErpcProxyReturnCode_SUCCESS_c; } #foreach($exp in $throwExceptions) catch(${cxxhelper.getCxxType($exp).stubType.type} &e){ fill_error_message(&e,_err_msg,ERRMSG_MAX_LENGTH); return ErpcProxyReturnCode_${exp.simpleName}_c; } #end catch(${cxxhelper.getCxxType($schemainfo.serviceRuntimeExceptionClass).stubType.type} &e){ fill_error_message(&e,_err_msg,ERRMSG_MAX_LENGTH); return ErpcProxyReturnCode_${schemainfo.serviceRuntimeExceptionClass.simpleName}_c; } catch (::apache::thrift::TApplicationException &e) { fill_error_message(&e,_err_msg,ERRMSG_MAX_LENGTH); #if(${cxxhelper.getCxxType(${method.genericReturnType}).stubType.byReference}) if (e.getType() == ::apache::thrift::TApplicationException::TApplicationExceptionType::MISSING_RESULT) { return ErpcProxyReturnCode_EMPTY_REPLY_c; } #end return ErpcProxyReturnCode_THRIFT_ERROR_c; } catch (::apache::thrift::TException &e) { fill_error_message(&e,_err_msg,ERRMSG_MAX_LENGTH); return ErpcProxyReturnCode_THRIFT_ERROR_c; } catch (std::bad_alloc &e) { fill_error_message(&e,_err_msg,ERRMSG_MAX_LENGTH); return ErpcProxyReturnCode_MEMORY_ERROR_c; } catch (std::invalid_argument &e) { fill_error_message(&e,_err_msg,ERRMSG_MAX_LENGTH); return ErpcProxyReturnCode_INVALID_ARGUMENT_c; } catch (std::exception &e) { fill_error_message(&e,_err_msg,ERRMSG_MAX_LENGTH); return ErpcProxyReturnCode_FAIL_c; } catch (...) { return ErpcProxyReturnCode_RUNTIME_ERROR_c; } } #end##foreach $method




© 2015 - 2025 Weber Informatics LLC | Privacy Policy