Skip to content

Commit

Permalink
feat: add publication config token
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Oct 23, 2023
1 parent 5a1e59f commit 479322e
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 275 deletions.
186 changes: 94 additions & 92 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ int8_t z_info_routers_zid(const z_session_t zs, z_owned_closure_zid_t *callback)
*/
z_id_t z_info_zid(const z_session_t zs);

#if Z_FEATURE_PUBLICATION == 1
/**
* Constructs the default values for the put operation.
*
Expand Down Expand Up @@ -829,6 +830,99 @@ int8_t z_put(z_session_t zs, z_keyexpr_t keyexpr, const uint8_t *payload, z_zint
*/
int8_t z_delete(z_session_t zs, z_keyexpr_t keyexpr, const z_delete_options_t *options);

/**
* Constructs the default values for the publisher entity.
*
* Returns:
* Returns the constructed :c:type:`z_publisher_options_t`.
*/
z_publisher_options_t z_publisher_options_default(void);

/**
* Declares a publisher for the given keyexpr.
*
* Data can be put and deleted with this publisher with the help of the
* :c:func:`z_publisher_put` and :c:func:`z_publisher_delete` functions.
*
* Like most ``z_owned_X_t`` types, you may obtain an instance of :c:type:`z_owned_publisher_t` by loaning it using
* ``z_publisher_loan(&val)``. The ``z_loan(val)`` macro, available if your compiler supports C11's ``_Generic``, is
* equivalent to writing ``z_publisher_loan(&val)``.
*
* Like all ``z_owned_X_t``, an instance will be destroyed by any function which takes a mutable pointer to said
* instance, as this implies the instance's inners were moved. To make this fact more obvious when reading your code,
* consider using ``z_move(val)`` instead of ``&val`` as the argument. After a ``z_move``, ``val`` will still exist, but
* will no longer be valid. The destructors are double-drop-safe, but other functions will still trust that your ``val``
* is valid.
*
* To check if ``val`` is still valid, you may use ``z_publisher_check(&val)`` or ``z_check(val)`` if your compiler
* supports ``_Generic``, which will return ``true`` if ``val`` is valid, or ``false`` otherwise.
*
* Parameters:
* zs: A loaned instance of the the :c:type:`z_session_t` where to declare the publisher.
* keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the publisher.
* options: The options to apply to the publisher. If ``NULL`` is passed, the default options will be applied.
*
* Returns:
* A :c:type:`z_owned_publisher_t` with either a valid publisher or a failing publisher.
* Should the publisher be invalid, ``z_check(val)`` ing the returned value will return ``false``.
*/
z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, const z_publisher_options_t *options);

/**
* Undeclare the publisher generated by a call to :c:func:`z_declare_publisher`.
*
* Parameters:
* pub: A moved instance of :c:type:`z_owned_publisher_t` to undeclare.
*
* Returns:
* Returns ``0`` if the undeclare publisher operation is successful, or a ``negative value`` otherwise.
*/
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.
*
* Returns:
* Returns the constructed :c:type:`z_publisher_put_options_t`.
*/
z_publisher_put_options_t z_publisher_put_options_default(void);

/**
* Constructs the default values for the delete operation via a publisher entity.
*
* Returns:
* Returns the constructed :c:type:`z_publisher_delete_options_t`.
*/
z_publisher_delete_options_t z_publisher_delete_options_default(void);

/**
* Puts data for the keyexpr associated to the given publisher.
*
* Parameters:
* pub: A loaned instance of :c:type:`z_publisher_t` from where to put the data.
* options: The options to apply to the put operation. If ``NULL`` is passed, the default options will be applied.
*
* Returns:
* Returns ``0`` if the put operation is successful, or a ``negative value`` otherwise.
*/
int8_t z_publisher_put(const z_publisher_t pub, const uint8_t *payload, size_t len,
const z_publisher_put_options_t *options);

/**
* Deletes data from the keyexpr associated to the given publisher.
*
* Parameters:
* pub: A loaned instance of :c:type:`z_publisher_t` from where to delete the data.
* options: The options to apply to the delete operation. If ``NULL`` is passed, the default options will be applied.
*
* Returns:
* Returns ``0`` if the delete operation is successful, or a ``negative value`` otherwise.
*/
int8_t z_publisher_delete(const z_publisher_t pub, const z_publisher_delete_options_t *options);
#endif

#if Z_FEATURE_QUERY == 1
/**
* Constructs the default values for the get operation.
Expand Down Expand Up @@ -1024,98 +1118,6 @@ z_owned_keyexpr_t z_declare_keyexpr(z_session_t zs, z_keyexpr_t keyexpr);
*/
int8_t z_undeclare_keyexpr(z_session_t zs, z_owned_keyexpr_t *keyexpr);

/**
* Constructs the default values for the publisher entity.
*
* Returns:
* Returns the constructed :c:type:`z_publisher_options_t`.
*/
z_publisher_options_t z_publisher_options_default(void);

/**
* Declares a publisher for the given keyexpr.
*
* Data can be put and deleted with this publisher with the help of the
* :c:func:`z_publisher_put` and :c:func:`z_publisher_delete` functions.
*
* Like most ``z_owned_X_t`` types, you may obtain an instance of :c:type:`z_owned_publisher_t` by loaning it using
* ``z_publisher_loan(&val)``. The ``z_loan(val)`` macro, available if your compiler supports C11's ``_Generic``, is
* equivalent to writing ``z_publisher_loan(&val)``.
*
* Like all ``z_owned_X_t``, an instance will be destroyed by any function which takes a mutable pointer to said
* instance, as this implies the instance's inners were moved. To make this fact more obvious when reading your code,
* consider using ``z_move(val)`` instead of ``&val`` as the argument. After a ``z_move``, ``val`` will still exist, but
* will no longer be valid. The destructors are double-drop-safe, but other functions will still trust that your ``val``
* is valid.
*
* To check if ``val`` is still valid, you may use ``z_publisher_check(&val)`` or ``z_check(val)`` if your compiler
* supports ``_Generic``, which will return ``true`` if ``val`` is valid, or ``false`` otherwise.
*
* Parameters:
* zs: A loaned instance of the the :c:type:`z_session_t` where to declare the publisher.
* keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the publisher.
* options: The options to apply to the publisher. If ``NULL`` is passed, the default options will be applied.
*
* Returns:
* A :c:type:`z_owned_publisher_t` with either a valid publisher or a failing publisher.
* Should the publisher be invalid, ``z_check(val)`` ing the returned value will return ``false``.
*/
z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, const z_publisher_options_t *options);

/**
* Undeclares the publisher generated by a call to :c:func:`z_declare_publisher`.
*
* Parameters:
* pub: A moved instance of :c:type:`z_owned_publisher_t` to undeclare.
*
* Returns:
* Returns ``0`` if the undeclare publisher operation is successful, or a ``negative value`` otherwise.
*/
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.
*
* Returns:
* Returns the constructed :c:type:`z_publisher_put_options_t`.
*/
z_publisher_put_options_t z_publisher_put_options_default(void);

/**
* Constructs the default values for the delete operation via a publisher entity.
*
* Returns:
* Returns the constructed :c:type:`z_publisher_delete_options_t`.
*/
z_publisher_delete_options_t z_publisher_delete_options_default(void);

/**
* Puts data for the keyexpr associated to the given publisher.
*
* Parameters:
* pub: A loaned instance of :c:type:`z_publisher_t` from where to put the data.
* options: The options to apply to the put operation. If ``NULL`` is passed, the default options will be applied.
*
* Returns:
* Returns ``0`` if the put operation is successful, or a ``negative value`` otherwise.
*/
int8_t z_publisher_put(const z_publisher_t pub, const uint8_t *payload, size_t len,
const z_publisher_put_options_t *options);

/**
* Deletes data from the keyexpr associated to the given publisher.
*
* Parameters:
* pub: A loaned instance of :c:type:`z_publisher_t` from where to delete the data.
* options: The options to apply to the delete operation. If ``NULL`` is passed, the default options will be applied.
*
* Returns:
* Returns ``0`` if the delete operation is successful, or a ``negative value`` otherwise.
*/
int8_t z_publisher_delete(const z_publisher_t pub, const z_publisher_delete_options_t *options);

#if Z_FEATURE_SUBSCRIPTION == 1
/**
* Constructs the default values for the subscriber entity.
Expand Down
9 changes: 8 additions & 1 deletion include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,19 @@
#endif

/**
* Enable subscription to this node
* Enable subscription on this node
*/
#ifndef Z_FEATURE_SUBSCRIPTION
#define Z_FEATURE_SUBSCRIPTION 1
#endif

/**
* Enable publication
*/
#ifndef Z_FEATURE_PUBLICATION
#define Z_FEATURE_PUBLICATION 1
#endif

/**
* Enable TCP links.
*/
Expand Down
46 changes: 23 additions & 23 deletions include/zenoh-pico/net/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ uint16_t _z_declare_resource(_z_session_t *zn, _z_keyexpr_t keyexpr);
*/
int8_t _z_undeclare_resource(_z_session_t *zn, uint16_t rid);

#if Z_FEATURE_PUBLICATION == 1
/**
* Declare a :c:type:`_z_publisher_t` for the given resource key.
*
Expand Down Expand Up @@ -99,6 +100,28 @@ _z_publisher_t *_z_declare_publisher(_z_session_t *zn, _z_keyexpr_t keyexpr, z_c
*/
int8_t _z_undeclare_publisher(_z_publisher_t *pub);

/**
* Write data corresponding to a given resource key, allowing the definition of
* additional properties.
*
* Parameters:
* zn: The zenoh-net session. The caller keeps its ownership.
* keyexpr: The resource key to write. The caller keeps its ownership.
* payload: The value to write.
* len: The length of the value to write.
* encoding: The encoding of the payload. The callee gets the ownership of
* any allocated value.
* kind: The kind of the value.
* cong_ctrl: The congestion control of this write. Possible values defined
* in :c:type:`_z_congestion_control_t`.
* Returns:
* ``0`` in case of success, ``-1`` in case of failure.
*/
int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *payload, const size_t len,
const _z_encoding_t encoding, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl,
z_priority_t priority);
#endif

#if Z_FEATURE_SUBSCRIPTION == 1
/**
* Declare a :c:type:`_z_subscriber_t` for the given resource key.
Expand Down Expand Up @@ -208,27 +231,4 @@ int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters,
void *arg_call, _z_drop_handler_t dropper, void *arg_drop);
#endif

/*------------------ Operations ------------------*/

/**
* Write data corresponding to a given resource key, allowing the definition of
* additional properties.
*
* Parameters:
* zn: The zenoh-net session. The caller keeps its ownership.
* keyexpr: The resource key to write. The caller keeps its ownership.
* payload: The value to write.
* len: The length of the value to write.
* encoding: The encoding of the payload. The callee gets the ownership of
* any allocated value.
* kind: The kind of the value.
* cong_ctrl: The congestion control of this write. Possible values defined
* in :c:type:`_z_congestion_control_t`.
* Returns:
* ``0`` in case of success, ``-1`` in case of failure.
*/
int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *payload, const size_t len,
const _z_encoding_t encoding, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl,
z_priority_t priority);

#endif /* ZENOH_PICO_PRIMITIVES_NETAPI_H */
2 changes: 2 additions & 0 deletions include/zenoh-pico/net/publish.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ typedef struct {
z_priority_t _priority;
} _z_publisher_t;

#if Z_FEATURE_PUBLICATION == 1
void _z_publisher_clear(_z_publisher_t *pub);
void _z_publisher_free(_z_publisher_t **pub);
#endif

#endif /* INCLUDE_ZENOH_PICO_NET_PUBLISH_H */
20 changes: 0 additions & 20 deletions include/zenoh-pico/session/publication.h

This file was deleted.

Loading

0 comments on commit 479322e

Please sign in to comment.