diff --git a/docs/api.rst b/docs/api.rst index 35323dae5..b78f52968 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -396,6 +396,7 @@ Primitives .. autocfunction:: primitives.h::z_hello_zid .. autocfunction:: primitives.h::z_hello_whatami .. autocfunction:: primitives.h::z_hello_locators +.. autocfunction:: primitives.h::zp_hello_locators .. autocfunction:: primitives.h::z_whatami_to_view_string .. autocfunction:: primitives.h::z_scout .. autocfunction:: primitives.h::z_open diff --git a/examples/arduino/z_scout.ino b/examples/arduino/z_scout.ino index 17d033100..b8306c362 100644 --- a/examples/arduino/z_scout.ino +++ b/examples/arduino/z_scout.ino @@ -71,7 +71,7 @@ void fprinthello(const z_loaned_hello_t *hello) { Serial.print(", whatami: "); fprintwhatami(z_hello_whatami(hello)); Serial.print(", locators: "); - fprintlocators(z_hello_locators(hello)); + fprintlocators(zp_hello_locators(hello)); Serial.println(" }"); } diff --git a/examples/espidf/z_scout.c b/examples/espidf/z_scout.c index a8adc731d..d429a78ad 100644 --- a/examples/espidf/z_scout.c +++ b/examples/espidf/z_scout.c @@ -125,7 +125,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, ", whatami: "); fprintwhatami(stream, z_hello_whatami(hello)); fprintf(stream, ", locators: "); - fprintlocators(stream, z_hello_locators(hello)); + fprintlocators(stream, zp_hello_locators(hello)); fprintf(stream, " }"); } diff --git a/examples/freertos_plus_tcp/z_scout.c b/examples/freertos_plus_tcp/z_scout.c index 5a5e45c65..bff7ebc50 100644 --- a/examples/freertos_plus_tcp/z_scout.c +++ b/examples/freertos_plus_tcp/z_scout.c @@ -59,7 +59,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, ", whatami: "); fprintwhatami(stream, z_hello_whatami(hello)); fprintf(stream, ", locators: "); - fprintlocators(stream, z_hello_locators(hello)); + fprintlocators(stream, zp_hello_locators(hello)); fprintf(stream, " }"); } diff --git a/examples/mbed/z_scout.cpp b/examples/mbed/z_scout.cpp index 2d9f71b69..de55be05c 100644 --- a/examples/mbed/z_scout.cpp +++ b/examples/mbed/z_scout.cpp @@ -67,7 +67,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, ", whatami: "); fprintwhatami(stream, z_hello_whatami(hello)); fprintf(stream, ", locators: "); - fprintlocators(stream, z_hello_locators(hello)); + fprintlocators(stream, zp_hello_locators(hello)); fprintf(stream, " }"); } diff --git a/examples/unix/c11/z_scout.c b/examples/unix/c11/z_scout.c index 4324a966a..41ce814e0 100644 --- a/examples/unix/c11/z_scout.c +++ b/examples/unix/c11/z_scout.c @@ -57,7 +57,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, ", whatami: "); fprintwhatami(stream, z_hello_whatami(hello)); fprintf(stream, ", locators: "); - fprintlocators(stream, z_hello_locators(hello)); + fprintlocators(stream, zp_hello_locators(hello)); fprintf(stream, " }"); } diff --git a/examples/unix/c99/z_scout.c b/examples/unix/c99/z_scout.c index 412bb73b2..fa625e548 100644 --- a/examples/unix/c99/z_scout.c +++ b/examples/unix/c99/z_scout.c @@ -56,7 +56,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, ", whatami: "); fprintwhatami(stream, z_hello_whatami(hello)); fprintf(stream, ", locators: "); - fprintlocators(stream, z_hello_locators(hello)); + fprintlocators(stream, zp_hello_locators(hello)); fprintf(stream, " }"); } diff --git a/examples/windows/z_scout.c b/examples/windows/z_scout.c index b8de576be..321900480 100644 --- a/examples/windows/z_scout.c +++ b/examples/windows/z_scout.c @@ -56,7 +56,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, ", whatami: "); fprintwhatami(stream, z_hello_whatami(hello)); fprintf(stream, ", locators: "); - fprintlocators(stream, z_hello_locators(hello)); + fprintlocators(stream, zp_hello_locators(hello)); fprintf(stream, " }"); } diff --git a/examples/zephyr/z_scout.c b/examples/zephyr/z_scout.c index 1ae6b9be0..5da870042 100644 --- a/examples/zephyr/z_scout.c +++ b/examples/zephyr/z_scout.c @@ -53,7 +53,7 @@ void fprinthello(FILE *stream, const z_loaned_hello_t *hello) { fprintf(stream, ", whatami: "); fprintwhatami(stream, z_hello_whatami(hello)); fprintf(stream, ", locators: "); - fprintlocators(stream, z_hello_locators(hello)); + fprintlocators(stream, zp_hello_locators(hello)); fprintf(stream, " }"); } diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 0bf48e9c8..f815f5c93 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1479,14 +1479,25 @@ z_id_t z_hello_zid(const z_loaned_hello_t *hello); z_whatami_t z_hello_whatami(const z_loaned_hello_t *hello); /** - * Constructs an array of locators of Zenoh entity that sent hello message. + * Returns an array of locators of Zenoh entity that sent hello message. * * Parameters: * hello: Pointer to a :c:type:`z_loaned_hello_t` message. * Return: * :c:type:`z_loaned_string_array_t` containing locators. */ -const z_loaned_string_array_t *z_hello_locators(const z_loaned_hello_t *hello); +const z_loaned_string_array_t *zp_hello_locators(const z_loaned_hello_t *hello); + +/** + * Constructs an array of locators of Zenoh entity that sent hello message. + * Note that it is a method for zenoh-c compatiblity, in zenoh-pico :c:func:`zp_hello_locators` + * can be used. + * + * Parameters: + * hello: Pointer to a :c:type:`z_loaned_hello_t` message. + * locators_out: An uninitialized memory location where :c:type:`z_owned_string_array_t` will be constructed. + */ +void z_hello_locators(const z_loaned_hello_t *hello, z_owned_string_array_t *locators_out); /** * Constructs a non-owned non-null-terminated string from the kind of zenoh entity. diff --git a/src/api/api.c b/src/api/api.c index 2897c103d..8d5afb655 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -790,7 +790,11 @@ z_id_t z_hello_zid(const z_loaned_hello_t *hello) { return hello->_zid; } z_whatami_t z_hello_whatami(const z_loaned_hello_t *hello) { return hello->_whatami; } -const z_loaned_string_array_t *z_hello_locators(const z_loaned_hello_t *hello) { return &hello->_locators; } +const z_loaned_string_array_t *zp_hello_locators(const z_loaned_hello_t *hello) { return &hello->_locators; } + +void z_hello_locators(const z_loaned_hello_t *hello, z_owned_string_array_t *locators_out) { + z_string_array_clone(locators_out, &hello->_locators); +} static const char *WHAT_AM_I_TO_STRING_MAP[8] = { "Other", // 0