百度Apollo cyber中的transport和shm处理整理

近期一直在阅读apollo中cyber部分的源码,所以把最近看的代码稍微整理了下。

transport部分:
transport构造,transport一开始就创建好了intra、shm、rtps这三种dispatcher。

Transport::Transport
	|
	|->CreateParticipant // 给rtps用
	|
	|->NotifierFactory::CreateNotifier  // 这个notifier感觉没啥用啊
	|
	|->intra_dispatcher_
	|
	|->shm_dispatcher_
		|
		|->ShmDispatcher::ShmDispatcher
			|
			|->ShmDispatcher::Init
				|
				|->NotifierFactory::CreateNotifier // 这里的notifier才是真正有用的
				|
				|->ShmDispatcher::ThreadFunc // 这里起了个listen的线程
					|
					|->Listen                // 循环listen,这里有点奇怪,为啥没有每个channel 都有一个notifier?
	|
	|->rtps_dispatcher_
	|
	|->RtpsDispatcher::set_participant() // 将上面的CreateParticipant设置进去

创建transmitter,根据mode(intra、shm、rtps、Hybrid)去创建对应的transmitter,transmitter 继承于Endpoint,Endpoint中有三个成员,enabled_用于标记是否被启用,Identity 我理解应该是每个Endpoint的id唯一,RoleAttributes这就是读取的配置。

Transport::CreateTransmitter
	|
	|->switch (mode) // 按照模式创建对应的transmitter,如果不填,默认hybrid
		|
		|->IntraTransmitter
		|
		|->ShmTransmitter // 继承关系:ShmTransmitter->Transmitter->Endpoint
		|
		|->RtpsTransmitter
		|
		|->HybridTransmitter
	|
	|->Enable    // 调用具体派生类的Enable,这里HybridTransmitter不会触发Enable
		|
		|->ShmTransmitter<M>::Enable // 这里暂时只看shm的Enable
			|
			|->ShmTransmitter<M>::Enable
			|
			|->SegmentFactory::CreateSegment //一个ShmTransmitter对应一个Segment,一个Segment对应一个channelid
			|
			|->NotifierFactory::CreateNotifier // 这里主要根据配置来看创建的是单播还是组播
				|
				|->CreateMulticastNotifier
				|
				|->CreateConditionNotifier // 先只看单播
					|
					|->ConditionNotifier::Instance

创建Receiver,同样也是继承于Endpoint,根据mode去创建对应的Receiver,但是这里创建的时候会带一个msg_listener callback,将msg_listener 注册到对应的Receiver中去。主要就是向diapatcher添加监听器,绑定回调函数,将自己的OnNewMessage函数注册到Dispatcher。这里用到了qt中信号和槽的设计理念。

Transport::CreateReceiver
	|
	|->switch (mode)
		|
		|->IntraReceiver 
		|
		|->ShmReceiver  //继承关系ShmReceiver->Receiver->Endpoint
			|
			|->ShmReceiver<M>::ShmReceiver // 构造里new了ShmDispatcher,继承
				|
				|->dispatcher_ = ShmDispatcher::Instance() 
					|
					|->ShmDispatcher::ShmDispatcher
						|
						|->ShmDispatcher::Init
		|
		|->RtpsReceiver
		|
		|->HybridReceiver
	|
	|->Enable    // 调用具体派生类的Enable,这里HybridTransmitter不会触发Enable
		|		
		|->ShmReceiver<M>::Enable  // 这里先只看shm的Enable,这里主要就是向diapatcher添加监听器,绑定回调函数
			|					   // 将自己的OnNewMessage函数注册到Dispatcher
			|->dispatcher_->AddListener<M>(this->attr_, std::bind(&ShmReceiver<M>::OnNewMessage, ...)); // dispatcher_是在ShmReceiver构造里创建
				|					// 这里OnNewMessage里就是去调用一下自己的函数指针成员msg_listener
				|->handler->Connect(self_attr.id(), listener); // 这里用到了qt里信号和槽的概念,就是将listener绑定
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值