diff --git a/ecal/core/src/ecal_descgate.cpp b/ecal/core/src/ecal_descgate.cpp index 40d69e85..52f82f5a 100644 --- a/ecal/core/src/ecal_descgate.cpp +++ b/ecal/core/src/ecal_descgate.cpp @@ -125,12 +125,12 @@ namespace eCAL response_type.name = method.resp_type; response_type.descriptor = method.resp_desc; - ApplyServiceDescription(m_service_info_map, sample_.service.sname, method.mname, std::stoull(sample_.service.sid), request_type, response_type, GetDataTypeInfoQuality(request_type, true), GetDataTypeInfoQuality(response_type, true)); + ApplyServiceDescription(m_service_info_map, sample_.service.sname, method.mname, std::stoull(sample_.identifier.entity_id), request_type, response_type, GetDataTypeInfoQuality(request_type, true), GetDataTypeInfoQuality(response_type, true)); } } break; case bct_unreg_service: - RemServiceDescription(m_service_info_map, sample_.service.sname, std::stoull(sample_.service.sid)); + RemServiceDescription(m_service_info_map, sample_.service.sname, std::stoull(sample_.identifier.entity_id)); break; case bct_reg_client: for (const auto& method : sample_.client.methods) @@ -143,23 +143,23 @@ namespace eCAL response_type.name = method.resp_type; response_type.descriptor = method.resp_desc; - ApplyServiceDescription(m_client_info_map, sample_.client.sname, method.mname, std::stoull(sample_.client.sid), request_type, response_type, GetDataTypeInfoQuality(request_type, false), GetDataTypeInfoQuality(response_type, false)); + ApplyServiceDescription(m_client_info_map, sample_.client.sname, method.mname, std::stoull(sample_.identifier.entity_id), request_type, response_type, GetDataTypeInfoQuality(request_type, false), GetDataTypeInfoQuality(response_type, false)); } break; case bct_unreg_client: - RemServiceDescription(m_client_info_map, sample_.client.sname, std::stoull(sample_.client.sid)); + RemServiceDescription(m_client_info_map, sample_.client.sname, std::stoull(sample_.identifier.entity_id)); break; case bct_reg_publisher: - ApplyTopicDescription(m_publisher_info_map, sample_.topic.tname, std::stoull(sample_.topic.tid), sample_.topic.tdatatype, GetDataTypeInfoQuality(sample_.topic.tdatatype, true)); + ApplyTopicDescription(m_publisher_info_map, sample_.topic.tname, std::stoull(sample_.identifier.entity_id), sample_.topic.tdatatype, GetDataTypeInfoQuality(sample_.topic.tdatatype, true)); break; case bct_unreg_publisher: - RemTopicDescription(m_publisher_info_map, sample_.topic.tname, std::stoull(sample_.topic.tid)); + RemTopicDescription(m_publisher_info_map, sample_.topic.tname, std::stoull(sample_.identifier.entity_id)); break; case bct_reg_subscriber: - ApplyTopicDescription(m_subscriber_info_map, sample_.topic.tname, std::stoull(sample_.topic.tid), sample_.topic.tdatatype, GetDataTypeInfoQuality(sample_.topic.tdatatype, false)); + ApplyTopicDescription(m_subscriber_info_map, sample_.topic.tname, std::stoull(sample_.identifier.entity_id), sample_.topic.tdatatype, GetDataTypeInfoQuality(sample_.topic.tdatatype, false)); break; case bct_unreg_subscriber: - RemTopicDescription(m_subscriber_info_map, sample_.topic.tname, std::stoull(sample_.topic.tid)); + RemTopicDescription(m_subscriber_info_map, sample_.topic.tname, std::stoull(sample_.identifier.entity_id)); break; default: { diff --git a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp index e0cc7c13..820df996 100644 --- a/ecal/core/src/monitoring/ecal_monitoring_impl.cpp +++ b/ecal/core/src/monitoring/ecal_monitoring_impl.cpp @@ -197,7 +197,7 @@ namespace eCAL bool CMonitoringImpl::RegisterTopic(const Registration::Sample& sample_, enum ePubSub pubsub_type_) { const auto& sample_topic = sample_.topic; - const int process_id = sample_topic.pid; + const int process_id = sample_.identifier.process_id; const std::string& topic_name = sample_topic.tname; const int32_t topic_size = sample_topic.tsize; bool topic_tlayer_ecal_udp(false); @@ -253,11 +253,11 @@ namespace eCAL const std::lock_guard lock(pTopicMap->sync); // common infos - const std::string& host_name = sample_topic.hname; + const std::string& host_name = sample_.identifier.host_name; const std::string& host_group_name = sample_topic.hgname; const std::string& process_name = sample_topic.pname; const std::string& unit_name = sample_topic.uname; - const std::string& topic_id = sample_topic.tid; + const std::string& topic_id = sample_.identifier.entity_id; std::string direction; switch (pubsub_type_) { @@ -338,7 +338,7 @@ namespace eCAL { const auto& sample_topic = sample_.topic; const std::string& topic_name = sample_topic.tname; - const std::string& topic_id = sample_topic.tid; + const std::string& topic_id = sample_.identifier.entity_id; // unregister from topic map STopicMonMap* pTopicMap = GetMap(pubsub_type_); @@ -358,10 +358,10 @@ namespace eCAL bool CMonitoringImpl::RegisterProcess(const Registration::Sample& sample_) { const auto& sample_process = sample_.process; - const std::string& host_name = sample_process.hname; + const std::string& host_name = sample_.identifier.host_name; const std::string& host_group_name = sample_process.hgname; const std::string& process_name = sample_process.pname; - const int process_id = sample_process.pid; + const int process_id = sample_.identifier.process_id; const std::string& process_param = sample_process.pparam; const std::string& unit_name = sample_process.uname; const auto& sample_process_state = sample_process.state; @@ -409,7 +409,7 @@ namespace eCAL { const auto& sample_process = sample_.process; const std::string& process_name = sample_process.pname; - const int process_id = sample_process.pid; + const int process_id = sample_.identifier.process_id; // create map key const std::string process_name_id = process_name + std::to_string(process_id); @@ -425,13 +425,16 @@ namespace eCAL bool CMonitoringImpl::RegisterServer(const Registration::Sample& sample_) { + const auto& sample_identifier = sample_.identifier; + const std::string& service_id = sample_identifier.entity_id; + const int32_t process_id = sample_identifier.process_id; + const std::string& host_name = sample_identifier.host_name; + const auto& sample_service = sample_.service; - const std::string& host_name = sample_service.hname; const std::string& service_name = sample_service.sname; - const std::string& service_id = sample_service.sid; const std::string& process_name = sample_service.pname; const std::string& unit_name = sample_service.uname; - const int32_t process_id = sample_service.pid; + const uint32_t tcp_port_v0 = sample_service.tcp_port_v0; const uint32_t tcp_port_v1 = sample_service.tcp_port_v1; @@ -474,10 +477,12 @@ namespace eCAL bool CMonitoringImpl::UnregisterServer(const Registration::Sample& sample_) { - const auto& sample_service = sample_.service; + const auto& sample_service = sample_.service; + const auto& sample_identifier = sample_.identifier; + const std::string& service_name = sample_service.sname; - const std::string& service_id = sample_service.sid; - const int process_id = sample_service.pid; + const std::string& service_id = sample_identifier.entity_id; + const int process_id = sample_identifier.process_id; // create map key const std::string service_name_id = service_name + service_id + std::to_string(process_id); @@ -493,13 +498,15 @@ namespace eCAL bool CMonitoringImpl::RegisterClient(const Registration::Sample& sample_) { + const auto& sample_identifier = sample_.identifier; + const std::string& service_id = sample_identifier.entity_id; + const int32_t process_id = sample_identifier.process_id; + const std::string& host_name = sample_identifier.host_name; + const auto& sample_client = sample_.client; - const std::string& host_name = sample_client.hname; const std::string& service_name = sample_client.sname; - const std::string& service_id = sample_client.sid; const std::string& process_name = sample_client.pname; const std::string& unit_name = sample_client.uname; - const int process_id = sample_client.pid; // create map key const std::string service_name_id = service_name + service_id + std::to_string(process_id); @@ -538,10 +545,12 @@ namespace eCAL bool CMonitoringImpl::UnregisterClient(const Registration::Sample& sample_) { + const auto& sample_identifier = sample_.identifier; + const std::string& service_id = sample_identifier.entity_id; + const int32_t process_id = sample_identifier.process_id; + const auto& sample_client = sample_.client; const std::string& service_name = sample_client.sname; - const std::string& service_id = sample_client.sid; - const int process_id = sample_client.pid; // create map key const std::string service_name_id = service_name + service_id + std::to_string(process_id); diff --git a/ecal/core/src/pubsub/ecal_pubgate.cpp b/ecal/core/src/pubsub/ecal_pubgate.cpp index 84e92f1d..498aec16 100644 --- a/ecal/core/src/pubsub/ecal_pubgate.cpp +++ b/ecal/core/src/pubsub/ecal_pubgate.cpp @@ -120,10 +120,11 @@ namespace eCAL // check topic name if (topic_name.empty()) return; + // TODO: Substitute ProducerInfo type CDataWriter::SSubscriptionInfo subscription_info; - subscription_info.host_name = ecal_topic.hname; - subscription_info.topic_id = ecal_topic.tid; - subscription_info.process_id = ecal_topic.pid; + subscription_info.host_name = ecal_sample_.identifier.host_name; + subscription_info.topic_id = ecal_sample_.identifier.entity_id; + subscription_info.process_id = ecal_sample_.identifier.process_id; const SDataTypeInformation topic_information = ecal_topic.tdatatype; CDataWriter::SLayerStates layer_states; @@ -180,10 +181,11 @@ namespace eCAL // check topic name if (topic_name.empty()) return; + //TODO: Remove the subscription info type CDataWriter::SSubscriptionInfo subscription_info; - subscription_info.host_name = ecal_topic.hname; - subscription_info.topic_id = ecal_topic.tid; - subscription_info.process_id = ecal_topic.pid; + subscription_info.host_name = ecal_sample_.identifier.host_name; + subscription_info.topic_id = ecal_sample_.identifier.entity_id; + subscription_info.process_id = ecal_sample_.identifier.process_id; // unregister subscriber const std::shared_lock lock(m_topic_name_datawriter_sync); diff --git a/ecal/core/src/pubsub/ecal_subgate.cpp b/ecal/core/src/pubsub/ecal_subgate.cpp index cdac6281..bd2f1633 100644 --- a/ecal/core/src/pubsub/ecal_subgate.cpp +++ b/ecal/core/src/pubsub/ecal_subgate.cpp @@ -219,10 +219,11 @@ namespace eCAL // check topic name if (topic_name.empty()) return; + // TODO: Remove the PublicationInfo type CDataReader::SPublicationInfo publication_info; - publication_info.host_name = ecal_topic.hname; - publication_info.topic_id = ecal_topic.tid; - publication_info.process_id = ecal_topic.pid; + publication_info.host_name = ecal_sample_.identifier.host_name; + publication_info.topic_id = ecal_sample_.identifier.entity_id; + publication_info.process_id = ecal_sample_.identifier.process_id; const SDataTypeInformation topic_information = ecal_topic.tdatatype; CDataReader::SLayerStates layer_states; @@ -282,10 +283,11 @@ namespace eCAL // check topic name if (topic_name.empty()) return; + // TODO: Remove the SPublicationInfo type! CDataReader::SPublicationInfo publication_info; - publication_info.host_name = ecal_topic.hname; - publication_info.topic_id = ecal_topic.tid; - publication_info.process_id = ecal_topic.pid; + publication_info.host_name = ecal_sample_.identifier.host_name; + publication_info.topic_id = ecal_sample_.identifier.entity_id; + publication_info.process_id = ecal_sample_.identifier.process_id; // unregister publisher const std::shared_lock lock(m_topic_name_datareader_sync); diff --git a/ecal/core/src/readwrite/ecal_reader.cpp b/ecal/core/src/readwrite/ecal_reader.cpp index 97e937fa..6f590d4b 100644 --- a/ecal/core/src/readwrite/ecal_reader.cpp +++ b/ecal/core/src/readwrite/ecal_reader.cpp @@ -570,11 +570,14 @@ namespace eCAL Registration::Sample ecal_reg_sample; ecal_reg_sample.cmd_type = bct_reg_subscriber; + auto& ecal_reg_sample_identifier = ecal_reg_sample.identifier; + ecal_reg_sample_identifier.process_id = m_pid; + ecal_reg_sample_identifier.entity_id = m_topic_id; + ecal_reg_sample_identifier.host_name = m_host_name; + auto& ecal_reg_sample_topic = ecal_reg_sample.topic; - ecal_reg_sample_topic.hname = m_host_name; ecal_reg_sample_topic.hgname = m_host_group_name; ecal_reg_sample_topic.tname = m_topic_name; - ecal_reg_sample_topic.tid = m_topic_id; // topic_information { auto& ecal_reg_sample_tdatatype = ecal_reg_sample_topic.tdatatype; @@ -627,7 +630,6 @@ namespace eCAL } #endif - ecal_reg_sample_topic.pid = m_pid; ecal_reg_sample_topic.pname = m_pname; ecal_reg_sample_topic.uname = Process::GetUnitName(); ecal_reg_sample_topic.dclock = m_clock; @@ -647,13 +649,15 @@ namespace eCAL Registration::Sample ecal_unreg_sample; ecal_unreg_sample.cmd_type = bct_unreg_subscriber; + auto& ecal_reg_sample_identifier = ecal_unreg_sample.identifier; + ecal_reg_sample_identifier.process_id = m_pid; + ecal_reg_sample_identifier.entity_id = m_topic_id; + ecal_reg_sample_identifier.host_name = m_host_name; + auto& ecal_reg_sample_topic = ecal_unreg_sample.topic; - ecal_reg_sample_topic.hname = m_host_name; ecal_reg_sample_topic.hgname = m_host_group_name; ecal_reg_sample_topic.pname = m_pname; - ecal_reg_sample_topic.pid = m_pid; ecal_reg_sample_topic.tname = m_topic_name; - ecal_reg_sample_topic.tid = m_topic_id; ecal_reg_sample_topic.uname = Process::GetUnitName(); return ecal_unreg_sample; diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index 2639df18..2c08fef9 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -616,11 +616,15 @@ namespace eCAL Registration::Sample ecal_reg_sample; ecal_reg_sample.cmd_type = bct_reg_publisher; + auto& ecal_reg_sample_identifier = ecal_reg_sample.identifier; + ecal_reg_sample_identifier.process_id = m_pid; + ecal_reg_sample_identifier.entity_id = m_topic_id; + ecal_reg_sample_identifier.host_name = m_host_name; + auto& ecal_reg_sample_topic = ecal_reg_sample.topic; - ecal_reg_sample_topic.hname = m_host_name; ecal_reg_sample_topic.hgname = m_host_group_name; ecal_reg_sample_topic.tname = m_topic_name; - ecal_reg_sample_topic.tid = m_topic_id; + // topic_information { auto& ecal_reg_sample_tdatatype = ecal_reg_sample_topic.tdatatype; @@ -679,7 +683,6 @@ namespace eCAL } #endif - ecal_reg_sample_topic.pid = m_pid; ecal_reg_sample_topic.pname = m_pname; ecal_reg_sample_topic.uname = Process::GetUnitName(); ecal_reg_sample_topic.did = m_id; @@ -711,13 +714,15 @@ namespace eCAL Registration::Sample ecal_unreg_sample; ecal_unreg_sample.cmd_type = bct_unreg_publisher; + auto& ecal_reg_sample_identifier = ecal_unreg_sample.identifier; + ecal_reg_sample_identifier.process_id = m_pid; + ecal_reg_sample_identifier.entity_id = m_topic_id; + ecal_reg_sample_identifier.host_name = m_host_name; + auto& ecal_reg_sample_topic = ecal_unreg_sample.topic; - ecal_reg_sample_topic.hname = m_host_name; ecal_reg_sample_topic.hgname = m_host_group_name; ecal_reg_sample_topic.pname = m_pname; - ecal_reg_sample_topic.pid = m_pid; ecal_reg_sample_topic.tname = m_topic_name; - ecal_reg_sample_topic.tid = m_topic_id; ecal_reg_sample_topic.uname = Process::GetUnitName(); return ecal_unreg_sample; diff --git a/ecal/core/src/registration/ecal_process_registration.cpp b/ecal/core/src/registration/ecal_process_registration.cpp index 18ca56aa..34b6104a 100644 --- a/ecal/core/src/registration/ecal_process_registration.cpp +++ b/ecal/core/src/registration/ecal_process_registration.cpp @@ -34,10 +34,13 @@ eCAL::Registration::Sample eCAL::Registration::GetProcessRegisterSample() { Registration::Sample process_sample; process_sample.cmd_type = bct_reg_process; + + auto& process_sample_identifier = process_sample.identifier; + process_sample_identifier.host_name = eCAL::Process::GetHostName(); + process_sample_identifier.process_id = eCAL::Process::GetProcessID(); + auto& process_sample_process = process_sample.process; - process_sample_process.hname = eCAL::Process::GetHostName(); process_sample_process.hgname = eCAL::Process::GetHostGroupName(); - process_sample_process.pid = eCAL::Process::GetProcessID(); process_sample_process.pname = eCAL::Process::GetProcessName(); process_sample_process.uname = eCAL::Process::GetUnitName(); process_sample_process.pparam = eCAL::Process::GetProcessParameter(); @@ -94,9 +97,12 @@ eCAL::Registration::Sample eCAL::Registration::GetProcessUnregisterSample() { Registration::Sample process_sample; process_sample.cmd_type = bct_unreg_process; + + auto& process_sample_identifier = process_sample.identifier; + process_sample_identifier.host_name = eCAL::Process::GetHostName(); + process_sample_identifier.process_id = eCAL::Process::GetProcessID(); + auto& process_sample_process = process_sample.process; - process_sample_process.hname = eCAL::Process::GetHostName(); - process_sample_process.pid = eCAL::Process::GetProcessID(); process_sample_process.pname = eCAL::Process::GetProcessName(); process_sample_process.uname = eCAL::Process::GetUnitName(); diff --git a/ecal/core/src/registration/ecal_registration_sample_applier.cpp b/ecal/core/src/registration/ecal_registration_sample_applier.cpp index 5dba33db..975cfbc0 100644 --- a/ecal/core/src/registration/ecal_registration_sample_applier.cpp +++ b/ecal/core/src/registration/ecal_registration_sample_applier.cpp @@ -62,7 +62,7 @@ namespace eCAL bool CSampleApplier::IsHostGroupMember(const Registration::Sample& sample_) const { std::string host_group_name; - std::string host_name; + const std::string host_name = sample_.identifier.host_name; switch (sample_.cmd_type) { case bct_reg_publisher: @@ -70,17 +70,14 @@ namespace eCAL case bct_reg_subscriber: case bct_unreg_subscriber: host_group_name = sample_.topic.hgname; - host_name = sample_.topic.hname; break; case bct_reg_service: case bct_unreg_service: //host_group_name = sample_.service.hgname; // TODO: we need to add hgname attribute to services - host_name = sample_.service.hname; break; case bct_reg_client: case bct_unreg_client: //host_group_name = sample_.client.hgname; // TODO: we need to add hgname attribute to clients - host_name = sample_.client.hname; break; default: break; @@ -98,31 +95,8 @@ namespace eCAL bool CSampleApplier::IsSameProcess(const Registration::Sample& sample_) const { - int32_t pid(0); - switch (sample_.cmd_type) - { - case bct_reg_process: - case bct_unreg_process: - pid = sample_.process.pid; - break; - case bct_reg_publisher: - case bct_unreg_publisher: - case bct_reg_subscriber: - case bct_unreg_subscriber: - pid = sample_.topic.pid; - break; - case bct_reg_service: - case bct_unreg_service: - pid = sample_.service.pid; - break; - case bct_reg_client: - case bct_unreg_client: - pid = sample_.client.pid; - break; - default: - break; - } - + // is this actually sufficient? should we also check host_name? + const int32_t pid = sample_.identifier.process_id; return pid == m_pid; } diff --git a/ecal/core/src/serialization/ecal_serialize_sample_registration.cpp b/ecal/core/src/serialization/ecal_serialize_sample_registration.cpp index c4bfffd9..8390d1e0 100644 --- a/ecal/core/src/serialization/ecal_serialize_sample_registration.cpp +++ b/ecal/core/src/serialization/ecal_serialize_sample_registration.cpp @@ -37,161 +37,214 @@ namespace { - ///////////////////////////////////////////////////////////////////////////////// - // eCAL::Registration::Sample - ///////////////////////////////////////////////////////////////////////////////// - void PrepareEncoding(const eCAL::Registration::Sample& registration_, eCAL_pb_Sample& pb_sample_) + /////////////////////////////////////////////// + // process information + /////////////////////////////////////////////// + void PrepareEncoding(const eCAL::Registration::Sample& registration_, eCAL_pb_Process& pb_process_) { - // command type - pb_sample_.cmd_type = static_cast(registration_.cmd_type); - - /////////////////////////////////////////////// - // host information - /////////////////////////////////////////////// - pb_sample_.has_host = true; - - // hname - eCAL::nanopb::encode_string(pb_sample_.host.hname, registration_.host.hname); - - /////////////////////////////////////////////// - // process information - /////////////////////////////////////////////// - pb_sample_.has_process = true; - + const auto& registration_process_ = registration_.process; + const auto& registration_identifier_ = registration_.identifier; // rclock - pb_sample_.process.rclock = registration_.process.rclock; + pb_process_.rclock = registration_process_.rclock; // hname - eCAL::nanopb::encode_string(pb_sample_.process.hname, registration_.process.hname); + eCAL::nanopb::encode_string(pb_process_.hname, registration_identifier_.host_name); // hgname - eCAL::nanopb::encode_string(pb_sample_.process.hgname, registration_.process.hgname); + eCAL::nanopb::encode_string(pb_process_.hgname, registration_process_.hgname); // pid - pb_sample_.process.pid = registration_.process.pid; + pb_process_.pid = registration_identifier_.process_id; // pname - eCAL::nanopb::encode_string(pb_sample_.process.pname, registration_.process.pname); + eCAL::nanopb::encode_string(pb_process_.pname, registration_process_.pname); // uname - eCAL::nanopb::encode_string(pb_sample_.process.uname, registration_.process.uname); + eCAL::nanopb::encode_string(pb_process_.uname, registration_process_.uname); // pparam - eCAL::nanopb::encode_string(pb_sample_.process.pparam, registration_.process.pparam); + eCAL::nanopb::encode_string(pb_process_.pparam, registration_process_.pparam); + // state - pb_sample_.process.has_state = true; + pb_process_.has_state = true; // state.severity - pb_sample_.process.state.severity = static_cast(registration_.process.state.severity); + pb_process_.state.severity = static_cast(registration_process_.state.severity); // state.severity_level - pb_sample_.process.state.severity_level = static_cast(registration_.process.state.severity_level); + pb_process_.state.severity_level = static_cast(registration_process_.state.severity_level); // state.info - eCAL::nanopb::encode_string(pb_sample_.process.state.info, registration_.process.state.info); + eCAL::nanopb::encode_string(pb_process_.state.info, registration_process_.state.info); // process.tsync_state - pb_sample_.process.tsync_state = static_cast(registration_.process.tsync_state); + pb_process_.tsync_state = static_cast(registration_process_.tsync_state); // tsync_mod_name - eCAL::nanopb::encode_string(pb_sample_.process.tsync_mod_name, registration_.process.tsync_mod_name); + eCAL::nanopb::encode_string(pb_process_.tsync_mod_name, registration_process_.tsync_mod_name); // component_init_state - pb_sample_.process.component_init_state = registration_.process.component_init_state; + pb_process_.component_init_state = registration_process_.component_init_state; // component_init_info - eCAL::nanopb::encode_string(pb_sample_.process.component_init_info, registration_.process.component_init_info); + eCAL::nanopb::encode_string(pb_process_.component_init_info, registration_process_.component_init_info); // ecal_runtime_version - eCAL::nanopb::encode_string(pb_sample_.process.ecal_runtime_version, registration_.process.ecal_runtime_version); + eCAL::nanopb::encode_string(pb_process_.ecal_runtime_version, registration_process_.ecal_runtime_version); + } - /////////////////////////////////////////////// - // service information - /////////////////////////////////////////////// - pb_sample_.has_service = true; + /////////////////////////////////////////////// + // service information + /////////////////////////////////////////////// + void PrepareEncoding(const eCAL::Registration::Sample& registration_, eCAL_pb_Service& pb_service_) + { + const auto& registration_service_ = registration_.service; + const auto& registration_identifier_ = registration_.identifier; // rclock - pb_sample_.service.rclock = registration_.service.rclock; + pb_service_.rclock = registration_service_.rclock; // hname - eCAL::nanopb::encode_string(pb_sample_.service.hname, registration_.service.hname); + eCAL::nanopb::encode_string(pb_service_.hname, registration_identifier_.host_name); // pname - eCAL::nanopb::encode_string(pb_sample_.service.pname, registration_.service.pname); + eCAL::nanopb::encode_string(pb_service_.pname, registration_service_.pname); // uname - eCAL::nanopb::encode_string(pb_sample_.service.uname, registration_.service.uname); + eCAL::nanopb::encode_string(pb_service_.uname, registration_service_.uname); // pid - pb_sample_.service.pid = registration_.service.pid; + pb_service_.pid = registration_identifier_.process_id; // sname - eCAL::nanopb::encode_string(pb_sample_.service.sname, registration_.service.sname); + eCAL::nanopb::encode_string(pb_service_.sname, registration_service_.sname); // sid - eCAL::nanopb::encode_string(pb_sample_.service.sid, registration_.service.sid); + eCAL::nanopb::encode_string(pb_service_.sid, registration_identifier_.entity_id); // methods - eCAL::nanopb::encode_service_methods(pb_sample_.service.methods, registration_.service.methods); + eCAL::nanopb::encode_service_methods(pb_service_.methods, registration_service_.methods); // version - pb_sample_.service.version = registration_.service.version; + pb_service_.version = registration_service_.version; // tcp_port_v0 - pb_sample_.service.tcp_port_v0 = registration_.service.tcp_port_v0; + pb_service_.tcp_port_v0 = registration_service_.tcp_port_v0; // tcp_port_v1 - pb_sample_.service.tcp_port_v1 = registration_.service.tcp_port_v1; + pb_service_.tcp_port_v1 = registration_service_.tcp_port_v1; + } - /////////////////////////////////////////////// - // client information - /////////////////////////////////////////////// - pb_sample_.has_client = true; + /////////////////////////////////////////////// + // client information + /////////////////////////////////////////////// + void PrepareEncoding(const eCAL::Registration::Sample& registration_, eCAL_pb_Client& pb_client_) + { + const auto& registration_client_ = registration_.client; + const auto& registration_producer_ = registration_.identifier; // rclock - pb_sample_.client.rclock = registration_.client.rclock; + pb_client_.rclock = registration_client_.rclock; // hname - eCAL::nanopb::encode_string(pb_sample_.client.hname, registration_.client.hname); + eCAL::nanopb::encode_string(pb_client_.hname, registration_producer_.host_name); // pname - eCAL::nanopb::encode_string(pb_sample_.client.pname, registration_.client.pname); + eCAL::nanopb::encode_string(pb_client_.pname, registration_client_.pname); // uname - eCAL::nanopb::encode_string(pb_sample_.client.uname, registration_.client.uname); + eCAL::nanopb::encode_string(pb_client_.uname, registration_client_.uname); // pid - pb_sample_.client.pid = registration_.client.pid; + pb_client_.pid = registration_producer_.process_id; // sname - eCAL::nanopb::encode_string(pb_sample_.client.sname, registration_.client.sname); + eCAL::nanopb::encode_string(pb_client_.sname, registration_client_.sname); // sid - eCAL::nanopb::encode_string(pb_sample_.client.sid, registration_.client.sid); + eCAL::nanopb::encode_string(pb_client_.sid, registration_producer_.entity_id); // methods - eCAL::nanopb::encode_service_methods(pb_sample_.client.methods, registration_.client.methods); + eCAL::nanopb::encode_service_methods(pb_client_.methods, registration_client_.methods); // version - pb_sample_.client.version = registration_.client.version; + pb_client_.version = registration_client_.version; + } - /////////////////////////////////////////////// - // topic information - /////////////////////////////////////////////// - pb_sample_.has_topic = true; + /////////////////////////////////////////////// + // topic information + /////////////////////////////////////////////// + void PrepareEncoding(const eCAL::Registration::Sample& registration_sample_, eCAL_pb_Topic& pb_topic_) + { + const auto& registration_identifier_ = registration_sample_.identifier; + const auto& registration_topic_ = registration_sample_.topic; // rclock - pb_sample_.topic.rclock = registration_.topic.rclock; + pb_topic_.rclock = registration_topic_.rclock; // hname - eCAL::nanopb::encode_string(pb_sample_.topic.hname, registration_.topic.hname); + eCAL::nanopb::encode_string(pb_topic_.hname, registration_identifier_.host_name); // hgname - eCAL::nanopb::encode_string(pb_sample_.topic.hgname, registration_.topic.hgname); + eCAL::nanopb::encode_string(pb_topic_.hgname, registration_topic_.hgname); // pid - pb_sample_.topic.pid = registration_.topic.pid; + pb_topic_.pid = registration_identifier_.process_id; // pname - eCAL::nanopb::encode_string(pb_sample_.topic.pname, registration_.topic.pname); + eCAL::nanopb::encode_string(pb_topic_.pname, registration_topic_.pname); // uname - eCAL::nanopb::encode_string(pb_sample_.topic.uname, registration_.topic.uname); + eCAL::nanopb::encode_string(pb_topic_.uname, registration_topic_.uname); // tid - eCAL::nanopb::encode_string(pb_sample_.topic.tid, registration_.topic.tid); + eCAL::nanopb::encode_string(pb_topic_.tid, registration_identifier_.entity_id); // tname - eCAL::nanopb::encode_string(pb_sample_.topic.tname, registration_.topic.tname); + eCAL::nanopb::encode_string(pb_topic_.tname, registration_topic_.tname); // direction - eCAL::nanopb::encode_string(pb_sample_.topic.direction, registration_.topic.direction); + eCAL::nanopb::encode_string(pb_topic_.direction, registration_topic_.direction); // tdatatype - pb_sample_.topic.has_tdatatype = true; + pb_topic_.has_tdatatype = true; // tdatatype.name - eCAL::nanopb::encode_string(pb_sample_.topic.tdatatype.name, registration_.topic.tdatatype.name); + eCAL::nanopb::encode_string(pb_topic_.tdatatype.name, registration_topic_.tdatatype.name); // tdatatype.encoding - eCAL::nanopb::encode_string(pb_sample_.topic.tdatatype.encoding, registration_.topic.tdatatype.encoding); + eCAL::nanopb::encode_string(pb_topic_.tdatatype.encoding, registration_topic_.tdatatype.encoding); // tdatatype.desc - eCAL::nanopb::encode_string(pb_sample_.topic.tdatatype.desc, registration_.topic.tdatatype.descriptor); + eCAL::nanopb::encode_string(pb_topic_.tdatatype.desc, registration_topic_.tdatatype.descriptor); // tsize - pb_sample_.topic.tsize = registration_.topic.tsize; + pb_topic_.tsize = registration_topic_.tsize; // connections_loc - pb_sample_.topic.connections_loc = registration_.topic.connections_loc; + pb_topic_.connections_loc = registration_topic_.connections_loc; // connections_ext - pb_sample_.topic.connections_ext = registration_.topic.connections_ext; + pb_topic_.connections_ext = registration_topic_.connections_ext; // message_drops - pb_sample_.topic.message_drops = registration_.topic.message_drops; + pb_topic_.message_drops = registration_topic_.message_drops; // did - pb_sample_.topic.did = registration_.topic.did; + pb_topic_.did = registration_topic_.did; // dclock - pb_sample_.topic.dclock = registration_.topic.dclock; + pb_topic_.dclock = registration_topic_.dclock; // dfreq - pb_sample_.topic.dfreq = registration_.topic.dfreq; + pb_topic_.dfreq = registration_topic_.dfreq; // tlayer - eCAL::nanopb::encode_registration_layer(pb_sample_.topic.tlayer, registration_.topic.tlayer); + eCAL::nanopb::encode_registration_layer(pb_topic_.tlayer, registration_topic_.tlayer); // attr - eCAL::nanopb::encode_map(pb_sample_.topic.attr, registration_.topic.attr); + eCAL::nanopb::encode_map(pb_topic_.attr, registration_topic_.attr); + } + + ///////////////////////////////////////////////////////////////////////////////// + // eCAL::Registration::Sample + ///////////////////////////////////////////////////////////////////////////////// + void PrepareEncoding(const eCAL::Registration::Sample& registration_, eCAL_pb_Sample& pb_sample_) + { + // command type + pb_sample_.cmd_type = static_cast(registration_.cmd_type); + + /////////////////////////////////////////////// + // host information + /////////////////////////////////////////////// + pb_sample_.has_host = true; + + // hname + eCAL::nanopb::encode_string(pb_sample_.host.hname, registration_.host.hname); + + pb_sample_.has_process = false; + pb_sample_.has_service = false; + pb_sample_.has_client = false; + pb_sample_.has_topic = false; + + switch (registration_.cmd_type) + { + case eCAL::bct_reg_process: + case eCAL::bct_unreg_process: + pb_sample_.has_process = true; + PrepareEncoding(registration_, pb_sample_.process); + break; + + case eCAL::bct_reg_service: + case eCAL::bct_unreg_service: + pb_sample_.has_service = true; + PrepareEncoding(registration_, pb_sample_.service); + break; + + case eCAL::bct_reg_client: + case eCAL::bct_unreg_client: + pb_sample_.has_client = true; + PrepareEncoding(registration_, pb_sample_.client); + break; + + case eCAL::bct_reg_publisher: + case eCAL::bct_unreg_publisher: + case eCAL::bct_reg_subscriber: + case eCAL::bct_unreg_subscriber: + pb_sample_.has_topic = true; + PrepareEncoding(registration_, pb_sample_.topic); + break; + + default: + break; + } } size_t RegistrationStruct2PbSample(const eCAL::Registration::Sample& registration_, eCAL_pb_Sample& pb_sample_) @@ -259,7 +312,7 @@ namespace // process information /////////////////////////////////////////////// // hname - eCAL::nanopb::decode_string(pb_sample_.process.hname, registration_.process.hname); + eCAL::nanopb::decode_string(pb_sample_.process.hname, registration_.identifier.host_name); // hgname eCAL::nanopb::decode_string(pb_sample_.process.hgname, registration_.process.hgname); // pname @@ -281,7 +334,7 @@ namespace // service information /////////////////////////////////////////////// // hname - eCAL::nanopb::decode_string(pb_sample_.service.hname, registration_.service.hname); + eCAL::nanopb::decode_string(pb_sample_.service.hname, registration_.identifier.host_name); // pname eCAL::nanopb::decode_string(pb_sample_.service.pname, registration_.service.pname); // uname @@ -289,7 +342,7 @@ namespace // sname eCAL::nanopb::decode_string(pb_sample_.service.sname, registration_.service.sname); // sid - eCAL::nanopb::decode_string(pb_sample_.service.sid, registration_.service.sid); + eCAL::nanopb::decode_string(pb_sample_.service.sid, registration_.identifier.entity_id); // methods eCAL::nanopb::decode_service_methods(pb_sample_.service.methods, registration_.service.methods); @@ -297,7 +350,7 @@ namespace // client information /////////////////////////////////////////////// // hname - eCAL::nanopb::decode_string(pb_sample_.client.hname, registration_.client.hname); + eCAL::nanopb::decode_string(pb_sample_.client.hname, registration_.identifier.host_name); // pname eCAL::nanopb::decode_string(pb_sample_.client.pname, registration_.client.pname); // uname @@ -305,7 +358,7 @@ namespace // sname eCAL::nanopb::decode_string(pb_sample_.client.sname, registration_.client.sname); // sid - eCAL::nanopb::decode_string(pb_sample_.client.sid, registration_.client.sid); + eCAL::nanopb::decode_string(pb_sample_.client.sid, registration_.identifier.entity_id); // methods eCAL::nanopb::decode_service_methods(pb_sample_.client.methods, registration_.client.methods); @@ -313,7 +366,7 @@ namespace // topic information /////////////////////////////////////////////// // hname - eCAL::nanopb::decode_string(pb_sample_.topic.hname, registration_.topic.hname); + eCAL::nanopb::decode_string(pb_sample_.topic.hname, registration_.identifier.host_name); // hgname eCAL::nanopb::decode_string(pb_sample_.topic.hgname, registration_.topic.hgname); // pname @@ -321,7 +374,7 @@ namespace // uname eCAL::nanopb::decode_string(pb_sample_.topic.uname, registration_.topic.uname); // tid - eCAL::nanopb::decode_string(pb_sample_.topic.tid, registration_.topic.tid); + eCAL::nanopb::decode_string(pb_sample_.topic.tid, registration_.identifier.entity_id); // tname eCAL::nanopb::decode_string(pb_sample_.topic.tname, registration_.topic.tname); // direction @@ -345,68 +398,71 @@ namespace /////////////////////////////////////////////// // command type registration_.cmd_type = static_cast(pb_sample_.cmd_type); - - /////////////////////////////////////////////// - // process information - /////////////////////////////////////////////// - // rclock - registration_.process.rclock = pb_sample_.process.rclock; - // pid - registration_.process.pid = pb_sample_.process.pid; - // state.severity - registration_.process.state.severity = static_cast(pb_sample_.process.state.severity); - // state.severity_level - registration_.process.state.severity_level = static_cast(pb_sample_.process.state.severity_level); - // tsync_state - registration_.process.tsync_state = static_cast(pb_sample_.process.tsync_state); - // component_init_state - registration_.process.component_init_state = pb_sample_.process.component_init_state; - - /////////////////////////////////////////////// - // service information - /////////////////////////////////////////////// - // rclock - registration_.service.rclock = pb_sample_.service.rclock; - // pid - registration_.service.pid = pb_sample_.service.pid; - // version - registration_.service.version = pb_sample_.service.version; - // tcp_port_v0 - registration_.service.tcp_port_v0 = pb_sample_.service.tcp_port_v0; - // tcp_port_v1 - registration_.service.tcp_port_v1 = pb_sample_.service.tcp_port_v1; - - /////////////////////////////////////////////// - // client information - /////////////////////////////////////////////// - // rclock - registration_.client.rclock = pb_sample_.client.rclock; - // pid - registration_.client.pid = pb_sample_.client.pid; - // version - registration_.client.version = pb_sample_.client.version; - - /////////////////////////////////////////////// - // topic information - /////////////////////////////////////////////// - // rclock - registration_.topic.rclock = pb_sample_.topic.rclock; - // pid - registration_.topic.pid = pb_sample_.topic.pid; - // tsize - registration_.topic.tsize = pb_sample_.topic.tsize; - // connections_loc - registration_.topic.connections_loc = pb_sample_.topic.connections_loc; - // connections_ext - registration_.topic.connections_ext = pb_sample_.topic.connections_ext; - // message_drops - registration_.topic.message_drops = pb_sample_.topic.message_drops; - // did - registration_.topic.did = pb_sample_.topic.did; - // dclock - registration_.topic.dclock = pb_sample_.topic.dclock; - // dfreq - registration_.topic.dfreq = pb_sample_.topic.dfreq; + switch (registration_.cmd_type) + { + case eCAL::bct_reg_process: + case eCAL::bct_unreg_process: + // rclock + registration_.process.rclock = pb_sample_.process.rclock; + // pid + registration_.identifier.process_id = pb_sample_.process.pid; + // state.severity + registration_.process.state.severity = static_cast(pb_sample_.process.state.severity); + // state.severity_level + registration_.process.state.severity_level = static_cast(pb_sample_.process.state.severity_level); + // tsync_state + registration_.process.tsync_state = static_cast(pb_sample_.process.tsync_state); + // component_init_state + registration_.process.component_init_state = pb_sample_.process.component_init_state; + break; + case eCAL::bct_reg_service: + case eCAL::bct_unreg_service: + // rclock + registration_.service.rclock = pb_sample_.service.rclock; + // pid + registration_.identifier.process_id = pb_sample_.service.pid; + // version + registration_.service.version = pb_sample_.service.version; + // tcp_port_v0 + registration_.service.tcp_port_v0 = pb_sample_.service.tcp_port_v0; + // tcp_port_v1 + registration_.service.tcp_port_v1 = pb_sample_.service.tcp_port_v1; + break; + case eCAL::bct_reg_client: + case eCAL::bct_unreg_client: + // rclock + registration_.client.rclock = pb_sample_.client.rclock; + // pid + registration_.identifier.process_id = pb_sample_.client.pid; + // version + registration_.client.version = pb_sample_.client.version; + break; + case eCAL::bct_reg_publisher: + case eCAL::bct_unreg_publisher: + case eCAL::bct_reg_subscriber: + case eCAL::bct_unreg_subscriber: + // rclock + registration_.topic.rclock = pb_sample_.topic.rclock; + // pid + registration_.identifier.process_id = pb_sample_.topic.pid; + // tsize + registration_.topic.tsize = pb_sample_.topic.tsize; + // connections_loc + registration_.topic.connections_loc = pb_sample_.topic.connections_loc; + // connections_ext + registration_.topic.connections_ext = pb_sample_.topic.connections_ext; + // message_drops + registration_.topic.message_drops = pb_sample_.topic.message_drops; + // did + registration_.topic.did = pb_sample_.topic.did; + // dclock + registration_.topic.dclock = pb_sample_.topic.dclock; + // dfreq + registration_.topic.dfreq = pb_sample_.topic.dfreq; + break; + default: + break; + } } bool Buffer2RegistrationStruct(const char* data_, size_t size_, eCAL::Registration::Sample& registration_) diff --git a/ecal/core/src/serialization/ecal_struct_sample_registration.h b/ecal/core/src/serialization/ecal_struct_sample_registration.h index 79cfc0ef..13d6c8d5 100644 --- a/ecal/core/src/serialization/ecal_struct_sample_registration.h +++ b/ecal/core/src/serialization/ecal_struct_sample_registration.h @@ -125,9 +125,7 @@ namespace eCAL struct Process { int32_t rclock = 0; // registration clock - std::string hname; // host name std::string hgname; // host group name - int32_t pid = 0; // process id std::string pname; // process name std::string uname; // unit name std::string pparam; // process parameter @@ -143,12 +141,9 @@ namespace eCAL struct Topic { int32_t rclock = 0; // registration clock (heart beat) - std::string hname; // host name std::string hgname; // host group name - int32_t pid = 0; // process id std::string pname; // process name std::string uname; // unit name - std::string tid; // topic id std::string tname; // topic name std::string direction; // direction (publisher, subscriber) SDataTypeInformation tdatatype; // topic datatype information (encoding & type & description) @@ -167,9 +162,17 @@ namespace eCAL std::map attr; // generic topic description }; + struct SampleIdentifier + { + std::string entity_id; // unique id within that process + int32_t process_id = 0; // process id which produced the sample + std::string host_name; // host which produced the sample + }; + // Registration sample struct Sample { + SampleIdentifier identifier; // Unique identifier to see who produced the sample (publisher / subscriber / ...) eCmdType cmd_type = bct_none; // registration command type Host host; // host information Process process; // process information diff --git a/ecal/core/src/serialization/ecal_struct_service.h b/ecal/core/src/serialization/ecal_struct_service.h index c3384a37..24123461 100644 --- a/ecal/core/src/serialization/ecal_struct_service.h +++ b/ecal/core/src/serialization/ecal_struct_service.h @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -82,12 +82,9 @@ namespace eCAL struct Service { int32_t rclock = 0; // Registration clock - std::string hname; // Host name std::string pname; // Process name std::string uname; // Unit name - int32_t pid = 0; // Process id std::string sname; // Service name - std::string sid; // Service id std::vector methods; // List of methods uint32_t version = 0; // Service protocol version uint32_t tcp_port_v0 = 0; // The TCP port used for that service (v0) @@ -98,12 +95,9 @@ namespace eCAL struct Client { int32_t rclock = 0; // Registration clock - std::string hname; // Host name std::string pname; // Process name std::string uname; // Unit name - int32_t pid = 0; // Process id std::string sname; // Service name - std::string sid; // Service id std::vector methods; // List of methods uint32_t version = 0; // Client protocol version }; diff --git a/ecal/core/src/service/ecal_clientgate.cpp b/ecal/core/src/service/ecal_clientgate.cpp index 698d96d4..f72ca78c 100644 --- a/ecal/core/src/service/ecal_clientgate.cpp +++ b/ecal/core/src/service/ecal_clientgate.cpp @@ -101,12 +101,13 @@ namespace eCAL { SServiceAttr service; const auto& ecal_sample_service = ecal_sample_.service; - service.hname = ecal_sample_service.hname; + const auto& ecal_sample_identifier = ecal_sample_.identifier; + service.hname = ecal_sample_identifier.host_name; service.pname = ecal_sample_service.pname; service.uname = ecal_sample_service.uname; service.sname = ecal_sample_service.sname; - service.sid = ecal_sample_service.sid; - service.pid = static_cast(ecal_sample_service.pid); + service.sid = ecal_sample_identifier.entity_id; + service.pid = static_cast(ecal_sample_identifier.process_id); // internal protocol specifics service.version = static_cast(ecal_sample_service.version); diff --git a/ecal/core/src/service/ecal_service_client_impl.cpp b/ecal/core/src/service/ecal_service_client_impl.cpp index abce7327..7f6ca3f7 100644 --- a/ecal/core/src/service/ecal_service_client_impl.cpp +++ b/ecal/core/src/service/ecal_service_client_impl.cpp @@ -639,14 +639,16 @@ namespace eCAL Registration::Sample ecal_reg_sample; ecal_reg_sample.cmd_type = bct_reg_client; + auto& service_identifier = ecal_reg_sample.identifier; + service_identifier.entity_id = m_service_id; + service_identifier.process_id = Process::GetProcessID(); + service_identifier.host_name = Process::GetHostName(); + auto& service_client = ecal_reg_sample.client; service_client.version = m_client_version; - service_client.hname = Process::GetHostName(); service_client.pname = Process::GetProcessName(); service_client.uname = Process::GetUnitName(); - service_client.pid = Process::GetProcessID(); service_client.sname = m_service_name; - service_client.sid = m_service_id; { const std::lock_guard lock(m_method_sync); @@ -675,13 +677,15 @@ namespace eCAL Registration::Sample ecal_reg_sample; ecal_reg_sample.cmd_type = bct_unreg_client; + auto& service_identifier = ecal_reg_sample.identifier; + service_identifier.entity_id = m_service_id; + service_identifier.process_id = Process::GetProcessID(); + service_identifier.host_name = Process::GetHostName(); + auto& service_client = ecal_reg_sample.client; - service_client.hname = Process::GetHostName(); service_client.pname = Process::GetProcessName(); service_client.uname = Process::GetUnitName(); - service_client.pid = Process::GetProcessID(); service_client.sname = m_service_name; - service_client.sid = m_service_id; service_client.version = m_client_version; return ecal_reg_sample; diff --git a/ecal/core/src/service/ecal_service_server_impl.cpp b/ecal/core/src/service/ecal_service_server_impl.cpp index 10d2ff64..ec1812af 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -135,12 +135,6 @@ namespace eCAL { if (!m_created) return(false); - if (m_tcp_server_v0) - m_tcp_server_v0->stop(); - - if (m_tcp_server_v1) - m_tcp_server_v1->stop(); - // reset method callback map { std::lock_guard const lock(m_method_map_sync); @@ -153,6 +147,12 @@ namespace eCAL m_event_callback_map.clear(); } + if (m_tcp_server_v0) + m_tcp_server_v0->stop(); + + if (m_tcp_server_v1) + m_tcp_server_v1->stop(); + // mark as no more created m_created = false; @@ -320,14 +320,17 @@ namespace eCAL unsigned short const server_tcp_port_v1(m_tcp_server_v1 ? m_tcp_server_v1->get_port() : 0); if ((Config::IsServiceProtocolV1Enabled()) && (server_tcp_port_v1 == 0)) return ecal_reg_sample; + auto& identifier = ecal_reg_sample.identifier; + identifier.entity_id = m_service_id; + identifier.process_id = Process::GetProcessID(); + identifier.host_name = Process::GetHostName(); + auto& service = ecal_reg_sample.service; service.version = m_server_version; - service.hname = Process::GetHostName(); service.pname = Process::GetProcessName(); service.uname = Process::GetUnitName(); - service.pid = Process::GetProcessID(); service.sname = m_service_name; - service.sid = m_service_id; + service.tcp_port_v0 = server_tcp_port_v0; service.tcp_port_v1 = server_tcp_port_v1; @@ -356,14 +359,16 @@ namespace eCAL Registration::Sample ecal_reg_sample; ecal_reg_sample.cmd_type = bct_unreg_service; + auto& identifier = ecal_reg_sample.identifier; + identifier.entity_id = m_service_id; + identifier.process_id = Process::GetProcessID(); + identifier.host_name = Process::GetHostName(); + auto& service = ecal_reg_sample.service; service.version = m_server_version; - service.hname = Process::GetHostName(); - service.pname = Process::GetProcessName(); - service.uname = Process::GetUnitName(); - service.pid = Process::GetProcessID(); - service.sname = m_service_name; - service.sid = m_service_id; + service.pname = Process::GetProcessName(); + service.uname = Process::GetUnitName(); + service.sname = m_service_name; return ecal_reg_sample; } diff --git a/ecal/tests/cpp/descgate_test/src/getpublisher.cpp b/ecal/tests/cpp/descgate_test/src/getpublisher.cpp index c631905c..4d696477 100644 --- a/ecal/tests/cpp/descgate_test/src/getpublisher.cpp +++ b/ecal/tests/cpp/descgate_test/src/getpublisher.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,8 @@ namespace { eCAL::Registration::Sample reg_sample; reg_sample.cmd_type = eCAL::bct_reg_publisher; + reg_sample.identifier.entity_id = std::to_string(topic_id_); reg_sample.topic.tname = topic_name_; - reg_sample.topic.tid = std::to_string(topic_id_); reg_sample.topic.tdatatype.name = topic_name_ + "-tdatatype.name"; reg_sample.topic.tdatatype.encoding = topic_name_ + "-tdatatype.encoding"; reg_sample.topic.tdatatype.descriptor = topic_name_ + "-tdatatype.descriptor"; @@ -44,8 +44,8 @@ namespace { eCAL::Registration::Sample reg_sample; reg_sample.cmd_type = eCAL::bct_reg_subscriber; + reg_sample.identifier.entity_id = std::to_string(topic_id_); reg_sample.topic.tname = topic_name_; - reg_sample.topic.tid = std::to_string(topic_id_); reg_sample.topic.tdatatype.name = topic_name_ + "-tdatatype.name"; reg_sample.topic.tdatatype.encoding = topic_name_ + "-tdatatype.encoding"; reg_sample.topic.tdatatype.descriptor = topic_name_ + "-tdatatype.descriptor"; @@ -55,9 +55,9 @@ namespace eCAL::Registration::Sample CreateService(const std::string& service_name_, std::uint64_t service_id_) { eCAL::Registration::Sample reg_sample; - reg_sample.cmd_type = eCAL::bct_reg_service; - reg_sample.service.sname = service_name_; - reg_sample.service.sid = std::to_string(service_id_); + reg_sample.cmd_type = eCAL::bct_reg_service; + reg_sample.service.sname = service_name_; + reg_sample.identifier.entity_id = std::to_string(service_id_); eCAL::Service::Method method; method.mname = "method_name"; @@ -68,9 +68,9 @@ namespace eCAL::Registration::Sample CreateClient(const std::string& client_name_, std::uint64_t service_id_) { eCAL::Registration::Sample reg_sample; - reg_sample.cmd_type = eCAL::bct_reg_client; - reg_sample.client.sname = client_name_; - reg_sample.client.sid = std::to_string(service_id_); + reg_sample.cmd_type = eCAL::bct_reg_client; + reg_sample.client.sname = client_name_; + reg_sample.identifier.entity_id = std::to_string(service_id_); eCAL::Service::Method method; method.mname = "method_name"; diff --git a/ecal/tests/cpp/serialization_test/src/registration_compare.cpp b/ecal/tests/cpp/serialization_test/src/registration_compare.cpp index 2054b0de..39682f86 100644 --- a/ecal/tests/cpp/serialization_test/src/registration_compare.cpp +++ b/ecal/tests/cpp/serialization_test/src/registration_compare.cpp @@ -37,9 +37,7 @@ namespace eCAL bool CompareProcess(const Process& process1, const Process& process2) { return (process1.rclock == process2.rclock) && - (process1.hname == process2.hname) && (process1.hgname == process2.hgname) && - (process1.pid == process2.pid) && (process1.pname == process2.pname) && (process1.uname == process2.uname) && (process1.pparam == process2.pparam) && @@ -76,12 +74,9 @@ namespace eCAL bool CompareService(const Service::Service& service1, const Service::Service& service2) { return (service1.rclock == service2.rclock) && - (service1.hname == service2.hname) && (service1.pname == service2.pname) && (service1.uname == service2.uname) && - (service1.pid == service2.pid) && (service1.sname == service2.sname) && - (service1.sid == service2.sid) && CompareMethods(service1.methods, service2.methods) && (service1.version == service2.version) && (service1.tcp_port_v0 == service2.tcp_port_v0) && @@ -92,12 +87,9 @@ namespace eCAL bool CompareClient(const Service::Client& client1, const Service::Client& client2) { return (client1.rclock == client2.rclock) && - (client1.hname == client2.hname) && (client1.pname == client2.pname) && (client1.uname == client2.uname) && - (client1.pid == client2.pid) && (client1.sname == client2.sname) && - (client1.sid == client2.sid) && CompareMethods(client1.methods, client2.methods) && (client1.version == client2.version); } @@ -158,12 +150,9 @@ namespace eCAL bool CompareTopic(const Topic& topic1, const Topic& topic2) { return (topic1.rclock == topic2.rclock) && - (topic1.hname == topic2.hname) && (topic1.hgname == topic2.hgname) && - (topic1.pid == topic2.pid) && (topic1.pname == topic2.pname) && (topic1.uname == topic2.uname) && - (topic1.tid == topic2.tid) && (topic1.tname == topic2.tname) && (topic1.direction == topic2.direction) && CompareDataTypeInformation(topic1.tdatatype, topic2.tdatatype) && @@ -178,11 +167,19 @@ namespace eCAL (topic1.attr == topic2.attr); } + bool CompareIdentifier(const SampleIdentifier& identifier1, const SampleIdentifier& identifier2) + { + return (identifier1.entity_id == identifier2.entity_id) && + (identifier1.process_id == identifier2.process_id) && + (identifier1.host_name == identifier2.host_name); + } + // compare two Registration Sample objects bool CompareRegistrationSamples(const Sample& sample1, const Sample& sample2) { return (sample1.cmd_type == sample2.cmd_type) && (sample1.host.hname == sample2.host.hname) && + CompareIdentifier(sample1.identifier, sample2.identifier) && CompareProcess(sample1.process, sample2.process) && CompareService(sample1.service, sample2.service) && CompareClient(sample1.client, sample2.client) && diff --git a/ecal/tests/cpp/serialization_test/src/registration_generate.cpp b/ecal/tests/cpp/serialization_test/src/registration_generate.cpp index b969ca02..1fd33ece 100644 --- a/ecal/tests/cpp/serialization_test/src/registration_generate.cpp +++ b/ecal/tests/cpp/serialization_test/src/registration_generate.cpp @@ -16,9 +16,9 @@ * * ========================= eCAL LICENSE ================================= */ +#include "registration_generate.h" -#include "../../serialization/ecal_struct_sample_registration.h" - +#include #include namespace eCAL @@ -46,12 +46,9 @@ namespace eCAL { Service::Service service; service.rclock = rand() % 1000; - service.hname = GenerateString(8); service.pname = GenerateString(10); service.uname = GenerateString(5); - service.pid = rand() % 100; service.sname = GenerateString(8); - service.sid = GenerateString(7); service.methods.push_back(GenerateMethod()); service.methods.push_back(GenerateMethod()); service.version = rand() % 10; @@ -66,12 +63,9 @@ namespace eCAL { Service::Client client; client.rclock = rand() % 1000; - client.hname = GenerateString(8); client.pname = GenerateString(10); client.uname = GenerateString(5); - client.pid = rand() % 100; client.sname = GenerateString(8); - client.sid = GenerateString(7); client.methods.push_back(GenerateMethod()); client.methods.push_back(GenerateMethod()); client.version = rand() % 10; @@ -105,12 +99,9 @@ namespace eCAL { Topic topic; topic.rclock = rand() % 1000; - topic.hname = GenerateString(8); topic.hgname = GenerateString(6); - topic.pid = rand() % 100; topic.pname = GenerateString(10); topic.uname = GenerateString(5); - topic.tid = GenerateString(7); topic.tname = GenerateString(8); topic.direction = GenerateString(5); topic.tdatatype = GenerateDataTypeInformation(); @@ -126,31 +117,73 @@ namespace eCAL return topic; } - // generate Registration Sample - Sample GenerateRegistrationSample() + Process GenerateProcess() + { + Process process; + process.rclock = rand() % 1000; + process.hgname = GenerateString(6); + process.pname = GenerateString(10); + process.uname = GenerateString(5); + process.pparam = GenerateString(12); + process.state.severity = static_cast(rand() % (proc_sev_failed + 1)); + process.state.severity_level = static_cast(rand() % (proc_sev_level5 + 1)); + process.state.info = GenerateString(10); + process.tsync_state = static_cast(rand() % (tsync_replay + 1)); + process.tsync_mod_name = GenerateString(6); + process.component_init_state = rand() % 5; + process.component_init_info = GenerateString(8); + process.ecal_runtime_version = GenerateString(5); + return process; + } + + SampleIdentifier GenerateIdentifier() + { + SampleIdentifier identifier; + identifier.entity_id = GenerateString(7); + identifier.process_id = rand() % 100; + identifier.host_name = GenerateString(8); + return identifier; + } + + Sample GenerateProcessSample() { Sample sample; - sample.cmd_type = static_cast(rand() % (bct_unreg_client + 1)); - sample.host.hname = GenerateString(8); - sample.process.rclock = rand() % 1000; - sample.process.hname = GenerateString(8); - sample.process.hgname = GenerateString(6); - sample.process.pid = rand() % 100; - sample.process.pname = GenerateString(10); - sample.process.uname = GenerateString(5); - sample.process.pparam = GenerateString(12); - sample.process.state.severity = static_cast(rand() % (proc_sev_failed + 1)); - sample.process.state.severity_level = static_cast(rand() % (proc_sev_level5 + 1)); - sample.process.state.info = GenerateString(10); - sample.process.tsync_state = static_cast(rand() % (tsync_replay + 1)); - sample.process.tsync_mod_name = GenerateString(6); - sample.process.component_init_state = rand() % 5; - sample.process.component_init_info = GenerateString(8); - sample.process.ecal_runtime_version = GenerateString(5); - sample.service = GenerateService(); - sample.client = GenerateClient(); - sample.topic = GenerateTopic(); + sample.cmd_type = bct_reg_process; + sample.host.hname = GenerateString(8); + sample.identifier = GenerateIdentifier(); + // Process samples don't have an id internally, hence it must be 0. + sample.identifier.entity_id = ""; + sample.process = GenerateProcess(); + return sample; + } + Sample GenerateTopicSample() + { + Sample sample; + sample.cmd_type = bct_reg_publisher; + sample.host.hname = GenerateString(8); + sample.identifier = GenerateIdentifier(); + sample.topic = GenerateTopic(); + return sample; + } + + Sample GenerateServiceSample() + { + Sample sample; + sample.cmd_type = bct_reg_service; + sample.host.hname = GenerateString(8); + sample.identifier = GenerateIdentifier(); + sample.service = GenerateService(); + return sample; + } + + Sample GenerateClientSample() + { + Sample sample; + sample.cmd_type = bct_reg_client; + sample.host.hname = GenerateString(8); + sample.identifier = GenerateIdentifier(); + sample.client = GenerateClient(); return sample; } } diff --git a/ecal/tests/cpp/serialization_test/src/registration_generate.h b/ecal/tests/cpp/serialization_test/src/registration_generate.h new file mode 100644 index 00000000..64d1a765 --- /dev/null +++ b/ecal/tests/cpp/serialization_test/src/registration_generate.h @@ -0,0 +1,30 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2024 Continental Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ========================= eCAL LICENSE ================================= +*/ +#include "serialization/ecal_struct_sample_registration.h" + +namespace eCAL +{ + namespace Registration + { + Sample GenerateProcessSample(); + Sample GenerateTopicSample(); + Sample GenerateServiceSample(); + Sample GenerateClientSample(); + } +} \ No newline at end of file diff --git a/ecal/tests/cpp/serialization_test/src/registration_serialization_test.cpp b/ecal/tests/cpp/serialization_test/src/registration_serialization_test.cpp index b279884a..82c9c1bd 100644 --- a/ecal/tests/cpp/serialization_test/src/registration_serialization_test.cpp +++ b/ecal/tests/cpp/serialization_test/src/registration_serialization_test.cpp @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ */ #include "../../serialization/ecal_serialize_sample_registration.h" +#include "registration_generate.h" #include @@ -25,67 +26,86 @@ namespace eCAL { namespace Registration { - Sample GenerateRegistrationSample(); bool CompareRegistrationSamples(const Sample& sample1, const Sample& sample2); - TEST(core_cpp_serialization, Registration2String) - { - Sample sample_in = GenerateRegistrationSample(); + class RegistrationSampleSerializationTest : public ::testing::Test { + public: - std::string sample_buffer; - ASSERT_TRUE(SerializeToBuffer(sample_in, sample_buffer)); + RegistrationSampleSerializationTest() { + samples.push_back(GenerateProcessSample()); + samples.push_back(GenerateTopicSample()); + samples.push_back(GenerateServiceSample()); + samples.push_back(GenerateClientSample()); + } - Sample sample_out; - ASSERT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_out)); + protected: + std::vector samples; + }; + using core_cpp_registration_serialization = RegistrationSampleSerializationTest; - ASSERT_TRUE(CompareRegistrationSamples(sample_in, sample_out)); - } - TEST(core_cpp_serialization, Registration2Vector) + TEST_F(core_cpp_registration_serialization, Registration2String) { - Sample sample_in = GenerateRegistrationSample(); + for (const auto& sample_in : samples) + { + std::string sample_buffer; + EXPECT_TRUE(SerializeToBuffer(sample_in, sample_buffer)); - std::vector sample_buffer; - ASSERT_TRUE(SerializeToBuffer(sample_in, sample_buffer)); + Sample sample_out; + EXPECT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_out)); + + EXPECT_TRUE(CompareRegistrationSamples(sample_in, sample_out)); + } + } + + TEST_F(core_cpp_registration_serialization, Registration2Vector) + { + for (const auto& sample_in : samples) + { + std::vector sample_buffer; + EXPECT_TRUE(SerializeToBuffer(sample_in, sample_buffer)); - Sample sample_out; - ASSERT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_out)); + Sample sample_out; + EXPECT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_out)); - ASSERT_TRUE(CompareRegistrationSamples(sample_in, sample_out)); + EXPECT_TRUE(CompareRegistrationSamples(sample_in, sample_out)); + } } - TEST(core_cpp_serialization, RegistrationList2String) + TEST_F(core_cpp_registration_serialization, RegistrationList2String) { SampleList sample_list_in; - sample_list_in.samples.push_back(GenerateRegistrationSample()); - sample_list_in.samples.push_back(GenerateRegistrationSample()); - sample_list_in.samples.push_back(GenerateRegistrationSample()); + for (const auto& sample_in : samples) + { + sample_list_in.samples.push_back(sample_in); + } std::string sample_buffer; - ASSERT_TRUE(SerializeToBuffer(sample_list_in, sample_buffer)); + EXPECT_TRUE(SerializeToBuffer(sample_list_in, sample_buffer)); SampleList sample_list_out; - ASSERT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_list_out)); + EXPECT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_list_out)); - ASSERT_TRUE(sample_list_in.samples.size() == sample_list_out.samples.size()); - ASSERT_TRUE(std::equal(sample_list_in.samples.begin(), sample_list_in.samples.end(), sample_list_out.samples.begin(), CompareRegistrationSamples)); + EXPECT_TRUE(sample_list_in.samples.size() == sample_list_out.samples.size()); + EXPECT_TRUE(std::equal(sample_list_in.samples.begin(), sample_list_in.samples.end(), sample_list_out.samples.begin(), CompareRegistrationSamples)); } - TEST(core_cpp_serialization, RegistrationList2Vector) + TEST_F(core_cpp_registration_serialization, RegistrationList2Vector) { SampleList sample_list_in; - sample_list_in.samples.push_back(GenerateRegistrationSample()); - sample_list_in.samples.push_back(GenerateRegistrationSample()); - sample_list_in.samples.push_back(GenerateRegistrationSample()); + for (const auto& sample_in : samples) + { + sample_list_in.samples.push_back(sample_in); + } std::vector sample_buffer; - ASSERT_TRUE(SerializeToBuffer(sample_list_in, sample_buffer)); + EXPECT_TRUE(SerializeToBuffer(sample_list_in, sample_buffer)); SampleList sample_list_out; - ASSERT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_list_out)); + EXPECT_TRUE(DeserializeFromBuffer(sample_buffer.data(), sample_buffer.size(), sample_list_out)); - ASSERT_TRUE(sample_list_in.samples.size() == sample_list_out.samples.size()); - ASSERT_TRUE(std::equal(sample_list_in.samples.begin(), sample_list_in.samples.end(), sample_list_out.samples.begin(), CompareRegistrationSamples)); + EXPECT_TRUE(sample_list_in.samples.size() == sample_list_out.samples.size()); + EXPECT_TRUE(std::equal(sample_list_in.samples.begin(), sample_list_in.samples.end(), sample_list_out.samples.begin(), CompareRegistrationSamples)); } } }