Skip to content

Commit

Permalink
Merge pull request #36 from milk-org/vd/pyfps
Browse files Browse the repository at this point in the history
Vd/pyfps
  • Loading branch information
DasVinch authored Dec 12, 2024
2 parents b3adb61 + c129cbe commit 5188882
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 57 deletions.
137 changes: 82 additions & 55 deletions python_module/CacaoProcessTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,34 @@ int fps_value_to_key(pyFps &cls,

switch(switch_fps_type)
{
case FPS_type::ONOFF:
return functionparameter_SetParamValue_ONOFF(cls,
key.c_str(), py::bool_(value));
case FPS_type::INT32:
case FPS_type::UINT32:
case FPS_type::INT64:
case FPS_type::UINT64:
return functionparameter_SetParamValue_INT64(cls,
key.c_str(),
py::int_(value));
case FPS_type::FLOAT32:
return functionparameter_SetParamValue_FLOAT32(cls,
key.c_str(),
py::float_(value));
case FPS_type::FLOAT64:
return functionparameter_SetParamValue_FLOAT64(cls,
key.c_str(),
py::float_(value));
case FPS_type::STRING:
case FPS_type::STREAMNAME:
case FPS_type::DIRNAME:
case FPS_type::EXECFILENAME:
case FPS_type::FILENAME:
case FPS_type::FITSFILENAME:
return functionparameter_SetParamValue_STRING(
cls,
key.c_str(),
std::string(py::str(value)).c_str());
default:
return EXIT_FAILURE;
case FPS_type::ONOFF:
return functionparameter_SetParamValue_ONOFF(cls, key.c_str(),
py::bool_(value));
case FPS_type::INT32:
case FPS_type::UINT32:
case FPS_type::INT64:
return functionparameter_SetParamValue_INT64(cls, key.c_str(), py::int_(value));
case FPS_type::UINT64:
return functionparameter_SetParamValue_UINT64(cls, key.c_str(),
py::int_(value));
case FPS_type::FLOAT32:
return functionparameter_SetParamValue_FLOAT32(cls, key.c_str(),
py::float_(value));
case FPS_type::FLOAT64:
return functionparameter_SetParamValue_FLOAT64(cls, key.c_str(),
py::float_(value));
case FPS_type::STRING:
case FPS_type::STREAMNAME:
case FPS_type::DIRNAME:
case FPS_type::EXECFILENAME:
case FPS_type::FILENAME:
case FPS_type::FITSFILENAME:
return functionparameter_SetParamValue_STRING(
cls,
key.c_str(),
std::string(py::str(value)).c_str());
default:
return EXIT_FAILURE;
}
}

Expand All @@ -61,29 +59,31 @@ fps_value_from_key(pyFps &cls, const std::string &key, const FPS_type fps_type)
{
switch(fps_type)
{
case FPS_type::ONOFF:
return py::bool_(functionparameter_GetParamValue_ONOFF(cls, key.c_str()));
case FPS_type::INT32:
case FPS_type::UINT32:
case FPS_type::INT64:
case FPS_type::UINT64:
return py::int_(
functionparameter_GetParamValue_INT64(cls, key.c_str()));
case FPS_type::FLOAT32:
return py::float_(
functionparameter_GetParamValue_FLOAT32(cls, key.c_str()));
case FPS_type::FLOAT64:
return py::float_(
functionparameter_GetParamValue_FLOAT64(cls, key.c_str()));
case FPS_type::STRING:
case FPS_type::STREAMNAME:
case FPS_type::DIRNAME:
case FPS_type::EXECFILENAME:
case FPS_type::FILENAME:
case FPS_type::FITSFILENAME:
return py::str(functionparameter_GetParamPtr_STRING(cls, key.c_str()));
default:
return py::none();
case FPS_type::ONOFF:
return py::bool_(functionparameter_GetParamValue_ONOFF(cls, key.c_str()));
case FPS_type::INT32:
case FPS_type::UINT32:
case FPS_type::INT64:
return py::int_(
functionparameter_GetParamValue_INT64(cls, key.c_str()));
case FPS_type::UINT64:
return py::int_(
functionparameter_GetParamValue_UINT64(cls, key.c_str()));
case FPS_type::FLOAT32:
return py::float_(
functionparameter_GetParamValue_FLOAT32(cls, key.c_str()));
case FPS_type::FLOAT64:
return py::float_(
functionparameter_GetParamValue_FLOAT64(cls, key.c_str()));
case FPS_type::STRING:
case FPS_type::STREAMNAME:
case FPS_type::DIRNAME:
case FPS_type::EXECFILENAME:
case FPS_type::FILENAME:
case FPS_type::FITSFILENAME:
return py::str(functionparameter_GetParamPtr_STRING(cls, key.c_str()));
default:
return py::none();
}
}

Expand Down Expand Up @@ -154,6 +154,15 @@ PYBIND11_MODULE(CacaoProcessTools, m)
.value("FPSNAME", FPS_type::FPSNAME)
.export_values();

py::enum_<FPS_flags>(m, "FPS_flags")
.value("DEFAULT_INPUT", FPS_flags::DEFAULT_INPUT)
.value("DEFAULT_OUTPUT", FPS_flags::DEFAULT_OUTPUT)
.value("DEFAULT_INPUT_STREAM", FPS_flags::DEFAULT_INPUT_STREAM)
.value("DEFAULT_OUTPUT_STREAM", FPS_flags::DEFAULT_OUTPUT_STREAM)
.value("DEFAULT_STATUS", FPS_flags::DEFAULT_STATUS)
.export_values();


py::class_<timespec>(m, "timespec")
.def(py::init<time_t, long>())
.def_readwrite("tv_sec", &timespec::tv_sec)
Expand Down Expand Up @@ -410,13 +419,30 @@ If entry already exists, do not modify it
Parameters:
name [in]: the name of the shared memory file to connect
create [in]: flag for creating of shared memory identifier
NBparamMAX [in]: Max number of parameters
comment [in]: description
fptype [in]: datatype
)pbdoc",
py::arg("entry_name"),
py::arg("entry_desc"),
py::arg("fptype"))

.def("add_entry",
&pyFps::add_entry_w_flags,
R"pbdoc(Add parameter to database with custom flags
If entry already exists, do not modify it
Parameters:
name [in]: the name of the shared memory file to connect
comment [in]: description
fptype [in]: datatype
fpflag [in]: fps flags
)pbdoc",
py::arg("entry_name"),
py::arg("entry_desc"),
py::arg("fptype"),
py::arg("fpflag"))

.def("get_status", &pyFps::get_status)
.def("set_status", &pyFps::set_status)
.def("disconnect", &pyFps::disconnect)
Expand Down Expand Up @@ -726,6 +752,7 @@ Requires setup performed by milk-fpsinit, which performs the following setup
// }))
.def_readonly("name", &FUNCTION_PARAMETER_STRUCT_MD::name)
.def_readonly("description", &FUNCTION_PARAMETER_STRUCT_MD::description)
.def_readonly("kwarray", &FUNCTION_PARAMETER_STRUCT_MD::keywordarray)
.def_readonly("workdir", &FUNCTION_PARAMETER_STRUCT_MD::workdir)
.def_readonly("datadir", &FUNCTION_PARAMETER_STRUCT_MD::datadir)
.def_readonly("confdir", &FUNCTION_PARAMETER_STRUCT_MD::confdir)
Expand Down
9 changes: 7 additions & 2 deletions python_module/pyFps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum FPS_flags : uint64_t
DEFAULT_OUTPUT = FPFLAG_DEFAULT_OUTPUT,
DEFAULT_INPUT_STREAM = FPFLAG_DEFAULT_INPUT_STREAM,
DEFAULT_OUTPUT_STREAM = FPFLAG_DEFAULT_OUTPUT_STREAM,
DEFAULT_STATUS = FPFLAG_DEFAULT_STATUS,
};

class pyFps
Expand Down Expand Up @@ -221,7 +222,10 @@ class pyFps
uint32_t fptype)
{
keys_[entry_name] = static_cast<FPS_type>(fptype);
return function_parameter_add_entry(&fps_, entry_name.c_str(),
// We need to prepend a . to entry to abide by FPS conventions
// See fps_add_entry.c
std::string prepended = "." + entry_name;
return function_parameter_add_entry(&fps_, prepended.c_str(),
entry_desc.c_str(), fptype,
FPFLAG_DEFAULT_INPUT, nullptr, nullptr);
}
Expand All @@ -241,7 +245,8 @@ class pyFps
uint32_t fptype, uint64_t fpflag)
{
keys_[entry_name] = static_cast<FPS_type>(fptype);
return function_parameter_add_entry(&fps_, entry_name.c_str(),
std::string prepended = "." + entry_name;
return function_parameter_add_entry(&fps_, prepended.c_str(),
entry_desc.c_str(), fptype,
fpflag, nullptr, nullptr);
}
Expand Down

0 comments on commit 5188882

Please sign in to comment.