Skip to content

Commit

Permalink
Add publication token config (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland authored Oct 23, 2023
1 parent 5a1e59f commit 5bd1370
Show file tree
Hide file tree
Showing 28 changed files with 398 additions and 288 deletions.
7 changes: 7 additions & 0 deletions examples/arduino/z_pub.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <WiFi.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
// WiFi-specific parameters
#define SSID "SSID"
#define PASS "PASS"
Expand Down Expand Up @@ -107,3 +108,9 @@ void loop() {

delay(1000);
}
#else
void setup() {
Serial.println("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.");
}
void loop() {}
#endif
6 changes: 6 additions & 0 deletions examples/espidf/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <unistd.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
#define ESP_WIFI_SSID "SSID"
#define ESP_WIFI_PASS "PASS"
#define ESP_MAXIMUM_RETRY 5
Expand Down Expand Up @@ -163,3 +164,8 @@ void app_main() {
z_close(z_move(s));
printf("OK!\n");
}
#else
void app_main() {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
}
#endif
7 changes: 7 additions & 0 deletions examples/mbed/z_pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <randLIB.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
Expand Down Expand Up @@ -85,3 +86,9 @@ int main(int argc, char **argv) {

return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
6 changes: 4 additions & 2 deletions examples/unix/c11/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "zenoh-pico.h"
#include "zenoh-pico/system/platform.h"

#if Z_FEATURE_SUBSCRIPTION == 1
#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1
// WARNING: for the sake of this example we are using "internal" structs and functions (starting with "_").
// Synchronisation primitives are planned to be added to the API in the future.
_z_condvar_t cond;
Expand Down Expand Up @@ -168,7 +168,9 @@ struct args_t parse_args(int argc, char** argv) {
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n");
printf(
"ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example "
"requires them.\n");
return -1;
}
#endif
6 changes: 4 additions & 2 deletions examples/unix/c11/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "stdio.h"
#include "zenoh-pico.h"

#if Z_FEATURE_SUBSCRIPTION == 1
#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1
void callback(const z_sample_t* sample, void* context) {
z_publisher_t pub = z_loan(*(z_owned_publisher_t*)context);
z_publisher_put(pub, sample->payload.start, sample->payload.len, NULL);
Expand Down Expand Up @@ -71,7 +71,9 @@ int main(int argc, char** argv) {
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n");
printf(
"ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example "
"requires them.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/unix/c11/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "zenoh-pico/system/platform.h"

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-pub";
char *const default_value = "Pub from Pico!";
Expand Down Expand Up @@ -117,3 +118,9 @@ int main(int argc, char **argv) {
}
return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/unix/c11/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <unistd.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-pub";
const char *value = "Pub from Pico!";
Expand Down Expand Up @@ -103,3 +104,9 @@ int main(int argc, char **argv) {
free(buf);
return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/unix/c11/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <unistd.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-put";
const char *value = "Pub from Pico!";
Expand Down Expand Up @@ -101,3 +102,9 @@ int main(int argc, char **argv) {
z_close(z_move(s));
return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
6 changes: 4 additions & 2 deletions examples/unix/c99/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "zenoh-pico/api/primitives.h"
#include "zenoh-pico/system/platform.h"

#if Z_FEATURE_SUBSCRIPTION == 1
#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1
_z_condvar_t cond;
_z_mutex_t mutex;

Expand Down Expand Up @@ -168,7 +168,9 @@ struct args_t parse_args(int argc, char** argv) {
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n");
printf(
"ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example "
"requires them.\n");
return -1;
}
#endif
15 changes: 12 additions & 3 deletions examples/unix/c99/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "zenoh-pico.h"
#include "zenoh-pico/api/primitives.h"

#if Z_FEATURE_SUBSCRIPTION == 1
#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1
void callback(const z_sample_t* sample, void* context) {
z_publisher_t pub = z_publisher_loan((z_owned_publisher_t*)context);
z_publisher_put(pub, sample->payload.start, sample->payload.len, NULL);
Expand Down Expand Up @@ -45,7 +45,14 @@ int main(int argc, char** argv) {
printf("Unable to start read and lease tasks");
return -1;
}

#else
int main(void) {
printf(
"ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example "
"requires them.\n");
return -1;
}
#endif
z_keyexpr_t pong = z_keyexpr_unchecked("test/pong");
z_owned_publisher_t pub = z_declare_publisher(z_session_loan(&session), pong, NULL);
if (!z_publisher_check(&pub)) {
Expand Down Expand Up @@ -74,7 +81,9 @@ int main(int argc, char** argv) {
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n");
printf(
"ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example "
"requires them.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/unix/c99/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <unistd.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-pub";
const char *value = "Pub from Pico!";
Expand Down Expand Up @@ -106,3 +107,9 @@ int main(int argc, char **argv) {
free(buf);
return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/unix/c99/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <unistd.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-pub";
const char *value = "Pub from Pico!";
Expand Down Expand Up @@ -103,3 +104,9 @@ int main(int argc, char **argv) {
free(buf);
return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/unix/c99/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <unistd.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-put";
const char *value = "Pub from Pico!";
Expand Down Expand Up @@ -101,3 +102,9 @@ int main(int argc, char **argv) {
z_close(z_session_move(&s));
return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
6 changes: 4 additions & 2 deletions examples/windows/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "zenoh-pico.h"
#include "zenoh-pico/system/platform.h"

#if Z_FEATURE_SUBSCRIPTION == 1
#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1
_z_condvar_t cond;
_z_mutex_t mutex;

Expand Down Expand Up @@ -165,7 +165,9 @@ struct args_t parse_args(int argc, char** argv) {
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n");
printf(
"ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example "
"requires them.\n");
return -1;
}
#endif
6 changes: 4 additions & 2 deletions examples/windows/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "stdio.h"
#include "zenoh-pico.h"

#if Z_FEATURE_SUBSCRIPTION == 1
#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1
void callback(const z_sample_t* sample, void* context) {
z_publisher_t pub = z_loan(*(z_owned_publisher_t*)context);
z_publisher_put(pub, sample->payload.start, sample->payload.len, NULL);
Expand Down Expand Up @@ -71,7 +71,9 @@ int main(int argc, char** argv) {
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this example requires it.\n");
printf(
"ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example "
"requires them.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/windows/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdlib.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
(void)(argc);
(void)(argv);
Expand Down Expand Up @@ -74,3 +75,9 @@ int main(int argc, char **argv) {
free(buf);
return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/windows/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdlib.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
(void)(argc);
(void)(argv);
Expand Down Expand Up @@ -70,3 +71,9 @@ int main(int argc, char **argv) {
free(buf);
return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/windows/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdlib.h>
#include <zenoh-pico.h>

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
(void)(argc);
(void)(argv);
Expand Down Expand Up @@ -68,3 +69,9 @@ int main(int argc, char **argv) {
z_close(z_move(s));
return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
7 changes: 7 additions & 0 deletions examples/zephyr/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define KEYEXPR "demo/example/zenoh-pico-pub"
#define VALUE "[STSTM32]{nucleo-F767ZI} Pub from Zenoh-Pico!"

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
sleep(5);

Expand Down Expand Up @@ -82,3 +83,9 @@ int main(int argc, char **argv) {

return 0;
}
#else
int main(void) {
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_PUBLICATION but this example requires it.\n");
return -1;
}
#endif
Loading

0 comments on commit 5bd1370

Please sign in to comment.