Skip to content
Draft
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
3 changes: 2 additions & 1 deletion ecal/core/include/ecal/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <ecal/process_mode.h>
#include <ecal/process_severity.h>
#include <ecal/deprecate.h>
#include <ecal/types.h>

namespace eCAL
{
Expand Down Expand Up @@ -111,7 +112,7 @@ namespace eCAL
*
* @return The process id.
**/
ECAL_API int GetProcessID();
ECAL_API ProcessID GetProcessID();

/**
* @brief Get current process id as string.
Expand Down
19 changes: 18 additions & 1 deletion ecal/core/include/ecal/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#include <string>
#include <tuple>

#define ECAL_USE_STRONG_TYPES 0
#if ECAL_USE_STRONG_TYPES
#include <strong_type/strong_type.hpp>
#endif

namespace eCAL
{
/**
Expand Down Expand Up @@ -76,11 +81,23 @@ namespace eCAL
};

using EntityIdT = uint64_t;
#if ECAL_USE_STRONG_TYPES
using ProcessID = strong::type<
int32_t,
struct ProcessIDT,
strong::ostreamable,
strong::convertible_to<int32_t>,
strong::equality,
strong::hashable,
strong::ordered>;
# else
using ProcessID = int32_t;
# endif

struct SEntityId
{
EntityIdT entity_id = 0; // unique id within that process (it should already be unique within the whole system)
int32_t process_id = 0; // process id which produced the sample
ProcessID process_id{ 0 }; // process id which produced the sample
std::string host_name; // host which produced the sample

bool operator==(const SEntityId& other) const {
Expand Down
4 changes: 3 additions & 1 deletion ecal/core/include/ecal/types/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <list>
#include <string>

#include <ecal/types.h>

namespace eCAL
{
namespace Logging
Expand All @@ -38,7 +40,7 @@ namespace eCAL
{
int64_t time = 0; // time
std::string host_name; // host name
int32_t process_id = 0; // process id
ProcessID process_id{ 0 }; // process id
std::string process_name; // process name
std::string unit_name; // unit name
eLogLevel level = log_level_none; // message level
Expand Down
8 changes: 4 additions & 4 deletions ecal/core/include/ecal/types/monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace eCAL
int32_t registration_clock{0}; //!< registration clock (heart beat)
std::string host_name; //!< host name
std::string shm_transport_domain; //!< shm transport domain
int32_t process_id{0}; //!< process id
ProcessID process_id{0}; //!< process id
std::string process_name; //!< process name
std::string unit_name; //!< unit name
EntityIdT topic_id{0}; //!< topic id
Expand All @@ -99,7 +99,7 @@ namespace eCAL
int32_t registration_clock{0}; //!< registration clock
std::string host_name; //!< host name
std::string shm_transport_domain; //!< shm transport domain
int32_t process_id{0}; //!< process id
ProcessID process_id{0}; //!< process id
std::string process_name; //!< process name
std::string unit_name; //!< unit name
std::string process_parameter; //!< process parameter
Expand Down Expand Up @@ -146,7 +146,7 @@ namespace eCAL
std::string host_name; //<! host name
std::string process_name; //<! process name
std::string unit_name; //<! unit name
int32_t process_id{0}; //<! process id
ProcessID process_id{0}; //<! process id

std::string service_name; //<! service name
EntityIdT service_id{0}; //<! service id
Expand All @@ -164,7 +164,7 @@ namespace eCAL
std::string host_name; //<! host name
std::string process_name; //<! process name
std::string unit_name; //<! unit name
int32_t process_id{0}; //<! process id
ProcessID process_id{0}; //<! process id

std::string service_name; //<! service name
EntityIdT service_id{0}; //<! service id
Expand Down
3 changes: 2 additions & 1 deletion ecal/core/include/ecal/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <ecal/os.h>
#include <ecal/deprecate.h>
#include <ecal/types.h>

#include <string>
#include <utility>
Expand Down Expand Up @@ -76,7 +77,7 @@ namespace eCAL
*
* @param process_id_ Process id.
**/
ECAL_API void ShutdownProcess(int process_id_);
ECAL_API void ShutdownProcess(ProcessID process_id_);

/**
* @brief Send shutdown event to all local user processes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace eCAL
{
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Configuration& config_, int process_id_)
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Configuration& config_, ProcessID process_id_)
{
const auto& reg_config = config_.registration;
const auto& tl_udp_config = config_.transport_layer.udp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@

namespace eCAL
{
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Configuration& config_, int process_id_);
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Configuration& config_, ProcessID process_id_);
}
2 changes: 1 addition & 1 deletion ecal/core/src/ecal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace
const eCAL::EventHandleT& ShutdownProcEvent()
{
static eCAL::EventHandleT evt;
static const std::string event_name(EVENT_SHUTDOWN_PROC + std::string("_") + std::to_string(eCAL::Process::GetProcessID()));
static const std::string event_name(EVENT_SHUTDOWN_PROC + std::string("_") + std::to_string(static_cast<int32_t>(eCAL::Process::GetProcessID())));
if (!gEventIsValid(evt))
{
gOpenNamedEvent(&evt, event_name, true);
Expand Down
24 changes: 12 additions & 12 deletions ecal/core/src/ecal_global_accessors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@

namespace eCAL
{
std::shared_ptr<CGlobals> g_globals_ctx(nullptr);

std::string g_default_ini_file(ECAL_DEFAULT_CFG);
Configuration g_ecal_configuration{};

std::string g_host_name;
std::string g_unit_name;
std::string g_process_name;
std::string g_process_par;
int g_process_id(0);
std::string g_process_id_s;
std::shared_ptr<CGlobals> g_globals_ctx(nullptr);

std::string g_default_ini_file(ECAL_DEFAULT_CFG);
Configuration g_ecal_configuration{};

std::string g_host_name;
std::string g_unit_name;

std::string g_process_name;
std::string g_process_par;
ProcessID g_process_id{0};
std::string g_process_id_s;

Types::Process::SProcessState g_process_state;
std::mutex g_process_state_mutex;
Expand Down
3 changes: 2 additions & 1 deletion ecal/core/src/ecal_global_accessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <vector>

#include "ecal/types/process.h"
#include <ecal/types.h>

// Forward declaration of global accessible classes
namespace eCAL
Expand Down Expand Up @@ -119,7 +120,7 @@ namespace eCAL

extern std::string g_process_name;
extern std::string g_process_par;
extern int g_process_id;
extern ProcessID g_process_id;
extern std::string g_process_id_s;

extern Types::Process::SProcessState g_process_state;
Expand Down
16 changes: 9 additions & 7 deletions ecal/core/src/ecal_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include <thread>
#include <vector>

#include <ecal/types.h>

#ifdef ECAL_OS_WINDOWS
#include "ecal_win_main.h"
#include <iphlpapi.h>
Expand Down Expand Up @@ -301,10 +303,10 @@ namespace
{
void create_proc_id()
{
if (eCAL::g_process_id == 0)
if (::eCAL::g_process_id == ::eCAL::ProcessID{ 0 })
{
eCAL::g_process_id = GetCurrentProcessId();
eCAL::g_process_id_s = std::to_string(eCAL::g_process_id);
::eCAL::g_process_id = ::eCAL::ProcessID{ static_cast<int32_t>(GetCurrentProcessId()) };
::eCAL::g_process_id_s = std::to_string(static_cast<int32_t>(::eCAL::g_process_id));
}
}
}
Expand All @@ -313,7 +315,7 @@ namespace eCAL
{
namespace Process
{
int GetProcessID()
ProcessID GetProcessID()
{
create_proc_id();
return(g_process_id);
Expand Down Expand Up @@ -588,9 +590,9 @@ namespace
{
void create_proc_id()
{
if (eCAL::g_process_id == 0)
if (eCAL::g_process_id == eCAL::ProcessID{ 0 })
{
eCAL::g_process_id = getpid();
eCAL::g_process_id = eCAL::ProcessID{ getpid() };
eCAL::g_process_id_s = std::to_string(eCAL::g_process_id);
}
}
Expand Down Expand Up @@ -683,7 +685,7 @@ namespace eCAL
{
namespace Process
{
int GetProcessID()
ProcessID GetProcessID()
{
create_proc_id();
return(g_process_id);
Expand Down
14 changes: 7 additions & 7 deletions ecal/core/src/ecal_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace eCAL
const Monitoring::SMonitoring monitoring = GetMonitoring();
const std::string host_name = Process::GetHostName();

std::vector<int> proc_id_list;
std::vector<ProcessID> proc_id_list;
for (const auto& process : monitoring.processes)
{
const std::string process_name = process.process_name;
Expand All @@ -80,15 +80,15 @@ namespace eCAL
}
}

for (auto id : proc_id_list)
for (const auto& id : proc_id_list)
{
ShutdownProcess(id);
}
}

void ShutdownProcess(const int process_id_)
void ShutdownProcess(const ProcessID process_id_)
{
const std::string event_name = EVENT_SHUTDOWN_PROC + std::string("_") + std::to_string(process_id_);
const std::string event_name = EVENT_SHUTDOWN_PROC + std::string("_") + std::to_string(static_cast<int32_t>(process_id_));
EventHandleT event;
if (gOpenNamedEvent(&event, event_name, true))
{
Expand All @@ -103,7 +103,7 @@ namespace eCAL
const Monitoring::SMonitoring monitoring = GetMonitoring();
const std::string host_name = eCAL::Process::GetHostName();

std::vector<int> proc_id_list;
std::vector<ProcessID> proc_id_list;
for (const auto& process : monitoring.processes)
{
const std::string unit_name = process.unit_name;
Expand Down Expand Up @@ -134,7 +134,7 @@ namespace eCAL
const Monitoring::SMonitoring monitoring = GetMonitoring();
const std::string host_name = Process::GetHostName();

std::vector<int> proc_id_list;
std::vector<ProcessID> proc_id_list;
for (const auto& process : monitoring.processes)
{
const std::string unit_name = process.unit_name;
Expand All @@ -155,7 +155,7 @@ namespace eCAL
}
}

for (auto id : proc_id_list)
for (const auto& id : proc_id_list)
{
ShutdownProcess(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string>

#include <ecal/log_level.h>
#include <ecal/types.h>

namespace eCAL
{
Expand Down Expand Up @@ -57,7 +58,7 @@ namespace eCAL
SUDP udp_config;
SFile file_config;

int process_id;
ProcessID process_id{ 0 };
std::string host_name;
std::string process_name;
std::string unit_name;
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/logging/ecal_log_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ namespace eCAL
if (EcalUtils::Filesystem::ToUnixSeperators(log_path).back() == '/')
log_path.pop_back();

const std::string file_name = tstring + "_" + m_attributes.unit_name + "_" + std::to_string(m_attributes.process_id) + ".log";
const std::string file_name = tstring + "_" + m_attributes.unit_name + "_" + std::to_string(static_cast<int32_t>(m_attributes.process_id)) + ".log";
const std::vector<std::string> file_path_components = { log_path, file_name };

m_logfile_name = EcalUtils::String::Join(std::string(1, EcalUtils::Filesystem::NativeSeparator()), file_path_components);
Expand Down
8 changes: 4 additions & 4 deletions ecal/core/src/monitoring/ecal_monitoring_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,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_.identifier.process_id;
const ProcessID process_id = sample_.identifier.process_id;
const std::string& topic_name = sample_topic.topic_name;
const int32_t topic_size = sample_topic.topic_size;
bool topic_tlayer_ecal_udp(false);
Expand Down Expand Up @@ -279,7 +279,7 @@ namespace eCAL
const std::string& host_name = sample_.identifier.host_name;
const std::string& shm_transport_domain = sample_process.shm_transport_domain;
const std::string& process_name = sample_process.process_name;
const int process_id = sample_.identifier.process_id;
const ProcessID process_id = sample_.identifier.process_id;
const std::string& process_param = sample_process.process_parameter;
const std::string& unit_name = sample_process.unit_name;
const auto& sample_process_state = sample_process.state;
Expand Down Expand Up @@ -342,7 +342,7 @@ namespace eCAL
{
const auto& sample_identifier = sample_.identifier;
const auto& service_id = sample_.identifier.entity_id;
const int32_t process_id = sample_identifier.process_id;
const ProcessID process_id = sample_identifier.process_id;
const std::string& host_name = sample_identifier.host_name;

const auto& sample_service = sample_.service;
Expand Down Expand Up @@ -408,7 +408,7 @@ namespace eCAL
{
const auto& sample_identifier = sample_.identifier;
const auto& service_id = sample_identifier.entity_id;
const int32_t process_id = sample_identifier.process_id;
const ProcessID process_id = sample_identifier.process_id;
const std::string& host_name = sample_identifier.host_name;

const auto& sample_client = sample_.client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string>
#include <cstddef>
#include <ecal/config/configuration.h>
#include <ecal/types.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like the coupling we're introducing here.


namespace eCAL
{
Expand Down Expand Up @@ -62,7 +63,7 @@ namespace eCAL
std::string topic_name;
std::string host_name;
std::string shm_transport_domain;
int process_id;
ProcessID process_id{ 0 };
std::string process_name;
std::string unit_name;
bool share_topic_type;
Expand Down
Loading
Loading