Skip to content

Commit

Permalink
Merge branch 'moved_as_ptr_merge_main2' into moved_as_ptr_merge_main
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Aug 17, 2024
2 parents fc202ab + 7140a38 commit a56d016
Show file tree
Hide file tree
Showing 24 changed files with 45 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ phf = { version = "0.11.2", features = ["macros"] }

[lib]
path = "src/lib.rs"
name = "zenohcd"
name = "zenohc"
crate-type = ["cdylib", "staticlib"]
doctest = false

Expand Down
11 changes: 7 additions & 4 deletions examples/parse_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ char** parse_pos_args(const int argc, char** argv, const size_t nb_args) {
* @param config_key: zenoh configuration key under which the parsed values will be inserted
*/
void parse_zenoh_json_list_config(int argc, char** argv, const char* opt, const char* config_key,
const z_owned_config_t* config) {
z_owned_config_t* config) {
char* buf = (char*)calloc(1, sizeof(char));
const char* value = parse_opt(argc, argv, opt, true);
while (value) {
Expand All @@ -158,7 +158,7 @@ void parse_zenoh_json_list_config(int argc, char** argv, const char* opt, const
char* json_list = (char*)malloc(json_list_len);
snprintf(json_list, json_list_len, "[%s]", buf);
// insert in config
if (zc_config_insert_json(z_loan(*config), config_key, json_list) < 0) {
if (zc_config_insert_json(z_loan_mut(*config), config_key, json_list) < 0) {
printf(
"Couldn't insert value `%s` in configuration at `%s`\n`%s` is either not a JSON-serialized list of "
"strings, or values within the list do not respect expected format for `%s`\n",
Expand All @@ -183,14 +183,16 @@ void parse_zenoh_common_args(const int argc, char** argv, z_owned_config_t* conf
const char* config_file = parse_opt(argc, argv, "c", true);
if (config_file) {
zc_config_from_file(config, config_file);
} else {
z_config_default(config);
}
// -m: The Zenoh session mode [default: peer].
const char* mode = parse_opt(argc, argv, "m", true);
if (mode) {
size_t buflen = strlen(mode) + 3; // mode + quotes + nullbyte
char* buf = (char*)malloc(buflen);
snprintf(buf, buflen, "'%s'", mode);
if (zc_config_insert_json(z_loan(*config), Z_CONFIG_MODE_KEY, buf) < 0) {
if (zc_config_insert_json(z_loan_mut(*config), Z_CONFIG_MODE_KEY, buf) < 0) {
printf(
"Couldn't insert value `%s` in configuration at `%s`. Value must be one of: 'client', 'peer' or "
"'router'\n",
Expand All @@ -206,7 +208,8 @@ void parse_zenoh_common_args(const int argc, char** argv, z_owned_config_t* conf
parse_zenoh_json_list_config(argc, argv, "l", Z_CONFIG_LISTEN_KEY, config);
// --no-multicast-scrouting: Disable the multicast-based scouting mechanism.
const char* no_multicast_scouting = parse_opt(argc, argv, "no-multicast-scouting", false);
if (no_multicast_scouting && zc_config_insert_json(z_loan(*config), Z_CONFIG_MULTICAST_SCOUTING_KEY, "false") < 0) {
if (no_multicast_scouting &&
zc_config_insert_json(z_loan_mut(*config), Z_CONFIG_MULTICAST_SCOUTING_KEY, "false") < 0) {
printf("Couldn't disable multicast-scouting.\n");
exit(-1);
}
Expand Down
1 change: 0 additions & 1 deletion examples/z_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

printf("Opening session...\n");
Expand Down
1 change: 0 additions & 1 deletion examples/z_get.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) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

z_view_keyexpr_t keyexpr;
Expand Down
1 change: 0 additions & 1 deletion examples/z_get_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

z_view_keyexpr_t keyexpr;
Expand Down
1 change: 0 additions & 1 deletion examples/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void print_zid(const z_id_t* id, void* ctx) {

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
parse_args(argc, argv, &config);

printf("Opening session...\n");
Expand Down
1 change: 0 additions & 1 deletion examples/z_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

z_view_keyexpr_t keyexpr;
Expand Down
3 changes: 1 addition & 2 deletions examples/z_non_blocking_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

z_view_keyexpr_t keyexpr;
if (z_view_keyexpr_from_str(&keyexpr, args.keyexpr) < 0) {
if (z_view_keyexpr_from_str(&keyexpr, args.selector) < 0) {
printf("%s is not a valid key expression", args.selector);
exit(-1);
}
Expand Down
8 changes: 1 addition & 7 deletions examples/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
struct args_t args = parse_args(argc, argv, &config);

z_owned_config_t config;
if (args.config_path) {
zc_config_from_file(&config, args.config_path);
} else {
z_config_default(&config);
}
struct args_t args = parse_args(argc, argv, &config);

z_mutex_init(&mutex);
z_condvar_init(&cond);
Expand Down
6 changes: 0 additions & 6 deletions examples/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ int main(int argc, char** argv) {
z_owned_config_t config;
parse_args(argc, argv, &config);

if (args.config_path) {
zc_config_from_file(&config, args.config_path);
} else {
z_config_default(&config);
}

z_owned_session_t session;
z_open(&session, z_move(config));
z_view_keyexpr_t ping;
Expand Down
6 changes: 3 additions & 3 deletions examples/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct args_t {
};
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

#ifdef UNSTABLE
void matching_status_handler(const zc_matching_status_t* matching_status, void* arg) {
if (matching_status->matching) {
printf("Subscriber matched\n");
Expand All @@ -38,7 +39,6 @@ void matching_status_handler(const zc_matching_status_t* matching_status, void*

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

printf("Opening session...\n");
Expand All @@ -65,7 +65,7 @@ int main(int argc, char** argv) {
zc_publisher_matching_listener_declare(&listener, z_loan(pub), z_move(callback));
}
#else
if (add_matching_listener) {
if (args.add_matching_listener) {
printf("To enable matching listener you must compile Zenoh-c with unstable feature support!\n");
exit(-1);
}
Expand All @@ -86,7 +86,7 @@ int main(int argc, char** argv) {
z_publisher_put(z_loan(pub), z_move(payload), &options);
}
#ifdef UNSTABLE
if (add_matching_listener) {
if (args.add_matching_listener) {
zc_publisher_matching_listener_undeclare(z_move(listener));
}
#endif
Expand Down
1 change: 0 additions & 1 deletion examples/z_pub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

printf("Opening session...\n");
Expand Down
1 change: 0 additions & 1 deletion examples/z_pub_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

if (zc_config_insert_json(z_loan_mut(config), Z_CONFIG_ADD_TIMESTAMP_KEY, "true") < 0) {
Expand Down
1 change: 0 additions & 1 deletion examples/z_pub_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

printf("Opening session...\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/z_pub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ int main(int argc, char** argv) {
char* keyexpr = "test/thr";

z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);
uint8_t* value = (uint8_t*)z_malloc(args.size);
memset(value, 1, args.size);
Expand All @@ -50,8 +49,9 @@ int main(int argc, char** argv) {
}

printf("Press CTRL-C to quit...\n");
z_owned_bytes_t payload;
while (1) {
z_bytes_from_buf(&payload, value, len, NULL, NULL);
z_bytes_from_buf(&payload, value, args.size, NULL, NULL);
z_publisher_put(z_loan(pub), z_move(payload), NULL);
}

Expand Down
5 changes: 2 additions & 3 deletions examples/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ void handle_sample(const z_loaned_sample_t* sample) {

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

printf("Opening session...\n");
Expand All @@ -52,9 +51,9 @@ int main(int argc, char** argv) {
z_owned_ring_handler_sample_t handler;
z_owned_closure_sample_t closure;

printf("Declaring Subscriber on '%s'...\n", expr);
printf("Declaring Subscriber on '%s'...\n", args.keyexpr);
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, expr);
z_view_keyexpr_from_str(&ke, args.keyexpr);
z_owned_subscriber_t sub;

if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(closure), NULL) < 0) {
Expand Down
4 changes: 1 addition & 3 deletions examples/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ struct args_t {
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

int main(int argc, char** argv) {
struct args_t args = parse_args(argc, argv, &config);

z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

printf("Opening session...\n");
z_owned_session_t s;
Expand Down
22 changes: 13 additions & 9 deletions examples/z_query_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);

const char* kind_to_str(z_sample_kind_t kind);

void data_handler(const z_sample_t* sample, void* arg) {
z_owned_str_t keystr;
z_keyexpr_to_string(&keystr, sample->keyexpr);
printf(">> [Subscriber] Received %s ('%s': '%.*s')\n", kind_to_str(sample->kind), z_loan(keystr),
(int)sample->payload.len, sample->payload.start);
z_drop(z_move(keystr));
void data_handler(const z_loaned_sample_t* sample, void* arg) {
z_view_string_t key_string;
z_keyexpr_as_view_string(z_sample_keyexpr(sample), &key_string);
z_owned_string_t payload_string;
z_bytes_deserialize_into_string(z_sample_payload(sample), &payload_string);

printf(">> [Subscriber] Received %s ('%.*s': '%.*s')\n", kind_to_str(z_sample_kind(sample)),
(int)z_string_len(z_loan(key_string)), z_string_data(z_loan(key_string)),
(int)z_string_len(z_loan(payload_string)), z_string_data(z_loan(payload_string)));
z_drop(z_move(payload_string));
}

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

printf("Opening session...\n");
Expand All @@ -48,12 +51,13 @@ int main(int argc, char** argv) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, args.keyexpr);

ze_querying_subscriber_options_t sub_opts = ze_querying_subscriber_options_default();
ze_querying_subscriber_options_t sub_opts;
ze_querying_subscriber_options_default(&sub_opts);
z_owned_closure_sample_t callback;
z_closure(&callback, data_handler, NULL, NULL);
printf("Declaring querying subscriber on '%s'...\n", args.keyexpr);
ze_owned_querying_subscriber_t sub;
if (ze_declare_querying_subscriber(z_loan(s), z_loan(ke), z_move(callback), &sub_opts) < 0) {
if (ze_declare_querying_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), &sub_opts) < 0) {
printf("Unable to declare querying subscriber.\n");
exit(-1);
}
Expand Down
10 changes: 9 additions & 1 deletion examples/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
#define DEFAULT_VALUE "Queryable from C!"
z_view_keyexpr_t ke;

struct args_t {
char *keyexpr; // -k
char *value; // -v
};

char *value;

struct args_t parse_args(int argc, char **argv, z_owned_config_t *config);

void query_handler(const z_loaned_query_t *query, void *context) {
z_view_string_t key_string;
z_keyexpr_as_view_string(z_query_keyexpr(query), &key_string);
Expand Down Expand Up @@ -55,7 +64,6 @@ void query_handler(const z_loaned_query_t *query, void *context) {

int main(int argc, char **argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);
value = args.value;

Expand Down
5 changes: 2 additions & 3 deletions examples/z_queryable_with_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ z_view_keyexpr_t ke;

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);

printf("Opening session...\n");
Expand All @@ -41,7 +40,7 @@ int main(int argc, char** argv) {
}

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

Expand Down Expand Up @@ -84,7 +83,7 @@ int main(int argc, char** argv) {
z_query_reply_options_default(&options);

z_owned_bytes_t reply_payload;
z_bytes_from_static_str(&reply_payload, value);
z_bytes_from_static_str(&reply_payload, args.value);
z_query_reply(query, z_loan(ke), z_move(reply_payload), &options);
z_drop(z_move(oquery));
}
Expand Down
1 change: 0 additions & 1 deletion examples/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) {

int main(int argc, char **argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, args.keyexpr);
Expand Down
2 changes: 1 addition & 1 deletion examples/z_sub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct args_t {
char* keyexpr; // -k
};
struct args_t parse_args(int argc, char** argv, z_owned_config_t* config);
const char* kind_to_str(z_sample_kind_t kind);

void data_handler(const z_loaned_sample_t* sample, void* arg) {
z_view_string_t key_string;
Expand Down Expand Up @@ -63,7 +64,6 @@ void data_handler(const z_loaned_sample_t* sample, void* arg) {

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, args.keyexpr);
Expand Down
5 changes: 2 additions & 3 deletions examples/z_sub_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ void data_handler(const z_loaned_sample_t* sample, void* arg) {

int main(int argc, char** argv) {
z_owned_config_t config;
z_config_default(&config);
struct args_t args = parse_args(argc, argv, &config);
z_view_keyexpr_t ke;
if (z_view_keyexpr_from_str(&ke, keyexpr) < 0) {
printf("%s is not a valid key expression\n", keyexpr);
if (z_view_keyexpr_from_str(&ke, args.keyexpr) < 0) {
printf("%s is not a valid key expression\n", args.keyexpr);
exit(-1);
}

Expand Down
1 change: 0 additions & 1 deletion examples/z_sub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ void drop_stats(void *context) {

int main(int argc, char **argv) {
z_owned_config_t config;
z_config_default(&config);
parse_args(argc, argv, &config);

#ifdef SHARED_MEMORY
Expand Down

0 comments on commit a56d016

Please sign in to comment.