Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Jun 24, 2024
1 parent eaff4a2 commit 99abc68
Show file tree
Hide file tree
Showing 110 changed files with 1,334 additions and 968 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
uses: eclipse-zenoh/ci/build-crates-standalone@main
with:
repo: eclipse-zenoh/zenoh
branch: interests
branch: dev/1.0.0
artifact-patterns: |
^zenohd$
^libzenoh_plugin_rest.so$
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
BUILD_TESTING: OFF # Workaround for Windows as it seems the previous step is being ignored
BUILD_MULTICAST: OFF # Workaround for Windows as it seems the previous step is being ignored
BUILD_INTEGRATION: ON # Workaround for Windows as it seems the previous step is being ignored
ZENOH_BRANCH: interests
ZENOH_BRANCH: dev/1.0.0
2 changes: 1 addition & 1 deletion .github/workflows/multicast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
BUILD_TESTING: OFF
BUILD_MULTICAST: ON
BUILD_INTEGRATION: OFF
ZENOH_BRANCH: interests
ZENOH_BRANCH: dev/1.0.0

- name: Test debug
run: make test
Expand Down
73 changes: 39 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
endif()
endif()

# Language options
if(NOT CMAKE_C_STANDARD)
if(c_std_11 IN_LIST CMAKE_C_COMPILE_FEATURES)
set(CMAKE_C_STANDARD 11)
message(STATUS "Setting C11 as the C Standard")
else()
# C99 pedantic doesn't like unix header anonymous structure
set(CMAKE_C_STANDARD 99)
message(STATUS "Setting C99 as the C Standard")
endif()
endif()
set(CMAKE_C_STANDARD_REQUIRED TRUE)

# Compile options
if(CMAKE_BUILD_TYPE MATCHES "RELEASE" OR "Release")
if(UNIX)
add_compile_options(-pipe -O3)
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
add_compile_options(-pipe -O3)
endif()
else()
if(UNIX)
add_compile_options(-c -Wall -Wextra -Werror -Wshadow -Wunused -Wstrict-prototypes -pipe -g -O0)
# C99 pedantic doesn't like struct anonymous in unix header
if (NOT CMAKE_C_STANDARD STREQUAL "99")
add_compile_options(-Wpedantic)
endif()
# add_compile_options(-Wconversion)
# add_link_options(-fsanitize=address)
elseif(MSVC)
add_compile_options(/W4 /WX /Od /wd4127)
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -pipe -g -O0)
endif()
endif()

set(Libname "zenohpico")
if(BUILD_SHARED_LIBS)
add_library(${Libname} SHARED)
Expand All @@ -50,16 +86,6 @@ function(add_definition value)
target_compile_definitions(${Libname} PUBLIC ${value})
endfunction()

if(NOT CMAKE_C_STANDARD)
if(c_std_11 IN_LIST CMAKE_C_COMPILE_FEATURES)
set(CMAKE_C_STANDARD 11)
message(STATUS "Setting C11 as the C Standard")
else()
set(CMAKE_C_STANDARD 99)
message(STATUS "Setting C99 as the C Standard")
endif()
endif()
set(CMAKE_C_STANDARD_REQUIRED TRUE)
add_definition(ZENOH_C_STANDARD=${CMAKE_C_STANDARD})

# while in development, use timestamp for patch version:
Expand Down Expand Up @@ -175,31 +201,11 @@ if(CHECK_THREADS)
find_package(Threads REQUIRED)
endif()

if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
if(UNIX)
# FIXME: seems to not apply to library files, Issue #422
add_compile_options(-c -Wall -Wextra -Werror -Wshadow -Wpedantic -Wunused -Wstrict-prototypes -pipe -g -O0)
# add_compile_options(-Wconversion)
# add_link_options(-fsanitize=address)
elseif(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11 /experimental:c11atomics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /experimental:c11atomics")
add_compile_options(/W4 /WX /Od /wd4127)
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -pipe -g -O0)
endif()
elseif(CMAKE_BUILD_TYPE MATCHES "RELEASE")
if(UNIX)
add_compile_options(-pipe -O3)
elseif(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11 /experimental:c11atomics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /experimental:c11atomics")
elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
add_compile_options(-pipe -O3)
endif()
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11 /experimental:c11atomics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /experimental:c11atomics")
endif()


file(GLOB_RECURSE PublicHeaders
"include/zenoh-pico/api/*.h"
"include/zenoh-pico/collections/*.h"
Expand All @@ -216,7 +222,6 @@ target_include_directories(${Libname} PUBLIC ${PROJECT_SOURCE_DIR}/include)
file(GLOB_RECURSE Sources
"src/api/*.c"
"src/collections/*.c"
"src/deprecated/*.c"
"src/link/*.c"
"src/net/*.c"
"src/protocol/*.c"
Expand Down
15 changes: 9 additions & 6 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ TODO: owned type description
Represents the encoding of a payload, in a MIME-like format.

.. c:type:: z_owned_value_t
.. c:type:: z_owned_reply_err_t
Represents a Zenoh value.
Represents a Zenoh reply error value.

.. c:type:: z_owned_sample_t
Expand Down Expand Up @@ -182,9 +182,9 @@ TODO: loaned type description
Represents the encoding of a payload, in a MIME-like format.

.. c:type:: z_loaned_value_t
.. c:type:: z_loaned_reply_err_t
Represents a Zenoh value.
Represents a Zenoh reply error.

.. c:type:: z_loaned_sample_t
Expand Down Expand Up @@ -287,9 +287,11 @@ Primitives
.. autocfunction:: primitives.h::z_encoding_check
.. autocfunction:: primitives.h::z_encoding_drop
.. autocfunction:: primitives.h::z_encoding_loan
.. autocfunction:: primitives.h::z_encoding_loan_mut
.. autocfunction:: primitives.h::z_encoding_move
.. autocfunction:: primitives.h::z_encoding_null
.. autocfunction:: primitives.h::z_value_payload
.. autocfunction:: primitives.h::z_reply_err_payload
.. autocfunction:: primitives.h::z_reply_err_encoding
.. autocfunction:: primitives.h::z_slice_data
.. autocfunction:: primitives.h::z_slice_len
.. autocfunction:: primitives.h::z_bytes_deserialize_into_int8
Expand Down Expand Up @@ -326,7 +328,8 @@ Primitives
.. autocfunction:: primitives.h::z_query_consolidation_monotonic
.. autocfunction:: primitives.h::z_query_consolidation_none
.. autocfunction:: primitives.h::z_query_parameters
.. autocfunction:: primitives.h::z_query_value
.. autocfunction:: primitives.h::z_query_payload
.. autocfunction:: primitives.h::z_query_encoding
.. autocfunction:: primitives.h::z_query_attachment
.. autocfunction:: primitives.h::z_query_keyexpr
.. autocfunction:: primitives.h::z_closure_sample
Expand Down
7 changes: 6 additions & 1 deletion examples/arduino/z_pub.ino
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,18 @@ void loop() {
delay(1000);
char buf[256];
sprintf(buf, "[%4d] %s", idx++, VALUE);

Serial.print("Writing Data ('");
Serial.print(KEYEXPR);
Serial.print("': '");
Serial.print(buf);
Serial.println("')");

if (z_publisher_put(z_publisher_loan(&pub), (const uint8_t *)buf, strlen(buf), NULL) < 0) {
// Create payload
z_owned_bytes_t payload;
z_bytes_serialize_from_string(&payload, buf);

if (z_publisher_put(z_publisher_loan(&pub), z_bytes_move(&payload), NULL) < 0) {
Serial.println("Error while publishing data");
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/arduino/z_queryable.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void query_handler(const z_loaned_query_t *query, void *arg) {

// Process value
z_owned_string_t payload_string;
z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string);
z_bytes_deserialize_into_string(z_query_payload(query), &payload_string);
if (z_string_len(z_string_loan(&payload_string)) > 1) {
Serial.print(" with value '");
Serial.print(z_string_data(z_string_loan(&payload_string)));
Expand Down
7 changes: 6 additions & 1 deletion examples/espidf/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ void app_main() {
sleep(1);
sprintf(buf, "[%4d] %s", idx, VALUE);
printf("Putting Data ('%s': '%s')...\n", KEYEXPR, buf);
z_publisher_put(z_loan(pub), (const uint8_t*)buf, strlen(buf), NULL);

// Create payload
z_owned_bytes_t payload;
z_bytes_serialize_from_string(&payload, buf);

z_publisher_put(z_loan(pub), z_move(payload), NULL);
}

printf("Closing Zenoh Session...");
Expand Down
2 changes: 1 addition & 1 deletion examples/espidf/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) {
z_loan(params)->val);
// Process value
z_owned_string_t payload_string;
z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string);
z_bytes_deserialize_into_string(z_query_payload(query), &payload_string);
if (z_string_len(z_loan(payload_string)) > 1) {
printf(" with value '%s'\n", z_string_data(z_loan(payload_string)));
}
Expand Down
6 changes: 5 additions & 1 deletion examples/freertos_plus_tcp/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ void app_main(void) {
snprintf(buf, 256, "[%4d] %s", idx, VALUE);
printf("Putting Data ('%s': '%s')...\n", KEYEXPR, buf);

// Create payload
z_owned_bytes_t payload;
z_bytes_serialize_from_string(&payload, buf);

z_publisher_put_options_t options;
z_publisher_put_options_default(&options);
z_publisher_put(z_loan(pub), (const uint8_t *)buf, strlen(buf), &options);
z_publisher_put(z_loan(pub), z_move(payload), &options);
}

// Clean-up
Expand Down
7 changes: 6 additions & 1 deletion examples/freertos_plus_tcp/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ void app_main(void) {
if (z_clock_elapsed_ms(&now) > 1000) {
snprintf(buf, 256, "[%4d] %s", idx, VALUE);
printf("Putting Data ('%s': '%s')...\n", KEYEXPR, buf);
z_publisher_put(z_loan(pub), (const uint8_t *)buf, strlen(buf), NULL);

// Create payload
z_owned_bytes_t payload;
z_bytes_serialize_from_string(&payload, buf);

z_publisher_put(z_loan(pub), z_move(payload), NULL);
++idx;

now = z_clock_now();
Expand Down
7 changes: 6 additions & 1 deletion examples/freertos_plus_tcp/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ void app_main(void) {
printf("Putting Data ('%s': '%s')...\n", KEYEXPR, VALUE);
z_put_options_t options;
z_put_options_default(&options);
if (z_put(z_loan(s), z_loan(ke), (const uint8_t *)VALUE, strlen(VALUE), &options) < 0) {

// Create payload
z_owned_bytes_t payload;
z_bytes_serialize_from_string(&payload, VALUE);

if (z_put(z_loan(s), z_loan(ke), z_move(payload), &options) < 0) {
printf("Oh no! Put has failed...\n");
}

Expand Down
2 changes: 1 addition & 1 deletion examples/freertos_plus_tcp/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) {
z_loan(params)->val);
// Process value
z_owned_string_t payload_string;
z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string);
z_bytes_deserialize_into_string(z_query_payload(query), &payload_string);
if (z_string_len(z_loan(payload_string)) > 1) {
printf(" with value '%s'\n", z_string_data(z_loan(payload_string)));
}
Expand Down
7 changes: 6 additions & 1 deletion examples/mbed/z_pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ int main(int argc, char **argv) {
z_sleep_s(1);
sprintf(buf, "[%4d] %s", idx, VALUE);
printf("Putting Data ('%s': '%s')...\n", KEYEXPR, buf);
z_publisher_put(z_publisher_loan(&pub), (const uint8_t *)buf, strlen(buf), NULL);

// Create payload
z_owned_bytes_t payload;
z_bytes_serialize_from_string(&payload, buf);

z_publisher_put(z_publisher_loan(&pub), z_bytes_move(&payload), NULL);
}

printf("Closing Zenoh Session...");
Expand Down
2 changes: 1 addition & 1 deletion examples/mbed/z_queryable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) {
(int)z_view_string_loan(&pred)->len, z_view_string_loan(&pred)->val);
// Process value
z_owned_string_t payload_string;
z_bytes_deserialize_into_string(z_value_payload(z_query_value(query)), &payload_string);
z_bytes_deserialize_into_string(z_query_payload(query), &payload_string);
if (z_string_len(z_string_loan(&payload_string)) > 1) {
printf(" with value '%s'\n", z_string_data(z_string_loan(&payload_string)));
}
Expand Down
11 changes: 6 additions & 5 deletions examples/unix/c11/z_get_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ int main(int argc, char **argv) {
z_bytes_serialize_from_string(&payload, value);
opts.payload = &payload;
}
z_owned_reply_ring_channel_t channel;
z_reply_ring_channel_new(&channel, 1);
if (z_get(z_loan(s), z_loan(ke), "", z_move(channel.send), &opts) < 0) {
z_owned_closure_reply_t closure;
z_owned_ring_handler_reply_t handler;
z_ring_channel_reply_new(&closure, &handler, 1);
if (z_get(z_loan(s), z_loan(ke), "", z_move(closure), &opts) < 0) {
printf("Unable to send query.\n");
return -1;
}

z_owned_reply_t reply;
z_null(&reply);
for (z_call(channel.recv, &reply); z_check(reply); z_call(channel.recv, &reply)) {
for (z_recv(z_loan(handler), &reply); z_check(reply); z_recv(z_loan(handler), &reply)) {
if (z_reply_is_ok(z_loan(reply))) {
const z_loaned_sample_t *sample = z_reply_ok(z_loan(reply));
z_owned_string_t keystr;
Expand All @@ -121,7 +122,7 @@ int main(int argc, char **argv) {
}
}

z_drop(z_move(channel));
z_drop(z_move(handler));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
Expand Down
12 changes: 10 additions & 2 deletions examples/unix/c11/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,23 @@ int main(int argc, char** argv) {
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);
// Create payload
z_owned_bytes_t payload;
z_bytes_serialize_from_slice(&payload, data, args.size);

z_publisher_put(z_loan(pub), z_move(payload), NULL);
z_condvar_wait(&cond, &mutex);
elapsed_us = z_clock_elapsed_us(&warmup_start);
}
}
unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings);
for (unsigned int i = 0; i < args.number_of_pings; i++) {
z_clock_t measure_start = z_clock_now();
z_publisher_put(z_loan(pub), data, args.size, NULL);
// Create payload
z_owned_bytes_t payload;
z_bytes_serialize_from_slice(&payload, data, args.size);

z_publisher_put(z_loan(pub), z_move(payload), NULL);
z_condvar_wait(&cond, &mutex);
results[i] = z_clock_elapsed_us(&measure_start);
}
Expand Down
4 changes: 3 additions & 1 deletion examples/unix/c11/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ void callback(const z_loaned_sample_t* sample, void* context) {
const z_loaned_publisher_t* pub = z_loan(*(z_owned_publisher_t*)context);
z_owned_slice_t value;
z_bytes_deserialize_into_slice(z_sample_payload(sample), &value);
z_publisher_put(pub, z_slice_data(z_loan(value)), z_slice_len(z_loan(value)), NULL);
z_owned_bytes_t payload;
z_bytes_serialize_from_slice(&payload, z_slice_data(z_loan(value)), z_slice_len(z_loan(value)));
z_publisher_put(pub, z_move(payload), NULL);
z_drop(z_move(value));
}
void drop(void* context) {
Expand Down
6 changes: 5 additions & 1 deletion examples/unix/c11/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,18 @@ int main(int argc, char **argv) {
sprintf(buf, "[%4d] %s", idx, value);
printf("Putting Data ('%s': '%s')...\n", keyexpr, buf);

// Create payload
z_owned_bytes_t payload;
z_bytes_serialize_from_string(&payload, buf);

// Create encoding
z_owned_encoding_t encoding;
zp_encoding_make(&encoding, Z_ENCODING_ID_TEXT_PLAIN, "utf8");
z_publisher_put_options_t options;
z_publisher_put_options_default(&options);
options.encoding = z_move(encoding);

z_publisher_put(z_loan(pub), (const uint8_t *)buf, strlen(buf), &options);
z_publisher_put(z_loan(pub), z_move(payload), &options);
}
// Clean up
z_undeclare_publisher(z_move(pub));
Expand Down
Loading

0 comments on commit 99abc68

Please sign in to comment.