From 5bd1370c4c9c74a7f58934b41ba97f2b6f8627c0 Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Mon, 23 Oct 2023 17:26:06 +0200 Subject: [PATCH] Add publication token config (#267) --- examples/arduino/z_pub.ino | 7 + examples/espidf/z_pub.c | 6 + examples/mbed/z_pub.cpp | 7 + examples/unix/c11/z_ping.c | 6 +- examples/unix/c11/z_pong.c | 6 +- examples/unix/c11/z_pub.c | 7 + examples/unix/c11/z_pub_st.c | 7 + examples/unix/c11/z_put.c | 7 + examples/unix/c99/z_ping.c | 6 +- examples/unix/c99/z_pong.c | 15 +- examples/unix/c99/z_pub.c | 7 + examples/unix/c99/z_pub_st.c | 7 + examples/unix/c99/z_put.c | 7 + examples/windows/z_ping.c | 6 +- examples/windows/z_pong.c | 6 +- examples/windows/z_pub.c | 7 + examples/windows/z_pub_st.c | 7 + examples/windows/z_put.c | 7 + examples/zephyr/z_pub.c | 7 + include/zenoh-pico/api/primitives.h | 186 ++++++++++++----------- include/zenoh-pico/config.h | 9 +- include/zenoh-pico/net/primitives.h | 46 +++--- include/zenoh-pico/net/publish.h | 2 + include/zenoh-pico/session/publication.h | 20 --- src/api/api.c | 164 ++++++++++---------- src/net/primitives.c | 104 ++++++------- src/net/publish.c | 2 + tests/z_api_null_drop_test.c | 18 ++- 28 files changed, 398 insertions(+), 288 deletions(-) delete mode 100644 include/zenoh-pico/session/publication.h diff --git a/examples/arduino/z_pub.ino b/examples/arduino/z_pub.ino index 81f3745b2..763d69ee2 100644 --- a/examples/arduino/z_pub.ino +++ b/examples/arduino/z_pub.ino @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 // WiFi-specific parameters #define SSID "SSID" #define PASS "PASS" @@ -107,3 +108,9 @@ void loop() { delay(1000); } +#else +void setup() { + Serial.println("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it."); +} +void loop() {} +#endif diff --git a/examples/espidf/z_pub.c b/examples/espidf/z_pub.c index 112429cbd..b55336f94 100644 --- a/examples/espidf/z_pub.c +++ b/examples/espidf/z_pub.c @@ -25,6 +25,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 #define ESP_WIFI_SSID "SSID" #define ESP_WIFI_PASS "PASS" #define ESP_MAXIMUM_RETRY 5 @@ -163,3 +164,8 @@ void app_main() { z_close(z_move(s)); printf("OK!\n"); } +#else +void app_main() { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); +} +#endif diff --git a/examples/mbed/z_pub.cpp b/examples/mbed/z_pub.cpp index 8720faaa3..b51127a37 100644 --- a/examples/mbed/z_pub.cpp +++ b/examples/mbed/z_pub.cpp @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -85,3 +86,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c11/z_ping.c b/examples/unix/c11/z_ping.c index 775420bd7..d3853d475 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -21,7 +21,7 @@ #include "zenoh-pico.h" #include "zenoh-pico/system/platform.h" -#if Z_FEATURE_SUBSCRIPTION == 1 +#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 // WARNING: for the sake of this example we are using "internal" structs and functions (starting with "_"). // Synchronisation primitives are planned to be added to the API in the future. _z_condvar_t cond; @@ -168,7 +168,9 @@ struct args_t parse_args(int argc, char** argv) { } #else int main(void) { - printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + printf( + "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " + "requires them.\n"); return -1; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_pong.c b/examples/unix/c11/z_pong.c index a79fb7285..0a9ee2d26 100644 --- a/examples/unix/c11/z_pong.c +++ b/examples/unix/c11/z_pong.c @@ -15,7 +15,7 @@ #include "stdio.h" #include "zenoh-pico.h" -#if Z_FEATURE_SUBSCRIPTION == 1 +#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 void callback(const z_sample_t* sample, void* context) { z_publisher_t pub = z_loan(*(z_owned_publisher_t*)context); z_publisher_put(pub, sample->payload.start, sample->payload.len, NULL); @@ -71,7 +71,9 @@ int main(int argc, char** argv) { } #else int main(void) { - printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + printf( + "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " + "requires them.\n"); return -1; } #endif \ No newline at end of file diff --git a/examples/unix/c11/z_pub.c b/examples/unix/c11/z_pub.c index e4f96b7ea..35df1383d 100644 --- a/examples/unix/c11/z_pub.c +++ b/examples/unix/c11/z_pub.c @@ -22,6 +22,7 @@ #include "zenoh-pico/system/platform.h" +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-pub"; char *const default_value = "Pub from Pico!"; @@ -117,3 +118,9 @@ int main(int argc, char **argv) { } return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif diff --git a/examples/unix/c11/z_pub_st.c b/examples/unix/c11/z_pub_st.c index f2b0fef79..7dda9936e 100644 --- a/examples/unix/c11/z_pub_st.c +++ b/examples/unix/c11/z_pub_st.c @@ -19,6 +19,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-pub"; const char *value = "Pub from Pico!"; @@ -103,3 +104,9 @@ int main(int argc, char **argv) { free(buf); return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c11/z_put.c b/examples/unix/c11/z_put.c index 0445d48f9..557a128a5 100644 --- a/examples/unix/c11/z_put.c +++ b/examples/unix/c11/z_put.c @@ -19,6 +19,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-put"; const char *value = "Pub from Pico!"; @@ -101,3 +102,9 @@ int main(int argc, char **argv) { z_close(z_move(s)); return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c99/z_ping.c b/examples/unix/c99/z_ping.c index 18c296a7d..451a8fc30 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -22,7 +22,7 @@ #include "zenoh-pico/api/primitives.h" #include "zenoh-pico/system/platform.h" -#if Z_FEATURE_SUBSCRIPTION == 1 +#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 _z_condvar_t cond; _z_mutex_t mutex; @@ -168,7 +168,9 @@ struct args_t parse_args(int argc, char** argv) { } #else int main(void) { - printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + printf( + "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " + "requires them.\n"); return -1; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_pong.c b/examples/unix/c99/z_pong.c index d7671b38d..b175c49b0 100644 --- a/examples/unix/c99/z_pong.c +++ b/examples/unix/c99/z_pong.c @@ -16,7 +16,7 @@ #include "zenoh-pico.h" #include "zenoh-pico/api/primitives.h" -#if Z_FEATURE_SUBSCRIPTION == 1 +#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 void callback(const z_sample_t* sample, void* context) { z_publisher_t pub = z_publisher_loan((z_owned_publisher_t*)context); z_publisher_put(pub, sample->payload.start, sample->payload.len, NULL); @@ -45,7 +45,14 @@ int main(int argc, char** argv) { printf("Unable to start read and lease tasks"); return -1; } - +#else +int main(void) { + printf( + "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " + "requires them.\n"); + return -1; +} +#endif z_keyexpr_t pong = z_keyexpr_unchecked("test/pong"); z_owned_publisher_t pub = z_declare_publisher(z_session_loan(&session), pong, NULL); if (!z_publisher_check(&pub)) { @@ -74,7 +81,9 @@ int main(int argc, char** argv) { } #else int main(void) { - printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + printf( + "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " + "requires them.\n"); return -1; } #endif \ No newline at end of file diff --git a/examples/unix/c99/z_pub.c b/examples/unix/c99/z_pub.c index 8ee66dfdb..0e0c22f1f 100644 --- a/examples/unix/c99/z_pub.c +++ b/examples/unix/c99/z_pub.c @@ -19,6 +19,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-pub"; const char *value = "Pub from Pico!"; @@ -106,3 +107,9 @@ int main(int argc, char **argv) { free(buf); return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c99/z_pub_st.c b/examples/unix/c99/z_pub_st.c index 96eeba2a4..237a892d9 100644 --- a/examples/unix/c99/z_pub_st.c +++ b/examples/unix/c99/z_pub_st.c @@ -19,6 +19,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-pub"; const char *value = "Pub from Pico!"; @@ -103,3 +104,9 @@ int main(int argc, char **argv) { free(buf); return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c99/z_put.c b/examples/unix/c99/z_put.c index be22b6eea..20d13fb11 100644 --- a/examples/unix/c99/z_put.c +++ b/examples/unix/c99/z_put.c @@ -19,6 +19,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { const char *keyexpr = "demo/example/zenoh-pico-put"; const char *value = "Pub from Pico!"; @@ -101,3 +102,9 @@ int main(int argc, char **argv) { z_close(z_session_move(&s)); return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/windows/z_ping.c b/examples/windows/z_ping.c index 247b18eb7..da6cb75db 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -21,7 +21,7 @@ #include "zenoh-pico.h" #include "zenoh-pico/system/platform.h" -#if Z_FEATURE_SUBSCRIPTION == 1 +#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 _z_condvar_t cond; _z_mutex_t mutex; @@ -165,7 +165,9 @@ struct args_t parse_args(int argc, char** argv) { } #else int main(void) { - printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + printf( + "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " + "requires them.\n"); return -1; } #endif \ No newline at end of file diff --git a/examples/windows/z_pong.c b/examples/windows/z_pong.c index a79fb7285..0a9ee2d26 100644 --- a/examples/windows/z_pong.c +++ b/examples/windows/z_pong.c @@ -15,7 +15,7 @@ #include "stdio.h" #include "zenoh-pico.h" -#if Z_FEATURE_SUBSCRIPTION == 1 +#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 void callback(const z_sample_t* sample, void* context) { z_publisher_t pub = z_loan(*(z_owned_publisher_t*)context); z_publisher_put(pub, sample->payload.start, sample->payload.len, NULL); @@ -71,7 +71,9 @@ int main(int argc, char** argv) { } #else int main(void) { - printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + printf( + "ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example " + "requires them.\n"); return -1; } #endif \ No newline at end of file diff --git a/examples/windows/z_pub.c b/examples/windows/z_pub.c index 31bf582db..aecc29806 100644 --- a/examples/windows/z_pub.c +++ b/examples/windows/z_pub.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { (void)(argc); (void)(argv); @@ -74,3 +75,9 @@ int main(int argc, char **argv) { free(buf); return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif diff --git a/examples/windows/z_pub_st.c b/examples/windows/z_pub_st.c index 55475ad22..4623098ae 100644 --- a/examples/windows/z_pub_st.c +++ b/examples/windows/z_pub_st.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { (void)(argc); (void)(argv); @@ -70,3 +71,9 @@ int main(int argc, char **argv) { free(buf); return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/windows/z_put.c b/examples/windows/z_put.c index 464eab495..dff826725 100644 --- a/examples/windows/z_put.c +++ b/examples/windows/z_put.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { (void)(argc); (void)(argv); @@ -68,3 +69,9 @@ int main(int argc, char **argv) { z_close(z_move(s)); return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/zephyr/z_pub.c b/examples/zephyr/z_pub.c index 606311860..09623fd49 100644 --- a/examples/zephyr/z_pub.c +++ b/examples/zephyr/z_pub.c @@ -31,6 +31,7 @@ #define KEYEXPR "demo/example/zenoh-pico-pub" #define VALUE "[STSTM32]{nucleo-F767ZI} Pub from Zenoh-Pico!" +#if Z_FEATURE_PUBLICATION == 1 int main(int argc, char **argv) { sleep(5); @@ -82,3 +83,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 36d4cfb05..c96937518 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -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. * @@ -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. @@ -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. diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index 1b8993694..3d55a7edd 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -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. */ diff --git a/include/zenoh-pico/net/primitives.h b/include/zenoh-pico/net/primitives.h index 7a8d0b428..3711d8ceb 100644 --- a/include/zenoh-pico/net/primitives.h +++ b/include/zenoh-pico/net/primitives.h @@ -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. * @@ -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. @@ -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 */ diff --git a/include/zenoh-pico/net/publish.h b/include/zenoh-pico/net/publish.h index 0e6ab763c..15933e035 100644 --- a/include/zenoh-pico/net/publish.h +++ b/include/zenoh-pico/net/publish.h @@ -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 */ diff --git a/include/zenoh-pico/session/publication.h b/include/zenoh-pico/session/publication.h deleted file mode 100644 index bdfa52d65..000000000 --- a/include/zenoh-pico/session/publication.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright (c) 2022 ZettaScale Technology -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// -// Contributors: -// ZettaScale Zenoh Team, -// - -#ifndef ZENOH_PICO_SESSION_PUBLICATION_H -#define ZENOH_PICO_SESSION_PUBLICATION_H - -#include "zenoh-pico/protocol/core.h" - -#endif /* ZENOH_PICO_SESSION_PUBLICATION_H */ diff --git a/src/api/api.c b/src/api/api.c index d02b0a036..288465a70 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -409,10 +409,6 @@ OWNED_FUNCTIONS_PTR_COMMON(z_session_t, z_owned_session_t, session) OWNED_FUNCTIONS_PTR_CLONE(z_session_t, z_owned_session_t, session, _z_owner_noop_copy) void z_session_drop(z_owned_session_t *val) { z_close(val); } -OWNED_FUNCTIONS_PTR_COMMON(z_publisher_t, z_owned_publisher_t, publisher) -OWNED_FUNCTIONS_PTR_CLONE(z_publisher_t, z_owned_publisher_t, publisher, _z_owner_noop_copy) -void z_publisher_drop(z_owned_publisher_t *val) { z_undeclare_publisher(val); } - OWNED_FUNCTIONS_PTR_INTERNAL(z_keyexpr_t, z_owned_keyexpr_t, keyexpr, _z_keyexpr_free, _z_keyexpr_copy) OWNED_FUNCTIONS_PTR_INTERNAL(z_hello_t, z_owned_hello_t, hello, _z_hello_free, _z_owner_noop_copy) OWNED_FUNCTIONS_PTR_INTERNAL(z_str_array_t, z_owned_str_array_t, str_array, _z_str_array_free, _z_owner_noop_copy) @@ -589,6 +585,11 @@ 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) { return zs._val->_local_zid; } +#if Z_FEATURE_PUBLICATION == 1 +OWNED_FUNCTIONS_PTR_COMMON(z_publisher_t, z_owned_publisher_t, publisher) +OWNED_FUNCTIONS_PTR_CLONE(z_publisher_t, z_owned_publisher_t, publisher, _z_owner_noop_copy) +void z_publisher_drop(z_owned_publisher_t *val) { z_undeclare_publisher(val); } + z_put_options_t z_put_options_default(void) { return (z_put_options_t){.encoding = z_encoding_default(), .congestion_control = Z_CONGESTION_CONTROL_DEFAULT, @@ -629,6 +630,84 @@ int8_t z_delete(z_session_t zs, z_keyexpr_t keyexpr, const z_delete_options_t *o return ret; } +z_publisher_options_t z_publisher_options_default(void) { + return (z_publisher_options_t){.congestion_control = Z_CONGESTION_CONTROL_DEFAULT, .priority = Z_PRIORITY_DEFAULT}; +} + +z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, const z_publisher_options_t *options) { + z_keyexpr_t key = keyexpr; + + // TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition + // lacks a way to convey them to later-joining nodes. Thus, in the current version automatic + // resource declarations are only performed on unicast transports. +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 + if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) { +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 + _z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr); + if (r == NULL) { + uint16_t id = _z_declare_resource(zs._val, keyexpr); + key = _z_rid_with_suffix(id, NULL); + } +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 + } +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 + + z_publisher_options_t opt = z_publisher_options_default(); + if (options != NULL) { + opt.congestion_control = options->congestion_control; + opt.priority = options->priority; + } + + return (z_owned_publisher_t){._value = _z_declare_publisher(zs._val, key, opt.congestion_control, opt.priority)}; +} + +int8_t z_undeclare_publisher(z_owned_publisher_t *pub) { + int8_t ret = _Z_RES_OK; + + ret = _z_undeclare_publisher(pub->_value); + _z_publisher_free(&pub->_value); + + return ret; +} + +z_publisher_put_options_t z_publisher_put_options_default(void) { + return (z_publisher_put_options_t){.encoding = z_encoding_default()}; +} + +z_publisher_delete_options_t z_publisher_delete_options_default(void) { + return (z_publisher_delete_options_t){.__dummy = 0}; +} + +int8_t z_publisher_put(const z_publisher_t pub, const uint8_t *payload, size_t len, + const z_publisher_put_options_t *options) { + int8_t ret = _Z_RES_OK; + + z_publisher_put_options_t opt = z_publisher_put_options_default(); + if (options != NULL) { + opt.encoding = options->encoding; + } + + ret = _z_write(pub._val->_zn, pub._val->_key, payload, len, opt.encoding, Z_SAMPLE_KIND_PUT, + pub._val->_congestion_control, pub._val->_priority); + + return ret; +} + +int8_t z_publisher_delete(const z_publisher_t pub, const z_publisher_delete_options_t *options) { + (void)(options); + return _z_write(pub._val->_zn, pub._val->_key, NULL, 0, z_encoding_default(), Z_SAMPLE_KIND_DELETE, + pub._val->_congestion_control, pub._val->_priority); +} + +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; +} +#endif + #if Z_FEATURE_QUERY == 1 OWNED_FUNCTIONS_PTR_INTERNAL(z_reply_t, z_owned_reply_t, reply, _z_reply_free, _z_owner_noop_copy) @@ -801,75 +880,6 @@ int8_t z_undeclare_keyexpr(z_session_t zs, z_owned_keyexpr_t *keyexpr) { return ret; } -z_publisher_options_t z_publisher_options_default(void) { - return (z_publisher_options_t){.congestion_control = Z_CONGESTION_CONTROL_DEFAULT, .priority = Z_PRIORITY_DEFAULT}; -} - -z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, const z_publisher_options_t *options) { - z_keyexpr_t key = keyexpr; - - // TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition - // lacks a way to convey them to later-joining nodes. Thus, in the current version automatic - // resource declarations are only performed on unicast transports. -#if Z_FEATURE_MULTICAST_TRANSPORT == 1 - if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) { -#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 - _z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr); - if (r == NULL) { - uint16_t id = _z_declare_resource(zs._val, keyexpr); - key = _z_rid_with_suffix(id, NULL); - } -#if Z_FEATURE_MULTICAST_TRANSPORT == 1 - } -#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 - - z_publisher_options_t opt = z_publisher_options_default(); - if (options != NULL) { - opt.congestion_control = options->congestion_control; - opt.priority = options->priority; - } - - return (z_owned_publisher_t){._value = _z_declare_publisher(zs._val, key, opt.congestion_control, opt.priority)}; -} - -int8_t z_undeclare_publisher(z_owned_publisher_t *pub) { - int8_t ret = _Z_RES_OK; - - ret = _z_undeclare_publisher(pub->_value); - _z_publisher_free(&pub->_value); - - return ret; -} - -z_publisher_put_options_t z_publisher_put_options_default(void) { - return (z_publisher_put_options_t){.encoding = z_encoding_default()}; -} - -z_publisher_delete_options_t z_publisher_delete_options_default(void) { - return (z_publisher_delete_options_t){.__dummy = 0}; -} - -int8_t z_publisher_put(const z_publisher_t pub, const uint8_t *payload, size_t len, - const z_publisher_put_options_t *options) { - int8_t ret = _Z_RES_OK; - - z_publisher_put_options_t opt = z_publisher_put_options_default(); - if (options != NULL) { - opt.encoding = options->encoding; - } - - ret = _z_write(pub._val->_zn, pub._val->_key, payload, len, opt.encoding, Z_SAMPLE_KIND_PUT, - pub._val->_congestion_control, pub._val->_priority); - - return ret; -} - -int8_t z_publisher_delete(const z_publisher_t pub, const z_publisher_delete_options_t *options) { - (void)(options); - return _z_write(pub._val->_zn, pub._val->_key, NULL, 0, z_encoding_default(), Z_SAMPLE_KIND_DELETE, - pub._val->_congestion_control, pub._val->_priority); -} - #if Z_FEATURE_SUBSCRIPTION == 1 OWNED_FUNCTIONS_PTR_COMMON(z_subscriber_t, z_owned_subscriber_t, subscriber) OWNED_FUNCTIONS_PTR_CLONE(z_subscriber_t, z_owned_subscriber_t, subscriber, _z_owner_noop_copy) @@ -1069,12 +1079,4 @@ zp_send_join_options_t zp_send_join_options_default(void) { return (zp_send_join 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; } \ No newline at end of file diff --git a/src/net/primitives.c b/src/net/primitives.c index 3a4087719..7f0123695 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -96,6 +96,7 @@ int8_t _z_undeclare_resource(_z_session_t *zn, uint16_t rid) { return ret; } +#if Z_FEATURE_PUBLICATION == 1 /*------------------ Publisher Declaration ------------------*/ _z_publisher_t *_z_declare_publisher(_z_session_t *zn, _z_keyexpr_t keyexpr, z_congestion_control_t congestion_control, z_priority_t priority) { @@ -124,6 +125,57 @@ int8_t _z_undeclare_publisher(_z_publisher_t *pub) { return ret; } +/*------------------ Write ------------------*/ +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) { + int8_t ret = _Z_RES_OK; + _z_network_message_t msg; + switch (kind) { + case Z_SAMPLE_KIND_PUT: + msg = (_z_network_message_t){ + ._tag = _Z_N_PUSH, + ._body._push = + { + ._key = keyexpr, + ._qos = _z_n_qos_make(0, cong_ctrl == Z_CONGESTION_CONTROL_BLOCK, priority), + ._timestamp = _z_timestamp_null(), + ._body._is_put = true, + ._body._body._put = + { + ._commons = {._timestamp = _z_timestamp_null(), ._source_info = _z_source_info_null()}, + ._payload = _z_bytes_wrap(payload, len), + ._encoding = encoding, + }, + }, + }; + break; + case Z_SAMPLE_KIND_DELETE: + msg = (_z_network_message_t){ + ._tag = _Z_N_PUSH, + ._body._push = + { + ._key = keyexpr, + ._qos = _z_n_qos_make(0, cong_ctrl == Z_CONGESTION_CONTROL_BLOCK, priority), + ._timestamp = _z_timestamp_null(), + ._body._is_put = false, + ._body._body._del = {._commons = {._timestamp = _z_timestamp_null(), + ._source_info = _z_source_info_null()}}, + }, + }; + break; + } + + if (_z_send_n_msg(zn, &msg, Z_RELIABILITY_RELIABLE, cong_ctrl) != _Z_RES_OK) { + ret = _Z_ERR_TRANSPORT_TX_FAILED; + } + + // Freeing z_msg is unnecessary, as all of its components are aliased + + return ret; +} +#endif + #if Z_FEATURE_SUBSCRIPTION == 1 /*------------------ Subscriber Declaration ------------------*/ _z_subscriber_t *_z_declare_subscriber(_z_session_t *zn, _z_keyexpr_t keyexpr, _z_subinfo_t sub_info, @@ -365,54 +417,4 @@ int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, return ret; } -#endif - -/*------------------ Write ------------------*/ -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) { - int8_t ret = _Z_RES_OK; - _z_network_message_t msg; - switch (kind) { - case Z_SAMPLE_KIND_PUT: - msg = (_z_network_message_t){ - ._tag = _Z_N_PUSH, - ._body._push = - { - ._key = keyexpr, - ._qos = _z_n_qos_make(0, cong_ctrl == Z_CONGESTION_CONTROL_BLOCK, priority), - ._timestamp = _z_timestamp_null(), - ._body._is_put = true, - ._body._body._put = - { - ._commons = {._timestamp = _z_timestamp_null(), ._source_info = _z_source_info_null()}, - ._payload = _z_bytes_wrap(payload, len), - ._encoding = encoding, - }, - }, - }; - break; - case Z_SAMPLE_KIND_DELETE: - msg = (_z_network_message_t){ - ._tag = _Z_N_PUSH, - ._body._push = - { - ._key = keyexpr, - ._qos = _z_n_qos_make(0, cong_ctrl == Z_CONGESTION_CONTROL_BLOCK, priority), - ._timestamp = _z_timestamp_null(), - ._body._is_put = false, - ._body._body._del = {._commons = {._timestamp = _z_timestamp_null(), - ._source_info = _z_source_info_null()}}, - }, - }; - break; - } - - if (_z_send_n_msg(zn, &msg, Z_RELIABILITY_RELIABLE, cong_ctrl) != _Z_RES_OK) { - ret = _Z_ERR_TRANSPORT_TX_FAILED; - } - - // Freeing z_msg is unnecessary, as all of its components are aliased - - return ret; -} \ No newline at end of file +#endif \ No newline at end of file diff --git a/src/net/publish.c b/src/net/publish.c index 7ef50abd2..7b2d1bffc 100644 --- a/src/net/publish.c +++ b/src/net/publish.c @@ -16,6 +16,7 @@ #include +#if Z_FEATURE_PUBLICATION == 1 void _z_publisher_clear(_z_publisher_t *pub) { _z_keyexpr_clear(&pub->_key); } void _z_publisher_free(_z_publisher_t **pub) { @@ -28,3 +29,4 @@ void _z_publisher_free(_z_publisher_t **pub) { *pub = NULL; } } +#endif diff --git a/tests/z_api_null_drop_test.c b/tests/z_api_null_drop_test.c index 979280900..a3c0f74cf 100644 --- a/tests/z_api_null_drop_test.c +++ b/tests/z_api_null_drop_test.c @@ -25,7 +25,6 @@ int main(void) { // Check that all null functions exists // z_owned_session_t session_null_1 = z_session_null(); - z_owned_publisher_t publisher_null_1 = z_publisher_null(); z_owned_keyexpr_t keyexpr_null_1 = z_keyexpr_null(); z_owned_config_t config_null_1 = z_config_null(); z_owned_scouting_config_t scouting_config_null_1 = z_scouting_config_null(); @@ -41,7 +40,6 @@ int main(void) { // Test that they actually make invalid value (where applicable) // assert(!z_check(session_null_1)); - assert(!z_check(publisher_null_1)); assert(!z_check(keyexpr_null_1)); assert(!z_check(config_null_1)); assert(!z_check(scouting_config_null_1)); @@ -52,7 +50,6 @@ int main(void) { // Test that z_null macro defined for all types // z_owned_session_t session_null_2; - z_owned_publisher_t publisher_null_2; z_owned_keyexpr_t keyexpr_null_2; z_owned_config_t config_null_2; z_owned_scouting_config_t scouting_config_null_2; @@ -65,7 +62,6 @@ int main(void) { z_owned_str_t str_null_2; z_null(&session_null_2); - z_null(&publisher_null_2); z_null(&keyexpr_null_2); z_null(&config_null_2); z_null(&scouting_config_null_2); @@ -77,6 +73,13 @@ int main(void) { z_null(&closure_zid_null_2); z_null(&str_null_2); +#if Z_FEATURE_PUBLICATION == 1 + z_owned_publisher_t publisher_null_1 = z_publisher_null(); + assert(!z_check(publisher_null_1)); + z_owned_publisher_t publisher_null_2; + z_null(&publisher_null_2); + assert(!z_check(publisher_null_2)); +#endif #if Z_FEATURE_SUBSCRIPTION == 1 z_owned_pull_subscriber_t pull_subscriber_null_1 = z_pull_subscriber_null(); z_owned_subscriber_t subscriber_null_1 = z_subscriber_null(); @@ -108,7 +111,6 @@ int main(void) { // Test that null macro works the same as direct call // assert(!z_check(session_null_2)); - assert(!z_check(publisher_null_2)); assert(!z_check(keyexpr_null_2)); assert(!z_check(config_null_2)); assert(!z_check(scouting_config_null_2)); @@ -120,7 +122,6 @@ int main(void) { // for (int i = 0; i < 2; ++i) { z_drop(z_move(session_null_1)); - z_drop(z_move(publisher_null_1)); z_drop(z_move(keyexpr_null_1)); z_drop(z_move(config_null_1)); z_drop(z_move(scouting_config_null_1)); @@ -133,7 +134,6 @@ int main(void) { z_drop(z_move(str_null_1)); z_drop(z_move(session_null_2)); - z_drop(z_move(publisher_null_2)); z_drop(z_move(keyexpr_null_2)); z_drop(z_move(config_null_2)); z_drop(z_move(scouting_config_null_2)); @@ -145,6 +145,10 @@ int main(void) { z_drop(z_move(closure_zid_null_2)); z_drop(z_move(str_null_2)); +#if Z_FEATURE_PUBLICATION == 1 + z_drop(z_move(publisher_null_1)); + z_drop(z_move(publisher_null_2)); +#endif #if Z_FEATURE_SUBSCRIPTION == 1 z_drop(z_move(pull_subscriber_null_1)); z_drop(z_move(subscriber_null_1));