|
| 1 | +/* ========================= eCAL LICENSE ================================= |
| 2 | + * |
| 3 | + * Copyright (C) 2016 - 2024 Continental Corporation |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + * ========================= eCAL LICENSE ================================= |
| 18 | +*/ |
| 19 | + |
| 20 | +/** |
| 21 | + * @brief Functions to generate Process Registration / Unregistration samples. |
| 22 | + * |
| 23 | +**/ |
| 24 | + |
| 25 | +#include "ecal_process_registration.h" |
| 26 | + |
| 27 | +#include <ecal/ecal_init.h> |
| 28 | +#include <ecal/ecal_process.h> |
| 29 | +#include "ecal_global_accessors.h" |
| 30 | +#include "ecal_globals.h" |
| 31 | +#include "time/ecal_timegate.h" |
| 32 | + |
| 33 | +eCAL::Registration::Sample eCAL::Registration::GetProcessRegisterSample() |
| 34 | +{ |
| 35 | + Registration::Sample process_sample; |
| 36 | + process_sample.cmd_type = bct_reg_process; |
| 37 | + auto& process_sample_process = process_sample.process; |
| 38 | + process_sample_process.hname = eCAL::Process::GetHostName(); |
| 39 | + process_sample_process.hgname = eCAL::Process::GetHostGroupName(); |
| 40 | + process_sample_process.pid = eCAL::Process::GetProcessID(); |
| 41 | + process_sample_process.pname = eCAL::Process::GetProcessName(); |
| 42 | + process_sample_process.uname = eCAL::Process::GetUnitName(); |
| 43 | + process_sample_process.pparam = eCAL::Process::GetProcessParameter(); |
| 44 | + process_sample_process.state.severity = static_cast<Registration::eProcessSeverity>(g_process_severity); |
| 45 | + process_sample_process.state.severity_level = static_cast<Registration::eProcessSeverityLevel>(g_process_severity_level); |
| 46 | + process_sample_process.state.info = g_process_info; |
| 47 | +#if ECAL_CORE_TIMEPLUGIN |
| 48 | + if (g_timegate() == nullptr) |
| 49 | + { |
| 50 | + process_sample_process.tsync_state = Registration::eTSyncState::tsync_none; |
| 51 | + } |
| 52 | + else |
| 53 | + { |
| 54 | + if (!g_timegate()->IsSynchronized()) |
| 55 | + { |
| 56 | + process_sample_process.tsync_state = Registration::eTSyncState::tsync_none; |
| 57 | + } |
| 58 | + else |
| 59 | + { |
| 60 | + switch (g_timegate()->GetSyncMode()) |
| 61 | + { |
| 62 | + case CTimeGate::eTimeSyncMode::realtime: |
| 63 | + process_sample_process.tsync_state = Registration::eTSyncState::tsync_realtime; |
| 64 | + break; |
| 65 | + case CTimeGate::eTimeSyncMode::replay: |
| 66 | + process_sample_process.tsync_state = Registration::eTSyncState::tsync_replay; |
| 67 | + break; |
| 68 | + default: |
| 69 | + process_sample_process.tsync_state = Registration::eTSyncState::tsync_none; |
| 70 | + break; |
| 71 | + } |
| 72 | + } |
| 73 | + process_sample_process.tsync_mod_name = g_timegate()->GetName(); |
| 74 | + } |
| 75 | +#endif |
| 76 | + |
| 77 | + // eCAL initialization state |
| 78 | + const unsigned int comp_state(g_globals()->GetComponents()); |
| 79 | + process_sample_process.component_init_state = static_cast<int32_t>(comp_state); |
| 80 | + std::string component_info; |
| 81 | + if ((comp_state & eCAL::Init::Publisher) != 0u) component_info += "|pub"; |
| 82 | + if ((comp_state & eCAL::Init::Subscriber) != 0u) component_info += "|sub"; |
| 83 | + if ((comp_state & eCAL::Init::Logging) != 0u) component_info += "|log"; |
| 84 | + if ((comp_state & eCAL::Init::TimeSync) != 0u) component_info += "|time"; |
| 85 | + if (!component_info.empty()) component_info = component_info.substr(1); |
| 86 | + process_sample_process.component_init_info = component_info; |
| 87 | + |
| 88 | + process_sample_process.ecal_runtime_version = eCAL::GetVersionString(); |
| 89 | + |
| 90 | + return process_sample; |
| 91 | +} |
| 92 | + |
| 93 | +eCAL::Registration::Sample eCAL::Registration::GetProcessUnregisterSample() |
| 94 | +{ |
| 95 | + Registration::Sample process_sample; |
| 96 | + process_sample.cmd_type = bct_unreg_process; |
| 97 | + auto& process_sample_process = process_sample.process; |
| 98 | + process_sample_process.hname = eCAL::Process::GetHostName(); |
| 99 | + process_sample_process.pid = eCAL::Process::GetProcessID(); |
| 100 | + process_sample_process.pname = eCAL::Process::GetProcessName(); |
| 101 | + process_sample_process.uname = eCAL::Process::GetUnitName(); |
| 102 | + |
| 103 | + return process_sample; |
| 104 | +} |
0 commit comments