Skip to content

Commit

Permalink
[Python/clang] Add missing core functions (#1300)
Browse files Browse the repository at this point in the history
Adds the missing core functions from ecal_core.h (GetVersion, IsInitialized, SetUnitName) to ecal_clang and the python wrapper.
  • Loading branch information
DownerCase authored Jan 17, 2024
1 parent d523faa commit c532f86
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ecal/core/include/ecal/ecal_clang.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
**/
ECAL_API const char* ecal_getversion();

/**
* @brief Get eCAL version as separated integer values.
*
* @param [out] major_ The eCAL major version number.
* @param [out] minor_ The eCAL minor version number.
* @param [out] patch_ The eCAL patch version number.
*
* @return Zero if succeeded.
**/
ECAL_API int ecal_getversion_components(int* major_, int* minor_, int* patch_);

/**
* @brief Get eCAL version date.
*
Expand All @@ -62,6 +73,22 @@ ECAL_API int ecal_initialize(int argc_, char **argv_, const char* unit_name_);
**/
ECAL_API int ecal_finalize();

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

/**
* @brief Set/change the unit name of current module.
*
* @param unit_name_ Defines the name of the eCAL unit.
*
* @return Zero if succeeded.
**/
ECAL_API int ecal_set_unit_name(const char *unit_name_);

/**
* @brief Set process state info.
*
Expand Down
25 changes: 25 additions & 0 deletions ecal/core/src/ecal_clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ ECAL_API const char* ecal_getversion()
return(ECAL_VERSION);
}

/****************************************/
/* ecal_getversion_components */
/****************************************/
ECAL_API int ecal_getversion_components(int* major_, int* minor_, int* patch_)
{
return eCAL::GetVersion(major_, minor_, patch_);
}

/****************************************/
/* ecal_getdate */
/****************************************/
Expand All @@ -74,6 +82,23 @@ ECAL_API int ecal_finalize()
return(eCAL::Finalize());
}

/****************************************/
/* ecal_is_initialized */
/****************************************/
ECAL_API int ecal_is_initialized()
{
//* @return 1 if eCAL is initialized.
return(eCAL::IsInitialized());
}

/****************************************/
/* ecal_set_unit_name */
/****************************************/
ECAL_API int ecal_set_unit_name(const char* unit_name_)
{
return(eCAL::SetUnitName(unit_name_));
}

/****************************************/
/* ecal_set_process_state */
/****************************************/
Expand Down
21 changes: 21 additions & 0 deletions lang/python/core/ecal/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,33 @@ def finalize():
return _ecal.finalize()


def is_initialized():
""" get if ecal has been initialized
"""
return _ecal.is_initialized()


def getversion():
""" get ecal version string
"""
return _ecal.getversion()


def getversion_components():
""" get ecal version as major, minor, patch tuple
"""
return _ecal.getversion_components()


def set_unit_name(unit_name):
""" set/change the unit name of the current module
:param unit_name: Name of the eCAL unit
:type unit_name: string
"""
return _ecal.set_unit_name(unit_name)


def getdate():
""" get ecal date string
"""
Expand Down
36 changes: 36 additions & 0 deletions lang/python/core/src/ecal_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ PyObject* finalize(PyObject* /*self*/, PyObject* /*args*/)
return(Py_BuildValue("i", finalize));
}

/****************************************/
/* is_initialized */
/****************************************/
PyObject* is_initialized(PyObject* /*self*/, PyObject* /*args*/)
{
return(Py_BuildValue("i", ecal_is_initialized()));
}

/****************************************/
/* set_unit_name */
/****************************************/
PyObject* set_unit_name(PyObject* /*self*/, PyObject* args)
{
char* unit_name = nullptr;

if (!PyArg_ParseTuple(args, "s", &unit_name))
return nullptr;

return(Py_BuildValue("i", ecal_set_unit_name(unit_name)));
}

/****************************************/
/* getversion */
/****************************************/
Expand All @@ -147,6 +168,18 @@ PyObject* getversion(PyObject* /*self*/, PyObject* /*args*/)
return(Py_BuildValue("s", ecal_getversion()));
}

/****************************************/
/* getversioncomponents */
/****************************************/
PyObject* getversion_components(PyObject* /*self*/, PyObject* /*args*/)
{
int major = 0;
int minor = 0;
int patch = 0;
ecal_getversion_components(&major, &minor, &patch);
return(Py_BuildValue("iii", major, minor, patch));
}

/****************************************/
/* getdate */
/****************************************/
Expand Down Expand Up @@ -1574,8 +1607,11 @@ static PyMethodDef _ecal_methods[] =
{
{"initialize", initialize, METH_VARARGS, "initialize(argv, unit_name)"},
{"finalize", finalize, METH_NOARGS, "finalize()"},
{"is_initialized", is_initialized, METH_NOARGS, "is_initialized()"},
{"set_unit_name", set_unit_name, METH_VARARGS, "set_unit_name(unit_name)"},

{"getversion", getversion, METH_NOARGS, "getversion()"},
{"getversion_components", getversion_components, METH_NOARGS, "getversion_components()"},
{"getdate", getdate, METH_NOARGS, "getdate()"},
{"getmicroseconds", getmicroseconds, METH_NOARGS, "getmicroseconds()"},

Expand Down

0 comments on commit c532f86

Please sign in to comment.