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

Protocol cleanup #374

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
24 changes: 13 additions & 11 deletions examples/arduino/z_pull.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#define KEYEXPR "demo/example/**"

z_owned_pull_subscriber_t sub;
// z_owned_pull_subscriber_t sub;

void data_handler(const z_sample_t *sample, void *arg) {
z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr);
Expand Down Expand Up @@ -92,22 +92,24 @@ void setup() {
Serial.print(KEYEXPR);
Serial.println(" ...");
z_owned_closure_sample_t callback = z_closure_sample(data_handler, NULL, NULL);
sub = z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL);
if (!z_pull_subscriber_check(&sub)) {
Serial.println("Unable to declare subscriber.");
while (1) {
;
}
}
Serial.println("OK");
Serial.println("Zenoh setup finished!");
// @TODO
// sub = z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL);
// if (!z_pull_subscriber_check(&sub)) {
// Serial.println("Unable to declare subscriber.");
// while (1) {
// ;
// }
// }
// Serial.println("OK");
// Serial.println("Zenoh setup finished!");
Serial.println("Pull Subscriber not supported... exiting");

delay(300);
}

void loop() {
delay(5000);
z_subscriber_pull(z_pull_subscriber_loan(&sub));
// z_subscriber_pull(z_pull_subscriber_loan(&sub));
}
#else
void setup() {
Expand Down
32 changes: 17 additions & 15 deletions examples/espidf/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,23 @@ void app_main() {

printf("Declaring Subscriber on '%s'...", KEYEXPR);
z_owned_closure_sample_t callback = z_closure(data_handler);
z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL);
if (!z_check(sub)) {
printf("Unable to declare subscriber.\n");
exit(-1);
}
printf("OK!\n");

while (1) {
sleep(5);
printf("Pulling data from '%s'...\n", KEYEXPR);
z_subscriber_pull(z_loan(sub));
}

printf("Closing Zenoh Session...");
z_undeclare_pull_subscriber(z_move(sub));
// @TODO
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL);
// if (!z_check(sub)) {
// printf("Unable to declare subscriber.\n");
// exit(-1);
// }
// printf("OK!\n");

// while (1) {
// sleep(5);
// printf("Pulling data from '%s'...\n", KEYEXPR);
// z_subscriber_pull(z_loan(sub));
// }

// printf("Closing Zenoh Session...");
// z_undeclare_pull_subscriber(z_move(sub));
printf("Pull Subscriber not supported... exiting\n");

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_loan(s));
Expand Down
24 changes: 13 additions & 11 deletions examples/freertos_plus_tcp/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,21 @@ void app_main(void) {

z_owned_closure_sample_t callback = z_closure(data_handler);
printf("Declaring Subscriber on '%s'...\n", KEYEXPR);
z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL);
if (!z_check(sub)) {
printf("Unable to declare subscriber.\n");
return;
}
// @TODO
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL);
// if (!z_check(sub)) {
// printf("Unable to declare subscriber.\n");
// return;
// }

while (1) {
zp_sleep_s(5);
printf("Pulling data from '%s'...\n", KEYEXPR);
z_subscriber_pull(z_loan(sub));
}
// while (1) {
// zp_sleep_s(5);
// printf("Pulling data from '%s'...\n", KEYEXPR);
// z_subscriber_pull(z_loan(sub));
// }

z_undeclare_pull_subscriber(z_move(sub));
// z_undeclare_pull_subscriber(z_move(sub));
printf("Pull Subscriber not supported... exiting\n");

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan(s));
Expand Down
30 changes: 16 additions & 14 deletions examples/mbed/z_pull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,24 @@ int main(int argc, char **argv) {

printf("Declaring Subscriber on '%s'...", KEYEXPR);
z_owned_closure_sample_t callback = z_closure_sample(data_handler, NULL, NULL);
z_owned_pull_subscriber_t sub =
z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL);
if (!z_pull_subscriber_check(&sub)) {
printf("Unable to declare subscriber.\n");
exit(-1);
}
printf("OK!\n");
// @TODO
// z_owned_pull_subscriber_t sub =
// z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL);
// if (!z_pull_subscriber_check(&sub)) {
// printf("Unable to declare subscriber.\n");
// exit(-1);
// }
// printf("OK!\n");

while (1) {
zp_sleep_s(5);
printf("Pulling data from '%s'...\n", KEYEXPR);
z_subscriber_pull(z_pull_subscriber_loan(&sub));
}
// while (1) {
// zp_sleep_s(5);
// printf("Pulling data from '%s'...\n", KEYEXPR);
// z_subscriber_pull(z_pull_subscriber_loan(&sub));
// }

printf("Closing Zenoh Session...");
z_undeclare_pull_subscriber(z_pull_subscriber_move(&sub));
// printf("Closing Zenoh Session...");
// z_undeclare_pull_subscriber(z_pull_subscriber_move(&sub));
printf("Pull Subscriber not supported... exiting\n");

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_session_loan(&s));
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c11/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
return -1;
}

printf("Enter any key to pull data or 'q' to quit...\n");
printf("Enter any key to get data or 'q' to quit...\n");

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
char c = '\0';
while (1) {
fflush(stdin);
Expand Down
37 changes: 20 additions & 17 deletions examples/unix/c11/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,28 @@

z_owned_closure_sample_t callback = z_closure(data_handler);
printf("Declaring Subscriber on '%s'...\n", keyexpr);
z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL);
if (!z_check(sub)) {
printf("Unable to declare subscriber.\n");
return -1;
}

printf("Enter any key to pull data or 'q' to quit...\n");
char c = '\0';
while (1) {
fflush(stdin);
int ret = scanf("%c", &c);
(void)ret; // Remove unused result warning
if (c == 'q') {
break;
}
z_subscriber_pull(z_loan(sub));
}
// @TODO
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL);
// if (!z_check(sub)) {
// printf("Unable to declare subscriber.\n");
// return -1;
// }

// printf("Enter any key to pull data or 'q' to quit...\n");
// char c = '\0';
// while (1) {
// fflush(stdin);
// int ret = scanf("%c", &c);
// (void)ret; // Remove unused result warning
// if (c == 'q') {
// break;
// }
// z_subscriber_pull(z_loan(sub));
// }

z_undeclare_pull_subscriber(z_move(sub));
// z_undeclare_pull_subscriber(z_move(sub));
printf("Pull Subscriber not supported... exiting\n");

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan(s));
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c99/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
return -1;
}

printf("Enter any key to pull data or 'q' to quit...\n");
printf("Enter any key to get data or 'q' to quit...\n");
Dismissed Show dismissed Hide dismissed
char c = '\0';
while (1) {
fflush(stdin);
Expand Down
38 changes: 20 additions & 18 deletions examples/unix/c99/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,28 @@

z_owned_closure_sample_t callback = z_closure_sample(data_handler, NULL, NULL);
printf("Declaring Subscriber on '%s'...\n", keyexpr);
z_owned_pull_subscriber_t sub =
z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(keyexpr), z_closure_sample_move(&callback), NULL);
if (!z_pull_subscriber_check(&sub)) {
printf("Unable to declare subscriber.\n");
return -1;
}
// @TODO
// z_owned_pull_subscriber_t sub =
// z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(keyexpr), z_closure_sample_move(&callback), NULL);
// if (!z_pull_subscriber_check(&sub)) {
// printf("Unable to declare subscriber.\n");
// return -1;
// }

printf("Enter any key to pull data or 'q' to quit...\n");
char c = '\0';
while (1) {
fflush(stdin);
int ret = scanf("%c", &c);
(void)ret; // Clear unused result warning
if (c == 'q') {
break;
}
z_subscriber_pull(z_pull_subscriber_loan(&sub));
}
// printf("Enter any key to pull data or 'q' to quit...\n");
// char c = '\0';
// while (1) {
// fflush(stdin);
// int ret = scanf("%c", &c);
// (void)ret; // Clear unused result warning
// if (c == 'q') {
// break;
// }
// z_subscriber_pull(z_pull_subscriber_loan(&sub));
// }

z_undeclare_pull_subscriber(z_pull_subscriber_move(&sub));
// z_undeclare_pull_subscriber(z_pull_subscriber_move(&sub));
printf("Pull Subscriber not supported... exiting\n");
Dismissed Show dismissed Hide dismissed

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_session_loan(&s));
Expand Down
2 changes: 1 addition & 1 deletion examples/windows/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
return -1;
}

printf("Enter any key to pull data or 'q' to quit...\n");
printf("Enter any key to get data or 'q' to quit...\n");

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
char c = '\0';
while (1) {
fflush(stdin);
Expand Down
34 changes: 18 additions & 16 deletions examples/windows/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,26 @@

z_owned_closure_sample_t callback = z_closure(data_handler);
printf("Declaring Subscriber on '%s'...\n", keyexpr);
z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL);
if (!z_check(sub)) {
printf("Unable to declare subscriber.\n");
return -1;
}
// @TODO
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(keyexpr), z_move(callback), NULL);
// if (!z_check(sub)) {
// printf("Unable to declare subscriber.\n");
// return -1;
// }

printf("Enter any key to pull data or 'q' to quit...\n");
char c = '\0';
while (1) {
fflush(stdin);
scanf("%c", &c);
if (c == 'q') {
break;
}
z_subscriber_pull(z_loan(sub));
}
// printf("Enter any key to pull data or 'q' to quit...\n");
// char c = '\0';
// while (1) {
// fflush(stdin);
// scanf("%c", &c);
// if (c == 'q') {
// break;
// }
// z_subscriber_pull(z_loan(sub));
// }

z_undeclare_pull_subscriber(z_move(sub));
// z_undeclare_pull_subscriber(z_move(sub));
printf("Pull Subscriber not supported... exiting\n");

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan(s));
Expand Down
28 changes: 15 additions & 13 deletions examples/zephyr/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,23 @@

printf("Declaring Subscriber on '%s'...", KEYEXPR);
z_owned_closure_sample_t callback = z_closure(data_handler);
z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL);
if (!z_check(sub)) {
printf("Unable to declare subscriber.\n");
exit(-1);
}
printf("OK!\n");
// @TODO
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL);
// if (!z_check(sub)) {
// printf("Unable to declare subscriber.\n");
// exit(-1);
// }
// printf("OK!\n");

while (1) {
sleep(5);
printf("Pulling data from '%s'...\n", KEYEXPR);
z_subscriber_pull(z_loan(sub));
}
// while (1) {
// sleep(5);
// printf("Pulling data from '%s'...\n", KEYEXPR);
// z_subscriber_pull(z_loan(sub));
// }

printf("Closing Zenoh Session...");
z_undeclare_pull_subscriber(z_move(sub));
// printf("Closing Zenoh Session...");
// z_undeclare_pull_subscriber(z_move(sub));
printf("Pull Subscriber not supported... exiting\n");
Fixed Show fixed Hide fixed

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_loan(s));
Expand Down
10 changes: 0 additions & 10 deletions include/zenoh-pico/api/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,6 @@ typedef enum {
} z_priority_t;
#define Z_PRIORITY_DEFAULT Z_PRIORITY_DATA

/**
* Subscription mode values.
*
* Enumerators:
* Z_SUBMODE_PUSH: Defines the subscription with a push paradigm.
* Z_SUBMODE_PULL: Defines the subscription with a pull paradigm.
*/
typedef enum { Z_SUBMODE_PUSH = 0, Z_SUBMODE_PULL = 1 } z_submode_t;
#define Z_SUBMODE_DEFAULT Z_SUBMODE_PUSH

/**
* Query target values.
*
Expand Down
Loading
Loading