Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachment support for pub/sub #318

Merged
merged 21 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/build-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ jobs:
- name: Run clang-format dry-run
run: find include/ src/ tests/ examples/ -iname "*.ino" -o -iname "*.h" -o -iname "*.c" | xargs clang-format -n -Werror

c99_build:
name: Check c99 compilation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build with C99
run: |
sudo apt install -y ninja-build
FORCE_C99=ON CMAKE_GENERATOR=Ninja make

modular_build:
name: Modular build on ubuntu-latest
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ if(UNIX OR MSVC)
target_link_libraries(z_keyexpr_canonizer ${Libname})
endif()

if(BUILD_TESTING)
if(BUILD_TESTING AND CMAKE_C_STANDARD MATCHES "11")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

add_executable(z_data_struct_test ${PROJECT_SOURCE_DIR}/tests/z_data_struct_test.c)
Expand Down
8 changes: 8 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ BUILD_INTEGRATION?=OFF
# Accepted values: ON, OFF
BUILD_TOOLS?=OFF

# Force the use of c99 standard.
# Accepted values: ON, OFF
FORCE_C99?=OFF

# Debug level. This sets the ZENOH_DEBUG variable.
# Accepted values:
# 0: NONE
Expand Down Expand Up @@ -72,6 +76,10 @@ CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAK
-DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\
-DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.

ifeq ($(FORCE_C99), ON)
CMAKE_OPT += -DCMAKE_C_STANDARD=99
endif

all: make

$(BUILD_DIR)/Makefile:
Expand Down
11 changes: 10 additions & 1 deletion examples/unix/c11/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@

#include <ctype.h>
#include <stddef.h>
#include <stdint.h>

Check warning

Code scanning / Cppcheck (reported by Codacy)

Include file: <stdint.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. Warning

Include file: <stdint.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <zenoh-pico.h>

#include "zenoh-pico/api/macros.h"
#include "zenoh-pico/api/types.h"
#include "zenoh-pico/collections/bytes.h"
#include "zenoh-pico/protocol/core.h"
p-avital marked this conversation as resolved.
Show resolved Hide resolved

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-put";
Expand Down Expand Up @@ -89,16 +95,19 @@
printf("Putting Data ('%s': '%s')...\n", keyexpr, value);
z_put_options_t options = z_put_options_default();
options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL);
z_owned_bytes_map_t map = z_bytes_map_new();
z_bytes_map_insert_by_alias(&map, _z_bytes_wrap((uint8_t *)"hi", 2), _z_bytes_wrap((uint8_t *)"there", 5));
options.attachment = z_bytes_map_as_attachment(&map);
if (z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)value, strlen(value), &options) < 0) {
printf("Oh no! Put has failed...\n");
}

z_bytes_map_drop(&map);
// z_undeclare_keyexpr(z_loan(s), z_move(ke));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan(s));
zp_stop_lease_task(z_loan(s));

z_close(z_move(s));
return 0;
}
Expand Down
14 changes: 14 additions & 0 deletions examples/unix/c11/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,31 @@

#include <ctype.h>
#include <stddef.h>
#include <stdint.h>

Check warning

Code scanning / Cppcheck (reported by Codacy)

Include file: <stdint.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. Warning

Include file: <stdint.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <zenoh-pico.h>

#include "zenoh-pico/api/types.h"
#include "zenoh-pico/protocol/core.h"
p-avital marked this conversation as resolved.
Show resolved Hide resolved

#if Z_FEATURE_SUBSCRIPTION == 1
int8_t attachment_handler(z_bytes_t key, z_bytes_t value, void *ctx) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
(void)ctx;
printf(">>> %.*s: %.*s\n", (int)key.len, key.start, (int)value.len, value.start);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
return 0;
}

void data_handler(const z_sample_t *sample, void *ctx) {
(void)(ctx);
z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr);
printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_loan(keystr), (int)sample->payload.len,
sample->payload.start);
if (z_attachment_check(&sample->attachment)) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
printf("Attachement found\n");

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
z_attachment_iterate(sample->attachment, attachment_handler, NULL);
}
z_drop(z_move(keystr));
}

Expand Down
5 changes: 3 additions & 2 deletions examples/unix/c99/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand All @@ -105,7 +105,8 @@ int main(int argc, char **argv) {
char c = '\0';
while (1) {
fflush(stdin);
scanf("%c", &c);
int ret = scanf("%c", &c);
(void)ret; // Clear unused result warning
if (c == 'q') {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c99/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ int main(int argc, char **argv) {
char c = '\0';
while (1) {
fflush(stdin);
scanf("%c", &c);
int ret = scanf("%c", &c);
(void)ret; // Clear unused result warning
if (c == 'q') {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
5 changes: 3 additions & 2 deletions examples/unix/c99/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down Expand Up @@ -108,7 +108,8 @@ int main(int argc, char **argv) {
char c = '\0';
while (c != 'q') {
fflush(stdin);
scanf("%c", &c);
int ret = scanf("%c", &c);
(void)ret; // Clear unused result warning
}

z_undeclare_queryable(z_queryable_move(&qable));
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void callback(z_owned_hello_t *hello, void *context) {
fprinthello(stdout, z_hello_loan(hello));
fprintf(stdout, "\n");
(*(int *)context)++;
z_drop(hello);
z_hello_drop(hello);
}

void drop(void *context) {
Expand Down
5 changes: 3 additions & 2 deletions examples/unix/c99/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down Expand Up @@ -96,7 +96,8 @@ int main(int argc, char **argv) {
char c = '\0';
while (c != 'q') {
fflush(stdin);
scanf("%c", &c);
int ret = scanf("%c", &c);
(void)ret; // Clear unused result warning
}

z_undeclare_subscriber(z_subscriber_move(&sub));
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_sub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main(int argc, char **argv) {
zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}

printf("Opening session...\n");
Expand Down
6 changes: 3 additions & 3 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_API_PRIMITIVES_H
#define ZENOH_PICO_API_PRIMITIVES_H
#ifndef INCLUDE_ZENOH_PICO_API_PRIMITIVES_H
#define INCLUDE_ZENOH_PICO_API_PRIMITIVES_H

#include <stdbool.h>
#include <stdint.h>
Expand Down Expand Up @@ -1413,4 +1413,4 @@ int8_t zp_send_join(z_session_t zs, const zp_send_join_options_t *options);
}
#endif

#endif /* ZENOH_PICO_API_PRIMITIVES_H */
#endif /* INCLUDE_ZENOH_PICO_API_PRIMITIVES_H */
Loading
Loading