30namespace service_discovery {
32using transport::AttributesFiller;
33using transport::QosProfileConf;
36 : is_shutdown_(false),
37 is_discovery_started_(false),
39 change_type_(proto::ChangeType::CHANGE_PARTICIPANT),
44 host_name_ = common::GlobalData::Instance()->HostName();
45 process_id_ = common::GlobalData::Instance()->ProcessId();
51 if (participant ==
nullptr) {
58 AERROR <<
"create publisher or subscriber failed.";
71 std::lock_guard<std::mutex> lg(
lock_);
73 eprosima::fastrtps::Domain::removePublisher(
publisher_);
79 eprosima::fastrtps::Domain::removeSubscriber(
subscriber_);
101 ADEBUG <<
"the manager has been shut down.";
107 Convert(attr, role, OperateType::OPT_JOIN, &msg);
117 ADEBUG <<
"the manager has been shut down.";
123 Convert(attr, role, OperateType::OPT_LEAVE, &msg);
136 auto local_conn = conn;
147 eprosima::fastrtps::Domain::createPublisher(participant, pub_attr);
160 subscriber_ = eprosima::fastrtps::Domain::createSubscriber(
174 msg->set_operate_type(opt);
175 msg->set_role_type(role);
176 auto role_attr = msg->mutable_role_attr();
177 role_attr->CopyFrom(attr);
178 if (!role_attr->has_host_name()) {
181 if (!role_attr->has_process_id()) {
190 ADEBUG <<
"the manager has been shut down.";
205 ADEBUG <<
"discovery is not started.";
212 std::lock_guard<std::mutex> lg(
lock_);
214 return publisher_->write(
reinterpret_cast<void*
>(&m));
static Time Now()
get the current time.
void DisconnectAllSlots()
ConnectionType Connect(const Callback &cb)
void Notify(const ChangeMsg &msg)
bool StartDiscovery(RtpsParticipant *participant)
Startup topology discovery
void Convert(const RoleAttributes &attr, RoleType role, OperateType opt, ChangeMsg *msg)
eprosima::fastrtps::PublisherAttributes RtpsPublisherAttr
std::function< void(const ChangeMsg &)> ChangeFunc
bool Join(const RoleAttributes &attr, RoleType role, bool need_publish=true)
Join the topology
std::atomic< bool > is_shutdown_
bool IsFromSameProcess(const ChangeMsg &msg)
bool Publish(const ChangeMsg &msg)
void RemoveChangeListener(const ChangeConnection &conn)
Remove our listener for topology change.
std::string channel_name_
eprosima::fastrtps::Subscriber * subscriber_
virtual ~Manager()
Destroy the Manager object
virtual void Dispose(const ChangeMsg &msg)=0
bool CreatePublisher(RtpsParticipant *participant)
eprosima::fastrtps::Participant RtpsParticipant
bool CreateSubscriber(RtpsParticipant *participant)
std::atomic< bool > is_discovery_started_
Manager()
Construct a new Manager object
void OnRemoteChange(const std::string &msg_str)
SubscriberListener * listener_
ChangeConnection AddChangeListener(const ChangeFunc &func)
Add topology change listener, when topology changed, func will be called.
eprosima::fastrtps::Publisher * publisher_
bool Leave(const RoleAttributes &attr, RoleType role)
Leave the topology
eprosima::fastrtps::SubscriberAttributes RtpsSubscriberAttr
virtual bool Check(const RoleAttributes &attr)=0
void StopDiscovery()
Stop topology discovery
virtual bool NeedPublish(const ChangeMsg &msg) const
virtual void Shutdown()
Shutdown module
static bool FillInSubAttr(const std::string &channel_name, const QosProfile &qos, eprosima::fastrtps::SubscriberAttributes *sub_attr)
static bool FillInPubAttr(const std::string &channel_name, const QosProfile &qos, eprosima::fastrtps::PublisherAttributes *pub_attr)
static const QosProfile QOS_PROFILE_TOPO_CHANGE
This class represents the structure UnderlayMessage defined by the user in the IDL file.
void data(const std::string &_data)
This function copies the value in member data
#define RETURN_VAL_IF(condition, val)
#define RETURN_IF(condition)
std::enable_if< HasSerializeToString< T >::value, bool >::type SerializeToString(const T &message, std::string *str)
std::enable_if< HasParseFromString< T >::value, bool >::type ParseFromString(const std::string &str, T *message)
optional RoleAttributes role_attr
optional int32 process_id
optional string host_name