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

[core] Aligned return types of ecal_core.h and ecal_logging.h #1867

Merged
merged 5 commits into from
Dec 19, 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
8 changes: 4 additions & 4 deletions ecal/core/include/ecal/cimpl/ecal_core_cimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extern "C"
* @param unit_name_ Defines the name of the eCAL unit.
* @param components_ Defines which component to initialize.
*
* @return Zero if succeeded, 1 if already initialized, -1 if failed.
* @return Zero if succeeded.
**/
ECALC_API int eCAL_Initialize(const char *unit_name_, unsigned int components_);

Expand All @@ -83,21 +83,21 @@ extern "C"
/**
* @brief Finalize eCAL API.
*
* @return Zero if succeeded, 1 if already finalized, -1 if failed.
* @return Zero if succeeded.
**/
ECALC_API int eCAL_Finalize();

/**
* @brief Check eCAL initialize state.
*
* @return None zero if eCAL is initialized.
* @return Non-zero if eCAL is initialized.
**/
ECALC_API int eCAL_IsInitialized();

/**
* @brief Return the eCAL process state.
*
* @return None zero if eCAL is in proper state.
* @return Non-zero if eCAL is in proper state.
**/
ECALC_API int eCAL_Ok();

Expand Down
24 changes: 12 additions & 12 deletions ecal/core/include/ecal/ecal_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ namespace eCAL
* @param unit_name_ Defines the name of the eCAL unit.
* @param components_ Defines which component to initialize.
*
* @return Zero if succeeded, 1 if already initialized, -1 if failed.
* @return True.
**/
ECAL_API int Initialize(const std::string& unit_name_ = "", unsigned int components_ = Init::Default);
ECAL_API bool Initialize(const std::string& unit_name_ = "", unsigned int components_ = Init::Default);

/**
* @brief Initialize eCAL API.
Expand All @@ -74,42 +74,42 @@ namespace eCAL
* @param unit_name_ Defines the name of the eCAL unit.
* @param components_ Defines which component to initialize.
*
* @return Zero if succeeded, 1 if already initialized, -1 if failed.
* @return True if succeeded.
**/
ECAL_API int Initialize(eCAL::Configuration& config_, const std::string& unit_name_ = "", unsigned int components_ = Init::Default);
ECAL_API bool Initialize(eCAL::Configuration& config_, const std::string& unit_name_ = "", unsigned int components_ = Init::Default);

/**
* @brief Finalize eCAL API.
*
* @return Zero if succeeded, 1 if already finalized, -1 if failed.
* @return True if succeeded.
**/
ECAL_API int Finalize();
ECAL_API bool Finalize();

/**
* @brief Check eCAL initialize state.
*
* @return 1 if eCAL is initialized.
* @return True if eCAL is initialized.
**/
ECAL_API int IsInitialized();
ECAL_API bool IsInitialized();

/**
* @brief Check initialization state for a specific component.
*
* @param component_ Specific component to check
*
* @return 1 if eCAL component is initialized.
* @return True if eCAL component is initialized.
**/
ECAL_API int IsInitialized(unsigned int component_);
ECAL_API bool IsInitialized(unsigned int component_);


/**
* @brief Set/change the unit name of current module.
*
* @param unit_name_ Defines the name of the eCAL unit.
*
* @return Zero if succeeded.
* @return True if succeeded.
**/
ECAL_API int SetUnitName(const std::string& unit_name_);
ECAL_API bool SetUnitName(const std::string& unit_name_);

/**
* @brief Return the eCAL process state.
Expand Down
8 changes: 4 additions & 4 deletions ecal/core/include/ecal/ecal_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ namespace eCAL
*
* @param [out] log_ String to store the logging information.
*
* @return Logging buffer length or zero if failed.
* @return True if succeeded.
**/
ECAL_API int GetLogging(std::string& log_);
ECAL_API bool GetLogging(std::string& log_);

/**
* @brief Get logging as struct.
*
* @param [out] log_ Target struct to store the logging information.
*
* @return Number of log messages.
* @return True if succeeded.
**/
ECAL_API int GetLogging(Logging::SLogging& log_);
ECAL_API bool GetLogging(Logging::SLogging& log_);
}
}
8 changes: 4 additions & 4 deletions ecal/core/src/cimpl/ecal_core_cimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ extern "C"
ECALC_API int eCAL_Initialize(const char* unit_name_, unsigned int components_)
{
const std::string unit_name = (unit_name_ != nullptr) ? std::string(unit_name_) : std::string("");
return eCAL::Initialize(unit_name, components_);
return static_cast<int>(!eCAL::Initialize(unit_name, components_));
}

ECALC_API int eCAL_SetUnitName(const char* unit_name_)
{
const std::string unit_name = (unit_name_ != nullptr) ? std::string(unit_name_) : std::string("");
return(eCAL::SetUnitName(unit_name));
return static_cast<int>(!eCAL::SetUnitName(unit_name));
}

ECALC_API int eCAL_Finalize()
{
return(eCAL::Finalize());
return static_cast<int>(!eCAL::Finalize());
}

ECALC_API int eCAL_IsInitialized()
{
return(eCAL::IsInitialized());
return static_cast<int>(eCAL::IsInitialized());
}

ECALC_API int eCAL_Ok()
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/cimpl/ecal_log_cimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern "C"
ECALC_API int eCAL_Logging_GetLogging(void* buf_, int buf_len_)
{
std::string buf;
if (eCAL::Logging::GetLogging(buf) != 0)
if (eCAL::Logging::GetLogging(buf))
{
return(CopyBuffer(buf_, buf_len_, buf));
}
Expand Down
55 changes: 30 additions & 25 deletions ecal/core/src/ecal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ namespace eCAL
* @param unit_name_ Defines the name of the eCAL unit.
* @param components_ Defines which component to initialize.
*
* @return Zero if succeeded, 1 if already initialized, -1 if failed.
* @return True if succeeded.
**/
int Initialize(const std::string& unit_name_ /*= ""*/, unsigned int components_ /*= Init::Default*/)
bool Initialize(const std::string& unit_name_ /*= ""*/, unsigned int components_ /*= Init::Default*/)
{
eCAL::Configuration config;

Expand All @@ -101,9 +101,9 @@ namespace eCAL
* @param unit_name_ Defines the name of the eCAL unit.
* @param components_ Defines which component to initialize.
*
* @return Zero if succeeded, 1 if already initialized, -1 if failed.
* @return True if succeeded
**/
int Initialize(eCAL::Configuration& config_, const std::string& unit_name_ /*= nullptr*/, unsigned int components_ /*= Init::Default*/)
bool Initialize(eCAL::Configuration& config_, const std::string& unit_name_ /*= nullptr*/, unsigned int components_ /*= Init::Default*/)
{
InitGlobals();

Expand All @@ -114,7 +114,7 @@ namespace eCAL
g_globals_ctx_ref_cnt++;

// (post)initialize single components
const int success = g_globals()->Initialize(components_);
const auto success = g_globals()->Initialize(components_);

if (config_.command_line_arguments.dump_config)
{
Expand All @@ -129,57 +129,62 @@ namespace eCAL
*
* @param component_ Check specific component or 0 for general state of eCAL core.
*
* @return 1 if eCAL is initialized.
* @return True if eCAL is initialized.
**/
int IsInitialized()
bool IsInitialized()
{
if (g_globals_ctx == nullptr) return(0);
if(g_globals()->IsInitialized()) return(1);
return(0);
if (g_globals_ctx == nullptr)
return false;

return g_globals()->IsInitialized();
}

/**
* @brief Check eCAL initialize state.
*
* @param component_ Check specific component or 0 for general state of eCAL core.
*
* @return 1 if eCAL is initialized.
* @return True if component is initialized.
**/
int IsInitialized(unsigned int component_)
bool IsInitialized(unsigned int component_)
{
if (g_globals_ctx == nullptr) return(0);
if (g_globals()->IsInitialized(component_)) return(1);
return(0);
if (g_globals_ctx == nullptr)
return false;

return g_globals()->IsInitialized(component_);
}

/**
* @brief Set/change the unit name of current module.
*
* @param unit_name_ Defines the name of the eCAL unit.
*
* @return Zero if succeeded, -1 if failed.
* @return True if succeeded.
**/
int SetUnitName(const std::string& unit_name_)
bool SetUnitName(const std::string& unit_name_)
{
if (unit_name_.empty()) return -1;
if (unit_name_.empty())
return false;
g_unit_name = unit_name_;
return 0;
return true;
}

/**
* @brief Finalize eCAL API.
*
* @return Zero if succeeded, 1 if already finalized, -1 if failed.
* @return True if succeeded.
**/
int Finalize()
bool Finalize()
{
if (g_globals_ctx == nullptr) return 1;
if (g_globals_ctx == nullptr)
return false;
g_globals_ctx_ref_cnt--;
if (g_globals_ctx_ref_cnt > 0) return 0;
int const ret = g_globals()->Finalize();
if (g_globals_ctx_ref_cnt > 0)
return true;
const auto ret = g_globals()->Finalize();
delete g_globals_ctx;
g_globals_ctx = nullptr;
return(ret);
return ret;
}

/**
Expand Down
11 changes: 5 additions & 6 deletions ecal/core/src/ecal_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace eCAL
Finalize();
}

int CGlobals::Initialize(unsigned int components_)
bool CGlobals::Initialize(unsigned int components_)
{
// will be set if any new module was initialized
bool new_initialization(false);
Expand Down Expand Up @@ -245,8 +245,7 @@ namespace eCAL
initialized = true;
components |= components_;

if (new_initialization) return 0;
else return 1;
return new_initialization;
}

bool CGlobals::IsInitialized()
Expand Down Expand Up @@ -286,9 +285,9 @@ namespace eCAL
}
}

int CGlobals::Finalize()
bool CGlobals::Finalize()
{
if (!initialized) return(1);
if (!initialized) return false;

// start destruction
#if ECAL_CORE_MONITORING
Expand Down Expand Up @@ -364,6 +363,6 @@ namespace eCAL
// reset configuration to default values
g_ecal_configuration = Configuration();

return(0);
return true;
}
}
4 changes: 2 additions & 2 deletions ecal/core/src/ecal_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ namespace eCAL
CGlobals();
~CGlobals();

int Initialize ( unsigned int components_);
bool Initialize ( unsigned int components_);
bool IsInitialized ();
bool IsInitialized ( unsigned int component_ );

unsigned int GetComponents() const { return(components); };

int Finalize();
bool Finalize();

const std::unique_ptr<Logging::CLogProvider>& log_provider() { return log_provider_instance; };
const std::unique_ptr<Logging::CLogReceiver>& log_udp_receiver() { return log_udp_receiver_instance; };
Expand Down
20 changes: 12 additions & 8 deletions ecal/core/src/logging/ecal_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,29 @@ namespace eCAL
*
* @param [out] log_ String to store the logging information.
*
* @return Logging buffer length or zero if failed.
* @return True if succeeded.
**/
int GetLogging(std::string& log_)
bool GetLogging(std::string& log_)
{
if (g_log_udp_receiver() != nullptr) g_log_udp_receiver()->GetLogging(log_);
return static_cast<int>(log_.size());
if (g_log_udp_receiver() == nullptr)
return false;
g_log_udp_receiver()->GetLogging(log_);
return true;
}

/**
* @brief Get logging as struct.
*
* @param [out] log_ Target struct to store the logging information.
*
* @return Number of struct elements if succeeded.
* @return True if succeeded.
**/
int GetLogging(Logging::SLogging& log_)
bool GetLogging(Logging::SLogging& log_)
{
if (g_log_udp_receiver() != nullptr) g_log_udp_receiver()->GetLogging(log_);
return static_cast<int>(log_.log_messages.size());
if (g_log_udp_receiver() == nullptr)
return false;
g_log_udp_receiver()->GetLogging(log_);
return true;
}
}
}
4 changes: 2 additions & 2 deletions ecal/tests/c/core_test/src/core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ TEST(core_c_core, SetGetUnitName)
EXPECT_STREQ("unit name", unit_name);

// set nullptr unit name (should not change the unit name)
EXPECT_EQ(-1, eCAL_SetUnitName(nullptr));
EXPECT_EQ(1, eCAL_SetUnitName(nullptr));
memset(unit_name, 0, sizeof(unit_name));
eCAL_Process_GetUnitName(unit_name, sizeof(unit_name));
EXPECT_STREQ("unit name", unit_name);

// set empty unit name (should not change the unit name)
EXPECT_EQ(-1, eCAL_SetUnitName(""));
EXPECT_EQ(1, eCAL_SetUnitName(""));
memset(unit_name, 0, sizeof(unit_name));
eCAL_Process_GetUnitName(unit_name, sizeof(unit_name));
EXPECT_STREQ("unit name", unit_name);
Expand Down
Loading
Loading