From 57f972b4149c46751c020cfd1d5ffaebabbda860 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:11:22 +0100 Subject: [PATCH] python api fixed to work again based on new c++/c core api --- ecal/core/include/ecal/ecal_clang.h | 18 +- ecal/core/src/ecal_clang.cpp | 14 +- lang/python/core/ecal/core/core.py | 369 ++---------------- lang/python/core/ecal/core/publisher.py | 83 +--- lang/python/core/ecal/core/subscriber.py | 53 +-- lang/python/core/src/ecal_wrap.cxx | 29 +- samples/CMakeLists.txt | 1 - .../benchmarks/latency_rec/latency_rec.py | 2 +- .../latency_rec_cb/latency_rec_cb.py | 4 +- .../protobuf/person_rec_json/CMakeLists.txt | 32 -- .../person_rec_json/person_rec_json.py | 53 --- .../person_rec_json/person_rec_json.pyproj | 35 -- 12 files changed, 116 insertions(+), 577 deletions(-) delete mode 100644 samples/python/pubsub/protobuf/person_rec_json/CMakeLists.txt delete mode 100644 samples/python/pubsub/protobuf/person_rec_json/person_rec_json.py delete mode 100644 samples/python/pubsub/protobuf/person_rec_json/person_rec_json.pyproj diff --git a/ecal/core/include/ecal/ecal_clang.h b/ecal/core/include/ecal/ecal_clang.h index 7db5bfb1ae..56c00f2e95 100644 --- a/ecal/core/include/ecal/ecal_clang.h +++ b/ecal/core/include/ecal/ecal_clang.h @@ -231,12 +231,15 @@ ECAL_API void log_message(const char* message_); /** * @brief Create a publisher. * - * @param topic_name_ Unique topic name. - * @param topic_type_ Topic type name. + * @param topic_name_ Unique topic name. + * @param topic_type_ Topic type name. + * @param topic_enc_ Topic type encoding. + * @param topic_desc_ Topic type description. + * @param topic_desc_length_ Topic type description length. * * @return Handle of the created publisher or NULL if failed. **/ -ECAL_API ECAL_HANDLE pub_create(const char* topic_name_, const char* topic_type_); +ECAL_API ECAL_HANDLE pub_create(const char* topic_name_, const char* topic_type_, const char* topic_enc_, const char* topic_desc_, const int topic_desc_length_); /** * @brief Destroy a publisher. @@ -287,12 +290,15 @@ ECAL_API bool pub_rem_event_callback(ECAL_HANDLE handle_, enum eCAL_Publisher_Ev /** * @brief Create a subscriber. * - * @param topic_name_ Unique topic name. - * @param topic_type_ Topic type name. + * @param topic_name_ Unique topic name. + * @param topic_type_ Topic type name. + * @param topic_enc_ Topic type encoding. + * @param topic_desc_ Topic type description. + * @param topic_desc_length_ Topic type description length. * * @return Handle of the created subscriber or NULL if failed. **/ -ECAL_API ECAL_HANDLE sub_create(const char* topic_name_, const char* topic_type_); +ECAL_API ECAL_HANDLE sub_create(const char* topic_name_, const char* topic_type_, const char* topic_enc_, const char* topic_desc_, const int topic_desc_length_); /** * @brief Destroy a subscriber. diff --git a/ecal/core/src/ecal_clang.cpp b/ecal/core/src/ecal_clang.cpp index 49cb86002e..e3b42166ea 100644 --- a/ecal/core/src/ecal_clang.cpp +++ b/ecal/core/src/ecal_clang.cpp @@ -276,10 +276,13 @@ ECAL_API void log_message(const char* message_) /****************************************/ /* pub_create */ /****************************************/ -ECAL_API ECAL_HANDLE pub_create(const char* topic_name_, const char* topic_type_) +ECAL_API ECAL_HANDLE pub_create(const char* topic_name_, const char* topic_type_, const char* topic_enc_, const char* topic_desc_, const int topic_desc_length_) { eCAL::SDataTypeInformation topic_info; - topic_info.name = topic_type_; + topic_info.name = topic_type_; + topic_info.encoding = topic_enc_; + topic_info.descriptor = std::string(topic_desc_, static_cast(topic_desc_length_)); + auto* pub = new eCAL::CPublisher; if (!pub->Create(topic_name_, topic_info)) { @@ -365,10 +368,13 @@ ECAL_API bool pub_rem_event_callback(ECAL_HANDLE handle_, enum eCAL_Publisher_Ev /****************************************/ /* sub_create */ /****************************************/ -ECAL_API ECAL_HANDLE sub_create(const char* topic_name_, const char* topic_type_) +ECAL_API ECAL_HANDLE sub_create(const char* topic_name_, const char* topic_type_, const char* topic_enc_, const char* topic_desc_, const int topic_desc_length_) { eCAL::SDataTypeInformation topic_info; - topic_info.name = topic_type_; + topic_info.name = topic_type_; + topic_info.encoding = topic_enc_; + topic_info.descriptor = std::string(topic_desc_, static_cast(topic_desc_length_)); + auto* sub = new eCAL::CSubscriber; if (!sub->Create(topic_name_, topic_info)) { diff --git a/lang/python/core/ecal/core/core.py b/lang/python/core/ecal/core/core.py index 86d58c7776..2731044aa0 100644 --- a/lang/python/core/ecal/core/core.py +++ b/lang/python/core/ecal/core/core.py @@ -171,19 +171,20 @@ def log_message(message): return _ecal.log_message(message) -def pub_create(topic_name, topic_type, topic_desc): +def pub_create(topic_name, topic_type, topic_enc, topic_desc): """ create publisher :param topic_name: the unique topic name :type topic_name: string :param topic_type: optional type name :type topic_type: string + :param topic_enc: optional type encoding + :type topic_enc: string :param topic_desc: optional type description :type topic_desc: bytes """ - topic_handle = _ecal.pub_create(topic_name, topic_type) - pub_set_description(topic_handle, topic_desc) + topic_handle = _ecal.pub_create(topic_name, topic_type, topic_enc, topic_desc) return topic_handle @@ -196,81 +197,6 @@ def pub_destroy(topic_handle): return _ecal.pub_destroy(topic_handle) -def pub_set_topic_type_name(topic_handle, topic_type_name): - """ set publisher topic type name - - :param topic_handle: the topic handle - :type topic_handle: string - :param topic_type_name: the topic type name - :type topic_type_name: string - - """ - return _ecal.pub_set_topic_type_name(topic_handle, topic_type_name) - -def pub_set_description(topic_handle, description): - """ set publisher topic type description - - :param topic_handle: the topic handle - :type topic_handle: string - :param description: the topic type description - :type description: bytes - - """ - return _ecal.pub_set_description(topic_handle, description) - - -def pub_set_qos_historykind(topic_handle, qpolicy, depth): - """ set publisher quality of service historykind mode and depth - - :param topic_handle: the topic handle - :param qpolicy: 0 = keep_last_history_qos, 1 = keep_all_history_qos - :type qpolicy: int - :param depth: history kind buffer depth - - """ - - return _ecal.pub_set_qos_historykind(topic_handle, qpolicy, depth) - - -def pub_set_qos_reliability(topic_handle, qpolicy): - """ set publisher quality of service reliability mode - - :param topic_handle: the topic handle - :param qpolicy: 0 = best_effort_reliability_qos, 1 = reliable_reliability_qos - :type qpolicy: int - :param depth: history kind buffer depth - - """ - - return _ecal.pub_set_qos_reliability(topic_handle, qpolicy) - - -def pub_set_layer_mode(topic_handle, layer, mode): - """ set send mode for specific transport layer - - :param topic_handle: the topic handle - :param layer: 0 = udp, 1 = shm, 42 = inproc - :type layer: int - :param mode: 0 = off, 1 = on, 2 = auto - :type mode: int - - """ - - return _ecal.pub_set_layer_mode(topic_handle, layer, mode) - - -def pub_set_max_bandwidth_udp(topic_handle, bandwidth): - """ set publisher maximum transmit bandwidth for the udp layer. - - :param topic_handle: the topic handle - :param bandwidth: maximum bandwidth in bytes/s (-1 == unlimited) - :type bandwidth: int - - """ - - return _ecal.pub_set_max_bandwidth_udp(topic_handle, bandwidth) - - def pub_send(topic_handle, msg_payload, msg_time=-1): """ send publisher content @@ -284,30 +210,21 @@ def pub_send(topic_handle, msg_payload, msg_time=-1): return _ecal.pub_send(topic_handle, msg_payload, msg_time) -def pub_send_sync(topic_handle, msg_payload, msg_time, ack_timeout_ms): - """ send publisher content synchronized to connected local subscribers with acknowledge timeout - - :param topic_handle: the topic handle - :param msg_payload: message python string (can contain zeros) - :type msg_payload: bytes - :param msg_time: message time in us (-1 == eCAL system time) - :type msg_time: int - :param ack_timeout_ms: Maximum time to wait for all subscribers acknowledge feedback in ms (message received and processed) - :type ack_timeout_ms: int - - """ - return _ecal.pub_send_sync(topic_handle, msg_payload, msg_time, ack_timeout_ms) - -def sub_create(topic_name, topic_type): +def sub_create(topic_name, topic_type, topic_enc, topic_desc): """ create subscriber :param topic_name: the unique topic name - :type topic_name: string - :param topic_type: optional topic type - :type topic_type: string - + :type topic_name: string + :param topic_type: optional type name + :type topic_type: string + :param topic_enc: optional type encoding + :type topic_enc: string + :param topic_desc: optional type description + :type topic_desc: bytes + """ - return _ecal.sub_create(topic_name, topic_type) + topic_handle = _ecal.sub_create(topic_name, topic_type, topic_enc, topic_desc) + return topic_handle def sub_destroy(topic_handle): @@ -319,32 +236,6 @@ def sub_destroy(topic_handle): return _ecal.sub_destroy(topic_handle) -def sub_set_qos_historykind(topic_handle, qpolicy, depth): - """ set subscriber quality of service historykind mode and depth - - :param topic_handle: the topic handle - :param qpolicy: 0 = keep_last_history_qos, 1 = keep_all_history_qos - :type qpolicy: int - :param depth: history kind buffer depth - :type depth: int - - """ - - return _ecal.sub_set_qos_historykind(topic_handle, qpolicy, depth) - - -def sub_set_qos_reliability(topic_handle, qpolicy): - """ set subscriber quality of service reliability mode - - :param topic_handle: the topic handle - :param qpolicy: 0 = best_effort_reliability_qos, 1 = reliable_reliability_qos - :type qpolicy: int - - """ - - return _ecal.sub_set_qos_reliability(topic_handle, qpolicy) - - def sub_receive(topic_handle, timeout=0): """ receive subscriber content with timeout @@ -376,45 +267,6 @@ def sub_rem_callback(topic_handle, callback): return _ecal.sub_rem_callback(topic_handle, callback) -def dyn_json_sub_create(topic_name): - """ create subscriber - - :param topic_name: the unique topic name - :type topic_name: string - - """ - return _ecal.dyn_json_sub_create(topic_name) - - -def dyn_json_sub_destroy(topic_handle): - """ destroy subscriber - - :param topic_handle: the topic handle - - """ - return _ecal.dyn_json_sub_destroy(topic_handle) - - -def dyn_json_sub_set_callback(topic_handle, callback): - """ set callback function for incoming messages - - :param topic_handle: the topic handle - :param callback: python callback function (f(topic_name, msg, time)) - - """ - return _ecal.dyn_json_sub_set_callback(topic_handle, callback) - - -def dyn_json_sub_rem_callback(topic_handle, callback): - """ remove callback function for incoming messages - - :param topic_handle: the topic handle - :param callback: python callback function (f(topic_name, msg, time)) - - """ - return _ecal.dyn_json_sub_rem_callback(topic_handle, callback) - - def server_create(service_name): """ create server @@ -576,40 +428,20 @@ def mon_logging(): return _ecal.mon_logging() -def mon_pubmonitoring(state_, name_): - """ activate an eCAL internal publisher for monitoring info - - :param state_: publisher state on / off - :param name_: topic name for the publisher - :type name_: string - - """ - return _ecal.mon_pubmonitoring(state_, name_) - - -def mon_publogging(state_, name_): - """ activate an eCAL internal publisher for logging info - - :param state_: publisher state on / off - :param name_: topic name for the publisher - :type name_: string - - """ - return _ecal.mon_publogging(state_, name_) - - class publisher(object): """ eCAL publisher """ - def __init__(self, topic_name, topic_type="", topic_desc=b""): + def __init__(self, topic_name, topic_type="", topic_enc="", topic_desc=b""): """ initialize publisher :param topic_name: the unique topic name - :type topic_name: string - :param topic_type: optional topic type name - :type topic_type: string - :param topic_desc: optional topic type description - :type topic_desc: bytes + :type topic_name: string + :param topic_type: optional type name + :type topic_type: string + :param topic_enc: optional type encoding + :type topic_enc: string + :param topic_desc: optional type description + :type topic_desc: bytes """ # topic name @@ -617,75 +449,17 @@ def __init__(self, topic_name, topic_type="", topic_desc=b""): # topic type self.ttype = topic_type # topic description + self.tenc = topic_enc + # topic description self.tdesc = topic_desc # topic handle - self.thandle = pub_create(self.tname, self.ttype, self.tdesc) + self.thandle = pub_create(self.tname, self.ttype, self.tenc, self.tdesc) def destroy(self): """ destroy publisher """ return pub_destroy(self.thandle) - def set_topic_type_name(self, topic_type_name): - """ set topic type name - - :param topic_type_name: the topic type name - :type topic_type_name: string - - """ - - return pub_set_topic_type_name(self.thandle, topic_type_name) - - def set_topic_description(self, description): - """ set topic description - - :param description: the topic type description - :type description: bytes - - """ - - return pub_set_description(self.thandle, description) - - def set_qos_historykind(self, qpolicy, depth): - """ set quality of service historykind mode and depth - - :param qpolicy: 0 = keep_last_history_qos, 1 = keep_all_history_qos - :param depth: history kind buffer depth - - """ - - return pub_set_qos_historykind(self.thandle, qpolicy, depth) - - def set_qos_reliability(self, qpolicy): - """ set quality of service reliability mode - - :param qpolicy: 0 = best_effort_reliability_qos, 1 = reliable_reliability_qos - - """ - - return pub_set_qos_reliability(self.thandle, qpolicy) - - def set_layer_mode(self, layer, mode): - """ set send mode for specific transport layer - - :param layer: 0 = udp, 1 = shm, 42 = inproc - :type layer: int - :param mode: 0 = off, 1 = on, 2 = auto - :type layer: int - - """ - return _ecal.pub_set_layer_mode(self.thandle, layer, mode) - - def set_max_bandwidth_udp(self, bandwidth): - """ set publisher maximum transmit bandwidth for the udp layer. - - :param bandwidth: maximum bandwidth in bytes/s (-1 == unlimited) - :type bandwidth: int - - """ - - return _ecal.pub_set_max_bandwidth_udp(self.thandle, bandwidth) - def send(self, msg_payload, msg_time=-1): """ send publisher content @@ -697,67 +471,40 @@ def send(self, msg_payload, msg_time=-1): """ return pub_send(self.thandle, msg_payload, msg_time) - def send_sync(self, msg_payload, msg_time, ack_timeout_ms): - """ send publisher content synchronized to connected local subscribers with acknowledge timeout - - :param msg_payload: message python string (can contain zeros) - :type msg_payload: bytes - :param msg_time: message time in us (-1 == eCAL system time) - :type msg_time: int - :param ack_timeout_ms: Maximum time to wait for subscriber receive and process acknowledge feedback in ms - :type ack_timeout_ms: int - - """ - return pub_send_sync(self.thandle, msg_payload, msg_time, ack_timeout_ms) - class subscriber(object): """ eCAL subscriber """ - def __init__(self, topic_name, topic_type=""): + def __init__(self, topic_name, topic_type="", topic_enc="", topic_desc=b""): """ initialize subscriber :param topic_name: the unique topic name - :type topic_name: string - :param topic_type: optional topic type name - :type topic_type: string + :type topic_name: string + :param topic_type: optional type name + :type topic_type: string + :param topic_enc: optional type encoding + :type topic_enc: string + :param topic_desc: optional type description + :type topic_desc: bytes """ # topic name self.tname = topic_name # topic type self.ttype = topic_type + # topic description + self.tenc = topic_enc + # topic description + self.tdesc = topic_desc # topic handle - self.thandle = sub_create(self.tname, self.ttype) + self.thandle = sub_create(self.tname, self.ttype, self.tenc, self.tdesc) def destroy(self): """ destroy subscriber """ return sub_destroy(self.thandle) - def set_qos_historykind(self, qpolicy, depth): - """ set quality of service historykind mode and depth - - :param qpolicy: 0 = keep_last_history_qos, 1 = keep_all_history_qos - :type qpolicy: int - :param depth: history kind buffer depth - :type depth: int - - """ - - return sub_set_qos_historykind(self.thandle, qpolicy, depth) - - def set_qos_reliability(self, qpolicy): - """ set quality of service reliability mode - - :param qpolicy: 0 = best_effort_reliability_qos, 1 = reliable_reliability_qos - :type qpolicy: int - - """ - - return sub_set_qos_reliability(self.thandle, qpolicy) - def receive(self, timeout=0): """ receive subscriber content with timeout @@ -782,41 +529,3 @@ def rem_callback(self, callback): """ return sub_rem_callback(self.thandle, callback) - - -class subscriberDynJSON(object): - """ eCAL Protobuf dynamic JSON subscriber - """ - - def __init__(self, topic_name): - """ initialize subscriber - - :param topic_name: the unique topic name - :type topic_name: string - - """ - # topic name - self.tname = topic_name - # topic handle - self.thandle = dyn_json_sub_create(self.tname) - - def destroy(self): - """ destroy subscriber - """ - return dyn_json_sub_destroy(self.thandle) - - def set_callback(self, callback): - """ set callback function for incoming messages - - :param callback: python callback function (f(topic_name, msg, time)) - - """ - return dyn_json_sub_set_callback(self.thandle, callback) - - def rem_callback(self, callback): - """ remove callback function for incoming messages - - :param callback: python callback function (f(topic_name, msg, time)) - - """ - return dyn_json_sub_rem_callback(self.thandle, callback) diff --git a/lang/python/core/ecal/core/publisher.py b/lang/python/core/ecal/core/publisher.py index ad5c535d4f..8f341dfaa8 100644 --- a/lang/python/core/ecal/core/publisher.py +++ b/lang/python/core/ecal/core/publisher.py @@ -25,19 +25,20 @@ class MessagePublisher(object): Classes inheriting from this class need to implement the :func:`~msg_publisher.msg_publisher.send` function. """ - def __init__(self, name, topic_type="", topic_descriptor=b""): + + def __init__(self, topic_name, topic_type="", topic_encoding="", topic_descriptor=b""): """ Initialize a message publisher - :param name: subscription name of the publisher - :type name: string + :param topic_name: topic name of the publisher + :type topic_name: string :param topic_type: optional, type of the transported payload, eg a a string, a protobuf message :type topic_type: string - :param topic_descriptor: optional, a string which can be registered with ecal to allow io - reflection features + :param topic_encoding: optional type encoding (e.g. base, proto ..) + :type topic_encoding: string + :param topic_descriptor: optional, a string which can be registered with ecal to allow io reflection features :type topic_descriptor: bytes - """ - self.c_publisher = ecal_core.publisher(name, topic_type, topic_descriptor) + self.c_publisher = ecal_core.publisher(topic_name, topic_type, topic_encoding, topic_descriptor) def send(self, msg, time=-1): """ Send out a message @@ -49,89 +50,33 @@ def send(self, msg, time=-1): """ raise NotImplementedError("Please Implement this method") - def set_topic_type_name(self, topic_type_name): - """ set topic type name - - :param topic_type_name: the topic type name - :type topic_type_name: string - - """ - - return self.c_publisher.set_topic_type_name(topic_type_name) - - def set_topic_description(self, topic_desc): - """ set topic description - - :param topic_desc: the topic type description - :type topic_desc: bytes - - """ - - return self.c_publisher.set_topic_description(topic_desc) - - def set_qos(self, qos): - """ set publisher quality of service - - :param qos: 0 = default, 1 = best effort, 2 = reliable - :type qos: int - - """ - return self.c_publisher.set_qos(qos) - - def set_layer_mode(self, layer, mode): - """ set send mode for specific transport layer - - :param layer: 0 = udp, 1 = shm, 2 = hdf5 - :type layer: int - :param mode: 0 = off, 1 = on, 2 = auto - :type layer: int - - """ - return self.c_publisher.set_layer_mode(layer, mode) - - def set_max_bandwidth_udp(self, bandwidth): - """ set publisher maximum transmit bandwidth for the udp layer. - - :param bandwidth: maximum bandwidth in bytes/s (-1 == unlimited) - :type bandwidth: int - - """ - - return self.c_publisher.pub_set_max_bandwidth_upd(bandwidth) - - class ProtoPublisher(MessagePublisher): """Spezialized publisher that sends out protobuf messages """ def __init__(self, name, type_=None): if type_ is not None: - topic_type = "proto:" + type_.DESCRIPTOR.full_name + topic_type = type_.DESCRIPTOR.full_name + topic_enc = "proto" topic_desc = pb_helper.get_descriptor_from_type(type_) - super(ProtoPublisher, self).__init__(name, topic_type, topic_desc) + super(ProtoPublisher, self).__init__(name, topic_type, topic_enc, topic_desc) else: super(ProtoPublisher, self).__init__(name) def send(self, msg, time=-1): return self.c_publisher.send(msg.SerializeToString(), time) - def send_sync(self, msg, time, ack_timeout_ms): - return self.c_publisher.send_sync(msg.SerializeToString(), time, ack_timeout_ms) - - class StringPublisher(MessagePublisher): """Spezialized publisher that sends out plain strings """ def __init__(self, name): - topic_type = "base:std::string" + topic_type = "std::string" + topic_enc = "base" topic_desc = b"" - super(StringPublisher, self).__init__(name, topic_type, topic_desc) + super(StringPublisher, self).__init__(name, topic_type, topic_enc, topic_desc) def send(self, msg, time=-1): return self.c_publisher.send(msg.encode(), time) - def send_sync(self, msg, time, ack_timeout_ms): - return self.c_publisher.send_sync(msg.encode(), time, ack_timeout_ms) - if __name__ == '__main__': """Test the publisher API diff --git a/lang/python/core/ecal/core/subscriber.py b/lang/python/core/ecal/core/subscriber.py index 1fa0bb8a08..f6ca858f02 100644 --- a/lang/python/core/ecal/core/subscriber.py +++ b/lang/python/core/ecal/core/subscriber.py @@ -27,28 +27,20 @@ class MessageSubscriber(object): :func:`~subscriber.MessageSubscriber.set_callback` and :func:`~subscriber.MessageSubscriber.rem_callback` functions. """ - - def __init__(self, name, topic_type=""): - self.c_subscriber = ecal_core.subscriber(name, topic_type) - - def set_qos_historykind(self, qpolicy, depth): - """ set quality of service historykind mode and depth - - :param qpolicy: 0 = keep_last_history_qos, 1 = keep_all_history_qos - :param depth: history kind buffer depth + def __init__(self, topic_name, topic_type="", topic_encoding="", topic_descriptor=b""): + """ Initialize a message subscriber + + :param topic_name: topic name of the subscriber + :type topic_name: string + :param topic_type: optional, type of the transported payload, eg a a string, a protobuf message + :type topic_type: string + :param topic_encoding: optional type encoding (e.g. base, proto ..) + :type topic_encoding: string + :param topic_descriptor: optional, a string which can be registered with ecal to allow io reflection features + :type topic_descriptor: bytes """ - - return self.c_subscriber.set_qos_historykind(qpolicy, depth) - - def set_qos_reliability(self, topic_handle, qpolicy): - """ set quality of service reliability mode - - :param qpolicy: 0 = best_effort_reliability_qos, 1 = reliable_reliability_qos - - """ - - return self.c_subscriber.set_qos_reliability(topic_handle, qpolicy) + self.c_subscriber = ecal_core.subscriber(topic_name, topic_type, topic_encoding, topic_descriptor) def receive(self, timeout=0): """ receive subscriber content with timeout @@ -80,17 +72,10 @@ class ProtoSubscriber(MessageSubscriber): """Spezialized subscriber that subscribes to protobuf messages """ def __init__(self, name, type_protobuf): - """ receive subscriber content with timeout - - :param name: name on which the subscriber listens to traffic - :type name: string - :param type_protobuf: type of the protobuf object, which the subscriber will receive - - """ - topic_type = "proto:" + type_protobuf.DESCRIPTOR.full_name - #topic_desc = pb_helper.get_descriptor_from_type(type_protobuf) - # ProtoSubscriber only takes two arguments, check about subscriber - super(ProtoSubscriber, self).__init__(name, topic_type) + topic_type = type_protobuf.DESCRIPTOR.full_name + topic_enc = "proto" + topic_desc = pb_helper.get_descriptor_from_type(type_protobuf) + super(ProtoSubscriber, self).__init__(name, topic_type, topic_enc, topic_desc) self.protobuf_type = type_protobuf self.callback = None @@ -136,8 +121,10 @@ class StringSubscriber(MessageSubscriber): """Spezialized publisher subscribes to plain strings """ def __init__(self, name): - topic_type = "base:std::string" - super(StringSubscriber, self).__init__(name, topic_type) + topic_type = "std::string" + topic_enc = "base" + topic_desc = b"" + super(StringSubscriber, self).__init__(name, topic_type, topic_enc, topic_desc) self.callback = None def receive(self, timeout=0): diff --git a/lang/python/core/src/ecal_wrap.cxx b/lang/python/core/src/ecal_wrap.cxx index 45fe084f28..a1620ba40f 100644 --- a/lang/python/core/src/ecal_wrap.cxx +++ b/lang/python/core/src/ecal_wrap.cxx @@ -312,13 +312,16 @@ PyObject* log_message(PyObject* /*self*/, PyObject* args) /****************************************/ PyObject* pub_create(PyObject* /*self*/, PyObject* args) { - char* topic_name = nullptr; - char* topic_type = nullptr; + char* topic_name = nullptr; + char* topic_type = nullptr; + char* topic_enc = nullptr; + char* topic_desc = nullptr; + Py_ssize_t topic_desc_len = 0; - if (!PyArg_ParseTuple(args, "ss", &topic_name, &topic_type)) + if (!PyArg_ParseTuple(args, "sssy#", &topic_name, &topic_type, &topic_enc, &topic_desc, &topic_desc_len)) return nullptr; - return(PyAnswerHandle(pub_create(topic_name, topic_type))); + return(PyAnswerHandle(pub_create(topic_name, topic_type, topic_enc, topic_desc, (int)topic_desc_len))); } /****************************************/ @@ -361,19 +364,23 @@ PyObject* pub_send(PyObject* /*self*/, PyObject* args) /****************************************/ PyObject* sub_create(PyObject* /*self*/, PyObject* args) { - char* topic_name = nullptr; - char* topic_type = nullptr; + char* topic_name = nullptr; + char* topic_type = nullptr; + char* topic_enc = nullptr; + char* topic_desc = nullptr; + Py_ssize_t topic_desc_len = 0; - if (!PyArg_ParseTuple(args, "ss", &topic_name, &topic_type)) + if (!PyArg_ParseTuple(args, "sssy#", &topic_name, &topic_type, &topic_enc, &topic_desc, &topic_desc_len)) return nullptr; ECAL_HANDLE sub{ nullptr }; Py_BEGIN_ALLOW_THREADS - sub = sub_create(topic_name, topic_type); + sub = sub_create(topic_name, topic_type, topic_enc, topic_desc, (int)topic_desc_len); Py_END_ALLOW_THREADS - return(PyAnswerHandle(sub)); + return(PyAnswerHandle(sub)); } + /****************************************/ /* sub_destroy */ /****************************************/ @@ -1300,12 +1307,12 @@ static PyMethodDef _ecal_methods[] = {"log_setlevel", log_setlevel, METH_VARARGS, "log_setlevel(level)"}, {"log_message", log_message, METH_VARARGS, "log_message(message)"}, - {"pub_create", pub_create, METH_VARARGS, "pub_create(topic_name, topic_type)"}, + {"pub_create", pub_create, METH_VARARGS, "pub_create(topic_name, topic_type, topic_encoding, topic_desc)"}, {"pub_destroy", pub_destroy, METH_VARARGS, "pub_destroy(topic_handle)"}, {"pub_send", pub_send, METH_VARARGS, "pub_send(topic_handle, payload, time)"}, - {"sub_create", sub_create, METH_VARARGS, "sub_create(topic_name, topuic_type)"}, + {"sub_create", sub_create, METH_VARARGS, "sub_create(topic_name, topic_type, topic_encoding, topic_desc)"}, {"sub_destroy", sub_destroy, METH_VARARGS, "sub_destroy(topic_handle)"}, {"sub_receive", sub_receive, METH_VARARGS, "sub_receive(topic_handle, timeout)"}, diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index fbe81f54cc..f403383d85 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -69,7 +69,6 @@ if(BUILD_PY_BINDING) # pubsub add_subdirectory(python/pubsub/protobuf/person_rec) add_subdirectory(python/pubsub/protobuf/person_rec_cb) - add_subdirectory(python/pubsub/protobuf/person_rec_json) add_subdirectory(python/pubsub/protobuf/person_snd) add_subdirectory(python/pubsub/string/minimal_rec) add_subdirectory(python/pubsub/string/minimal_rec_cb) diff --git a/samples/python/benchmarks/latency_rec/latency_rec.py b/samples/python/benchmarks/latency_rec/latency_rec.py index de560bbf45..04abff4973 100644 --- a/samples/python/benchmarks/latency_rec/latency_rec.py +++ b/samples/python/benchmarks/latency_rec/latency_rec.py @@ -70,5 +70,5 @@ def do_run(): if __name__ == "__main__": - while ecal_core.ok(): + while True: do_run() diff --git a/samples/python/benchmarks/latency_rec_cb/latency_rec_cb.py b/samples/python/benchmarks/latency_rec_cb/latency_rec_cb.py index 2ac0e28f74..c7916c1135 100644 --- a/samples/python/benchmarks/latency_rec_cb/latency_rec_cb.py +++ b/samples/python/benchmarks/latency_rec_cb/latency_rec_cb.py @@ -44,7 +44,7 @@ def callback(topic_name, msg, snt_time): msg_num += 1 msg_size = len(msg) # reply - pub.send(msg) + pub.send(bytes(msg)) # apply message callback to subscriber sub.set_callback(callback) @@ -76,5 +76,5 @@ def callback(topic_name, msg, snt_time): if __name__ == "__main__": - while ecal_core.ok(): + while True: do_run() diff --git a/samples/python/pubsub/protobuf/person_rec_json/CMakeLists.txt b/samples/python/pubsub/protobuf/person_rec_json/CMakeLists.txt deleted file mode 100644 index a9df833a5a..0000000000 --- a/samples/python/pubsub/protobuf/person_rec_json/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# ========================= eCAL LICENSE ================================= -# -# Copyright (C) 2016 - 2019 Continental Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ========================= eCAL LICENSE ================================= - -project(person_rec_json) - -find_package(eCAL REQUIRED) - -set(PROJECT_GROUP person) - -if(ECAL_INCLUDE_PY_SAMPLES) - if(WIN32) - - include_external_msproject(${PROJECT_NAME}_py ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pyproj) - set_property(TARGET ${PROJECT_NAME}_py PROPERTY FOLDER samples/python/${PROJECT_GROUP}) - - endif() -endif() diff --git a/samples/python/pubsub/protobuf/person_rec_json/person_rec_json.py b/samples/python/pubsub/protobuf/person_rec_json/person_rec_json.py deleted file mode 100644 index 6aa9eabbce..0000000000 --- a/samples/python/pubsub/protobuf/person_rec_json/person_rec_json.py +++ /dev/null @@ -1,53 +0,0 @@ -# ========================= eCAL LICENSE ================================= -# -# Copyright (C) 2016 - 2019 Continental Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ========================= eCAL LICENSE ================================= - -import os -import sys -import time -import json - -import ecal.core.core as ecal_core - -def callback(topic_name, person, time): - person_dict = json.loads(person) - print(person_dict) - print("ID: {}".format(person_dict["id"])) - -def main(): - # print eCAL version and date - print("eCAL {} ({})\n".format(ecal_core.getversion(),ecal_core.getdate())) - - # initialize eCAL API - ecal_core.initialize(sys.argv, "py_person_rec_json") - - # set process state - ecal_core.set_process_state(1, 1, "I feel good") - - # create publisher - sub = ecal_core.subscriberDynJSON("person") - sub.set_callback(callback) - - # receive messages - while ecal_core.ok(): - time.sleep(0.1) - - # finalize eCAL API - ecal_core.finalize() - -if __name__ == "__main__": - main() diff --git a/samples/python/pubsub/protobuf/person_rec_json/person_rec_json.pyproj b/samples/python/pubsub/protobuf/person_rec_json/person_rec_json.pyproj deleted file mode 100644 index b9dd4013c7..0000000000 --- a/samples/python/pubsub/protobuf/person_rec_json/person_rec_json.pyproj +++ /dev/null @@ -1,35 +0,0 @@ - - - - Debug - 2.0 - . - person_rec_json.py - ..\..\..\lang\python\src - . - . - person_rec_json - person_rec_json - {d55e30a0-4680-3450-802f-a63216f10007} - - - true - false - - - true - false - - - - - - 10.0 - - - - - - - - \ No newline at end of file