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

ecal c api split #33

Merged
merged 5 commits into from
Feb 28, 2024
Merged

ecal c api split #33

merged 5 commits into from
Feb 28, 2024

Conversation

rex-schilasky
Copy link
Contributor

Description

  • eCAL C API module ecalc.cpp split in single units
  • deprecated functions removed

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 20 out of 54. Check the log or trigger a new build to see more.

if(source_s_.empty()) return(0);
if(target_len_ == ECAL_ALLOCATE_4ME)
{
void* buf_alloc = malloc(source_s_.size());

Choose a reason for hiding this comment

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

warning: initializing non-owner 'void *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]

    void* buf_alloc = malloc(source_s_.size());
    ^

if(source_s_.empty()) return(0);
if(target_len_ == ECAL_ALLOCATE_4ME)
{
void* buf_alloc = malloc(source_s_.size());

Choose a reason for hiding this comment

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

warning: do not manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]

    void* buf_alloc = malloc(source_s_.size());
                      ^

{
void* buf_alloc = malloc(source_s_.size());
if(buf_alloc == nullptr) return(0);
int copied = CopyBuffer(buf_alloc, static_cast<int>(source_s_.size()), source_s_);

Choose a reason for hiding this comment

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

warning: variable 'copied' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int copied = CopyBuffer(buf_alloc, static_cast<int>(source_s_.size()), source_s_);
int const copied = CopyBuffer(buf_alloc, static_cast<int>(source_s_.size()), source_s_);

int copied = CopyBuffer(buf_alloc, static_cast<int>(source_s_.size()), source_s_);
if(copied > 0)
{
*((void**)target_) = buf_alloc; //-V206

Choose a reason for hiding this comment

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

warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]

     *((void**)target_) = buf_alloc; //-V206
       ^

else
{
// copying buffer failed, so free allocated memory.
free(buf_alloc);

Choose a reason for hiding this comment

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

warning: do not manage memory manually; use RAII [cppcoreguidelines-no-malloc]

      free(buf_alloc);
      ^


ECALC_API int eCAL_Process_GetHostName(void* name_, int name_len_)
{
std::string name = eCAL::Process::GetHostName();

Choose a reason for hiding this comment

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

warning: variable 'name' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string name = eCAL::Process::GetHostName();
std::string const name = eCAL::Process::GetHostName();


ECALC_API int eCAL_Process_GetUnitName(void* name_, int name_len_)
{
std::string name = eCAL::Process::GetUnitName();

Choose a reason for hiding this comment

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

warning: variable 'name' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string name = eCAL::Process::GetUnitName();
std::string const name = eCAL::Process::GetUnitName();


ECALC_API int eCAL_Process_GetTaskParameter(void* par_, int par_len_, const char* sep_)
{
std::string par = eCAL::Process::GetTaskParameter(sep_);

Choose a reason for hiding this comment

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

warning: variable 'par' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string par = eCAL::Process::GetTaskParameter(sep_);
std::string const par = eCAL::Process::GetTaskParameter(sep_);


ECALC_API int eCAL_Process_GetProcessName(void* name_, int name_len_)
{
std::string name = eCAL::Process::GetProcessName();

Choose a reason for hiding this comment

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

warning: variable 'name' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string name = eCAL::Process::GetProcessName();
std::string const name = eCAL::Process::GetProcessName();


ECALC_API int eCAL_Process_GetProcessParameter(void* par_, int par_len_)
{
std::string par = eCAL::Process::GetProcessParameter();

Choose a reason for hiding this comment

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

warning: variable 'par' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string par = eCAL::Process::GetProcessParameter();
std::string const par = eCAL::Process::GetProcessParameter();

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 20 out of 34. Check the log or trigger a new build to see more.


ECALC_API int eCAL_Process_StopProcessName(const char* proc_name_)
{
return(eCAL::Process::StopProcess(proc_name_));

Choose a reason for hiding this comment

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

warning: implicit conversion bool -> 'int' [readability-implicit-bool-conversion]

Suggested change
return(eCAL::Process::StopProcess(proc_name_));
returnstatic_cast<int>(eCAL::Process::StopProcess(proc_name_));


ECALC_API int eCAL_Process_StopProcessID(int proc_id_)
{
return(eCAL::Process::StopProcess(proc_id_));

Choose a reason for hiding this comment

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

warning: implicit conversion bool -> 'int' [readability-implicit-bool-conversion]

Suggested change
return(eCAL::Process::StopProcess(proc_id_));
returnstatic_cast<int>(eCAL::Process::StopProcess(proc_id_));

#if ECAL_CORE_PUBLISHER
namespace
{
std::recursive_mutex g_pub_event_callback_mtx;

Choose a reason for hiding this comment

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

warning: variable 'g_pub_event_callback_mtx' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

  std::recursive_mutex g_pub_event_callback_mtx;
                       ^

{
ECALC_API ECAL_HANDLE eCAL_Pub_New()
{
auto* pub = new eCAL::CPublisher;

Choose a reason for hiding this comment

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

warning: initializing non-owner 'eCAL::CPublisher *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]

    auto* pub = new eCAL::CPublisher;
    ^

{
if (handle_ == nullptr) return(0);
auto* pub = static_cast<eCAL::CPublisher*>(handle_);
struct eCAL::SDataTypeInformation topic_info = { topic_type_name_, topic_type_encoding_, std::string(topic_desc_, static_cast<size_t>(topic_desc_len_)) };

Choose a reason for hiding this comment

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

warning: variable 'topic_info' of type 'struct eCAL::SDataTypeInformation' can be declared 'const' [misc-const-correctness]

Suggested change
struct eCAL::SDataTypeInformation topic_info = { topic_type_name_, topic_type_encoding_, std::string(topic_desc_, static_cast<size_t>(topic_desc_len_)) };
struct eCAL::SDataTypeInformation const topic_info = { topic_type_name_, topic_type_encoding_, std::string(topic_desc_, static_cast<size_t>(topic_desc_len_)) };

{
if (handle_ == nullptr) return(0);
auto* sub = static_cast<eCAL::CSubscriber*>(handle_);
struct eCAL::SDataTypeInformation topic_info = { topic_type_name_, topic_type_encoding_, std::string(topic_desc_, static_cast<size_t>(topic_desc_len_)) };

Choose a reason for hiding this comment

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

warning: variable 'topic_info' of type 'struct eCAL::SDataTypeInformation' can be declared 'const' [misc-const-correctness]

Suggested change
struct eCAL::SDataTypeInformation topic_info = { topic_type_name_, topic_type_encoding_, std::string(topic_desc_, static_cast<size_t>(topic_desc_len_)) };
struct eCAL::SDataTypeInformation const topic_info = { topic_type_name_, topic_type_encoding_, std::string(topic_desc_, static_cast<size_t>(topic_desc_len_)) };

{
if (handle_ == nullptr) return(0);
auto* sub = static_cast<eCAL::CSubscriber*>(handle_);
delete sub;

Choose a reason for hiding this comment

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

warning: deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead [cppcoreguidelines-owning-memory]

    delete sub;
    ^
Additional context

ecal/core/src/cimpl/ecal_subscriber_cimpl.cpp:83: variable declared here

    auto* sub = static_cast<eCAL::CSubscriber*>(handle_);
    ^

if (handle_ == nullptr) return(0);
auto* sub = static_cast<eCAL::CSubscriber*>(handle_);
const eCAL::SDataTypeInformation datatype_info = sub->GetDataTypeInformation();
int buffer_len = CopyBuffer(buf_, buf_len_, datatype_info.name);

Choose a reason for hiding this comment

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

warning: variable 'buffer_len' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int buffer_len = CopyBuffer(buf_, buf_len_, datatype_info.name);
int const buffer_len = CopyBuffer(buf_, buf_len_, datatype_info.name);

if (handle_ == nullptr) return(0);
auto* sub = static_cast<eCAL::CSubscriber*>(handle_);
const eCAL::SDataTypeInformation datatype_info = sub->GetDataTypeInformation();
int buffer_len = CopyBuffer(buf_, buf_len_, datatype_info.encoding);

Choose a reason for hiding this comment

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

warning: variable 'buffer_len' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int buffer_len = CopyBuffer(buf_, buf_len_, datatype_info.encoding);
int const buffer_len = CopyBuffer(buf_, buf_len_, datatype_info.encoding);

if (handle_ == nullptr) return(0);
auto* sub = static_cast<eCAL::CSubscriber*>(handle_);
const eCAL::SDataTypeInformation datatype_info = sub->GetDataTypeInformation();
int buffer_len = CopyBuffer(buf_, buf_len_, datatype_info.descriptor);

Choose a reason for hiding this comment

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

warning: variable 'buffer_len' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int buffer_len = CopyBuffer(buf_, buf_len_, datatype_info.descriptor);
int const buffer_len = CopyBuffer(buf_, buf_len_, datatype_info.descriptor);

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

#if ECAL_CORE_MONITORING
ECALC_API void eCAL_Util_ShutdownUnitName(const char* unit_name_)
{
std::string unit_name = unit_name_;

Choose a reason for hiding this comment

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

warning: variable 'unit_name' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string unit_name = unit_name_;
std::string const unit_name = unit_name_;

@rex-schilasky rex-schilasky merged commit 2d96438 into main Feb 28, 2024
82 checks passed
@rex-schilasky rex-schilasky deleted the c-api-splitted branch February 28, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant