Skip to content

Commit

Permalink
Code cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Nov 8, 2023
1 parent d4bf467 commit 4e14797
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions examples/z_get_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ int main(int argc, char **argv) {

z_keyexpr_t keyexpr = z_keyexpr(expr);
if (!z_check(keyexpr)) {
printf("%s is not a valid key expression", expr);
printf("%s is not a valid key expression\n", expr);
exit(-1);
}

z_owned_config_t config = z_config_default();
if (argc > 2) {
if (zc_config_insert_json(z_loan(config), Z_CONFIG_CONNECT_KEY, argv[2]) < 0) {
printf(
"Couldn't insert value `%s` in configuration at `%s`. This is likely because `%s` expects a "
"JSON-serialized list of strings\n",
argv[3], Z_CONFIG_CONNECT_KEY, Z_CONFIG_CONNECT_KEY);
argv[2], Z_CONFIG_CONNECT_KEY, Z_CONFIG_CONNECT_KEY);
exit(-1);
}
}
Expand All @@ -47,7 +48,6 @@ int main(int argc, char **argv) {

printf("Sending liveliness query '%s'...\n", expr);
z_owned_reply_channel_t channel = zc_reply_fifo_new(16);
z_get_options_t opts = z_get_options_default();
zc_liveliness_get(z_loan(s), keyexpr, z_move(channel.send), NULL);
z_owned_reply_t reply = z_reply_null();
for (z_call(channel.recv, &reply); z_check(reply); z_call(channel.recv, &reply)) {
Expand Down
18 changes: 9 additions & 9 deletions examples/z_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
#endif
#include "zenoh.h"

const char *expr = "group1/zenoh-rs";
z_keyexpr_t keyexpr;

int main(int argc, char **argv) {
char *expr = "group1/zenoh-rs";
if (argc > 1) {
expr = argv[1];
}

z_keyexpr_t keyexpr = z_keyexpr(expr);
if (!z_check(keyexpr)) {
printf("%s is not a valid key expression\n", expr);
exit(-1);
}

z_owned_config_t config = z_config_default();
if (argc > 2) {
if (zc_config_insert_json(z_loan(config), Z_CONFIG_CONNECT_KEY, argv[2]) < 0) {
Expand All @@ -45,16 +50,11 @@ int main(int argc, char **argv) {
printf("Unable to open session!\n");
exit(-1);
}
keyexpr = z_keyexpr(expr);
if (!z_check(keyexpr)) {
printf("%s is not a valid key expression", expr);
exit(-1);
}

printf("Declaring liveliness token '%s'...\n", expr);
zc_owned_liveliness_token_t token = zc_liveliness_declare_token(z_loan(s), keyexpr, NULL);
if (!zc_liveliness_token_check(&token)) {
printf("Unable to create liveliness token.\n");
printf("Unable to create liveliness token!\n");
exit(-1);
}

Expand Down
10 changes: 8 additions & 2 deletions examples/z_sub_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ int main(int argc, char **argv) {
expr = argv[1];
}

z_keyexpr_t keyexpr = z_keyexpr(expr);
if (!z_check(keyexpr)) {
printf("%s is not a valid key expression\n", expr);
exit(-1);
}

z_owned_config_t config = z_config_default();
if (argc > 2) {
if (zc_config_insert_json(z_loan(config), Z_CONFIG_LISTEN_KEY, argv[2]) < 0) {
Expand All @@ -57,9 +63,9 @@ int main(int argc, char **argv) {
exit(-1);
}

z_owned_closure_sample_t callback = z_closure(data_handler);
printf("Declaring liveliness subscriber on '%s'...\n", expr);
z_owned_subscriber_t sub = zc_liveliness_declare_subscriber(z_loan(s), z_keyexpr(expr), z_move(callback), NULL);
z_owned_closure_sample_t callback = z_closure(data_handler);
z_owned_subscriber_t sub = zc_liveliness_declare_subscriber(z_loan(s), keyexpr, z_move(callback), NULL);
if (!z_check(sub)) {
printf("Unable to declare liveliness subscriber.\n");
exit(-1);
Expand Down

0 comments on commit 4e14797

Please sign in to comment.