Skip to content

Commit

Permalink
Subscriber/Queryable api alignment (#720)
Browse files Browse the repository at this point in the history
* make z_undeclare_publisher/subscriber/queryable take their argument by reference

* remove z_undeclare_xxx functions;
add z_declare_background_subscriber/queryable functions;

* Update include/zenoh-pico/api/primitives.h

Co-authored-by: Alexander Bushnev <sashacmc@gmail.com>

* examples update

* rename z_declare_xxx functions to z_xxx_declare

---------

Co-authored-by: Alexander Bushnev <sashacmc@gmail.com>
  • Loading branch information
DenisBiryukov91 and sashacmc authored Oct 9, 2024
1 parent 64ae44c commit 33af156
Show file tree
Hide file tree
Showing 67 changed files with 205 additions and 209 deletions.
11 changes: 5 additions & 6 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -893,10 +893,9 @@ Functions
.. autocfunction:: primitives.h::z_put
.. autocfunction:: primitives.h::z_delete
.. autocfunction:: primitives.h::z_declare_publisher
.. autocfunction:: primitives.h::z_publisher_declare
.. autocfunction:: primitives.h::z_publisher_put
.. autocfunction:: primitives.h::z_publisher_delete
.. autocfunction:: primitives.h::z_undeclare_publisher
.. autocfunction:: primitives.h::z_publisher_keyexpr
.. autocfunction:: primitives.h::z_put_options_default
Expand Down Expand Up @@ -936,8 +935,8 @@ Option Types
Functions
---------
.. autocfunction:: primitives.h::z_declare_subscriber
.. autocfunction:: primitives.h::z_undeclare_subscriber
.. autocfunction:: primitives.h::z_subscriber_declare
.. autocfunction:: primitives.h::z_subscriber_declare_background
.. autocfunction:: primitives.h::z_subscriber_options_default
.. autocfunction:: primitives.h::z_subscriber_keyexpr
Expand Down Expand Up @@ -981,8 +980,8 @@ Option Types
Functions
---------
.. autocfunction:: primitives.h::z_declare_queryable
.. autocfunction:: primitives.h::z_undeclare_queryable
.. autocfunction:: primitives.h::z_queryable_declare
.. autocfunction:: primitives.h::z_queryable_declare_background
.. autocfunction:: primitives.h::z_queryable_options_default
.. autocfunction:: primitives.h::z_query_reply_options_default
Expand Down
2 changes: 1 addition & 1 deletion examples/arduino/z_pub.ino
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void setup() {
Serial.println("...");
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) {
if (z_publisher_declare(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) {
Serial.println("Unable to declare publisher for key expression!");
while (1) {
;
Expand Down
2 changes: 1 addition & 1 deletion examples/arduino/z_pull.ino
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void setup() {
z_ring_channel_sample_new(&closure, &handler, SIZE);
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, KEYEXPR);
if (z_declare_subscriber(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&closure),
if (z_subscriber_declare(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&closure),
NULL) < 0) {
Serial.println("Unable to declare subscriber.");
return;
Expand Down
2 changes: 1 addition & 1 deletion examples/arduino/z_queryable.ino
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void setup() {
z_closure_query(&callback, query_handler, NULL, NULL);
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_queryable(&qable, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_query_move(&callback),
if (z_queryable_declare(&qable, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_query_move(&callback),
NULL) < 0) {
Serial.println("Unable to declare queryable.");
while (1) {
Expand Down
2 changes: 1 addition & 1 deletion examples/arduino/z_sub.ino
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void setup() {
z_closure_sample(&callback, data_handler, NULL, NULL);
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_subscriber(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback),
if (z_subscriber_declare(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback),
NULL) < 0) {
Serial.println("Unable to declare subscriber.");
while (1) {
Expand Down
4 changes: 2 additions & 2 deletions examples/espidf/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void app_main() {
z_owned_publisher_t pub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
if (z_publisher_declare(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
exit(-1);
}
Expand All @@ -163,7 +163,7 @@ void app_main() {
}

printf("Closing Zenoh Session...");
z_undeclare_publisher(z_move(pub));
z_drop(z_move(pub));

z_drop(z_move(s));
printf("OK!\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/espidf/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void app_main() {
z_owned_subscriber_t sub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, KEYEXPR);
if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(closure), NULL) < 0) {
if (z_subscriber_declare(&sub, z_loan(s), z_loan(ke), z_move(closure), NULL) < 0) {
printf("Unable to declare subscriber.\n");
exit(-1);
}
Expand All @@ -178,7 +178,7 @@ void app_main() {
}
}

z_undeclare_subscriber(z_move(sub));
z_drop(z_move(sub));
z_drop(z_move(handler));

z_drop(z_move(s));
Expand Down
4 changes: 2 additions & 2 deletions examples/espidf/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void app_main() {
z_owned_queryable_t qable;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
if (z_queryable_declare(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to declare queryable.\n");
exit(-1);
}
Expand All @@ -185,7 +185,7 @@ void app_main() {
}

printf("Closing Zenoh Session...");
z_undeclare_queryable(z_move(qable));
z_drop(z_move(qable));

z_drop(z_move(s));
printf("OK!\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/espidf/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void app_main() {
z_owned_subscriber_t sub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
if (z_subscriber_declare(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to declare subscriber.\n");
exit(-1);
}
Expand All @@ -166,7 +166,7 @@ void app_main() {
}

printf("Closing Zenoh Session...");
z_undeclare_subscriber(z_move(sub));
z_drop(z_move(sub));

z_drop(z_move(s));
printf("OK!\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/freertos_plus_tcp/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void app_main(void) {
z_owned_publisher_t pub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
if (z_publisher_declare(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
return;
}
Expand All @@ -107,7 +107,7 @@ void app_main(void) {
}

// Clean-up
z_undeclare_publisher(z_move(pub));
z_drop(z_move(pub));
z_drop(z_move(s));
}
#else
Expand Down
4 changes: 2 additions & 2 deletions examples/freertos_plus_tcp/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void app_main(void) {
z_owned_publisher_t pub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
if (z_publisher_declare(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
return;
}
Expand All @@ -78,7 +78,7 @@ void app_main(void) {
zp_send_join(z_loan(s), NULL);
}

z_undeclare_publisher(z_move(pub));
z_drop(z_move(pub));

z_drop(z_move(s));
}
Expand Down
4 changes: 2 additions & 2 deletions examples/freertos_plus_tcp/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void app_main(void) {
z_owned_subscriber_t sub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, KEYEXPR);
if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(closure), NULL) < 0) {
if (z_subscriber_declare(&sub, z_loan(s), z_loan(ke), z_move(closure), NULL) < 0) {
printf("Unable to declare subscriber.\n");
return;
}
Expand All @@ -87,7 +87,7 @@ void app_main(void) {
}
}

z_undeclare_subscriber(z_move(sub));
z_drop(z_move(sub));
z_drop(z_move(handler));

z_drop(z_move(s));
Expand Down
4 changes: 2 additions & 2 deletions examples/freertos_plus_tcp/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void app_main(void) {
z_owned_closure_query_t callback;
z_closure(&callback, query_handler);
z_owned_queryable_t qable;
if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
if (z_queryable_declare(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to create queryable.\n");
return;
}
Expand All @@ -96,7 +96,7 @@ void app_main(void) {
z_sleep_s(1);
}

z_undeclare_queryable(z_move(qable));
z_drop(z_move(qable));

z_drop(z_move(s));
}
Expand Down
4 changes: 2 additions & 2 deletions examples/freertos_plus_tcp/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void app_main(void) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
z_owned_subscriber_t sub;
if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
if (z_subscriber_declare(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to declare subscriber.\n");
return;
}
Expand All @@ -76,7 +76,7 @@ void app_main(void) {
z_sleep_s(1);
}

z_undeclare_subscriber(z_move(sub));
z_drop(z_move(sub));

z_drop(z_move(s));
}
Expand Down
4 changes: 2 additions & 2 deletions examples/freertos_plus_tcp/z_sub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void app_main(void) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
z_owned_subscriber_t sub;
if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
if (z_subscriber_declare(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to declare subscriber.\n");
return;
}
Expand All @@ -76,7 +76,7 @@ void app_main(void) {
zp_send_join(z_loan(s), NULL);
}

z_undeclare_subscriber(z_move(sub));
z_drop(z_move(sub));

z_drop(z_move(s));
}
Expand Down
4 changes: 2 additions & 2 deletions examples/mbed/z_pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv) {
z_owned_publisher_t pub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) {
if (z_publisher_declare(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
exit(-1);
}
Expand All @@ -83,7 +83,7 @@ int main(int argc, char **argv) {
}

printf("Closing Zenoh Session...");
z_undeclare_publisher(z_publisher_move(&pub));
z_publisher_drop(z_publisher_move(&pub));

z_session_drop(z_session_move(&s));
printf("OK!\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/mbed/z_pull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(int argc, char **argv) {
z_owned_subscriber_t sub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, KEYEXPR);
if (z_declare_subscriber(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&closure),
if (z_subscriber_declare(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&closure),
NULL) < 0) {
printf("Unable to declare subscriber.\n");
return -1;
Expand Down Expand Up @@ -101,7 +101,7 @@ int main(int argc, char **argv) {
}
}

z_undeclare_subscriber(z_subscriber_move(&sub));
z_subscriber_drop(z_subscriber_move(&sub));
z_ring_handler_sample_drop(z_ring_handler_sample_move(&handler));

z_session_drop(z_session_move(&s));
Expand Down
4 changes: 2 additions & 2 deletions examples/mbed/z_queryable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int main(int argc, char **argv) {
z_owned_queryable_t qable;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_queryable(&qable, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_query_move(&callback),
if (z_queryable_declare(&qable, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_query_move(&callback),
NULL) < 0) {
printf("Unable to declare queryable.\n");
exit(-1);
Expand All @@ -104,7 +104,7 @@ int main(int argc, char **argv) {
}

printf("Closing Zenoh Session...");
z_undeclare_queryable(z_queryable_move(&qable));
z_queryable_drop(z_queryable_move(&qable));

z_session_drop(z_session_move(&s));
printf("OK!\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/mbed/z_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main(int argc, char **argv) {
z_owned_subscriber_t sub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str_unchecked(&ke, KEYEXPR);
if (z_declare_subscriber(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback),
if (z_subscriber_declare(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback),
NULL) < 0) {
printf("Unable to declare subscriber.\n");
exit(-1);
Expand All @@ -87,7 +87,7 @@ int main(int argc, char **argv) {
}

printf("Closing Zenoh Session...");
z_undeclare_subscriber(z_subscriber_move(&sub));
z_subscriber_drop(z_subscriber_move(&sub));

z_session_drop(z_session_move(&s));
printf("OK!\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/unix/c11/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ int main(int argc, char** argv) {
z_view_keyexpr_from_str_unchecked(&pong, "test/pong");

z_owned_publisher_t pub;
if (z_declare_publisher(&pub, z_loan(session), z_loan(ping), NULL) < 0) {
if (z_publisher_declare(&pub, z_loan(session), z_loan(ping), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
return -1;
}

z_owned_closure_sample_t respond;
z_closure(&respond, callback, drop, NULL);
z_owned_subscriber_t sub;
if (z_declare_subscriber(&sub, z_loan(session), z_loan(pong), z_move(respond), NULL) < 0) {
if (z_subscriber_declare(&sub, z_loan(session), z_loan(pong), z_move(respond), NULL) < 0) {
printf("Unable to declare subscriber for key expression.\n");
return -1;
}
Expand Down
7 changes: 2 additions & 5 deletions examples/unix/c11/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main(int argc, char** argv) {
z_view_keyexpr_t pong;
z_view_keyexpr_from_str_unchecked(&pong, "test/pong");
z_owned_publisher_t pub;
if (z_declare_publisher(&pub, z_loan(session), z_loan(pong), NULL) < 0) {
if (z_publisher_declare(&pub, z_loan(session), z_loan(pong), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
return -1;
}
Expand All @@ -60,17 +60,14 @@ int main(int argc, char** argv) {
z_view_keyexpr_from_str_unchecked(&ping, "test/ping");
z_owned_closure_sample_t respond;
z_closure(&respond, callback, drop, (void*)(&pub));
z_owned_subscriber_t sub;
if (z_declare_subscriber(&sub, z_loan(session), z_loan(ping), z_move(respond), NULL) < 0) {
if (z_subscriber_declare_background(z_loan(session), z_loan(ping), z_move(respond), NULL) < 0) {
printf("Unable to declare subscriber for key expression.\n");
return -1;
}

while (getchar() != 'q') {
}

z_drop(z_move(sub));

z_drop(z_move(session));
}
#else
Expand Down
4 changes: 2 additions & 2 deletions examples/unix/c11/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int main(int argc, char **argv) {
z_owned_publisher_t pub;
z_view_keyexpr_t ke;
z_view_keyexpr_from_str(&ke, keyexpr);
if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
if (z_publisher_declare(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
return -1;
}
Expand All @@ -119,7 +119,7 @@ int main(int argc, char **argv) {
z_publisher_put(z_loan(pub), z_move(payload), NULL);
}
// Clean up
z_undeclare_publisher(z_move(pub));
z_drop(z_move(pub));
z_drop(z_move(s));
return 0;
}
Expand Down
Loading

0 comments on commit 33af156

Please sign in to comment.