目录结构
文件 | 说明 |
---|---|
role_test.cc | 单元测试 |
role.cc | 实现 |
我们从role_test.cc学习role.cc是什么实现的。
概述
在cyber RT中,我们将主要通信角色(Role)分为:
- Node
- Reader/Writer
- Server/Client
每个角色使用RoleAttributes进行标志。
在本目录中,实现了三个类:
- RoleBase
- RoleWriter
- RoleServer
分析
首先我们看下它的第一个测试例子,可以看到它测试的是构造函数以及get和set函数
从上面我们可以看到,这里调用了三个类RoleWriter,RoleServer,里面都有一个成员叫做timestamp_ns,即使ns级别的时间戳。然后我们来看看role.cc是怎么定义它的
是一个基类,RoleWriter和RoleServer都继承了它。timestamp_ns_是RoleBase的成员变量。
timestamp_ns_这个成员变量可以用来比较哪个成员更早一些。
我们接着往下看:
可以看到RoleBase还有一个成员叫做attributes_,它表示当前角色的属性。比如进程id等。我们可以通过比较这个属性判断两个角色是否是同一个角色,即之前的Match
小结
当前目录实现了服务发现中的角色类RoleWriter,RoleServer。我们可以比较这些角色哪个发现的更早或者是否是同一个角色