diff --git a/Cargo.toml b/Cargo.toml index 95867f95f..2735c3f86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ serde_yaml = "0.9.19" [lib] path="src/lib.rs" -name = "zenohc" +name = "zenohcd" crate-type = ["cdylib", "staticlib"] doctest = false diff --git a/docs/api.rst b/docs/api.rst index 758c405b5..3bdf769ee 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -203,8 +203,6 @@ Types .. autocstruct:: zenoh_concrete.h::z_owned_subscriber_t -.. autocstruct:: zenoh_concrete.h::z_owned_pull_subscriber_t - .. autocstruct:: zenoh_commons.h::z_owned_closure_sample_t .. autocenum:: zenoh_commons.h::z_reliability_t @@ -219,11 +217,6 @@ Functions .. autocfunction:: zenoh_commons.h::z_subscriber_check .. autocfunction:: zenoh_commons.h::z_undeclare_subscriber -.. autocfunction:: zenoh_commons.h::z_declare_pull_subscriber -.. autocfunction:: zenoh_commons.h::z_subscriber_pull -.. autocfunction:: zenoh_commons.h::z_pull_subscriber_check -.. autocfunction:: zenoh_commons.h::z_undeclare_pull_subscriber - .. autocfunction:: zenoh_commons.h::z_closure_sample_call .. autocfunction:: zenoh_commons.h::z_closure_sample_drop diff --git a/examples/z_pull.c b/examples/z_pull.c index 0af23f7e2..581c6d490 100644 --- a/examples/z_pull.c +++ b/examples/z_pull.c @@ -11,73 +11,85 @@ // Contributors: // ZettaScale Zenoh Team, // +#include +#include #include -#include "zenoh.h" - -const char *kind_to_str(z_sample_kind_t kind); - -void data_handler(const z_sample_t *sample, void *arg) { - z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); - printf(">> [Subscriber] Received %s ('%s': '%.*s')\n", kind_to_str(sample->kind), z_loan(keystr), - (int)sample->payload.len, sample->payload.start); - z_drop(z_move(keystr)); -} +#include +#include +#include int main(int argc, char **argv) { - char *expr = "demo/example/**"; - if (argc > 1) { - expr = argv[1]; + const char *keyexpr = "demo/example/**"; + char *locator = NULL; + size_t interval = 5000; + size_t size = 3; + + int opt; + while ((opt = getopt(argc, argv, "k:e:i:s:")) != -1) { + switch (opt) { + case 'k': + keyexpr = optarg; + break; + case 'e': + locator = optarg; + break; + case 'i': + interval = (size_t)atoi(optarg); + break; + case 's': + size = (size_t)atoi(optarg); + break; + case '?': + if (optopt == 'k' || optopt == 'e' || optopt == 'i' || optopt == 's') { + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + } else { + fprintf(stderr, "Unknown option `-%c'.\n", optopt); + } + return 1; + default: + return -1; + } } z_owned_config_t config = z_config_default(); - if (argc > 2) { - if (zc_config_insert_json(z_loan(config), Z_CONFIG_LISTEN_KEY, argv[2]) < 0) { - printf( - "Couldn't insert value `%s` in configuration at `%s`. This is likely because `%s` expects a " - "JSON-serialized list of strings\n", - argv[2], Z_CONFIG_LISTEN_KEY, Z_CONFIG_LISTEN_KEY); - exit(-1); - } + if (locator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); } printf("Opening session...\n"); z_owned_session_t s = z_open(z_move(config)); if (!z_check(s)) { printf("Unable to open session!\n"); - exit(-1); + return -1; } - z_owned_closure_sample_t callback = z_closure(data_handler); - printf("Declaring Subscriber on '%s'...\n", expr); - z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(expr), z_move(callback), NULL); - if (!z_check(sub)) { - printf("Unable to declare subscriber.\n"); - exit(-1); - } + printf("Pull functionality not implemented!\n"); + // @TODO: implement z_owned_sample_channel_t and z_sample_channel_ring_new + // printf("Declaring Subscriber on '%s'...\n", keyexpr); + // z_owned_sample_channel_t channel = z_sample_channel_ring_new(size); + // z_owned_subscriber_t sub = z_declare_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(channel.send), NULL); + // if (!z_check(sub)) { + // printf("Unable to declare subscriber.\n"); + // return -1; + // } - printf("Press to pull data...\n"); - char c = 0; - while (c != 'q') { - c = getchar(); - if (c == -1) { - z_sleep_s(1); - } else { - z_subscriber_pull(z_loan(sub)); - } - } + // printf("Pulling data every %zu ms... Ring size: %zd\n", interval, size); + // z_owned_sample_t sample = z_sample_null(); + // while (true) { + // for (z_call(channel.recv, &sample); z_check(sample); z_call(channel.recv, &sample)) { + // z_owned_str_t keystr = z_keyexpr_to_string(z_loan(sample.keyexpr)); + // printf(">> [Subscriber] Pulled ('%s': '%.*s')\n", z_loan(keystr), (int)sample.payload.len, + // sample.payload.start); + // z_drop(z_move(keystr)); + // z_drop(z_move(sample)); + // } + // printf(">> [Subscriber] Nothing to pull... sleep for %zu ms\n", interval); + // zp_sleep_ms(interval); + // } + + // z_undeclare_subscriber(z_move(sub)); - z_undeclare_pull_subscriber(z_move(sub)); z_close(z_move(s)); + return 0; } - -const char *kind_to_str(z_sample_kind_t kind) { - switch (kind) { - case Z_SAMPLE_KIND_PUT: - return "PUT"; - case Z_SAMPLE_KIND_DELETE: - return "DELETE"; - default: - return "UNKNOWN"; - } -} \ No newline at end of file diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 84b125fbe..067170fd4 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -591,16 +591,6 @@ typedef struct z_publisher_options_t { enum z_congestion_control_t congestion_control; enum z_priority_t priority; } z_publisher_options_t; -/** - * Represents the set of options that can be applied to a pull subscriber, - * upon its declaration via :c:func:`z_declare_pull_subscriber`. - * - * Members: - * z_reliability_t reliability: The subscription reliability. - */ -typedef struct z_pull_subscriber_options_t { - enum z_reliability_t reliability; -} z_pull_subscriber_options_t; /** * Options passed to the :c:func:`z_declare_queryable` function. * @@ -611,7 +601,7 @@ typedef struct z_queryable_options_t { bool complete; } z_queryable_options_t; /** - * Options passed to the :c:func:`z_declare_subscriber` or :c:func:`z_declare_pull_subscriber` function. + * Options passed to the :c:func:`z_declare_subscriber` function. * * Members: * z_reliability_t reliability: The subscription reliability. @@ -736,9 +726,6 @@ typedef struct z_publisher_put_options_t { struct z_encoding_t encoding; struct z_attachment_t attachment; } z_publisher_put_options_t; -typedef struct z_pull_subscriber_t { - const struct z_owned_pull_subscriber_t *_0; -} z_pull_subscriber_t; /** * Options passed to the :c:func:`z_put` function. * @@ -1363,44 +1350,6 @@ ZENOHC_API struct z_owned_publisher_t z_declare_publisher(struct z_session_t session, struct z_keyexpr_t keyexpr, const struct z_publisher_options_t *options); -/** - * Declares a pull subscriber for a given key expression. - * - * Parameters: - * session: The zenoh session. - * keyexpr: The key expression to subscribe. - * callback: The callback function that will be called each time a data matching the subscribed expression is received. - * opts: additional options for the pull subscriber. - * - * Returns: - * A :c:type:`z_owned_subscriber_t`. - * - * To check if the subscription succeeded and if the pull subscriber is still valid, - * you may use `z_pull_subscriber_check(&val)` or `z_check(val)` if your compiler supports `_Generic`, which will return `true` if `val` is valid. - * - * 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 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. - * - * Example: - * Declaring a subscriber passing ``NULL`` for the options: - * - * .. code-block:: C - * - * z_owned_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(expr), callback, NULL); - * - * is equivalent to initializing and passing the default subscriber options: - * - * .. code-block:: C - * - * z_subscriber_options_t opts = z_subscriber_options_default(); - * z_owned_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(expr), callback, &opts); - */ -ZENOHC_API -struct z_owned_pull_subscriber_t z_declare_pull_subscriber(struct z_session_t session, - struct z_keyexpr_t keyexpr, - struct z_owned_closure_sample_t *callback, - const struct z_pull_subscriber_options_t *opts); /** * Creates a Queryable for the given key expression. * @@ -1778,23 +1727,6 @@ int8_t z_publisher_put(struct z_publisher_t publisher, * Constructs the default value for :c:type:`z_publisher_put_options_t`. */ ZENOHC_API struct z_publisher_put_options_t z_publisher_put_options_default(void); -/** - * Returns ``true`` if `sub` is valid. - */ -ZENOHC_API bool z_pull_subscriber_check(const struct z_owned_pull_subscriber_t *sub); -/** - * Returns ``true`` if `sub` is valid. - */ -ZENOHC_API -struct z_pull_subscriber_t z_pull_subscriber_loan(const struct z_owned_pull_subscriber_t *sub); -/** - * Constructs a null safe-to-drop value of 'z_owned_pull_subscriber_t' type - */ -ZENOHC_API struct z_owned_pull_subscriber_t z_pull_subscriber_null(void); -/** - * Constructs the default value for :c:type:`z_pull_subscriber_options_t`. - */ -ZENOHC_API struct z_pull_subscriber_options_t z_pull_subscriber_options_default(void); /** * Put data. * @@ -2128,14 +2060,6 @@ ZENOHC_API struct z_owned_subscriber_t z_subscriber_null(void); * Constructs the default value for :c:type:`z_subscriber_options_t`. */ ZENOHC_API struct z_subscriber_options_t z_subscriber_options_default(void); -/** - * Pull data for :c:type:`z_owned_pull_subscriber_t`. The pulled data will be provided - * by calling the **callback** function provided to the :c:func:`z_declare_subscriber` function. - * - * Parameters: - * sub: The :c:type:`z_owned_pull_subscriber_t` to pull from. - */ -ZENOHC_API int8_t z_subscriber_pull(struct z_pull_subscriber_t sub); ZENOHC_API int8_t z_task_init(struct z_task_t *task, const struct z_task_attr_t *_attr, @@ -2160,11 +2084,6 @@ ZENOHC_API int8_t z_undeclare_keyexpr(struct z_session_t session, struct z_owned */ ZENOHC_API int8_t z_undeclare_publisher(struct z_owned_publisher_t *publisher); -/** - * Undeclares the given :c:type:`z_owned_pull_subscriber_t`, droping it and invalidating it for double-drop safety. - */ -ZENOHC_API -int8_t z_undeclare_pull_subscriber(struct z_owned_pull_subscriber_t *sub); /** * Undeclares a `z_owned_queryable_t`, droping it and invalidating it for doube-drop safety. * diff --git a/include/zenoh_concrete.h b/include/zenoh_concrete.h index 44f208496..8572e956b 100644 --- a/include/zenoh_concrete.h +++ b/include/zenoh_concrete.h @@ -51,28 +51,6 @@ typedef struct z_query_t { typedef struct z_session_t { size_t _0; } z_session_t; -/** - * An owned zenoh pull subscriber. Destroying the subscriber cancels the subscription. - * - * Like most `z_owned_X_t` types, you may obtain an instance of `z_X_t` by loaning it using `z_X_loan(&val)`. - * The `z_loan(val)` macro, available if your compiler supports C11's `_Generic`, is equivalent to writing `z_X_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 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_X_check(&val)` or `z_check(val)` if your compiler supports `_Generic`, which will return `true` if `val` is valid. - */ -#if !defined(TARGET_ARCH_ARM) -typedef struct ALIGN(8) z_owned_pull_subscriber_t { - uint64_t _0[1]; -} z_owned_pull_subscriber_t; -#endif -#if defined(TARGET_ARCH_ARM) -typedef struct ALIGN(4) z_owned_pull_subscriber_t { - uint32_t _0[1]; -} z_owned_pull_subscriber_t; -#endif /** * An owned zenoh queryable. * diff --git a/include/zenoh_macros.h b/include/zenoh_macros.h index fa6668d48..57a691d7a 100644 --- a/include/zenoh_macros.h +++ b/include/zenoh_macros.h @@ -9,7 +9,6 @@ z_owned_config_t : z_config_loan, \ z_owned_publisher_t : z_publisher_loan, \ z_owned_subscriber_t : z_subscriber_loan, \ - z_owned_pull_subscriber_t : z_pull_subscriber_loan, \ z_owned_encoding_t : z_encoding_loan, \ z_owned_hello_t : z_hello_loan, \ z_owned_str_t : z_str_loan, \ @@ -23,7 +22,6 @@ z_owned_keyexpr_t * : z_keyexpr_drop, \ z_owned_config_t * : z_config_drop, \ z_owned_scouting_config_t * : z_scouting_config_drop, \ - z_owned_pull_subscriber_t * : z_undeclare_pull_subscriber, \ z_owned_subscriber_t * : z_undeclare_subscriber, \ z_owned_queryable_t * : z_undeclare_queryable, \ z_owned_encoding_t * : z_encoding_drop, \ @@ -56,7 +54,6 @@ z_owned_keyexpr_t * : z_keyexpr_null, \ z_owned_config_t * : z_config_null, \ z_owned_scouting_config_t * : z_scouting_config_null, \ - z_owned_pull_subscriber_t * : z_pull_subscriber_null, \ z_owned_subscriber_t * : z_subscriber_null, \ z_owned_queryable_t * : z_queryable_null, \ z_owned_encoding_t * : z_encoding_null, \ @@ -90,7 +87,6 @@ z_owned_scouting_config_t : z_scouting_config_check, \ z_bytes_t : z_bytes_check, \ z_owned_subscriber_t : z_subscriber_check, \ - z_owned_pull_subscriber_t : z_pull_subscriber_check, \ z_owned_queryable_t : z_queryable_check, \ z_owned_encoding_t : z_encoding_check, \ z_owned_reply_t : z_reply_check, \ @@ -137,7 +133,6 @@ template<> struct zenoh_loan_type{ typedef z_config_t type; }; template<> struct zenoh_loan_type{ typedef z_publisher_t type; }; template<> struct zenoh_loan_type{ typedef z_subscriber_t type; }; template<> struct zenoh_loan_type{ typedef z_query_t type; }; -template<> struct zenoh_loan_type{ typedef z_pull_subscriber_t type; }; template<> struct zenoh_loan_type{ typedef z_encoding_t type; }; template<> struct zenoh_loan_type{ typedef z_hello_t type; }; template<> struct zenoh_loan_type{ typedef const char* type; }; @@ -148,7 +143,6 @@ template<> inline z_keyexpr_t z_loan(const z_owned_keyexpr_t& x) { return z_keye template<> inline z_config_t z_loan(const z_owned_config_t& x) { return z_config_loan(&x); } template<> inline z_publisher_t z_loan(const z_owned_publisher_t& x) { return z_publisher_loan(&x); } template<> inline z_subscriber_t z_loan(const z_owned_subscriber_t& x) { return z_subscriber_loan(&x); } -template<> inline z_pull_subscriber_t z_loan(const z_owned_pull_subscriber_t& x) { return z_pull_subscriber_loan(&x); } template<> inline z_encoding_t z_loan(const z_owned_encoding_t& x) { return z_encoding_loan(&x); } template<> inline z_hello_t z_loan(const z_owned_hello_t& x) { return z_hello_loan(&x); } template<> inline z_query_t z_loan(const z_owned_query_t& x) { return z_query_loan(&x); } @@ -163,7 +157,6 @@ template<> struct zenoh_drop_type { typedef int8_t type; }; template<> struct zenoh_drop_type { typedef void type; }; template<> struct zenoh_drop_type { typedef void type; }; template<> struct zenoh_drop_type { typedef void type; }; -template<> struct zenoh_drop_type { typedef int8_t type; }; template<> struct zenoh_drop_type { typedef int8_t type; }; template<> struct zenoh_drop_type { typedef int8_t type; }; template<> struct zenoh_drop_type { typedef void type; }; @@ -192,7 +185,6 @@ template<> inline int8_t z_drop(z_owned_publisher_t* v) { return z_undeclare_pub template<> inline void z_drop(z_owned_keyexpr_t* v) { z_keyexpr_drop(v); } template<> inline void z_drop(z_owned_config_t* v) { z_config_drop(v); } template<> inline void z_drop(z_owned_scouting_config_t* v) { z_scouting_config_drop(v); } -template<> inline int8_t z_drop(z_owned_pull_subscriber_t* v) { return z_undeclare_pull_subscriber(v); } template<> inline int8_t z_drop(z_owned_subscriber_t* v) { return z_undeclare_subscriber(v); } template<> inline int8_t z_drop(z_owned_queryable_t* v) { return z_undeclare_queryable(v); } template<> inline void z_drop(z_owned_encoding_t* v) { z_encoding_drop(v); } @@ -221,7 +213,6 @@ inline void z_null(z_owned_publisher_t& v) { v = z_publisher_null(); } inline void z_null(z_owned_keyexpr_t& v) { v = z_keyexpr_null(); } inline void z_null(z_owned_config_t& v) { v = z_config_null(); } inline void z_null(z_owned_scouting_config_t& v) { v = z_scouting_config_null(); } -inline void z_null(z_owned_pull_subscriber_t& v) { v = z_pull_subscriber_null(); } inline void z_null(z_owned_subscriber_t& v) { v = z_subscriber_null(); } inline void z_null(z_owned_queryable_t& v) { v = z_queryable_null(); } inline void z_null(z_owned_encoding_t& v) { v = z_encoding_null(); } @@ -256,7 +247,6 @@ inline bool z_check(const zc_owned_payload_t& v) { return zc_payload_check(&v); inline bool z_check(const zc_owned_shmbuf_t& v) { return zc_shmbuf_check(&v); } inline bool z_check(const zc_owned_shm_manager_t& v) { return zc_shm_manager_check(&v); } inline bool z_check(const z_owned_subscriber_t& v) { return z_subscriber_check(&v); } -inline bool z_check(const z_owned_pull_subscriber_t& v) { return z_pull_subscriber_check(&v); } inline bool z_check(const z_owned_queryable_t& v) { return z_queryable_check(&v); } inline bool z_check(const z_owned_encoding_t& v) { return z_encoding_check(&v); } inline bool z_check(const z_owned_reply_t& v) { return z_reply_check(&v); } diff --git a/splitguide.yaml b/splitguide.yaml index 4cb19de82..5469f25de 100644 --- a/splitguide.yaml +++ b/splitguide.yaml @@ -9,6 +9,5 @@ zenoh_concrete.h: - z_owned_session_t! - z_session_t! - z_owned_subscriber_t! - - z_owned_pull_subscriber_t! - z_query_t! - z_owned_queryable_t! diff --git a/src/lib.rs b/src/lib.rs index de6584885..02c392611 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,8 +39,6 @@ mod session; pub use crate::session::*; mod subscriber; pub use crate::subscriber::*; -mod pull_subscriber; -pub use crate::pull_subscriber::*; mod publisher; pub use crate::publisher::*; mod closures; diff --git a/src/liveliness.rs b/src/liveliness.rs index 0a7c689dd..c9d48c92d 100644 --- a/src/liveliness.rs +++ b/src/liveliness.rs @@ -173,7 +173,7 @@ pub extern "C" fn zc_liveliness_declare_subscriber( return z_owned_subscriber_t::null(); }; let callback = core::mem::replace(callback, z_owned_closure_sample_t::empty()); - match session + let res = session .liveliness() .declare_subscriber(key) .callback(move |sample| { @@ -185,8 +185,8 @@ pub extern "C" fn zc_liveliness_declare_subscriber( let sample = z_sample_t::new(&sample, &owner); z_closure_sample_call(&callback, &sample) }) - .res() - { + .res(); + match res { Ok(token) => z_owned_subscriber_t::new(token), Err(e) => { log::error!("Failed to subscribe to liveliness: {e}"); diff --git a/src/pull_subscriber.rs b/src/pull_subscriber.rs deleted file mode 100644 index 931b48d84..000000000 --- a/src/pull_subscriber.rs +++ /dev/null @@ -1,239 +0,0 @@ -use crate::GuardedTransmute; -// -// Copyright (c) 2017, 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, -// - -use crate::commons::*; -use crate::impl_guarded_transmute; -use crate::keyexpr::*; -use crate::session::*; -use crate::z_closure_sample_call; -use crate::z_owned_closure_sample_t; -use crate::z_reliability_t; -use crate::LOG_INVALID_SESSION; -use zenoh::prelude::sync::SyncResolve; -use zenoh::prelude::SessionDeclarations; -use zenoh::prelude::SplitBuffer; -use zenoh_protocol::core::SubInfo; -use zenoh_util::core::zresult::ErrNo; - -/**************************************/ -/* DECLARATION */ -/**************************************/ -type PullSubscriber = Option>>; - -/// An owned zenoh pull subscriber. Destroying the subscriber cancels the subscription. -/// -/// Like most `z_owned_X_t` types, you may obtain an instance of `z_X_t` by loaning it using `z_X_loan(&val)`. -/// The `z_loan(val)` macro, available if your compiler supports C11's `_Generic`, is equivalent to writing `z_X_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 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_X_check(&val)` or `z_check(val)` if your compiler supports `_Generic`, which will return `true` if `val` is valid. -#[cfg(not(target_arch = "arm"))] -#[repr(C, align(8))] -pub struct z_owned_pull_subscriber_t([u64; 1]); - -#[cfg(target_arch = "arm")] -#[repr(C, align(4))] -pub struct z_owned_pull_subscriber_t([u32; 1]); - -impl_guarded_transmute!(PullSubscriber, z_owned_pull_subscriber_t); - -#[repr(C)] -#[allow(non_camel_case_types)] -pub struct z_pull_subscriber_t<'a>(&'a z_owned_pull_subscriber_t); - -impl From for z_owned_pull_subscriber_t { - fn from(val: PullSubscriber) -> Self { - val.transmute() - } -} - -impl AsRef for z_owned_pull_subscriber_t { - fn as_ref(&self) -> &PullSubscriber { - unsafe { std::mem::transmute(self) } - } -} - -impl<'a> AsRef for z_pull_subscriber_t<'a> { - fn as_ref(&self) -> &PullSubscriber { - self.0.as_ref() - } -} - -impl AsMut for z_owned_pull_subscriber_t { - fn as_mut(&mut self) -> &mut PullSubscriber { - unsafe { std::mem::transmute(self) } - } -} - -impl z_owned_pull_subscriber_t { - pub fn new(sub: zenoh::subscriber::PullSubscriber<'static, ()>) -> Self { - Some(Box::new(sub)).into() - } - pub fn null() -> Self { - None.into() - } -} - -/// Constructs a null safe-to-drop value of 'z_owned_pull_subscriber_t' type -#[no_mangle] -#[allow(clippy::missing_safety_doc)] -pub extern "C" fn z_pull_subscriber_null() -> z_owned_pull_subscriber_t { - z_owned_pull_subscriber_t::null() -} - -/// Represents the set of options that can be applied to a pull subscriber, -/// upon its declaration via :c:func:`z_declare_pull_subscriber`. -/// -/// Members: -/// z_reliability_t reliability: The subscription reliability. -#[repr(C)] -#[allow(non_camel_case_types)] -pub struct z_pull_subscriber_options_t { - reliability: z_reliability_t, -} - -/// Constructs the default value for :c:type:`z_pull_subscriber_options_t`. -#[no_mangle] -pub extern "C" fn z_pull_subscriber_options_default() -> z_pull_subscriber_options_t { - let info = SubInfo::default(); - z_pull_subscriber_options_t { - reliability: info.reliability.into(), - } -} - -/// Declares a pull subscriber for a given key expression. -/// -/// Parameters: -/// session: The zenoh session. -/// keyexpr: The key expression to subscribe. -/// callback: The callback function that will be called each time a data matching the subscribed expression is received. -/// opts: additional options for the pull subscriber. -/// -/// Returns: -/// A :c:type:`z_owned_subscriber_t`. -/// -/// To check if the subscription succeeded and if the pull subscriber is still valid, -/// you may use `z_pull_subscriber_check(&val)` or `z_check(val)` if your compiler supports `_Generic`, which will return `true` if `val` is valid. -/// -/// 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 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. -/// -/// Example: -/// Declaring a subscriber passing ``NULL`` for the options: -/// -/// .. code-block:: C -/// -/// z_owned_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(expr), callback, NULL); -/// -/// is equivalent to initializing and passing the default subscriber options: -/// -/// .. code-block:: C -/// -/// z_subscriber_options_t opts = z_subscriber_options_default(); -/// z_owned_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(expr), callback, &opts); -#[no_mangle] -#[allow(clippy::missing_safety_doc)] -pub extern "C" fn z_declare_pull_subscriber( - session: z_session_t, - keyexpr: z_keyexpr_t, - callback: &mut z_owned_closure_sample_t, - opts: Option<&z_pull_subscriber_options_t>, -) -> z_owned_pull_subscriber_t { - let mut closure = z_owned_closure_sample_t::empty(); - std::mem::swap(callback, &mut closure); - - match session.upgrade() { - Some(s) => { - let mut res = s - .declare_subscriber(keyexpr) - .callback(move |sample| { - let payload = sample.payload.contiguous(); - let owner = match payload { - std::borrow::Cow::Owned(v) => zenoh::buffers::ZBuf::from(v), - _ => sample.payload.clone(), - }; - let sample = z_sample_t::new(&sample, &owner); - z_closure_sample_call(&closure, &sample) - }) - .pull_mode(); - if let Some(opts) = opts { - res = res.reliability(opts.reliability.into()) - } - match res.res() { - Ok(sub) => z_owned_pull_subscriber_t::new(sub), - Err(e) => { - log::debug!("{}", e); - z_owned_pull_subscriber_t::null() - } - } - } - None => { - log::debug!("{}", LOG_INVALID_SESSION); - z_owned_pull_subscriber_t::null() - } - } -} - -/// Undeclares the given :c:type:`z_owned_pull_subscriber_t`, droping it and invalidating it for double-drop safety. -#[allow(clippy::missing_safety_doc)] -#[no_mangle] -pub extern "C" fn z_undeclare_pull_subscriber(sub: &mut z_owned_pull_subscriber_t) -> i8 { - if let Some(s) = sub.as_mut().take() { - if let Err(e) = s.undeclare().res_sync() { - log::warn!("{}", e); - return e.errno().get(); - } - } - 0 -} - -/// Returns ``true`` if `sub` is valid. -#[allow(clippy::missing_safety_doc)] -#[no_mangle] -pub extern "C" fn z_pull_subscriber_check(sub: &z_owned_pull_subscriber_t) -> bool { - sub.as_ref().is_some() -} - -/// Returns ``true`` if `sub` is valid. -#[allow(clippy::missing_safety_doc)] -#[no_mangle] -pub extern "C" fn z_pull_subscriber_loan(sub: &z_owned_pull_subscriber_t) -> z_pull_subscriber_t { - z_pull_subscriber_t(sub) -} - -/// Pull data for :c:type:`z_owned_pull_subscriber_t`. The pulled data will be provided -/// by calling the **callback** function provided to the :c:func:`z_declare_subscriber` function. -/// -/// Parameters: -/// sub: The :c:type:`z_owned_pull_subscriber_t` to pull from. -#[allow(clippy::missing_safety_doc)] -#[no_mangle] -pub extern "C" fn z_subscriber_pull(sub: z_pull_subscriber_t) -> i8 { - match sub.0.as_ref() { - Some(tx) => { - if let Err(e) = tx.pull().res_sync() { - log::error!("{}", e); - e.errno().get() - } else { - 0 - } - } - None => i8::MIN, - } -} diff --git a/src/querying_subscriber.rs b/src/querying_subscriber.rs index d407f9646..d46792bca 100644 --- a/src/querying_subscriber.rs +++ b/src/querying_subscriber.rs @@ -202,7 +202,7 @@ pub unsafe extern "C" fn ze_declare_querying_subscriber( .query_timeout(std::time::Duration::from_millis(options.query_timeout_ms)); } } - match sub + let res = sub .callback(move |sample| { let payload = sample.payload.contiguous(); let owner = match payload { @@ -212,8 +212,8 @@ pub unsafe extern "C" fn ze_declare_querying_subscriber( let sample = z_sample_t::new(&sample, &owner); z_closure_sample_call(&closure, &sample) }) - .res() - { + .res(); + match res { Ok(sub) => ze_owned_querying_subscriber_t::new(sub, session), Err(e) => { log::debug!("{}", e); diff --git a/src/subscriber.rs b/src/subscriber.rs index 910ec424b..18a0dceb6 100644 --- a/src/subscriber.rs +++ b/src/subscriber.rs @@ -135,7 +135,7 @@ pub extern "C" fn z_subscriber_loan(p: &z_owned_subscriber_t) -> z_subscriber_t z_subscriber_t(p) } -/// Options passed to the :c:func:`z_declare_subscriber` or :c:func:`z_declare_pull_subscriber` function. +/// Options passed to the :c:func:`z_declare_subscriber` function. /// /// Members: /// z_reliability_t reliability: The subscription reliability. diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 43ce08cc3..672c79f70 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -13,40 +13,61 @@ #include #include +#include #include #undef NDEBUG #include + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) +#include +#define sleep(x) Sleep(x * 1000) +#else +#include +#endif + #include "zenoh.h" -#define SLEEP 1 -#define URI "demo/example/**/*" +#define SLEEP 2 #define SCOUTING_TIMEOUT "1000" -char *value = "Test value"; +#define assert_eq(x, y) \ + { \ + int l = (int)x; \ + int r = (int)y; \ + if (l != r) { \ + printf("assert_eq failed: l=%d, r=%d\n", l, r); \ + assert(false); \ + } \ + } + +const char *value = "Test value"; volatile unsigned int zids = 0; void zid_handler(const z_id_t *id, void *arg) { (void)(arg); (void)(id); + printf("%s\n", __func__); zids++; } volatile unsigned int hellos = 0; void hello_handler(z_owned_hello_t *hello, void *arg) { (void)(arg); - (void)(hello); + printf("%s\n", __func__); hellos++; z_hello_null(); + z_drop(hello); // validate double-drop safety: caller drops hello if it's not dropped by the handler } volatile unsigned int queries = 0; void query_handler(const z_query_t *query, void *arg) { + printf("%s\n", __func__); queries++; z_owned_str_t k_str = z_keyexpr_to_string(z_query_keyexpr(query)); #ifdef ZENOH_PICO - if (k_str == NULL) { + if (z_check(k_str) == false) { k_str = zp_keyexpr_resolve(*(z_session_t *)arg, z_query_keyexpr(query)); } #endif @@ -63,6 +84,7 @@ void query_handler(const z_query_t *query, void *arg) { volatile unsigned int replies = 0; void reply_handler(z_owned_reply_t *reply, void *arg) { + printf("%s\n", __func__); replies++; if (z_reply_is_ok(reply)) { @@ -70,7 +92,7 @@ void reply_handler(z_owned_reply_t *reply, void *arg) { z_owned_str_t k_str = z_keyexpr_to_string(sample.keyexpr); #ifdef ZENOH_PICO - if (k_str == NULL) { + if (z_check(k_str) == false) { k_str = zp_keyexpr_resolve(*(z_session_t *)arg, sample.keyexpr); } #endif @@ -81,15 +103,17 @@ void reply_handler(z_owned_reply_t *reply, void *arg) { } z_reply_null(); // Does nothing. Just to test compilation + z_drop(reply); // validate double-drop safety: caller drops reply if it's not dropped by the handler } volatile unsigned int datas = 0; void data_handler(const z_sample_t *sample, void *arg) { + printf("%s\n", __func__); datas++; z_owned_str_t k_str = z_keyexpr_to_string(sample->keyexpr); #ifdef ZENOH_PICO - if (k_str == NULL) { + if (z_check(k_str) == false) { k_str = zp_keyexpr_resolve(*(z_session_t *)arg, sample->keyexpr); } #endif @@ -97,43 +121,45 @@ void data_handler(const z_sample_t *sample, void *arg) { } int main(int argc, char **argv) { - setbuf(stdout, NULL); + assert_eq(argc, 2); + (void)(argc); + setvbuf(stdout, NULL, _IOLBF, 1024); #ifdef ZENOH_C zc_init_logger(); #endif + printf("Testing Keyexpr..."); z_keyexpr_t key = z_keyexpr("demo/example"); _Bool _ret_bool = z_keyexpr_is_initialized(&key); - assert(_ret_bool == true); + assert_eq(_ret_bool, true); - int8_t _ret_int; - _ret_int = z_keyexpr_includes(z_keyexpr("demo/example/**"), z_keyexpr("demo/example/a")); - assert(_ret_int == 0); + int8_t _ret_int8 = z_keyexpr_includes(z_keyexpr("demo/example/**"), z_keyexpr("demo/example/a")); + assert_eq(_ret_int8, 0); #ifdef ZENOH_PICO - _ret_bool = zp_keyexpr_includes_null_terminated("demo/example/**", "demo/example/a"); - assert(_ret_int == 0); + _ret_int8 = zp_keyexpr_includes_null_terminated("demo/example/**", "demo/example/a"); + assert_eq(_ret_int8, 0); #endif - _ret_int = z_keyexpr_intersects(z_keyexpr("demo/example/**"), z_keyexpr("demo/example/a")); - assert(_ret_int == 0); + _ret_int8 = z_keyexpr_intersects(z_keyexpr("demo/example/**"), z_keyexpr("demo/example/a")); + assert_eq(_ret_int8, 0); #ifdef ZENOH_PICO - _ret_bool = zp_keyexpr_intersect_null_terminated("demo/example/**", "demo/example/a"); - assert(_ret_int == 0); + _ret_int8 = zp_keyexpr_intersect_null_terminated("demo/example/**", "demo/example/a"); + assert_eq(_ret_int8, 0); #endif - _ret_int = z_keyexpr_equals(z_keyexpr("demo/example/**"), z_keyexpr("demo/example")); - assert(_ret_int == -1); + _ret_int8 = z_keyexpr_equals(z_keyexpr("demo/example/**"), z_keyexpr("demo/example")); + assert_eq(_ret_int8, -1); #ifdef ZENOH_PICO - _ret_bool = zp_keyexpr_equals_null_terminated("demo/example/**", "demo/example"); - assert(_ret_int == -1); + _ret_int8 = zp_keyexpr_equals_null_terminated("demo/example/**", "demo/example"); + assert_eq(_ret_int8, -1); #endif - z_sleep_s(SLEEP); + sleep(SLEEP); - size_t keyexpr_len = strlen(URI); - char *keyexpr_str = (char *)z_malloc(keyexpr_len + 1); - memcpy(keyexpr_str, URI, keyexpr_len); + size_t keyexpr_len = strlen("demo/example/**/*"); + char *keyexpr_str = (char *)malloc(keyexpr_len + 1); + memcpy(keyexpr_str, "demo/example/**/*", keyexpr_len); keyexpr_str[keyexpr_len] = '\0'; - int8_t _ret_int8 = z_keyexpr_is_canon(keyexpr_str, keyexpr_len); + _ret_int8 = z_keyexpr_is_canon(keyexpr_str, keyexpr_len); assert(_ret_int8 < 0); #ifdef ZENOH_PICO @@ -141,27 +167,29 @@ int main(int argc, char **argv) { assert(_ret_int8 < 0); #endif _ret_int8 = z_keyexpr_canonize(keyexpr_str, &keyexpr_len); - assert(_ret_int8 == 0); - assert(strlen(URI) == keyexpr_len); + assert_eq(_ret_int8, 0); + assert_eq(strlen("demo/example/**/*"), keyexpr_len); #ifdef ZENOH_PICO _ret_int8 = zp_keyexpr_canonize_null_terminated(keyexpr_str); - assert(_ret_int8 == 0); - assert(strlen(URI) == keyexpr_len); + assert_eq(_ret_int8, 0); + assert_eq(strlen("demo/example/**/*"), keyexpr_len); #endif - z_sleep_s(SLEEP); + printf("Ok\n"); + sleep(SLEEP); + printf("Testing Configs..."); z_owned_config_t _ret_config = z_config_new(); assert(z_check(_ret_config)); z_drop(z_move(_ret_config)); _ret_config = z_config_default(); assert(z_check(_ret_config)); #ifdef ZENOH_PICO - _ret_int8 = zp_config_insert(z_loan(_ret_config), Z_CONFIG_PEER_KEY, z_string_make(argv[1])); - assert(_ret_int8 == 0); - const char *_ret_cstr = zp_config_get(z_loan(_ret_config), Z_CONFIG_PEER_KEY); - assert(strlen(_ret_cstr) == strlen(argv[1])); - assert(strncmp(_ret_cstr, argv[1], strlen(_ret_cstr)) == 0); + _ret_int8 = zp_config_insert(z_loan(_ret_config), Z_CONFIG_CONNECT_KEY, z_string_make(argv[1])); + assert_eq(_ret_int8, 0); + const char *_ret_cstr = zp_config_get(z_loan(_ret_config), Z_CONFIG_CONNECT_KEY); + assert_eq(strlen(_ret_cstr), strlen(argv[1])); + assert_eq(strncmp(_ret_cstr, argv[1], strlen(_ret_cstr)), 0); #endif z_owned_scouting_config_t _ret_sconfig = z_scouting_config_default(); @@ -169,23 +197,27 @@ int main(int argc, char **argv) { #ifdef ZENOH_PICO _ret_int8 = zp_scouting_config_insert(z_loan(_ret_sconfig), Z_CONFIG_SCOUTING_TIMEOUT_KEY, z_string_make(SCOUTING_TIMEOUT)); - assert(_ret_int8 == 0); + assert_eq(_ret_int8, 0); _ret_cstr = zp_scouting_config_get(z_loan(_ret_sconfig), Z_CONFIG_SCOUTING_TIMEOUT_KEY); - assert(strlen(_ret_cstr) == strlen(SCOUTING_TIMEOUT)); - assert(strncmp(_ret_cstr, SCOUTING_TIMEOUT, strlen(_ret_cstr)) == 0); + assert_eq(strlen(_ret_cstr), strlen(SCOUTING_TIMEOUT)); + assert_eq(strncmp(_ret_cstr, SCOUTING_TIMEOUT, strlen(_ret_cstr)), 0); #endif z_drop(z_move(_ret_sconfig)); - z_sleep_s(SLEEP); + printf("Ok\n"); + sleep(SLEEP); + printf("Testing Scouting..."); _ret_sconfig = z_scouting_config_from(z_loan(_ret_config)); z_owned_closure_hello_t _ret_closure_hello = z_closure(hello_handler, NULL, NULL); _ret_int8 = z_scout(z_move(_ret_sconfig), z_move(_ret_closure_hello)); - assert(_ret_int8 == 0); - assert(hellos == 1); + assert_eq(_ret_int8, 0); + assert(hellos >= 1); - z_sleep_s(atoi(SCOUTING_TIMEOUT) / 1000); - z_sleep_s(SLEEP); + uint32_t _scouting_timeout = strtoul(SCOUTING_TIMEOUT, NULL, 10); + zp_sleep_ms(_scouting_timeout); + printf("Ok\n"); + zp_sleep_s(SLEEP); z_owned_session_t s1 = z_open(z_move(_ret_config)); assert(z_check(s1)); @@ -198,15 +230,15 @@ int main(int argc, char **argv) { z_owned_closure_zid_t _ret_closure_zid = z_closure(zid_handler, NULL, NULL); _ret_int8 = z_info_peers_zid(z_loan(s1), z_move(_ret_closure_zid)); - assert(_ret_int8 == 0); - z_sleep_s(SLEEP); - assert(zids == 0); + assert_eq(_ret_int8, 0); + sleep(SLEEP); + assert_eq(zids, 0); _ret_int8 = z_info_routers_zid(z_loan(s1), z_move(_ret_closure_zid)); - assert(_ret_int8 == 0); + assert_eq(_ret_int8, 0); - z_sleep_s(SLEEP); - assert(zids == 1); + sleep(SLEEP); + assert_eq(zids, 1); #ifdef ZENOH_PICO zp_task_read_options_t _ret_read_opt = zp_task_read_options_default(); @@ -215,15 +247,15 @@ int main(int argc, char **argv) { zp_start_lease_task(z_loan(s1), &_ret_lease_opt); #endif - z_sleep_s(SLEEP); + sleep(SLEEP); _ret_config = z_config_default(); #ifdef ZENOH_PICO - _ret_int8 = zp_config_insert(z_loan(_ret_config), Z_CONFIG_PEER_KEY, z_string_make(argv[1])); - assert(_ret_int8 == 0); - _ret_cstr = zp_config_get(z_loan(_ret_config), Z_CONFIG_PEER_KEY); - assert(strlen(_ret_cstr) == strlen(argv[1])); - assert(strncmp(_ret_cstr, argv[1], strlen(_ret_cstr)) == 0); + _ret_int8 = zp_config_insert(z_loan(_ret_config), Z_CONFIG_CONNECT_KEY, z_string_make(argv[1])); + assert_eq(_ret_int8, 0); + _ret_cstr = zp_config_get(z_loan(_ret_config), Z_CONFIG_CONNECT_KEY); + assert_eq(strlen(_ret_cstr), strlen(argv[1])); + assert_eq(strncmp(_ret_cstr, argv[1], strlen(_ret_cstr)), 0); #endif z_owned_session_t s2 = z_open(z_move(_ret_config)); @@ -240,133 +272,162 @@ int main(int argc, char **argv) { zp_start_lease_task(z_loan(s2), NULL); #endif - z_sleep_s(SLEEP); + sleep(SLEEP); z_session_t ls1 = z_loan(s1); + printf("Declaring Subscriber..."); z_owned_closure_sample_t _ret_closure_sample = z_closure(data_handler, NULL, &ls1); z_subscriber_options_t _ret_sub_opt = z_subscriber_options_default(); z_owned_subscriber_t _ret_sub = z_declare_subscriber(z_loan(s2), z_keyexpr(keyexpr_str), z_move(_ret_closure_sample), &_ret_sub_opt); assert(z_check(_ret_sub)); + printf("Ok\n"); - z_sleep_s(SLEEP); + sleep(SLEEP); - char s1_res[64]; - sprintf(s1_res, "%s/chunk/%d", keyexpr_str, 1); + printf("Declaring Keyexpr..."); + char *s1_res = (char *)malloc(64); + snprintf(s1_res, 64, "%s/chunk/%d", keyexpr_str, 1); z_owned_keyexpr_t _ret_expr = z_declare_keyexpr(z_loan(s1), z_keyexpr(s1_res)); assert(z_check(_ret_expr)); + printf("Ok\n"); + + printf("Session Put..."); z_put_options_t _ret_put_opt = z_put_options_default(); _ret_put_opt.congestion_control = Z_CONGESTION_CONTROL_BLOCK; z_encoding_t _ret_encoding = z_encoding_default(); + (void)(_ret_encoding); _ret_encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); _ret_put_opt.encoding = _ret_encoding; _ret_int8 = z_put(z_loan(s1), z_loan(_ret_expr), (const uint8_t *)value, strlen(value), &_ret_put_opt); - assert(_ret_int8 == 0); + assert_eq(_ret_int8, 0); + printf("Ok\n"); - z_sleep_s(SLEEP); - assert(datas == 1); + sleep(SLEEP); + assert_eq(datas, 1); + printf("Session delete..."); z_delete_options_t _ret_delete_opt = z_delete_options_default(); + _ret_delete_opt.congestion_control = Z_CONGESTION_CONTROL_BLOCK; _ret_int8 = z_delete(z_loan(s1), z_loan(_ret_expr), &_ret_delete_opt); - assert(_ret_int8 == 0); + assert_eq(_ret_int8, 0); + printf("Ok\n"); - z_sleep_s(SLEEP); - assert(datas == 2); + sleep(SLEEP); + assert_eq(datas, 2); + printf("Undeclaring Keyexpr..."); _ret_int8 = z_undeclare_keyexpr(z_loan(s1), z_move(_ret_expr)); - assert(_ret_int8 == 0); + printf(" %02x\n", _ret_int8); + assert_eq(_ret_int8, 0); assert(!z_check(_ret_expr)); + printf("Ok\n"); - _ret_int8 = z_undeclare_subscriber(z_move(_ret_sub)); - assert(_ret_int8 == 0); - - z_owned_closure_sample_t _ret_closure_sample2 = z_closure(data_handler, NULL, &ls1); - z_pull_subscriber_options_t _ret_psub_opt = z_pull_subscriber_options_default(); - z_owned_pull_subscriber_t _ret_psub = - z_declare_pull_subscriber(z_loan(s2), z_keyexpr(keyexpr_str), z_move(_ret_closure_sample2), &_ret_psub_opt); - assert(z_check(_ret_psub)); - + printf("Declaring Publisher..."); z_publisher_options_t _ret_pub_opt = z_publisher_options_default(); _ret_pub_opt.congestion_control = Z_CONGESTION_CONTROL_BLOCK; z_owned_publisher_t _ret_pub = z_declare_publisher(z_loan(s1), z_keyexpr(keyexpr_str), &_ret_pub_opt); assert(z_check(_ret_pub)); + printf("Ok\n"); + sleep(SLEEP); + + printf("Publisher Put..."); z_publisher_put_options_t _ret_pput_opt = z_publisher_put_options_default(); _ret_int8 = z_publisher_put(z_loan(_ret_pub), (const uint8_t *)value, strlen(value), &_ret_pput_opt); - assert(_ret_int8 == 0); - - z_sleep_s(SLEEP); + assert_eq(_ret_int8, 0); + printf("Ok\n"); - _ret_int8 = z_subscriber_pull(z_loan(_ret_psub)); - assert(_ret_int8 == 0); - - z_sleep_s(SLEEP); - assert(datas == 3); + sleep(SLEEP); + assert_eq(datas, 3); + printf("Publisher Delete..."); z_publisher_delete_options_t _ret_pdelete_opt = z_publisher_delete_options_default(); _ret_int8 = z_publisher_delete(z_loan(_ret_pub), &_ret_pdelete_opt); + assert_eq(_ret_int8, 0); + printf("Ok\n"); - z_sleep_s(SLEEP); - - _ret_int8 = z_subscriber_pull(z_loan(_ret_psub)); - assert(_ret_int8 == 0); - - z_sleep_s(SLEEP); - assert(datas == 4); + sleep(SLEEP); + assert_eq(datas, 4); + printf("Undeclaring Publisher..."); _ret_int8 = z_undeclare_publisher(z_move(_ret_pub)); + assert_eq(_ret_int8, 0); assert(!z_check(_ret_pub)); + printf("Ok\n"); + + sleep(SLEEP); - _ret_int8 = z_undeclare_pull_subscriber(z_move(_ret_psub)); - assert(_ret_int8 == 0); + printf("Undeclaring Subscriber..."); + _ret_int8 = z_undeclare_subscriber(z_move(_ret_sub)); + assert_eq(_ret_int8, 0); + assert(!z_check(_ret_sub)); + printf("Ok\n"); - z_sleep_s(SLEEP); + sleep(SLEEP); + printf("Declaring Queryable..."); z_owned_closure_query_t _ret_closure_query = z_closure(query_handler, NULL, &ls1); z_queryable_options_t _ret_qle_opt = z_queryable_options_default(); z_owned_queryable_t qle = z_declare_queryable(z_loan(s1), z_keyexpr(s1_res), z_move(_ret_closure_query), &_ret_qle_opt); assert(z_check(qle)); + printf("Ok\n"); - z_sleep_s(SLEEP); + sleep(SLEEP); + printf("Testing Consolidations..."); z_session_t ls2 = z_loan(s2); z_owned_closure_reply_t _ret_closure_reply = z_closure(reply_handler, NULL, &ls2); z_get_options_t _ret_get_opt = z_get_options_default(); _ret_get_opt.target = z_query_target_default(); _ret_get_opt.consolidation = z_query_consolidation_auto(); + (void)(_ret_get_opt.consolidation); _ret_get_opt.consolidation = z_query_consolidation_default(); + (void)(_ret_get_opt.consolidation); _ret_get_opt.consolidation = z_query_consolidation_latest(); + (void)(_ret_get_opt.consolidation); _ret_get_opt.consolidation = z_query_consolidation_monotonic(); + (void)(_ret_get_opt.consolidation); _ret_get_opt.consolidation = z_query_consolidation_none(); + (void)(_ret_get_opt.consolidation); + printf("Ok\n"); + + printf("Testing Get..."); _ret_int8 = z_get(z_loan(s2), z_keyexpr(s1_res), "", z_move(_ret_closure_reply), &_ret_get_opt); - assert(_ret_int8 == 0); + assert_eq(_ret_int8, 0); + printf("Ok\n"); - z_sleep_s(SLEEP); - assert(queries == 1); - assert(replies == 1); + sleep(SLEEP); + assert_eq(queries, 1); + assert_eq(replies, 1); + printf("Undeclaring Queryable..."); _ret_int8 = z_undeclare_queryable(z_move(qle)); - assert(_ret_int8 == 0); + assert_eq(_ret_int8, 0); + printf("Ok\n"); #ifdef ZENOH_PICO zp_stop_read_task(z_loan(s1)); zp_stop_lease_task(z_loan(s1)); #endif + printf("Close sessions..."); _ret_int8 = z_close(z_move(s1)); - assert(_ret_int8 == 0); + assert_eq(_ret_int8, 0); #ifdef ZENOH_PICO zp_stop_read_task(z_loan(s2)); zp_stop_lease_task(z_loan(s2)); #endif _ret_int8 = z_close(z_move(s2)); - assert(_ret_int8 == 0); + assert_eq(_ret_int8, 0); + printf("Ok\n"); - z_sleep_s(SLEEP * 5); + sleep(SLEEP * 5); - z_free(keyexpr_str); + free(s1_res); + free(keyexpr_str); return 0; } diff --git a/tests/z_api_double_drop_test.c b/tests/z_api_double_drop_test.c index 3fd158f12..604ad2e26 100644 --- a/tests/z_api_double_drop_test.c +++ b/tests/z_api_double_drop_test.c @@ -73,19 +73,6 @@ void test_scouting_config() { void data_handler(const z_sample_t *sample, void *arg) {} -void test_pull_subscriber() { - z_owned_config_t config = z_config_default(); - z_owned_session_t s = z_open(z_move(config)); - z_owned_closure_sample_t callback = z_closure(data_handler); - z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(URL), z_move(callback), NULL); - assert(z_check(sub)); - z_drop(z_move(sub)); - assert(!z_check(sub)); - z_drop(z_move(sub)); - assert(!z_check(sub)); - z_drop(z_move(s)); -} - void test_subscriber() { z_owned_config_t config = z_config_default(); z_owned_session_t s = z_open(z_move(config)); @@ -120,7 +107,6 @@ int main(int argc, char **argv) { test_keyexpr(); test_config(); test_scouting_config(); - test_pull_subscriber(); test_subscriber(); test_queryable(); diff --git a/tests/z_api_keyexpr_drop_test.c b/tests/z_api_keyexpr_drop_test.c index ac81be4cd..cea0594b6 100644 --- a/tests/z_api_keyexpr_drop_test.c +++ b/tests/z_api_keyexpr_drop_test.c @@ -38,18 +38,6 @@ void test_publisher() { void data_handler(const z_sample_t *sample, void *arg) {} -// void test_pull_subscriber() { -// z_owned_config_t config = z_config_default(); -// z_owned_session_t s = z_open(z_move(config)); -// z_owned_closure_sample_t callback = z_closure(data_handler); -// char keyexpr[256]; -// strncpy(keyexpr, "foo/bar", 256); -// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL); -// strncpy(keyexpr, "baz/quax", 256); -// z_drop(z_move(sub)); -// z_drop(z_move(s)); -// } - void test_subscriber() { z_owned_config_t config = z_config_default(); z_owned_session_t s = z_open(z_move(config)); @@ -83,8 +71,7 @@ void test_subscriber() { int main(int argc, char **argv) { test_publisher(); test_subscriber(); - // TODO: Make same tests for pull subscriber and queryable when their `keyexpr` getters are implemented - // test_pull_subscriber(); + // TODO: Make same tests for queryable when its `keyexpr` getters is implemented // test_queryable(); return 0; diff --git a/tests/z_api_null_drop_test.c b/tests/z_api_null_drop_test.c index 814d80e7c..96eb102ce 100644 --- a/tests/z_api_null_drop_test.c +++ b/tests/z_api_null_drop_test.c @@ -29,7 +29,6 @@ int main(int argc, char **argv) { 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(); - z_owned_pull_subscriber_t pull_subscriber_null_1 = z_pull_subscriber_null(); z_owned_subscriber_t subscriber_null_1 = z_subscriber_null(); z_owned_queryable_t queryable_null_1 = z_queryable_null(); z_owned_encoding_t encoding_null_1 = z_encoding_null(); @@ -55,7 +54,6 @@ int main(int argc, char **argv) { assert(!z_check(keyexpr_null_1)); assert(!z_check(config_null_1)); assert(!z_check(scouting_config_null_1)); - assert(!z_check(pull_subscriber_null_1)); assert(!z_check(subscriber_null_1)); assert(!z_check(queryable_null_1)); assert(!z_check(encoding_null_1)); @@ -74,7 +72,6 @@ int main(int argc, char **argv) { z_owned_keyexpr_t keyexpr_null_2; z_owned_config_t config_null_2; z_owned_scouting_config_t scouting_config_null_2; - z_owned_pull_subscriber_t pull_subscriber_null_2; z_owned_subscriber_t subscriber_null_2; z_owned_queryable_t queryable_null_2; z_owned_encoding_t encoding_null_2; @@ -97,7 +94,6 @@ int main(int argc, char **argv) { z_null(&keyexpr_null_2); z_null(&config_null_2); z_null(&scouting_config_null_2); - z_null(&pull_subscriber_null_2); z_null(&subscriber_null_2); z_null(&queryable_null_2); z_null(&encoding_null_2); @@ -123,7 +119,6 @@ int main(int argc, char **argv) { assert(!z_check(keyexpr_null_2)); assert(!z_check(config_null_2)); assert(!z_check(scouting_config_null_2)); - assert(!z_check(pull_subscriber_null_2)); assert(!z_check(subscriber_null_2)); assert(!z_check(queryable_null_2)); assert(!z_check(encoding_null_2)); @@ -143,7 +138,6 @@ int main(int argc, char **argv) { z_drop(z_move(keyexpr_null_1)); z_drop(z_move(config_null_1)); z_drop(z_move(scouting_config_null_1)); - z_drop(z_move(pull_subscriber_null_1)); z_drop(z_move(subscriber_null_1)); z_drop(z_move(queryable_null_1)); z_drop(z_move(encoding_null_1)); @@ -166,7 +160,6 @@ int main(int argc, char **argv) { z_drop(z_move(keyexpr_null_2)); z_drop(z_move(config_null_2)); z_drop(z_move(scouting_config_null_2)); - z_drop(z_move(pull_subscriber_null_2)); z_drop(z_move(subscriber_null_2)); z_drop(z_move(queryable_null_2)); z_drop(z_move(encoding_null_2));