Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Dec 4, 2024
1 parent c77f3d7 commit 430fa97
Show file tree
Hide file tree
Showing 10 changed files with 443 additions and 566 deletions.
2 changes: 1 addition & 1 deletion examples/parse_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,4 @@ z_priority_t parse_priority(const char* arg) {
#define _Z_CHECK_FLAG(VALUE, ID) \
do { \
VALUE = (parse_opt(argc, argv, ID, false) != NULL); \
} while (0)
} while (0)
2 changes: 1 addition & 1 deletion examples/z_get_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char** argv) {
z_liveliness_get_options_t opts;
z_liveliness_get_options_default(&opts);
opts.timeout_ms = args.timeout_ms;
z_liveliness_get(z_loan(s), z_loan(keyexpr), z_move(closure), NULL);
z_liveliness_get(z_loan(s), z_loan(keyexpr), z_move(closure), &opts);
z_owned_reply_t reply;
for (z_result_t res = z_recv(z_loan(handler), &reply); res == Z_OK; res = z_recv(z_loan(handler), &reply)) {
if (z_reply_is_ok(z_loan(reply))) {
Expand Down
4 changes: 2 additions & 2 deletions examples/z_non_blocking_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ int main(int argc, char** argv) {
}

z_view_keyexpr_t keyexpr;
if (z_view_keyexpr_from_str(&keyexpr, ke) < 0) {
printf("%s is not a valid key expression", ke);
if (z_view_keyexpr_from_substr(&keyexpr, ke, ke_len) < 0) {
printf("%.*s is not a valid key expression", (int)ke_len, ke);
exit(-1);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, char** argv) {
z_publisher_options_t opts;
z_publisher_options_default(&opts);
opts.is_express = !args.no_express;
z_declare_publisher(z_loan(session), &pub, z_loan(pong), NULL);
z_declare_publisher(z_loan(session), &pub, z_loan(pong), &opts);
z_owned_closure_sample_t respond;
z_closure(&respond, callback, drop, (void*)&pub);
z_declare_background_subscriber(z_loan(session), z_loan(ping), z_move(respond), NULL);
Expand Down
2 changes: 2 additions & 0 deletions examples/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config) {
_Z_PARSE_ARG(args.keyexpr, "k", (char*), (char*)DEFAULT_KEYEXPR);
_Z_PARSE_ARG(args.value, "p", (char*), (char*)DEFAULT_VALUE);
_Z_PARSE_ARG(args.attachment, "a", (char*), (char*)DEFAULT_ATTACHMENT);
#if defined(Z_FEATURE_UNSTABLE_API)
_Z_CHECK_FLAG(args.add_matching_listener, "add-matching-listener");
#endif
parse_zenoh_common_args(argc, argv, config);
const char* unknown_arg = check_unknown_opts(argc, argv);
if (unknown_arg) {
Expand Down
24 changes: 8 additions & 16 deletions examples/z_pub_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,10 @@ int main(int argc, char** argv) {
exit(-1);
}
#if defined(Z_FEATURE_UNSTABLE_API)
zc_owned_matching_listener_t listener;
if (args.add_matching_listener) {
zc_owned_closure_matching_status_t callback;
z_closure(&callback, matching_status_handler, NULL, NULL);
zc_publisher_declare_matching_listener(z_loan(pub), &listener, z_move(callback));
}
#else
if (add_matching_listener) {
printf("To enable matching listener you must compile Zenoh-c with unstable feature support!\n");
exit(-1);
zc_publisher_declare_background_matching_listener(z_loan(pub), z_move(callback));
}
#endif

Expand Down Expand Up @@ -108,15 +102,8 @@ int main(int argc, char** argv) {
}
}

#if defined(Z_FEATURE_UNSTABLE_API)
if (args.add_matching_listener) {
z_drop(z_move(listener));
}
#endif

z_drop(z_move(pub));
z_drop(z_move(s));

z_drop(z_move(provider));
z_drop(z_move(layout));

Expand All @@ -129,7 +116,11 @@ void print_help() {
Usage: z_pub_shm [OPTIONS]\n\n\
Options:\n\
-k <KEYEXPR> (optional, string, default='%s'): The key expression to write to\n\
-p <PAYLOAD> (optional, string, default='%s'): The value to write\n",
-p <PAYLOAD> (optional, string, default='%s'): The value to write\n"
#if defined(Z_FEATURE_UNSTABLE_API)
" --add-matching-listener (optional): Add matching listener\n"
#endif
,
DEFAULT_KEYEXPR, DEFAULT_VALUE);
printf(COMMON_HELP);
printf(
Expand All @@ -145,8 +136,9 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config) {
struct args_t args;
_Z_PARSE_ARG(args.keyexpr, "k", (char*), (char*)DEFAULT_KEYEXPR);
_Z_PARSE_ARG(args.value, "p", (char*), (char*)DEFAULT_VALUE);
#if defined(Z_FEATURE_UNSTABLE_API)
_Z_CHECK_FLAG(args.add_matching_listener, "add-matching-listener");

#endif
parse_zenoh_common_args(argc, argv, config);
const char* arg = check_unknown_opts(argc, argv);
if (arg) {
Expand Down
5 changes: 2 additions & 3 deletions examples/z_pub_shm_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
char* keyexpr = "test/thr";
size_t len = atoi(argv[1]);

zc_init_log_from_env_or("error");

Expand Down Expand Up @@ -62,12 +61,12 @@ int main(int argc, char** argv) {

printf("Allocating single SHM buffer\n");
z_buf_layout_alloc_result_t alloc;
z_shm_provider_alloc(&alloc, z_loan(provider), len, alignment);
z_shm_provider_alloc(&alloc, z_loan(provider), args.size, alignment);
if (alloc.status != ZC_BUF_LAYOUT_ALLOC_STATUS_OK) {
printf("Unexpected failure during SHM buffer allocation...\n");
return -1;
}
memset(z_shm_mut_data_mut(z_loan_mut(alloc.buf)), 1, len);
memset(z_shm_mut_data_mut(z_loan_mut(alloc.buf)), 1, args.size);
z_owned_shm_t shm;
z_shm_from_mut(&shm, z_move(alloc.buf));

Expand Down
2 changes: 2 additions & 0 deletions examples/z_querier.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config) {
_Z_PARSE_ARG(args.value, "p", (char*), (char*)DEFAULT_VALUE);
_Z_PARSE_ARG(args.timeout_ms, "o", atoi, DEFAULT_TIMEOUT_MS);
_Z_PARSE_ARG(args.target, "t", parse_query_target, z_query_target_default());
#if defined(Z_FEATURE_UNSTABLE_API)
_Z_CHECK_FLAG(args.add_matching_listener, "add-matching-listener");
#endif

parse_zenoh_common_args(argc, argv, config);
const char* arg = check_unknown_opts(argc, argv);
Expand Down
Loading

0 comments on commit 430fa97

Please sign in to comment.