一. 代码范例
从CommonAPI自带的HelloworldClient来示范:
int main() {
...
std::shared_ptr<HelloWorldProxy<>> myProxy =
runtime->buildProxy<HelloWorldProxy>("local", "test"); // 此处返回的是绑定层的HelloWorldSomeIPProxy,具体看buildProxy实现
CommonAPI::CallStatus callStatus;
std::string returnMessage;
myProxy->sayHello("Bob", callStatus, returnMessage);
...
}
可以看到,在上面的代码中, “Bob”是SomeIP的sayHello这个Method方法的参数,因此在发送sayHello的REQUEST报文的时候,“Bob”需要被序列化到报文的payload中,这部分工作应该是在HelloWorldSomeIPProxy的sayHello函数中完成的:
void HelloWorldSomeIPProxy::sayHello(std::string _name, CommonAPI::CallStatus &_internalCallStatus, std::string &_message, const CommonAPI::CallInfo *_info) {
CommonAPI::Deployable< std::string, CommonAPI::SomeIP::StringDeployment> deploy_name(_name, static_cast< CommonAPI::SomeIP::StringDeployment* >(nullptr)); // 输入参数name
CommonAPI::Deployable< std::string, CommonAPI::SomeIP::StringDeployment> deploy_message(static_cast< CommonAPI::SomeIP::StringDeployment* >(nullptr)); // 返回参数message
CommonAPI::SomeIP::ProxyHelper<...>::callMethodWithReply( // 调用CommonAPI Someip绑定层的接口发送REQUEST报文
*this,
CommonAPI::SomeIP::method_id_t(0x7b),
false,
false,
(_info ? _info : &CommonAPI::SomeIP::defaultCallInfo),
deploy_name, // 输入参数(Deployable类型),需要序列化到payload中
_internalCa

最低0.47元/天 解锁文章
1829

被折叠的 条评论
为什么被折叠?



