28namespace service_discovery {
30using transport::QosProfileConf;
33 : is_shutdown_(false),
34 is_discovery_started_(false),
36 change_type_(proto::ChangeType::CHANGE_PARTICIPANT),
39 subscriber_(nullptr) {
40 host_name_ = common::GlobalData::Instance()->HostName();
41 process_id_ = common::GlobalData::Instance()->ProcessId();
47 if (participant ==
nullptr) {
54 AERROR <<
"create publisher or subscriber failed.";
80 ADEBUG <<
"the manager has been shut down.";
86 Convert(attr, role, OperateType::OPT_JOIN, &msg);
96 ADEBUG <<
"the manager has been shut down.";
102 Convert(attr, role, OperateType::OPT_LEAVE, &msg);
115 auto local_conn = conn;
141 msg->set_operate_type(opt);
142 msg->set_role_type(role);
143 auto role_attr = msg->mutable_role_attr();
144 role_attr->CopyFrom(attr);
145 if (!role_attr->has_host_name()) {
148 if (!role_attr->has_process_id()) {
157 ADEBUG <<
"the manager has been shut down.";
172 ADEBUG <<
"discovery is not started.";
179 std::lock_guard<std::mutex> lg(
lock_);
static Time Now()
get the current time.
void DisconnectAllSlots()
ConnectionType Connect(const Callback &cb)
void Notify(const ChangeMsg &msg)
void Convert(const RoleAttributes &attr, RoleType role, OperateType opt, ChangeMsg *msg)
std::function< void(const ChangeMsg &)> ChangeFunc
std::shared_ptr< transport::Participant > ParticipantPtr
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_
SubscriberPtr subscriber_
bool StartDiscovery(const ParticipantPtr &participant)
Startup topology discovery
bool CreateSubscriber(const ParticipantPtr &participant)
virtual ~Manager()
Destroy the Manager object
virtual void Dispose(const ChangeMsg &msg)=0
void OnRemoteChange(const std::shared_ptr< std::string > &msg_str)
std::atomic< bool > is_discovery_started_
Manager()
Construct a new Manager object
ChangeConnection AddChangeListener(const ChangeFunc &func)
Add topology change listener, when topology changed, func will be called.
bool Leave(const RoleAttributes &attr, RoleType role)
Leave the topology
virtual bool Check(const RoleAttributes &attr)=0
ParticipantPtr participant_
void StopDiscovery()
Stop topology discovery
virtual bool NeedPublish(const ChangeMsg &msg) const
virtual void Shutdown()
Shutdown module
bool CreatePublisher(const ParticipantPtr &participant)
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