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 all 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
72 changes: 36 additions & 36 deletions .github/workflows/build-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ name: build-check

on:
push:
branches: [ '**' ]
branches: ["**"]
pull_request:
branches: [ '**' ]
branches: ["**"]

jobs:
run_tests:
run_tests:
name: Run unit tests on ubuntu-latest
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build & run tests
run: |
sudo apt install -y ninja-build
CMAKE_GENERATOR=Ninja make test

check_format:
name: Check codebase format with clang-format
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- 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

Expand All @@ -48,11 +48,11 @@ jobs:
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
FORCE_C99=ON CMAKE_GENERATOR=Ninja make

modular_build:
name: Modular build on ubuntu-latest
Expand All @@ -64,30 +64,30 @@ jobs:
feature_queryable: [1, 0]
feature_query: [1, 0]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run docker image
run: docker run --name zenoh_router --init --net host -d eclipse/zenoh:latest

- name: Build project
run: |
sudo apt install -y ninja-build
CMAKE_GENERATOR=Ninja make
python3 ./build/tests/modularity.py --pub $Z_FEATURE_PUBLICATION --sub $Z_FEATURE_SUBSCRIPTION --queryable $Z_FEATURE_QUERYABLE --query $Z_FEATURE_QUERY
timeout-minutes: 5
env:
Z_FEATURE_PUBLICATION: ${{ matrix.feature_publication }}
Z_FEATURE_SUBSCRIPTION: ${{ matrix.feature_subscription }}
Z_FEATURE_QUERYABLE: ${{ matrix.feature_queryable }}
Z_FEATURE_QUERY: ${{ matrix.feature_query }}
- name: Stop docker image
if: always()
run: |
docker stop zenoh_router
docker rm zenoh_router
- name: Checkout code
uses: actions/checkout@v4

- name: Run docker image
run: docker run --name zenoh_router --init --net host -d eclipse/zenoh:latest

- name: Build project
run: |
sudo apt install -y ninja-build
CMAKE_GENERATOR=Ninja make
python3 ./build/tests/modularity.py --pub $Z_FEATURE_PUBLICATION --sub $Z_FEATURE_SUBSCRIPTION --queryable $Z_FEATURE_QUERYABLE --query $Z_FEATURE_QUERY
timeout-minutes: 5
env:
Z_FEATURE_PUBLICATION: ${{ matrix.feature_publication }}
Z_FEATURE_SUBSCRIPTION: ${{ matrix.feature_subscription }}
Z_FEATURE_QUERYABLE: ${{ matrix.feature_queryable }}
Z_FEATURE_QUERY: ${{ matrix.feature_query }}

- name: Stop docker image
if: always()
run: |
docker stop zenoh_router
docker rm zenoh_router

raweth_build:
name: Build and test raweth transport on ubuntu-latest
runs-on: ubuntu-latest
Expand All @@ -106,7 +106,7 @@ jobs:
timeout-minutes: 5
env:
Z_FEATURE_RAWETH_TRANSPORT: ${{ matrix.feature_reth }}

st_build:
name: Build and test in single thread on ubuntu-latest
runs-on: ubuntu-latest
Expand All @@ -124,13 +124,13 @@ jobs:
python3 ./build/tests/single_thread.py
timeout-minutes: 5
env:
Z_FEATURE_MULTI_THREAD: 0
Z_FEATURE_MULTI_THREAD: 0

- name: Stop docker image
if: always()
run: |
docker stop zenoh_router
docker rm zenoh_router
docker stop zenoh_router
docker rm zenoh_router

fragment_test:
name: Test multicast and unicast fragmentation
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,22 @@ set(Z_FEATURE_SUBSCRIPTION 1 CACHE STRING "Toggle subscription feature")
set(Z_FEATURE_QUERY 1 CACHE STRING "Toggle query feature")
set(Z_FEATURE_QUERYABLE 1 CACHE STRING "Toggle queryable feature")
set(Z_FEATURE_RAWETH_TRANSPORT 0 CACHE STRING "Toggle raw ethernet transport feature")
set(Z_FEATURE_ATTACHMENT 1 CACHE STRING "Toggle attachment feature")
add_definition(Z_FEATURE_MULTI_THREAD=${Z_FEATURE_MULTI_THREAD})
add_definition(Z_FEATURE_PUBLICATION=${Z_FEATURE_PUBLICATION})
add_definition(Z_FEATURE_SUBSCRIPTION=${Z_FEATURE_SUBSCRIPTION})
add_definition(Z_FEATURE_QUERY=${Z_FEATURE_QUERY})
add_definition(Z_FEATURE_QUERYABLE=${Z_FEATURE_QUERYABLE})
add_definition(Z_FEATURE_RAWETH_TRANSPORT=${Z_FEATURE_RAWETH_TRANSPORT})
add_definition(Z_FEATURE_ATTACHMENT=${Z_FEATURE_ATTACHMENT})
add_compile_definitions("Z_BUILD_DEBUG=$<CONFIG:Debug>")
message(STATUS "Building with feature confing:\n\
* MULTI-THREAD: ${Z_FEATURE_MULTI_THREAD}\n\
* PUBLICATION: ${Z_FEATURE_PUBLICATION}\n\
* SUBSCRIPTION: ${Z_FEATURE_SUBSCRIPTION}\n\
* QUERY: ${Z_FEATURE_QUERY}\n\
* QUERYABLE: ${Z_FEATURE_QUERYABLE}\n\
* ATTACHMENT: ${Z_FEATURE_ATTACHMENT}\n\
* RAWETH: ${Z_FEATURE_RAWETH_TRANSPORT}")

# Print summary of CMAKE configurations
Expand Down
3 changes: 2 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Z_FEATURE_PUBLICATION?=1
Z_FEATURE_SUBSCRIPTION?=1
Z_FEATURE_QUERY?=1
Z_FEATURE_QUERYABLE?=1
Z_FEATURE_ATTACHMENT?=1
Z_FEATURE_RAWETH_TRANSPORT?=0

# zenoh-pico/ directory
Expand All @@ -74,7 +75,7 @@ CROSSIMG_PREFIX=zenoh-pico_
CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_MULTICAST=$(BUILD_MULTICAST)\
-DZ_FEATURE_MULTI_THREAD=$(Z_FEATURE_MULTI_THREAD) \
-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.
-DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DZ_FEATURE_ATTACHMENT=$(Z_FEATURE_ATTACHMENT) -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
Expand Down
13 changes: 12 additions & 1 deletion examples/unix/c11/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

#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"

#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 +93,23 @@
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);
#if Z_FEATURE_ATTACHMENT == 1

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
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));

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 11.8 rule Note

MISRA 11.8 rule
options.attachment = z_bytes_map_as_attachment(&map);
#endif
if (z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)value, strlen(value), &options) < 0) {
printf("Oh no! Put has failed...\n");
}

#if Z_FEATURE_ATTACHMENT == 1

Check warning

Code scanning / Cppcheck (reported by Codacy)

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

misra violation 2009 with no text in the supplied rule-texts-file
z_bytes_map_drop(&map);
#endif
// 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
16 changes: 16 additions & 0 deletions examples/unix/c11/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,33 @@

#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>

#if Z_FEATURE_SUBSCRIPTION == 1

#if Z_FEATURE_ATTACHMENT == 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);
return 0;
}
#endif

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_FEATURE_ATTACHMENT == 1
if (z_attachment_check(&sample->attachment)) {
printf("Attachement found\n");
z_attachment_iterate(sample->attachment, attachment_handler, NULL);
}
#endif
z_drop(z_move(keystr));
}

Expand Down
8 changes: 5 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 All @@ -32,6 +32,8 @@ extern "C" {
#endif

/********* Data Types Handlers *********/
#define z_bytes_wrap _z_bytes_wrap

/**
* Constructs a :c:type:`z_string_t` departing from a ``const char *``.
* It is a loaned key expression that aliases ``value``.
Expand Down Expand Up @@ -1413,4 +1415,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