From 79bf88c6315119bf0236c93b3cd398168d2bc9c6 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Tue, 26 Sep 2023 11:56:20 +0200 Subject: [PATCH 01/26] Update zenoh-pico.h (#253) --- include/zenoh-pico.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/zenoh-pico.h b/include/zenoh-pico.h index 9515f25a0..5e18fc3c5 100644 --- a/include/zenoh-pico.h +++ b/include/zenoh-pico.h @@ -17,8 +17,8 @@ #define ZENOH_PICO "0.10.0.0" #define ZENOH_PICO_MAJOR 0 -#define ZENOH_PICO_MINOR 7 -#define ZENOH_PICO_PATCH 2 +#define ZENOH_PICO_MINOR 10 +#define ZENOH_PICO_PATCH 0 #define ZENOH_PICO_TWEAK 0 #include "zenoh-pico/api/constants.h" From ba75847df3842433fabf800a08be65fc49267233 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 2 Oct 2023 11:36:04 +0200 Subject: [PATCH 02/26] Add P2P UDP multicast examples to README (#255) --- README.md | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 14950d9d7..74a8de814 100644 --- a/README.md +++ b/README.md @@ -330,23 +330,24 @@ To build and upload the code into the board, run the following command: ``` ## 3. Running the Examples -The simplest way to run some of the example is to get a Docker image of the **zenoh** network router (see [http://zenoh.io/docs/getting-started/quick-test/](http://zenoh.io/docs/getting-started/quick-test/)) and then to run the examples on your machine. - -### 3.1. Starting the zenoh Network Service -Assuming you've pulled the Docker image of the **zenoh** network router on a Linux host (to leverage UDP multicast scouting has explained [here](https://zenoh.io/docs/getting-started/quick-test/#run-zenoh-router-in-a-docker-container), then simply do: +The simplest way to run some of the example is to get a Docker image of the **zenoh** router (see [http://zenoh.io/docs/getting-started/quick-test/](http://zenoh.io/docs/getting-started/quick-test/)) and then to run the examples on your machine. +### 3.1. Starting the Zenoh Router +Assuming you've pulled the Docker image of the **zenoh** router on a Linux host (to leverage UDP multicast scouting as explained [here](https://zenoh.io/docs/getting-started/quick-test/#run-zenoh-router-in-a-docker-container), then simply do: ```bash $ docker run --init --net host eclipse/zenoh:master ``` To see the zenoh manual page, simply do: - ```bash $ docker run --init --net host eclipse/zenoh:master --help ``` +:warning: **Please notice that the `--net host` option in Docker is restricted to Linux only.** +The cause is that Docker doesn't support UDP multicast between a container and its host (see cases [moby/moby#23659](https://github.com/moby/moby/issues/23659), [moby/libnetwork#2397](https://github.com/moby/libnetwork/issues/2397) or [moby/libnetwork#552](https://github.com/moby/libnetwork/issues/552)). The only known way to make it work is to use the `--net host` option that is [only supported on Linux hosts](https://docs.docker.com/network/host/). + ### 3.2. Basic Pub/Sub Example -Assuming that (1) you are running the **zenoh** network router, and (2) you are under the build directory, do: +Assuming that (1) you are running the **zenoh** router, and (2) you are under the build directory, do: ```bash $ ./z_sub ``` @@ -356,7 +357,7 @@ And on another shell, do: $ ./z_pub ``` ### 3.3. Basic Queryable/Get Example -Assuming you are running the **zenoh** network router, do: +Assuming you are running the **zenoh** router, do: ```bash $ ./z_queryable ``` @@ -365,3 +366,35 @@ And on another shell, do: ```bash $ ./z_get ``` + +### 3.4. Basic Pub/Sub Example - P2P over UDP multicast +Zenoh-Pico can also work in P2P mode over UDP multicast. This allows a Zenoh-Pico application to communicate directly with another Zenoh-Pico application, as well as with a Zenoh Router configured to work on UDP multicast. + +Assuming that (1) you are under the build directory, do: +```bash +$ ./z_sub -m peer -l udp/224.0.0.123:7447#iface=lo0 +``` + +And on another shell, do: +```bash +$ ./z_pub -m peer -l udp/224.0.0.123:7447#iface=lo0 +``` +where `lo0` is the network interface you want to use for multicast communication. + +### 3.4. Basic Pub/Sub Example - Mixing Client and P2P communication +To allow Zenoh-Pico unicast clients to talk to Zenoh-Pico multicast peers, you need to start a Zenoh Router that listens on both multicast and unicast: +```bash +$ docker run --init --net host eclipse/zenoh:master -l udp/224.0.0.123:7447#iface=lo0 -l tcp/127.0.0.1:7447 +``` + +Assuming that (1) you are running the **zenoh** router as indicated above, and (2) you are under the build directory, do: +```bash +$ ./z_sub -m client -e tcp/127.0.0.1:7447 +``` +A subscriber will connect in client mode to the **zenoh** router over TCP unicast. + +And on another shell, do: +```bash +$ ./z_pub -m peer -l udp/224.0.0.123:7447#iface=lo0 +``` +A publisher will start publishing over UDP multicast and the **zenoh** router will take care of forwarding data from the Zenoh-Pico publisher to the Zenoh-Pico subscriber. From 315e1e0013c5db71c8e2279c72c113ceb01578fa Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 2 Oct 2023 12:07:52 +0200 Subject: [PATCH 03/26] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74a8de814..7deb65bc5 100644 --- a/README.md +++ b/README.md @@ -368,7 +368,7 @@ $ ./z_get ``` ### 3.4. Basic Pub/Sub Example - P2P over UDP multicast -Zenoh-Pico can also work in P2P mode over UDP multicast. This allows a Zenoh-Pico application to communicate directly with another Zenoh-Pico application, as well as with a Zenoh Router configured to work on UDP multicast. +Zenoh-Pico can also work in P2P mode over UDP multicast. This allows a Zenoh-Pico application to communicate directly with another Zenoh-Pico application. Assuming that (1) you are under the build directory, do: ```bash @@ -382,7 +382,7 @@ $ ./z_pub -m peer -l udp/224.0.0.123:7447#iface=lo0 where `lo0` is the network interface you want to use for multicast communication. ### 3.4. Basic Pub/Sub Example - Mixing Client and P2P communication -To allow Zenoh-Pico unicast clients to talk to Zenoh-Pico multicast peers, you need to start a Zenoh Router that listens on both multicast and unicast: +To allow Zenoh-Pico unicast clients to talk to Zenoh-Pico multicast peers, as well as with any other Zenoh client/peer, you need to start a Zenoh Router that listens on both multicast and unicast: ```bash $ docker run --init --net host eclipse/zenoh:master -l udp/224.0.0.123:7447#iface=lo0 -l tcp/127.0.0.1:7447 ``` From e32edfa4cac33878fab86fc5d95d30936175295f Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 2 Oct 2023 12:56:04 +0200 Subject: [PATCH 04/26] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7deb65bc5..62992f3de 100644 --- a/README.md +++ b/README.md @@ -368,7 +368,7 @@ $ ./z_get ``` ### 3.4. Basic Pub/Sub Example - P2P over UDP multicast -Zenoh-Pico can also work in P2P mode over UDP multicast. This allows a Zenoh-Pico application to communicate directly with another Zenoh-Pico application. +Zenoh-Pico can also work in P2P mode over UDP multicast. This allows a Zenoh-Pico application to communicate directly with another Zenoh-Pico application without requiring a Zenoh Router. Assuming that (1) you are under the build directory, do: ```bash From 47032e0b8abec63a104e43cf334b233fae52c294 Mon Sep 17 00:00:00 2001 From: OlivierHecart Date: Wed, 4 Oct 2023 10:22:56 +0200 Subject: [PATCH 05/26] Bump version to 0.11.0.0 --- CMakeLists.txt | 2 +- docs/conf.py | 2 +- include/zenoh-pico.h | 2 +- library.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23b0c6011..076446581 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ # cmake_minimum_required(VERSION 3.13) -project(zenohpico VERSION 0.10.0.0 LANGUAGES C) +project(zenohpico VERSION 0.11.0.0 LANGUAGES C) include(CMakePackageConfigHelpers) include(GNUInstallDirs) diff --git a/docs/conf.py b/docs/conf.py index 1d5c7d92c..f642ca203 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -21,7 +21,7 @@ project = 'zenoh-pico' copyright = '2017, 2022 ZettaScale Technology Inc' author = 'ZettaScale Zenoh team' -release = '0.10.0.0' +release = '0.11.0.0' # -- General configuration --------------------------------------------------- master_doc = 'index' diff --git a/include/zenoh-pico.h b/include/zenoh-pico.h index 5e18fc3c5..f1ea60301 100644 --- a/include/zenoh-pico.h +++ b/include/zenoh-pico.h @@ -15,7 +15,7 @@ #ifndef ZENOH_PICO_H #define ZENOH_PICO_H -#define ZENOH_PICO "0.10.0.0" +#define ZENOH_PICO "0.11.0.0" #define ZENOH_PICO_MAJOR 0 #define ZENOH_PICO_MINOR 10 #define ZENOH_PICO_PATCH 0 diff --git a/library.json b/library.json index 1176941ff..5197887b1 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "zenoh-pico", - "version": "0.10.0.0", + "version": "0.11.0.0", "description": "The Eclipse Zenoh: Zero Overhead Pub/sub, Store/Query and Compute. It unifies data in motion, data in-use, data at rest and computations. It carefully blends traditional pub/sub with geo-distributed storages, queries and computations, while retaining a level of time and space efficiency that is well beyond any of the mainstream stacks. Zenoh-Pico is the implementation able to scale down to extremely constrainded devices and networks.", "keywords": [ "pubsub", From 7f623656ccea9795a8ba09714b804dc8af8f7eeb Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Wed, 4 Oct 2023 14:30:07 +0200 Subject: [PATCH 06/26] style: remove typos in constants and comments --- include/zenoh-pico/api/macros.h | 16 ++++++------- include/zenoh-pico/api/primitives.h | 24 +++++++++---------- include/zenoh-pico/config.h | 8 +++---- include/zenoh-pico/link/link.h | 6 ++--- include/zenoh-pico/net/primitives.h | 2 +- include/zenoh-pico/net/session.h | 2 +- include/zenoh-pico/net/zenoh-pico.h | 1 - include/zenoh-pico/protocol/codec/ext.h | 4 ++-- .../protocol/definitions/transport.h | 16 ++++++------- include/zenoh-pico/utils/string.h | 4 ++-- src/link/endpoint.c | 2 +- src/link/unicast/tcp.c | 2 +- src/link/unicast/ws.c | 2 +- src/protocol/codec.c | 2 +- src/session/query.c | 2 +- src/session/resource.c | 2 +- src/system/arduino/opencr/network.cpp | 4 ++-- src/transport/common/tx.c | 2 +- src/transport/multicast/link/tx.c | 4 ++-- src/transport/unicast/link/rx.c | 4 ++-- src/transport/unicast/link/tx.c | 4 ++-- tests/z_client_test.c | 4 ++-- tests/z_peer_multicast_test.c | 2 +- 23 files changed, 59 insertions(+), 60 deletions(-) diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index f6b6077fb..c7cb700a9 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -46,7 +46,7 @@ z_owned_str_array_t : z_str_array_loan \ )(&x) /** - * Defines a generic function for droping any of the ``z_owned_X_t`` types. + * Defines a generic function for dropping any of the ``z_owned_X_t`` types. * * Parameters: * x: The instance to drop. @@ -75,7 +75,7 @@ * Defines a generic function for making null object of any of the ``z_owned_X_t`` types. * * Returns: - * Returns the unitialized instance of `x`. + * Returns the uninitialized instance of `x`. */ #define z_null(x) (*x = _Generic((x), \ z_owned_session_t * : z_session_null, \ @@ -193,7 +193,7 @@ * Defines a generic function for making null object of any of the ``z_owned_X_t`` types. * * Returns: - * Returns the unitialized instance of `x`. + * Returns the uninitialized instance of `x`. */ #define z_null(x) (*x = _Generic((x), \ z_owned_session_t * : z_session_null, \ @@ -216,15 +216,15 @@ // clang-format on -#define _z_closure_overloader(callback, droper, ctx, ...) \ - { .call = callback, .drop = droper, .context = ctx } +#define _z_closure_overloader(callback, dropper, ctx, ...) \ + { .call = callback, .drop = dropper, .context = ctx } /** * Defines a variadic macro to ease the definition of callback closures. * * Parameters: * callback: the typical ``callback`` function. ``context`` will be passed as its last argument. - * droper: allows the callback's state to be freed. ``context`` will be passed as its last argument. + * dropper: allows the callback's state to be freed. ``context`` will be passed as its last argument. * context: a pointer to an arbitrary state. * * Returns: @@ -334,8 +334,8 @@ inline void z_call(const z_owned_closure_zid_t &closure, const z_id_t *zid) { z_closure_zid_call(&closure, zid); } // clang-format on -#define _z_closure_overloader(callback, droper, ctx, ...) \ - { .context = const_cast(static_cast(ctx)), .call = callback, .drop = droper } +#define _z_closure_overloader(callback, dropper, ctx, ...) \ + { .context = const_cast(static_cast(ctx)), .call = callback, .drop = dropper } #define z_closure(...) _z_closure_overloader(__VA_ARGS__, NULL, NULL) #define z_move(x) (&x) diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 9b0307df3..9b44c2c0e 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -73,7 +73,7 @@ z_keyexpr_t z_keyexpr_unchecked(const char *name); /** * Get null-terminated string departing from a :c:type:`z_keyexpr_t`. * - * If given keyexpr contains a declared keyexpr, the resulting owned string will be unitialized. + * If given keyexpr contains a declared keyexpr, the resulting owned string will be uninitialized. * In that case, the user must use :c:func:`zp_keyexpr_resolve` to resolve the nesting declarations * and get its full expanded representation. * @@ -99,7 +99,7 @@ z_bytes_t z_keyexpr_as_bytes(z_keyexpr_t keyexpr); /** * Constructs a null-terminated string departing from a :c:type:`z_keyexpr_t` for a given :c:type:`z_session_t`. - * The user is responsible of droping the returned string using ``z_free``. + * The user is responsible of dropping the returned string using ``z_free``. * * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` to resolve the keyexpr. @@ -471,7 +471,7 @@ z_query_consolidation_t z_query_consolidation_latest(void); * Monotonic consolidation. * * This strategy offers the best latency. Replies are directly transmitted to the application when received - * without needing to wait for all replies. This mode does not garantee that there will be no duplicates. + * without needing to wait for all replies. This mode does not guarantee that there will be no duplicates. * * Returns: * Returns the constructed :c:type:`z_query_consolidation_t`. @@ -481,7 +481,7 @@ z_query_consolidation_t z_query_consolidation_monotonic(void); /** * No consolidation. * - * This strategy is usefull when querying timeseries data bases or when using quorums. + * This strategy is useful when querying timeseries data bases or when using quorums. * * Returns: * Returns the constructed :c:type:`z_query_consolidation_t`. @@ -697,7 +697,7 @@ _OWNED_FUNCTIONS_CLOSURE(z_owned_closure_zid_t, closure_zid) * * Parameters: * config: A moved instance of :c:type:`z_owned_scouting_config_t` containing the set properties to configure the - * scouting. callback: A moved instance of :c:type:`z_owned_closure_hello_t` containg the callbacks to be called. + * scouting. callback: A moved instance of :c:type:`z_owned_closure_hello_t` containing the callbacks to be called. * * Returns: * Returns ``0`` if the scouting is successful triggered, or a ``negative value`` otherwise. @@ -748,7 +748,7 @@ int8_t z_close(z_owned_session_t *zs); * * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` to inquiry. - * callback: A moved instance of :c:type:`z_owned_closure_zid_t` containg the callbacks to be called. + * callback: A moved instance of :c:type:`z_owned_closure_zid_t` containing the callbacks to be called. * * Returns: * Returns ``0`` if the info is successful triggered, or a ``negative value`` otherwise. @@ -763,7 +763,7 @@ int8_t z_info_peers_zid(const z_session_t zs, z_owned_closure_zid_t *callback); * * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` to inquiry. - * callback: A moved instance of :c:type:`z_owned_closure_zid_t` containg the callbacks to be called. + * callback: A moved instance of :c:type:`z_owned_closure_zid_t` containing the callbacks to be called. * * Returns: * Returns ``0`` if the info is successful triggered, or a ``negative value`` otherwise. @@ -844,8 +844,8 @@ z_get_options_t z_get_options_default(void); * zs: A loaned instance of the the :c:type:`z_session_t` through where data will be put. * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to put. * parameters: Pointer to the parameters as a null-terminated string. - * callback: A moved instance of :c:type:`z_owned_closure_reply_t` containg the callbacks to be called. - * options: The get options to be aplied in the distributed query. + * callback: A moved instance of :c:type:`z_owned_closure_reply_t` containing the callbacks to be called. + * options: The get options to be applied in the distributed query. * * Returns: * Returns ``0`` if the put operation is successful, or a ``negative value`` otherwise. @@ -1078,7 +1078,7 @@ z_pull_subscriber_options_t z_pull_subscriber_options_default(void); * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` where to declare the subscriber. * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. - * callback: A moved instance of :c:type:`z_owned_closure_sample_t` containg the callbacks to be called and the + * callback: A moved instance of :c:type:`z_owned_closure_sample_t` containing the callbacks to be called and the * context to pass to them. options: The options to apply to the pull subscriber. If ``NULL`` is passed, the default * options will be applied. * @@ -1142,7 +1142,7 @@ z_queryable_options_t z_queryable_options_default(void); * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` where to declare the subscriber. * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. - * callback: A moved instance of :c:type:`z_owned_closure_query_t` containg the callbacks to be called and the context + * callback: A moved instance of :c:type:`z_owned_closure_query_t` containing the callbacks to be called and the context * to pass to them. options: The options to apply to the queryable. If ``NULL`` is passed, the default options will be * applied. * @@ -1246,7 +1246,7 @@ z_value_t z_reply_err(const z_owned_reply_t *reply); */ _Bool z_value_is_initialized(z_value_t *value); -/************* Multi Thread Taks helpers **************/ +/************* Multi Thread Tasks helpers **************/ /** * Constructs the default values for the session read task. * diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index 2bbb9abc2..21fa2063a 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -57,7 +57,7 @@ #define Z_CONFIG_PASSWORD_KEY 0x44 /** - * Activates/Desactivates multicast scouting. + * Activates/Deactivates multicast scouting. * Accepted values : `false`, `true`. * Default value : `true`. */ @@ -223,20 +223,20 @@ #endif /** - * Defaulf maximum batch size possible to be received or sent. + * Default maximum batch size possible to be received or sent. */ #ifndef Z_BATCH_UNICAST_SIZE #define Z_BATCH_UNICAST_SIZE 65535 #endif /** - * Defaulf maximum batch size possible to be received or sent. + * Default maximum batch size possible to be received or sent. */ #ifndef Z_BATCH_MULTICAST_SIZE #define Z_BATCH_MULTICAST_SIZE 8192 #endif /** - * Defaulf maximum size for fragmented messages. + * Default maximum size for fragmented messages. */ #ifndef Z_FRAG_MAX_SIZE #define Z_FRAG_MAX_SIZE 300000 diff --git a/include/zenoh-pico/link/link.h b/include/zenoh-pico/link/link.h index e28d8d89d..10a892982 100644 --- a/include/zenoh-pico/link/link.h +++ b/include/zenoh-pico/link/link.h @@ -47,18 +47,18 @@ * * Enumerators: * Z_LINK_CAPABILITY_NONE: Bitmask to define that link has no capabilities. - * Z_LINK_CAPABILITY_RELIEABLE: Bitmask to define and check if link is reliable. + * Z_LINK_CAPABILITY_RELIABLE: Bitmask to define and check if link is reliable. * Z_LINK_CAPABILITY_STREAMED: Bitmask to define and check if link is streamed. * Z_LINK_CAPABILITY_MULTICAST: Bitmask to define and check if link is multicast. */ typedef enum { Z_LINK_CAPABILITY_NONE = 0x00, // 0 - Z_LINK_CAPABILITY_RELIEABLE = 0x01, // 1 << 0 + Z_LINK_CAPABILITY_RELIABLE = 0x01, // 1 << 0 Z_LINK_CAPABILITY_STREAMED = 0x02, // 1 << 1 Z_LINK_CAPABILITY_MULTICAST = 0x04 // 1 << 2 } _z_link_capabilities_t; -#define _Z_LINK_IS_RELIABLE(X) ((X & Z_LINK_CAPABILITY_RELIEABLE) == Z_LINK_CAPABILITY_RELIEABLE) +#define _Z_LINK_IS_RELIABLE(X) ((X & Z_LINK_CAPABILITY_RELIABLE) == Z_LINK_CAPABILITY_RELIABLE) #define _Z_LINK_IS_STREAMED(X) ((X & Z_LINK_CAPABILITY_STREAMED) == Z_LINK_CAPABILITY_STREAMED) #define _Z_LINK_IS_MULTICAST(X) ((X & Z_LINK_CAPABILITY_MULTICAST) == Z_LINK_CAPABILITY_MULTICAST) diff --git a/include/zenoh-pico/net/primitives.h b/include/zenoh-pico/net/primitives.h index 1ebcf43aa..38a2affb4 100644 --- a/include/zenoh-pico/net/primitives.h +++ b/include/zenoh-pico/net/primitives.h @@ -34,7 +34,7 @@ * what: A what bitmask of zenoh entities kind to scout for. * zid: The ZenohID of the scouting origin. * locator: The locator where to scout. - * timeout: The time that should be spent scouting before returnng the results. + * timeout: The time that should be spent scouting before returning the results. */ void _z_scout(const z_what_t what, const _z_id_t zid, const char *locator, const uint32_t timeout, _z_hello_handler_t callback, void *arg_call, _z_drop_handler_t dropper, void *arg_drop); diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index 19c90adee..bebe7608c 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -90,7 +90,7 @@ void _z_close(_z_session_t *session); */ _z_config_t *_z_info(const _z_session_t *session); -/*------------------ Zenoh-Pico Session Management Auxiliar------------------*/ +/*------------------ Zenoh-Pico Session Management Auxiliary ------------------*/ /** * Read from the network. This function should be called manually called when * the read loop has not been started, e.g., when running in a single thread. diff --git a/include/zenoh-pico/net/zenoh-pico.h b/include/zenoh-pico/net/zenoh-pico.h index 80d1f89c2..b90fcf05a 100644 --- a/include/zenoh-pico/net/zenoh-pico.h +++ b/include/zenoh-pico/net/zenoh-pico.h @@ -20,7 +20,6 @@ #include "zenoh-pico/net/primitives.h" #include "zenoh-pico/net/publish.h" #include "zenoh-pico/net/query.h" -#include "zenoh-pico/net/resource.h" #include "zenoh-pico/net/session.h" #include "zenoh-pico/net/subscribe.h" diff --git a/include/zenoh-pico/protocol/codec/ext.h b/include/zenoh-pico/protocol/codec/ext.h index 428842aa1..d8c086566 100644 --- a/include/zenoh-pico/protocol/codec/ext.h +++ b/include/zenoh-pico/protocol/codec/ext.h @@ -28,7 +28,7 @@ int8_t _z_msg_ext_decode_na(_z_msg_ext_t *ext, _z_zbuf_t *zbf, _Bool *has_next); int8_t _z_msg_ext_vec_encode(_z_wbuf_t *wbf, const _z_msg_ext_vec_t *extensions); int8_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf); /** - * Iterates through the extensions in `zbf`, assuming at least one is present at its begining + * Iterates through the extensions in `zbf`, assuming at least one is present at its beginning * (calling this function otherwise is UB). Short-circuits if `callback` returns a non-zero value. * * `callback` will receive `context` as its second argument, and may "steal" its first argument by @@ -36,7 +36,7 @@ int8_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf); */ int8_t _z_msg_ext_decode_iter(_z_zbuf_t *zbf, int8_t (*callback)(_z_msg_ext_t *, void *), void *context); /** - * Iterates through the extensions in `zbf`, assuming at least one is present at its begining. + * Iterates through the extensions in `zbf`, assuming at least one is present at its beginning. * Returns `_Z_ERR_MESSAGE_EXTENSION_MANDATORY_AND_UNKNOWN` if a mandatory extension is found, * `_Z_RES_OK` otherwise. */ diff --git a/include/zenoh-pico/protocol/definitions/transport.h b/include/zenoh-pico/protocol/definitions/transport.h index 32b8dd82a..f92bd3ae3 100644 --- a/include/zenoh-pico/protocol/definitions/transport.h +++ b/include/zenoh-pico/protocol/definitions/transport.h @@ -111,7 +111,7 @@ // +---------------+ // // (#) ZID length. If Flag(I)==1 it indicates how many bytes are used for the ZenohID bytes. -// A ZenohID is minimum 1 byte and maximum 16 bytes. Therefore, the actual lenght is computed as: +// A ZenohID is minimum 1 byte and maximum 16 bytes. Therefore, the actual length is computed as: // real_zid_len := 1 + zid_len // // (*) What. It indicates a bitmap of WhatAmI interests. @@ -138,7 +138,7 @@ void _z_s_msg_scout_clear(_z_s_msg_scout_t *msg); // 1) in response to a SCOUT message; // 2) to (periodically) advertise (e.g., on multicast) the Peer and the locators it is reachable at; // 3) in a already established session to update the corresponding peer on the new capabilities -// (i.e., whatmai) and/or new set of locators (i.e., added or deleted). +// (i.e., whatami) and/or new set of locators (i.e., added or deleted). // Locators are expressed as: // // udp/192.168.0.2:1234 @@ -285,7 +285,7 @@ void _z_t_msg_join_clear(_z_t_msg_join_t *msg); // // (#) ZID length. It indicates how many bytes are used for the ZenohID bytes. // A ZenohID is minimum 1 byte and maximum 16 bytes. Therefore, the actual -// lenght is computed as: +// length is computed as: // real_zid_len := 1 + zid_len // // (+) Sequence Number/ID resolution. It indicates the resolution and @@ -315,11 +315,11 @@ typedef struct { void _z_t_msg_init_clear(_z_t_msg_init_t *msg); /*------------------ Open Message ------------------*/ -// NOTE: 16 bits (2 bytes) may be prepended to the serialized message indicating the total lenght -// in bytes of the message, resulting in the maximum lenght of a message being 65_535 bytes. +// NOTE: 16 bits (2 bytes) may be prepended to the serialized message indicating the total length +// in bytes of the message, resulting in the maximum length of a message being 65_535 bytes. // This is necessary in those stream-oriented transports (e.g., TCP) that do not preserve // the boundary of the serialized messages. The length is encoded as little-endian. -// In any case, the lenght of a message must not exceed 65_535 bytes. +// In any case, the length of a message must not exceed 65_535 bytes. // // The OPEN message is sent on a link to finally open an initialized session with the peer. // @@ -361,7 +361,7 @@ void _z_t_msg_open_clear(_z_t_msg_open_t *msg); // // The CLOSE message is sent in any of the following two cases: // 1) in response to an OPEN message which is not accepted; -// 2) at any time to arbitrarly close the session with the corresponding peer. +// 2) at any time to arbitrarily close the session with the corresponding peer. // // Flags: // - S: Session Close if S==1 Session close or S==0 Link close @@ -451,7 +451,7 @@ void _z_t_msg_frame_clear(_z_t_msg_frame_t *msg); /*------------------ Fragment Message ------------------*/ // The Fragment message is used to transmit on the wire large Zenoh Message that require fragmentation -// because they are larger thatn the maximum batch size (i.e. 2^16-1) and/or the link MTU. +// because they are larger than the maximum batch size (i.e. 2^16-1) and/or the link MTU. // // The [`Fragment`] message flow is the following: // diff --git a/include/zenoh-pico/utils/string.h b/include/zenoh-pico/utils/string.h index 89f8e7cf7..43cd2d63f 100644 --- a/include/zenoh-pico/utils/string.h +++ b/include/zenoh-pico/utils/string.h @@ -30,7 +30,7 @@ typedef struct { * The reverse equivalent of libc's `strstr`. * * Returns NULL if the needle is not found. - * If found, the return pointer will point to the end of the last occuring + * If found, the return pointer will point to the end of the last occurring * needle within the haystack. */ char const *_z_rstrstr(const char *haystack_start, const char *haystack_end, const char *needle); @@ -39,7 +39,7 @@ char const *_z_rstrstr(const char *haystack_start, const char *haystack_end, con * A non-null-terminated haystack equivalent of libc's `strstr`. * * Returns NULL if the needle is not found. - * If found, the return pointer will point to the start of the first occurence + * If found, the return pointer will point to the start of the first occurrence * of the needle within the haystack. */ char const *_z_strstr(char const *haystack_start, char const *haystack_end, const char *needle_start); diff --git a/src/link/endpoint.c b/src/link/endpoint.c index 722887ffd..a4348db71 100644 --- a/src/link/endpoint.c +++ b/src/link/endpoint.c @@ -192,7 +192,7 @@ size_t _z_locator_strlen(const _z_locator_t *l) { size_t md_len = _z_locator_metadata_strlen(&l->_metadata); if (md_len > (size_t)0) { ret = ret + (size_t)1; // Locator metadata separator - ret = ret + md_len; // Locator medatada content + ret = ret + md_len; // Locator metadata content } } return ret; diff --git a/src/link/unicast/tcp.c b/src/link/unicast/tcp.c index f05980924..c6af264d2 100644 --- a/src/link/unicast/tcp.c +++ b/src/link/unicast/tcp.c @@ -156,7 +156,7 @@ uint16_t _z_get_link_mtu_tcp(void) { int8_t _z_new_link_tcp(_z_link_t *zl, _z_endpoint_t *endpoint) { int8_t ret = _Z_RES_OK; - zl->_capabilities = Z_LINK_CAPABILITY_RELIEABLE | Z_LINK_CAPABILITY_STREAMED; + zl->_capabilities = Z_LINK_CAPABILITY_RELIABLE | Z_LINK_CAPABILITY_STREAMED; zl->_mtu = _z_get_link_mtu_tcp(); zl->_endpoint = *endpoint; diff --git a/src/link/unicast/ws.c b/src/link/unicast/ws.c index 5d1119d8d..cd7edd673 100644 --- a/src/link/unicast/ws.c +++ b/src/link/unicast/ws.c @@ -157,7 +157,7 @@ uint16_t _z_get_link_mtu_ws(void) { int8_t _z_new_link_ws(_z_link_t *zl, _z_endpoint_t *endpoint) { int8_t ret = _Z_RES_OK; - zl->_capabilities = Z_LINK_CAPABILITY_RELIEABLE; + zl->_capabilities = Z_LINK_CAPABILITY_RELIABLE; zl->_mtu = _z_get_link_mtu_ws(); zl->_endpoint = *endpoint; diff --git a/src/protocol/codec.c b/src/protocol/codec.c index e05d7ba28..a67bd20db 100644 --- a/src/protocol/codec.c +++ b/src/protocol/codec.c @@ -319,7 +319,7 @@ int8_t _z_bytes_val_decode_na(_z_bytes_t *bs, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; if (ret == _Z_RES_OK) { - if (_z_zbuf_len(zbf) >= bs->len) { // Check if we have enought bytes to read + if (_z_zbuf_len(zbf) >= bs->len) { // Check if we have enough bytes to read *bs = _z_bytes_wrap(_z_zbuf_get_rptr(zbf), bs->len); // Decode without allocating _z_zbuf_set_rpos(zbf, _z_zbuf_get_rpos(zbf) + bs->len); // Move the read position } else { diff --git a/src/session/query.c b/src/session/query.c index 17a8667db..52caa9beb 100644 --- a/src/session/query.c +++ b/src/session/query.c @@ -201,7 +201,7 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons // No need to store the whole reply in the monotonic mode. _z_reply_t partial_reply; (void)memset(&partial_reply, 0, - sizeof(_z_reply_t)); // Avoid warnings on uninitialised values on the reply + sizeof(_z_reply_t)); // Avoid warnings on uninitialized values on the reply partial_reply.data.sample.keyexpr = _z_keyexpr_duplicate(reply.data.sample.keyexpr); pen_rep->_reply = partial_reply; } else { diff --git a/src/session/resource.c b/src/session/resource.c index d997b5b4b..30c29702e 100644 --- a/src/session/resource.c +++ b/src/session/resource.c @@ -98,7 +98,7 @@ _z_keyexpr_t __z_get_expanded_key_from_key(_z_resource_list_t *xs, const _z_keye // or will release the suffix as well } - // Recursevely go through all the RIDs + // Recursively go through all the RIDs _z_zint_t id = keyexpr->_id; uint16_t mapping = _z_keyexpr_mapping_id(keyexpr); while (id != Z_RESOURCE_ID_NONE) { diff --git a/src/system/arduino/opencr/network.cpp b/src/system/arduino/opencr/network.cpp index 8dfecbcec..1912d7cfb 100644 --- a/src/system/arduino/opencr/network.cpp +++ b/src/system/arduino/opencr/network.cpp @@ -186,7 +186,7 @@ void _z_close_udp_unicast(_z_sys_net_socket_t *sock) { size_t _z_read_udp_unicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { // Block until something to read - // FIXME: provide somekind of timeout functionality + // FIXME: provide some kind of timeout functionality ssize_t rb = 0; do { rb = sock._udp->parsePacket(); @@ -282,7 +282,7 @@ void _z_close_udp_multicast(_z_sys_net_socket_t *sockrecv, _z_sys_net_socket_t * size_t _z_read_udp_multicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len, const _z_sys_net_endpoint_t lep, _z_bytes_t *addr) { // Block until something to read - // FIXME: provide somekind of timeout functionality + // FIXME: provide some kind of timeout functionality ssize_t rb = 0; do { rb = sock._udp->parsePacket(); diff --git a/src/transport/common/tx.c b/src/transport/common/tx.c index a1144be24..f3625250e 100644 --- a/src/transport/common/tx.c +++ b/src/transport/common/tx.c @@ -88,7 +88,7 @@ int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_m // Encode the session message ret = _z_transport_message_encode(&wbf, t_msg); if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed if (_Z_LINK_IS_STREAMED(zl->_capabilities) == true) { size_t len = _z_wbuf_len(&wbf) - _Z_MSG_LEN_ENC_SIZE; for (uint8_t i = 0; i < _Z_MSG_LEN_ENC_SIZE; i++) { diff --git a/src/transport/multicast/link/tx.c b/src/transport/multicast/link/tx.c index 67e4e35bd..991f878f3 100644 --- a/src/transport/multicast/link/tx.c +++ b/src/transport/multicast/link/tx.c @@ -54,7 +54,7 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport // Encode the session message ret = _z_transport_message_encode(&ztm->_wbuf, t_msg); if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed __unsafe_z_finalize_wbuf(&ztm->_wbuf, _Z_LINK_IS_STREAMED(ztm->_link._capabilities)); // Send the wbuf on the socket ret = _z_link_send_wbuf(&ztm->_link, &ztm->_wbuf); @@ -105,7 +105,7 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m if (ret == _Z_RES_OK) { ret = _z_network_message_encode(&ztm->_wbuf, n_msg); // Encode the network message if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed __unsafe_z_finalize_wbuf(&ztm->_wbuf, _Z_LINK_IS_STREAMED(ztm->_link._capabilities)); ret = _z_link_send_wbuf(&ztm->_link, &ztm->_wbuf); // Send the wbuf on the socket diff --git a/src/transport/unicast/link/rx.c b/src/transport/unicast/link/rx.c index bac48d82e..6604e71ea 100644 --- a/src/transport/unicast/link/rx.c +++ b/src/transport/unicast/link/rx.c @@ -97,7 +97,7 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans // Check if the SN is correct if (_Z_HAS_FLAG(t_msg->_header, _Z_FLAG_T_FRAME_R) == true) { // @TODO: amend once reliability is in place. For the time being only - // monothonic SNs are ensured + // monotonic SNs are ensured if (_z_sn_precedes(ztu->_sn_res, ztu->_sn_rx_reliable, t_msg->_body._frame._sn) == true) { ztu->_sn_rx_reliable = t_msg->_body._frame._sn; } else { @@ -133,7 +133,7 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans _Bool drop = false; if ((_z_wbuf_len(dbuf) + t_msg->_body._fragment._payload.len) > Z_FRAG_MAX_SIZE) { - // Filling the wbuf capacity as a way to signling the last fragment to reset the dbuf + // Filling the wbuf capacity as a way to signal the last fragment to reset the dbuf // Otherwise, last (smaller) fragments can be understood as a complete message _z_wbuf_write_bytes(dbuf, t_msg->_body._fragment._payload.start, 0, _z_wbuf_space_left(dbuf)); drop = true; diff --git a/src/transport/unicast/link/tx.c b/src/transport/unicast/link/tx.c index 3375d08e9..8f825b7e4 100644 --- a/src/transport/unicast/link/tx.c +++ b/src/transport/unicast/link/tx.c @@ -57,7 +57,7 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes // Encode the session message ret = _z_transport_message_encode(&ztu->_wbuf, t_msg); if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed __unsafe_z_finalize_wbuf(&ztu->_wbuf, _Z_LINK_IS_STREAMED(ztu->_link._capabilities)); // Send the wbuf on the socket ret = _z_link_send_wbuf(&ztu->_link, &ztu->_wbuf); @@ -108,7 +108,7 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg if (ret == _Z_RES_OK) { ret = _z_network_message_encode(&ztu->_wbuf, n_msg); // Encode the network message if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed __unsafe_z_finalize_wbuf(&ztu->_wbuf, _Z_LINK_IS_STREAMED(ztu->_link._capabilities)); if (ztu->_wbuf._ioss._len == 1) { diff --git a/tests/z_client_test.c b/tests/z_client_test.c index 80ca3c2e5..0c42ab132 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -199,7 +199,7 @@ int main(int argc, char **argv) { z_sleep_s(SLEEP); - // Write data from firt session + // Write data from first session size_t len = MSG_LEN; uint8_t *payload = (uint8_t *)z_malloc(len); memset(payload, 1, MSG_LEN); @@ -256,7 +256,7 @@ int main(int argc, char **argv) { assert(queries >= expected); queries = 0; - // Wait to receive all the expectred replies + // Wait to receive all the expected replies now = z_clock_now(); while (replies < expected) { assert(z_clock_elapsed_s(&now) < TIMEOUT); diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index 29b05223a..e1ede7104 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -113,7 +113,7 @@ int main(int argc, char **argv) { subs2 = _z_list_push(subs2, sub); } - // Write data from firt session + // Write data from first session size_t len = MSG_LEN; uint8_t *payload = (uint8_t *)z_malloc(len); memset(payload, 1, MSG_LEN); From 1a67d067edb0a8344838a3717c3c71dffb1c5fd5 Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Wed, 4 Oct 2023 16:42:27 +0200 Subject: [PATCH 07/26] Remove typos in constants and comments (#256) --- include/zenoh-pico/api/macros.h | 16 ++++++------- include/zenoh-pico/api/primitives.h | 24 +++++++++---------- include/zenoh-pico/config.h | 8 +++---- include/zenoh-pico/link/link.h | 6 ++--- include/zenoh-pico/net/primitives.h | 2 +- include/zenoh-pico/net/session.h | 2 +- include/zenoh-pico/net/zenoh-pico.h | 1 - include/zenoh-pico/protocol/codec/ext.h | 4 ++-- .../protocol/definitions/transport.h | 16 ++++++------- include/zenoh-pico/utils/string.h | 4 ++-- src/link/endpoint.c | 2 +- src/link/unicast/tcp.c | 2 +- src/link/unicast/ws.c | 2 +- src/protocol/codec.c | 2 +- src/session/query.c | 2 +- src/session/resource.c | 2 +- src/system/arduino/opencr/network.cpp | 4 ++-- src/transport/common/tx.c | 2 +- src/transport/multicast/link/tx.c | 4 ++-- src/transport/unicast/link/rx.c | 4 ++-- src/transport/unicast/link/tx.c | 4 ++-- tests/z_client_test.c | 4 ++-- tests/z_peer_multicast_test.c | 2 +- 23 files changed, 59 insertions(+), 60 deletions(-) diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index f6b6077fb..c7cb700a9 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -46,7 +46,7 @@ z_owned_str_array_t : z_str_array_loan \ )(&x) /** - * Defines a generic function for droping any of the ``z_owned_X_t`` types. + * Defines a generic function for dropping any of the ``z_owned_X_t`` types. * * Parameters: * x: The instance to drop. @@ -75,7 +75,7 @@ * Defines a generic function for making null object of any of the ``z_owned_X_t`` types. * * Returns: - * Returns the unitialized instance of `x`. + * Returns the uninitialized instance of `x`. */ #define z_null(x) (*x = _Generic((x), \ z_owned_session_t * : z_session_null, \ @@ -193,7 +193,7 @@ * Defines a generic function for making null object of any of the ``z_owned_X_t`` types. * * Returns: - * Returns the unitialized instance of `x`. + * Returns the uninitialized instance of `x`. */ #define z_null(x) (*x = _Generic((x), \ z_owned_session_t * : z_session_null, \ @@ -216,15 +216,15 @@ // clang-format on -#define _z_closure_overloader(callback, droper, ctx, ...) \ - { .call = callback, .drop = droper, .context = ctx } +#define _z_closure_overloader(callback, dropper, ctx, ...) \ + { .call = callback, .drop = dropper, .context = ctx } /** * Defines a variadic macro to ease the definition of callback closures. * * Parameters: * callback: the typical ``callback`` function. ``context`` will be passed as its last argument. - * droper: allows the callback's state to be freed. ``context`` will be passed as its last argument. + * dropper: allows the callback's state to be freed. ``context`` will be passed as its last argument. * context: a pointer to an arbitrary state. * * Returns: @@ -334,8 +334,8 @@ inline void z_call(const z_owned_closure_zid_t &closure, const z_id_t *zid) { z_closure_zid_call(&closure, zid); } // clang-format on -#define _z_closure_overloader(callback, droper, ctx, ...) \ - { .context = const_cast(static_cast(ctx)), .call = callback, .drop = droper } +#define _z_closure_overloader(callback, dropper, ctx, ...) \ + { .context = const_cast(static_cast(ctx)), .call = callback, .drop = dropper } #define z_closure(...) _z_closure_overloader(__VA_ARGS__, NULL, NULL) #define z_move(x) (&x) diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 9b0307df3..9b44c2c0e 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -73,7 +73,7 @@ z_keyexpr_t z_keyexpr_unchecked(const char *name); /** * Get null-terminated string departing from a :c:type:`z_keyexpr_t`. * - * If given keyexpr contains a declared keyexpr, the resulting owned string will be unitialized. + * If given keyexpr contains a declared keyexpr, the resulting owned string will be uninitialized. * In that case, the user must use :c:func:`zp_keyexpr_resolve` to resolve the nesting declarations * and get its full expanded representation. * @@ -99,7 +99,7 @@ z_bytes_t z_keyexpr_as_bytes(z_keyexpr_t keyexpr); /** * Constructs a null-terminated string departing from a :c:type:`z_keyexpr_t` for a given :c:type:`z_session_t`. - * The user is responsible of droping the returned string using ``z_free``. + * The user is responsible of dropping the returned string using ``z_free``. * * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` to resolve the keyexpr. @@ -471,7 +471,7 @@ z_query_consolidation_t z_query_consolidation_latest(void); * Monotonic consolidation. * * This strategy offers the best latency. Replies are directly transmitted to the application when received - * without needing to wait for all replies. This mode does not garantee that there will be no duplicates. + * without needing to wait for all replies. This mode does not guarantee that there will be no duplicates. * * Returns: * Returns the constructed :c:type:`z_query_consolidation_t`. @@ -481,7 +481,7 @@ z_query_consolidation_t z_query_consolidation_monotonic(void); /** * No consolidation. * - * This strategy is usefull when querying timeseries data bases or when using quorums. + * This strategy is useful when querying timeseries data bases or when using quorums. * * Returns: * Returns the constructed :c:type:`z_query_consolidation_t`. @@ -697,7 +697,7 @@ _OWNED_FUNCTIONS_CLOSURE(z_owned_closure_zid_t, closure_zid) * * Parameters: * config: A moved instance of :c:type:`z_owned_scouting_config_t` containing the set properties to configure the - * scouting. callback: A moved instance of :c:type:`z_owned_closure_hello_t` containg the callbacks to be called. + * scouting. callback: A moved instance of :c:type:`z_owned_closure_hello_t` containing the callbacks to be called. * * Returns: * Returns ``0`` if the scouting is successful triggered, or a ``negative value`` otherwise. @@ -748,7 +748,7 @@ int8_t z_close(z_owned_session_t *zs); * * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` to inquiry. - * callback: A moved instance of :c:type:`z_owned_closure_zid_t` containg the callbacks to be called. + * callback: A moved instance of :c:type:`z_owned_closure_zid_t` containing the callbacks to be called. * * Returns: * Returns ``0`` if the info is successful triggered, or a ``negative value`` otherwise. @@ -763,7 +763,7 @@ int8_t z_info_peers_zid(const z_session_t zs, z_owned_closure_zid_t *callback); * * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` to inquiry. - * callback: A moved instance of :c:type:`z_owned_closure_zid_t` containg the callbacks to be called. + * callback: A moved instance of :c:type:`z_owned_closure_zid_t` containing the callbacks to be called. * * Returns: * Returns ``0`` if the info is successful triggered, or a ``negative value`` otherwise. @@ -844,8 +844,8 @@ z_get_options_t z_get_options_default(void); * zs: A loaned instance of the the :c:type:`z_session_t` through where data will be put. * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to put. * parameters: Pointer to the parameters as a null-terminated string. - * callback: A moved instance of :c:type:`z_owned_closure_reply_t` containg the callbacks to be called. - * options: The get options to be aplied in the distributed query. + * callback: A moved instance of :c:type:`z_owned_closure_reply_t` containing the callbacks to be called. + * options: The get options to be applied in the distributed query. * * Returns: * Returns ``0`` if the put operation is successful, or a ``negative value`` otherwise. @@ -1078,7 +1078,7 @@ z_pull_subscriber_options_t z_pull_subscriber_options_default(void); * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` where to declare the subscriber. * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. - * callback: A moved instance of :c:type:`z_owned_closure_sample_t` containg the callbacks to be called and the + * callback: A moved instance of :c:type:`z_owned_closure_sample_t` containing the callbacks to be called and the * context to pass to them. options: The options to apply to the pull subscriber. If ``NULL`` is passed, the default * options will be applied. * @@ -1142,7 +1142,7 @@ z_queryable_options_t z_queryable_options_default(void); * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` where to declare the subscriber. * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. - * callback: A moved instance of :c:type:`z_owned_closure_query_t` containg the callbacks to be called and the context + * callback: A moved instance of :c:type:`z_owned_closure_query_t` containing the callbacks to be called and the context * to pass to them. options: The options to apply to the queryable. If ``NULL`` is passed, the default options will be * applied. * @@ -1246,7 +1246,7 @@ z_value_t z_reply_err(const z_owned_reply_t *reply); */ _Bool z_value_is_initialized(z_value_t *value); -/************* Multi Thread Taks helpers **************/ +/************* Multi Thread Tasks helpers **************/ /** * Constructs the default values for the session read task. * diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index 2bbb9abc2..21fa2063a 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -57,7 +57,7 @@ #define Z_CONFIG_PASSWORD_KEY 0x44 /** - * Activates/Desactivates multicast scouting. + * Activates/Deactivates multicast scouting. * Accepted values : `false`, `true`. * Default value : `true`. */ @@ -223,20 +223,20 @@ #endif /** - * Defaulf maximum batch size possible to be received or sent. + * Default maximum batch size possible to be received or sent. */ #ifndef Z_BATCH_UNICAST_SIZE #define Z_BATCH_UNICAST_SIZE 65535 #endif /** - * Defaulf maximum batch size possible to be received or sent. + * Default maximum batch size possible to be received or sent. */ #ifndef Z_BATCH_MULTICAST_SIZE #define Z_BATCH_MULTICAST_SIZE 8192 #endif /** - * Defaulf maximum size for fragmented messages. + * Default maximum size for fragmented messages. */ #ifndef Z_FRAG_MAX_SIZE #define Z_FRAG_MAX_SIZE 300000 diff --git a/include/zenoh-pico/link/link.h b/include/zenoh-pico/link/link.h index e28d8d89d..10a892982 100644 --- a/include/zenoh-pico/link/link.h +++ b/include/zenoh-pico/link/link.h @@ -47,18 +47,18 @@ * * Enumerators: * Z_LINK_CAPABILITY_NONE: Bitmask to define that link has no capabilities. - * Z_LINK_CAPABILITY_RELIEABLE: Bitmask to define and check if link is reliable. + * Z_LINK_CAPABILITY_RELIABLE: Bitmask to define and check if link is reliable. * Z_LINK_CAPABILITY_STREAMED: Bitmask to define and check if link is streamed. * Z_LINK_CAPABILITY_MULTICAST: Bitmask to define and check if link is multicast. */ typedef enum { Z_LINK_CAPABILITY_NONE = 0x00, // 0 - Z_LINK_CAPABILITY_RELIEABLE = 0x01, // 1 << 0 + Z_LINK_CAPABILITY_RELIABLE = 0x01, // 1 << 0 Z_LINK_CAPABILITY_STREAMED = 0x02, // 1 << 1 Z_LINK_CAPABILITY_MULTICAST = 0x04 // 1 << 2 } _z_link_capabilities_t; -#define _Z_LINK_IS_RELIABLE(X) ((X & Z_LINK_CAPABILITY_RELIEABLE) == Z_LINK_CAPABILITY_RELIEABLE) +#define _Z_LINK_IS_RELIABLE(X) ((X & Z_LINK_CAPABILITY_RELIABLE) == Z_LINK_CAPABILITY_RELIABLE) #define _Z_LINK_IS_STREAMED(X) ((X & Z_LINK_CAPABILITY_STREAMED) == Z_LINK_CAPABILITY_STREAMED) #define _Z_LINK_IS_MULTICAST(X) ((X & Z_LINK_CAPABILITY_MULTICAST) == Z_LINK_CAPABILITY_MULTICAST) diff --git a/include/zenoh-pico/net/primitives.h b/include/zenoh-pico/net/primitives.h index 1ebcf43aa..38a2affb4 100644 --- a/include/zenoh-pico/net/primitives.h +++ b/include/zenoh-pico/net/primitives.h @@ -34,7 +34,7 @@ * what: A what bitmask of zenoh entities kind to scout for. * zid: The ZenohID of the scouting origin. * locator: The locator where to scout. - * timeout: The time that should be spent scouting before returnng the results. + * timeout: The time that should be spent scouting before returning the results. */ void _z_scout(const z_what_t what, const _z_id_t zid, const char *locator, const uint32_t timeout, _z_hello_handler_t callback, void *arg_call, _z_drop_handler_t dropper, void *arg_drop); diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index 19c90adee..bebe7608c 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -90,7 +90,7 @@ void _z_close(_z_session_t *session); */ _z_config_t *_z_info(const _z_session_t *session); -/*------------------ Zenoh-Pico Session Management Auxiliar------------------*/ +/*------------------ Zenoh-Pico Session Management Auxiliary ------------------*/ /** * Read from the network. This function should be called manually called when * the read loop has not been started, e.g., when running in a single thread. diff --git a/include/zenoh-pico/net/zenoh-pico.h b/include/zenoh-pico/net/zenoh-pico.h index 80d1f89c2..b90fcf05a 100644 --- a/include/zenoh-pico/net/zenoh-pico.h +++ b/include/zenoh-pico/net/zenoh-pico.h @@ -20,7 +20,6 @@ #include "zenoh-pico/net/primitives.h" #include "zenoh-pico/net/publish.h" #include "zenoh-pico/net/query.h" -#include "zenoh-pico/net/resource.h" #include "zenoh-pico/net/session.h" #include "zenoh-pico/net/subscribe.h" diff --git a/include/zenoh-pico/protocol/codec/ext.h b/include/zenoh-pico/protocol/codec/ext.h index 428842aa1..d8c086566 100644 --- a/include/zenoh-pico/protocol/codec/ext.h +++ b/include/zenoh-pico/protocol/codec/ext.h @@ -28,7 +28,7 @@ int8_t _z_msg_ext_decode_na(_z_msg_ext_t *ext, _z_zbuf_t *zbf, _Bool *has_next); int8_t _z_msg_ext_vec_encode(_z_wbuf_t *wbf, const _z_msg_ext_vec_t *extensions); int8_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf); /** - * Iterates through the extensions in `zbf`, assuming at least one is present at its begining + * Iterates through the extensions in `zbf`, assuming at least one is present at its beginning * (calling this function otherwise is UB). Short-circuits if `callback` returns a non-zero value. * * `callback` will receive `context` as its second argument, and may "steal" its first argument by @@ -36,7 +36,7 @@ int8_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf); */ int8_t _z_msg_ext_decode_iter(_z_zbuf_t *zbf, int8_t (*callback)(_z_msg_ext_t *, void *), void *context); /** - * Iterates through the extensions in `zbf`, assuming at least one is present at its begining. + * Iterates through the extensions in `zbf`, assuming at least one is present at its beginning. * Returns `_Z_ERR_MESSAGE_EXTENSION_MANDATORY_AND_UNKNOWN` if a mandatory extension is found, * `_Z_RES_OK` otherwise. */ diff --git a/include/zenoh-pico/protocol/definitions/transport.h b/include/zenoh-pico/protocol/definitions/transport.h index 32b8dd82a..f92bd3ae3 100644 --- a/include/zenoh-pico/protocol/definitions/transport.h +++ b/include/zenoh-pico/protocol/definitions/transport.h @@ -111,7 +111,7 @@ // +---------------+ // // (#) ZID length. If Flag(I)==1 it indicates how many bytes are used for the ZenohID bytes. -// A ZenohID is minimum 1 byte and maximum 16 bytes. Therefore, the actual lenght is computed as: +// A ZenohID is minimum 1 byte and maximum 16 bytes. Therefore, the actual length is computed as: // real_zid_len := 1 + zid_len // // (*) What. It indicates a bitmap of WhatAmI interests. @@ -138,7 +138,7 @@ void _z_s_msg_scout_clear(_z_s_msg_scout_t *msg); // 1) in response to a SCOUT message; // 2) to (periodically) advertise (e.g., on multicast) the Peer and the locators it is reachable at; // 3) in a already established session to update the corresponding peer on the new capabilities -// (i.e., whatmai) and/or new set of locators (i.e., added or deleted). +// (i.e., whatami) and/or new set of locators (i.e., added or deleted). // Locators are expressed as: // // udp/192.168.0.2:1234 @@ -285,7 +285,7 @@ void _z_t_msg_join_clear(_z_t_msg_join_t *msg); // // (#) ZID length. It indicates how many bytes are used for the ZenohID bytes. // A ZenohID is minimum 1 byte and maximum 16 bytes. Therefore, the actual -// lenght is computed as: +// length is computed as: // real_zid_len := 1 + zid_len // // (+) Sequence Number/ID resolution. It indicates the resolution and @@ -315,11 +315,11 @@ typedef struct { void _z_t_msg_init_clear(_z_t_msg_init_t *msg); /*------------------ Open Message ------------------*/ -// NOTE: 16 bits (2 bytes) may be prepended to the serialized message indicating the total lenght -// in bytes of the message, resulting in the maximum lenght of a message being 65_535 bytes. +// NOTE: 16 bits (2 bytes) may be prepended to the serialized message indicating the total length +// in bytes of the message, resulting in the maximum length of a message being 65_535 bytes. // This is necessary in those stream-oriented transports (e.g., TCP) that do not preserve // the boundary of the serialized messages. The length is encoded as little-endian. -// In any case, the lenght of a message must not exceed 65_535 bytes. +// In any case, the length of a message must not exceed 65_535 bytes. // // The OPEN message is sent on a link to finally open an initialized session with the peer. // @@ -361,7 +361,7 @@ void _z_t_msg_open_clear(_z_t_msg_open_t *msg); // // The CLOSE message is sent in any of the following two cases: // 1) in response to an OPEN message which is not accepted; -// 2) at any time to arbitrarly close the session with the corresponding peer. +// 2) at any time to arbitrarily close the session with the corresponding peer. // // Flags: // - S: Session Close if S==1 Session close or S==0 Link close @@ -451,7 +451,7 @@ void _z_t_msg_frame_clear(_z_t_msg_frame_t *msg); /*------------------ Fragment Message ------------------*/ // The Fragment message is used to transmit on the wire large Zenoh Message that require fragmentation -// because they are larger thatn the maximum batch size (i.e. 2^16-1) and/or the link MTU. +// because they are larger than the maximum batch size (i.e. 2^16-1) and/or the link MTU. // // The [`Fragment`] message flow is the following: // diff --git a/include/zenoh-pico/utils/string.h b/include/zenoh-pico/utils/string.h index 89f8e7cf7..43cd2d63f 100644 --- a/include/zenoh-pico/utils/string.h +++ b/include/zenoh-pico/utils/string.h @@ -30,7 +30,7 @@ typedef struct { * The reverse equivalent of libc's `strstr`. * * Returns NULL if the needle is not found. - * If found, the return pointer will point to the end of the last occuring + * If found, the return pointer will point to the end of the last occurring * needle within the haystack. */ char const *_z_rstrstr(const char *haystack_start, const char *haystack_end, const char *needle); @@ -39,7 +39,7 @@ char const *_z_rstrstr(const char *haystack_start, const char *haystack_end, con * A non-null-terminated haystack equivalent of libc's `strstr`. * * Returns NULL if the needle is not found. - * If found, the return pointer will point to the start of the first occurence + * If found, the return pointer will point to the start of the first occurrence * of the needle within the haystack. */ char const *_z_strstr(char const *haystack_start, char const *haystack_end, const char *needle_start); diff --git a/src/link/endpoint.c b/src/link/endpoint.c index 722887ffd..a4348db71 100644 --- a/src/link/endpoint.c +++ b/src/link/endpoint.c @@ -192,7 +192,7 @@ size_t _z_locator_strlen(const _z_locator_t *l) { size_t md_len = _z_locator_metadata_strlen(&l->_metadata); if (md_len > (size_t)0) { ret = ret + (size_t)1; // Locator metadata separator - ret = ret + md_len; // Locator medatada content + ret = ret + md_len; // Locator metadata content } } return ret; diff --git a/src/link/unicast/tcp.c b/src/link/unicast/tcp.c index f05980924..c6af264d2 100644 --- a/src/link/unicast/tcp.c +++ b/src/link/unicast/tcp.c @@ -156,7 +156,7 @@ uint16_t _z_get_link_mtu_tcp(void) { int8_t _z_new_link_tcp(_z_link_t *zl, _z_endpoint_t *endpoint) { int8_t ret = _Z_RES_OK; - zl->_capabilities = Z_LINK_CAPABILITY_RELIEABLE | Z_LINK_CAPABILITY_STREAMED; + zl->_capabilities = Z_LINK_CAPABILITY_RELIABLE | Z_LINK_CAPABILITY_STREAMED; zl->_mtu = _z_get_link_mtu_tcp(); zl->_endpoint = *endpoint; diff --git a/src/link/unicast/ws.c b/src/link/unicast/ws.c index 5d1119d8d..cd7edd673 100644 --- a/src/link/unicast/ws.c +++ b/src/link/unicast/ws.c @@ -157,7 +157,7 @@ uint16_t _z_get_link_mtu_ws(void) { int8_t _z_new_link_ws(_z_link_t *zl, _z_endpoint_t *endpoint) { int8_t ret = _Z_RES_OK; - zl->_capabilities = Z_LINK_CAPABILITY_RELIEABLE; + zl->_capabilities = Z_LINK_CAPABILITY_RELIABLE; zl->_mtu = _z_get_link_mtu_ws(); zl->_endpoint = *endpoint; diff --git a/src/protocol/codec.c b/src/protocol/codec.c index e05d7ba28..a67bd20db 100644 --- a/src/protocol/codec.c +++ b/src/protocol/codec.c @@ -319,7 +319,7 @@ int8_t _z_bytes_val_decode_na(_z_bytes_t *bs, _z_zbuf_t *zbf) { int8_t ret = _Z_RES_OK; if (ret == _Z_RES_OK) { - if (_z_zbuf_len(zbf) >= bs->len) { // Check if we have enought bytes to read + if (_z_zbuf_len(zbf) >= bs->len) { // Check if we have enough bytes to read *bs = _z_bytes_wrap(_z_zbuf_get_rptr(zbf), bs->len); // Decode without allocating _z_zbuf_set_rpos(zbf, _z_zbuf_get_rpos(zbf) + bs->len); // Move the read position } else { diff --git a/src/session/query.c b/src/session/query.c index 17a8667db..52caa9beb 100644 --- a/src/session/query.c +++ b/src/session/query.c @@ -201,7 +201,7 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons // No need to store the whole reply in the monotonic mode. _z_reply_t partial_reply; (void)memset(&partial_reply, 0, - sizeof(_z_reply_t)); // Avoid warnings on uninitialised values on the reply + sizeof(_z_reply_t)); // Avoid warnings on uninitialized values on the reply partial_reply.data.sample.keyexpr = _z_keyexpr_duplicate(reply.data.sample.keyexpr); pen_rep->_reply = partial_reply; } else { diff --git a/src/session/resource.c b/src/session/resource.c index d997b5b4b..30c29702e 100644 --- a/src/session/resource.c +++ b/src/session/resource.c @@ -98,7 +98,7 @@ _z_keyexpr_t __z_get_expanded_key_from_key(_z_resource_list_t *xs, const _z_keye // or will release the suffix as well } - // Recursevely go through all the RIDs + // Recursively go through all the RIDs _z_zint_t id = keyexpr->_id; uint16_t mapping = _z_keyexpr_mapping_id(keyexpr); while (id != Z_RESOURCE_ID_NONE) { diff --git a/src/system/arduino/opencr/network.cpp b/src/system/arduino/opencr/network.cpp index 8dfecbcec..1912d7cfb 100644 --- a/src/system/arduino/opencr/network.cpp +++ b/src/system/arduino/opencr/network.cpp @@ -186,7 +186,7 @@ void _z_close_udp_unicast(_z_sys_net_socket_t *sock) { size_t _z_read_udp_unicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { // Block until something to read - // FIXME: provide somekind of timeout functionality + // FIXME: provide some kind of timeout functionality ssize_t rb = 0; do { rb = sock._udp->parsePacket(); @@ -282,7 +282,7 @@ void _z_close_udp_multicast(_z_sys_net_socket_t *sockrecv, _z_sys_net_socket_t * size_t _z_read_udp_multicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len, const _z_sys_net_endpoint_t lep, _z_bytes_t *addr) { // Block until something to read - // FIXME: provide somekind of timeout functionality + // FIXME: provide some kind of timeout functionality ssize_t rb = 0; do { rb = sock._udp->parsePacket(); diff --git a/src/transport/common/tx.c b/src/transport/common/tx.c index a1144be24..f3625250e 100644 --- a/src/transport/common/tx.c +++ b/src/transport/common/tx.c @@ -88,7 +88,7 @@ int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_m // Encode the session message ret = _z_transport_message_encode(&wbf, t_msg); if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed if (_Z_LINK_IS_STREAMED(zl->_capabilities) == true) { size_t len = _z_wbuf_len(&wbf) - _Z_MSG_LEN_ENC_SIZE; for (uint8_t i = 0; i < _Z_MSG_LEN_ENC_SIZE; i++) { diff --git a/src/transport/multicast/link/tx.c b/src/transport/multicast/link/tx.c index 67e4e35bd..991f878f3 100644 --- a/src/transport/multicast/link/tx.c +++ b/src/transport/multicast/link/tx.c @@ -54,7 +54,7 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport // Encode the session message ret = _z_transport_message_encode(&ztm->_wbuf, t_msg); if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed __unsafe_z_finalize_wbuf(&ztm->_wbuf, _Z_LINK_IS_STREAMED(ztm->_link._capabilities)); // Send the wbuf on the socket ret = _z_link_send_wbuf(&ztm->_link, &ztm->_wbuf); @@ -105,7 +105,7 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m if (ret == _Z_RES_OK) { ret = _z_network_message_encode(&ztm->_wbuf, n_msg); // Encode the network message if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed __unsafe_z_finalize_wbuf(&ztm->_wbuf, _Z_LINK_IS_STREAMED(ztm->_link._capabilities)); ret = _z_link_send_wbuf(&ztm->_link, &ztm->_wbuf); // Send the wbuf on the socket diff --git a/src/transport/unicast/link/rx.c b/src/transport/unicast/link/rx.c index bac48d82e..6604e71ea 100644 --- a/src/transport/unicast/link/rx.c +++ b/src/transport/unicast/link/rx.c @@ -97,7 +97,7 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans // Check if the SN is correct if (_Z_HAS_FLAG(t_msg->_header, _Z_FLAG_T_FRAME_R) == true) { // @TODO: amend once reliability is in place. For the time being only - // monothonic SNs are ensured + // monotonic SNs are ensured if (_z_sn_precedes(ztu->_sn_res, ztu->_sn_rx_reliable, t_msg->_body._frame._sn) == true) { ztu->_sn_rx_reliable = t_msg->_body._frame._sn; } else { @@ -133,7 +133,7 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans _Bool drop = false; if ((_z_wbuf_len(dbuf) + t_msg->_body._fragment._payload.len) > Z_FRAG_MAX_SIZE) { - // Filling the wbuf capacity as a way to signling the last fragment to reset the dbuf + // Filling the wbuf capacity as a way to signal the last fragment to reset the dbuf // Otherwise, last (smaller) fragments can be understood as a complete message _z_wbuf_write_bytes(dbuf, t_msg->_body._fragment._payload.start, 0, _z_wbuf_space_left(dbuf)); drop = true; diff --git a/src/transport/unicast/link/tx.c b/src/transport/unicast/link/tx.c index 3375d08e9..8f825b7e4 100644 --- a/src/transport/unicast/link/tx.c +++ b/src/transport/unicast/link/tx.c @@ -57,7 +57,7 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes // Encode the session message ret = _z_transport_message_encode(&ztu->_wbuf, t_msg); if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed __unsafe_z_finalize_wbuf(&ztu->_wbuf, _Z_LINK_IS_STREAMED(ztu->_link._capabilities)); // Send the wbuf on the socket ret = _z_link_send_wbuf(&ztu->_link, &ztu->_wbuf); @@ -108,7 +108,7 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg if (ret == _Z_RES_OK) { ret = _z_network_message_encode(&ztu->_wbuf, n_msg); // Encode the network message if (ret == _Z_RES_OK) { - // Write the message legnth in the reserved space if needed + // Write the message length in the reserved space if needed __unsafe_z_finalize_wbuf(&ztu->_wbuf, _Z_LINK_IS_STREAMED(ztu->_link._capabilities)); if (ztu->_wbuf._ioss._len == 1) { diff --git a/tests/z_client_test.c b/tests/z_client_test.c index 80ca3c2e5..0c42ab132 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -199,7 +199,7 @@ int main(int argc, char **argv) { z_sleep_s(SLEEP); - // Write data from firt session + // Write data from first session size_t len = MSG_LEN; uint8_t *payload = (uint8_t *)z_malloc(len); memset(payload, 1, MSG_LEN); @@ -256,7 +256,7 @@ int main(int argc, char **argv) { assert(queries >= expected); queries = 0; - // Wait to receive all the expectred replies + // Wait to receive all the expected replies now = z_clock_now(); while (replies < expected) { assert(z_clock_elapsed_s(&now) < TIMEOUT); diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index 29b05223a..e1ede7104 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -113,7 +113,7 @@ int main(int argc, char **argv) { subs2 = _z_list_push(subs2, sub); } - // Write data from firt session + // Write data from first session size_t len = MSG_LEN; uint8_t *payload = (uint8_t *)z_malloc(len); memset(payload, 1, MSG_LEN); From b2ac6bc1f3d3ade287e7ac0307dea5c793e50211 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 5 Oct 2023 16:21:20 +0200 Subject: [PATCH 08/26] style: add missing disclaimers --- examples/unix/c11/z_ping.c | 14 ++++++++++++++ examples/unix/c11/z_pong.c | 14 ++++++++++++++ examples/unix/c11/z_scout.c | 1 - examples/unix/c99/z_ping.c | 14 ++++++++++++++ examples/unix/c99/z_pong.c | 14 ++++++++++++++ examples/windows/z_ping.c | 14 ++++++++++++++ examples/windows/z_pong.c | 14 ++++++++++++++ examples/windows/z_scout.c | 1 - src/protocol/codec/core.c | 15 +++++++++++++++ src/protocol/core.c | 14 ++++++++++++++ src/protocol/definitions/message.c | 14 ++++++++++++++ src/protocol/definitions/network.c | 14 ++++++++++++++ src/protocol/definitions/transport.c | 14 ++++++++++++++ 13 files changed, 155 insertions(+), 2 deletions(-) diff --git a/examples/unix/c11/z_ping.c b/examples/unix/c11/z_ping.c index 4db578c7e..dc9cbf4f7 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include #include #include diff --git a/examples/unix/c11/z_pong.c b/examples/unix/c11/z_pong.c index 503c37e25..8acf09564 100644 --- a/examples/unix/c11/z_pong.c +++ b/examples/unix/c11/z_pong.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "stdio.h" #include "zenoh-pico.h" diff --git a/examples/unix/c11/z_scout.c b/examples/unix/c11/z_scout.c index 751609db1..3a6950aad 100644 --- a/examples/unix/c11/z_scout.c +++ b/examples/unix/c11/z_scout.c @@ -1,4 +1,3 @@ - // // Copyright (c) 2022 ZettaScale Technology // diff --git a/examples/unix/c99/z_ping.c b/examples/unix/c99/z_ping.c index 379afd986..cbae19ccb 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include #include #include diff --git a/examples/unix/c99/z_pong.c b/examples/unix/c99/z_pong.c index 1f0955d56..53f6d14ee 100644 --- a/examples/unix/c99/z_pong.c +++ b/examples/unix/c99/z_pong.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "stdio.h" #include "zenoh-pico.h" #include "zenoh-pico/api/primitives.h" diff --git a/examples/windows/z_ping.c b/examples/windows/z_ping.c index fe25ed3c9..dcfb1fc8e 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include #include #include diff --git a/examples/windows/z_pong.c b/examples/windows/z_pong.c index c0d1cd0b0..698c086f7 100644 --- a/examples/windows/z_pong.c +++ b/examples/windows/z_pong.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "stdio.h" #include "zenoh-pico.h" diff --git a/examples/windows/z_scout.c b/examples/windows/z_scout.c index 8d7feea64..378a61327 100644 --- a/examples/windows/z_scout.c +++ b/examples/windows/z_scout.c @@ -1,4 +1,3 @@ - // // Copyright (c) 2022 ZettaScale Technology // diff --git a/src/protocol/codec/core.c b/src/protocol/codec/core.c index 403c28d8c..90ad38a4a 100644 --- a/src/protocol/codec/core.c +++ b/src/protocol/codec/core.c @@ -1,6 +1,21 @@ +// +// 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, +// + #include "zenoh-pico/protocol/codec/core.h" #include "zenoh-pico/protocol/iobuf.h" + int8_t _z_zbuf_read_exact(_z_zbuf_t *zbf, uint8_t *dest, size_t length) { if (length > _z_zbuf_len(zbf)) { return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; diff --git a/src/protocol/core.c b/src/protocol/core.c index c5cfc0c3f..b937f1e89 100644 --- a/src/protocol/core.c +++ b/src/protocol/core.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "zenoh-pico/protocol/core.h" #include "zenoh-pico/api/primitives.h" diff --git a/src/protocol/definitions/message.c b/src/protocol/definitions/message.c index fc6b14491..e3865635f 100644 --- a/src/protocol/definitions/message.c +++ b/src/protocol/definitions/message.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "zenoh-pico/protocol/definitions/message.h" #include "zenoh-pico/collections/bytes.h" diff --git a/src/protocol/definitions/network.c b/src/protocol/definitions/network.c index af852e4e2..56855657c 100644 --- a/src/protocol/definitions/network.c +++ b/src/protocol/definitions/network.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "zenoh-pico/protocol/definitions/network.h" #include "zenoh-pico/api/constants.h" diff --git a/src/protocol/definitions/transport.c b/src/protocol/definitions/transport.c index 3be09369f..6960672a4 100644 --- a/src/protocol/definitions/transport.c +++ b/src/protocol/definitions/transport.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "zenoh-pico/protocol/definitions/transport.h" #include "zenoh-pico/collections/bytes.h" From 9a7472d9ff81a352f1b125cffd92cc77c2e40b62 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 5 Oct 2023 16:21:56 +0200 Subject: [PATCH 09/26] chore: run clang-format --- include/zenoh-pico/api/primitives.h | 6 +++--- include/zenoh-pico/link/link.h | 6 +++--- tests/z_keyexpr_test.c | 15 +++++---------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 9b44c2c0e..68861d6f9 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1142,9 +1142,9 @@ z_queryable_options_t z_queryable_options_default(void); * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` where to declare the subscriber. * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. - * callback: A moved instance of :c:type:`z_owned_closure_query_t` containing the callbacks to be called and the context - * to pass to them. options: The options to apply to the queryable. If ``NULL`` is passed, the default options will be - * applied. + * callback: A moved instance of :c:type:`z_owned_closure_query_t` containing the callbacks to be called and the + * context to pass to them. options: The options to apply to the queryable. If ``NULL`` is passed, the default options + * will be applied. * * Returns: * A :c:type:`z_owned_queryable_t` with either a valid queryable or a failing queryable. diff --git a/include/zenoh-pico/link/link.h b/include/zenoh-pico/link/link.h index 10a892982..3f0400b20 100644 --- a/include/zenoh-pico/link/link.h +++ b/include/zenoh-pico/link/link.h @@ -52,10 +52,10 @@ * Z_LINK_CAPABILITY_MULTICAST: Bitmask to define and check if link is multicast. */ typedef enum { - Z_LINK_CAPABILITY_NONE = 0x00, // 0 + Z_LINK_CAPABILITY_NONE = 0x00, // 0 Z_LINK_CAPABILITY_RELIABLE = 0x01, // 1 << 0 - Z_LINK_CAPABILITY_STREAMED = 0x02, // 1 << 1 - Z_LINK_CAPABILITY_MULTICAST = 0x04 // 1 << 2 + Z_LINK_CAPABILITY_STREAMED = 0x02, // 1 << 1 + Z_LINK_CAPABILITY_MULTICAST = 0x04 // 1 << 2 } _z_link_capabilities_t; #define _Z_LINK_IS_RELIABLE(X) ((X & Z_LINK_CAPABILITY_RELIABLE) == Z_LINK_CAPABILITY_RELIABLE) diff --git a/tests/z_keyexpr_test.c b/tests/z_keyexpr_test.c index 9b9567f7a..d4cf921ef 100644 --- a/tests/z_keyexpr_test.c +++ b/tests/z_keyexpr_test.c @@ -20,8 +20,7 @@ #undef NDEBUG #include -int main(void) -{ +int main(void) { assert(_z_keyexpr_intersects("a", strlen("a"), "a", strlen("a"))); assert(_z_keyexpr_intersects("a/b", strlen("a/b"), "a/b", strlen("a/b"))); assert(_z_keyexpr_intersects("*", strlen("*"), "abc", strlen("abc"))); @@ -339,8 +338,7 @@ int main(void) // clang-format on - for (int i = 0; i < N; i++) - { + for (int i = 0; i < N; i++) { const char *ke = input[i]; char *canon = (char *)malloc(128); memset(canon, 0, 128); @@ -350,15 +348,13 @@ int main(void) printf("%s ", ke); printf(" Status: %d : %d\n", status, expected[i]); assert(status == expected[i]); - if (status == Z_KEYEXPR_CANON_SUCCESS) - { + if (status == Z_KEYEXPR_CANON_SUCCESS) { printf(" Match: %.*s : %s\n", (int)canon_len, canon, canonized[i]); assert(strncmp(canonized[i], canon, canon_len) == 0); } } - for (int i = 0; i < N; i++) - { + for (int i = 0; i < N; i++) { const char *ke = input[i]; char *canon = (char *)malloc(128); memset(canon, 0, 128); @@ -368,8 +364,7 @@ int main(void) printf("%s ", ke); printf(" Status: %d : %d", status, expected[i]); assert(status == expected[i]); - if (status == Z_KEYEXPR_CANON_SUCCESS) - { + if (status == Z_KEYEXPR_CANON_SUCCESS) { printf(" Match: %.*s : %s", (int)canon_len, canon, canonized[i]); assert(strcmp(canonized[i], canon) == 0); } From 45e80f7e7053b16bfd7cc6af0cf4efc88a5e50d0 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 5 Oct 2023 16:22:12 +0200 Subject: [PATCH 10/26] chore: remove empty source file --- src/protocol/definitions/core.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/protocol/definitions/core.c diff --git a/src/protocol/definitions/core.c b/src/protocol/definitions/core.c deleted file mode 100644 index e69de29bb..000000000 From c4f78b2165741578a259a72eab140afa5233303b Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Fri, 6 Oct 2023 09:51:57 +0200 Subject: [PATCH 11/26] Missing disclaimers & clang-format (#257) --- examples/unix/c11/z_ping.c | 14 ++++++++++++++ examples/unix/c11/z_pong.c | 14 ++++++++++++++ examples/unix/c11/z_scout.c | 1 - examples/unix/c99/z_ping.c | 14 ++++++++++++++ examples/unix/c99/z_pong.c | 14 ++++++++++++++ examples/windows/z_ping.c | 14 ++++++++++++++ examples/windows/z_pong.c | 14 ++++++++++++++ examples/windows/z_scout.c | 1 - include/zenoh-pico/api/primitives.h | 6 +++--- include/zenoh-pico/link/link.h | 6 +++--- src/protocol/codec/core.c | 15 +++++++++++++++ src/protocol/core.c | 14 ++++++++++++++ src/protocol/definitions/core.c | 0 src/protocol/definitions/message.c | 14 ++++++++++++++ src/protocol/definitions/network.c | 14 ++++++++++++++ src/protocol/definitions/transport.c | 14 ++++++++++++++ tests/z_keyexpr_test.c | 15 +++++---------- 17 files changed, 166 insertions(+), 18 deletions(-) delete mode 100644 src/protocol/definitions/core.c diff --git a/examples/unix/c11/z_ping.c b/examples/unix/c11/z_ping.c index 4db578c7e..dc9cbf4f7 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include #include #include diff --git a/examples/unix/c11/z_pong.c b/examples/unix/c11/z_pong.c index 503c37e25..8acf09564 100644 --- a/examples/unix/c11/z_pong.c +++ b/examples/unix/c11/z_pong.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "stdio.h" #include "zenoh-pico.h" diff --git a/examples/unix/c11/z_scout.c b/examples/unix/c11/z_scout.c index 751609db1..3a6950aad 100644 --- a/examples/unix/c11/z_scout.c +++ b/examples/unix/c11/z_scout.c @@ -1,4 +1,3 @@ - // // Copyright (c) 2022 ZettaScale Technology // diff --git a/examples/unix/c99/z_ping.c b/examples/unix/c99/z_ping.c index 379afd986..cbae19ccb 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include #include #include diff --git a/examples/unix/c99/z_pong.c b/examples/unix/c99/z_pong.c index 1f0955d56..53f6d14ee 100644 --- a/examples/unix/c99/z_pong.c +++ b/examples/unix/c99/z_pong.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "stdio.h" #include "zenoh-pico.h" #include "zenoh-pico/api/primitives.h" diff --git a/examples/windows/z_ping.c b/examples/windows/z_ping.c index fe25ed3c9..dcfb1fc8e 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include #include #include diff --git a/examples/windows/z_pong.c b/examples/windows/z_pong.c index c0d1cd0b0..698c086f7 100644 --- a/examples/windows/z_pong.c +++ b/examples/windows/z_pong.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "stdio.h" #include "zenoh-pico.h" diff --git a/examples/windows/z_scout.c b/examples/windows/z_scout.c index 8d7feea64..378a61327 100644 --- a/examples/windows/z_scout.c +++ b/examples/windows/z_scout.c @@ -1,4 +1,3 @@ - // // Copyright (c) 2022 ZettaScale Technology // diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 9b44c2c0e..68861d6f9 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1142,9 +1142,9 @@ z_queryable_options_t z_queryable_options_default(void); * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` where to declare the subscriber. * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. - * callback: A moved instance of :c:type:`z_owned_closure_query_t` containing the callbacks to be called and the context - * to pass to them. options: The options to apply to the queryable. If ``NULL`` is passed, the default options will be - * applied. + * callback: A moved instance of :c:type:`z_owned_closure_query_t` containing the callbacks to be called and the + * context to pass to them. options: The options to apply to the queryable. If ``NULL`` is passed, the default options + * will be applied. * * Returns: * A :c:type:`z_owned_queryable_t` with either a valid queryable or a failing queryable. diff --git a/include/zenoh-pico/link/link.h b/include/zenoh-pico/link/link.h index 10a892982..3f0400b20 100644 --- a/include/zenoh-pico/link/link.h +++ b/include/zenoh-pico/link/link.h @@ -52,10 +52,10 @@ * Z_LINK_CAPABILITY_MULTICAST: Bitmask to define and check if link is multicast. */ typedef enum { - Z_LINK_CAPABILITY_NONE = 0x00, // 0 + Z_LINK_CAPABILITY_NONE = 0x00, // 0 Z_LINK_CAPABILITY_RELIABLE = 0x01, // 1 << 0 - Z_LINK_CAPABILITY_STREAMED = 0x02, // 1 << 1 - Z_LINK_CAPABILITY_MULTICAST = 0x04 // 1 << 2 + Z_LINK_CAPABILITY_STREAMED = 0x02, // 1 << 1 + Z_LINK_CAPABILITY_MULTICAST = 0x04 // 1 << 2 } _z_link_capabilities_t; #define _Z_LINK_IS_RELIABLE(X) ((X & Z_LINK_CAPABILITY_RELIABLE) == Z_LINK_CAPABILITY_RELIABLE) diff --git a/src/protocol/codec/core.c b/src/protocol/codec/core.c index 403c28d8c..90ad38a4a 100644 --- a/src/protocol/codec/core.c +++ b/src/protocol/codec/core.c @@ -1,6 +1,21 @@ +// +// 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, +// + #include "zenoh-pico/protocol/codec/core.h" #include "zenoh-pico/protocol/iobuf.h" + int8_t _z_zbuf_read_exact(_z_zbuf_t *zbf, uint8_t *dest, size_t length) { if (length > _z_zbuf_len(zbf)) { return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; diff --git a/src/protocol/core.c b/src/protocol/core.c index c5cfc0c3f..b937f1e89 100644 --- a/src/protocol/core.c +++ b/src/protocol/core.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "zenoh-pico/protocol/core.h" #include "zenoh-pico/api/primitives.h" diff --git a/src/protocol/definitions/core.c b/src/protocol/definitions/core.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/protocol/definitions/message.c b/src/protocol/definitions/message.c index fc6b14491..e3865635f 100644 --- a/src/protocol/definitions/message.c +++ b/src/protocol/definitions/message.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "zenoh-pico/protocol/definitions/message.h" #include "zenoh-pico/collections/bytes.h" diff --git a/src/protocol/definitions/network.c b/src/protocol/definitions/network.c index af852e4e2..56855657c 100644 --- a/src/protocol/definitions/network.c +++ b/src/protocol/definitions/network.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "zenoh-pico/protocol/definitions/network.h" #include "zenoh-pico/api/constants.h" diff --git a/src/protocol/definitions/transport.c b/src/protocol/definitions/transport.c index 3be09369f..6960672a4 100644 --- a/src/protocol/definitions/transport.c +++ b/src/protocol/definitions/transport.c @@ -1,3 +1,17 @@ +// +// 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, +// + #include "zenoh-pico/protocol/definitions/transport.h" #include "zenoh-pico/collections/bytes.h" diff --git a/tests/z_keyexpr_test.c b/tests/z_keyexpr_test.c index 9b9567f7a..d4cf921ef 100644 --- a/tests/z_keyexpr_test.c +++ b/tests/z_keyexpr_test.c @@ -20,8 +20,7 @@ #undef NDEBUG #include -int main(void) -{ +int main(void) { assert(_z_keyexpr_intersects("a", strlen("a"), "a", strlen("a"))); assert(_z_keyexpr_intersects("a/b", strlen("a/b"), "a/b", strlen("a/b"))); assert(_z_keyexpr_intersects("*", strlen("*"), "abc", strlen("abc"))); @@ -339,8 +338,7 @@ int main(void) // clang-format on - for (int i = 0; i < N; i++) - { + for (int i = 0; i < N; i++) { const char *ke = input[i]; char *canon = (char *)malloc(128); memset(canon, 0, 128); @@ -350,15 +348,13 @@ int main(void) printf("%s ", ke); printf(" Status: %d : %d\n", status, expected[i]); assert(status == expected[i]); - if (status == Z_KEYEXPR_CANON_SUCCESS) - { + if (status == Z_KEYEXPR_CANON_SUCCESS) { printf(" Match: %.*s : %s\n", (int)canon_len, canon, canonized[i]); assert(strncmp(canonized[i], canon, canon_len) == 0); } } - for (int i = 0; i < N; i++) - { + for (int i = 0; i < N; i++) { const char *ke = input[i]; char *canon = (char *)malloc(128); memset(canon, 0, 128); @@ -368,8 +364,7 @@ int main(void) printf("%s ", ke); printf(" Status: %d : %d", status, expected[i]); assert(status == expected[i]); - if (status == Z_KEYEXPR_CANON_SUCCESS) - { + if (status == Z_KEYEXPR_CANON_SUCCESS) { printf(" Match: %.*s : %s", (int)canon_len, canon, canonized[i]); assert(strcmp(canonized[i], canon) == 0); } From c84c0921e50360f6fa35894efbdde71be0ecc399 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Mon, 9 Oct 2023 10:05:11 +0200 Subject: [PATCH 12/26] refactor: rename feature config tokens --- extra_script.py | 2 +- include/zenoh-pico/config.h | 162 +++++++++--------- include/zenoh-pico/link/config/bt.h | 2 +- include/zenoh-pico/link/config/serial.h | 2 +- include/zenoh-pico/link/config/tcp.h | 2 +- include/zenoh-pico/link/config/udp.h | 2 +- include/zenoh-pico/link/config/ws.h | 2 +- include/zenoh-pico/link/endpoint.h | 10 +- include/zenoh-pico/link/link.h | 20 +-- include/zenoh-pico/link/manager.h | 12 +- include/zenoh-pico/net/session.h | 8 +- include/zenoh-pico/session/session.h | 4 +- include/zenoh-pico/system/link/bt.h | 2 +- include/zenoh-pico/system/link/serial.h | 2 +- include/zenoh-pico/system/link/tcp.h | 2 +- include/zenoh-pico/system/link/udp.h | 2 +- include/zenoh-pico/system/link/ws.h | 2 +- include/zenoh-pico/system/platform.h | 4 +- .../system/platform/arduino/esp32.h | 16 +- .../system/platform/arduino/opencr.h | 10 +- .../zenoh-pico/system/platform/emscripten.h | 8 +- include/zenoh-pico/system/platform/espidf.h | 10 +- include/zenoh-pico/system/platform/mbed.h | 12 +- include/zenoh-pico/system/platform/unix.h | 8 +- include/zenoh-pico/system/platform/void.h | 4 +- include/zenoh-pico/system/platform/windows.h | 8 +- include/zenoh-pico/system/platform/zephyr.h | 10 +- include/zenoh-pico/transport/transport.h | 16 +- src/api/api.c | 40 ++--- src/link/config/bt.c | 2 +- src/link/config/serial.c | 2 +- src/link/config/tcp.c | 2 +- src/link/config/udp.c | 2 +- src/link/config/ws.c | 2 +- src/link/endpoint.c | 40 ++--- src/link/link.c | 14 +- src/link/multicast/bt.c | 2 +- src/link/multicast/udp.c | 2 +- src/link/unicast/serial.c | 2 +- src/link/unicast/tcp.c | 2 +- src/link/unicast/udp.c | 2 +- src/link/unicast/ws.c | 2 +- src/net/session.c | 46 ++--- src/session/query.c | 48 +++--- src/session/queryable.c | 52 +++--- src/session/resource.c | 56 +++--- src/session/scout.c | 10 +- src/session/subscription.c | 52 +++--- src/session/tx.c | 8 +- src/session/utils.c | 16 +- src/system/arduino/esp32/network.cpp | 12 +- src/system/arduino/esp32/system.c | 4 +- src/system/arduino/opencr/network.cpp | 12 +- src/system/arduino/opencr/system.c | 6 +- src/system/emscripten/network.c | 10 +- src/system/emscripten/system.c | 4 +- src/system/espidf/network.c | 12 +- src/system/espidf/system.c | 4 +- src/system/mbed/network.cpp | 12 +- src/system/mbed/system.cpp | 4 +- src/system/unix/network.c | 12 +- src/system/unix/system.c | 4 +- src/system/windows/network.c | 12 +- src/system/windows/system.c | 4 +- src/system/zephyr/network.c | 14 +- src/system/zephyr/system.c | 4 +- src/transport/common/join.c | 4 +- src/transport/common/lease.c | 16 +- src/transport/common/read.c | 16 +- src/transport/common/tx.c | 12 +- src/transport/manager.c | 16 +- src/transport/multicast/link/rx.c | 22 +-- src/transport/multicast/link/task/join.c | 4 +- src/transport/multicast/link/task/lease.c | 8 +- src/transport/multicast/link/task/read.c | 8 +- src/transport/multicast/link/tx.c | 24 +-- src/transport/transport.c | 100 +++++------ src/transport/unicast/link/rx.c | 12 +- src/transport/unicast/link/task/lease.c | 8 +- src/transport/unicast/link/task/read.c | 8 +- src/transport/unicast/link/tx.c | 24 +-- 81 files changed, 581 insertions(+), 579 deletions(-) diff --git a/extra_script.py b/extra_script.py index 391eb8047..3d4780ca8 100644 --- a/extra_script.py +++ b/extra_script.py @@ -57,7 +57,7 @@ "-", "-", "-"] - CPPDEFINES = ["ZENOH_ARDUINO_OPENCR", "ZENOH_C_STANDARD=99", "Z_MULTI_THREAD=0"] + CPPDEFINES = ["ZENOH_ARDUINO_OPENCR", "ZENOH_C_STANDARD=99", "Z_FEATURE_MULTI_THREAD=0"] elif FRAMEWORK == 'espidf': SRC_FILTER = ["+<*>", diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index 21fa2063a..fa2a3ff2a 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -102,117 +102,148 @@ #define Z_CONFIG_ADD_TIMESTAMP_KEY 0x4A #define Z_CONFIG_ADD_TIMESTAMP_DEFAULT "false" -/*------------------ Compile-time configuration properties ------------------*/ +/*------------------ Compile-time feature configuration ------------------*/ + /** - * Default length for Zenoh ID. Maximum size is 16 bytes. - * This configuration will only be applied to Zenoh IDs generated by Zenoh-Pico. + * Enable multi-thread support. */ -#ifndef Z_ZID_LENGTH -#define Z_ZID_LENGTH 16 +#ifndef Z_FEATURE_MULTI_THREAD +#define Z_FEATURE_MULTI_THREAD 1 #endif -#ifndef Z_TSID_LENGTH -#define Z_TSID_LENGTH 16 +/** + * Enable dynamic memory allocation. + */ +#ifndef Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION +#define Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION 0 #endif /** - * Protocol version identifier. - * Do not change this value. + * Enable TCP links. */ -#ifndef Z_PROTO_VERSION -#define Z_PROTO_VERSION 0x08 +#ifndef Z_FEATURE_LINK_TCP +#define Z_FEATURE_LINK_TCP 1 #endif /** - * Default session lease in milliseconds. + * Enable Bluetooth links. */ -#ifndef Z_TRANSPORT_LEASE -#define Z_TRANSPORT_LEASE 10000 +#ifndef Z_FEATURE_LINK_BLUETOOTH +#define Z_FEATURE_LINK_BLUETOOTH 0 #endif /** - * Default session lease expire factor. + * Enable WebSocket links. */ -#ifndef Z_TRANSPORT_LEASE_EXPIRE_FACTOR -#define Z_TRANSPORT_LEASE_EXPIRE_FACTOR 3.5 +#ifndef Z_FEATURE_LINK_WS +#define Z_FEATURE_LINK_WS 0 #endif /** - * Default multicast session join interval in milliseconds. + * Enable Serial links. */ -#ifndef Z_JOIN_INTERVAL -#define Z_JOIN_INTERVAL 2500 +#ifndef Z_FEATURE_LINK_SERIAL +#define Z_FEATURE_LINK_SERIAL 0 #endif /** - * Default socket timeout in milliseconds. + * Enable UDP Scouting. */ -#ifndef Z_CONFIG_SOCKET_TIMEOUT -#define Z_CONFIG_SOCKET_TIMEOUT 100 +#ifndef Z_FEATURE_SCOUTING_UDP +#define Z_FEATURE_SCOUTING_UDP 1 #endif -#ifndef Z_SN_RESOLUTION -#define Z_SN_RESOLUTION 0x02 +/** + * Enable UDP Multicast links. + */ +#ifndef Z_FEATURE_LINK_UDP_MULTICAST +#define Z_FEATURE_LINK_UDP_MULTICAST 1 #endif -#ifndef Z_REQ_RESOLUTION -#define Z_REQ_RESOLUTION 0x02 +/** + * Enable UDP Unicast links. + */ +#ifndef Z_FEATURE_LINK_UDP_UNICAST +#define Z_FEATURE_LINK_UDP_UNICAST 1 #endif /** - * Enable multi-thread support. + * Enable Multicast Transport. */ -#ifndef Z_MULTI_THREAD -#define Z_MULTI_THREAD 1 +#ifndef Z_FEATURE_MULTICAST_TRANSPORT +#if Z_FEATURE_SCOUTING_UDP == 0 && Z_FEATURE_LINK_BLUETOOTH == 0 && Z_FEATURE_LINK_UDP_MULTICAST == 0 +#define Z_FEATURE_MULTICAST_TRANSPORT 0 +#else +#define Z_FEATURE_MULTICAST_TRANSPORT 1 +#endif #endif /** - * Enable TCP links. + * Enable Unicast Transport. */ -#ifndef Z_LINK_TCP -#define Z_LINK_TCP 1 +#ifndef Z_FEATURE_UNICAST_TRANSPORT +#if Z_FEATURE_LINK_TCP == 0 && Z_FEATURE_LINK_UDP_UNICAST == 0 && Z_FEATURE_LINK_SERIAL == 0 && Z_FEATURE_LINK_WS == 0 +#define Z_FEATURE_UNICAST_TRANSPORT 0 +#else +#define Z_FEATURE_UNICAST_TRANSPORT 1 +#endif #endif +/*------------------ Compile-time configuration properties ------------------*/ /** - * Enable UDP Multicast links. + * Default length for Zenoh ID. Maximum size is 16 bytes. + * This configuration will only be applied to Zenoh IDs generated by Zenoh-Pico. */ -#ifndef Z_LINK_UDP_MULTICAST -#define Z_LINK_UDP_MULTICAST 1 +#ifndef Z_ZID_LENGTH +#define Z_ZID_LENGTH 16 +#endif + +#ifndef Z_TSID_LENGTH +#define Z_TSID_LENGTH 16 #endif /** - * Enable UDP Unicast links. + * Protocol version identifier. + * Do not change this value. */ -#ifndef Z_LINK_UDP_UNICAST -#define Z_LINK_UDP_UNICAST 1 +#ifndef Z_PROTO_VERSION +#define Z_PROTO_VERSION 0x08 #endif /** - * Enable Bluetooth links. + * Default session lease in milliseconds. */ -#ifndef Z_LINK_BLUETOOTH -#define Z_LINK_BLUETOOTH 0 +#ifndef Z_TRANSPORT_LEASE +#define Z_TRANSPORT_LEASE 10000 #endif /** - * Enable Serial links. + * Default session lease expire factor. */ -#ifndef Z_LINK_SERIAL -#define Z_LINK_SERIAL 0 +#ifndef Z_TRANSPORT_LEASE_EXPIRE_FACTOR +#define Z_TRANSPORT_LEASE_EXPIRE_FACTOR 3.5 #endif /** - * Enable WebSocket links. + * Default multicast session join interval in milliseconds. */ -#ifndef Z_LINK_WS -#define Z_LINK_WS 0 +#ifndef Z_JOIN_INTERVAL +#define Z_JOIN_INTERVAL 2500 #endif /** - * Enable UDP Scouting. + * Default socket timeout in milliseconds. */ -#ifndef Z_SCOUTING_UDP -#define Z_SCOUTING_UDP 1 +#ifndef Z_CONFIG_SOCKET_TIMEOUT +#define Z_CONFIG_SOCKET_TIMEOUT 100 +#endif + +#ifndef Z_SN_RESOLUTION +#define Z_SN_RESOLUTION 0x02 +#endif + +#ifndef Z_REQ_RESOLUTION +#define Z_REQ_RESOLUTION 0x02 #endif /** @@ -242,33 +273,4 @@ #define Z_FRAG_MAX_SIZE 300000 #endif -/** - * Enable dynamic memory allocation. - */ -#ifndef Z_DYNAMIC_MEMORY_ALLOCATION -#define Z_DYNAMIC_MEMORY_ALLOCATION 0 -#endif - -/** - * Enable Multicast Transport. - */ -#ifndef Z_MULTICAST_TRANSPORT -#if Z_SCOUTING_UDP == 0 && Z_LINK_BLUETOOTH == 0 && Z_LINK_UDP_MULTICAST == 0 -#define Z_MULTICAST_TRANSPORT 0 -#else -#define Z_MULTICAST_TRANSPORT 1 -#endif -#endif - -/** - * Enable Unicast Transport. - */ -#ifndef Z_UNICAST_TRANSPORT -#if Z_LINK_TCP == 0 && Z_LINK_UDP_UNICAST == 0 && Z_LINK_SERIAL == 0 && Z_LINK_WS == 0 -#define Z_UNICAST_TRANSPORT 0 -#else -#define Z_UNICAST_TRANSPORT 1 -#endif -#endif - #endif /* INCLUDE_ZENOH_PICO_CONFIG_H */ diff --git a/include/zenoh-pico/link/config/bt.h b/include/zenoh-pico/link/config/bt.h index ae24fa245..40827e76c 100644 --- a/include/zenoh-pico/link/config/bt.h +++ b/include/zenoh-pico/link/config/bt.h @@ -19,7 +19,7 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #define BT_CONFIG_ARGC 3 diff --git a/include/zenoh-pico/link/config/serial.h b/include/zenoh-pico/link/config/serial.h index 3b5fd16a6..85270be62 100644 --- a/include/zenoh-pico/link/config/serial.h +++ b/include/zenoh-pico/link/config/serial.h @@ -20,7 +20,7 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #define SERIAL_CONFIG_ARGC 1 diff --git a/include/zenoh-pico/link/config/tcp.h b/include/zenoh-pico/link/config/tcp.h index a5d758544..ed57e7700 100644 --- a/include/zenoh-pico/link/config/tcp.h +++ b/include/zenoh-pico/link/config/tcp.h @@ -19,7 +19,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/config.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #define TCP_CONFIG_ARGC 1 diff --git a/include/zenoh-pico/link/config/udp.h b/include/zenoh-pico/link/config/udp.h index 877896493..ab8875d5e 100644 --- a/include/zenoh-pico/link/config/udp.h +++ b/include/zenoh-pico/link/config/udp.h @@ -18,7 +18,7 @@ #include "zenoh-pico/collections/intmap.h" #include "zenoh-pico/collections/string.h" -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #define UDP_CONFIG_ARGC 3 diff --git a/include/zenoh-pico/link/config/ws.h b/include/zenoh-pico/link/config/ws.h index 1551bc31e..82ef8d596 100644 --- a/include/zenoh-pico/link/config/ws.h +++ b/include/zenoh-pico/link/config/ws.h @@ -19,7 +19,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/config.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #define WS_CONFIG_TOUT_KEY 0x01 #define WS_CONFIG_TOUT_STR "tout" diff --git a/include/zenoh-pico/link/endpoint.h b/include/zenoh-pico/link/endpoint.h index c3cf1b42a..bd7c8cbc3 100644 --- a/include/zenoh-pico/link/endpoint.h +++ b/include/zenoh-pico/link/endpoint.h @@ -22,19 +22,19 @@ #include "zenoh-pico/utils/result.h" /*------------------ Locator ------------------*/ -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #define TCP_SCHEMA "tcp" #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #define UDP_SCHEMA "udp" #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #define BT_SCHEMA "bt" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #define SERIAL_SCHEMA "serial" #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #define WS_SCHEMA "ws" #endif diff --git a/include/zenoh-pico/link/link.h b/include/zenoh-pico/link/link.h index 3f0400b20..9a49f2862 100644 --- a/include/zenoh-pico/link/link.h +++ b/include/zenoh-pico/link/link.h @@ -20,23 +20,23 @@ #include "zenoh-pico/protocol/iobuf.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #include "zenoh-pico/system/link/tcp.h" #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #include "zenoh-pico/system/link/udp.h" #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #include "zenoh-pico/system/link/bt.h" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #include "zenoh-pico/system/link/serial.h" #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #include "zenoh-pico/system/link/ws.h" #endif @@ -77,19 +77,19 @@ typedef struct _z_link_t { _z_endpoint_t _endpoint; union { -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 _z_tcp_socket_t _tcp; #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 _z_udp_socket_t _udp; #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 _z_bt_socket_t _bt; #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 _z_serial_socket_t _serial; #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 _z_ws_socket_t _ws; #endif } _socket; diff --git a/include/zenoh-pico/link/manager.h b/include/zenoh-pico/link/manager.h index fefeea002..f494784e4 100644 --- a/include/zenoh-pico/link/manager.h +++ b/include/zenoh-pico/link/manager.h @@ -19,27 +19,27 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/link/link.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 int8_t _z_endpoint_tcp_valid(_z_endpoint_t *ep); int8_t _z_new_link_tcp(_z_link_t *zl, _z_endpoint_t *ep); #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *ep); int8_t _z_new_link_udp_unicast(_z_link_t *zl, _z_endpoint_t ep); #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *ep); int8_t _z_new_link_udp_multicast(_z_link_t *zl, _z_endpoint_t ep); #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 int8_t _z_endpoint_bt_valid(_z_endpoint_t *ep); int8_t _z_new_link_bt(_z_link_t *zl, _z_endpoint_t ep); #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 int8_t _z_endpoint_serial_valid(_z_endpoint_t *ep); int8_t _z_new_link_serial(_z_link_t *zl, _z_endpoint_t ep); #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 int8_t _z_endpoint_ws_valid(_z_endpoint_t *ep); int8_t _z_new_link_ws(_z_link_t *zl, _z_endpoint_t *ep); #endif diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index bebe7608c..a23fb84dc 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -28,9 +28,9 @@ * A zenoh-net session. */ typedef struct { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_t _mutex_inner; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Zenoh-pico is considering a single transport per session. _z_transport_t _tp; @@ -122,7 +122,7 @@ int8_t _zp_send_keep_alive(_z_session_t *z); */ int8_t _zp_send_join(_z_session_t *z); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /** * Start a separate task to read from the network and process the messages * as soon as they are received. Note that the task can be implemented in @@ -172,6 +172,6 @@ int8_t _zp_start_lease_task(_z_session_t *z); * ``0`` in case of success, ``-1`` in case of failure. */ int8_t _zp_stop_lease_task(_z_session_t *z); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 #endif /* INCLUDE_ZENOH_PICO_NET_SESSION_H */ diff --git a/include/zenoh-pico/session/session.h b/include/zenoh-pico/session/session.h index 8b394e844..a6102da23 100644 --- a/include/zenoh-pico/session/session.h +++ b/include/zenoh-pico/session/session.h @@ -170,10 +170,10 @@ _Z_ELEM_DEFINE(_z_pending_query, _z_pending_query_t, _z_noop_size, _z_pending_qu _Z_LIST_DEFINE(_z_pending_query, _z_pending_query_t) typedef struct { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_t _mutex; _z_condvar_t _cond_var; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_reply_data_list_t *_replies; } _z_pending_query_collect_t; diff --git a/include/zenoh-pico/system/link/bt.h b/include/zenoh-pico/system/link/bt.h index 86fe2bbcf..b155e34b3 100644 --- a/include/zenoh-pico/system/link/bt.h +++ b/include/zenoh-pico/system/link/bt.h @@ -19,7 +19,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/config.h" -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #ifdef __cplusplus extern "C" { diff --git a/include/zenoh-pico/system/link/serial.h b/include/zenoh-pico/system/link/serial.h index 1fa81c7af..954fd2911 100644 --- a/include/zenoh-pico/system/link/serial.h +++ b/include/zenoh-pico/system/link/serial.h @@ -21,7 +21,7 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #define _Z_SERIAL_MTU_SIZE 1500 #define _Z_SERIAL_MFS_SIZE _Z_SERIAL_MTU_SIZE + 2 + 4 // MTU + Serial Len + Serial CRC32 diff --git a/include/zenoh-pico/system/link/tcp.h b/include/zenoh-pico/system/link/tcp.h index 382b8b7de..e90b688eb 100644 --- a/include/zenoh-pico/system/link/tcp.h +++ b/include/zenoh-pico/system/link/tcp.h @@ -20,7 +20,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 typedef struct { _z_sys_net_socket_t _sock; diff --git a/include/zenoh-pico/system/link/udp.h b/include/zenoh-pico/system/link/udp.h index a154c20f0..8b6957812 100644 --- a/include/zenoh-pico/system/link/udp.h +++ b/include/zenoh-pico/system/link/udp.h @@ -20,7 +20,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 typedef struct { _z_sys_net_socket_t _sock; diff --git a/include/zenoh-pico/system/link/ws.h b/include/zenoh-pico/system/link/ws.h index feab79328..52edd2f11 100644 --- a/include/zenoh-pico/system/link/ws.h +++ b/include/zenoh-pico/system/link/ws.h @@ -20,7 +20,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 typedef struct { _z_sys_net_socket_t _sock; diff --git a/include/zenoh-pico/system/platform.h b/include/zenoh-pico/system/platform.h index 07e1f009e..4a8697800 100644 --- a/include/zenoh-pico/system/platform.h +++ b/include/zenoh-pico/system/platform.h @@ -56,7 +56,7 @@ void *z_malloc(size_t size); void *z_realloc(void *ptr, size_t size); void z_free(void *ptr); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Thread ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg); int8_t _z_task_join(_z_task_t *task); @@ -77,7 +77,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv); int8_t _z_condvar_signal(_z_condvar_t *cv); int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time); diff --git a/include/zenoh-pico/system/platform/arduino/esp32.h b/include/zenoh-pico/system/platform/arduino/esp32.h index bac42aa72..569efe46f 100644 --- a/include/zenoh-pico/system/platform/arduino/esp32.h +++ b/include/zenoh-pico/system/platform/arduino/esp32.h @@ -19,16 +19,16 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 #include -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef TaskHandle_t _z_task_t; typedef void *_z_task_attr_t; // Not used in ESP32 typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; @@ -38,13 +38,13 @@ typedef struct HardwareSerial HardwareSerial; // Forward declaration to be us typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 int _fd; #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 BluetoothSerial *_bts; // As pointer to cross the boundary between C and C++ #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 HardwareSerial *_serial; // As pointer to cross the boundary between C and C++ #endif }; @@ -52,7 +52,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/arduino/opencr.h b/include/zenoh-pico/system/platform/arduino/opencr.h index 23c43f222..2a7488775 100644 --- a/include/zenoh-pico/system/platform/arduino/opencr.h +++ b/include/zenoh-pico/system/platform/arduino/opencr.h @@ -20,12 +20,12 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef void *_z_task_t; typedef void *_z_task_attr_t; typedef void *_z_mutex_t; typedef void *_z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; @@ -36,10 +36,10 @@ typedef struct WiFiUDP WiFiUDP; // Forward declaration to be used in _z_s typedef struct { union { -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 WiFiClient *_tcp; // As pointer to cross the boundary between C and C++ #endif -#if Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 WiFiUDP *_udp; // As pointer to cross the boundary between C and C++ #endif _Bool _err; @@ -53,7 +53,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 __z_net_iptcp_addr_t _iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/emscripten.h b/include/zenoh-pico/system/platform/emscripten.h index a2f340921..fcb732aab 100644 --- a/include/zenoh-pico/system/platform/emscripten.h +++ b/include/zenoh-pico/system/platform/emscripten.h @@ -20,19 +20,19 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef pthread_t _z_task_t; typedef pthread_attr_t _z_task_attr_t; typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef double z_clock_t; typedef double z_time_t; typedef struct { union { -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 struct { int _fd; uint32_t _tout; @@ -43,7 +43,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/espidf.h b/include/zenoh-pico/system/platform/espidf.h index 6c35dd1f0..2ba7773d7 100644 --- a/include/zenoh-pico/system/platform/espidf.h +++ b/include/zenoh-pico/system/platform/espidf.h @@ -22,22 +22,22 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef TaskHandle_t _z_task_t; typedef void *_z_task_attr_t; // Not used in ESP32 typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 int _fd; #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 uart_port_t _serial; #endif }; @@ -45,7 +45,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/mbed.h b/include/zenoh-pico/system/platform/mbed.h index ca10d0459..ba18844e8 100644 --- a/include/zenoh-pico/system/platform/mbed.h +++ b/include/zenoh-pico/system/platform/mbed.h @@ -22,12 +22,12 @@ typedef int _z_socket_t; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef void *_z_task_t; // Workaround as MBED is a C++ library typedef void *_z_task_attr_t; // Workaround as MBED is a C++ library typedef void *_z_mutex_t; // Workaround as MBED is a C++ library typedef void *_z_condvar_t; // Workaround as MBED is a C++ library -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef void *z_clock_t; // Not defined typedef struct timeval z_time_t; @@ -40,13 +40,13 @@ typedef struct SocketAddress SocketAddress; // Forward declaration to be used typedef struct { _Bool _err; union { -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 TCPSocket *_tcp; // As pointer to cross the boundary between C and C++ #endif -#if Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 UDPSocket *_udp; // As pointer to cross the boundary between C and C++ #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 BufferedSerial *_serial; // As pointer to cross the boundary between C and C++ #endif }; @@ -55,7 +55,7 @@ typedef struct { typedef struct { _Bool _err; union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 SocketAddress *_iptcp; // As pointer to cross the boundary between C and C++ #endif }; diff --git a/include/zenoh-pico/system/platform/unix.h b/include/zenoh-pico/system/platform/unix.h index 3faa48333..8084e22db 100644 --- a/include/zenoh-pico/system/platform/unix.h +++ b/include/zenoh-pico/system/platform/unix.h @@ -23,19 +23,19 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef pthread_t _z_task_t; typedef pthread_attr_t _z_task_attr_t; typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 int _fd; #endif }; @@ -43,7 +43,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/void.h b/include/zenoh-pico/system/platform/void.h index 26197d375..8bebe22f2 100644 --- a/include/zenoh-pico/system/platform/void.h +++ b/include/zenoh-pico/system/platform/void.h @@ -17,12 +17,12 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef void *_z_task_t; typedef void *_z_task_attr_t; typedef void *_z_mutex_t; typedef void *_z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef void *z_clock_t; typedef void *z_time_t; diff --git a/include/zenoh-pico/system/platform/windows.h b/include/zenoh-pico/system/platform/windows.h index f7c7d1ccb..fa5aff62d 100644 --- a/include/zenoh-pico/system/platform/windows.h +++ b/include/zenoh-pico/system/platform/windows.h @@ -20,19 +20,19 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef HANDLE *_z_task_t; typedef void *_z_task_attr_t; // Not used in Windows typedef SRWLOCK _z_mutex_t; typedef CONDITION_VARIABLE _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timeb z_clock_t; typedef struct timeb z_time_t; typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 SOCKET _fd; #endif } _sock; @@ -40,7 +40,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif } _ep; diff --git a/include/zenoh-pico/system/platform/zephyr.h b/include/zenoh-pico/system/platform/zephyr.h index 4b318c9d9..c0ad3c378 100644 --- a/include/zenoh-pico/system/platform/zephyr.h +++ b/include/zenoh-pico/system/platform/zephyr.h @@ -30,22 +30,22 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef pthread_t _z_task_t; typedef pthread_attr_t _z_task_attr_t; typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 int _fd; #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 const struct device *_serial; #endif }; @@ -53,7 +53,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/transport/transport.h b/include/zenoh-pico/transport/transport.h index 1982b1b92..6996f4b5a 100644 --- a/include/zenoh-pico/transport/transport.h +++ b/include/zenoh-pico/transport/transport.h @@ -56,11 +56,11 @@ _z_transport_peer_entry_list_t *_z_transport_peer_entry_list_insert(_z_transport typedef struct { // Session associated to the transport -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // TX and RX mutexes _z_mutex_t _mutex_rx; _z_mutex_t _mutex_tx; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_link_t _link; @@ -82,12 +82,12 @@ typedef struct { void *_session; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_task_t *_read_task; _z_task_t *_lease_task; volatile _Bool _read_task_running; volatile _Bool _lease_task_running; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 volatile _Bool _received; volatile _Bool _transmitted; @@ -97,14 +97,14 @@ typedef struct { // Session associated to the transport void *_session; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // TX and RX mutexes _z_mutex_t _mutex_rx; _z_mutex_t _mutex_tx; // Peer list mutex _z_mutex_t _mutex_peer; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_link_t _link; @@ -121,12 +121,12 @@ typedef struct { // Known valid peers _z_transport_peer_entry_list_t *_peers; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_task_t *_read_task; _z_task_t *_lease_task; volatile _Bool _read_task_running; volatile _Bool _lease_task_running; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 volatile _Bool _transmitted; } _z_transport_multicast_t; diff --git a/src/api/api.c b/src/api/api.c index db8d725e9..b673e3659 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -561,7 +561,7 @@ int8_t z_info_peers_zid(const z_session_t zs, z_owned_closure_zid_t *callback) { void *ctx = callback->context; callback->context = NULL; -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zs._val->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { _z_transport_peer_entry_list_t *l = zs._val->_tp._transport._multicast._peers; for (; l != NULL; l = _z_transport_peer_entry_list_tail(l)) { @@ -573,7 +573,7 @@ int8_t z_info_peers_zid(const z_session_t zs, z_owned_closure_zid_t *callback) { } #else (void)zs; -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 if (callback->drop != NULL) { callback->drop(ctx); @@ -586,12 +586,12 @@ int8_t z_info_routers_zid(const z_session_t zs, z_owned_closure_zid_t *callback) void *ctx = callback->context; callback->context = NULL; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zs._val->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { z_id_t id = zs._val->_tp._transport._unicast._remote_zid; callback->call(&id, ctx); } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 if (callback->drop != NULL) { callback->drop(ctx); @@ -739,17 +739,17 @@ z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, con // 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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) { -#endif // Z_MULTICAST_TRANSPORT == 1 +#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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 z_publisher_options_t opt = z_publisher_options_default(); if (options != NULL) { @@ -815,9 +815,9 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z // 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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) { -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr); if (r == NULL) { char *wild = strpbrk(keyexpr._suffix, "*$"); @@ -833,9 +833,9 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z uint16_t id = _z_declare_resource(zs._val, keyexpr); key = _z_rid_with_suffix(id, wild); } -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_subinfo_t subinfo = _z_subinfo_push_default(); if (options != NULL) { @@ -904,17 +904,17 @@ z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_o // 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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) { -#endif // Z_MULTICAST_TRANSPORT == 1 +#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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 z_queryable_options_t opt = z_queryable_options_default(); if (options != NULL) { @@ -970,7 +970,7 @@ zp_task_read_options_t zp_task_read_options_default(void) { return (zp_task_read int8_t zp_start_read_task(z_session_t zs, const zp_task_read_options_t *options) { (void)(options); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 return _zp_start_read_task(zs._val); #else (void)(zs); @@ -979,7 +979,7 @@ int8_t zp_start_read_task(z_session_t zs, const zp_task_read_options_t *options) } int8_t zp_stop_read_task(z_session_t zs) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 return _zp_stop_read_task(zs._val); #else (void)(zs); @@ -991,7 +991,7 @@ zp_task_lease_options_t zp_task_lease_options_default(void) { return (zp_task_le int8_t zp_start_lease_task(z_session_t zs, const zp_task_lease_options_t *options) { (void)(options); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 return _zp_start_lease_task(zs._val); #else (void)(zs); @@ -1000,7 +1000,7 @@ int8_t zp_start_lease_task(z_session_t zs, const zp_task_lease_options_t *option } int8_t zp_stop_lease_task(z_session_t zs) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 return _zp_stop_lease_task(zs._val); #else (void)(zs); diff --git a/src/link/config/bt.c b/src/link/config/bt.c index 989817cac..0c633b7cc 100644 --- a/src/link/config/bt.c +++ b/src/link/config/bt.c @@ -15,7 +15,7 @@ #include -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 size_t _z_bt_config_strlen(const _z_str_intmap_t *s) { BT_CONFIG_MAPPING_BUILD diff --git a/src/link/config/serial.c b/src/link/config/serial.c index c0608195d..876174f79 100644 --- a/src/link/config/serial.c +++ b/src/link/config/serial.c @@ -16,7 +16,7 @@ #include -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 size_t _z_serial_config_strlen(const _z_str_intmap_t *s) { SERIAL_CONFIG_MAPPING_BUILD diff --git a/src/link/config/tcp.c b/src/link/config/tcp.c index e5ad017ae..0da276204 100644 --- a/src/link/config/tcp.c +++ b/src/link/config/tcp.c @@ -18,7 +18,7 @@ #include "zenoh-pico/config.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 size_t _z_tcp_config_strlen(const _z_str_intmap_t *s) { TCP_CONFIG_MAPPING_BUILD diff --git a/src/link/config/udp.c b/src/link/config/udp.c index 3629f25be..3dc5f06c6 100644 --- a/src/link/config/udp.c +++ b/src/link/config/udp.c @@ -18,7 +18,7 @@ #include "zenoh-pico/config.h" -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 size_t _z_udp_config_strlen(const _z_str_intmap_t *s) { UDP_CONFIG_MAPPING_BUILD diff --git a/src/link/config/ws.c b/src/link/config/ws.c index ae876596b..14e4c113c 100644 --- a/src/link/config/ws.c +++ b/src/link/config/ws.c @@ -18,7 +18,7 @@ #include "zenoh-pico/config.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 size_t _z_ws_config_strlen(const _z_str_intmap_t *s) { WS_CONFIG_MAPPING_BUILD diff --git a/src/link/endpoint.c b/src/link/endpoint.c index a4348db71..d06a67158 100644 --- a/src/link/endpoint.c +++ b/src/link/endpoint.c @@ -20,19 +20,19 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #include "zenoh-pico/link/config/tcp.h" #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #include "zenoh-pico/link/config/udp.h" #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #include "zenoh-pico/link/config/bt.h" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #include "zenoh-pico/link/config/serial.h" #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #include "zenoh-pico/link/config/ws.h" #endif /*------------------ Locator ------------------*/ @@ -292,27 +292,27 @@ int8_t _z_endpoint_config_from_str(_z_str_intmap_t *strint, const char *str, con p_start = _z_ptr_char_offset(p_start, 1); // Call the right configuration parser depending on the protocol -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 if (_z_str_eq(proto, TCP_SCHEMA) == true) { ret = _z_tcp_config_from_str(strint, p_start); } else #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 if (_z_str_eq(proto, UDP_SCHEMA) == true) { ret = _z_udp_config_from_str(strint, p_start); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_str_eq(proto, BT_SCHEMA) == true) { ret = _z_bt_config_from_str(strint, p_start); } else #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 if (_z_str_eq(proto, SERIAL_SCHEMA) == true) { ret = _z_serial_config_from_str(strint, p_start); } else #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 if (_z_str_eq(proto, WS_SCHEMA) == true) { ret = _z_ws_config_from_str(strint, p_start); } else @@ -329,27 +329,27 @@ size_t _z_endpoint_config_strlen(const _z_str_intmap_t *s, const char *proto) { size_t len = 0; // Call the right configuration parser depending on the protocol -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 if (_z_str_eq(proto, TCP_SCHEMA) == true) { len = _z_tcp_config_strlen(s); } else #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 if (_z_str_eq(proto, UDP_SCHEMA) == true) { len = _z_udp_config_strlen(s); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_str_eq(proto, BT_SCHEMA) == true) { len = _z_bt_config_strlen(s); } else #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 if (_z_str_eq(proto, SERIAL_SCHEMA) == true) { len = _z_serial_config_strlen(s); } else #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 if (_z_str_eq(proto, WS_SCHEMA) == true) { len = _z_ws_config_strlen(s); } else @@ -365,27 +365,27 @@ char *_z_endpoint_config_to_str(const _z_str_intmap_t *s, const char *proto) { char *res = NULL; // Call the right configuration parser depending on the protocol -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 if (_z_str_eq(proto, TCP_SCHEMA) == true) { res = _z_tcp_config_to_str(s); } else #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 if (_z_str_eq(proto, UDP_SCHEMA) == true) { res = _z_udp_config_to_str(s); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_str_eq(proto, BT_SCHEMA) == true) { res = _z_bt_config_to_str(s); } else #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 if (_z_str_eq(proto, SERIAL_SCHEMA) == true) { res = _z_serial_config_to_str(s); } else #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 if (_z_str_eq(proto, WS_SCHEMA) == true) { res = _z_ws_config_to_str(s); } else diff --git a/src/link/link.c b/src/link/link.c index 5c409e353..1a5f89925 100644 --- a/src/link/link.c +++ b/src/link/link.c @@ -28,27 +28,27 @@ int8_t _z_open_link(_z_link_t *zl, const char *locator) { if (ret == _Z_RES_OK) { // TODO[peer]: when peer unicast mode is supported, this must be revisited // Create transport link -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 if (_z_endpoint_tcp_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_tcp(zl, &ep); } else #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 if (_z_endpoint_udp_unicast_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_udp_unicast(zl, ep); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_endpoint_bt_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_bt(zl, ep); } else #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 if (_z_endpoint_serial_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_serial(zl, ep); } else #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 if (_z_endpoint_ws_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_ws(zl, &ep); } else @@ -82,12 +82,12 @@ int8_t _z_listen_link(_z_link_t *zl, const char *locator) { if (ret == _Z_RES_OK) { // TODO[peer]: when peer unicast mode is supported, this must be revisited // Create transport link -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 if (_z_endpoint_udp_multicast_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_udp_multicast(zl, ep); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_endpoint_bt_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_bt(zl, ep); } else diff --git a/src/link/multicast/bt.c b/src/link/multicast/bt.c index e269d420e..332e5f9fa 100644 --- a/src/link/multicast/bt.c +++ b/src/link/multicast/bt.c @@ -20,7 +20,7 @@ #include "zenoh-pico/link/manager.h" #include "zenoh-pico/system/link/bt.h" -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #define SPP_MAXIMUM_PAYLOAD 128 diff --git a/src/link/multicast/udp.c b/src/link/multicast/udp.c index 981b1a37f..bcb2a4dc8 100644 --- a/src/link/multicast/udp.c +++ b/src/link/multicast/udp.c @@ -23,7 +23,7 @@ #include "zenoh-pico/system/link/udp.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 char *__z_parse_port_segment_udp_multicast(const char *address) { char *ret = NULL; diff --git a/src/link/unicast/serial.c b/src/link/unicast/serial.c index 40cdbf349..eebbff12a 100644 --- a/src/link/unicast/serial.c +++ b/src/link/unicast/serial.c @@ -23,7 +23,7 @@ #include "zenoh-pico/system/link/serial.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #define SPP_MAXIMUM_PAYLOAD 128 diff --git a/src/link/unicast/tcp.c b/src/link/unicast/tcp.c index c6af264d2..b7b78fa43 100644 --- a/src/link/unicast/tcp.c +++ b/src/link/unicast/tcp.c @@ -23,7 +23,7 @@ #include "zenoh-pico/system/link/tcp.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 char *__z_parse_port_segment_tcp(char *address) { char *ret = NULL; diff --git a/src/link/unicast/udp.c b/src/link/unicast/udp.c index 63ae5de04..c87441709 100644 --- a/src/link/unicast/udp.c +++ b/src/link/unicast/udp.c @@ -23,7 +23,7 @@ #include "zenoh-pico/system/link/udp.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 char *__z_parse_port_segment_udp_unicast(char *address) { char *ret = NULL; diff --git a/src/link/unicast/ws.c b/src/link/unicast/ws.c index cd7edd673..426e5fa96 100644 --- a/src/link/unicast/ws.c +++ b/src/link/unicast/ws.c @@ -24,7 +24,7 @@ #include "zenoh-pico/system/link/ws.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 char *__z_parse_port_segment_ws(char *address) { char *ret = NULL; diff --git a/src/net/session.c b/src/net/session.c index 2f2b0c93e..24d66dea6 100644 --- a/src/net/session.c +++ b/src/net/session.c @@ -33,7 +33,7 @@ int8_t __z_open_inner(_z_session_t *zn, char *locator, z_whatami_t mode) { int8_t ret = _Z_RES_OK; _z_id_t local_zid = _z_id_empty(); -#if Z_UNICAST_TRANSPORT == 1 || Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 || Z_FEATURE_MULTICAST_TRANSPORT == 1 ret = _z_session_generate_zid(&local_zid, Z_ZID_LENGTH); if (ret == _Z_RES_OK) { ret = _z_new_transport(&zn->_tp, &local_zid, locator, mode); @@ -154,14 +154,14 @@ _z_config_t *_z_info(const _z_session_t *zn) { _z_bytes_t local_zid = _z_bytes_wrap(zn->_local_zid.id, _z_id_len(zn->_local_zid)); _zp_config_insert(ps, Z_INFO_PID_KEY, _z_string_from_bytes(&local_zid)); -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { _z_id_t remote_zid = zn->_tp._transport._unicast._remote_zid; _z_bytes_t remote_zidbytes = _z_bytes_wrap(remote_zid.id, _z_id_len(remote_zid)); _zp_config_insert(ps, Z_INFO_ROUTER_PID_KEY, _z_string_from_bytes(&remote_zidbytes)); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { _z_transport_peer_entry_list_t *xs = zn->_tp._transport._multicast._peers; while (xs != NULL) { @@ -172,7 +172,7 @@ _z_config_t *_z_info(const _z_session_t *zn) { xs = _z_transport_peer_entry_list_tail(xs); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { __asm__("nop"); } @@ -187,7 +187,7 @@ int8_t _zp_send_keep_alive(_z_session_t *zn) { return _z_send_keep_alive(&zn->_t int8_t _zp_send_join(_z_session_t *zn) { return _z_send_join(&zn->_tp); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 int8_t _zp_start_read_task(_z_session_t *zn) { int8_t ret = _Z_RES_OK; @@ -195,7 +195,7 @@ int8_t _zp_start_read_task(_z_session_t *zn) { if (task != NULL) { (void)memset(task, 0, sizeof(_z_task_t)); -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._read_task = task; zn->_tp._transport._unicast._read_task_running = true; @@ -205,8 +205,8 @@ int8_t _zp_start_read_task(_z_session_t *zn) { z_free(task); } } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._read_task = task; zn->_tp._transport._multicast._read_task_running = true; @@ -216,7 +216,7 @@ int8_t _zp_start_read_task(_z_session_t *zn) { z_free(task); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; z_free(task); @@ -229,16 +229,16 @@ int8_t _zp_start_read_task(_z_session_t *zn) { int8_t _zp_stop_read_task(_z_session_t *zn) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._read_task_running = false; } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._read_task_running = false; } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -253,7 +253,7 @@ int8_t _zp_start_lease_task(_z_session_t *zn) { if (task != NULL) { (void)memset(task, 0, sizeof(_z_task_t)); -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._lease_task = task; zn->_tp._transport._unicast._lease_task_running = true; @@ -263,8 +263,8 @@ int8_t _zp_start_lease_task(_z_session_t *zn) { z_free(task); } } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._lease_task = task; zn->_tp._transport._multicast._lease_task_running = true; @@ -274,7 +274,7 @@ int8_t _zp_start_lease_task(_z_session_t *zn) { z_free(task); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; z_free(task); @@ -287,20 +287,20 @@ int8_t _zp_start_lease_task(_z_session_t *zn) { int8_t _zp_stop_lease_task(_z_session_t *zn) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._lease_task_running = false; } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._lease_task_running = false; } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } return ret; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 diff --git a/src/session/query.c b/src/session/query.c index 52caa9beb..ec976c7e3 100644 --- a/src/session/query.c +++ b/src/session/query.c @@ -102,15 +102,15 @@ _z_pending_query_t *__unsafe__z_get_pending_query_by_id(_z_session_t *zn, const } _z_pending_query_t *_z_get_pending_query_by_id(_z_session_t *zn, const _z_zint_t id) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_t *pql = __unsafe__z_get_pending_query_by_id(zn, id); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return pql; } @@ -120,9 +120,9 @@ int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) _Z_DEBUG(">>> Allocating query for (%ju:%s,%s)\n", (uintmax_t)pen_qry->_key._id, pen_qry->_key._suffix, pen_qry->_parameters); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_t *pql = __unsafe__z_get_pending_query_by_id(zn, pen_qry->_id); if (pql == NULL) { // Register query only if a pending one with the same ID does not exist @@ -131,9 +131,9 @@ int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) ret = _Z_ERR_ENTITY_DECLARATION_FAILED; } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -143,9 +143,9 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons const _z_timestamp_t timestamp) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_t *pen_qry = __unsafe__z_get_pending_query_by_id(zn, id); if ((ret == _Z_RES_OK) && (pen_qry == NULL)) { @@ -215,9 +215,9 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Trigger the user callback if ((ret == _Z_RES_OK) && (pen_qry->_consolidation != Z_CONSOLIDATION_MODE_LATEST)) { @@ -234,9 +234,9 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Final reply received for unknown query id _z_pending_query_t *pen_qry = __unsafe__z_get_pending_query_by_id(zn, id); @@ -260,33 +260,33 @@ int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { zn->_pending_queries = _z_pending_query_list_drop_filter(zn->_pending_queries, _z_pending_query_eq, pen_qry); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } void _z_unregister_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 zn->_pending_queries = _z_pending_query_list_drop_filter(zn->_pending_queries, _z_pending_query_eq, pen_qry); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_pending_queries(_z_session_t *zn) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_list_free(&zn->_pending_queries); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/queryable.c b/src/session/queryable.c index d18c5705e..7431712b4 100644 --- a/src/session/queryable.c +++ b/src/session/queryable.c @@ -89,30 +89,30 @@ _z_questionable_sptr_list_t *__unsafe_z_get_questionable_by_key(_z_session_t *zn } _z_questionable_sptr_t *_z_get_questionable_by_id(_z_session_t *zn, const _z_zint_t id) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_questionable_sptr_t *qle = __unsafe_z_get_questionable_by_id(zn, id); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return qle; } _z_questionable_sptr_list_t *_z_get_questionable_by_key(_z_session_t *zn, const _z_keyexpr_t *keyexpr) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, keyexpr); _z_questionable_sptr_list_t *qles = __unsafe_z_get_questionable_by_key(zn, key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return qles; } @@ -121,9 +121,9 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab _Z_DEBUG(">>> Allocating queryable for (%ju:%s)\n", (uintmax_t)q->_key._id, q->_key._suffix); _z_questionable_sptr_t *ret = NULL; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 ret = (_z_questionable_sptr_t *)z_malloc(sizeof(_z_questionable_sptr_t)); if (ret != NULL) { @@ -131,9 +131,9 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab zn->_local_questionable = _z_questionable_sptr_list_push(zn->_local_questionable, ret); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -141,17 +141,17 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, const _z_keyexpr_t q_key, uint32_t qid) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, &q_key); if (key._suffix != NULL) { _z_questionable_sptr_list_t *qles = __unsafe_z_get_questionable_by_key(zn, key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Build the query z_query_t q; @@ -190,9 +190,9 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons } _z_msg_clear(&z_msg); } else { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 ret = _Z_ERR_KEYEXPR_UNKNOWN; } @@ -201,26 +201,26 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons } void _z_unregister_questionable(_z_session_t *zn, _z_questionable_sptr_t *qle) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 zn->_local_questionable = _z_questionable_sptr_list_drop_filter(zn->_local_questionable, _z_questionable_sptr_eq, qle); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_questionables(_z_session_t *zn) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_questionable_sptr_list_free(&zn->_local_questionable); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/resource.c b/src/session/resource.c index 30c29702e..8a36ef951 100644 --- a/src/session/resource.c +++ b/src/session/resource.c @@ -174,15 +174,15 @@ _z_keyexpr_t __unsafe_z_get_expanded_key_from_key(_z_session_t *zn, const _z_key } _z_resource_t *_z_get_resource_by_id(_z_session_t *zn, uint16_t mapping, _z_zint_t rid) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_t *res = __unsafe_z_get_resource_by_id(zn, mapping, rid); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return res; } @@ -191,28 +191,28 @@ _z_resource_t *_z_get_resource_by_key(_z_session_t *zn, const _z_keyexpr_t *keye if (keyexpr->_suffix == NULL) { return _z_get_resource_by_id(zn, _z_keyexpr_mapping_id(keyexpr), keyexpr->_id); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_t *res = __unsafe_z_get_resource_by_key(zn, keyexpr); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return res; } _z_keyexpr_t _z_get_expanded_key_from_key(_z_session_t *zn, const _z_keyexpr_t *keyexpr) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_keyexpr_t res = __unsafe_z_get_expanded_key_from_key(zn, keyexpr); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return res; } @@ -224,9 +224,9 @@ int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, ui uint16_t mapping = register_to_mapping; uint16_t parent_mapping = _z_keyexpr_mapping_id(&key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 if (key._id != Z_RESOURCE_ID_NONE) { if (parent_mapping == mapping) { @@ -255,9 +255,9 @@ int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, ui } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -265,9 +265,9 @@ int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, ui void _z_unregister_resource(_z_session_t *zn, uint16_t id, uint16_t mapping) { _Bool is_local = mapping == _Z_KEYEXPR_MAPPING_LOCAL; _Z_DEBUG("unregistering: id %d, mapping: %d\n", id, mapping); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_list_t **parent_mut = is_local ? &zn->_local_resources : &zn->_remote_resources; while (id != 0) { _z_resource_list_t *parent = *parent_mut; @@ -289,9 +289,9 @@ void _z_unregister_resource(_z_session_t *zn, uint16_t id, uint16_t mapping) { parent = *parent_mut; } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } _Bool _z_unregister_resource_for_peer_filter(const _z_resource_t *candidate, const _z_resource_t *ctx) { @@ -299,27 +299,27 @@ _Bool _z_unregister_resource_for_peer_filter(const _z_resource_t *candidate, con return _z_keyexpr_mapping_id(&candidate->_key) == mapping; } void _z_unregister_resources_for_peer(_z_session_t *zn, uint16_t mapping) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_t ctx = {._id = mapping, ._refcount = 0, ._key = {0}}; zn->_remote_resources = _z_resource_list_drop_filter(zn->_remote_resources, _z_unregister_resource_for_peer_filter, &ctx); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_resources(_z_session_t *zn) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_list_free(&zn->_local_resources); _z_resource_list_free(&zn->_remote_resources); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/scout.c b/src/session/scout.c index 7a45a3ecc..e9191da07 100644 --- a/src/session/scout.c +++ b/src/session/scout.c @@ -20,8 +20,8 @@ #include "zenoh-pico/protocol/core.h" #include "zenoh-pico/utils/logging.h" -#if Z_SCOUTING_UDP == 1 && Z_LINK_UDP_UNICAST == 0 -#error "Scouting UDP requires UDP unicast links to be enabled (Z_LINK_UDP_UNICAST = 1 in config.h)" +#if Z_FEATURE_SCOUTING_UDP == 1 && Z_FEATURE_LINK_UDP_UNICAST == 0 +#error "Scouting UDP requires UDP unicast links to be enabled (Z_FEATURE_LINK_UDP_UNICAST = 1 in config.h)" #endif _z_hello_list_t *__z_scout_loop(const _z_wbuf_t *wbf, const char *locator, unsigned long period, _Bool exit_on_first) { @@ -32,7 +32,7 @@ _z_hello_list_t *__z_scout_loop(const _z_wbuf_t *wbf, const char *locator, unsig _z_endpoint_t ep; err = _z_endpoint_from_str(&ep, locator); -#if Z_SCOUTING_UDP == 1 +#if Z_FEATURE_SCOUTING_UDP == 1 if ((err == _Z_RES_OK) && (_z_str_eq(ep._locator._protocol, UDP_SCHEMA) == true)) { _z_endpoint_clear(&ep); } else @@ -140,13 +140,13 @@ _z_hello_list_t *_z_scout_inner(const z_what_t what, _z_id_t zid, const char *lo _z_scouting_message_encode(&wbf, &scout); // Scout on multicast -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 ret = __z_scout_loop(&wbf, locator, timeout, exit_on_first); #else (void)(locator); (void)(timeout); (void)(exit_on_first); -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_wbuf_clear(&wbf); diff --git a/src/session/subscription.c b/src/session/subscription.c index fd057aac3..e3e0833f3 100644 --- a/src/session/subscription.c +++ b/src/session/subscription.c @@ -96,29 +96,29 @@ _z_subscription_sptr_list_t *__unsafe_z_get_subscriptions_by_key(_z_session_t *z } _z_subscription_sptr_t *_z_get_subscription_by_id(_z_session_t *zn, uint8_t is_local, const _z_zint_t id) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_t *sub = __unsafe_z_get_subscription_by_id(zn, is_local, id); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return sub; } _z_subscription_sptr_list_t *_z_get_subscriptions_by_key(_z_session_t *zn, uint8_t is_local, const _z_keyexpr_t *key) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, is_local, *key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return subs; } @@ -127,9 +127,9 @@ _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_lo _Z_DEBUG(">>> Allocating sub decl for (%ju:%s)\n", (uintmax_t)s->_key._id, s->_key._suffix); _z_subscription_sptr_t *ret = NULL; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, is_local, s->_key); if (subs == NULL) { // A subscription for this name does not yet exists @@ -144,9 +144,9 @@ _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_lo } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -155,9 +155,9 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co const _z_encoding_t encoding, const _z_zint_t kind, const _z_timestamp_t timestamp) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _Z_DEBUG("Resolving %d - %s on mapping 0x%x\n", keyexpr._id, keyexpr._suffix, _z_keyexpr_mapping_id(&keyexpr)); _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, &keyexpr); @@ -165,9 +165,9 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co if (key._suffix != NULL) { _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, _Z_RESOURCE_IS_LOCAL, key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Build the sample _z_sample_t s; @@ -187,9 +187,9 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co _z_keyexpr_clear(&key); _z_subscription_sptr_list_free(&subs); } else { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 ret = _Z_ERR_KEYEXPR_UNKNOWN; } @@ -197,9 +197,9 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co } void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscription_sptr_t *sub) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 if (is_local == _Z_RESOURCE_IS_LOCAL) { zn->_local_subscriptions = @@ -209,20 +209,20 @@ void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscript _z_subscription_sptr_list_drop_filter(zn->_remote_subscriptions, _z_subscription_sptr_eq, sub); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_subscriptions(_z_session_t *zn) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_list_free(&zn->_local_subscriptions); _z_subscription_sptr_list_free(&zn->_remote_subscriptions); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/tx.c b/src/session/tx.c index ae3697b42..409f5d402 100644 --- a/src/session/tx.c +++ b/src/session/tx.c @@ -21,16 +21,16 @@ int8_t _z_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reli int8_t ret = _Z_RES_OK; _Z_DEBUG(">> send network message\n"); -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _z_unicast_send_n_msg(zn, z_msg, reliability, cong_ctrl); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _z_multicast_send_n_msg(zn, z_msg, reliability, cong_ctrl); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } diff --git a/src/session/utils.c b/src/session/utils.c index 215c2717f..494cb7a5d 100644 --- a/src/session/utils.c +++ b/src/session/utils.c @@ -66,21 +66,21 @@ int8_t _z_session_init(_z_session_t *zn, _z_id_t *zid) { zn->_local_questionable = NULL; zn->_pending_queries = NULL; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 ret = _z_mutex_init(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 if (ret == _Z_RES_OK) { zn->_local_zid = *zid; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._session = zn; } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._session = zn; } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { // Do nothing. Required to be here because of the #if directive } @@ -103,9 +103,9 @@ void _z_session_clear(_z_session_t *zn) { _z_flush_questionables(zn); _z_flush_pending_queries(zn); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_free(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_session_free(_z_session_t **zn) { diff --git a/src/system/arduino/esp32/network.cpp b/src/system/arduino/esp32/network.cpp index c85ea7d07..c02557fac 100644 --- a/src/system/arduino/esp32/network.cpp +++ b/src/system/arduino/esp32/network.cpp @@ -32,7 +32,7 @@ extern "C" { #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -143,7 +143,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -165,7 +165,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -238,7 +238,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -544,7 +544,7 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 /*------------------ Bluetooth sockets ------------------*/ int8_t _z_open_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -641,7 +641,7 @@ size_t _z_send_bt(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len } #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 /*------------------ Serial sockets ------------------*/ int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { int8_t ret = _Z_RES_OK; diff --git a/src/system/arduino/esp32/system.c b/src/system/arduino/esp32/system.c index 1d823c14c..a9eab813c 100644 --- a/src/system/arduino/esp32/system.c +++ b/src/system/arduino/esp32/system.c @@ -44,7 +44,7 @@ void *z_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MA void z_free(void *ptr) { heap_caps_free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // This wrapper is only used for ESP32. // In FreeRTOS, tasks created using xTaskCreate must end with vTaskDelete. // A task function should __not__ simply return. @@ -112,7 +112,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { return usleep(time); } diff --git a/src/system/arduino/opencr/network.cpp b/src/system/arduino/opencr/network.cpp index 1912d7cfb..bdbb9939a 100644 --- a/src/system/arduino/opencr/network.cpp +++ b/src/system/arduino/opencr/network.cpp @@ -26,7 +26,7 @@ extern "C" { #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { @@ -118,7 +118,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { @@ -147,7 +147,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { delete ep->_iptcp._addr; } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -229,7 +229,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -340,11 +340,11 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on OpenCR port of Zenoh-Pico" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #error "Serial not supported yet on OpenCR port of Zenoh-Pico" #endif } diff --git a/src/system/arduino/opencr/system.c b/src/system/arduino/opencr/system.c index 946392bb3..9ad314b5c 100644 --- a/src/system/arduino/opencr/system.c +++ b/src/system/arduino/opencr/system.c @@ -59,8 +59,8 @@ void z_free(void *ptr) { return free(ptr); } -#if Z_MULTI_THREAD == 1 -#error "Multi-threading not supported yet on OpenCR port. Disable it by defining Z_MULTI_THREAD=0" +#if Z_FEATURE_MULTI_THREAD == 1 +#error "Multi-threading not supported yet on OpenCR port. Disable it by defining Z_FEATURE_MULTI_THREAD=0" /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return -1; } @@ -94,7 +94,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return -1; } int8_t _z_condvar_signal(_z_condvar_t *cv) { return -1; } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return -1; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { diff --git a/src/system/emscripten/network.c b/src/system/emscripten/network.c index 56a67714a..8b2f14caf 100644 --- a/src/system/emscripten/network.c +++ b/src/system/emscripten/network.c @@ -28,7 +28,7 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #define WS_LINK_SLEEP 1 @@ -158,18 +158,18 @@ size_t _z_send_ws(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len #endif -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #error "TCP not supported yet on Emscripten port of Zenoh-Pico" #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #error "UDP not supported yet on Emscripten port of Zenoh-Pico" #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on Emscripten port of Zenoh-Pico" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #error "Serial not supported yet on Emscripten port of Zenoh-Pico" #endif diff --git a/src/system/emscripten/system.c b/src/system/emscripten/system.c index 89242bd72..0654898b3 100644 --- a/src/system/emscripten/system.c +++ b/src/system/emscripten/system.c @@ -42,7 +42,7 @@ void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } void z_free(void *ptr) { free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, pthread_attr_t *attr, void *(*fun)(void *), void *arg) { return pthread_create(task, attr, fun, arg); @@ -77,7 +77,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { diff --git a/src/system/espidf/network.c b/src/system/espidf/network.c index 55b3e7036..9a49bf157 100644 --- a/src/system/espidf/network.c +++ b/src/system/espidf/network.c @@ -28,7 +28,7 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -139,7 +139,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -161,7 +161,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -234,7 +234,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -540,7 +540,7 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 /*------------------ Serial sockets ------------------*/ int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { int8_t ret = _Z_RES_OK; @@ -736,6 +736,6 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on ESP-IDF port of Zenoh-Pico" #endif diff --git a/src/system/espidf/system.c b/src/system/espidf/system.c index a3a4dd472..8a655cf0d 100644 --- a/src/system/espidf/system.c +++ b/src/system/espidf/system.c @@ -45,7 +45,7 @@ void *z_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MA void z_free(void *ptr) { heap_caps_free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // This wrapper is only used for ESP32. // In FreeRTOS, tasks created using xTaskCreate must end with vTaskDelete. // A task function should __not__ simply return. @@ -113,7 +113,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { return usleep(time); } diff --git a/src/system/mbed/network.cpp b/src/system/mbed/network.cpp index 6653fceea..744b92df0 100644 --- a/src/system/mbed/network.cpp +++ b/src/system/mbed/network.cpp @@ -31,7 +31,7 @@ extern "C" { #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -115,7 +115,7 @@ size_t _z_read_exact_tcp(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t le size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { return sock._tcp->send(ptr, len); } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -134,7 +134,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { delete ep->_iptcp; } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; (void)sock; @@ -205,7 +205,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -317,7 +317,7 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { int8_t ret = _Z_RES_OK; @@ -479,7 +479,7 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on MBED port of Zenoh-Pico" #endif diff --git a/src/system/mbed/system.cpp b/src/system/mbed/system.cpp index 68dc20b01..2adeec297 100644 --- a/src/system/mbed/system.cpp +++ b/src/system/mbed/system.cpp @@ -39,7 +39,7 @@ void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } void z_free(void *ptr) { free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg) { *task = new Thread(); @@ -106,7 +106,7 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { ((ConditionVariable *)*cv)->wait(); return 0; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { diff --git a/src/system/unix/network.c b/src/system/unix/network.c index 917e9a4be..b7e899e23 100644 --- a/src/system/unix/network.c +++ b/src/system/unix/network.c @@ -31,7 +31,7 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { @@ -158,7 +158,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -180,7 +180,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -253,7 +253,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 unsigned int __get_ip_from_iface(const char *iface, int sa_family, struct sockaddr **lsockaddr) { unsigned int addrlen = 0U; @@ -584,10 +584,10 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on Unix port of Zenoh-Pico" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #error "Serial not supported yet on Unix port of Zenoh-Pico" #endif diff --git a/src/system/unix/system.c b/src/system/unix/system.c index e5dca90e9..875bc5f2b 100644 --- a/src/system/unix/system.c +++ b/src/system/unix/system.c @@ -98,7 +98,7 @@ void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } void z_free(void *ptr) { free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return pthread_create(task, attr, fun, arg); @@ -133,7 +133,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { return usleep(time); } diff --git a/src/system/windows/network.c b/src/system/windows/network.c index 6ce0eb5ab..76d37027c 100644 --- a/src/system/windows/network.c +++ b/src/system/windows/network.c @@ -25,7 +25,7 @@ WSADATA wsaData; -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { @@ -161,7 +161,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -190,7 +190,7 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -272,7 +272,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 unsigned int __get_ip_from_iface(const char *iface, int sa_family, SOCKADDR **lsockaddr) { unsigned int addrlen = 0U; @@ -603,10 +603,10 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on Windows port of Zenoh-Pico" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #error "Serial not supported yet on Windows port of Zenoh-Pico" #endif diff --git a/src/system/windows/system.c b/src/system/windows/system.c index b813d6627..581b42291 100644 --- a/src/system/windows/system.c +++ b/src/system/windows/system.c @@ -58,7 +58,7 @@ void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } void z_free(void *ptr) { free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg) { (void)(attr); @@ -146,7 +146,7 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { SleepConditionVariableSRW(cv, m, INFINITE, 0); return ret; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { return z_sleep_ms((time / 1000) + (time % 1000 == 0 ? 0 : 1)); } diff --git a/src/system/zephyr/network.c b/src/system/zephyr/network.c index 49978b49c..e07381914 100644 --- a/src/system/zephyr/network.c +++ b/src/system/zephyr/network.c @@ -34,7 +34,7 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -147,7 +147,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -169,7 +169,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -243,7 +243,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -550,9 +550,9 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, _z_sys_net_endpoint_t rep) { return sendto(sock._fd, ptr, len, 0, rep._iptcp->ai_addr, rep._iptcp->ai_addrlen); } -#endif // Z_LINK_UDP_MULTICAST == 1 +#endif // Z_FEATURE_LINK_UDP_MULTICAST == 1 -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { int8_t ret = _Z_RES_OK; (void)(sock); @@ -725,6 +725,6 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on Zephyr port of Zenoh-Pico" #endif diff --git a/src/system/zephyr/system.c b/src/system/zephyr/system.c index 2670ae9cb..28ce1d303 100644 --- a/src/system/zephyr/system.c +++ b/src/system/zephyr/system.c @@ -55,7 +55,7 @@ void *z_realloc(void *ptr, size_t size) { void z_free(void *ptr) { k_free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 #define Z_THREADS_NUM 4 @@ -112,7 +112,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { diff --git a/src/transport/common/join.c b/src/transport/common/join.c index b896dac2e..5c9d6819b 100644 --- a/src/transport/common/join.c +++ b/src/transport/common/join.c @@ -17,12 +17,12 @@ int8_t _z_send_join(_z_transport_t *zt) { int8_t ret = _Z_RES_OK; -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 // Join task only applies to multicast transports if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_send_join(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { (void)zt; ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; diff --git a/src/transport/common/lease.c b/src/transport/common/lease.c index dcf2d908d..bf32a5884 100644 --- a/src/transport/common/lease.c +++ b/src/transport/common/lease.c @@ -18,16 +18,16 @@ int8_t _z_send_keep_alive(_z_transport_t *zt) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _zp_unicast_send_keep_alive(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_send_keep_alive(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -39,16 +39,16 @@ void *_zp_lease_task(void *zt_arg) { void *ret = NULL; _z_transport_t *zt = (_z_transport_t *)zt_arg; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _zp_unicast_lease_task(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_lease_task(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = NULL; } diff --git a/src/transport/common/read.c b/src/transport/common/read.c index bf0f20381..e1bcdcee8 100644 --- a/src/transport/common/read.c +++ b/src/transport/common/read.c @@ -19,16 +19,16 @@ int8_t _z_read(_z_transport_t *zt) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _zp_unicast_read(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_read(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -40,16 +40,16 @@ void *_zp_read_task(void *zt_arg) { void *ret = NULL; _z_transport_t *zt = (_z_transport_t *)zt_arg; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _zp_unicast_read_task(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_read_task(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = NULL; } diff --git a/src/transport/common/tx.c b/src/transport/common/tx.c index f3625250e..811cf7a2d 100644 --- a/src/transport/common/tx.c +++ b/src/transport/common/tx.c @@ -54,16 +54,16 @@ void __unsafe_z_finalize_wbuf(_z_wbuf_t *buf, _Bool is_streamed) { int8_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _z_unicast_send_t_msg(&zt->_transport._unicast, t_msg); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _z_multicast_send_t_msg(&zt->_transport._multicast, t_msg); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -71,7 +71,7 @@ int8_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg) { return ret; } -#if Z_UNICAST_TRANSPORT == 1 || Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 || Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg) { int8_t ret = _Z_RES_OK; @@ -103,7 +103,7 @@ int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_m return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 || Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 || Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z_reliability_t reliability, size_t sn) { int8_t ret = _Z_RES_OK; diff --git a/src/transport/manager.c b/src/transport/manager.c index f365a399e..c7e868ed1 100644 --- a/src/transport/manager.c +++ b/src/transport/manager.c @@ -25,7 +25,7 @@ int8_t _z_new_transport_client(_z_transport_t *zt, char *locator, _z_id_t *local ret = _z_open_link(&zl, locator); if (ret == _Z_RES_OK) { -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (_Z_LINK_IS_MULTICAST(zl._capabilities) == false) { _z_transport_unicast_establish_param_t tp_param; ret = _z_transport_unicast_open_client(&tp_param, &zl, local_zid); @@ -35,8 +35,8 @@ int8_t _z_new_transport_client(_z_transport_t *zt, char *locator, _z_id_t *local _z_link_clear(&zl); } } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (_Z_LINK_IS_MULTICAST(zl._capabilities) == true) { _z_transport_multicast_establish_param_t tp_param; ret = _z_transport_multicast_open_client(&tp_param, &zl, local_zid); @@ -46,7 +46,7 @@ int8_t _z_new_transport_client(_z_transport_t *zt, char *locator, _z_id_t *local _z_link_clear(&zl); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { _z_link_clear(&zl); ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; @@ -64,7 +64,7 @@ int8_t _z_new_transport_peer(_z_transport_t *zt, char *locator, _z_id_t *local_z ret = _z_listen_link(&zl, locator); if (ret == _Z_RES_OK) { -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (_Z_LINK_IS_MULTICAST(zl._capabilities) == false) { _z_transport_unicast_establish_param_t tp_param; ret = _z_transport_unicast_open_peer(&tp_param, &zl, local_zid); @@ -74,8 +74,8 @@ int8_t _z_new_transport_peer(_z_transport_t *zt, char *locator, _z_id_t *local_z _z_link_clear(&zl); } } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (_Z_LINK_IS_MULTICAST(zl._capabilities) == true) { _z_transport_multicast_establish_param_t tp_param; ret = _z_transport_multicast_open_peer(&tp_param, &zl, local_zid); @@ -85,7 +85,7 @@ int8_t _z_new_transport_peer(_z_transport_t *zt, char *locator, _z_id_t *local_z _z_link_clear(&zl); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { _z_link_clear(&zl); ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; diff --git a/src/transport/multicast/link/rx.c b/src/transport/multicast/link/rx.c index b5d50e030..cb585503c 100644 --- a/src/transport/multicast/link/rx.c +++ b/src/transport/multicast/link/rx.c @@ -27,7 +27,7 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_transport_peer_entry_t *_z_find_peer_entry(_z_transport_peer_entry_list_t *l, _z_bytes_t *remote_addr) { _z_transport_peer_entry_t *ret = NULL; @@ -52,10 +52,10 @@ int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_me _Z_DEBUG(">> recv session msg\n"); int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock _z_mutex_lock(&ztm->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 size_t to_read = 0; do { @@ -96,9 +96,9 @@ int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_me ret = _z_transport_message_decode(t_msg, &ztm->_zbuf); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztm->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -110,10 +110,10 @@ int8_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_messa int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_bytes_t *addr) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire and keep the lock _z_mutex_lock(&ztm->_mutex_peer); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Mark the session that we have received data from this peer _z_transport_peer_entry_t *entry = _z_find_peer_entry(ztm->_peers, addr); @@ -254,7 +254,7 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t _z_conduit_sn_list_copy(&entry->_sn_rx_sns, &t_msg->_body._join._next_sn); _z_conduit_sn_list_decrement(entry->_sn_res, &entry->_sn_rx_sns); -#if Z_DYNAMIC_MEMORY_ALLOCATION == 1 +#if Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION == 1 entry->_dbuf_reliable = _z_wbuf_make(0, true); entry->_dbuf_best_effort = _z_wbuf_make(0, true); #else @@ -313,11 +313,11 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztm->_mutex_peer); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/multicast/link/task/join.c b/src/transport/multicast/link/task/join.c index 345ab689c..45ce08aaa 100644 --- a/src/transport/multicast/link/task/join.c +++ b/src/transport/multicast/link/task/join.c @@ -17,7 +17,7 @@ #include "zenoh-pico/session/utils.h" #include "zenoh-pico/transport/link/tx.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { _z_conduit_sn_list_t next_sn; @@ -31,4 +31,4 @@ int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { return _z_multicast_send_t_msg(ztm, &jsm); } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/multicast/link/task/lease.c b/src/transport/multicast/link/task/lease.c index c653d2dea..91a594c4b 100644 --- a/src/transport/multicast/link/task/lease.c +++ b/src/transport/multicast/link/task/lease.c @@ -22,7 +22,7 @@ #include "zenoh-pico/transport/link/tx.h" #include "zenoh-pico/utils/logging.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_zint_t _z_get_minimum_lease(_z_transport_peer_entry_list_t *peers, _z_zint_t local_lease) { _z_zint_t ret = local_lease; @@ -68,7 +68,7 @@ int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { } void *_zp_multicast_lease_task(void *ztm_arg) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_transport_multicast_t *ztm = (_z_transport_multicast_t *)ztm_arg; ztm->_transmitted = false; @@ -158,9 +158,9 @@ void *_zp_multicast_lease_task(void *ztm_arg) { _z_mutex_unlock(&ztm->_mutex_peer); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return 0; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/multicast/link/task/read.c b/src/transport/multicast/link/task/read.c index 2c4278426..606f2a8c1 100644 --- a/src/transport/multicast/link/task/read.c +++ b/src/transport/multicast/link/task/read.c @@ -22,7 +22,7 @@ #include "zenoh-pico/transport/link/rx.h" #include "zenoh-pico/utils/logging.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) { int8_t ret = _Z_RES_OK; @@ -39,7 +39,7 @@ int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) { } void *_zp_multicast_read_task(void *ztm_arg) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_transport_multicast_t *ztm = (_z_transport_multicast_t *)ztm_arg; // Acquire and keep the lock @@ -113,9 +113,9 @@ void *_zp_multicast_read_task(void *ztm_arg) { } _z_mutex_unlock(&ztm->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return NULL; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/multicast/link/tx.c b/src/transport/multicast/link/tx.c index 991f878f3..81197bf12 100644 --- a/src/transport/multicast/link/tx.c +++ b/src/transport/multicast/link/tx.c @@ -20,7 +20,7 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 /** * This function is unsafe because it operates in potentially concurrent data. @@ -43,10 +43,10 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport int8_t ret = _Z_RES_OK; _Z_DEBUG(">> send session message\n"); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock _z_mutex_lock(&ztm->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Prepare the buffer eventually reserving space for the message length __unsafe_z_prepare_wbuf(&ztm->_wbuf, _Z_LINK_IS_STREAMED(ztm->_link._capabilities)); @@ -63,9 +63,9 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztm->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -80,18 +80,18 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m // Acquire the lock and drop the message if needed _Bool drop = false; if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&ztm->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } else { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 int8_t locked = _z_mutex_trylock(&ztm->_mutex_tx); if (locked != (int8_t)0) { _Z_INFO("Dropping zenoh message because of congestion control\n"); // We failed to acquire the lock, drop the message drop = true; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } if (drop == false) { @@ -145,12 +145,12 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztm->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/transport.c b/src/transport/transport.c index af71c2016..0019be34e 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -26,7 +26,7 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, _Bool link_only) { int8_t ret = _Z_RES_OK; @@ -37,9 +37,9 @@ int8_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, _Bool return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, _Bool link_only) { int8_t ret = _Z_RES_OK; @@ -50,21 +50,21 @@ int8_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, _B return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_send_close(_z_transport_t *zt, uint8_t reason, _Bool link_only) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _z_unicast_send_close(&zt->_transport._unicast, reason, link_only); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _z_multicast_send_close(&zt->_transport._multicast, reason, link_only); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -72,13 +72,13 @@ int8_t _z_send_close(_z_transport_t *zt, uint8_t reason, _Bool link_only) { return ret; } -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unicast_establish_param_t *param) { int8_t ret = _Z_RES_OK; zt->_type = _Z_TRANSPORT_UNICAST_TYPE; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Initialize the mutexes ret = _z_mutex_init(&zt->_transport._unicast._mutex_tx); if (ret == _Z_RES_OK) { @@ -87,7 +87,7 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic _z_mutex_free(&zt->_transport._unicast._mutex_tx); } } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Initialize the read and write buffers if (ret == _Z_RES_OK) { @@ -95,7 +95,7 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic _Bool expandable = _Z_LINK_IS_STREAMED(zl->_capabilities); size_t dbuf_size = 0; -#if Z_DYNAMIC_MEMORY_ALLOCATION == 0 +#if Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION == 0 expandable = false; dbuf_size = Z_FRAG_MAX_SIZE; #endif @@ -109,7 +109,7 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic // Clean up the buffers if one of them failed to be allocated if ((_z_wbuf_capacity(&zt->_transport._unicast._wbuf) != mtu) || (_z_zbuf_capacity(&zt->_transport._unicast._zbuf) != Z_BATCH_UNICAST_SIZE) || -#if Z_DYNAMIC_MEMORY_ALLOCATION == 0 +#if Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION == 0 (_z_wbuf_capacity(&zt->_transport._unicast._dbuf_reliable) != dbuf_size) || (_z_wbuf_capacity(&zt->_transport._unicast._dbuf_best_effort) != dbuf_size)) { #else @@ -118,10 +118,10 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic #endif ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_free(&zt->_transport._unicast._mutex_tx); _z_mutex_free(&zt->_transport._unicast._mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_wbuf_clear(&zt->_transport._unicast._wbuf); _z_zbuf_clear(&zt->_transport._unicast._zbuf); @@ -143,13 +143,13 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic zt->_transport._unicast._sn_rx_reliable = initial_sn_rx; zt->_transport._unicast._sn_rx_best_effort = initial_sn_rx; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Tasks zt->_transport._unicast._read_task_running = false; zt->_transport._unicast._read_task = NULL; zt->_transport._unicast._lease_task_running = false; zt->_transport._unicast._lease_task = NULL; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Notifiers zt->_transport._unicast._received = 0; @@ -169,15 +169,15 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_multicast_establish_param_t *param) { int8_t ret = _Z_RES_OK; zt->_type = _Z_TRANSPORT_MULTICAST_TYPE; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Initialize the mutexes ret = _z_mutex_init(&zt->_transport._multicast._mutex_tx); if (ret == _Z_RES_OK) { @@ -192,7 +192,7 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu _z_mutex_free(&zt->_transport._multicast._mutex_tx); } } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Initialize the read and write buffers if (ret == _Z_RES_OK) { @@ -205,11 +205,11 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu (_z_zbuf_capacity(&zt->_transport._multicast._zbuf) != Z_BATCH_MULTICAST_SIZE)) { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_free(&zt->_transport._multicast._mutex_tx); _z_mutex_free(&zt->_transport._multicast._mutex_rx); _z_mutex_free(&zt->_transport._multicast._mutex_peer); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_wbuf_clear(&zt->_transport._multicast._wbuf); _z_zbuf_clear(&zt->_transport._multicast._zbuf); @@ -227,13 +227,13 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu // Initialize peer list zt->_transport._multicast._peers = _z_transport_peer_entry_list_new(); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Tasks zt->_transport._multicast._read_task_running = false; zt->_transport._multicast._read_task = NULL; zt->_transport._multicast._lease_task_running = false; zt->_transport._multicast._lease_task = NULL; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 zt->_transport._multicast._lease = Z_TRANSPORT_LEASE; @@ -246,9 +246,9 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_transport_unicast_open_client(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, const _z_id_t *local_zid) { int8_t ret = _Z_RES_OK; @@ -343,9 +343,9 @@ int8_t _z_transport_unicast_open_client(_z_transport_unicast_establish_param_t * return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, const _z_id_t *local_zid) { (void)(param); @@ -357,9 +357,9 @@ int8_t _z_transport_multicast_open_client(_z_transport_multicast_establish_param return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_transport_unicast_open_peer(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, const _z_id_t *local_zid) { (void)(param); @@ -371,9 +371,9 @@ int8_t _z_transport_unicast_open_peer(_z_transport_unicast_establish_param_t *pa return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, const _z_id_t *local_zid) { int8_t ret = _Z_RES_OK; @@ -402,25 +402,25 @@ int8_t _z_transport_multicast_open_peer(_z_transport_multicast_establish_param_t return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_transport_unicast_close(_z_transport_unicast_t *ztu, uint8_t reason) { return _z_unicast_send_close(ztu, reason, false); } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_multicast_close(_z_transport_multicast_t *ztm, uint8_t reason) { return _z_multicast_send_close(ztm, reason, false); } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_close(_z_transport_t *zt, uint8_t reason) { return _z_send_close(zt, reason, false); } -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 void _z_transport_unicast_clear(_z_transport_unicast_t *ztu) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Clean up tasks if (ztu->_read_task != NULL) { _z_task_join(ztu->_read_task); @@ -434,7 +434,7 @@ void _z_transport_unicast_clear(_z_transport_unicast_t *ztu) { // Clean up the mutexes _z_mutex_free(&ztu->_mutex_tx); _z_mutex_free(&ztu->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Clean up the buffers _z_wbuf_clear(&ztu->_wbuf); @@ -446,11 +446,11 @@ void _z_transport_unicast_clear(_z_transport_unicast_t *ztu) { ztu->_remote_zid = _z_id_empty(); _z_link_clear(&ztu->_link); } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 void _z_transport_multicast_clear(_z_transport_multicast_t *ztm) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Clean up tasks if (ztm->_read_task != NULL) { _z_task_join(ztm->_read_task); @@ -465,7 +465,7 @@ void _z_transport_multicast_clear(_z_transport_multicast_t *ztm) { _z_mutex_free(&ztm->_mutex_tx); _z_mutex_free(&ztm->_mutex_rx); _z_mutex_free(&ztm->_mutex_peer); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Clean up the buffers _z_wbuf_clear(&ztm->_wbuf); @@ -475,19 +475,19 @@ void _z_transport_multicast_clear(_z_transport_multicast_t *ztm) { _z_transport_peer_entry_list_free(&ztm->_peers); _z_link_clear(&ztm->_link); } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 void _z_transport_clear(_z_transport_t *zt) { -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { _z_transport_unicast_clear(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { _z_transport_multicast_clear(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { __asm__("nop"); } diff --git a/src/transport/unicast/link/rx.c b/src/transport/unicast/link/rx.c index 6604e71ea..dfc580e4d 100644 --- a/src/transport/unicast/link/rx.c +++ b/src/transport/unicast/link/rx.c @@ -25,15 +25,15 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { _Z_DEBUG(">> recv session msg\n"); int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock _z_mutex_lock(&ztu->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 size_t to_read = 0; do { @@ -79,9 +79,9 @@ int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_messag } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztu->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -197,4 +197,4 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans return _Z_RES_OK; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 diff --git a/src/transport/unicast/link/task/lease.c b/src/transport/unicast/link/task/lease.c index 5d9e0a2f2..02ff178db 100644 --- a/src/transport/unicast/link/task/lease.c +++ b/src/transport/unicast/link/task/lease.c @@ -17,7 +17,7 @@ #include "zenoh-pico/transport/link/tx.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { int8_t ret = _Z_RES_OK; @@ -29,7 +29,7 @@ int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { } void *_zp_unicast_lease_task(void *ztu_arg) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_transport_unicast_t *ztu = (_z_transport_unicast_t *)ztu_arg; ztu->_received = false; @@ -83,9 +83,9 @@ void *_zp_unicast_lease_task(void *ztu_arg) { next_lease = next_lease - interval; next_keep_alive = next_keep_alive - interval; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return 0; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 diff --git a/src/transport/unicast/link/task/read.c b/src/transport/unicast/link/task/read.c index 31bc35609..bf27b1c70 100644 --- a/src/transport/unicast/link/task/read.c +++ b/src/transport/unicast/link/task/read.c @@ -21,7 +21,7 @@ #include "zenoh-pico/transport/link/rx.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) { int8_t ret = _Z_RES_OK; @@ -37,7 +37,7 @@ int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) { } void *_zp_unicast_read_task(void *ztu_arg) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_transport_unicast_t *ztu = (_z_transport_unicast_t *)ztu_arg; // Acquire and keep the lock @@ -107,9 +107,9 @@ void *_zp_unicast_read_task(void *ztu_arg) { } _z_mutex_unlock(&ztu->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return NULL; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 diff --git a/src/transport/unicast/link/tx.c b/src/transport/unicast/link/tx.c index 8f825b7e4..eb43c769d 100644 --- a/src/transport/unicast/link/tx.c +++ b/src/transport/unicast/link/tx.c @@ -23,7 +23,7 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 /** * This function is unsafe because it operates in potentially concurrent data. @@ -46,10 +46,10 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes int8_t ret = _Z_RES_OK; _Z_DEBUG(">> send session message\n"); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock _z_mutex_lock(&ztu->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Prepare the buffer eventually reserving space for the message length __unsafe_z_prepare_wbuf(&ztu->_wbuf, _Z_LINK_IS_STREAMED(ztu->_link._capabilities)); @@ -66,9 +66,9 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztu->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -83,18 +83,18 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg // Acquire the lock and drop the message if needed _Bool drop = false; if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&ztu->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } else { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 int8_t locked = _z_mutex_trylock(&ztu->_mutex_tx); if (locked != (int8_t)0) { _Z_INFO("Dropping zenoh message because of congestion control\n"); // We failed to acquire the lock, drop the message drop = true; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } if (drop == false) { @@ -154,12 +154,12 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztu->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 From 28818dfee6574b64320b3ee507a9d47cd6b0fe7a Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Mon, 9 Oct 2023 10:32:35 +0200 Subject: [PATCH 13/26] build: update config files with new token names --- .github/workflows/arduino_esp32.yaml | 2 +- .github/workflows/emscripten.yaml | 2 +- .github/workflows/mbed.yaml | 2 +- .github/workflows/zephyr.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/arduino_esp32.yaml b/.github/workflows/arduino_esp32.yaml index 197ce7776..0e1865973 100644 --- a/.github/workflows/arduino_esp32.yaml +++ b/.github/workflows/arduino_esp32.yaml @@ -51,7 +51,7 @@ jobs: mkdir -p $ARDUINO_BASE cd $ARDUINO_BASE - platformio init -b esp32thing_plus --project-option="build_flags=-DZ_LINK_BLUETOOTH=1 -DZENOH_DEBUG=3" + platformio init -b esp32thing_plus --project-option="build_flags=-DZ_FEATURE_LINK_BLUETOOTH=1 -DZENOH_DEBUG=3" cd $ARDUINO_BASE/lib ln -s $ZENOH_PICO_BASE diff --git a/.github/workflows/emscripten.yaml b/.github/workflows/emscripten.yaml index b995749d9..7080b5579 100644 --- a/.github/workflows/emscripten.yaml +++ b/.github/workflows/emscripten.yaml @@ -34,7 +34,7 @@ jobs: - name: Compile debug run: | mkdir build - emcmake cmake -E env CFLAGS="-DZ_LINK_WS=1 -DZ_LINK_TCP=0 -DZ_LINK_UDP_MULTICAST=0 -DZ_LINK_UDP_UNICAST=0 -DZ_SCOUTING_UDP=0" cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_STANDARD=11 -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_MULTICAST=OFF -DBUILD_INTEGRATION=OFF -DBUILD_TOOLS=OFF -DZENOH_DEBUG=3 -H. -Bbuild + emcmake cmake -E env CFLAGS="-DZ_FEATURE_LINK_WS=1 -DZ_FEATURE_LINK_TCP=0 -DZ_FEATURE_LINK_UDP_MULTICAST=0 -DZ_FEATURE_LINK_UDP_UNICAST=0 -DZ_FEATURE_SCOUTING_UDP=0" cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_STANDARD=11 -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_MULTICAST=OFF -DBUILD_INTEGRATION=OFF -DBUILD_TOOLS=OFF -DZENOH_DEBUG=3 -H. -Bbuild make -C build diff --git a/.github/workflows/mbed.yaml b/.github/workflows/mbed.yaml index 03386d06e..5bfbf4d94 100644 --- a/.github/workflows/mbed.yaml +++ b/.github/workflows/mbed.yaml @@ -51,7 +51,7 @@ jobs: mkdir -p $MBED_BASE cd $MBED_BASE - pio init -b nucleo_f767zi --project-option="framework=mbed" --project-option="build_flags=-DZ_LINK_SERIAL=1 -DZENOH_DEBUG=3" + pio init -b nucleo_f767zi --project-option="framework=mbed" --project-option="build_flags=-DZ_FEATURE_LINK_SERIAL=1 -DZENOH_DEBUG=3" cd $MBED_BASE/lib ln -s $ZENOH_PICO_BASE diff --git a/.github/workflows/zephyr.yaml b/.github/workflows/zephyr.yaml index 7ec080212..c7df7ecaa 100644 --- a/.github/workflows/zephyr.yaml +++ b/.github/workflows/zephyr.yaml @@ -51,7 +51,7 @@ jobs: mkdir -p $ZEPHYR_BASE cd $ZEPHYR_BASE - pio init -b nucleo_f767zi --project-option="framework=zephyr" --project-option="build_flags=-DZ_LINK_SERIAL=1 -DZENOH_DEBUG=3" + pio init -b nucleo_f767zi --project-option="framework=zephyr" --project-option="build_flags=-DZ_FEATURE_LINK_SERIAL=1 -DZENOH_DEBUG=3" cd $ZEPHYR_BASE/lib ln -s $ZENOH_PICO_BASE From eb657de7e460da7112a00739fe36debeb4a74a62 Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Wed, 11 Oct 2023 11:14:55 +0200 Subject: [PATCH 14/26] Rename feature config tokens (#258) --- .github/workflows/arduino_esp32.yaml | 2 +- .github/workflows/emscripten.yaml | 2 +- .github/workflows/mbed.yaml | 2 +- .github/workflows/zephyr.yaml | 2 +- extra_script.py | 2 +- include/zenoh-pico/config.h | 162 +++++++++--------- include/zenoh-pico/link/config/bt.h | 2 +- include/zenoh-pico/link/config/serial.h | 2 +- include/zenoh-pico/link/config/tcp.h | 2 +- include/zenoh-pico/link/config/udp.h | 2 +- include/zenoh-pico/link/config/ws.h | 2 +- include/zenoh-pico/link/endpoint.h | 10 +- include/zenoh-pico/link/link.h | 20 +-- include/zenoh-pico/link/manager.h | 12 +- include/zenoh-pico/net/session.h | 8 +- include/zenoh-pico/session/session.h | 4 +- include/zenoh-pico/system/link/bt.h | 2 +- include/zenoh-pico/system/link/serial.h | 2 +- include/zenoh-pico/system/link/tcp.h | 2 +- include/zenoh-pico/system/link/udp.h | 2 +- include/zenoh-pico/system/link/ws.h | 2 +- include/zenoh-pico/system/platform.h | 4 +- .../system/platform/arduino/esp32.h | 16 +- .../system/platform/arduino/opencr.h | 10 +- .../zenoh-pico/system/platform/emscripten.h | 8 +- include/zenoh-pico/system/platform/espidf.h | 10 +- include/zenoh-pico/system/platform/mbed.h | 12 +- include/zenoh-pico/system/platform/unix.h | 8 +- include/zenoh-pico/system/platform/void.h | 4 +- include/zenoh-pico/system/platform/windows.h | 8 +- include/zenoh-pico/system/platform/zephyr.h | 10 +- include/zenoh-pico/transport/transport.h | 16 +- src/api/api.c | 40 ++--- src/link/config/bt.c | 2 +- src/link/config/serial.c | 2 +- src/link/config/tcp.c | 2 +- src/link/config/udp.c | 2 +- src/link/config/ws.c | 2 +- src/link/endpoint.c | 40 ++--- src/link/link.c | 14 +- src/link/multicast/bt.c | 2 +- src/link/multicast/udp.c | 2 +- src/link/unicast/serial.c | 2 +- src/link/unicast/tcp.c | 2 +- src/link/unicast/udp.c | 2 +- src/link/unicast/ws.c | 2 +- src/net/session.c | 46 ++--- src/session/query.c | 48 +++--- src/session/queryable.c | 52 +++--- src/session/resource.c | 56 +++--- src/session/scout.c | 10 +- src/session/subscription.c | 52 +++--- src/session/tx.c | 8 +- src/session/utils.c | 16 +- src/system/arduino/esp32/network.cpp | 12 +- src/system/arduino/esp32/system.c | 4 +- src/system/arduino/opencr/network.cpp | 12 +- src/system/arduino/opencr/system.c | 6 +- src/system/emscripten/network.c | 10 +- src/system/emscripten/system.c | 4 +- src/system/espidf/network.c | 12 +- src/system/espidf/system.c | 4 +- src/system/mbed/network.cpp | 12 +- src/system/mbed/system.cpp | 4 +- src/system/unix/network.c | 12 +- src/system/unix/system.c | 4 +- src/system/windows/network.c | 12 +- src/system/windows/system.c | 4 +- src/system/zephyr/network.c | 14 +- src/system/zephyr/system.c | 4 +- src/transport/common/join.c | 4 +- src/transport/common/lease.c | 16 +- src/transport/common/read.c | 16 +- src/transport/common/tx.c | 12 +- src/transport/manager.c | 16 +- src/transport/multicast/link/rx.c | 22 +-- src/transport/multicast/link/task/join.c | 4 +- src/transport/multicast/link/task/lease.c | 8 +- src/transport/multicast/link/task/read.c | 8 +- src/transport/multicast/link/tx.c | 24 +-- src/transport/transport.c | 100 +++++------ src/transport/unicast/link/rx.c | 12 +- src/transport/unicast/link/task/lease.c | 8 +- src/transport/unicast/link/task/read.c | 8 +- src/transport/unicast/link/tx.c | 24 +-- 85 files changed, 585 insertions(+), 583 deletions(-) diff --git a/.github/workflows/arduino_esp32.yaml b/.github/workflows/arduino_esp32.yaml index 197ce7776..0e1865973 100644 --- a/.github/workflows/arduino_esp32.yaml +++ b/.github/workflows/arduino_esp32.yaml @@ -51,7 +51,7 @@ jobs: mkdir -p $ARDUINO_BASE cd $ARDUINO_BASE - platformio init -b esp32thing_plus --project-option="build_flags=-DZ_LINK_BLUETOOTH=1 -DZENOH_DEBUG=3" + platformio init -b esp32thing_plus --project-option="build_flags=-DZ_FEATURE_LINK_BLUETOOTH=1 -DZENOH_DEBUG=3" cd $ARDUINO_BASE/lib ln -s $ZENOH_PICO_BASE diff --git a/.github/workflows/emscripten.yaml b/.github/workflows/emscripten.yaml index b995749d9..7080b5579 100644 --- a/.github/workflows/emscripten.yaml +++ b/.github/workflows/emscripten.yaml @@ -34,7 +34,7 @@ jobs: - name: Compile debug run: | mkdir build - emcmake cmake -E env CFLAGS="-DZ_LINK_WS=1 -DZ_LINK_TCP=0 -DZ_LINK_UDP_MULTICAST=0 -DZ_LINK_UDP_UNICAST=0 -DZ_SCOUTING_UDP=0" cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_STANDARD=11 -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_MULTICAST=OFF -DBUILD_INTEGRATION=OFF -DBUILD_TOOLS=OFF -DZENOH_DEBUG=3 -H. -Bbuild + emcmake cmake -E env CFLAGS="-DZ_FEATURE_LINK_WS=1 -DZ_FEATURE_LINK_TCP=0 -DZ_FEATURE_LINK_UDP_MULTICAST=0 -DZ_FEATURE_LINK_UDP_UNICAST=0 -DZ_FEATURE_SCOUTING_UDP=0" cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_STANDARD=11 -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_MULTICAST=OFF -DBUILD_INTEGRATION=OFF -DBUILD_TOOLS=OFF -DZENOH_DEBUG=3 -H. -Bbuild make -C build diff --git a/.github/workflows/mbed.yaml b/.github/workflows/mbed.yaml index 03386d06e..5bfbf4d94 100644 --- a/.github/workflows/mbed.yaml +++ b/.github/workflows/mbed.yaml @@ -51,7 +51,7 @@ jobs: mkdir -p $MBED_BASE cd $MBED_BASE - pio init -b nucleo_f767zi --project-option="framework=mbed" --project-option="build_flags=-DZ_LINK_SERIAL=1 -DZENOH_DEBUG=3" + pio init -b nucleo_f767zi --project-option="framework=mbed" --project-option="build_flags=-DZ_FEATURE_LINK_SERIAL=1 -DZENOH_DEBUG=3" cd $MBED_BASE/lib ln -s $ZENOH_PICO_BASE diff --git a/.github/workflows/zephyr.yaml b/.github/workflows/zephyr.yaml index 7ec080212..c7df7ecaa 100644 --- a/.github/workflows/zephyr.yaml +++ b/.github/workflows/zephyr.yaml @@ -51,7 +51,7 @@ jobs: mkdir -p $ZEPHYR_BASE cd $ZEPHYR_BASE - pio init -b nucleo_f767zi --project-option="framework=zephyr" --project-option="build_flags=-DZ_LINK_SERIAL=1 -DZENOH_DEBUG=3" + pio init -b nucleo_f767zi --project-option="framework=zephyr" --project-option="build_flags=-DZ_FEATURE_LINK_SERIAL=1 -DZENOH_DEBUG=3" cd $ZEPHYR_BASE/lib ln -s $ZENOH_PICO_BASE diff --git a/extra_script.py b/extra_script.py index 391eb8047..3d4780ca8 100644 --- a/extra_script.py +++ b/extra_script.py @@ -57,7 +57,7 @@ "-", "-", "-"] - CPPDEFINES = ["ZENOH_ARDUINO_OPENCR", "ZENOH_C_STANDARD=99", "Z_MULTI_THREAD=0"] + CPPDEFINES = ["ZENOH_ARDUINO_OPENCR", "ZENOH_C_STANDARD=99", "Z_FEATURE_MULTI_THREAD=0"] elif FRAMEWORK == 'espidf': SRC_FILTER = ["+<*>", diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index 21fa2063a..fa2a3ff2a 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -102,117 +102,148 @@ #define Z_CONFIG_ADD_TIMESTAMP_KEY 0x4A #define Z_CONFIG_ADD_TIMESTAMP_DEFAULT "false" -/*------------------ Compile-time configuration properties ------------------*/ +/*------------------ Compile-time feature configuration ------------------*/ + /** - * Default length for Zenoh ID. Maximum size is 16 bytes. - * This configuration will only be applied to Zenoh IDs generated by Zenoh-Pico. + * Enable multi-thread support. */ -#ifndef Z_ZID_LENGTH -#define Z_ZID_LENGTH 16 +#ifndef Z_FEATURE_MULTI_THREAD +#define Z_FEATURE_MULTI_THREAD 1 #endif -#ifndef Z_TSID_LENGTH -#define Z_TSID_LENGTH 16 +/** + * Enable dynamic memory allocation. + */ +#ifndef Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION +#define Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION 0 #endif /** - * Protocol version identifier. - * Do not change this value. + * Enable TCP links. */ -#ifndef Z_PROTO_VERSION -#define Z_PROTO_VERSION 0x08 +#ifndef Z_FEATURE_LINK_TCP +#define Z_FEATURE_LINK_TCP 1 #endif /** - * Default session lease in milliseconds. + * Enable Bluetooth links. */ -#ifndef Z_TRANSPORT_LEASE -#define Z_TRANSPORT_LEASE 10000 +#ifndef Z_FEATURE_LINK_BLUETOOTH +#define Z_FEATURE_LINK_BLUETOOTH 0 #endif /** - * Default session lease expire factor. + * Enable WebSocket links. */ -#ifndef Z_TRANSPORT_LEASE_EXPIRE_FACTOR -#define Z_TRANSPORT_LEASE_EXPIRE_FACTOR 3.5 +#ifndef Z_FEATURE_LINK_WS +#define Z_FEATURE_LINK_WS 0 #endif /** - * Default multicast session join interval in milliseconds. + * Enable Serial links. */ -#ifndef Z_JOIN_INTERVAL -#define Z_JOIN_INTERVAL 2500 +#ifndef Z_FEATURE_LINK_SERIAL +#define Z_FEATURE_LINK_SERIAL 0 #endif /** - * Default socket timeout in milliseconds. + * Enable UDP Scouting. */ -#ifndef Z_CONFIG_SOCKET_TIMEOUT -#define Z_CONFIG_SOCKET_TIMEOUT 100 +#ifndef Z_FEATURE_SCOUTING_UDP +#define Z_FEATURE_SCOUTING_UDP 1 #endif -#ifndef Z_SN_RESOLUTION -#define Z_SN_RESOLUTION 0x02 +/** + * Enable UDP Multicast links. + */ +#ifndef Z_FEATURE_LINK_UDP_MULTICAST +#define Z_FEATURE_LINK_UDP_MULTICAST 1 #endif -#ifndef Z_REQ_RESOLUTION -#define Z_REQ_RESOLUTION 0x02 +/** + * Enable UDP Unicast links. + */ +#ifndef Z_FEATURE_LINK_UDP_UNICAST +#define Z_FEATURE_LINK_UDP_UNICAST 1 #endif /** - * Enable multi-thread support. + * Enable Multicast Transport. */ -#ifndef Z_MULTI_THREAD -#define Z_MULTI_THREAD 1 +#ifndef Z_FEATURE_MULTICAST_TRANSPORT +#if Z_FEATURE_SCOUTING_UDP == 0 && Z_FEATURE_LINK_BLUETOOTH == 0 && Z_FEATURE_LINK_UDP_MULTICAST == 0 +#define Z_FEATURE_MULTICAST_TRANSPORT 0 +#else +#define Z_FEATURE_MULTICAST_TRANSPORT 1 +#endif #endif /** - * Enable TCP links. + * Enable Unicast Transport. */ -#ifndef Z_LINK_TCP -#define Z_LINK_TCP 1 +#ifndef Z_FEATURE_UNICAST_TRANSPORT +#if Z_FEATURE_LINK_TCP == 0 && Z_FEATURE_LINK_UDP_UNICAST == 0 && Z_FEATURE_LINK_SERIAL == 0 && Z_FEATURE_LINK_WS == 0 +#define Z_FEATURE_UNICAST_TRANSPORT 0 +#else +#define Z_FEATURE_UNICAST_TRANSPORT 1 +#endif #endif +/*------------------ Compile-time configuration properties ------------------*/ /** - * Enable UDP Multicast links. + * Default length for Zenoh ID. Maximum size is 16 bytes. + * This configuration will only be applied to Zenoh IDs generated by Zenoh-Pico. */ -#ifndef Z_LINK_UDP_MULTICAST -#define Z_LINK_UDP_MULTICAST 1 +#ifndef Z_ZID_LENGTH +#define Z_ZID_LENGTH 16 +#endif + +#ifndef Z_TSID_LENGTH +#define Z_TSID_LENGTH 16 #endif /** - * Enable UDP Unicast links. + * Protocol version identifier. + * Do not change this value. */ -#ifndef Z_LINK_UDP_UNICAST -#define Z_LINK_UDP_UNICAST 1 +#ifndef Z_PROTO_VERSION +#define Z_PROTO_VERSION 0x08 #endif /** - * Enable Bluetooth links. + * Default session lease in milliseconds. */ -#ifndef Z_LINK_BLUETOOTH -#define Z_LINK_BLUETOOTH 0 +#ifndef Z_TRANSPORT_LEASE +#define Z_TRANSPORT_LEASE 10000 #endif /** - * Enable Serial links. + * Default session lease expire factor. */ -#ifndef Z_LINK_SERIAL -#define Z_LINK_SERIAL 0 +#ifndef Z_TRANSPORT_LEASE_EXPIRE_FACTOR +#define Z_TRANSPORT_LEASE_EXPIRE_FACTOR 3.5 #endif /** - * Enable WebSocket links. + * Default multicast session join interval in milliseconds. */ -#ifndef Z_LINK_WS -#define Z_LINK_WS 0 +#ifndef Z_JOIN_INTERVAL +#define Z_JOIN_INTERVAL 2500 #endif /** - * Enable UDP Scouting. + * Default socket timeout in milliseconds. */ -#ifndef Z_SCOUTING_UDP -#define Z_SCOUTING_UDP 1 +#ifndef Z_CONFIG_SOCKET_TIMEOUT +#define Z_CONFIG_SOCKET_TIMEOUT 100 +#endif + +#ifndef Z_SN_RESOLUTION +#define Z_SN_RESOLUTION 0x02 +#endif + +#ifndef Z_REQ_RESOLUTION +#define Z_REQ_RESOLUTION 0x02 #endif /** @@ -242,33 +273,4 @@ #define Z_FRAG_MAX_SIZE 300000 #endif -/** - * Enable dynamic memory allocation. - */ -#ifndef Z_DYNAMIC_MEMORY_ALLOCATION -#define Z_DYNAMIC_MEMORY_ALLOCATION 0 -#endif - -/** - * Enable Multicast Transport. - */ -#ifndef Z_MULTICAST_TRANSPORT -#if Z_SCOUTING_UDP == 0 && Z_LINK_BLUETOOTH == 0 && Z_LINK_UDP_MULTICAST == 0 -#define Z_MULTICAST_TRANSPORT 0 -#else -#define Z_MULTICAST_TRANSPORT 1 -#endif -#endif - -/** - * Enable Unicast Transport. - */ -#ifndef Z_UNICAST_TRANSPORT -#if Z_LINK_TCP == 0 && Z_LINK_UDP_UNICAST == 0 && Z_LINK_SERIAL == 0 && Z_LINK_WS == 0 -#define Z_UNICAST_TRANSPORT 0 -#else -#define Z_UNICAST_TRANSPORT 1 -#endif -#endif - #endif /* INCLUDE_ZENOH_PICO_CONFIG_H */ diff --git a/include/zenoh-pico/link/config/bt.h b/include/zenoh-pico/link/config/bt.h index ae24fa245..40827e76c 100644 --- a/include/zenoh-pico/link/config/bt.h +++ b/include/zenoh-pico/link/config/bt.h @@ -19,7 +19,7 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #define BT_CONFIG_ARGC 3 diff --git a/include/zenoh-pico/link/config/serial.h b/include/zenoh-pico/link/config/serial.h index 3b5fd16a6..85270be62 100644 --- a/include/zenoh-pico/link/config/serial.h +++ b/include/zenoh-pico/link/config/serial.h @@ -20,7 +20,7 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #define SERIAL_CONFIG_ARGC 1 diff --git a/include/zenoh-pico/link/config/tcp.h b/include/zenoh-pico/link/config/tcp.h index a5d758544..ed57e7700 100644 --- a/include/zenoh-pico/link/config/tcp.h +++ b/include/zenoh-pico/link/config/tcp.h @@ -19,7 +19,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/config.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #define TCP_CONFIG_ARGC 1 diff --git a/include/zenoh-pico/link/config/udp.h b/include/zenoh-pico/link/config/udp.h index 877896493..ab8875d5e 100644 --- a/include/zenoh-pico/link/config/udp.h +++ b/include/zenoh-pico/link/config/udp.h @@ -18,7 +18,7 @@ #include "zenoh-pico/collections/intmap.h" #include "zenoh-pico/collections/string.h" -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #define UDP_CONFIG_ARGC 3 diff --git a/include/zenoh-pico/link/config/ws.h b/include/zenoh-pico/link/config/ws.h index 1551bc31e..82ef8d596 100644 --- a/include/zenoh-pico/link/config/ws.h +++ b/include/zenoh-pico/link/config/ws.h @@ -19,7 +19,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/config.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #define WS_CONFIG_TOUT_KEY 0x01 #define WS_CONFIG_TOUT_STR "tout" diff --git a/include/zenoh-pico/link/endpoint.h b/include/zenoh-pico/link/endpoint.h index c3cf1b42a..bd7c8cbc3 100644 --- a/include/zenoh-pico/link/endpoint.h +++ b/include/zenoh-pico/link/endpoint.h @@ -22,19 +22,19 @@ #include "zenoh-pico/utils/result.h" /*------------------ Locator ------------------*/ -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #define TCP_SCHEMA "tcp" #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #define UDP_SCHEMA "udp" #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #define BT_SCHEMA "bt" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #define SERIAL_SCHEMA "serial" #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #define WS_SCHEMA "ws" #endif diff --git a/include/zenoh-pico/link/link.h b/include/zenoh-pico/link/link.h index 3f0400b20..9a49f2862 100644 --- a/include/zenoh-pico/link/link.h +++ b/include/zenoh-pico/link/link.h @@ -20,23 +20,23 @@ #include "zenoh-pico/protocol/iobuf.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #include "zenoh-pico/system/link/tcp.h" #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #include "zenoh-pico/system/link/udp.h" #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #include "zenoh-pico/system/link/bt.h" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #include "zenoh-pico/system/link/serial.h" #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #include "zenoh-pico/system/link/ws.h" #endif @@ -77,19 +77,19 @@ typedef struct _z_link_t { _z_endpoint_t _endpoint; union { -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 _z_tcp_socket_t _tcp; #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 _z_udp_socket_t _udp; #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 _z_bt_socket_t _bt; #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 _z_serial_socket_t _serial; #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 _z_ws_socket_t _ws; #endif } _socket; diff --git a/include/zenoh-pico/link/manager.h b/include/zenoh-pico/link/manager.h index fefeea002..f494784e4 100644 --- a/include/zenoh-pico/link/manager.h +++ b/include/zenoh-pico/link/manager.h @@ -19,27 +19,27 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/link/link.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 int8_t _z_endpoint_tcp_valid(_z_endpoint_t *ep); int8_t _z_new_link_tcp(_z_link_t *zl, _z_endpoint_t *ep); #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *ep); int8_t _z_new_link_udp_unicast(_z_link_t *zl, _z_endpoint_t ep); #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *ep); int8_t _z_new_link_udp_multicast(_z_link_t *zl, _z_endpoint_t ep); #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 int8_t _z_endpoint_bt_valid(_z_endpoint_t *ep); int8_t _z_new_link_bt(_z_link_t *zl, _z_endpoint_t ep); #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 int8_t _z_endpoint_serial_valid(_z_endpoint_t *ep); int8_t _z_new_link_serial(_z_link_t *zl, _z_endpoint_t ep); #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 int8_t _z_endpoint_ws_valid(_z_endpoint_t *ep); int8_t _z_new_link_ws(_z_link_t *zl, _z_endpoint_t *ep); #endif diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index bebe7608c..a23fb84dc 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -28,9 +28,9 @@ * A zenoh-net session. */ typedef struct { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_t _mutex_inner; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Zenoh-pico is considering a single transport per session. _z_transport_t _tp; @@ -122,7 +122,7 @@ int8_t _zp_send_keep_alive(_z_session_t *z); */ int8_t _zp_send_join(_z_session_t *z); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /** * Start a separate task to read from the network and process the messages * as soon as they are received. Note that the task can be implemented in @@ -172,6 +172,6 @@ int8_t _zp_start_lease_task(_z_session_t *z); * ``0`` in case of success, ``-1`` in case of failure. */ int8_t _zp_stop_lease_task(_z_session_t *z); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 #endif /* INCLUDE_ZENOH_PICO_NET_SESSION_H */ diff --git a/include/zenoh-pico/session/session.h b/include/zenoh-pico/session/session.h index 8b394e844..a6102da23 100644 --- a/include/zenoh-pico/session/session.h +++ b/include/zenoh-pico/session/session.h @@ -170,10 +170,10 @@ _Z_ELEM_DEFINE(_z_pending_query, _z_pending_query_t, _z_noop_size, _z_pending_qu _Z_LIST_DEFINE(_z_pending_query, _z_pending_query_t) typedef struct { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_t _mutex; _z_condvar_t _cond_var; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_reply_data_list_t *_replies; } _z_pending_query_collect_t; diff --git a/include/zenoh-pico/system/link/bt.h b/include/zenoh-pico/system/link/bt.h index 86fe2bbcf..b155e34b3 100644 --- a/include/zenoh-pico/system/link/bt.h +++ b/include/zenoh-pico/system/link/bt.h @@ -19,7 +19,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/config.h" -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #ifdef __cplusplus extern "C" { diff --git a/include/zenoh-pico/system/link/serial.h b/include/zenoh-pico/system/link/serial.h index 1fa81c7af..954fd2911 100644 --- a/include/zenoh-pico/system/link/serial.h +++ b/include/zenoh-pico/system/link/serial.h @@ -21,7 +21,7 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #define _Z_SERIAL_MTU_SIZE 1500 #define _Z_SERIAL_MFS_SIZE _Z_SERIAL_MTU_SIZE + 2 + 4 // MTU + Serial Len + Serial CRC32 diff --git a/include/zenoh-pico/system/link/tcp.h b/include/zenoh-pico/system/link/tcp.h index 382b8b7de..e90b688eb 100644 --- a/include/zenoh-pico/system/link/tcp.h +++ b/include/zenoh-pico/system/link/tcp.h @@ -20,7 +20,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 typedef struct { _z_sys_net_socket_t _sock; diff --git a/include/zenoh-pico/system/link/udp.h b/include/zenoh-pico/system/link/udp.h index a154c20f0..8b6957812 100644 --- a/include/zenoh-pico/system/link/udp.h +++ b/include/zenoh-pico/system/link/udp.h @@ -20,7 +20,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 typedef struct { _z_sys_net_socket_t _sock; diff --git a/include/zenoh-pico/system/link/ws.h b/include/zenoh-pico/system/link/ws.h index feab79328..52edd2f11 100644 --- a/include/zenoh-pico/system/link/ws.h +++ b/include/zenoh-pico/system/link/ws.h @@ -20,7 +20,7 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/system/platform.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 typedef struct { _z_sys_net_socket_t _sock; diff --git a/include/zenoh-pico/system/platform.h b/include/zenoh-pico/system/platform.h index 07e1f009e..4a8697800 100644 --- a/include/zenoh-pico/system/platform.h +++ b/include/zenoh-pico/system/platform.h @@ -56,7 +56,7 @@ void *z_malloc(size_t size); void *z_realloc(void *ptr, size_t size); void z_free(void *ptr); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Thread ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg); int8_t _z_task_join(_z_task_t *task); @@ -77,7 +77,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv); int8_t _z_condvar_signal(_z_condvar_t *cv); int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time); diff --git a/include/zenoh-pico/system/platform/arduino/esp32.h b/include/zenoh-pico/system/platform/arduino/esp32.h index bac42aa72..569efe46f 100644 --- a/include/zenoh-pico/system/platform/arduino/esp32.h +++ b/include/zenoh-pico/system/platform/arduino/esp32.h @@ -19,16 +19,16 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 #include -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef TaskHandle_t _z_task_t; typedef void *_z_task_attr_t; // Not used in ESP32 typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; @@ -38,13 +38,13 @@ typedef struct HardwareSerial HardwareSerial; // Forward declaration to be us typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 int _fd; #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 BluetoothSerial *_bts; // As pointer to cross the boundary between C and C++ #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 HardwareSerial *_serial; // As pointer to cross the boundary between C and C++ #endif }; @@ -52,7 +52,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/arduino/opencr.h b/include/zenoh-pico/system/platform/arduino/opencr.h index 23c43f222..2a7488775 100644 --- a/include/zenoh-pico/system/platform/arduino/opencr.h +++ b/include/zenoh-pico/system/platform/arduino/opencr.h @@ -20,12 +20,12 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef void *_z_task_t; typedef void *_z_task_attr_t; typedef void *_z_mutex_t; typedef void *_z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; @@ -36,10 +36,10 @@ typedef struct WiFiUDP WiFiUDP; // Forward declaration to be used in _z_s typedef struct { union { -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 WiFiClient *_tcp; // As pointer to cross the boundary between C and C++ #endif -#if Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 WiFiUDP *_udp; // As pointer to cross the boundary between C and C++ #endif _Bool _err; @@ -53,7 +53,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 __z_net_iptcp_addr_t _iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/emscripten.h b/include/zenoh-pico/system/platform/emscripten.h index a2f340921..fcb732aab 100644 --- a/include/zenoh-pico/system/platform/emscripten.h +++ b/include/zenoh-pico/system/platform/emscripten.h @@ -20,19 +20,19 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef pthread_t _z_task_t; typedef pthread_attr_t _z_task_attr_t; typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef double z_clock_t; typedef double z_time_t; typedef struct { union { -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 struct { int _fd; uint32_t _tout; @@ -43,7 +43,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/espidf.h b/include/zenoh-pico/system/platform/espidf.h index 6c35dd1f0..2ba7773d7 100644 --- a/include/zenoh-pico/system/platform/espidf.h +++ b/include/zenoh-pico/system/platform/espidf.h @@ -22,22 +22,22 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef TaskHandle_t _z_task_t; typedef void *_z_task_attr_t; // Not used in ESP32 typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 int _fd; #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 uart_port_t _serial; #endif }; @@ -45,7 +45,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/mbed.h b/include/zenoh-pico/system/platform/mbed.h index ca10d0459..ba18844e8 100644 --- a/include/zenoh-pico/system/platform/mbed.h +++ b/include/zenoh-pico/system/platform/mbed.h @@ -22,12 +22,12 @@ typedef int _z_socket_t; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef void *_z_task_t; // Workaround as MBED is a C++ library typedef void *_z_task_attr_t; // Workaround as MBED is a C++ library typedef void *_z_mutex_t; // Workaround as MBED is a C++ library typedef void *_z_condvar_t; // Workaround as MBED is a C++ library -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef void *z_clock_t; // Not defined typedef struct timeval z_time_t; @@ -40,13 +40,13 @@ typedef struct SocketAddress SocketAddress; // Forward declaration to be used typedef struct { _Bool _err; union { -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 TCPSocket *_tcp; // As pointer to cross the boundary between C and C++ #endif -#if Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 UDPSocket *_udp; // As pointer to cross the boundary between C and C++ #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 BufferedSerial *_serial; // As pointer to cross the boundary between C and C++ #endif }; @@ -55,7 +55,7 @@ typedef struct { typedef struct { _Bool _err; union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 SocketAddress *_iptcp; // As pointer to cross the boundary between C and C++ #endif }; diff --git a/include/zenoh-pico/system/platform/unix.h b/include/zenoh-pico/system/platform/unix.h index 3faa48333..8084e22db 100644 --- a/include/zenoh-pico/system/platform/unix.h +++ b/include/zenoh-pico/system/platform/unix.h @@ -23,19 +23,19 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef pthread_t _z_task_t; typedef pthread_attr_t _z_task_attr_t; typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 int _fd; #endif }; @@ -43,7 +43,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/system/platform/void.h b/include/zenoh-pico/system/platform/void.h index 26197d375..8bebe22f2 100644 --- a/include/zenoh-pico/system/platform/void.h +++ b/include/zenoh-pico/system/platform/void.h @@ -17,12 +17,12 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef void *_z_task_t; typedef void *_z_task_attr_t; typedef void *_z_mutex_t; typedef void *_z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef void *z_clock_t; typedef void *z_time_t; diff --git a/include/zenoh-pico/system/platform/windows.h b/include/zenoh-pico/system/platform/windows.h index f7c7d1ccb..fa5aff62d 100644 --- a/include/zenoh-pico/system/platform/windows.h +++ b/include/zenoh-pico/system/platform/windows.h @@ -20,19 +20,19 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef HANDLE *_z_task_t; typedef void *_z_task_attr_t; // Not used in Windows typedef SRWLOCK _z_mutex_t; typedef CONDITION_VARIABLE _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timeb z_clock_t; typedef struct timeb z_time_t; typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 SOCKET _fd; #endif } _sock; @@ -40,7 +40,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif } _ep; diff --git a/include/zenoh-pico/system/platform/zephyr.h b/include/zenoh-pico/system/platform/zephyr.h index 4b318c9d9..c0ad3c378 100644 --- a/include/zenoh-pico/system/platform/zephyr.h +++ b/include/zenoh-pico/system/platform/zephyr.h @@ -30,22 +30,22 @@ #include "zenoh-pico/config.h" -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 typedef pthread_t _z_task_t; typedef pthread_attr_t _z_task_attr_t; typedef pthread_mutex_t _z_mutex_t; typedef pthread_cond_t _z_condvar_t; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 typedef struct timespec z_clock_t; typedef struct timeval z_time_t; typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 int _fd; #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 const struct device *_serial; #endif }; @@ -53,7 +53,7 @@ typedef struct { typedef struct { union { -#if Z_LINK_TCP == 1 || Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 struct addrinfo *_iptcp; #endif }; diff --git a/include/zenoh-pico/transport/transport.h b/include/zenoh-pico/transport/transport.h index 1982b1b92..6996f4b5a 100644 --- a/include/zenoh-pico/transport/transport.h +++ b/include/zenoh-pico/transport/transport.h @@ -56,11 +56,11 @@ _z_transport_peer_entry_list_t *_z_transport_peer_entry_list_insert(_z_transport typedef struct { // Session associated to the transport -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // TX and RX mutexes _z_mutex_t _mutex_rx; _z_mutex_t _mutex_tx; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_link_t _link; @@ -82,12 +82,12 @@ typedef struct { void *_session; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_task_t *_read_task; _z_task_t *_lease_task; volatile _Bool _read_task_running; volatile _Bool _lease_task_running; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 volatile _Bool _received; volatile _Bool _transmitted; @@ -97,14 +97,14 @@ typedef struct { // Session associated to the transport void *_session; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // TX and RX mutexes _z_mutex_t _mutex_rx; _z_mutex_t _mutex_tx; // Peer list mutex _z_mutex_t _mutex_peer; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_link_t _link; @@ -121,12 +121,12 @@ typedef struct { // Known valid peers _z_transport_peer_entry_list_t *_peers; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_task_t *_read_task; _z_task_t *_lease_task; volatile _Bool _read_task_running; volatile _Bool _lease_task_running; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 volatile _Bool _transmitted; } _z_transport_multicast_t; diff --git a/src/api/api.c b/src/api/api.c index db8d725e9..b673e3659 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -561,7 +561,7 @@ int8_t z_info_peers_zid(const z_session_t zs, z_owned_closure_zid_t *callback) { void *ctx = callback->context; callback->context = NULL; -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zs._val->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { _z_transport_peer_entry_list_t *l = zs._val->_tp._transport._multicast._peers; for (; l != NULL; l = _z_transport_peer_entry_list_tail(l)) { @@ -573,7 +573,7 @@ int8_t z_info_peers_zid(const z_session_t zs, z_owned_closure_zid_t *callback) { } #else (void)zs; -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 if (callback->drop != NULL) { callback->drop(ctx); @@ -586,12 +586,12 @@ int8_t z_info_routers_zid(const z_session_t zs, z_owned_closure_zid_t *callback) void *ctx = callback->context; callback->context = NULL; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zs._val->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { z_id_t id = zs._val->_tp._transport._unicast._remote_zid; callback->call(&id, ctx); } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 if (callback->drop != NULL) { callback->drop(ctx); @@ -739,17 +739,17 @@ z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, con // 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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) { -#endif // Z_MULTICAST_TRANSPORT == 1 +#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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 z_publisher_options_t opt = z_publisher_options_default(); if (options != NULL) { @@ -815,9 +815,9 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z // 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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) { -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr); if (r == NULL) { char *wild = strpbrk(keyexpr._suffix, "*$"); @@ -833,9 +833,9 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z uint16_t id = _z_declare_resource(zs._val, keyexpr); key = _z_rid_with_suffix(id, wild); } -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_subinfo_t subinfo = _z_subinfo_push_default(); if (options != NULL) { @@ -904,17 +904,17 @@ z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_o // 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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) { -#endif // Z_MULTICAST_TRANSPORT == 1 +#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_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 z_queryable_options_t opt = z_queryable_options_default(); if (options != NULL) { @@ -970,7 +970,7 @@ zp_task_read_options_t zp_task_read_options_default(void) { return (zp_task_read int8_t zp_start_read_task(z_session_t zs, const zp_task_read_options_t *options) { (void)(options); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 return _zp_start_read_task(zs._val); #else (void)(zs); @@ -979,7 +979,7 @@ int8_t zp_start_read_task(z_session_t zs, const zp_task_read_options_t *options) } int8_t zp_stop_read_task(z_session_t zs) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 return _zp_stop_read_task(zs._val); #else (void)(zs); @@ -991,7 +991,7 @@ zp_task_lease_options_t zp_task_lease_options_default(void) { return (zp_task_le int8_t zp_start_lease_task(z_session_t zs, const zp_task_lease_options_t *options) { (void)(options); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 return _zp_start_lease_task(zs._val); #else (void)(zs); @@ -1000,7 +1000,7 @@ int8_t zp_start_lease_task(z_session_t zs, const zp_task_lease_options_t *option } int8_t zp_stop_lease_task(z_session_t zs) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 return _zp_stop_lease_task(zs._val); #else (void)(zs); diff --git a/src/link/config/bt.c b/src/link/config/bt.c index 989817cac..0c633b7cc 100644 --- a/src/link/config/bt.c +++ b/src/link/config/bt.c @@ -15,7 +15,7 @@ #include -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 size_t _z_bt_config_strlen(const _z_str_intmap_t *s) { BT_CONFIG_MAPPING_BUILD diff --git a/src/link/config/serial.c b/src/link/config/serial.c index c0608195d..876174f79 100644 --- a/src/link/config/serial.c +++ b/src/link/config/serial.c @@ -16,7 +16,7 @@ #include -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 size_t _z_serial_config_strlen(const _z_str_intmap_t *s) { SERIAL_CONFIG_MAPPING_BUILD diff --git a/src/link/config/tcp.c b/src/link/config/tcp.c index e5ad017ae..0da276204 100644 --- a/src/link/config/tcp.c +++ b/src/link/config/tcp.c @@ -18,7 +18,7 @@ #include "zenoh-pico/config.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 size_t _z_tcp_config_strlen(const _z_str_intmap_t *s) { TCP_CONFIG_MAPPING_BUILD diff --git a/src/link/config/udp.c b/src/link/config/udp.c index 3629f25be..3dc5f06c6 100644 --- a/src/link/config/udp.c +++ b/src/link/config/udp.c @@ -18,7 +18,7 @@ #include "zenoh-pico/config.h" -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 size_t _z_udp_config_strlen(const _z_str_intmap_t *s) { UDP_CONFIG_MAPPING_BUILD diff --git a/src/link/config/ws.c b/src/link/config/ws.c index ae876596b..14e4c113c 100644 --- a/src/link/config/ws.c +++ b/src/link/config/ws.c @@ -18,7 +18,7 @@ #include "zenoh-pico/config.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 size_t _z_ws_config_strlen(const _z_str_intmap_t *s) { WS_CONFIG_MAPPING_BUILD diff --git a/src/link/endpoint.c b/src/link/endpoint.c index a4348db71..d06a67158 100644 --- a/src/link/endpoint.c +++ b/src/link/endpoint.c @@ -20,19 +20,19 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #include "zenoh-pico/link/config/tcp.h" #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #include "zenoh-pico/link/config/udp.h" #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #include "zenoh-pico/link/config/bt.h" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #include "zenoh-pico/link/config/serial.h" #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #include "zenoh-pico/link/config/ws.h" #endif /*------------------ Locator ------------------*/ @@ -292,27 +292,27 @@ int8_t _z_endpoint_config_from_str(_z_str_intmap_t *strint, const char *str, con p_start = _z_ptr_char_offset(p_start, 1); // Call the right configuration parser depending on the protocol -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 if (_z_str_eq(proto, TCP_SCHEMA) == true) { ret = _z_tcp_config_from_str(strint, p_start); } else #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 if (_z_str_eq(proto, UDP_SCHEMA) == true) { ret = _z_udp_config_from_str(strint, p_start); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_str_eq(proto, BT_SCHEMA) == true) { ret = _z_bt_config_from_str(strint, p_start); } else #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 if (_z_str_eq(proto, SERIAL_SCHEMA) == true) { ret = _z_serial_config_from_str(strint, p_start); } else #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 if (_z_str_eq(proto, WS_SCHEMA) == true) { ret = _z_ws_config_from_str(strint, p_start); } else @@ -329,27 +329,27 @@ size_t _z_endpoint_config_strlen(const _z_str_intmap_t *s, const char *proto) { size_t len = 0; // Call the right configuration parser depending on the protocol -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 if (_z_str_eq(proto, TCP_SCHEMA) == true) { len = _z_tcp_config_strlen(s); } else #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 if (_z_str_eq(proto, UDP_SCHEMA) == true) { len = _z_udp_config_strlen(s); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_str_eq(proto, BT_SCHEMA) == true) { len = _z_bt_config_strlen(s); } else #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 if (_z_str_eq(proto, SERIAL_SCHEMA) == true) { len = _z_serial_config_strlen(s); } else #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 if (_z_str_eq(proto, WS_SCHEMA) == true) { len = _z_ws_config_strlen(s); } else @@ -365,27 +365,27 @@ char *_z_endpoint_config_to_str(const _z_str_intmap_t *s, const char *proto) { char *res = NULL; // Call the right configuration parser depending on the protocol -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 if (_z_str_eq(proto, TCP_SCHEMA) == true) { res = _z_tcp_config_to_str(s); } else #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 if (_z_str_eq(proto, UDP_SCHEMA) == true) { res = _z_udp_config_to_str(s); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_str_eq(proto, BT_SCHEMA) == true) { res = _z_bt_config_to_str(s); } else #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 if (_z_str_eq(proto, SERIAL_SCHEMA) == true) { res = _z_serial_config_to_str(s); } else #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 if (_z_str_eq(proto, WS_SCHEMA) == true) { res = _z_ws_config_to_str(s); } else diff --git a/src/link/link.c b/src/link/link.c index 5c409e353..1a5f89925 100644 --- a/src/link/link.c +++ b/src/link/link.c @@ -28,27 +28,27 @@ int8_t _z_open_link(_z_link_t *zl, const char *locator) { if (ret == _Z_RES_OK) { // TODO[peer]: when peer unicast mode is supported, this must be revisited // Create transport link -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 if (_z_endpoint_tcp_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_tcp(zl, &ep); } else #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 if (_z_endpoint_udp_unicast_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_udp_unicast(zl, ep); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_endpoint_bt_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_bt(zl, ep); } else #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 if (_z_endpoint_serial_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_serial(zl, ep); } else #endif -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 if (_z_endpoint_ws_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_ws(zl, &ep); } else @@ -82,12 +82,12 @@ int8_t _z_listen_link(_z_link_t *zl, const char *locator) { if (ret == _Z_RES_OK) { // TODO[peer]: when peer unicast mode is supported, this must be revisited // Create transport link -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 if (_z_endpoint_udp_multicast_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_udp_multicast(zl, ep); } else #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 if (_z_endpoint_bt_valid(&ep) == _Z_RES_OK) { ret = _z_new_link_bt(zl, ep); } else diff --git a/src/link/multicast/bt.c b/src/link/multicast/bt.c index e269d420e..332e5f9fa 100644 --- a/src/link/multicast/bt.c +++ b/src/link/multicast/bt.c @@ -20,7 +20,7 @@ #include "zenoh-pico/link/manager.h" #include "zenoh-pico/system/link/bt.h" -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #define SPP_MAXIMUM_PAYLOAD 128 diff --git a/src/link/multicast/udp.c b/src/link/multicast/udp.c index 981b1a37f..bcb2a4dc8 100644 --- a/src/link/multicast/udp.c +++ b/src/link/multicast/udp.c @@ -23,7 +23,7 @@ #include "zenoh-pico/system/link/udp.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 char *__z_parse_port_segment_udp_multicast(const char *address) { char *ret = NULL; diff --git a/src/link/unicast/serial.c b/src/link/unicast/serial.c index 40cdbf349..eebbff12a 100644 --- a/src/link/unicast/serial.c +++ b/src/link/unicast/serial.c @@ -23,7 +23,7 @@ #include "zenoh-pico/system/link/serial.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #define SPP_MAXIMUM_PAYLOAD 128 diff --git a/src/link/unicast/tcp.c b/src/link/unicast/tcp.c index c6af264d2..b7b78fa43 100644 --- a/src/link/unicast/tcp.c +++ b/src/link/unicast/tcp.c @@ -23,7 +23,7 @@ #include "zenoh-pico/system/link/tcp.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 char *__z_parse_port_segment_tcp(char *address) { char *ret = NULL; diff --git a/src/link/unicast/udp.c b/src/link/unicast/udp.c index 63ae5de04..c87441709 100644 --- a/src/link/unicast/udp.c +++ b/src/link/unicast/udp.c @@ -23,7 +23,7 @@ #include "zenoh-pico/system/link/udp.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 char *__z_parse_port_segment_udp_unicast(char *address) { char *ret = NULL; diff --git a/src/link/unicast/ws.c b/src/link/unicast/ws.c index cd7edd673..426e5fa96 100644 --- a/src/link/unicast/ws.c +++ b/src/link/unicast/ws.c @@ -24,7 +24,7 @@ #include "zenoh-pico/system/link/ws.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 char *__z_parse_port_segment_ws(char *address) { char *ret = NULL; diff --git a/src/net/session.c b/src/net/session.c index 2f2b0c93e..24d66dea6 100644 --- a/src/net/session.c +++ b/src/net/session.c @@ -33,7 +33,7 @@ int8_t __z_open_inner(_z_session_t *zn, char *locator, z_whatami_t mode) { int8_t ret = _Z_RES_OK; _z_id_t local_zid = _z_id_empty(); -#if Z_UNICAST_TRANSPORT == 1 || Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 || Z_FEATURE_MULTICAST_TRANSPORT == 1 ret = _z_session_generate_zid(&local_zid, Z_ZID_LENGTH); if (ret == _Z_RES_OK) { ret = _z_new_transport(&zn->_tp, &local_zid, locator, mode); @@ -154,14 +154,14 @@ _z_config_t *_z_info(const _z_session_t *zn) { _z_bytes_t local_zid = _z_bytes_wrap(zn->_local_zid.id, _z_id_len(zn->_local_zid)); _zp_config_insert(ps, Z_INFO_PID_KEY, _z_string_from_bytes(&local_zid)); -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { _z_id_t remote_zid = zn->_tp._transport._unicast._remote_zid; _z_bytes_t remote_zidbytes = _z_bytes_wrap(remote_zid.id, _z_id_len(remote_zid)); _zp_config_insert(ps, Z_INFO_ROUTER_PID_KEY, _z_string_from_bytes(&remote_zidbytes)); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { _z_transport_peer_entry_list_t *xs = zn->_tp._transport._multicast._peers; while (xs != NULL) { @@ -172,7 +172,7 @@ _z_config_t *_z_info(const _z_session_t *zn) { xs = _z_transport_peer_entry_list_tail(xs); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { __asm__("nop"); } @@ -187,7 +187,7 @@ int8_t _zp_send_keep_alive(_z_session_t *zn) { return _z_send_keep_alive(&zn->_t int8_t _zp_send_join(_z_session_t *zn) { return _z_send_join(&zn->_tp); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 int8_t _zp_start_read_task(_z_session_t *zn) { int8_t ret = _Z_RES_OK; @@ -195,7 +195,7 @@ int8_t _zp_start_read_task(_z_session_t *zn) { if (task != NULL) { (void)memset(task, 0, sizeof(_z_task_t)); -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._read_task = task; zn->_tp._transport._unicast._read_task_running = true; @@ -205,8 +205,8 @@ int8_t _zp_start_read_task(_z_session_t *zn) { z_free(task); } } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._read_task = task; zn->_tp._transport._multicast._read_task_running = true; @@ -216,7 +216,7 @@ int8_t _zp_start_read_task(_z_session_t *zn) { z_free(task); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; z_free(task); @@ -229,16 +229,16 @@ int8_t _zp_start_read_task(_z_session_t *zn) { int8_t _zp_stop_read_task(_z_session_t *zn) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._read_task_running = false; } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._read_task_running = false; } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -253,7 +253,7 @@ int8_t _zp_start_lease_task(_z_session_t *zn) { if (task != NULL) { (void)memset(task, 0, sizeof(_z_task_t)); -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._lease_task = task; zn->_tp._transport._unicast._lease_task_running = true; @@ -263,8 +263,8 @@ int8_t _zp_start_lease_task(_z_session_t *zn) { z_free(task); } } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._lease_task = task; zn->_tp._transport._multicast._lease_task_running = true; @@ -274,7 +274,7 @@ int8_t _zp_start_lease_task(_z_session_t *zn) { z_free(task); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; z_free(task); @@ -287,20 +287,20 @@ int8_t _zp_start_lease_task(_z_session_t *zn) { int8_t _zp_stop_lease_task(_z_session_t *zn) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._lease_task_running = false; } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._lease_task_running = false; } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } return ret; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 diff --git a/src/session/query.c b/src/session/query.c index 52caa9beb..ec976c7e3 100644 --- a/src/session/query.c +++ b/src/session/query.c @@ -102,15 +102,15 @@ _z_pending_query_t *__unsafe__z_get_pending_query_by_id(_z_session_t *zn, const } _z_pending_query_t *_z_get_pending_query_by_id(_z_session_t *zn, const _z_zint_t id) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_t *pql = __unsafe__z_get_pending_query_by_id(zn, id); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return pql; } @@ -120,9 +120,9 @@ int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) _Z_DEBUG(">>> Allocating query for (%ju:%s,%s)\n", (uintmax_t)pen_qry->_key._id, pen_qry->_key._suffix, pen_qry->_parameters); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_t *pql = __unsafe__z_get_pending_query_by_id(zn, pen_qry->_id); if (pql == NULL) { // Register query only if a pending one with the same ID does not exist @@ -131,9 +131,9 @@ int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) ret = _Z_ERR_ENTITY_DECLARATION_FAILED; } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -143,9 +143,9 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons const _z_timestamp_t timestamp) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_t *pen_qry = __unsafe__z_get_pending_query_by_id(zn, id); if ((ret == _Z_RES_OK) && (pen_qry == NULL)) { @@ -215,9 +215,9 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Trigger the user callback if ((ret == _Z_RES_OK) && (pen_qry->_consolidation != Z_CONSOLIDATION_MODE_LATEST)) { @@ -234,9 +234,9 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Final reply received for unknown query id _z_pending_query_t *pen_qry = __unsafe__z_get_pending_query_by_id(zn, id); @@ -260,33 +260,33 @@ int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { zn->_pending_queries = _z_pending_query_list_drop_filter(zn->_pending_queries, _z_pending_query_eq, pen_qry); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } void _z_unregister_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 zn->_pending_queries = _z_pending_query_list_drop_filter(zn->_pending_queries, _z_pending_query_eq, pen_qry); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_pending_queries(_z_session_t *zn) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_list_free(&zn->_pending_queries); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/queryable.c b/src/session/queryable.c index d18c5705e..7431712b4 100644 --- a/src/session/queryable.c +++ b/src/session/queryable.c @@ -89,30 +89,30 @@ _z_questionable_sptr_list_t *__unsafe_z_get_questionable_by_key(_z_session_t *zn } _z_questionable_sptr_t *_z_get_questionable_by_id(_z_session_t *zn, const _z_zint_t id) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_questionable_sptr_t *qle = __unsafe_z_get_questionable_by_id(zn, id); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return qle; } _z_questionable_sptr_list_t *_z_get_questionable_by_key(_z_session_t *zn, const _z_keyexpr_t *keyexpr) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, keyexpr); _z_questionable_sptr_list_t *qles = __unsafe_z_get_questionable_by_key(zn, key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return qles; } @@ -121,9 +121,9 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab _Z_DEBUG(">>> Allocating queryable for (%ju:%s)\n", (uintmax_t)q->_key._id, q->_key._suffix); _z_questionable_sptr_t *ret = NULL; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 ret = (_z_questionable_sptr_t *)z_malloc(sizeof(_z_questionable_sptr_t)); if (ret != NULL) { @@ -131,9 +131,9 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab zn->_local_questionable = _z_questionable_sptr_list_push(zn->_local_questionable, ret); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -141,17 +141,17 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, const _z_keyexpr_t q_key, uint32_t qid) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, &q_key); if (key._suffix != NULL) { _z_questionable_sptr_list_t *qles = __unsafe_z_get_questionable_by_key(zn, key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Build the query z_query_t q; @@ -190,9 +190,9 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons } _z_msg_clear(&z_msg); } else { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 ret = _Z_ERR_KEYEXPR_UNKNOWN; } @@ -201,26 +201,26 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons } void _z_unregister_questionable(_z_session_t *zn, _z_questionable_sptr_t *qle) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 zn->_local_questionable = _z_questionable_sptr_list_drop_filter(zn->_local_questionable, _z_questionable_sptr_eq, qle); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_questionables(_z_session_t *zn) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_questionable_sptr_list_free(&zn->_local_questionable); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/resource.c b/src/session/resource.c index 30c29702e..8a36ef951 100644 --- a/src/session/resource.c +++ b/src/session/resource.c @@ -174,15 +174,15 @@ _z_keyexpr_t __unsafe_z_get_expanded_key_from_key(_z_session_t *zn, const _z_key } _z_resource_t *_z_get_resource_by_id(_z_session_t *zn, uint16_t mapping, _z_zint_t rid) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_t *res = __unsafe_z_get_resource_by_id(zn, mapping, rid); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return res; } @@ -191,28 +191,28 @@ _z_resource_t *_z_get_resource_by_key(_z_session_t *zn, const _z_keyexpr_t *keye if (keyexpr->_suffix == NULL) { return _z_get_resource_by_id(zn, _z_keyexpr_mapping_id(keyexpr), keyexpr->_id); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_t *res = __unsafe_z_get_resource_by_key(zn, keyexpr); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return res; } _z_keyexpr_t _z_get_expanded_key_from_key(_z_session_t *zn, const _z_keyexpr_t *keyexpr) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_keyexpr_t res = __unsafe_z_get_expanded_key_from_key(zn, keyexpr); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return res; } @@ -224,9 +224,9 @@ int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, ui uint16_t mapping = register_to_mapping; uint16_t parent_mapping = _z_keyexpr_mapping_id(&key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 if (key._id != Z_RESOURCE_ID_NONE) { if (parent_mapping == mapping) { @@ -255,9 +255,9 @@ int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, ui } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -265,9 +265,9 @@ int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, ui void _z_unregister_resource(_z_session_t *zn, uint16_t id, uint16_t mapping) { _Bool is_local = mapping == _Z_KEYEXPR_MAPPING_LOCAL; _Z_DEBUG("unregistering: id %d, mapping: %d\n", id, mapping); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_list_t **parent_mut = is_local ? &zn->_local_resources : &zn->_remote_resources; while (id != 0) { _z_resource_list_t *parent = *parent_mut; @@ -289,9 +289,9 @@ void _z_unregister_resource(_z_session_t *zn, uint16_t id, uint16_t mapping) { parent = *parent_mut; } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } _Bool _z_unregister_resource_for_peer_filter(const _z_resource_t *candidate, const _z_resource_t *ctx) { @@ -299,27 +299,27 @@ _Bool _z_unregister_resource_for_peer_filter(const _z_resource_t *candidate, con return _z_keyexpr_mapping_id(&candidate->_key) == mapping; } void _z_unregister_resources_for_peer(_z_session_t *zn, uint16_t mapping) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_t ctx = {._id = mapping, ._refcount = 0, ._key = {0}}; zn->_remote_resources = _z_resource_list_drop_filter(zn->_remote_resources, _z_unregister_resource_for_peer_filter, &ctx); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_resources(_z_session_t *zn) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_list_free(&zn->_local_resources); _z_resource_list_free(&zn->_remote_resources); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/scout.c b/src/session/scout.c index 7a45a3ecc..e9191da07 100644 --- a/src/session/scout.c +++ b/src/session/scout.c @@ -20,8 +20,8 @@ #include "zenoh-pico/protocol/core.h" #include "zenoh-pico/utils/logging.h" -#if Z_SCOUTING_UDP == 1 && Z_LINK_UDP_UNICAST == 0 -#error "Scouting UDP requires UDP unicast links to be enabled (Z_LINK_UDP_UNICAST = 1 in config.h)" +#if Z_FEATURE_SCOUTING_UDP == 1 && Z_FEATURE_LINK_UDP_UNICAST == 0 +#error "Scouting UDP requires UDP unicast links to be enabled (Z_FEATURE_LINK_UDP_UNICAST = 1 in config.h)" #endif _z_hello_list_t *__z_scout_loop(const _z_wbuf_t *wbf, const char *locator, unsigned long period, _Bool exit_on_first) { @@ -32,7 +32,7 @@ _z_hello_list_t *__z_scout_loop(const _z_wbuf_t *wbf, const char *locator, unsig _z_endpoint_t ep; err = _z_endpoint_from_str(&ep, locator); -#if Z_SCOUTING_UDP == 1 +#if Z_FEATURE_SCOUTING_UDP == 1 if ((err == _Z_RES_OK) && (_z_str_eq(ep._locator._protocol, UDP_SCHEMA) == true)) { _z_endpoint_clear(&ep); } else @@ -140,13 +140,13 @@ _z_hello_list_t *_z_scout_inner(const z_what_t what, _z_id_t zid, const char *lo _z_scouting_message_encode(&wbf, &scout); // Scout on multicast -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 ret = __z_scout_loop(&wbf, locator, timeout, exit_on_first); #else (void)(locator); (void)(timeout); (void)(exit_on_first); -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_wbuf_clear(&wbf); diff --git a/src/session/subscription.c b/src/session/subscription.c index fd057aac3..e3e0833f3 100644 --- a/src/session/subscription.c +++ b/src/session/subscription.c @@ -96,29 +96,29 @@ _z_subscription_sptr_list_t *__unsafe_z_get_subscriptions_by_key(_z_session_t *z } _z_subscription_sptr_t *_z_get_subscription_by_id(_z_session_t *zn, uint8_t is_local, const _z_zint_t id) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_t *sub = __unsafe_z_get_subscription_by_id(zn, is_local, id); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return sub; } _z_subscription_sptr_list_t *_z_get_subscriptions_by_key(_z_session_t *zn, uint8_t is_local, const _z_keyexpr_t *key) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, is_local, *key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return subs; } @@ -127,9 +127,9 @@ _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_lo _Z_DEBUG(">>> Allocating sub decl for (%ju:%s)\n", (uintmax_t)s->_key._id, s->_key._suffix); _z_subscription_sptr_t *ret = NULL; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, is_local, s->_key); if (subs == NULL) { // A subscription for this name does not yet exists @@ -144,9 +144,9 @@ _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_lo } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -155,9 +155,9 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co const _z_encoding_t encoding, const _z_zint_t kind, const _z_timestamp_t timestamp) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _Z_DEBUG("Resolving %d - %s on mapping 0x%x\n", keyexpr._id, keyexpr._suffix, _z_keyexpr_mapping_id(&keyexpr)); _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, &keyexpr); @@ -165,9 +165,9 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co if (key._suffix != NULL) { _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, _Z_RESOURCE_IS_LOCAL, key); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Build the sample _z_sample_t s; @@ -187,9 +187,9 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co _z_keyexpr_clear(&key); _z_subscription_sptr_list_free(&subs); } else { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 ret = _Z_ERR_KEYEXPR_UNKNOWN; } @@ -197,9 +197,9 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co } void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscription_sptr_t *sub) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 if (is_local == _Z_RESOURCE_IS_LOCAL) { zn->_local_subscriptions = @@ -209,20 +209,20 @@ void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscript _z_subscription_sptr_list_drop_filter(zn->_remote_subscriptions, _z_subscription_sptr_eq, sub); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_subscriptions(_z_session_t *zn) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_list_free(&zn->_local_subscriptions); _z_subscription_sptr_list_free(&zn->_remote_subscriptions); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/tx.c b/src/session/tx.c index ae3697b42..409f5d402 100644 --- a/src/session/tx.c +++ b/src/session/tx.c @@ -21,16 +21,16 @@ int8_t _z_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reli int8_t ret = _Z_RES_OK; _Z_DEBUG(">> send network message\n"); -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _z_unicast_send_n_msg(zn, z_msg, reliability, cong_ctrl); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _z_multicast_send_n_msg(zn, z_msg, reliability, cong_ctrl); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } diff --git a/src/session/utils.c b/src/session/utils.c index 215c2717f..494cb7a5d 100644 --- a/src/session/utils.c +++ b/src/session/utils.c @@ -66,21 +66,21 @@ int8_t _z_session_init(_z_session_t *zn, _z_id_t *zid) { zn->_local_questionable = NULL; zn->_pending_queries = NULL; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 ret = _z_mutex_init(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 if (ret == _Z_RES_OK) { zn->_local_zid = *zid; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { zn->_tp._transport._unicast._session = zn; } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zn->_tp._type == _Z_TRANSPORT_MULTICAST_TYPE) { zn->_tp._transport._multicast._session = zn; } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { // Do nothing. Required to be here because of the #if directive } @@ -103,9 +103,9 @@ void _z_session_clear(_z_session_t *zn) { _z_flush_questionables(zn); _z_flush_pending_queries(zn); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_free(&zn->_mutex_inner); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_session_free(_z_session_t **zn) { diff --git a/src/system/arduino/esp32/network.cpp b/src/system/arduino/esp32/network.cpp index c85ea7d07..c02557fac 100644 --- a/src/system/arduino/esp32/network.cpp +++ b/src/system/arduino/esp32/network.cpp @@ -32,7 +32,7 @@ extern "C" { #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -143,7 +143,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -165,7 +165,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -238,7 +238,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -544,7 +544,7 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 /*------------------ Bluetooth sockets ------------------*/ int8_t _z_open_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -641,7 +641,7 @@ size_t _z_send_bt(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len } #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 /*------------------ Serial sockets ------------------*/ int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { int8_t ret = _Z_RES_OK; diff --git a/src/system/arduino/esp32/system.c b/src/system/arduino/esp32/system.c index 1d823c14c..a9eab813c 100644 --- a/src/system/arduino/esp32/system.c +++ b/src/system/arduino/esp32/system.c @@ -44,7 +44,7 @@ void *z_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MA void z_free(void *ptr) { heap_caps_free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // This wrapper is only used for ESP32. // In FreeRTOS, tasks created using xTaskCreate must end with vTaskDelete. // A task function should __not__ simply return. @@ -112,7 +112,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { return usleep(time); } diff --git a/src/system/arduino/opencr/network.cpp b/src/system/arduino/opencr/network.cpp index 1912d7cfb..bdbb9939a 100644 --- a/src/system/arduino/opencr/network.cpp +++ b/src/system/arduino/opencr/network.cpp @@ -26,7 +26,7 @@ extern "C" { #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { @@ -118,7 +118,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { @@ -147,7 +147,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { delete ep->_iptcp._addr; } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -229,7 +229,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -340,11 +340,11 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on OpenCR port of Zenoh-Pico" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #error "Serial not supported yet on OpenCR port of Zenoh-Pico" #endif } diff --git a/src/system/arduino/opencr/system.c b/src/system/arduino/opencr/system.c index 946392bb3..9ad314b5c 100644 --- a/src/system/arduino/opencr/system.c +++ b/src/system/arduino/opencr/system.c @@ -59,8 +59,8 @@ void z_free(void *ptr) { return free(ptr); } -#if Z_MULTI_THREAD == 1 -#error "Multi-threading not supported yet on OpenCR port. Disable it by defining Z_MULTI_THREAD=0" +#if Z_FEATURE_MULTI_THREAD == 1 +#error "Multi-threading not supported yet on OpenCR port. Disable it by defining Z_FEATURE_MULTI_THREAD=0" /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return -1; } @@ -94,7 +94,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return -1; } int8_t _z_condvar_signal(_z_condvar_t *cv) { return -1; } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return -1; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { diff --git a/src/system/emscripten/network.c b/src/system/emscripten/network.c index 56a67714a..8b2f14caf 100644 --- a/src/system/emscripten/network.c +++ b/src/system/emscripten/network.c @@ -28,7 +28,7 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_WS == 1 +#if Z_FEATURE_LINK_WS == 1 #define WS_LINK_SLEEP 1 @@ -158,18 +158,18 @@ size_t _z_send_ws(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len #endif -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 #error "TCP not supported yet on Emscripten port of Zenoh-Pico" #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 #error "UDP not supported yet on Emscripten port of Zenoh-Pico" #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on Emscripten port of Zenoh-Pico" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #error "Serial not supported yet on Emscripten port of Zenoh-Pico" #endif diff --git a/src/system/emscripten/system.c b/src/system/emscripten/system.c index 89242bd72..0654898b3 100644 --- a/src/system/emscripten/system.c +++ b/src/system/emscripten/system.c @@ -42,7 +42,7 @@ void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } void z_free(void *ptr) { free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, pthread_attr_t *attr, void *(*fun)(void *), void *arg) { return pthread_create(task, attr, fun, arg); @@ -77,7 +77,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { diff --git a/src/system/espidf/network.c b/src/system/espidf/network.c index 55b3e7036..9a49bf157 100644 --- a/src/system/espidf/network.c +++ b/src/system/espidf/network.c @@ -28,7 +28,7 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -139,7 +139,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -161,7 +161,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -234,7 +234,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -540,7 +540,7 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 /*------------------ Serial sockets ------------------*/ int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { int8_t ret = _Z_RES_OK; @@ -736,6 +736,6 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on ESP-IDF port of Zenoh-Pico" #endif diff --git a/src/system/espidf/system.c b/src/system/espidf/system.c index a3a4dd472..8a655cf0d 100644 --- a/src/system/espidf/system.c +++ b/src/system/espidf/system.c @@ -45,7 +45,7 @@ void *z_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MA void z_free(void *ptr) { heap_caps_free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // This wrapper is only used for ESP32. // In FreeRTOS, tasks created using xTaskCreate must end with vTaskDelete. // A task function should __not__ simply return. @@ -113,7 +113,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { return usleep(time); } diff --git a/src/system/mbed/network.cpp b/src/system/mbed/network.cpp index 6653fceea..744b92df0 100644 --- a/src/system/mbed/network.cpp +++ b/src/system/mbed/network.cpp @@ -31,7 +31,7 @@ extern "C" { #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -115,7 +115,7 @@ size_t _z_read_exact_tcp(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t le size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { return sock._tcp->send(ptr, len); } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -134,7 +134,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { delete ep->_iptcp; } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; (void)sock; @@ -205,7 +205,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -317,7 +317,7 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { int8_t ret = _Z_RES_OK; @@ -479,7 +479,7 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on MBED port of Zenoh-Pico" #endif diff --git a/src/system/mbed/system.cpp b/src/system/mbed/system.cpp index 68dc20b01..2adeec297 100644 --- a/src/system/mbed/system.cpp +++ b/src/system/mbed/system.cpp @@ -39,7 +39,7 @@ void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } void z_free(void *ptr) { free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg) { *task = new Thread(); @@ -106,7 +106,7 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { ((ConditionVariable *)*cv)->wait(); return 0; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { diff --git a/src/system/unix/network.c b/src/system/unix/network.c index 917e9a4be..b7e899e23 100644 --- a/src/system/unix/network.c +++ b/src/system/unix/network.c @@ -31,7 +31,7 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { @@ -158,7 +158,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -180,7 +180,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -253,7 +253,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 unsigned int __get_ip_from_iface(const char *iface, int sa_family, struct sockaddr **lsockaddr) { unsigned int addrlen = 0U; @@ -584,10 +584,10 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on Unix port of Zenoh-Pico" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #error "Serial not supported yet on Unix port of Zenoh-Pico" #endif diff --git a/src/system/unix/system.c b/src/system/unix/system.c index e5dca90e9..875bc5f2b 100644 --- a/src/system/unix/system.c +++ b/src/system/unix/system.c @@ -98,7 +98,7 @@ void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } void z_free(void *ptr) { free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return pthread_create(task, attr, fun, arg); @@ -133,7 +133,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { return usleep(time); } diff --git a/src/system/windows/network.c b/src/system/windows/network.c index 6ce0eb5ab..76d37027c 100644 --- a/src/system/windows/network.c +++ b/src/system/windows/network.c @@ -25,7 +25,7 @@ WSADATA wsaData; -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { @@ -161,7 +161,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -190,7 +190,7 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -272,7 +272,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 unsigned int __get_ip_from_iface(const char *iface, int sa_family, SOCKADDR **lsockaddr) { unsigned int addrlen = 0U; @@ -603,10 +603,10 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on Windows port of Zenoh-Pico" #endif -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 #error "Serial not supported yet on Windows port of Zenoh-Pico" #endif diff --git a/src/system/windows/system.c b/src/system/windows/system.c index b813d6627..581b42291 100644 --- a/src/system/windows/system.c +++ b/src/system/windows/system.c @@ -58,7 +58,7 @@ void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } void z_free(void *ptr) { free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ int8_t _z_task_init(_z_task_t *task, _z_task_attr_t *attr, void *(*fun)(void *), void *arg) { (void)(attr); @@ -146,7 +146,7 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { SleepConditionVariableSRW(cv, m, INFINITE, 0); return ret; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { return z_sleep_ms((time / 1000) + (time % 1000 == 0 ? 0 : 1)); } diff --git a/src/system/zephyr/network.c b/src/system/zephyr/network.c index 49978b49c..e07381914 100644 --- a/src/system/zephyr/network.c +++ b/src/system/zephyr/network.c @@ -34,7 +34,7 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" -#if Z_LINK_TCP == 1 +#if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -147,7 +147,7 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le } #endif -#if Z_LINK_UDP_UNICAST == 1 || Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { int8_t ret = _Z_RES_OK; @@ -169,7 +169,7 @@ int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } #endif -#if Z_LINK_UDP_UNICAST == 1 +#if Z_FEATURE_LINK_UDP_UNICAST == 1 int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { int8_t ret = _Z_RES_OK; @@ -243,7 +243,7 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s } #endif -#if Z_LINK_UDP_MULTICAST == 1 +#if Z_FEATURE_LINK_UDP_MULTICAST == 1 int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, uint32_t tout, const char *iface) { int8_t ret = _Z_RES_OK; @@ -550,9 +550,9 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, _z_sys_net_endpoint_t rep) { return sendto(sock._fd, ptr, len, 0, rep._iptcp->ai_addr, rep._iptcp->ai_addrlen); } -#endif // Z_LINK_UDP_MULTICAST == 1 +#endif // Z_FEATURE_LINK_UDP_MULTICAST == 1 -#if Z_LINK_SERIAL == 1 +#if Z_FEATURE_LINK_SERIAL == 1 int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { int8_t ret = _Z_RES_OK; (void)(sock); @@ -725,6 +725,6 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t } #endif -#if Z_LINK_BLUETOOTH == 1 +#if Z_FEATURE_LINK_BLUETOOTH == 1 #error "Bluetooth not supported yet on Zephyr port of Zenoh-Pico" #endif diff --git a/src/system/zephyr/system.c b/src/system/zephyr/system.c index 2670ae9cb..28ce1d303 100644 --- a/src/system/zephyr/system.c +++ b/src/system/zephyr/system.c @@ -55,7 +55,7 @@ void *z_realloc(void *ptr, size_t size) { void z_free(void *ptr) { k_free(ptr); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 #define Z_THREADS_NUM 4 @@ -112,7 +112,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); } int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); } int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { diff --git a/src/transport/common/join.c b/src/transport/common/join.c index b896dac2e..5c9d6819b 100644 --- a/src/transport/common/join.c +++ b/src/transport/common/join.c @@ -17,12 +17,12 @@ int8_t _z_send_join(_z_transport_t *zt) { int8_t ret = _Z_RES_OK; -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 // Join task only applies to multicast transports if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_send_join(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { (void)zt; ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; diff --git a/src/transport/common/lease.c b/src/transport/common/lease.c index dcf2d908d..bf32a5884 100644 --- a/src/transport/common/lease.c +++ b/src/transport/common/lease.c @@ -18,16 +18,16 @@ int8_t _z_send_keep_alive(_z_transport_t *zt) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _zp_unicast_send_keep_alive(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_send_keep_alive(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -39,16 +39,16 @@ void *_zp_lease_task(void *zt_arg) { void *ret = NULL; _z_transport_t *zt = (_z_transport_t *)zt_arg; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _zp_unicast_lease_task(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_lease_task(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = NULL; } diff --git a/src/transport/common/read.c b/src/transport/common/read.c index bf0f20381..e1bcdcee8 100644 --- a/src/transport/common/read.c +++ b/src/transport/common/read.c @@ -19,16 +19,16 @@ int8_t _z_read(_z_transport_t *zt) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _zp_unicast_read(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_read(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -40,16 +40,16 @@ void *_zp_read_task(void *zt_arg) { void *ret = NULL; _z_transport_t *zt = (_z_transport_t *)zt_arg; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _zp_unicast_read_task(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _zp_multicast_read_task(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = NULL; } diff --git a/src/transport/common/tx.c b/src/transport/common/tx.c index f3625250e..811cf7a2d 100644 --- a/src/transport/common/tx.c +++ b/src/transport/common/tx.c @@ -54,16 +54,16 @@ void __unsafe_z_finalize_wbuf(_z_wbuf_t *buf, _Bool is_streamed) { int8_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _z_unicast_send_t_msg(&zt->_transport._unicast, t_msg); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _z_multicast_send_t_msg(&zt->_transport._multicast, t_msg); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -71,7 +71,7 @@ int8_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg) { return ret; } -#if Z_UNICAST_TRANSPORT == 1 || Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 || Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg) { int8_t ret = _Z_RES_OK; @@ -103,7 +103,7 @@ int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_m return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 || Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 || Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z_reliability_t reliability, size_t sn) { int8_t ret = _Z_RES_OK; diff --git a/src/transport/manager.c b/src/transport/manager.c index f365a399e..c7e868ed1 100644 --- a/src/transport/manager.c +++ b/src/transport/manager.c @@ -25,7 +25,7 @@ int8_t _z_new_transport_client(_z_transport_t *zt, char *locator, _z_id_t *local ret = _z_open_link(&zl, locator); if (ret == _Z_RES_OK) { -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (_Z_LINK_IS_MULTICAST(zl._capabilities) == false) { _z_transport_unicast_establish_param_t tp_param; ret = _z_transport_unicast_open_client(&tp_param, &zl, local_zid); @@ -35,8 +35,8 @@ int8_t _z_new_transport_client(_z_transport_t *zt, char *locator, _z_id_t *local _z_link_clear(&zl); } } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (_Z_LINK_IS_MULTICAST(zl._capabilities) == true) { _z_transport_multicast_establish_param_t tp_param; ret = _z_transport_multicast_open_client(&tp_param, &zl, local_zid); @@ -46,7 +46,7 @@ int8_t _z_new_transport_client(_z_transport_t *zt, char *locator, _z_id_t *local _z_link_clear(&zl); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { _z_link_clear(&zl); ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; @@ -64,7 +64,7 @@ int8_t _z_new_transport_peer(_z_transport_t *zt, char *locator, _z_id_t *local_z ret = _z_listen_link(&zl, locator); if (ret == _Z_RES_OK) { -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (_Z_LINK_IS_MULTICAST(zl._capabilities) == false) { _z_transport_unicast_establish_param_t tp_param; ret = _z_transport_unicast_open_peer(&tp_param, &zl, local_zid); @@ -74,8 +74,8 @@ int8_t _z_new_transport_peer(_z_transport_t *zt, char *locator, _z_id_t *local_z _z_link_clear(&zl); } } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (_Z_LINK_IS_MULTICAST(zl._capabilities) == true) { _z_transport_multicast_establish_param_t tp_param; ret = _z_transport_multicast_open_peer(&tp_param, &zl, local_zid); @@ -85,7 +85,7 @@ int8_t _z_new_transport_peer(_z_transport_t *zt, char *locator, _z_id_t *local_z _z_link_clear(&zl); } } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { _z_link_clear(&zl); ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; diff --git a/src/transport/multicast/link/rx.c b/src/transport/multicast/link/rx.c index b5d50e030..cb585503c 100644 --- a/src/transport/multicast/link/rx.c +++ b/src/transport/multicast/link/rx.c @@ -27,7 +27,7 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_transport_peer_entry_t *_z_find_peer_entry(_z_transport_peer_entry_list_t *l, _z_bytes_t *remote_addr) { _z_transport_peer_entry_t *ret = NULL; @@ -52,10 +52,10 @@ int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_me _Z_DEBUG(">> recv session msg\n"); int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock _z_mutex_lock(&ztm->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 size_t to_read = 0; do { @@ -96,9 +96,9 @@ int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_me ret = _z_transport_message_decode(t_msg, &ztm->_zbuf); } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztm->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -110,10 +110,10 @@ int8_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_messa int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_bytes_t *addr) { int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire and keep the lock _z_mutex_lock(&ztm->_mutex_peer); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Mark the session that we have received data from this peer _z_transport_peer_entry_t *entry = _z_find_peer_entry(ztm->_peers, addr); @@ -254,7 +254,7 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t _z_conduit_sn_list_copy(&entry->_sn_rx_sns, &t_msg->_body._join._next_sn); _z_conduit_sn_list_decrement(entry->_sn_res, &entry->_sn_rx_sns); -#if Z_DYNAMIC_MEMORY_ALLOCATION == 1 +#if Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION == 1 entry->_dbuf_reliable = _z_wbuf_make(0, true); entry->_dbuf_best_effort = _z_wbuf_make(0, true); #else @@ -313,11 +313,11 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztm->_mutex_peer); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/multicast/link/task/join.c b/src/transport/multicast/link/task/join.c index 345ab689c..45ce08aaa 100644 --- a/src/transport/multicast/link/task/join.c +++ b/src/transport/multicast/link/task/join.c @@ -17,7 +17,7 @@ #include "zenoh-pico/session/utils.h" #include "zenoh-pico/transport/link/tx.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { _z_conduit_sn_list_t next_sn; @@ -31,4 +31,4 @@ int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { return _z_multicast_send_t_msg(ztm, &jsm); } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/multicast/link/task/lease.c b/src/transport/multicast/link/task/lease.c index c653d2dea..91a594c4b 100644 --- a/src/transport/multicast/link/task/lease.c +++ b/src/transport/multicast/link/task/lease.c @@ -22,7 +22,7 @@ #include "zenoh-pico/transport/link/tx.h" #include "zenoh-pico/utils/logging.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 _z_zint_t _z_get_minimum_lease(_z_transport_peer_entry_list_t *peers, _z_zint_t local_lease) { _z_zint_t ret = local_lease; @@ -68,7 +68,7 @@ int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { } void *_zp_multicast_lease_task(void *ztm_arg) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_transport_multicast_t *ztm = (_z_transport_multicast_t *)ztm_arg; ztm->_transmitted = false; @@ -158,9 +158,9 @@ void *_zp_multicast_lease_task(void *ztm_arg) { _z_mutex_unlock(&ztm->_mutex_peer); } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return 0; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/multicast/link/task/read.c b/src/transport/multicast/link/task/read.c index 2c4278426..606f2a8c1 100644 --- a/src/transport/multicast/link/task/read.c +++ b/src/transport/multicast/link/task/read.c @@ -22,7 +22,7 @@ #include "zenoh-pico/transport/link/rx.h" #include "zenoh-pico/utils/logging.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) { int8_t ret = _Z_RES_OK; @@ -39,7 +39,7 @@ int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) { } void *_zp_multicast_read_task(void *ztm_arg) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_transport_multicast_t *ztm = (_z_transport_multicast_t *)ztm_arg; // Acquire and keep the lock @@ -113,9 +113,9 @@ void *_zp_multicast_read_task(void *ztm_arg) { } _z_mutex_unlock(&ztm->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return NULL; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/multicast/link/tx.c b/src/transport/multicast/link/tx.c index 991f878f3..81197bf12 100644 --- a/src/transport/multicast/link/tx.c +++ b/src/transport/multicast/link/tx.c @@ -20,7 +20,7 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 /** * This function is unsafe because it operates in potentially concurrent data. @@ -43,10 +43,10 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport int8_t ret = _Z_RES_OK; _Z_DEBUG(">> send session message\n"); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock _z_mutex_lock(&ztm->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Prepare the buffer eventually reserving space for the message length __unsafe_z_prepare_wbuf(&ztm->_wbuf, _Z_LINK_IS_STREAMED(ztm->_link._capabilities)); @@ -63,9 +63,9 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztm->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -80,18 +80,18 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m // Acquire the lock and drop the message if needed _Bool drop = false; if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&ztm->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } else { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 int8_t locked = _z_mutex_trylock(&ztm->_mutex_tx); if (locked != (int8_t)0) { _Z_INFO("Dropping zenoh message because of congestion control\n"); // We failed to acquire the lock, drop the message drop = true; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } if (drop == false) { @@ -145,12 +145,12 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztm->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/transport.c b/src/transport/transport.c index af71c2016..0019be34e 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -26,7 +26,7 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, _Bool link_only) { int8_t ret = _Z_RES_OK; @@ -37,9 +37,9 @@ int8_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, _Bool return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, _Bool link_only) { int8_t ret = _Z_RES_OK; @@ -50,21 +50,21 @@ int8_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, _B return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_send_close(_z_transport_t *zt, uint8_t reason, _Bool link_only) { int8_t ret = _Z_RES_OK; -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { ret = _z_unicast_send_close(&zt->_transport._unicast, reason, link_only); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { ret = _z_multicast_send_close(&zt->_transport._multicast, reason, link_only); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -72,13 +72,13 @@ int8_t _z_send_close(_z_transport_t *zt, uint8_t reason, _Bool link_only) { return ret; } -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unicast_establish_param_t *param) { int8_t ret = _Z_RES_OK; zt->_type = _Z_TRANSPORT_UNICAST_TYPE; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Initialize the mutexes ret = _z_mutex_init(&zt->_transport._unicast._mutex_tx); if (ret == _Z_RES_OK) { @@ -87,7 +87,7 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic _z_mutex_free(&zt->_transport._unicast._mutex_tx); } } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Initialize the read and write buffers if (ret == _Z_RES_OK) { @@ -95,7 +95,7 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic _Bool expandable = _Z_LINK_IS_STREAMED(zl->_capabilities); size_t dbuf_size = 0; -#if Z_DYNAMIC_MEMORY_ALLOCATION == 0 +#if Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION == 0 expandable = false; dbuf_size = Z_FRAG_MAX_SIZE; #endif @@ -109,7 +109,7 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic // Clean up the buffers if one of them failed to be allocated if ((_z_wbuf_capacity(&zt->_transport._unicast._wbuf) != mtu) || (_z_zbuf_capacity(&zt->_transport._unicast._zbuf) != Z_BATCH_UNICAST_SIZE) || -#if Z_DYNAMIC_MEMORY_ALLOCATION == 0 +#if Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION == 0 (_z_wbuf_capacity(&zt->_transport._unicast._dbuf_reliable) != dbuf_size) || (_z_wbuf_capacity(&zt->_transport._unicast._dbuf_best_effort) != dbuf_size)) { #else @@ -118,10 +118,10 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic #endif ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_free(&zt->_transport._unicast._mutex_tx); _z_mutex_free(&zt->_transport._unicast._mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_wbuf_clear(&zt->_transport._unicast._wbuf); _z_zbuf_clear(&zt->_transport._unicast._zbuf); @@ -143,13 +143,13 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic zt->_transport._unicast._sn_rx_reliable = initial_sn_rx; zt->_transport._unicast._sn_rx_best_effort = initial_sn_rx; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Tasks zt->_transport._unicast._read_task_running = false; zt->_transport._unicast._read_task = NULL; zt->_transport._unicast._lease_task_running = false; zt->_transport._unicast._lease_task = NULL; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Notifiers zt->_transport._unicast._received = 0; @@ -169,15 +169,15 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_multicast_establish_param_t *param) { int8_t ret = _Z_RES_OK; zt->_type = _Z_TRANSPORT_MULTICAST_TYPE; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Initialize the mutexes ret = _z_mutex_init(&zt->_transport._multicast._mutex_tx); if (ret == _Z_RES_OK) { @@ -192,7 +192,7 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu _z_mutex_free(&zt->_transport._multicast._mutex_tx); } } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Initialize the read and write buffers if (ret == _Z_RES_OK) { @@ -205,11 +205,11 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu (_z_zbuf_capacity(&zt->_transport._multicast._zbuf) != Z_BATCH_MULTICAST_SIZE)) { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_free(&zt->_transport._multicast._mutex_tx); _z_mutex_free(&zt->_transport._multicast._mutex_rx); _z_mutex_free(&zt->_transport._multicast._mutex_peer); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 _z_wbuf_clear(&zt->_transport._multicast._wbuf); _z_zbuf_clear(&zt->_transport._multicast._zbuf); @@ -227,13 +227,13 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu // Initialize peer list zt->_transport._multicast._peers = _z_transport_peer_entry_list_new(); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Tasks zt->_transport._multicast._read_task_running = false; zt->_transport._multicast._read_task = NULL; zt->_transport._multicast._lease_task_running = false; zt->_transport._multicast._lease_task = NULL; -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 zt->_transport._multicast._lease = Z_TRANSPORT_LEASE; @@ -246,9 +246,9 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_transport_unicast_open_client(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, const _z_id_t *local_zid) { int8_t ret = _Z_RES_OK; @@ -343,9 +343,9 @@ int8_t _z_transport_unicast_open_client(_z_transport_unicast_establish_param_t * return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, const _z_id_t *local_zid) { (void)(param); @@ -357,9 +357,9 @@ int8_t _z_transport_multicast_open_client(_z_transport_multicast_establish_param return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_transport_unicast_open_peer(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, const _z_id_t *local_zid) { (void)(param); @@ -371,9 +371,9 @@ int8_t _z_transport_unicast_open_peer(_z_transport_unicast_establish_param_t *pa return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, const _z_id_t *local_zid) { int8_t ret = _Z_RES_OK; @@ -402,25 +402,25 @@ int8_t _z_transport_multicast_open_peer(_z_transport_multicast_establish_param_t return ret; } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_transport_unicast_close(_z_transport_unicast_t *ztu, uint8_t reason) { return _z_unicast_send_close(ztu, reason, false); } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_multicast_close(_z_transport_multicast_t *ztm, uint8_t reason) { return _z_multicast_send_close(ztm, reason, false); } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 int8_t _z_transport_close(_z_transport_t *zt, uint8_t reason) { return _z_send_close(zt, reason, false); } -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 void _z_transport_unicast_clear(_z_transport_unicast_t *ztu) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Clean up tasks if (ztu->_read_task != NULL) { _z_task_join(ztu->_read_task); @@ -434,7 +434,7 @@ void _z_transport_unicast_clear(_z_transport_unicast_t *ztu) { // Clean up the mutexes _z_mutex_free(&ztu->_mutex_tx); _z_mutex_free(&ztu->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Clean up the buffers _z_wbuf_clear(&ztu->_wbuf); @@ -446,11 +446,11 @@ void _z_transport_unicast_clear(_z_transport_unicast_t *ztu) { ztu->_remote_zid = _z_id_empty(); _z_link_clear(&ztu->_link); } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 void _z_transport_multicast_clear(_z_transport_multicast_t *ztm) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Clean up tasks if (ztm->_read_task != NULL) { _z_task_join(ztm->_read_task); @@ -465,7 +465,7 @@ void _z_transport_multicast_clear(_z_transport_multicast_t *ztm) { _z_mutex_free(&ztm->_mutex_tx); _z_mutex_free(&ztm->_mutex_rx); _z_mutex_free(&ztm->_mutex_peer); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Clean up the buffers _z_wbuf_clear(&ztm->_wbuf); @@ -475,19 +475,19 @@ void _z_transport_multicast_clear(_z_transport_multicast_t *ztm) { _z_transport_peer_entry_list_free(&ztm->_peers); _z_link_clear(&ztm->_link); } -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 void _z_transport_clear(_z_transport_t *zt) { -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_UNICAST_TYPE) { _z_transport_unicast_clear(&zt->_transport._unicast); } else -#endif // Z_UNICAST_TRANSPORT == 1 -#if Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 if (zt->_type == _Z_TRANSPORT_MULTICAST_TYPE) { _z_transport_multicast_clear(&zt->_transport._multicast); } else -#endif // Z_MULTICAST_TRANSPORT == 1 +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 { __asm__("nop"); } diff --git a/src/transport/unicast/link/rx.c b/src/transport/unicast/link/rx.c index 6604e71ea..dfc580e4d 100644 --- a/src/transport/unicast/link/rx.c +++ b/src/transport/unicast/link/rx.c @@ -25,15 +25,15 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { _Z_DEBUG(">> recv session msg\n"); int8_t ret = _Z_RES_OK; -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock _z_mutex_lock(&ztu->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 size_t to_read = 0; do { @@ -79,9 +79,9 @@ int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_messag } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztu->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -197,4 +197,4 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans return _Z_RES_OK; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 diff --git a/src/transport/unicast/link/task/lease.c b/src/transport/unicast/link/task/lease.c index 5d9e0a2f2..02ff178db 100644 --- a/src/transport/unicast/link/task/lease.c +++ b/src/transport/unicast/link/task/lease.c @@ -17,7 +17,7 @@ #include "zenoh-pico/transport/link/tx.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { int8_t ret = _Z_RES_OK; @@ -29,7 +29,7 @@ int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { } void *_zp_unicast_lease_task(void *ztu_arg) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_transport_unicast_t *ztu = (_z_transport_unicast_t *)ztu_arg; ztu->_received = false; @@ -83,9 +83,9 @@ void *_zp_unicast_lease_task(void *ztu_arg) { next_lease = next_lease - interval; next_keep_alive = next_keep_alive - interval; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return 0; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 diff --git a/src/transport/unicast/link/task/read.c b/src/transport/unicast/link/task/read.c index 31bc35609..bf27b1c70 100644 --- a/src/transport/unicast/link/task/read.c +++ b/src/transport/unicast/link/task/read.c @@ -21,7 +21,7 @@ #include "zenoh-pico/transport/link/rx.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) { int8_t ret = _Z_RES_OK; @@ -37,7 +37,7 @@ int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) { } void *_zp_unicast_read_task(void *ztu_arg) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_transport_unicast_t *ztu = (_z_transport_unicast_t *)ztu_arg; // Acquire and keep the lock @@ -107,9 +107,9 @@ void *_zp_unicast_read_task(void *ztu_arg) { } _z_mutex_unlock(&ztu->_mutex_rx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return NULL; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 diff --git a/src/transport/unicast/link/tx.c b/src/transport/unicast/link/tx.c index 8f825b7e4..eb43c769d 100644 --- a/src/transport/unicast/link/tx.c +++ b/src/transport/unicast/link/tx.c @@ -23,7 +23,7 @@ #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -#if Z_UNICAST_TRANSPORT == 1 +#if Z_FEATURE_UNICAST_TRANSPORT == 1 /** * This function is unsafe because it operates in potentially concurrent data. @@ -46,10 +46,10 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes int8_t ret = _Z_RES_OK; _Z_DEBUG(">> send session message\n"); -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock _z_mutex_lock(&ztu->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 // Prepare the buffer eventually reserving space for the message length __unsafe_z_prepare_wbuf(&ztu->_wbuf, _Z_LINK_IS_STREAMED(ztu->_link._capabilities)); @@ -66,9 +66,9 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztu->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } @@ -83,18 +83,18 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg // Acquire the lock and drop the message if needed _Bool drop = false; if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_lock(&ztu->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } else { -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 int8_t locked = _z_mutex_trylock(&ztu->_mutex_tx); if (locked != (int8_t)0) { _Z_INFO("Dropping zenoh message because of congestion control\n"); // We failed to acquire the lock, drop the message drop = true; } -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } if (drop == false) { @@ -154,12 +154,12 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg } } -#if Z_MULTI_THREAD == 1 +#if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_unlock(&ztu->_mutex_tx); -#endif // Z_MULTI_THREAD == 1 +#endif // Z_FEATURE_MULTI_THREAD == 1 } return ret; } -#endif // Z_UNICAST_TRANSPORT == 1 +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 From 0c2476900fb6a5901e62a0051083e9aafe3513e7 Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Thu, 12 Oct 2023 17:50:32 +0200 Subject: [PATCH 15/26] fix memory leak in z_declare_subscriber --- CMakeLists.txt | 5 +++++ include/zenoh-pico/session/session.h | 1 + src/api/api.c | 12 ++++++++---- src/net/primitives.c | 2 ++ zenohpico.pc | 8 ++++---- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 076446581..81105e115 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,11 @@ include(GNUInstallDirs) option(BUILD_SHARED_LIBS "Build shared libraries if ON, otherwise build static libraries" ON) option(ZENOH_DEBUG "Use this to set the ZENOH_DEBUG variable." 0) option(WITH_ZEPHYR "Build for Zephyr RTOS" OFF) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") +if(CMAKE_EXPORT_COMPILE_COMMANDS) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES + ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) +endif() if(CMAKE_SYSTEM_NAME MATCHES "Windows") set(BUILD_SHARED_LIBS "OFF") diff --git a/include/zenoh-pico/session/session.h b/include/zenoh-pico/session/session.h index a6102da23..ee3f1653e 100644 --- a/include/zenoh-pico/session/session.h +++ b/include/zenoh-pico/session/session.h @@ -90,6 +90,7 @@ typedef void (*_z_data_handler_t)(const _z_sample_t *sample, void *arg); typedef struct { _z_keyexpr_t _key; + uint16_t _key_id; uint32_t _id; _z_data_handler_t _callback; _z_drop_handler_t _dropper; diff --git a/src/api/api.c b/src/api/api.c index b673e3659..173c511db 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -810,6 +810,7 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z const z_subscriber_options_t *options) { void *ctx = callback->context; callback->context = NULL; + char *suffix = NULL; z_keyexpr_t key = keyexpr; // TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition @@ -824,11 +825,11 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z if (wild != NULL && wild != keyexpr._suffix) { wild -= 1; size_t len = wild - keyexpr._suffix; - char *suffix = z_malloc(len + 1); + suffix = z_malloc(len + 1); memcpy(suffix, keyexpr._suffix, len); suffix[len] = 0; keyexpr._suffix = suffix; - _z_keyexpr_set_owns_suffix(&keyexpr, true); + _z_keyexpr_set_owns_suffix(&keyexpr, false); } uint16_t id = _z_declare_resource(zs._val, keyexpr); key = _z_rid_with_suffix(id, wild); @@ -841,9 +842,12 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z if (options != NULL) { subinfo.reliability = options->reliability; } + _z_subscriber_t *sub = _z_declare_subscriber(zs._val, key, subinfo, callback->call, callback->drop, ctx); + if (suffix != NULL) { + z_free(suffix); + } - return (z_owned_subscriber_t){ - ._value = _z_declare_subscriber(zs._val, key, subinfo, callback->call, callback->drop, ctx)}; + return (z_owned_subscriber_t){._value = sub}; } z_owned_pull_subscriber_t z_declare_pull_subscriber(z_session_t zs, z_keyexpr_t keyexpr, diff --git a/src/net/primitives.c b/src/net/primitives.c index d536f2e96..9d36cc1a8 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -129,6 +129,7 @@ _z_subscriber_t *_z_declare_subscriber(_z_session_t *zn, _z_keyexpr_t keyexpr, _ _z_data_handler_t callback, _z_drop_handler_t dropper, void *arg) { _z_subscription_t s; s._id = _z_get_entity_id(zn); + s._key_id = keyexpr._id; s._key = _z_get_expanded_key_from_key(zn, &keyexpr); s._info = sub_info; s._callback = callback; @@ -175,6 +176,7 @@ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub) { _z_network_message_t n_msg = _z_n_msg_make_declare(declaration); if (_z_send_n_msg(sub->_zn, &n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) == _Z_RES_OK) { // Only if message is successfully send, local subscription state can be removed + _z_undeclare_resource(sub->_zn, s->ptr->_key_id); _z_unregister_subscription(sub->_zn, _Z_RESOURCE_IS_LOCAL, s); } else { ret = _Z_ERR_ENTITY_UNKNOWN; diff --git a/zenohpico.pc b/zenohpico.pc index 6325d30fe..ccbae71d3 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -1,8 +1,8 @@ -prefix=/usr/local +prefix=/var/empty/local Name: zenohpico Description: URL: -Version: 0.10.20230920dev -Cflags: -I${prefix}/ -Libs: -L${prefix}/ -lzenohpico +Version: 0.11.20231012dev +Cflags: -I${prefix}/include +Libs: -L${prefix}/lib64 -lzenohpico From 718d4c55df5ed64f912c58dafd7d62ca5549bcc7 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Thu, 12 Oct 2023 18:29:47 +0200 Subject: [PATCH 16/26] Fix u16 little endian encoding (#263) --- src/protocol/codec.c | 6 +++--- zenohpico.pc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/protocol/codec.c b/src/protocol/codec.c index a67bd20db..7b4be95f4 100644 --- a/src/protocol/codec.c +++ b/src/protocol/codec.c @@ -151,8 +151,8 @@ int8_t _z_uint8_decode(uint8_t *u8, _z_zbuf_t *zbf) { int8_t _z_uint16_encode(_z_wbuf_t *wbf, uint16_t u16) { int8_t ret = _Z_RES_OK; - ret |= _z_wbuf_write(wbf, ((u16 >> 8) & 0xFF)); ret |= _z_wbuf_write(wbf, (u16 & 0xFF)); + ret |= _z_wbuf_write(wbf, ((u16 >> 8) & 0xFF)); return ret; } @@ -163,9 +163,9 @@ int8_t _z_uint16_decode(uint16_t *u16, _z_zbuf_t *zbf) { uint8_t u8; ret |= _z_uint8_decode(&u8, zbf); - *u16 |= u8 << 8; - ret |= _z_uint8_decode(&u8, zbf); *u16 |= u8; + ret |= _z_uint8_decode(&u8, zbf); + *u16 |= u8 << 8; return ret; } diff --git a/zenohpico.pc b/zenohpico.pc index 6325d30fe..6a0f039aa 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -3,6 +3,6 @@ prefix=/usr/local Name: zenohpico Description: URL: -Version: 0.10.20230920dev -Cflags: -I${prefix}/ -Libs: -L${prefix}/ -lzenohpico +Version: 0.11.20231012dev +Cflags: -I${prefix}/include +Libs: -L${prefix}/lib -lzenohpico From d421206c0e44a1931cf5eb3d62a47007d41e0baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= Date: Thu, 12 Oct 2023 21:53:36 +0200 Subject: [PATCH 17/26] Update zenohpico.pc --- zenohpico.pc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zenohpico.pc b/zenohpico.pc index c0c342fea..6a0f039aa 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -1,8 +1,8 @@ -prefix=/var/local +prefix=/usr/local Name: zenohpico Description: URL: Version: 0.11.20231012dev Cflags: -I${prefix}/include -Libs: -L${prefix}/lib -lzenohpico \ No newline at end of file +Libs: -L${prefix}/lib -lzenohpico From 19e694fe68591ee14689cc0da87c7695068262a1 Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Fri, 13 Oct 2023 14:18:24 +0200 Subject: [PATCH 18/26] check the malloc --- src/api/api.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/api.c b/src/api/api.c index 173c511db..ba7bf18b6 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -826,10 +826,12 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z wild -= 1; size_t len = wild - keyexpr._suffix; suffix = z_malloc(len + 1); - memcpy(suffix, keyexpr._suffix, len); - suffix[len] = 0; - keyexpr._suffix = suffix; - _z_keyexpr_set_owns_suffix(&keyexpr, false); + if (suffix != NULL) { + memcpy(suffix, keyexpr._suffix, len); + suffix[len] = 0; + keyexpr._suffix = suffix; + _z_keyexpr_set_owns_suffix(&keyexpr, false); + } } uint16_t id = _z_declare_resource(zs._val, keyexpr); key = _z_rid_with_suffix(id, wild); From dd8b94363cefa5688762e13bf5d063e3cc25474a Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Fri, 13 Oct 2023 15:58:00 +0200 Subject: [PATCH 19/26] Add query & queryable token config (#260) --- examples/arduino/z_get.ino | 7 + examples/arduino/z_queryable.ino | 8 + examples/espidf/z_get.c | 4 + examples/espidf/z_queryable.c | 6 + examples/mbed/z_get.cpp | 7 + examples/mbed/z_queryable.cpp | 7 + examples/unix/c11/z_get.c | 7 + examples/unix/c11/z_queryable.c | 7 + examples/unix/c99/z_get.c | 7 + examples/unix/c99/z_queryable.c | 7 + examples/windows/z_get.c | 7 + examples/windows/z_queryable.c | 7 + examples/zephyr/z_get.c | 7 + include/zenoh-pico/api/primitives.h | 247 +++++++++++++------------ include/zenoh-pico/config.h | 14 ++ include/zenoh-pico/net/primitives.h | 74 ++++---- include/zenoh-pico/net/query.h | 2 + include/zenoh-pico/net/session.h | 4 + include/zenoh-pico/session/push.h | 26 +++ include/zenoh-pico/session/query.h | 2 + include/zenoh-pico/session/queryable.h | 2 + include/zenoh-pico/session/reply.h | 29 +++ src/api/api.c | 167 +++++++++-------- src/net/primitives.c | 80 ++++---- src/net/query.c | 2 + src/session/push.c | 35 ++++ src/session/query.c | 2 + src/session/queryable.c | 3 + src/session/reply.c | 44 +++++ src/session/rx.c | 22 +-- src/session/utils.c | 9 + tests/z_api_null_drop_test.c | 38 ++-- 32 files changed, 590 insertions(+), 300 deletions(-) create mode 100644 include/zenoh-pico/session/push.h create mode 100644 include/zenoh-pico/session/reply.h create mode 100644 src/session/push.c create mode 100644 src/session/reply.c diff --git a/examples/arduino/z_get.ino b/examples/arduino/z_get.ino index 1f92eb3c2..7ae75175f 100644 --- a/examples/arduino/z_get.ino +++ b/examples/arduino/z_get.ino @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_QUERY == 1 // WiFi-specific parameters #define SSID "SSID" #define PASS "PASS" @@ -118,3 +119,9 @@ void loop() { Serial.println("Unable to send query."); } } +#else +void setup() { + Serial.println("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it."); +} +void loop() {} +#endif diff --git a/examples/arduino/z_queryable.ino b/examples/arduino/z_queryable.ino index fe1f87b65..edde751ae 100644 --- a/examples/arduino/z_queryable.ino +++ b/examples/arduino/z_queryable.ino @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_QUERYABLE == 1 // WiFi-specific parameters #define SSID "SSID" #define PASS "PASS" @@ -106,3 +107,10 @@ void setup() { } void loop() { delay(5000); } + +#else +void setup() { + Serial.println("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it."); +} +void loop() {} +#endif diff --git a/examples/espidf/z_get.c b/examples/espidf/z_get.c index 83f321351..884dfc2a4 100644 --- a/examples/espidf/z_get.c +++ b/examples/espidf/z_get.c @@ -25,6 +25,7 @@ #include #include +#if Z_FEATURE_QUERY == 1 #define ESP_WIFI_SSID "SSID" #define ESP_WIFI_PASS "PASS" #define ESP_MAXIMUM_RETRY 5 @@ -172,3 +173,6 @@ void app_main() { z_close(z_move(s)); printf("OK!\n"); } +#else +void app_main() { printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it.\n"); } +#endif \ No newline at end of file diff --git a/examples/espidf/z_queryable.c b/examples/espidf/z_queryable.c index 9f5eb9abe..4448b3b2b 100644 --- a/examples/espidf/z_queryable.c +++ b/examples/espidf/z_queryable.c @@ -30,6 +30,7 @@ #define ESP_MAXIMUM_RETRY 5 #define WIFI_CONNECTED_BIT BIT0 +#if Z_FEATURE_QUERYABLE == 1 static bool s_is_wifi_connected = false; static EventGroupHandle_t s_event_group_handler; static int s_retry_count = 0; @@ -171,3 +172,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_QUERYABLE but this example requires it.\n"); +} +#endif diff --git a/examples/mbed/z_get.cpp b/examples/mbed/z_get.cpp index a7acba4fd..39ea2c5fd 100644 --- a/examples/mbed/z_get.cpp +++ b/examples/mbed/z_get.cpp @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_QUERY == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -94,3 +95,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/mbed/z_queryable.cpp b/examples/mbed/z_queryable.cpp index 5f621c74e..5a0dd4901 100644 --- a/examples/mbed/z_queryable.cpp +++ b/examples/mbed/z_queryable.cpp @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_QUERYABLE == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -94,3 +95,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c11/z_get.c b/examples/unix/c11/z_get.c index 000993ab9..6c47a550b 100644 --- a/examples/unix/c11/z_get.c +++ b/examples/unix/c11/z_get.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_QUERY == 1 void reply_dropper(void *ctx) { (void)(ctx); printf(">> Received query final notification\n"); @@ -129,3 +130,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index 31a7d10ba..01a04410b 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_QUERYABLE == 1 const char *keyexpr = "demo/example/zenoh-pico-queryable"; const char *value = "Queryable from Pico!"; @@ -124,3 +125,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index 65e22f91b..7b45b13f7 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_QUERY == 1 void reply_dropper(void *ctx) { (void)(ctx); printf(">> Received query final notification\n"); @@ -129,3 +130,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index 8ddcf74e6..8c8539bfe 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_QUERYABLE == 1 const char *keyexpr = "demo/example/zenoh-pico-queryable"; const char *value = "Queryable from Pico!"; @@ -120,3 +121,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/windows/z_get.c b/examples/windows/z_get.c index b2b6aafda..0d082a63e 100644 --- a/examples/windows/z_get.c +++ b/examples/windows/z_get.c @@ -17,6 +17,7 @@ #include #include +#if Z_FEATURE_QUERY == 1 void reply_dropper(void *ctx) { (void)(ctx); printf(">> Received query final notification\n"); @@ -94,3 +95,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/windows/z_queryable.c b/examples/windows/z_queryable.c index 60b03ab5d..8fafa11d9 100644 --- a/examples/windows/z_queryable.c +++ b/examples/windows/z_queryable.c @@ -17,6 +17,7 @@ #include #include +#if Z_FEATURE_QUERYABLE == 1 const char *keyexpr = "demo/example/zenoh-pico-queryable"; const char *value = "Queryable from Pico!"; @@ -89,3 +90,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERYABLE but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/zephyr/z_get.c b/examples/zephyr/z_get.c index 4fcc47649..279bd69a5 100644 --- a/examples/zephyr/z_get.c +++ b/examples/zephyr/z_get.c @@ -17,6 +17,7 @@ #include #include +#if Z_FEATURE_QUERY == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -88,3 +89,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_QUERY 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 68861d6f9..14189c48d 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -829,6 +829,7 @@ 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); +#if Z_FEATURE_QUERY == 1 /** * Constructs the default values for the get operation. * @@ -852,6 +853,130 @@ z_get_options_t z_get_options_default(void); */ int8_t z_get(z_session_t zs, z_keyexpr_t keyexpr, const char *parameters, z_owned_closure_reply_t *callback, const z_get_options_t *options); +/** + * Checks if the queryable answered with an OK, which allows this value to be treated as a sample. + * + * If this returns ``false``, you should use ``z_check`` before trying to use :c:func:`z_reply_err` if you want to + * process the error that may be here. + * + * Parameters: + * reply: Pointer to the received query reply. + * + * Returns: + * Returns ``true`` if the queryable answered with an OK, which allows this value to be treated as a sample, or + * ``false`` otherwise. + */ +_Bool z_reply_is_ok(const z_owned_reply_t *reply); + +/** + * Yields the contents of the reply by asserting it indicates a success. + * + * You should always make sure that :c:func:`z_reply_is_ok` returns ``true`` before calling this function. + * + * Parameters: + * reply: Pointer to the received query reply. + * + * Returns: + * Returns the :c:type:`z_sample_t` wrapped in the query reply. + */ +z_sample_t z_reply_ok(const z_owned_reply_t *reply); + +/** + * Yields the contents of the reply by asserting it indicates a failure. + * + * You should always make sure that :c:func:`z_reply_is_ok` returns ``false`` before calling this function. + * + * Parameters: + * reply: Pointer to the received query reply. + * + * Returns: + * Returns the :c:type:`z_value_t` wrapped in the query reply. + */ +z_value_t z_reply_err(const z_owned_reply_t *reply); +#endif + +#if Z_FEATURE_QUERYABLE == 1 +/** + * Constructs the default values for the queryable entity. + * + * Returns: + * Returns the constructed :c:type:`z_queryable_options_t`. + */ +z_queryable_options_t z_queryable_options_default(void); + +/** + * Declares a queryable for the given keyexpr. + * + * Received queries are processed by means of callbacks. + * + * Like most ``z_owned_X_t`` types, you may obtain an instance of :c:type:`z_owned_queryable_t` by loaning it using + * ``z_queryable_loan(&val)``. The ``z_loan(val)`` macro, available if your compiler supports C11's ``_Generic``, is + * equivalent to writing ``z_queryable_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_queryable_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 subscriber. + * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. + * callback: A moved instance of :c:type:`z_owned_closure_query_t` containing the callbacks to be called and the + * context to pass to them. options: The options to apply to the queryable. If ``NULL`` is passed, the default options + * will be applied. + * + * Returns: + * A :c:type:`z_owned_queryable_t` with either a valid queryable or a failing queryable. + * Should the queryable be invalid, ``z_check(val)`` ing the returned value will return ``false``. + */ +z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_owned_closure_query_t *callback, + const z_queryable_options_t *options); + +/** + * Undeclares the queryable generated by a call to :c:func:`z_declare_queryable`. + * + * Parameters: + * queryable: A moved instance of :c:type:`z_owned_queryable_t` to undeclare. + * + * Returns: + * Returns ``0`` if the undeclare queryable operation is successful, or a ``negative value`` otherwise. + */ +int8_t z_undeclare_queryable(z_owned_queryable_t *queryable); + +/** + * Constructs the default values for the query reply operation. + * + * Returns: + * Returns the constructed :c:type:`z_query_reply_options_t`. + */ +z_query_reply_options_t z_query_reply_options_default(void); + +/** + * Sends a reply to a query. + * + * This function must be called inside of a :c:type:`z_owned_closure_query_t` callback associated to the + * :c:type:`z_owned_queryable_t`, passing the received query as parameters of the callback function. This function can + * be called multiple times to send multiple replies to a query. The reply will be considered complete when the callback + * returns. + * + * Parameters: + * query: Pointer to the received query. + * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. + * payload: Pointer to the data to put. + * payload_len: The length of the ``payload``. + * options: The options to apply to the send query reply operation. If ``NULL`` is passed, the default options will be + * applied. + * + * Returns: + * Returns ``0`` if the send query reply operation is successful, or a ``negative value`` otherwise. + */ +int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const uint8_t *payload, size_t payload_len, + const z_query_reply_options_t *options); +#endif /** * Creates keyexpr owning string passed to it @@ -1113,128 +1238,6 @@ int8_t z_undeclare_pull_subscriber(z_owned_pull_subscriber_t *sub); */ int8_t z_subscriber_pull(const z_pull_subscriber_t sub); -/** - * Constructs the default values for the queryable entity. - * - * Returns: - * Returns the constructed :c:type:`z_queryable_options_t`. - */ -z_queryable_options_t z_queryable_options_default(void); - -/** - * Declares a queryable for the given keyexpr. - * - * Received queries are processed by means of callbacks. - * - * Like most ``z_owned_X_t`` types, you may obtain an instance of :c:type:`z_owned_queryable_t` by loaning it using - * ``z_queryable_loan(&val)``. The ``z_loan(val)`` macro, available if your compiler supports C11's ``_Generic``, is - * equivalent to writing ``z_queryable_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_queryable_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 subscriber. - * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. - * callback: A moved instance of :c:type:`z_owned_closure_query_t` containing the callbacks to be called and the - * context to pass to them. options: The options to apply to the queryable. If ``NULL`` is passed, the default options - * will be applied. - * - * Returns: - * A :c:type:`z_owned_queryable_t` with either a valid queryable or a failing queryable. - * Should the queryable be invalid, ``z_check(val)`` ing the returned value will return ``false``. - */ -z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_owned_closure_query_t *callback, - const z_queryable_options_t *options); - -/** - * Undeclares the queryable generated by a call to :c:func:`z_declare_queryable`. - * - * Parameters: - * queryable: A moved instance of :c:type:`z_owned_queryable_t` to undeclare. - * - * Returns: - * Returns ``0`` if the undeclare queryable operation is successful, or a ``negative value`` otherwise. - */ -int8_t z_undeclare_queryable(z_owned_queryable_t *queryable); - -/** - * Sends a reply to a query. - * - * This function must be called inside of a :c:type:`z_owned_closure_query_t` callback associated to the - * :c:type:`z_owned_queryable_t`, passing the received query as parameters of the callback function. This function can - * be called multiple times to send multiple replies to a query. The reply will be considered complete when the callback - * returns. - * - * Parameters: - * query: Pointer to the received query. - * keyexpr: A loaned instance of :c:type:`z_keyexpr_t` to associate with the subscriber. - * payload: Pointer to the data to put. - * payload_len: The length of the ``payload``. - * options: The options to apply to the send query reply operation. If ``NULL`` is passed, the default options will be - * applied. - * - * Returns: - * Returns ``0`` if the send query reply operation is successful, or a ``negative value`` otherwise. - */ -int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const uint8_t *payload, size_t payload_len, - const z_query_reply_options_t *options); - -/** - * Constructs the default values for the query reply operation. - * - * Returns: - * Returns the constructed :c:type:`z_query_reply_options_t`. - */ -z_query_reply_options_t z_query_reply_options_default(void); - -/** - * Checks if the queryable answered with an OK, which allows this value to be treated as a sample. - * - * If this returns ``false``, you should use ``z_check`` before trying to use :c:func:`z_reply_err` if you want to - * process the error that may be here. - * - * Parameters: - * reply: Pointer to the received query reply. - * - * Returns: - * Returns ``true`` if the queryable answered with an OK, which allows this value to be treated as a sample, or - * ``false`` otherwise. - */ -_Bool z_reply_is_ok(const z_owned_reply_t *reply); - -/** - * Yields the contents of the reply by asserting it indicates a success. - * - * You should always make sure that :c:func:`z_reply_is_ok` returns ``true`` before calling this function. - * - * Parameters: - * reply: Pointer to the received query reply. - * - * Returns: - * Returns the :c:type:`z_sample_t` wrapped in the query reply. - */ -z_sample_t z_reply_ok(const z_owned_reply_t *reply); - -/** - * Yields the contents of the reply by asserting it indicates a failure. - * - * You should always make sure that :c:func:`z_reply_is_ok` returns ``false`` before calling this function. - * - * Parameters: - * reply: Pointer to the received query reply. - * - * Returns: - * Returns the :c:type:`z_value_t` wrapped in the query reply. - */ -z_value_t z_reply_err(const z_owned_reply_t *reply); - /** * Checks if a given value is valid. * diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index fa2a3ff2a..f19a94b08 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -118,6 +118,20 @@ #define Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION 0 #endif +/** + * Enable queryables + */ +#ifndef Z_FEATURE_QUERYABLE +#define Z_FEATURE_QUERYABLE 1 +#endif + +/** + * Enable queries + */ +#ifndef Z_FEATURE_QUERY +#define Z_FEATURE_QUERY 1 +#endif + /** * Enable TCP links. */ diff --git a/include/zenoh-pico/net/primitives.h b/include/zenoh-pico/net/primitives.h index 38a2affb4..bfb66ea66 100644 --- a/include/zenoh-pico/net/primitives.h +++ b/include/zenoh-pico/net/primitives.h @@ -128,6 +128,7 @@ _z_subscriber_t *_z_declare_subscriber(_z_session_t *zn, _z_keyexpr_t keyexpr, _ */ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub); +#if Z_FEATURE_QUERYABLE == 1 /** * Declare a :c:type:`_z_queryable_t` for the given resource key. * @@ -156,6 +157,44 @@ _z_queryable_t *_z_declare_queryable(_z_session_t *zn, _z_keyexpr_t keyexpr, _Bo */ int8_t _z_undeclare_queryable(_z_queryable_t *qle); +/** + * Send a reply to a query. + * + * This function must be called inside of a Queryable callback passing the + * query received as parameters of the callback function. This function can + * be called multiple times to send multiple replies to a query. The reply + * will be considered complete when the Queryable callback returns. + * + * Parameters: + * query: The query to reply to. The caller keeps its ownership. + * key: The resource key of this reply. The caller keeps the ownership. + * payload: The value of this reply, the caller keeps ownership. + */ +int8_t _z_send_reply(const z_query_t *query, const _z_keyexpr_t keyexpr, const _z_value_t payload); +#endif + +#if Z_FEATURE_QUERY == 1 +/** + * Query data from the matching queryables in the system. + * + * Parameters: + * zn: The zenoh-net session. The caller keeps its ownership. + * keyexpr: The resource key to query. The callee gets the ownership of any + * allocated value. + * parameters: An indication to matching queryables about the queried data. + * target: The kind of queryables that should be target of this query. + * consolidation: The kind of consolidation that should be applied on replies. + * value: The payload of the query. + * callback: The callback function that will be called on reception of replies for this query. + * arg_call: A pointer that will be passed to the **callback** on each call. + * dropper: The callback function that will be called on upon completion of the callback. + * arg_drop: A pointer that will be passed to the **dropper** on each call. + */ +int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target, + const z_consolidation_mode_t consolidation, const _z_value_t value, _z_reply_handler_t callback, + void *arg_call, _z_drop_handler_t dropper, void *arg_drop); +#endif + /*------------------ Operations ------------------*/ /** @@ -190,39 +229,4 @@ int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *pay */ int8_t _z_subscriber_pull(const _z_subscriber_t *sub); -/** - * Query data from the matching queryables in the system. - * - * Parameters: - * zn: The zenoh-net session. The caller keeps its ownership. - * keyexpr: The resource key to query. The callee gets the ownership of any - * allocated value. - * parameters: An indication to matching queryables about the queried data. - * target: The kind of queryables that should be target of this query. - * consolidation: The kind of consolidation that should be applied on replies. - * value: The payload of the query. - * callback: The callback function that will be called on reception of replies for this query. - * arg_call: A pointer that will be passed to the **callback** on each call. - * dropper: The callback function that will be called on upon completion of the callback. - * arg_drop: A pointer that will be passed to the **dropper** on each call. - */ -int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target, - const z_consolidation_mode_t consolidation, const _z_value_t value, _z_reply_handler_t callback, - void *arg_call, _z_drop_handler_t dropper, void *arg_drop); - -/** - * Send a reply to a query. - * - * This function must be called inside of a Queryable callback passing the - * query received as parameters of the callback function. This function can - * be called multiple times to send multiple replies to a query. The reply - * will be considered complete when the Queryable callback returns. - * - * Parameters: - * query: The query to reply to. The caller keeps its ownership. - * key: The resource key of this reply. The caller keeps the ownership. - * payload: The value of this reply, the caller keeps ownership. - */ -int8_t _z_send_reply(const z_query_t *query, const _z_keyexpr_t keyexpr, const _z_value_t payload); - #endif /* ZENOH_PICO_PRIMITIVES_NETAPI_H */ diff --git a/include/zenoh-pico/net/query.h b/include/zenoh-pico/net/query.h index cb59f6dd5..0854907b7 100644 --- a/include/zenoh-pico/net/query.h +++ b/include/zenoh-pico/net/query.h @@ -39,7 +39,9 @@ typedef struct { void *_zn; // FIXME: _z_session_t *zn; } _z_queryable_t; +#if Z_FEATURE_QUERYABLE == 1 void _z_queryable_clear(_z_queryable_t *qbl); void _z_queryable_free(_z_queryable_t **qbl); +#endif #endif /* ZENOH_PICO_QUERY_NETAPI_H */ diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index a23fb84dc..8985eba02 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -54,8 +54,12 @@ typedef struct { _z_subscription_sptr_list_t *_remote_subscriptions; // Session queryables +#if Z_FEATURE_QUERYABLE == 1 _z_questionable_sptr_list_t *_local_questionable; +#endif +#if Z_FEATURE_QUERY == 1 _z_pending_query_list_t *_pending_queries; +#endif } _z_session_t; /** diff --git a/include/zenoh-pico/session/push.h b/include/zenoh-pico/session/push.h new file mode 100644 index 000000000..583746c15 --- /dev/null +++ b/include/zenoh-pico/session/push.h @@ -0,0 +1,26 @@ +// +// 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, +// + +#include + +#include "zenoh-pico/net/session.h" +#include "zenoh-pico/protocol/core.h" +#include "zenoh-pico/protocol/definitions/message.h" + +#ifndef ZENOH_PICO_SESSION_PUSH_H +#define ZENOH_PICO_SESSION_PUSH_H + +int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push); + +#endif /* ZENOH_PICO_SESSION_PUSH_H */ \ No newline at end of file diff --git a/include/zenoh-pico/session/query.h b/include/zenoh-pico/session/query.h index c5597c3c8..86d03bb6f 100644 --- a/include/zenoh-pico/session/query.h +++ b/include/zenoh-pico/session/query.h @@ -18,6 +18,7 @@ #include "zenoh-pico/net/session.h" #include "zenoh-pico/protocol/core.h" +#if Z_FEATURE_QUERY == 1 /*------------------ Query ------------------*/ _z_zint_t _z_get_query_id(_z_session_t *zn); @@ -30,5 +31,6 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, _z_zint_t reply_context, int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id); void _z_unregister_pending_query(_z_session_t *zn, _z_pending_query_t *pq); void _z_flush_pending_queries(_z_session_t *zn); +#endif #endif /* ZENOH_PICO_SESSION_QUERY_H */ diff --git a/include/zenoh-pico/session/queryable.h b/include/zenoh-pico/session/queryable.h index d6218b262..95e8cb08a 100644 --- a/include/zenoh-pico/session/queryable.h +++ b/include/zenoh-pico/session/queryable.h @@ -19,6 +19,7 @@ #include "zenoh-pico/net/session.h" +#if Z_FEATURE_QUERYABLE == 1 #define _Z_QUERYABLE_COMPLETE_DEFAULT false #define _Z_QUERYABLE_DISTANCE_DEFAULT 0 @@ -30,5 +31,6 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, const _z_keyexpr_t q_key, uint32_t qid); void _z_unregister_questionable(_z_session_t *zn, _z_questionable_sptr_t *q); void _z_flush_questionables(_z_session_t *zn); +#endif #endif /* ZENOH_PICO_SESSION_QUERYABLE_H */ diff --git a/include/zenoh-pico/session/reply.h b/include/zenoh-pico/session/reply.h new file mode 100644 index 000000000..e84fa5c7e --- /dev/null +++ b/include/zenoh-pico/session/reply.h @@ -0,0 +1,29 @@ +// +// 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, +// + +#include + +#include "zenoh-pico/net/session.h" +#include "zenoh-pico/protocol/core.h" +#include "zenoh-pico/protocol/definitions/message.h" +#include "zenoh-pico/protocol/definitions/network.h" + +#ifndef ZENOH_PICO_SESSION_REPLY_H +#define ZENOH_PICO_SESSION_REPLY_H + +int8_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key, _z_msg_reply_t *reply); + +int8_t _z_trigger_reply_final(_z_session_t *zn, _z_n_msg_response_final_t *final); + +#endif /* ZENOH_PICO_SESSION_REPLY_H */ \ No newline at end of file diff --git a/src/api/api.c b/src/api/api.c index b673e3659..7f1e0cdc1 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -421,13 +421,8 @@ 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_COMMON(z_queryable_t, z_owned_queryable_t, queryable) -OWNED_FUNCTIONS_PTR_CLONE(z_queryable_t, z_owned_queryable_t, queryable, _z_owner_noop_copy) -void z_queryable_drop(z_owned_queryable_t *val) { z_undeclare_queryable(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_reply_t, z_owned_reply_t, reply, _z_reply_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) #define OWNED_FUNCTIONS_CLOSURE(ownedtype, name) \ @@ -642,6 +637,9 @@ int8_t z_delete(z_session_t zs, z_keyexpr_t keyexpr, const z_delete_options_t *o return ret; } +#if Z_FEATURE_QUERY == 1 +OWNED_FUNCTIONS_PTR_INTERNAL(z_reply_t, z_owned_reply_t, reply, _z_reply_free, _z_owner_noop_copy) + z_get_options_t z_get_options_default(void) { return (z_get_options_t){.target = z_query_target_default(), .consolidation = z_query_consolidation_default(), @@ -697,6 +695,88 @@ int8_t z_get(z_session_t zs, z_keyexpr_t keyexpr, const char *parameters, z_owne return ret; } +_Bool z_reply_is_ok(const z_owned_reply_t *reply) { + (void)(reply); + // For the moment always return TRUE. + // The support for reply errors will come in the next release. + return true; +} + +z_sample_t z_reply_ok(const z_owned_reply_t *reply) { return reply->_value->data.sample; } + +z_value_t z_reply_err(const z_owned_reply_t *reply) { + (void)(reply); + return (z_value_t){.payload = _z_bytes_empty(), .encoding = z_encoding_default()}; +} +#endif + +#if Z_FEATURE_QUERYABLE == 1 +OWNED_FUNCTIONS_PTR_COMMON(z_queryable_t, z_owned_queryable_t, queryable) +OWNED_FUNCTIONS_PTR_CLONE(z_queryable_t, z_owned_queryable_t, queryable, _z_owner_noop_copy) +void z_queryable_drop(z_owned_queryable_t *val) { z_undeclare_queryable(val); } + +z_queryable_options_t z_queryable_options_default(void) { + return (z_queryable_options_t){.complete = _Z_QUERYABLE_COMPLETE_DEFAULT}; +} + +z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_owned_closure_query_t *callback, + const z_queryable_options_t *options) { + void *ctx = callback->context; + callback->context = NULL; + + 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_queryable_options_t opt = z_queryable_options_default(); + if (options != NULL) { + opt.complete = options->complete; + } + + return (z_owned_queryable_t){ + ._value = _z_declare_queryable(zs._val, key, opt.complete, callback->call, callback->drop, ctx)}; +} + +int8_t z_undeclare_queryable(z_owned_queryable_t *queryable) { + int8_t ret = _Z_RES_OK; + + ret = _z_undeclare_queryable(queryable->_value); + _z_queryable_free(&queryable->_value); + return ret; +} + +z_query_reply_options_t z_query_reply_options_default(void) { + return (z_query_reply_options_t){.encoding = z_encoding_default()}; +} + +int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const uint8_t *payload, size_t payload_len, + const z_query_reply_options_t *options) { + z_query_reply_options_t opts = options == NULL ? z_query_reply_options_default() : *options; + _z_value_t value = {.payload = + { + .start = payload, + ._is_alloc = false, + .len = payload_len, + }, + .encoding = {.prefix = opts.encoding.prefix, .suffix = opts.encoding.suffix}}; + return _z_send_reply(query, keyexpr, value); + return _Z_ERR_GENERIC; +} +#endif + z_owned_keyexpr_t z_keyexpr_new(const char *name) { z_owned_keyexpr_t key; @@ -890,81 +970,6 @@ int8_t z_undeclare_pull_subscriber(z_owned_pull_subscriber_t *sub) { int8_t z_subscriber_pull(const z_pull_subscriber_t sub) { return _z_subscriber_pull(sub._val); } -z_queryable_options_t z_queryable_options_default(void) { - return (z_queryable_options_t){.complete = _Z_QUERYABLE_COMPLETE_DEFAULT}; -} - -z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_owned_closure_query_t *callback, - const z_queryable_options_t *options) { - void *ctx = callback->context; - callback->context = NULL; - - 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_queryable_options_t opt = z_queryable_options_default(); - if (options != NULL) { - opt.complete = options->complete; - } - - return (z_owned_queryable_t){ - ._value = _z_declare_queryable(zs._val, key, opt.complete, callback->call, callback->drop, ctx)}; -} - -int8_t z_undeclare_queryable(z_owned_queryable_t *queryable) { - int8_t ret = _Z_RES_OK; - - ret = _z_undeclare_queryable(queryable->_value); - _z_queryable_free(&queryable->_value); - - return ret; -} - -z_query_reply_options_t z_query_reply_options_default(void) { - return (z_query_reply_options_t){.encoding = z_encoding_default()}; -} - -int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const uint8_t *payload, size_t payload_len, - const z_query_reply_options_t *options) { - z_query_reply_options_t opts = options == NULL ? z_query_reply_options_default() : *options; - _z_value_t value = {.payload = - { - .start = payload, - ._is_alloc = false, - .len = payload_len, - }, - .encoding = {.prefix = opts.encoding.prefix, .suffix = opts.encoding.suffix}}; - return _z_send_reply(query, keyexpr, value); -} - -_Bool z_reply_is_ok(const z_owned_reply_t *reply) { - (void)(reply); - // For the moment always return TRUE. - // The support for reply errors will come in the next release. - return true; -} - -z_value_t z_reply_err(const z_owned_reply_t *reply) { - (void)(reply); - return (z_value_t){.payload = _z_bytes_empty(), .encoding = z_encoding_default()}; -} - -z_sample_t z_reply_ok(const z_owned_reply_t *reply) { return reply->_value->data.sample; } - /**************** Tasks ****************/ zp_task_read_options_t zp_task_read_options_default(void) { return (zp_task_read_options_t){.__dummy = 0}; } @@ -1030,6 +1035,7 @@ 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) { @@ -1037,6 +1043,7 @@ z_owned_keyexpr_t z_publisher_keyexpr(z_publisher_t publisher) { } return ret; } + z_owned_keyexpr_t z_subscriber_keyexpr(z_subscriber_t sub) { z_owned_keyexpr_t ret = z_keyexpr_null(); uint32_t lookup = sub._val->_entity_id; diff --git a/src/net/primitives.c b/src/net/primitives.c index d536f2e96..65538ae62 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -190,6 +190,7 @@ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub) { return ret; } +#if Z_FEATURE_QUERYABLE == 1 /*------------------ Queryable Declaration ------------------*/ _z_queryable_t *_z_declare_queryable(_z_session_t *zn, _z_keyexpr_t keyexpr, _Bool complete, _z_questionable_handler_t callback, _z_drop_handler_t dropper, void *arg) { @@ -302,6 +303,47 @@ int8_t _z_send_reply(const z_query_t *query, _z_keyexpr_t keyexpr, const _z_valu return ret; } +#endif + +#if Z_FEATURE_QUERY == 1 +/*------------------ Query ------------------*/ +int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target, + const z_consolidation_mode_t consolidation, _z_value_t value, _z_reply_handler_t callback, + void *arg_call, _z_drop_handler_t dropper, void *arg_drop) { + int8_t ret = _Z_RES_OK; + + // Create the pending query object + _z_pending_query_t *pq = (_z_pending_query_t *)z_malloc(sizeof(_z_pending_query_t)); + if (pq != NULL) { + pq->_id = _z_get_query_id(zn); + pq->_key = _z_get_expanded_key_from_key(zn, &keyexpr); + pq->_parameters = _z_str_clone(parameters); + pq->_target = target; + pq->_consolidation = consolidation; + pq->_anykey = (strstr(pq->_parameters, Z_SELECTOR_QUERY_MATCH) == NULL) ? false : true; + pq->_callback = callback; + pq->_dropper = dropper; + pq->_pending_replies = NULL; + pq->_call_arg = arg_call; + pq->_drop_arg = arg_drop; + + ret = _z_register_pending_query(zn, pq); // Add the pending query to the current session + if (ret == _Z_RES_OK) { + _z_bytes_t params = _z_bytes_wrap((uint8_t *)pq->_parameters, strlen(pq->_parameters)); + _z_zenoh_message_t z_msg = _z_msg_make_query(&keyexpr, ¶ms, pq->_id, pq->_consolidation, &value); + + if (_z_send_n_msg(zn, &z_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) { + _z_unregister_pending_query(zn, pq); + ret = _Z_ERR_TRANSPORT_TX_FAILED; + } + } else { + _z_pending_query_clear(pq); + } + } + + 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, @@ -353,44 +395,6 @@ int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *pay return ret; } -/*------------------ Query ------------------*/ -int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target, - const z_consolidation_mode_t consolidation, _z_value_t value, _z_reply_handler_t callback, - void *arg_call, _z_drop_handler_t dropper, void *arg_drop) { - int8_t ret = _Z_RES_OK; - - // Create the pending query object - _z_pending_query_t *pq = (_z_pending_query_t *)z_malloc(sizeof(_z_pending_query_t)); - if (pq != NULL) { - pq->_id = _z_get_query_id(zn); - pq->_key = _z_get_expanded_key_from_key(zn, &keyexpr); - pq->_parameters = _z_str_clone(parameters); - pq->_target = target; - pq->_consolidation = consolidation; - pq->_anykey = (strstr(pq->_parameters, Z_SELECTOR_QUERY_MATCH) == NULL) ? false : true; - pq->_callback = callback; - pq->_dropper = dropper; - pq->_pending_replies = NULL; - pq->_call_arg = arg_call; - pq->_drop_arg = arg_drop; - - ret = _z_register_pending_query(zn, pq); // Add the pending query to the current session - if (ret == _Z_RES_OK) { - _z_bytes_t params = _z_bytes_wrap((uint8_t *)pq->_parameters, strlen(pq->_parameters)); - _z_zenoh_message_t z_msg = _z_msg_make_query(&keyexpr, ¶ms, pq->_id, pq->_consolidation, &value); - - if (_z_send_n_msg(zn, &z_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) { - _z_unregister_pending_query(zn, pq); - ret = _Z_ERR_TRANSPORT_TX_FAILED; - } - } else { - _z_pending_query_clear(pq); - } - } - - return ret; -} - /*------------------ Pull ------------------*/ int8_t _z_subscriber_pull(const _z_subscriber_t *sub) { int8_t ret = _Z_RES_OK; diff --git a/src/net/query.c b/src/net/query.c index b9302c2fe..8b6d71b97 100644 --- a/src/net/query.c +++ b/src/net/query.c @@ -13,6 +13,7 @@ #include "zenoh-pico/session/query.h" +#if Z_FEATURE_QUERYABLE == 1 void _z_queryable_clear(_z_queryable_t *qbl) { // Nothing to clear (void)(qbl); @@ -28,3 +29,4 @@ void _z_queryable_free(_z_queryable_t **qbl) { *qbl = NULL; } } +#endif \ No newline at end of file diff --git a/src/session/push.c b/src/session/push.c new file mode 100644 index 000000000..5e0649983 --- /dev/null +++ b/src/session/push.c @@ -0,0 +1,35 @@ +// +// 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, +// + +#include "zenoh-pico/session/push.h" + +#include "zenoh-pico/api/constants.h" +#include "zenoh-pico/api/primitives.h" +#include "zenoh-pico/collections/bytes.h" +#include "zenoh-pico/config.h" +#include "zenoh-pico/session/subscription.h" +#include "zenoh-pico/utils/logging.h" + +int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push) { + int8_t ret = _Z_RES_OK; + + // TODO check body to know where to dispatch + _z_bytes_t payload = push->_body._is_put ? push->_body._body._put._payload : _z_bytes_empty(); + _z_encoding_t encoding = push->_body._is_put ? push->_body._body._put._encoding : z_encoding_default(); + int kind = push->_body._is_put ? Z_SAMPLE_KIND_PUT : Z_SAMPLE_KIND_DELETE; + + ret = _z_trigger_subscriptions(zn, push->_key, payload, encoding, kind, push->_timestamp); + + return ret; +} \ No newline at end of file diff --git a/src/session/query.c b/src/session/query.c index ec976c7e3..d6a7a7910 100644 --- a/src/session/query.c +++ b/src/session/query.c @@ -22,6 +22,7 @@ #include "zenoh-pico/session/resource.h" #include "zenoh-pico/utils/logging.h" +#if Z_FEATURE_QUERY == 1 _z_reply_t *_z_reply_alloc_and_move(_z_reply_t *_reply) { _z_reply_t *reply = (_z_reply_t *)z_malloc(sizeof(_z_reply_t)); if (reply != NULL) { @@ -290,3 +291,4 @@ void _z_flush_pending_queries(_z_session_t *zn) { _z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } +#endif \ No newline at end of file diff --git a/src/session/queryable.c b/src/session/queryable.c index 7431712b4..243519b69 100644 --- a/src/session/queryable.c +++ b/src/session/queryable.c @@ -24,6 +24,7 @@ #include "zenoh-pico/session/utils.h" #include "zenoh-pico/utils/logging.h" +#if Z_FEATURE_QUERYABLE == 1 _Bool _z_questionable_eq(const _z_questionable_t *one, const _z_questionable_t *two) { return one->_id == two->_id; } void _z_questionable_clear(_z_questionable_t *qle) { @@ -224,3 +225,5 @@ void _z_flush_questionables(_z_session_t *zn) { _z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } + +#endif diff --git a/src/session/reply.c b/src/session/reply.c new file mode 100644 index 000000000..0ca562936 --- /dev/null +++ b/src/session/reply.c @@ -0,0 +1,44 @@ +// +// 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, +// + +#include "zenoh-pico/session/reply.h" + +#include "zenoh-pico/api/constants.h" +#include "zenoh-pico/config.h" +#include "zenoh-pico/session/query.h" +#include "zenoh-pico/utils/logging.h" + +int8_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key, _z_msg_reply_t *reply) { + int8_t ret = _Z_RES_OK; + + // TODO check id to know where to dispatch + +#if Z_FEATURE_QUERY == 1 + ret = _z_trigger_query_reply_partial(zn, id, key, reply->_value.payload, reply->_value.encoding, Z_SAMPLE_KIND_PUT, + reply->_timestamp); +#endif + return ret; +} + +int8_t _z_trigger_reply_final(_z_session_t *zn, _z_n_msg_response_final_t *final) { + int8_t ret = _Z_RES_OK; + + // TODO check id to know where to dispatch + _z_zint_t id = final->_request_id; + +#if Z_FEATURE_QUERY == 1 + _z_trigger_query_reply_final(zn, id); +#endif + return ret; +} \ No newline at end of file diff --git a/src/session/rx.c b/src/session/rx.c index 082fe21ee..d9e17587b 100644 --- a/src/session/rx.c +++ b/src/session/rx.c @@ -24,8 +24,9 @@ #include "zenoh-pico/protocol/definitions/message.h" #include "zenoh-pico/protocol/definitions/network.h" #include "zenoh-pico/protocol/keyexpr.h" -#include "zenoh-pico/session/query.h" +#include "zenoh-pico/session/push.h" #include "zenoh-pico/session/queryable.h" +#include "zenoh-pico/session/reply.h" #include "zenoh-pico/session/resource.h" #include "zenoh-pico/session/session.h" #include "zenoh-pico/session/subscription.h" @@ -81,19 +82,20 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint } break; case _Z_N_PUSH: { _Z_DEBUG("Handling _Z_N_PUSH\n"); - _z_n_msg_push_t push = msg->_body._push; - _z_bytes_t payload = push._body._is_put ? push._body._body._put._payload : _z_bytes_empty(); - _z_encoding_t encoding = push._body._is_put ? push._body._body._put._encoding : z_encoding_default(); - int kind = push._body._is_put ? Z_SAMPLE_KIND_PUT : Z_SAMPLE_KIND_DELETE; - ret = _z_trigger_subscriptions(zn, push._key, payload, encoding, kind, push._timestamp); + _z_n_msg_push_t *push = &msg->_body._push; + ret = _z_trigger_push(zn, push); } break; case _Z_N_REQUEST: { _Z_DEBUG("Handling _Z_N_REQUEST\n"); _z_n_msg_request_t req = msg->_body._request; switch (req._tag) { case _Z_REQUEST_QUERY: { +#if Z_FEATURE_QUERYABLE == 1 _z_msg_query_t *query = &req._body._query; ret = _z_trigger_queryables(zn, query, req._key, req._rid); +#else + _Z_DEBUG("_Z_REQUEST_QUERY dropped, queryables not supported\n"); +#endif } break; case _Z_REQUEST_PUT: { _z_msg_put_t put = req._body._put; @@ -127,9 +129,8 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint _z_n_msg_response_t response = msg->_body._response; switch (response._tag) { case _Z_RESPONSE_BODY_REPLY: { - _z_msg_reply_t reply = response._body._reply; - ret = _z_trigger_query_reply_partial(zn, response._request_id, response._key, reply._value.payload, - reply._value.encoding, Z_SAMPLE_KIND_PUT, reply._timestamp); + _z_msg_reply_t *reply = &response._body._reply; + ret = _z_trigger_reply_partial(zn, response._request_id, response._key, reply); } break; case _Z_RESPONSE_BODY_ERR: { // @TODO: expose errors to the user @@ -155,8 +156,7 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint } break; case _Z_N_RESPONSE_FINAL: { _Z_DEBUG("Handling _Z_N_RESPONSE_FINAL\n"); - _z_zint_t id = msg->_body._response_final._request_id; - _z_trigger_query_reply_final(zn, id); + ret = _z_trigger_reply_final(zn, &msg->_body._response_final); } break; } _z_msg_clear(msg); diff --git a/src/session/utils.c b/src/session/utils.c index 494cb7a5d..8f80c260c 100644 --- a/src/session/utils.c +++ b/src/session/utils.c @@ -63,8 +63,12 @@ int8_t _z_session_init(_z_session_t *zn, _z_id_t *zid) { zn->_remote_resources = NULL; zn->_local_subscriptions = NULL; zn->_remote_subscriptions = NULL; +#if Z_FEATURE_QUERYABLE == 1 zn->_local_questionable = NULL; +#endif +#if Z_FEATURE_QUERY == 1 zn->_pending_queries = NULL; +#endif #if Z_FEATURE_MULTI_THREAD == 1 ret = _z_mutex_init(&zn->_mutex_inner); @@ -100,8 +104,13 @@ void _z_session_clear(_z_session_t *zn) { // Clean up the entities _z_flush_resources(zn); _z_flush_subscriptions(zn); + +#if Z_FEATURE_QUERYABLE == 1 _z_flush_questionables(zn); +#endif +#if Z_FEATURE_QUERY == 1 _z_flush_pending_queries(zn); +#endif #if Z_FEATURE_MULTI_THREAD == 1 _z_mutex_free(&zn->_mutex_inner); diff --git a/tests/z_api_null_drop_test.c b/tests/z_api_null_drop_test.c index f5707167c..6d54fea94 100644 --- a/tests/z_api_null_drop_test.c +++ b/tests/z_api_null_drop_test.c @@ -31,8 +31,6 @@ int main(void) { 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_reply_t reply_null_1 = z_reply_null(); z_owned_hello_t hello_null_1 = z_hello_null(); z_owned_closure_sample_t closure_sample_null_1 = z_closure_sample_null(); z_owned_closure_query_t closure_query_null_1 = z_closure_query_null(); @@ -51,8 +49,6 @@ int main(void) { 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(reply_null_1)); assert(!z_check(hello_null_1)); assert(!z_check(str_null_1)); @@ -66,8 +62,6 @@ int main(void) { 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_reply_t reply_null_2; z_owned_hello_t hello_null_2; z_owned_closure_sample_t closure_sample_null_2; z_owned_closure_query_t closure_query_null_2; @@ -83,8 +77,6 @@ int main(void) { z_null(&scouting_config_null_2); z_null(&pull_subscriber_null_2); z_null(&subscriber_null_2); - z_null(&queryable_null_2); - z_null(&reply_null_2); z_null(&hello_null_2); z_null(&closure_sample_null_2); z_null(&closure_query_null_2); @@ -93,6 +85,21 @@ int main(void) { z_null(&closure_zid_null_2); z_null(&str_null_2); +#if Z_FEATURE_QUERYABLE == 1 + z_owned_queryable_t queryable_null_1 = z_queryable_null(); + assert(!z_check(queryable_null_1)); + z_owned_queryable_t queryable_null_2; + z_null(&queryable_null_2); + assert(!z_check(queryable_null_2)); +#endif +#if Z_FEATURE_QUERY == 1 + z_owned_reply_t reply_null_1 = z_reply_null(); + assert(!z_check(reply_null_1)); + z_owned_reply_t reply_null_2; + z_null(&reply_null_2); + assert(!z_check(reply_null_2)); +#endif + // // Test that null macro works the same as direct call // @@ -103,8 +110,6 @@ int main(void) { 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(reply_null_2)); assert(!z_check(hello_null_2)); assert(!z_check(str_null_2)); @@ -119,8 +124,6 @@ int main(void) { 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(reply_null_1)); z_drop(z_move(hello_null_1)); z_drop(z_move(closure_sample_null_1)); z_drop(z_move(closure_query_null_1)); @@ -136,8 +139,6 @@ int main(void) { 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(reply_null_2)); z_drop(z_move(hello_null_2)); z_drop(z_move(closure_sample_null_2)); z_drop(z_move(closure_query_null_2)); @@ -145,6 +146,15 @@ int main(void) { z_drop(z_move(closure_hello_null_2)); z_drop(z_move(closure_zid_null_2)); z_drop(z_move(str_null_2)); + +#if Z_FEATURE_QUERYABLE == 1 + z_drop(z_move(queryable_null_1)); + z_drop(z_move(queryable_null_2)); +#endif +#if Z_FEATURE_QUERY == 1 + z_drop(z_move(reply_null_1)); + z_drop(z_move(reply_null_2)); +#endif } return 0; From db2ac4cb91c990d668b3bdee3723b91b10ed45ee Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Tue, 17 Oct 2023 11:57:42 +0200 Subject: [PATCH 20/26] cancel prefix declaration if allocating suffix failed in subscriber declaration --- src/api/api.c | 9 +++++++-- zenohpico.pc | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/api/api.c b/src/api/api.c index ba7bf18b6..d8b4cd8b4 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -822,6 +822,7 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z _z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr); if (r == NULL) { char *wild = strpbrk(keyexpr._suffix, "*$"); + _Bool do_keydecl = true; if (wild != NULL && wild != keyexpr._suffix) { wild -= 1; size_t len = wild - keyexpr._suffix; @@ -831,10 +832,14 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z suffix[len] = 0; keyexpr._suffix = suffix; _z_keyexpr_set_owns_suffix(&keyexpr, false); + } else { + do_keydecl = false; } } - uint16_t id = _z_declare_resource(zs._val, keyexpr); - key = _z_rid_with_suffix(id, wild); + if (do_keydecl) { + uint16_t id = _z_declare_resource(zs._val, keyexpr); + key = _z_rid_with_suffix(id, wild); + } } #if Z_FEATURE_MULTICAST_TRANSPORT == 1 } diff --git a/zenohpico.pc b/zenohpico.pc index 6a0f039aa..5282169f0 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -1,8 +1,8 @@ -prefix=/usr/local +prefix=/var/empty/local Name: zenohpico Description: URL: -Version: 0.11.20231012dev +Version: 0.11.20231017dev Cflags: -I${prefix}/include -Libs: -L${prefix}/lib -lzenohpico +Libs: -L${prefix}/lib64 -lzenohpico From 4b564435f1683b43bd55a1b88b56ccf93fbacabf Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Thu, 19 Oct 2023 13:50:02 +0200 Subject: [PATCH 21/26] fix misencoding of query body --- src/protocol/codec/message.c | 2 +- zenohpico.pc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index 8a529400d..ad4279fe8 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -401,7 +401,7 @@ int8_t _z_query_encode(_z_wbuf_t *wbf, const _z_msg_query_t *msg) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); _Z_RETURN_IF_ERR(_z_zint_encode(wbf, _z_zint_len(msg->_ext_value.encoding.prefix) + _z_bytes_encode_len(&msg->_ext_value.encoding.suffix) + - _z_bytes_encode_len(&msg->_ext_value.payload))); + msg->_ext_value.payload.len)); _Z_RETURN_IF_ERR(_z_encoding_prefix_encode(wbf, msg->_ext_value.encoding.prefix)); _Z_RETURN_IF_ERR(_z_bytes_encode(wbf, &msg->_ext_value.encoding.suffix)); _Z_RETURN_IF_ERR(_z_bytes_val_encode(wbf, &msg->_ext_value.payload)); diff --git a/zenohpico.pc b/zenohpico.pc index 5282169f0..bcc1e5d18 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -1,8 +1,8 @@ -prefix=/var/empty/local +prefix=/usr/local Name: zenohpico Description: URL: -Version: 0.11.20231017dev +Version: 0.11.20231019dev Cflags: -I${prefix}/include -Libs: -L${prefix}/lib64 -lzenohpico +Libs: -L${prefix}/lib -lzenohpico From 5a90c012e744e1915f3bfb97f74ab3a9c6aaa3ae Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Thu, 19 Oct 2023 14:24:47 +0200 Subject: [PATCH 22/26] ensure generated strings are always ASCII to respect the UTF8 requirement on selectors and keyexprs --- tests/z_msgcodec_test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index dcf051d41..b56b40a9f 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -184,7 +184,9 @@ _z_bytes_t gen_bytes(size_t len) { if (len == 0) return arr; arr.start = (uint8_t *)z_malloc(sizeof(uint8_t) * len); - for (_z_zint_t i = 0; i < len; i++) ((uint8_t *)arr.start)[i] = gen_uint8(); + for (_z_zint_t i = 0; i < len; i++) { + ((uint8_t *)arr.start)[i] = gen_uint8() & 0b01111111; + } return arr; } From f9effd0ea93cc2d30e9e863bc5f9d1b9ba198756 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Fri, 20 Oct 2023 09:31:45 +0200 Subject: [PATCH 23/26] fix: Keep tests assert even in release build --- tests/z_api_alignment_test.c | 4 +++- tests/z_client_test.c | 4 +++- tests/z_data_struct_test.c | 4 +++- tests/z_endpoint_test.c | 4 +++- tests/z_iobuf_test.c | 5 ++++- tests/z_msgcodec_test.c | 4 +++- tests/z_peer_multicast_test.c | 4 +++- 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index a9cadb833..dd0be80da 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -11,12 +11,14 @@ // Contributors: // ZettaScale Zenoh Team, -#include #include #include #include #include +#undef NDEBUG +#include + #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) #include #define sleep(x) Sleep(x * 1000) diff --git a/tests/z_client_test.c b/tests/z_client_test.c index 0c42ab132..22475a352 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -11,7 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, -#include #include #include #include @@ -21,6 +20,9 @@ #include "zenoh-pico/api/types.h" #include "zenoh-pico/collections/string.h" +#undef NDEBUG +#include + #define MSG 1000 #define MSG_LEN 1024 #define QRY 100 diff --git a/tests/z_data_struct_test.c b/tests/z_data_struct_test.c index 8990ef678..461ee92ca 100644 --- a/tests/z_data_struct_test.c +++ b/tests/z_data_struct_test.c @@ -12,7 +12,6 @@ // ZettaScale Zenoh Team, // -#include #include #include #include @@ -22,6 +21,9 @@ #include "zenoh-pico/system/platform.h" #include "zenoh-pico/transport/transport.h" +#undef NDEBUG +#include + void entry_list_test(void) { _z_transport_peer_entry_list_t *root = _z_transport_peer_entry_list_new(); for (int i = 0; i < 10; i++) { diff --git a/tests/z_endpoint_test.c b/tests/z_endpoint_test.c index 217fe0f4a..621955c9d 100644 --- a/tests/z_endpoint_test.c +++ b/tests/z_endpoint_test.c @@ -12,7 +12,6 @@ // ZettaScale Zenoh Team, // -#include #include #include #include @@ -22,6 +21,9 @@ #include "zenoh-pico/link/endpoint.h" #include "zenoh-pico/utils/result.h" +#undef NDEBUG +#include + int main(void) { char *s = (char *)malloc(64); diff --git a/tests/z_iobuf_test.c b/tests/z_iobuf_test.c index 4b7d41462..0b490d515 100644 --- a/tests/z_iobuf_test.c +++ b/tests/z_iobuf_test.c @@ -11,7 +11,7 @@ // Contributors: // ZettaScale Zenoh Team, // -#include + #include #include #include @@ -20,6 +20,9 @@ #include "zenoh-pico/protocol/iobuf.h" +#undef NDEBUG +#include + #define RUNS 1000 /*=============================*/ diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index dcf051d41..168a3adce 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -19,7 +19,6 @@ #include "zenoh-pico/protocol/definitions/transport.h" #define ZENOH_PICO_TEST_H -#include #include #include #include @@ -41,6 +40,9 @@ #include "zenoh-pico/protocol/keyexpr.h" #include "zenoh-pico/system/platform.h" +#undef NDEBUG +#include + #define RUNS 1000 #define _Z_MOCK_EXTENSION_UNIT 0x01 diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index e1ede7104..d29551a0f 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -12,7 +12,6 @@ // ZettaScale Zenoh Team, // -#include #include #include #include @@ -22,6 +21,9 @@ #include "zenoh-pico/collections/bytes.h" #include "zenoh-pico/protocol/core.h" +#undef NDEBUG +#include + #define MSG 10 #define MSG_LEN 1024 #define QRY 10 From 5a1e59fc5799491ede7b4e52e29ae8a6a6d0a8c9 Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Mon, 23 Oct 2023 15:12:26 +0200 Subject: [PATCH 24/26] Add subscription token config (#264) --- examples/arduino/z_pull.ino | 7 +++ examples/arduino/z_sub.ino | 8 +++ examples/espidf/z_pull.c | 6 +++ examples/espidf/z_sub.c | 6 +++ examples/mbed/z_pull.cpp | 7 +++ examples/mbed/z_sub.cpp | 7 +++ examples/unix/c11/z_ping.c | 7 +++ examples/unix/c11/z_pong.c | 7 +++ examples/unix/c11/z_pull.c | 7 +++ examples/unix/c11/z_sub.c | 7 +++ examples/unix/c11/z_sub_st.c | 7 +++ examples/unix/c99/z_ping.c | 9 +++- examples/unix/c99/z_pong.c | 9 +++- examples/unix/c99/z_pull.c | 7 +++ examples/unix/c99/z_sub.c | 7 +++ examples/unix/c99/z_sub_st.c | 7 +++ examples/windows/z_ping.c | 9 +++- examples/windows/z_pong.c | 9 +++- examples/windows/z_pull.c | 7 +++ examples/windows/z_sub.c | 7 +++ examples/windows/z_sub_st.c | 7 +++ examples/zephyr/z_pull.c | 7 +++ examples/zephyr/z_sub.c | 7 +++ include/zenoh-pico/api/primitives.h | 2 + include/zenoh-pico/config.h | 7 +++ include/zenoh-pico/net/primitives.h | 24 +++++---- include/zenoh-pico/net/session.h | 2 + include/zenoh-pico/net/subscribe.h | 2 + include/zenoh-pico/session/subscription.h | 2 + src/api/api.c | 64 ++++++++++++----------- src/net/primitives.c | 40 +++++++------- src/net/subscribe.c | 2 + src/session/push.c | 4 +- src/session/rx.c | 8 +++ src/session/subscription.c | 2 + src/session/utils.c | 5 +- tests/z_api_null_drop_test.c | 32 +++++++----- 37 files changed, 282 insertions(+), 82 deletions(-) diff --git a/examples/arduino/z_pull.ino b/examples/arduino/z_pull.ino index 5e2952d6c..c1ffd7865 100644 --- a/examples/arduino/z_pull.ino +++ b/examples/arduino/z_pull.ino @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 // WiFi-specific parameters #define SSID "SSID" #define PASS "PASS" @@ -108,3 +109,9 @@ void loop() { delay(5000); z_subscriber_pull(z_pull_subscriber_loan(&sub)); } +#else +void setup() { + Serial.println("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it."); +} +void loop() {} +#endif diff --git a/examples/arduino/z_sub.ino b/examples/arduino/z_sub.ino index e9b829245..b07ca70c0 100644 --- a/examples/arduino/z_sub.ino +++ b/examples/arduino/z_sub.ino @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 // WiFi-specific parameters #define SSID "SSID" #define PASS "PASS" @@ -104,3 +105,10 @@ void setup() { } void loop() { delay(5000); } + +#else +void setup() { + Serial.println("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it."); +} +void loop() {} +#endif \ No newline at end of file diff --git a/examples/espidf/z_pull.c b/examples/espidf/z_pull.c index 976880a79..03175c898 100644 --- a/examples/espidf/z_pull.c +++ b/examples/espidf/z_pull.c @@ -25,6 +25,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 #define ESP_WIFI_SSID "SSID" #define ESP_WIFI_PASS "PASS" #define ESP_MAXIMUM_RETRY 5 @@ -168,3 +169,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_SUBSCRIPTION but this example requires it.\n"); +} +#endif \ No newline at end of file diff --git a/examples/espidf/z_sub.c b/examples/espidf/z_sub.c index e09bad00d..01272c46e 100644 --- a/examples/espidf/z_sub.c +++ b/examples/espidf/z_sub.c @@ -25,6 +25,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 #define ESP_WIFI_SSID "SSID" #define ESP_WIFI_PASS "PASS" #define ESP_MAXIMUM_RETRY 5 @@ -166,3 +167,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_SUBSCRIPTION but this example requires it.\n"); +} +#endif \ No newline at end of file diff --git a/examples/mbed/z_pull.cpp b/examples/mbed/z_pull.cpp index 3ca962ed7..8a5e0522c 100644 --- a/examples/mbed/z_pull.cpp +++ b/examples/mbed/z_pull.cpp @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -91,3 +92,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/mbed/z_sub.cpp b/examples/mbed/z_sub.cpp index d8f9329ee..27297b1c8 100644 --- a/examples/mbed/z_sub.cpp +++ b/examples/mbed/z_sub.cpp @@ -16,6 +16,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -89,3 +90,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION 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 dc9cbf4f7..775420bd7 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -21,6 +21,7 @@ #include "zenoh-pico.h" #include "zenoh-pico/system/platform.h" +#if Z_FEATURE_SUBSCRIPTION == 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; @@ -165,3 +166,9 @@ struct args_t parse_args(int argc, char** argv) { .warmup_ms = warmup_ms, }; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\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 8acf09564..a79fb7285 100644 --- a/examples/unix/c11/z_pong.c +++ b/examples/unix/c11/z_pong.c @@ -15,6 +15,7 @@ #include "stdio.h" #include "zenoh-pico.h" +#if Z_FEATURE_SUBSCRIPTION == 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); @@ -68,3 +69,9 @@ int main(int argc, char** argv) { z_close(z_move(session)); } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c11/z_pull.c b/examples/unix/c11/z_pull.c index 678641aed..cc8297a29 100644 --- a/examples/unix/c11/z_pull.c +++ b/examples/unix/c11/z_pull.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_sample_t *sample, void *ctx) { (void)(ctx); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); @@ -98,3 +99,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c11/z_sub.c b/examples/unix/c11/z_sub.c index 7b097fe72..77fdb29a8 100644 --- a/examples/unix/c11/z_sub.c +++ b/examples/unix/c11/z_sub.c @@ -19,6 +19,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_sample_t *sample, void *ctx) { (void)(ctx); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); @@ -107,3 +108,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c11/z_sub_st.c b/examples/unix/c11/z_sub_st.c index 567290484..d6ee0966f 100644 --- a/examples/unix/c11/z_sub_st.c +++ b/examples/unix/c11/z_sub_st.c @@ -19,6 +19,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_sample_t *sample, void *ctx) { (void)(ctx); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); @@ -96,3 +97,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION 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 cbae19ccb..18c296a7d 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -22,6 +22,7 @@ #include "zenoh-pico/api/primitives.h" #include "zenoh-pico/system/platform.h" +#if Z_FEATURE_SUBSCRIPTION == 1 _z_condvar_t cond; _z_mutex_t mutex; @@ -164,4 +165,10 @@ struct args_t parse_args(int argc, char** argv) { .number_of_pings = number_of_pings, .warmup_ms = warmup_ms, }; -} \ No newline at end of file +} +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\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 53f6d14ee..d7671b38d 100644 --- a/examples/unix/c99/z_pong.c +++ b/examples/unix/c99/z_pong.c @@ -16,6 +16,7 @@ #include "zenoh-pico.h" #include "zenoh-pico/api/primitives.h" +#if Z_FEATURE_SUBSCRIPTION == 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); @@ -70,4 +71,10 @@ int main(int argc, char** argv) { zp_stop_lease_task(z_session_loan(&session)); z_close(z_session_move(&session)); -} \ No newline at end of file +} +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c99/z_pull.c b/examples/unix/c99/z_pull.c index e01f43155..88361ff27 100644 --- a/examples/unix/c99/z_pull.c +++ b/examples/unix/c99/z_pull.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_sample_t *sample, void *ctx) { (void)(ctx); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); @@ -99,3 +100,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c99/z_sub.c b/examples/unix/c99/z_sub.c index 0f616525f..7cb1d2354 100644 --- a/examples/unix/c99/z_sub.c +++ b/examples/unix/c99/z_sub.c @@ -19,6 +19,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_sample_t *sample, void *arg) { (void)(arg); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); @@ -108,3 +109,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/unix/c99/z_sub_st.c b/examples/unix/c99/z_sub_st.c index fac31bd46..37c7d48cc 100644 --- a/examples/unix/c99/z_sub_st.c +++ b/examples/unix/c99/z_sub_st.c @@ -19,6 +19,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_sample_t *sample, void *arg) { (void)(arg); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); @@ -97,3 +98,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION 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 dcfb1fc8e..247b18eb7 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -21,6 +21,7 @@ #include "zenoh-pico.h" #include "zenoh-pico/system/platform.h" +#if Z_FEATURE_SUBSCRIPTION == 1 _z_condvar_t cond; _z_mutex_t mutex; @@ -161,4 +162,10 @@ struct args_t parse_args(int argc, char** argv) { .number_of_pings = number_of_pings, .warmup_ms = warmup_ms, }; -} \ No newline at end of file +} +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\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 698c086f7..a79fb7285 100644 --- a/examples/windows/z_pong.c +++ b/examples/windows/z_pong.c @@ -15,6 +15,7 @@ #include "stdio.h" #include "zenoh-pico.h" +#if Z_FEATURE_SUBSCRIPTION == 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); @@ -67,4 +68,10 @@ int main(int argc, char** argv) { zp_stop_lease_task(z_loan(session)); z_close(z_move(session)); -} \ No newline at end of file +} +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/windows/z_pull.c b/examples/windows/z_pull.c index 52941550e..efaa7676e 100644 --- a/examples/windows/z_pull.c +++ b/examples/windows/z_pull.c @@ -17,6 +17,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_sample_t *sample, void *ctx) { (void)(ctx); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); @@ -78,3 +79,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/windows/z_sub.c b/examples/windows/z_sub.c index d48328500..e46e1fbcb 100644 --- a/examples/windows/z_sub.c +++ b/examples/windows/z_sub.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_sample_t *sample, void *ctx) { (void)(ctx); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); @@ -77,3 +78,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/windows/z_sub_st.c b/examples/windows/z_sub_st.c index d9b66fa80..d34a2d17f 100644 --- a/examples/windows/z_sub_st.c +++ b/examples/windows/z_sub_st.c @@ -18,6 +18,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 void data_handler(const z_sample_t *sample, void *ctx) { (void)(ctx); z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); @@ -66,3 +67,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/zephyr/z_pull.c b/examples/zephyr/z_pull.c index 2d4d7c856..7b3522529 100644 --- a/examples/zephyr/z_pull.c +++ b/examples/zephyr/z_pull.c @@ -15,6 +15,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 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_SUBSCRIPTION but this example requires it.\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/examples/zephyr/z_sub.c b/examples/zephyr/z_sub.c index 3860f9e8a..4f1831154 100644 --- a/examples/zephyr/z_sub.c +++ b/examples/zephyr/z_sub.c @@ -15,6 +15,7 @@ #include #include +#if Z_FEATURE_SUBSCRIPTION == 1 #define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode #if CLIENT_OR_PEER == 0 #define MODE "client" @@ -83,3 +84,9 @@ int main(int argc, char **argv) { return 0; } +#else +int main(void) { + printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION 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 14189c48d..36d4cfb05 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1116,6 +1116,7 @@ int8_t z_publisher_put(const z_publisher_t pub, const uint8_t *payload, size_t l */ 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. * @@ -1237,6 +1238,7 @@ int8_t z_undeclare_pull_subscriber(z_owned_pull_subscriber_t *sub); * Returns ``0`` if the pull operation is successful, or a ``negative value`` otherwise. */ int8_t z_subscriber_pull(const z_pull_subscriber_t sub); +#endif /** * Checks if a given value is valid. diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index f19a94b08..1b8993694 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -132,6 +132,13 @@ #define Z_FEATURE_QUERY 1 #endif +/** + * Enable subscription to this node + */ +#ifndef Z_FEATURE_SUBSCRIPTION +#define Z_FEATURE_SUBSCRIPTION 1 +#endif + /** * Enable TCP links. */ diff --git a/include/zenoh-pico/net/primitives.h b/include/zenoh-pico/net/primitives.h index bfb66ea66..7a8d0b428 100644 --- a/include/zenoh-pico/net/primitives.h +++ b/include/zenoh-pico/net/primitives.h @@ -99,6 +99,7 @@ _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); +#if Z_FEATURE_SUBSCRIPTION == 1 /** * Declare a :c:type:`_z_subscriber_t` for the given resource key. * @@ -128,6 +129,18 @@ _z_subscriber_t *_z_declare_subscriber(_z_session_t *zn, _z_keyexpr_t keyexpr, _ */ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub); +/** + * Pull data for a pull mode :c:type:`_z_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_subscriber_t` to pull from. + * Returns: + * ``0`` in case of success, ``-1`` in case of failure. + */ +int8_t _z_subscriber_pull(const _z_subscriber_t *sub); +#endif + #if Z_FEATURE_QUERYABLE == 1 /** * Declare a :c:type:`_z_queryable_t` for the given resource key. @@ -218,15 +231,4 @@ int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *pay const _z_encoding_t encoding, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, z_priority_t priority); -/** - * Pull data for a pull mode :c:type:`_z_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_subscriber_t` to pull from. - * Returns: - * ``0`` in case of success, ``-1`` in case of failure. - */ -int8_t _z_subscriber_pull(const _z_subscriber_t *sub); - #endif /* ZENOH_PICO_PRIMITIVES_NETAPI_H */ diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index 8985eba02..a93e387ce 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -50,8 +50,10 @@ typedef struct { _z_resource_list_t *_remote_resources; // Session subscriptions +#if Z_FEATURE_SUBSCRIPTION == 1 _z_subscription_sptr_list_t *_local_subscriptions; _z_subscription_sptr_list_t *_remote_subscriptions; +#endif // Session queryables #if Z_FEATURE_QUERYABLE == 1 diff --git a/include/zenoh-pico/net/subscribe.h b/include/zenoh-pico/net/subscribe.h index 2a8a53c1b..d6c3ba67a 100644 --- a/include/zenoh-pico/net/subscribe.h +++ b/include/zenoh-pico/net/subscribe.h @@ -30,6 +30,7 @@ typedef struct { typedef _z_subscriber_t _z_pull_subscriber_t; +#if Z_FEATURE_SUBSCRIPTION == 1 /** * Create a default subscription info for a push subscriber. * @@ -48,5 +49,6 @@ _z_subinfo_t _z_subinfo_pull_default(void); void _z_subscriber_clear(_z_subscriber_t *sub); void _z_subscriber_free(_z_subscriber_t **sub); +#endif #endif /* ZENOH_PICO_SUBSCRIBE_NETAPI_H */ diff --git a/include/zenoh-pico/session/subscription.h b/include/zenoh-pico/session/subscription.h index d352f3a6a..a05de96d9 100644 --- a/include/zenoh-pico/session/subscription.h +++ b/include/zenoh-pico/session/subscription.h @@ -17,6 +17,7 @@ #include "zenoh-pico/net/session.h" +#if Z_FEATURE_SUBSCRIPTION == 1 /*------------------ Subscription ------------------*/ _z_subscription_sptr_t *_z_get_subscription_by_id(_z_session_t *zn, uint8_t is_local, const _z_zint_t id); _z_subscription_sptr_list_t *_z_get_subscriptions_by_key(_z_session_t *zn, uint8_t is_local, @@ -30,5 +31,6 @@ void _z_flush_subscriptions(_z_session_t *zn); /*------------------ Pull ------------------*/ _z_zint_t _z_get_pull_id(_z_session_t *zn); +#endif #endif /* ZENOH_PICO_SESSION_SUBSCRIPTION_H */ diff --git a/src/api/api.c b/src/api/api.c index 6ba0705d3..d02b0a036 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -409,14 +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_subscriber_t, z_owned_subscriber_t, subscriber) -OWNED_FUNCTIONS_PTR_CLONE(z_subscriber_t, z_owned_subscriber_t, subscriber, _z_owner_noop_copy) -void z_subscriber_drop(z_owned_subscriber_t *val) { z_undeclare_subscriber(val); } - -OWNED_FUNCTIONS_PTR_COMMON(z_pull_subscriber_t, z_owned_pull_subscriber_t, pull_subscriber) -OWNED_FUNCTIONS_PTR_CLONE(z_pull_subscriber_t, z_owned_pull_subscriber_t, pull_subscriber, _z_owner_noop_copy) -void z_pull_subscriber_drop(z_owned_pull_subscriber_t *val) { z_undeclare_pull_subscriber(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); } @@ -878,6 +870,15 @@ int8_t z_publisher_delete(const z_publisher_t pub, const z_publisher_delete_opti 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) +void z_subscriber_drop(z_owned_subscriber_t *val) { z_undeclare_subscriber(val); } + +OWNED_FUNCTIONS_PTR_COMMON(z_pull_subscriber_t, z_owned_pull_subscriber_t, pull_subscriber) +OWNED_FUNCTIONS_PTR_CLONE(z_pull_subscriber_t, z_owned_pull_subscriber_t, pull_subscriber, _z_owner_noop_copy) +void z_pull_subscriber_drop(z_owned_pull_subscriber_t *val) { z_undeclare_pull_subscriber(val); } + z_subscriber_options_t z_subscriber_options_default(void) { return (z_subscriber_options_t){.reliability = Z_RELIABILITY_DEFAULT}; } @@ -981,6 +982,29 @@ int8_t z_undeclare_pull_subscriber(z_owned_pull_subscriber_t *sub) { int8_t z_subscriber_pull(const z_pull_subscriber_t sub) { return _z_subscriber_pull(sub._val); } +z_owned_keyexpr_t z_subscriber_keyexpr(z_subscriber_t sub) { + z_owned_keyexpr_t ret = z_keyexpr_null(); + uint32_t lookup = sub._val->_entity_id; + if (sub._val != NULL) { + _z_subscription_sptr_list_t *tail = sub._val->_zn->_local_subscriptions; + while (tail != NULL && !z_keyexpr_check(&ret)) { + _z_subscription_sptr_t *head = _z_subscription_sptr_list_head(tail); + if (head->ptr->_id == lookup) { + _z_keyexpr_t key = _z_keyexpr_duplicate(head->ptr->_key); + ret = (z_owned_keyexpr_t){._value = z_malloc(sizeof(_z_keyexpr_t))}; + if (ret._value != NULL) { + *ret._value = key; + } else { + _z_keyexpr_clear(&key); + } + } + tail = _z_subscription_sptr_list_tail(tail); + } + } + return ret; +} +#endif + /**************** Tasks ****************/ zp_task_read_options_t zp_task_read_options_default(void) { return (zp_task_read_options_t){.__dummy = 0}; } @@ -1053,26 +1077,4 @@ z_owned_keyexpr_t z_publisher_keyexpr(z_publisher_t publisher) { *ret._value = _z_keyexpr_duplicate(publisher._val->_key); } return ret; -} - -z_owned_keyexpr_t z_subscriber_keyexpr(z_subscriber_t sub) { - z_owned_keyexpr_t ret = z_keyexpr_null(); - uint32_t lookup = sub._val->_entity_id; - if (sub._val != NULL) { - _z_subscription_sptr_list_t *tail = sub._val->_zn->_local_subscriptions; - while (tail != NULL && !z_keyexpr_check(&ret)) { - _z_subscription_sptr_t *head = _z_subscription_sptr_list_head(tail); - if (head->ptr->_id == lookup) { - _z_keyexpr_t key = _z_keyexpr_duplicate(head->ptr->_key); - ret = (z_owned_keyexpr_t){._value = z_malloc(sizeof(_z_keyexpr_t))}; - if (ret._value != NULL) { - *ret._value = key; - } else { - _z_keyexpr_clear(&key); - } - } - tail = _z_subscription_sptr_list_tail(tail); - } - } - return ret; -} +} \ No newline at end of file diff --git a/src/net/primitives.c b/src/net/primitives.c index 6263d7499..3a4087719 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -124,6 +124,7 @@ int8_t _z_undeclare_publisher(_z_publisher_t *pub) { return ret; } +#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, _z_data_handler_t callback, _z_drop_handler_t dropper, void *arg) { @@ -192,6 +193,25 @@ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub) { return ret; } +/*------------------ Pull ------------------*/ +int8_t _z_subscriber_pull(const _z_subscriber_t *sub) { + int8_t ret = _Z_RES_OK; + + _z_subscription_sptr_t *s = _z_get_subscription_by_id(sub->_zn, _Z_RESOURCE_IS_LOCAL, sub->_entity_id); + if (s != NULL) { + _z_zint_t pull_id = _z_get_pull_id(sub->_zn); + _z_zenoh_message_t z_msg = _z_msg_make_pull(_z_keyexpr_alias(s->ptr->_key), pull_id); + if (_z_send_n_msg(sub->_zn, &z_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) { + ret = _Z_ERR_TRANSPORT_TX_FAILED; + } + } else { + ret = _Z_ERR_ENTITY_UNKNOWN; + } + + return ret; +} +#endif + #if Z_FEATURE_QUERYABLE == 1 /*------------------ Queryable Declaration ------------------*/ _z_queryable_t *_z_declare_queryable(_z_session_t *zn, _z_keyexpr_t keyexpr, _Bool complete, @@ -395,22 +415,4 @@ int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const uint8_t *pay // Freeing z_msg is unnecessary, as all of its components are aliased return ret; -} - -/*------------------ Pull ------------------*/ -int8_t _z_subscriber_pull(const _z_subscriber_t *sub) { - int8_t ret = _Z_RES_OK; - - _z_subscription_sptr_t *s = _z_get_subscription_by_id(sub->_zn, _Z_RESOURCE_IS_LOCAL, sub->_entity_id); - if (s != NULL) { - _z_zint_t pull_id = _z_get_pull_id(sub->_zn); - _z_zenoh_message_t z_msg = _z_msg_make_pull(_z_keyexpr_alias(s->ptr->_key), pull_id); - if (_z_send_n_msg(sub->_zn, &z_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) { - ret = _Z_ERR_TRANSPORT_TX_FAILED; - } - } else { - ret = _Z_ERR_ENTITY_UNKNOWN; - } - - return ret; -} +} \ No newline at end of file diff --git a/src/net/subscribe.c b/src/net/subscribe.c index 97d0cf3ef..27e2ffe7c 100644 --- a/src/net/subscribe.c +++ b/src/net/subscribe.c @@ -13,6 +13,7 @@ #include "zenoh-pico/net/subscribe.h" +#if Z_FEATURE_SUBSCRIPTION == 1 _z_subinfo_t _z_subinfo_push_default(void) { _z_subinfo_t si; si.reliability = Z_RELIABILITY_RELIABLE; @@ -44,3 +45,4 @@ void _z_subscriber_free(_z_subscriber_t **sub) { *sub = NULL; } } +#endif \ No newline at end of file diff --git a/src/session/push.c b/src/session/push.c index 5e0649983..0028d4a83 100644 --- a/src/session/push.c +++ b/src/session/push.c @@ -28,8 +28,8 @@ int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push) { _z_bytes_t payload = push->_body._is_put ? push->_body._body._put._payload : _z_bytes_empty(); _z_encoding_t encoding = push->_body._is_put ? push->_body._body._put._encoding : z_encoding_default(); int kind = push->_body._is_put ? Z_SAMPLE_KIND_PUT : Z_SAMPLE_KIND_DELETE; - +#if Z_FEATURE_SUBSCRIPTION == 1 ret = _z_trigger_subscriptions(zn, push->_key, payload, encoding, kind, push->_timestamp); - +#endif return ret; } \ No newline at end of file diff --git a/src/session/rx.c b/src/session/rx.c index d9e17587b..28d225827 100644 --- a/src/session/rx.c +++ b/src/session/rx.c @@ -99,8 +99,10 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint } break; case _Z_REQUEST_PUT: { _z_msg_put_t put = req._body._put; +#if Z_FEATURE_SUBSCRIPTION == 1 ret = _z_trigger_subscriptions(zn, req._key, put._payload, put._encoding, Z_SAMPLE_KIND_PUT, put._commons._timestamp); +#endif if (ret == _Z_RES_OK) { _z_network_message_t ack = _z_n_msg_make_ack(req._rid, &req._key); ret = _z_send_n_msg(zn, &ack, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK); @@ -110,8 +112,10 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint } break; case _Z_REQUEST_DEL: { _z_msg_del_t del = req._body._del; +#if Z_FEATURE_SUBSCRIPTION == 1 ret = _z_trigger_subscriptions(zn, req._key, _z_bytes_empty(), z_encoding_default(), Z_SAMPLE_KIND_DELETE, del._commons._timestamp); +#endif if (ret == _Z_RES_OK) { _z_network_message_t ack = _z_n_msg_make_ack(req._rid, &req._key); ret = _z_send_n_msg(zn, &ack, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK); @@ -144,13 +148,17 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint } break; case _Z_RESPONSE_BODY_PUT: { _z_msg_put_t put = response._body._put; +#if Z_FEATURE_SUBSCRIPTION == 1 ret = _z_trigger_subscriptions(zn, response._key, put._payload, put._encoding, Z_SAMPLE_KIND_PUT, put._commons._timestamp); +#endif } break; case _Z_RESPONSE_BODY_DEL: { _z_msg_del_t del = response._body._del; +#if Z_FEATURE_SUBSCRIPTION == 1 ret = _z_trigger_subscriptions(zn, response._key, _z_bytes_empty(), z_encoding_default(), Z_SAMPLE_KIND_DELETE, del._commons._timestamp); +#endif } break; } } break; diff --git a/src/session/subscription.c b/src/session/subscription.c index e3e0833f3..fbb52e6b0 100644 --- a/src/session/subscription.c +++ b/src/session/subscription.c @@ -24,6 +24,7 @@ #include "zenoh-pico/session/session.h" #include "zenoh-pico/utils/logging.h" +#if Z_FEATURE_SUBSCRIPTION == 1 _Bool _z_subscription_eq(const _z_subscription_t *other, const _z_subscription_t *this) { return this->_id == other->_id; } @@ -226,3 +227,4 @@ void _z_flush_subscriptions(_z_session_t *zn) { _z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } +#endif \ No newline at end of file diff --git a/src/session/utils.c b/src/session/utils.c index 8f80c260c..b43104f25 100644 --- a/src/session/utils.c +++ b/src/session/utils.c @@ -61,8 +61,10 @@ int8_t _z_session_init(_z_session_t *zn, _z_id_t *zid) { // Initialize the data structs zn->_local_resources = NULL; zn->_remote_resources = NULL; +#if Z_FEATURE_SUBSCRIPTION == 1 zn->_local_subscriptions = NULL; zn->_remote_subscriptions = NULL; +#endif #if Z_FEATURE_QUERYABLE == 1 zn->_local_questionable = NULL; #endif @@ -103,8 +105,9 @@ void _z_session_clear(_z_session_t *zn) { // Clean up the entities _z_flush_resources(zn); +#if Z_FEATURE_SUBSCRIPTION == 1 _z_flush_subscriptions(zn); - +#endif #if Z_FEATURE_QUERYABLE == 1 _z_flush_questionables(zn); #endif diff --git a/tests/z_api_null_drop_test.c b/tests/z_api_null_drop_test.c index 6d54fea94..979280900 100644 --- a/tests/z_api_null_drop_test.c +++ b/tests/z_api_null_drop_test.c @@ -29,8 +29,6 @@ int main(void) { 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_hello_t hello_null_1 = z_hello_null(); z_owned_closure_sample_t closure_sample_null_1 = z_closure_sample_null(); z_owned_closure_query_t closure_query_null_1 = z_closure_query_null(); @@ -47,8 +45,6 @@ int main(void) { 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(hello_null_1)); assert(!z_check(str_null_1)); @@ -60,8 +56,6 @@ int main(void) { 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_hello_t hello_null_2; z_owned_closure_sample_t closure_sample_null_2; z_owned_closure_query_t closure_query_null_2; @@ -75,8 +69,6 @@ int main(void) { 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(&hello_null_2); z_null(&closure_sample_null_2); z_null(&closure_query_null_2); @@ -85,6 +77,18 @@ int main(void) { z_null(&closure_zid_null_2); z_null(&str_null_2); +#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(); + assert(!z_check(pull_subscriber_null_1)); + assert(!z_check(subscriber_null_1)); + z_owned_pull_subscriber_t pull_subscriber_null_2; + z_owned_subscriber_t subscriber_null_2; + z_null(&pull_subscriber_null_2); + z_null(&subscriber_null_2); + assert(!z_check(pull_subscriber_null_2)); + assert(!z_check(subscriber_null_2)); +#endif #if Z_FEATURE_QUERYABLE == 1 z_owned_queryable_t queryable_null_1 = z_queryable_null(); assert(!z_check(queryable_null_1)); @@ -108,8 +112,6 @@ int main(void) { 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(hello_null_2)); assert(!z_check(str_null_2)); @@ -122,8 +124,6 @@ int main(void) { 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(hello_null_1)); z_drop(z_move(closure_sample_null_1)); z_drop(z_move(closure_query_null_1)); @@ -137,8 +137,6 @@ int main(void) { 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(hello_null_2)); z_drop(z_move(closure_sample_null_2)); z_drop(z_move(closure_query_null_2)); @@ -147,6 +145,12 @@ int main(void) { z_drop(z_move(closure_zid_null_2)); z_drop(z_move(str_null_2)); +#if Z_FEATURE_SUBSCRIPTION == 1 + z_drop(z_move(pull_subscriber_null_1)); + z_drop(z_move(subscriber_null_1)); + z_drop(z_move(pull_subscriber_null_2)); + z_drop(z_move(subscriber_null_2)); +#endif #if Z_FEATURE_QUERYABLE == 1 z_drop(z_move(queryable_null_1)); z_drop(z_move(queryable_null_2)); From 5bd1370c4c9c74a7f58934b41ba97f2b6f8627c0 Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Mon, 23 Oct 2023 17:26:06 +0200 Subject: [PATCH 25/26] 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)); From 995f0821283aa9adf7cf56f754a3b2efc8582f4b Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Thu, 26 Oct 2023 14:25:38 +0200 Subject: [PATCH 26/26] Measure wall time in ping tests (#269) --- examples/unix/c11/z_ping.c | 36 ++++++++++++++++++------------- examples/unix/c99/z_ping.c | 36 ++++++++++++++++++------------- examples/windows/z_ping.c | 36 ++++++++++++++++++------------- src/system/arduino/esp32/system.c | 8 +++---- src/system/espidf/system.c | 8 +++---- src/system/unix/system.c | 8 +++---- src/system/zephyr/system.c | 8 +++---- 7 files changed, 79 insertions(+), 61 deletions(-) diff --git a/examples/unix/c11/z_ping.c b/examples/unix/c11/z_ping.c index d3853d475..af13efb2a 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -22,6 +22,11 @@ #include "zenoh-pico/system/platform.h" #if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 + +#define DEFAULT_PKT_SIZE 8 +#define DEFAULT_PING_NB 100 +#define DEFAULT_WARMUP_MS 1000 + // 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; @@ -50,11 +55,12 @@ int main(int argc, char** argv) { if (args.help_requested) { printf( "\ - -n (optional, int, default=4): the number of pings to be attempted\n\ - -s (optional, int, default=8): the size of the payload embedded in the ping and repeated by the pong\n\ - -w (optional, int, default=0): the warmup time in ms during which pings will be emitted but not measured\n\ + -n (optional, int, default=%d): the number of pings to be attempted\n\ + -s (optional, int, default=%d): the size of the payload embedded in the ping and repeated by the pong\n\ + -w (optional, int, default=%d): the warmup time in ms during which pings will be emitted but not measured\n\ -c (optional, string): the path to a configuration file for the session. If this option isn't passed, the default configuration will be used.\n\ - "); + ", + DEFAULT_PKT_SIZE, DEFAULT_PING_NB, DEFAULT_WARMUP_MS); return 1; } _z_mutex_init(&mutex); @@ -94,23 +100,23 @@ int main(int argc, char** argv) { _z_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); - clock_t warmup_end = clock() + CLOCKS_PER_SEC * args.warmup_ms / 1000; - for (clock_t now = clock(); now < warmup_end; now = clock()) { + z_clock_t warmup_start = z_clock_now(); + unsigned long elapsed_us = 0; + while (elapsed_us < args.warmup_ms * 1000) { z_publisher_put(z_loan(pub), data, args.size, NULL); _z_condvar_wait(&cond, &mutex); + elapsed_us = z_clock_elapsed_us(&warmup_start); } } - clock_t* results = z_malloc(sizeof(clock_t) * args.number_of_pings); + unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings); for (unsigned int i = 0; i < args.number_of_pings; i++) { - clock_t start = clock(); + z_clock_t measure_start = z_clock_now(); z_publisher_put(z_loan(pub), data, args.size, NULL); _z_condvar_wait(&cond, &mutex); - clock_t end = clock(); - results[i] = end - start; + results[i] = z_clock_elapsed_us(&measure_start); } for (unsigned int i = 0; i < args.number_of_pings; i++) { - clock_t rtt = results[i] * 1000000 / CLOCKS_PER_SEC; - printf("%d bytes: seq=%d rtt=%ldµs lat=%ldµs\n", args.size, i, rtt, rtt / 2); + printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2); } _z_mutex_unlock(&mutex); z_free(results); @@ -145,17 +151,17 @@ struct args_t parse_args(int argc, char** argv) { } } char* arg = getopt(argc, argv, 's'); - unsigned int size = 8; + unsigned int size = DEFAULT_PKT_SIZE; if (arg) { size = atoi(arg); } arg = getopt(argc, argv, 'n'); - unsigned int number_of_pings = 4; + unsigned int number_of_pings = DEFAULT_PING_NB; if (arg) { number_of_pings = atoi(arg); } arg = getopt(argc, argv, 'w'); - unsigned int warmup_ms = 0; + unsigned int warmup_ms = DEFAULT_WARMUP_MS; if (arg) { warmup_ms = atoi(arg); } diff --git a/examples/unix/c99/z_ping.c b/examples/unix/c99/z_ping.c index 451a8fc30..94fe42424 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -23,6 +23,11 @@ #include "zenoh-pico/system/platform.h" #if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 + +#define DEFAULT_PKT_SIZE 8 +#define DEFAULT_PING_NB 100 +#define DEFAULT_WARMUP_MS 1000 + _z_condvar_t cond; _z_mutex_t mutex; @@ -49,11 +54,12 @@ int main(int argc, char** argv) { if (args.help_requested) { printf( "\ - -n (optional, int, default=4): the number of pings to be attempted\n\ - -s (optional, int, default=8): the size of the payload embedded in the ping and repeated by the pong\n\ - -w (optional, int, default=0): the warmup time in ms during which pings will be emitted but not measured\n\ + -n (optional, int, default=%d): the number of pings to be attempted\n\ + -s (optional, int, default=%d): the size of the payload embedded in the ping and repeated by the pong\n\ + -w (optional, int, default=%d): the warmup time in ms during which pings will be emitted but not measured\n\ -c (optional, string): the path to a configuration file for the session. If this option isn't passed, the default configuration will be used.\n\ - "); + ", + DEFAULT_PKT_SIZE, DEFAULT_PING_NB, DEFAULT_WARMUP_MS); return 1; } _z_mutex_init(&mutex); @@ -94,23 +100,23 @@ int main(int argc, char** argv) { _z_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); - clock_t warmup_end = clock() + CLOCKS_PER_SEC * args.warmup_ms / 1000; - for (clock_t now = clock(); now < warmup_end; now = clock()) { + z_clock_t warmup_start = z_clock_now(); + unsigned long elapsed_us = 0; + while (elapsed_us < args.warmup_ms * 1000) { z_publisher_put(z_publisher_loan(&pub), data, args.size, NULL); _z_condvar_wait(&cond, &mutex); + elapsed_us = z_clock_elapsed_us(&warmup_start); } } - clock_t* results = z_malloc(sizeof(clock_t) * args.number_of_pings); + unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings); for (unsigned int i = 0; i < args.number_of_pings; i++) { - clock_t start = clock(); + z_clock_t measure_start = z_clock_now(); z_publisher_put(z_publisher_loan(&pub), data, args.size, NULL); _z_condvar_wait(&cond, &mutex); - clock_t end = clock(); - results[i] = end - start; + results[i] = z_clock_elapsed_us(&measure_start); } for (unsigned int i = 0; i < args.number_of_pings; i++) { - clock_t rtt = results[i] * 1000000 / CLOCKS_PER_SEC; - printf("%d bytes: seq=%d rtt=%ldµs lat=%ldµs\n", args.size, i, rtt, rtt / 2); + printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2); } _z_mutex_unlock(&mutex); z_free(results); @@ -145,17 +151,17 @@ struct args_t parse_args(int argc, char** argv) { } } char* arg = getopt(argc, argv, 's'); - unsigned int size = 8; + unsigned int size = DEFAULT_PKT_SIZE; if (arg) { size = atoi(arg); } arg = getopt(argc, argv, 'n'); - unsigned int number_of_pings = 4; + unsigned int number_of_pings = DEFAULT_PING_NB; if (arg) { number_of_pings = atoi(arg); } arg = getopt(argc, argv, 'w'); - unsigned int warmup_ms = 0; + unsigned int warmup_ms = DEFAULT_WARMUP_MS; if (arg) { warmup_ms = atoi(arg); } diff --git a/examples/windows/z_ping.c b/examples/windows/z_ping.c index da6cb75db..f1a218386 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -22,6 +22,11 @@ #include "zenoh-pico/system/platform.h" #if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 + +#define DEFAULT_PKT_SIZE 8 +#define DEFAULT_PING_NB 100 +#define DEFAULT_WARMUP_MS 1000 + _z_condvar_t cond; _z_mutex_t mutex; @@ -48,11 +53,12 @@ int main(int argc, char** argv) { if (args.help_requested) { printf( "\ - -n (optional, int, default=4): the number of pings to be attempted\n\ - -s (optional, int, default=8): the size of the payload embedded in the ping and repeated by the pong\n\ - -w (optional, int, default=0): the warmup time in ms during which pings will be emitted but not measured\n\ + -n (optional, int, default=%d): the number of pings to be attempted\n\ + -s (optional, int, default=%d): the size of the payload embedded in the ping and repeated by the pong\n\ + -w (optional, int, default=%d): the warmup time in ms during which pings will be emitted but not measured\n\ -c (optional, string): the path to a configuration file for the session. If this option isn't passed, the default configuration will be used.\n\ - "); + ", + DEFAULT_PKT_SIZE, DEFAULT_PING_NB, DEFAULT_WARMUP_MS); return 1; } _z_mutex_init(&mutex); @@ -91,23 +97,23 @@ int main(int argc, char** argv) { _z_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); - clock_t warmup_end = clock() + CLOCKS_PER_SEC * args.warmup_ms / 1000; - for (clock_t now = clock(); now < warmup_end; now = clock()) { + z_clock_t warmup_start = z_clock_now(); + unsigned long elapsed_us = 0; + while (elapsed_us < args.warmup_ms * 1000) { z_publisher_put(z_loan(pub), data, args.size, NULL); _z_condvar_wait(&cond, &mutex); + elapsed_us = z_clock_elapsed_us(&warmup_start); } } - clock_t* results = z_malloc(sizeof(clock_t) * args.number_of_pings); + unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings); for (unsigned int i = 0; i < args.number_of_pings; i++) { - clock_t start = clock(); + z_clock_t measure_start = z_clock_now(); z_publisher_put(z_loan(pub), data, args.size, NULL); _z_condvar_wait(&cond, &mutex); - clock_t end = clock(); - results[i] = end - start; + results[i] = z_clock_elapsed_us(&measure_start); } for (unsigned int i = 0; i < args.number_of_pings; i++) { - clock_t rtt = results[i] * 1000000 / CLOCKS_PER_SEC; - printf("%d bytes: seq=%d rtt=%ldµs lat=%ldµs\n", args.size, i, rtt, rtt / 2); + printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2); } _z_mutex_unlock(&mutex); z_free(results); @@ -142,17 +148,17 @@ struct args_t parse_args(int argc, char** argv) { } } char* arg = getopt(argc, argv, 's'); - unsigned int size = 8; + unsigned int size = DEFAULT_PKT_SIZE; if (arg) { size = atoi(arg); } arg = getopt(argc, argv, 'n'); - unsigned int number_of_pings = 4; + unsigned int number_of_pings = DEFAULT_PING_NB; if (arg) { number_of_pings = atoi(arg); } arg = getopt(argc, argv, 'w'); - unsigned int warmup_ms = 0; + unsigned int warmup_ms = DEFAULT_WARMUP_MS; if (arg) { warmup_ms = atoi(arg); } diff --git a/src/system/arduino/esp32/system.c b/src/system/arduino/esp32/system.c index a9eab813c..8f0773751 100644 --- a/src/system/arduino/esp32/system.c +++ b/src/system/arduino/esp32/system.c @@ -135,13 +135,13 @@ int z_sleep_s(size_t time) { return sleep(time); } /*------------------ Instant ------------------*/ z_clock_t z_clock_now(void) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); return now; } unsigned long z_clock_elapsed_us(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; @@ -149,7 +149,7 @@ unsigned long z_clock_elapsed_us(z_clock_t *instant) { unsigned long z_clock_elapsed_ms(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; @@ -157,7 +157,7 @@ unsigned long z_clock_elapsed_ms(z_clock_t *instant) { unsigned long z_clock_elapsed_s(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; return elapsed; diff --git a/src/system/espidf/system.c b/src/system/espidf/system.c index 8a655cf0d..a93c5b0e5 100644 --- a/src/system/espidf/system.c +++ b/src/system/espidf/system.c @@ -136,13 +136,13 @@ int z_sleep_s(size_t time) { return sleep(time); } /*------------------ Instant ------------------*/ z_clock_t z_clock_now(void) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); return now; } unsigned long z_clock_elapsed_us(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; @@ -150,7 +150,7 @@ unsigned long z_clock_elapsed_us(z_clock_t *instant) { unsigned long z_clock_elapsed_ms(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; @@ -158,7 +158,7 @@ unsigned long z_clock_elapsed_ms(z_clock_t *instant) { unsigned long z_clock_elapsed_s(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; return elapsed; diff --git a/src/system/unix/system.c b/src/system/unix/system.c index 875bc5f2b..990619dac 100644 --- a/src/system/unix/system.c +++ b/src/system/unix/system.c @@ -156,13 +156,13 @@ int z_sleep_s(size_t time) { return sleep(time); } /*------------------ Instant ------------------*/ z_clock_t z_clock_now(void) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); return now; } unsigned long z_clock_elapsed_us(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; @@ -170,7 +170,7 @@ unsigned long z_clock_elapsed_us(z_clock_t *instant) { unsigned long z_clock_elapsed_ms(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; @@ -178,7 +178,7 @@ unsigned long z_clock_elapsed_ms(z_clock_t *instant) { unsigned long z_clock_elapsed_s(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; return elapsed; diff --git a/src/system/zephyr/system.c b/src/system/zephyr/system.c index 28ce1d303..20e54d146 100644 --- a/src/system/zephyr/system.c +++ b/src/system/zephyr/system.c @@ -150,13 +150,13 @@ int z_sleep_s(size_t time) { /*------------------ Instant ------------------*/ z_clock_t z_clock_now(void) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); return now; } unsigned long z_clock_elapsed_us(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; @@ -164,7 +164,7 @@ unsigned long z_clock_elapsed_us(z_clock_t *instant) { unsigned long z_clock_elapsed_ms(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; @@ -172,7 +172,7 @@ unsigned long z_clock_elapsed_ms(z_clock_t *instant) { unsigned long z_clock_elapsed_s(z_clock_t *instant) { z_clock_t now; - clock_gettime(CLOCK_REALTIME, &now); + clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; return elapsed;