Skip to content

Commit

Permalink
single fields req_type, req_desc, resp_type and resp_desc removed fro…
Browse files Browse the repository at this point in the history
…m SMethodMon

ugly logic added to make new service server implementation compatible to old v5 API (where AddDescription may be called any time separately)
python API extended with datatype information for pub/sub and server/client
  • Loading branch information
rex-schilasky committed Jan 9, 2025
1 parent b1c89e5 commit 7194274
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 68 deletions.
5 changes: 0 additions & 5 deletions ecal/core/include/ecal/types/monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ namespace eCAL
{
std::string mname; //<! method name

std::string req_type; //<! request type (deprecated use req_datatype)
std::string req_desc; //<! request descriptor (deprecated use req_datatype)
std::string resp_type; //<! response type (deprecated use resp_datatype)
std::string resp_desc; //<! response descriptor (deprecated use resp_datatype)

SDataTypeInformation req_datatype; //<! request datatype information (encoding & type & description)
SDataTypeInformation resp_datatype; //<! response datatype information (encoding & type & description)

Expand Down
11 changes: 2 additions & 9 deletions ecal/core/src/monitoring/ecal_monitoring_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,6 @@ namespace eCAL
struct Monitoring::SMethodMon method;
method.mname = sample_service_method.mname;

method.req_type = sample_service_method.req_type;
method.req_desc = sample_service_method.req_desc;
method.resp_type = sample_service_method.resp_type;
method.resp_desc = sample_service_method.resp_desc;

method.req_datatype = sample_service_method.req_datatype;
method.resp_datatype = sample_service_method.resp_datatype;

Expand Down Expand Up @@ -493,10 +488,8 @@ namespace eCAL
{
struct Monitoring::SMethodMon method;
method.mname = sample_client_method.mname;
method.req_type = sample_client_method.req_type;
method.req_desc = sample_client_method.req_desc;
method.resp_type = sample_client_method.resp_type;
method.resp_desc = sample_client_method.resp_desc;
method.req_datatype = sample_client_method.req_datatype;
method.resp_datatype = sample_client_method.resp_datatype;
method.call_count = sample_client_method.call_count;
ClientInfo.methods.push_back(method);
}
Expand Down
9 changes: 0 additions & 9 deletions ecal/core/src/serialization/ecal_serialize_monitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,6 @@ namespace

eCAL_pb_Method pb_method = eCAL_pb_Method_init_default;
eCAL::nanopb::encode_string(pb_method.mname, method.mname);
eCAL::nanopb::encode_string(pb_method.req_type, method.req_type);
eCAL::nanopb::encode_string(pb_method.req_desc, method.req_desc);
eCAL::nanopb::encode_string(pb_method.resp_type, method.resp_type);
eCAL::nanopb::encode_string(pb_method.resp_desc, method.resp_desc);

pb_method.has_req_datatype = true;
eCAL::nanopb::encode_string(pb_method.req_datatype.name, method.req_datatype.name);
Expand Down Expand Up @@ -705,11 +701,6 @@ namespace
// decode method parameter
eCAL::nanopb::decode_string(pb_method.mname, method.mname);

eCAL::nanopb::decode_string(pb_method.req_type, method.req_type);
eCAL::nanopb::decode_string(pb_method.req_desc, method.req_desc);
eCAL::nanopb::decode_string(pb_method.resp_type, method.resp_type);
eCAL::nanopb::decode_string(pb_method.resp_desc, method.resp_desc);

eCAL::nanopb::decode_string(pb_method.req_datatype.name, method.req_datatype.name);
eCAL::nanopb::decode_string(pb_method.req_datatype.encoding, method.req_datatype.encoding);
eCAL::nanopb::decode_string(pb_method.req_datatype.desc, method.req_datatype.descriptor);
Expand Down
88 changes: 67 additions & 21 deletions ecal/core/src/service/ecal_service_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,42 @@ namespace eCAL
auto iter = m_method_map.find(method_);
if (iter != m_method_map.end())
{
Logging::Log(log_level_warning, "CServiceServerImpl::SetMethodCallback: Method already exists, updating callback: " + method_);

// old type and descriptor fields
iter->second.method.req_type = method_info_.request_type.name;
iter->second.method.req_desc = method_info_.request_type.descriptor;
iter->second.method.resp_type = method_info_.response_type.name;
iter->second.method.resp_desc = method_info_.response_type.descriptor;

// new type and descriptor fields
Logging::Log(log_level_warning, "CServiceServerImpl::SetMethodCallback: Method already exists, updating attributes and callback: " + method_);

#if 0 // this is how it should look like if we do not use the old type and descriptor fields
// update data type and callback
iter->second.method.req_datatype = method_info_.request_type;
iter->second.method.resp_datatype = method_info_.response_type;
iter->second.callback = callback_;
#else
/////////////////////////////////////////////
// old types and descriptors
/////////////////////////////////////////////
iter->second.method.req_type = method_info_.request_type.name;
iter->second.method.resp_type = method_info_.response_type.name;

// we need to check these fields, because the v5 implementation is using SetMethodCallback with partially filled fields
if (!method_info_.request_type.descriptor.empty()) iter->second.method.req_desc = method_info_.request_type.descriptor;
if (!method_info_.response_type.descriptor.empty()) iter->second.method.resp_desc = method_info_.response_type.descriptor;

// callback
iter->second.callback = callback_;
/////////////////////////////////////////////
// new types, encodings and descriptors
/////////////////////////////////////////////
iter->second.method.req_datatype.name = method_info_.request_type.name;
iter->second.method.resp_datatype.name = method_info_.response_type.name;

// we need to check these fields, because the v5 implementation is using SetMethodCallback with partially filled fields
if (!method_info_.request_type.encoding.empty()) iter->second.method.req_datatype.encoding = method_info_.request_type.encoding;
if (!method_info_.response_type.encoding.empty()) iter->second.method.resp_datatype.encoding = method_info_.response_type.encoding;
if (!method_info_.request_type.descriptor.empty()) iter->second.method.req_datatype.descriptor = method_info_.request_type.descriptor;
if (!method_info_.response_type.descriptor.empty()) iter->second.method.resp_datatype.descriptor = method_info_.response_type.descriptor;

// we need to do this ugly hack here, because the v5 implementation is using SetMethodCallback with nullptr to update descriptions (AddDescription)
if (callback_ != nullptr)
{
iter->second.callback = callback_;
}
#endif
}
else
{
Expand All @@ -99,19 +121,43 @@ namespace eCAL
SMethod method;
// method name
method.method.mname = method_;

// old type and descriptor fields
method.method.req_type = method_info_.request_type.name;
method.method.req_desc = method_info_.request_type.descriptor;
method.method.resp_type = method_info_.response_type.name;
method.method.resp_desc = method_info_.response_type.descriptor;

// new type and descriptor fields
#if 0 // this is how it should look like if we do not use the old type and descriptor fields
// set data type and callback
method.method.req_datatype = method_info_.request_type;
method.method.resp_datatype = method_info_.response_type;

// callback
method.callback = callback_;
method.callback = callback_;
#else
#endif
/////////////////////////////////////////////
// old types and descriptors
/////////////////////////////////////////////
method.method.req_type = method_info_.request_type.name;
method.method.resp_type = method_info_.response_type.name;

// we need to check these fields, because the v5 implementation is using SetMethodCallback with partially filled fields
if (!method_info_.request_type.descriptor.empty()) method.method.req_desc = method_info_.request_type.descriptor;
if (!method_info_.response_type.descriptor.empty()) method.method.resp_desc = method_info_.response_type.descriptor;

/////////////////////////////////////////////
// new types, encodings and descriptors
/////////////////////////////////////////////
method.method.req_datatype.name = method_info_.request_type.name;
method.method.resp_datatype.name = method_info_.response_type.name;

// we need to check these fields, because the v5 implementation is using SetMethodCallback with partially filled fields
if (!method_info_.request_type.encoding.empty()) method.method.req_datatype.encoding = method_info_.request_type.encoding;
if (!method_info_.response_type.encoding.empty()) method.method.resp_datatype.encoding = method_info_.response_type.encoding;
if (!method_info_.request_type.descriptor.empty()) method.method.req_datatype.descriptor = method_info_.request_type.descriptor;
if (!method_info_.response_type.descriptor.empty()) method.method.resp_datatype.descriptor = method_info_.response_type.descriptor;

// we need to do this ugly hack here, because the v5 implementation is using SetMethodCallback with nullptr to update descriptions (AddDescription)
if (callback_ != nullptr)
{
method.callback = callback_;
}

// apply new method
m_method_map[method_] = method;
}

Expand Down
8 changes: 0 additions & 8 deletions ecal/tests/cpp/serialization_test/src/monitoring_compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ namespace eCAL
for (size_t j = 0; j < monitoring1.server[i].methods.size(); ++j)
{
if (monitoring1.server[i].methods[j].mname != monitoring2.server[i].methods[j].mname ||
monitoring1.server[i].methods[j].req_type != monitoring2.server[i].methods[j].req_type ||
monitoring1.server[i].methods[j].req_desc != monitoring2.server[i].methods[j].req_desc ||
monitoring1.server[i].methods[j].resp_type != monitoring2.server[i].methods[j].resp_type ||
monitoring1.server[i].methods[j].resp_desc != monitoring2.server[i].methods[j].resp_desc ||
monitoring1.server[i].methods[j].req_datatype != monitoring2.server[i].methods[j].req_datatype ||
monitoring1.server[i].methods[j].resp_datatype != monitoring2.server[i].methods[j].resp_datatype ||
monitoring1.server[i].methods[j].call_count != monitoring2.server[i].methods[j].call_count)
Expand Down Expand Up @@ -184,10 +180,6 @@ namespace eCAL
for (size_t j = 0; j < monitoring1.clients[i].methods.size(); ++j)
{
if (monitoring1.clients[i].methods[j].mname != monitoring2.clients[i].methods[j].mname ||
monitoring1.clients[i].methods[j].req_type != monitoring2.clients[i].methods[j].req_type ||
monitoring1.clients[i].methods[j].req_desc != monitoring2.clients[i].methods[j].req_desc ||
monitoring1.clients[i].methods[j].resp_type != monitoring2.clients[i].methods[j].resp_type ||
monitoring1.clients[i].methods[j].resp_desc != monitoring2.clients[i].methods[j].resp_desc ||
monitoring1.clients[i].methods[j].req_datatype != monitoring2.clients[i].methods[j].req_datatype ||
monitoring1.clients[i].methods[j].resp_datatype != monitoring2.clients[i].methods[j].resp_datatype ||
monitoring1.clients[i].methods[j].call_count != monitoring2.clients[i].methods[j].call_count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ namespace eCAL
SMethodMon GenerateServiceMethod()
{
SMethodMon method;
method.mname = GenerateString(8);

method.req_type = GenerateString(8); // deprecated
method.req_desc = GenerateString(10); // deprecated
method.resp_type = GenerateString(8); // deprecated
method.resp_desc = GenerateString(10); // deprecated
method.mname = GenerateString(8);

method.req_datatype = eCAL::Registration::GenerateDataTypeInformation();
method.resp_datatype = eCAL::Registration::GenerateDataTypeInformation();
Expand Down
43 changes: 33 additions & 10 deletions lang/python/core/src/ecal_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,14 @@ namespace
val = Py_BuildValue("s", topic.direction.c_str());
PyDict_SetItemString(topicDict, "direction", val); Py_DECREF(val);

// TODO: SDataTypeInformation tdatatype
val = Py_BuildValue("s", topic.tdatatype.name.c_str());
PyDict_SetItemString(topicDict, "tdatatype_name", val); Py_DECREF(val);

val = Py_BuildValue("s", topic.tdatatype.encoding.c_str());
PyDict_SetItemString(topicDict, "tdatatype_encoding", val); Py_DECREF(val);

val = Py_BuildValue("y#", topic.tdatatype.descriptor.c_str(), topic.tdatatype.descriptor.length());
PyDict_SetItemString(topicDict, "tdatatype_descriptor", val); Py_DECREF(val);

// TODO: std::vector<TLayer> tlayer

Expand Down Expand Up @@ -1165,15 +1172,23 @@ PyObject* mon_monitoring(PyObject* /*self*/, PyObject* /*args*/)
val = Py_BuildValue("s", method.mname.c_str());
PyDict_SetItemString(methodsDict, "mname", val); Py_DECREF(val);

val = Py_BuildValue("s", method.req_type.c_str());
val = Py_BuildValue("s", method.req_datatype.name.c_str());
PyDict_SetItemString(methodsDict, "req_type", val); Py_DECREF(val);

// TODO: std::string req_desc
val = Py_BuildValue("s", method.req_datatype.encoding.c_str());
PyDict_SetItemString(methodsDict, "req_encoding", val); Py_DECREF(val);

val = Py_BuildValue("s", method.resp_type.c_str());
val = Py_BuildValue("y#", method.req_datatype.descriptor.c_str(), method.req_datatype.descriptor.length());
PyDict_SetItemString(methodsDict, "req_descriptor", val); Py_DECREF(val);

val = Py_BuildValue("s", method.resp_datatype.name.c_str());
PyDict_SetItemString(methodsDict, "resp_type", val); Py_DECREF(val);

// TODO: std::string resp_desc
val = Py_BuildValue("s", method.resp_datatype.encoding.c_str());
PyDict_SetItemString(methodsDict, "resp_encoding", val); Py_DECREF(val);

val = Py_BuildValue("y#", method.resp_datatype.descriptor.c_str(), method.resp_datatype.descriptor.length());
PyDict_SetItemString(methodsDict, "resp_descriptor", val); Py_DECREF(val);

val = Py_BuildValue("i", method.call_count);
PyDict_SetItemString(methodsDict, "call_count", val); Py_DECREF(val);
Expand Down Expand Up @@ -1220,15 +1235,23 @@ PyObject* mon_monitoring(PyObject* /*self*/, PyObject* /*args*/)
val = Py_BuildValue("s", method.mname.c_str());
PyDict_SetItemString(methodsDict, "mname", val); Py_DECREF(val);

val = Py_BuildValue("s", method.req_type.c_str());
val = Py_BuildValue("s", method.req_datatype.name.c_str());
PyDict_SetItemString(methodsDict, "req_type", val); Py_DECREF(val);

// TODO: std::string req_desc

val = Py_BuildValue("s", method.resp_type.c_str());
val = Py_BuildValue("s", method.req_datatype.encoding.c_str());
PyDict_SetItemString(methodsDict, "req_encoding", val); Py_DECREF(val);

val = Py_BuildValue("y#", method.req_datatype.descriptor.c_str(), method.req_datatype.descriptor.length());
PyDict_SetItemString(methodsDict, "req_descriptor", val); Py_DECREF(val);

val = Py_BuildValue("s", method.resp_datatype.name.c_str());
PyDict_SetItemString(methodsDict, "resp_type", val); Py_DECREF(val);

// TODO: std::string resp_desc
val = Py_BuildValue("s", method.resp_datatype.encoding.c_str());
PyDict_SetItemString(methodsDict, "resp_encoding", val); Py_DECREF(val);

val = Py_BuildValue("y#", method.resp_datatype.descriptor.c_str(), method.resp_datatype.descriptor.length());
PyDict_SetItemString(methodsDict, "resp_descriptor", val); Py_DECREF(val);

val = Py_BuildValue("i", method.call_count);
PyDict_SetItemString(methodsDict, "call_count", val); Py_DECREF(val);
Expand Down

0 comments on commit 7194274

Please sign in to comment.