Skip to content

Commit

Permalink
expose z_publiser/subcriber_keyexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
p-avital committed Sep 6, 2023
1 parent c5ab505 commit 464025b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "zenoh-pico/net/query.h"
#include "zenoh-pico/net/session.h"
#include "zenoh-pico/net/subscribe.h"
#include "zenoh-pico/protocol/core.h"
#include "zenoh-pico/protocol/keyexpr.h"
#include "zenoh-pico/session/session.h"
#include "zenoh-pico/system/platform.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -944,6 +948,8 @@ z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, con
*/
int8_t z_undeclare_publisher(z_owned_publisher_t *pub);

z_owned_keyexpr_t z_publisher_keyexpr(z_publisher_t publisher);

/**
* Constructs the default values for the put operation via a publisher entity.
*
Expand Down Expand Up @@ -1036,6 +1042,12 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z
*/
int8_t z_undeclare_subscriber(z_owned_subscriber_t *sub);

/**
* @brief
*
*/
z_owned_keyexpr_t z_subscriber_keyexpr(z_subscriber_t sub);

/**
* Constructs the default values for the pull subscriber entity.
*
Expand Down
28 changes: 28 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,3 +1030,31 @@ int8_t zp_send_join(z_session_t zs, const zp_send_join_options_t *options) {
(void)(options);
return _zp_send_join(zs._val);
}
z_owned_keyexpr_t z_publisher_keyexpr(z_publisher_t publisher) {
z_owned_keyexpr_t ret = {._value = z_malloc(sizeof(_z_keyexpr_t))};
if (ret._value != NULL && publisher._val != NULL) {
*ret._value = _z_keyexpr_duplicate(publisher._val->_key);
}
return ret;
}
z_owned_keyexpr_t z_subscriber_keyexpr(z_subscriber_t sub) {
z_owned_keyexpr_t ret = z_keyexpr_null();
__auto_type lookup = sub._val->_entity_id;
if (sub._val != NULL) {
_z_subscription_sptr_list_t *tail = sub._val->_zn->_local_subscriptions;
while (tail != NULL && !z_keyexpr_check(&ret)) {
_z_subscription_sptr_t *head = _z_subscription_sptr_list_head(tail);
if (head->ptr->_id == lookup) {
_z_keyexpr_t key = _z_keyexpr_duplicate(head->ptr->_key);
ret = (z_owned_keyexpr_t){._value = z_malloc(sizeof(_z_keyexpr_t))};
if (ret._value != NULL) {
*ret._value = key;
} else {
_z_keyexpr_clear(&key);
}
}
tail = _z_subscription_sptr_list_tail(tail);
}
}
return ret;
}
2 changes: 1 addition & 1 deletion zenohpico.pc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ prefix=/usr/local
Name: zenohpico
Description:
URL:
Version: 0.10.20230828dev
Version: 0.10.20230906dev
Cflags: -I${prefix}/
Libs: -L${prefix}/ -lzenohpico

0 comments on commit 464025b

Please sign in to comment.