当前位置: 首页 > news >正文

vsomeip用到的socket

概述:

​ vsomeip用到的socket的代码全部都在implementation\endpoints目录下面,主要分布在下面六个endpoint类中:

local_client_endpoint_impl  // 本地客户端socket(UDS Socket或者127.0.0.1的socket)local_server_endpoint_impl  // 本地服务端sockettcp_client_endpoint_impl     // tcp客户端sockettcp_server_endpoint_impl   // tcp服务端socketudp_client_endpoint_impl  // udp客户端socketudp_server_endpoint_impl   // udp服务端socket

endpoint

​ endpoint类是上面提到的各种endpoint的父类,其定义了endpoint的接口

class endpoint {
public:// 主要接口如下,略去了一部分接口virtual void start() = 0;virtual void stop() = 0;virtual bool send(const byte_t *_data, uint32_t _size) = 0;virtual bool send_to(const std::shared_ptr<endpoint_definition> _target,const byte_t *_data, uint32_t _size) = 0;virtual void receive() = 0;virtual bool is_reliable() const = 0;virtual bool is_local() const = 0;virtual void restart(bool _force = false) = 0;virtual void register_error_handler(error_handler_t _error) = 0;
};

​ 从endpoint类派生成client_endpoint以及server_endpoint类,分别用于定义客户端socket以及服务端socket的接口

class client_endpoint : public virtual endpoint {
public:virtual ~client_endpoint() {}virtual bool get_remote_address(boost::asio::ip::address &_address) const = 0;virtual std::uint16_t get_remote_port() const = 0;
};
class server_endpoint_impl: public endpoint_impl<Protocol>,public std::enable_shared_from_this<server_endpoint_impl<Protocol> > {
public:// 主要接口如下,略去了一部分接口void restart(bool _force);bool is_established() const;bool send(const uint8_t *_data, uint32_t _size);virtual void stop();void connect_cbk(boost::system::error_code const &_error);  void send_cbk(const queue_iterator_type _queue_iterator,boost::system::error_code const &_error, std::size_t _bytes);void flush_cbk(endpoint_type _target,const std::shared_ptr<train>& _train,const boost::system::error_code &_error_code);
};

​ 最后,从client_endpoint以及server_endpoint类,根据实际通信的方式(tcp/udp/local),派生出总共六种具体的endpoint类(local_client_endpoint,local_server_endpoint,tcp_client_endpoint,tcp_server_endpoint,udp_client_endpoint,udp_server_endpoint),每一种具体的endpoint类中根据协议的不同使用boost的asio创建对应的socket,完成通信功能。

在这里插入图片描述

endpoint_manager

​ endpoint_manager用于管理各种endpoint,包括创建,删除,查询等常见操作。endpoint_manager的类结构如下图:
在这里插入图片描述

​ endpoint_host是一个接口,表示endpoint的容器应该实现那些接口函数,这些接口用于让外界获取容器内的endpoint的状态变化(endpoint连接成功,发生错误,断开连接等),也可以获取某个endpoint属于哪个vsomeip应用(获取clientid),释放某个endpoint占用的端口(只针对非local类型的endpoint)。

​ 从endpoint_manage_base的接口可以看出其主要负责管理local_endpoint,包括创建local_client_endpoint(create_local_unlocked接口内实现),创建local_server_endpoint(create_local接口实现)等。

​ local_endpoint主要用于在同一主机内的不同someip应用间通信,也包括someip应用和routingmanager的通信的,这些都是依赖local_endpoint的。

​ 对于windows系统平台,local_endpoint是通过tcp传输类型的socket实现的,其他平台是通过boost::asio::local::stream_protocol_ext::endpoint来实现的。

​ endpoint_manager_impl则是负责管理费local_endpoint类型的其他endpoint(tcp/udp),同时,如果开启了SOMEIP的SD功能(ServiceDiscovery),则需要依赖组播通信,此时还会涉及到multicast_endpoint的管理。这些都是由endpoint_manager_impl来实现的。

使用场景

创建manager:

endpoint_manager_base:

​ 对于someip应用来说,如果其没有承担routingmanager的角色,那么也就不需要和其他主机上的someip应用以及其他主机上的routingmanager直接打交道,可以只依赖local_endpoint就完成功能(和其主机的通信交给routingmanager来完成)

​ 因此,这些someip应用只需要routingmanagerproxy既可(因为不是routingmanager应用,不需要创建routingmanagerimpl),而endpoint_manager_base的实例也就在routingmanagerproxy中创建,主要负责和同主机内的其他someip应用以及routingmanager应用通信。

void routing_manager_proxy::init() {routing_manager_base::init(std::make_shared<endpoint_manager_base>(this, io_, configuration_));{std::lock_guard<std::mutex> its_lock(sender_mutex_);sender_ = ep_mgr_->create_local(VSOMEIP_ROUTING_CLIENT);}
}
endpoint_manager_impl:

​ 对于承担了routingmanager功能的someip应用,其需要承担和其他主机的通信,因此需要依赖endpoint_manager_impl创建和管理各个TCP/UDP类型的endpoint。

routing_manager_impl::routing_manager_impl(routing_manager_host *_host) :routing_manager_base(_host),...ep_mgr_impl_(std::make_shared<endpoint_manager_impl>(this, io_, configuration_)),...

创建endpoint:

http://www.lryc.cn/news/453056.html

相关文章:

  • MFC有三个选项:MFC ActiveX控件、MFC应用程序、MFC DLL,如何选择?
  • 边缘概率 | 条件概率
  • 深入浅出:现代JavaScript开发者必知必会的Web性能优化技巧
  • 【S32K3 RTD LLD篇5】K344 ADC SW+HW trigger
  • TransFormer 视频笔记
  • 前端的混合全栈之路Meteor篇(三):发布订阅示例代码及如何将Meteor的响应数据映射到vue3的reactive系统
  • 自动驾驶系列—颠覆未来驾驶:深入解析自动驾驶线控转向系统技术
  • Webstorm 中对 Node.js 后端项目进行断点调试
  • VUE前后端分离毕业设计题目项目有哪些,VUE程序开发常见毕业论文设计推荐
  • 一、Spring Boot集成Spring Security之自动装配
  • 计数相关的题 Python 力扣
  • Express内置的中间件(express.json和express.urlencoded)格式的请求体数据
  • cmakelist加载Qt模块
  • 8-2.Android 任务之 CountDownTimer 编码模板(开启计时器、取消计时器)
  • Servlet的生命周期及用户提交表单页面的实现(实验报告)
  • 【Router】路由功能之IP过滤(IP Filter)功能(基于端口)介绍及实现
  • 数据结构_2.2、顺序表插入删除查找
  • 嵌入式C语言自我修养:编译链接
  • Mac制作Linux操作系统启动盘
  • PHP语言发展历程
  • Notepad++ 之 AndroidLogger插件
  • 开源2+1链动模式AI智能名片O2O商城小程序源码:线下店立体连接的超强助力器
  • 我为什么决定关闭ChatGPT的记忆功能?
  • 如何使用ssm实现中学生课后服务的信息管理与推荐+vue
  • 【分别为微服务云原生】9分钟ActiveMQ延时消息队列:定时任务的革命与Quartz的较量
  • 泛型编程--模板【C++提升】(特化、类属、参数包的展开、static、模板机制、重载......你想知道的全都有)
  • 安卓使用memtester进行内存压力测试
  • Dave Cheney: Go语言之禅
  • SpringMVC源码-AbstractUrlHandlerMapping处理器映射器将实现Controller接口的方式定义的路径存储进去
  • 满填充透明背景二维码生成