Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/registration provider refactoring #1647

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,22 @@ endif()
######################################
if (ECAL_CORE_REGISTRATION)
set(ecal_registration_src
src/registration/ecal_process_registration.cpp
src/registration/ecal_process_registration.h
src/registration/ecal_registration_provider.cpp
src/registration/ecal_registration_provider.h
src/registration/ecal_registration_receiver.cpp
src/registration/ecal_registration_receiver.h
src/registration/ecal_registration_sender.h
src/registration/ecal_registration_sender_udp.cpp
src/registration/ecal_registration_sender_udp.h
)
if(ECAL_CORE_REGISTRATION_SHM)
list(APPEND ecal_registration_src
src/registration/ecal_registration_receiver_shm.cpp
src/registration/ecal_registration_receiver_shm.h
src/registration/ecal_registration_sender_shm.cpp
src/registration/ecal_registration_sender_shm.h
src/registration/shm/ecal_memfile_broadcast.cpp
src/registration/shm/ecal_memfile_broadcast.h
src/registration/shm/ecal_memfile_broadcast_reader.cpp
Expand Down
104 changes: 104 additions & 0 deletions ecal/core/src/registration/ecal_process_registration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* ========================= 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 =================================
*/

/**
* @brief Functions to generate Process Registration / Unregistration samples.
*
**/

#include "ecal_process_registration.h"

#include <ecal/ecal_init.h>
#include <ecal/ecal_process.h>
#include "ecal_global_accessors.h"
#include "ecal_globals.h"
#include "time/ecal_timegate.h"

eCAL::Registration::Sample eCAL::Registration::GetProcessRegisterSample()
{
Registration::Sample process_sample;
process_sample.cmd_type = bct_reg_process;
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();
process_sample_process.state.severity = static_cast<Registration::eProcessSeverity>(g_process_severity);
process_sample_process.state.severity_level = static_cast<Registration::eProcessSeverityLevel>(g_process_severity_level);
process_sample_process.state.info = g_process_info;
#if ECAL_CORE_TIMEPLUGIN
if (g_timegate() == nullptr)
{
process_sample_process.tsync_state = Registration::eTSyncState::tsync_none;
}
else
{
if (!g_timegate()->IsSynchronized())
{
process_sample_process.tsync_state = Registration::eTSyncState::tsync_none;
}
else
{
switch (g_timegate()->GetSyncMode())
{
case CTimeGate::eTimeSyncMode::realtime:
process_sample_process.tsync_state = Registration::eTSyncState::tsync_realtime;
break;
case CTimeGate::eTimeSyncMode::replay:
process_sample_process.tsync_state = Registration::eTSyncState::tsync_replay;
break;
default:
process_sample_process.tsync_state = Registration::eTSyncState::tsync_none;
break;
}
}
process_sample_process.tsync_mod_name = g_timegate()->GetName();
}
#endif

// eCAL initialization state
const unsigned int comp_state(g_globals()->GetComponents());
process_sample_process.component_init_state = static_cast<int32_t>(comp_state);
std::string component_info;
if ((comp_state & eCAL::Init::Publisher) != 0u) component_info += "|pub";
if ((comp_state & eCAL::Init::Subscriber) != 0u) component_info += "|sub";
if ((comp_state & eCAL::Init::Logging) != 0u) component_info += "|log";
if ((comp_state & eCAL::Init::TimeSync) != 0u) component_info += "|time";
if (!component_info.empty()) component_info = component_info.substr(1);
process_sample_process.component_init_info = component_info;

process_sample_process.ecal_runtime_version = eCAL::GetVersionString();

return process_sample;
}

eCAL::Registration::Sample eCAL::Registration::GetProcessUnregisterSample()
{
Registration::Sample process_sample;
process_sample.cmd_type = bct_unreg_process;
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();

return process_sample;
}
37 changes: 37 additions & 0 deletions ecal/core/src/registration/ecal_process_registration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* ========================= 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 =================================
*/

/**
* @brief Functions to generate Process Registration / Unregistration samples.
*
**/

#pragma once

#include "serialization/ecal_struct_sample_registration.h"

namespace eCAL
{
namespace Registration
{
Sample GetProcessRegisterSample();

Sample GetProcessUnregisterSample();
}
}
Loading
Loading