Skip to content

Commit

Permalink
Keyexpr rework
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed May 17, 2024
1 parent d226db9 commit 07499d5
Show file tree
Hide file tree
Showing 73 changed files with 314 additions and 202 deletions.
4 changes: 3 additions & 1 deletion examples/arduino/z_get.ino
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ void loop() {
}
z_owned_closure_reply_t callback;
z_closure_reply(&callback, reply_handler, reply_dropper, NULL);
if (z_get(z_session_loan(&s), z_keyexpr(KEYEXPR), "", z_closure_reply_move(&callback), &opts) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_get(z_session_loan(&s), z_view_keyexpr_loan(ke), "", z_closure_reply_move(&callback), &opts) < 0) {
Serial.println("Unable to send query.");
}
}
Expand Down
4 changes: 3 additions & 1 deletion examples/arduino/z_pub.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ void setup() {
Serial.print("Declaring publisher for ");
Serial.print(KEYEXPR);
Serial.println("...");
if (z_declare_publisher(&pub, z_session_loan(&s), z_keyexpr(KEYEXPR), NULL) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&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
6 changes: 4 additions & 2 deletions examples/arduino/z_pull.ino
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ void setup() {
// z_owned_closure_sample_t callback;
// z_closure_sample(&callback, data_handler, NULL, NULL);
// @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)) {
// z_view_keyexpr_t ke;
// z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
// sub = z_declare_pull_subscriber(z_session_loan(&s), z_view_keyexpr_loan(ke), z_closure_sample_move(&callback),
// NULL); if (!z_pull_subscriber_check(&sub)) {
// Serial.println("Unable to declare subscriber.");
// while (1) {
// ;
Expand Down
10 changes: 7 additions & 3 deletions examples/arduino/z_queryable.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ void query_handler(const z_loaned_query_t *query, void *arg) {
Serial.print(VALUE);
Serial.println("')");

z_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), NULL);
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
z_query_reply(query, z_view_keyexpr_loan(ke), (const unsigned char *)VALUE, strlen(VALUE), NULL);

z_str_drop(z_str_move(&keystr));
}
Expand Down Expand Up @@ -96,8 +98,10 @@ void setup() {
z_owned_closure_query_t callback;
z_closure_query(&callback, query_handler, NULL, NULL);
z_owned_queryable_t qable;
if (z_declare_queryable(&qable, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_query_move(&callback), NULL) <
0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_queryable(&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
6 changes: 4 additions & 2 deletions examples/arduino/z_sub.ino
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ void setup() {
z_owned_closure_sample_t callback;
z_closure_sample(&callback, data_handler, NULL, NULL);
z_owned_subscriber_t sub;
if (z_declare_subscriber(&sub, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL) <
0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_subscriber(&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: 3 additions & 1 deletion examples/espidf/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ void app_main() {
}
z_owned_closure_reply_t callback;
z_closure(&callback, reply_handler, reply_dropper);
if (z_get(z_loan(s), z_keyexpr(KEYEXPR), "", z_move(callback), &opts) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_get(z_loan(s), z_loan(ke), "", z_move(callback), &opts) < 0) {
printf("Unable to send query.\n");
exit(-1);
}
Expand Down
4 changes: 3 additions & 1 deletion examples/espidf/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ void app_main() {

printf("Declaring publisher for '%s'...", KEYEXPR);
z_owned_publisher_t pub;
if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(KEYEXPR), NULL) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
exit(-1);
}
Expand Down
4 changes: 3 additions & 1 deletion examples/espidf/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ void app_main() {
// z_closure(&callback, data_handler);
printf("Declaring Subscriber on '%s'...", KEYEXPR);
// @TODO
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL);
// z_view_keyexpr_t ke;
// z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_loan(ke), z_move(callback), NULL);
// if (!z_check(sub)) {
// printf("Unable to declare subscriber.\n");
// exit(-1);
Expand Down
8 changes: 6 additions & 2 deletions examples/espidf/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ void query_handler(z_query_t *query, void *ctx) {
z_keyexpr_to_string(z_query_keyexpr(query), &keystr);
z_bytes_t pred = z_query_parameters(query);
printf(">> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), (int)pred.len, pred.start);
z_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), NULL);
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
z_query_reply(query, z_loan(ke), (const unsigned char *)VALUE, strlen(VALUE), NULL);
z_drop(z_move(keystr));
}

Expand Down Expand Up @@ -154,7 +156,9 @@ void app_main() {
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_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to declare queryable.\n");
exit(-1);
}
Expand Down
4 changes: 3 additions & 1 deletion examples/espidf/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ void app_main() {
z_owned_closure_sample_t callback;
z_closure(&callback, data_handler);
z_owned_subscriber_t sub;
if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to declare subscriber.\n");
exit(-1);
}
Expand Down
10 changes: 5 additions & 5 deletions examples/freertos_plus_tcp/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ void app_main(void) {
return;
}

z_keyexpr_t ke = z_keyexpr(KEYEXPR);
if (!z_check(ke)) {
printf("%s is not a valid key expression\n", KEYEXPR);
return;
z_view_keyexpr_t ke;
if (z_view_keyexpr_from_string(&ke, KEYEXPR) < 0) {
printf("%s is not a valid key expression", keyexpr);
return -1;
}

while (1) {
Expand All @@ -88,7 +88,7 @@ void app_main(void) {
}
z_owned_closure_reply_t callback;
z_closure(&callback, reply_handler, reply_dropper);
if (z_get(z_loan(s), ke, "", z_move(callback), &opts) < 0) {
if (z_get(z_loan(s), z_loan(ke), "", z_move(callback), &opts) < 0) {
printf("Unable to send query.\n");
return;
}
Expand Down
4 changes: 3 additions & 1 deletion examples/freertos_plus_tcp/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ void app_main(void) {

printf("Declaring publisher for '%s'...\n", KEYEXPR);
z_owned_publisher_t pub;
if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(KEYEXPR), NULL) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
return;
}
Expand Down
4 changes: 3 additions & 1 deletion examples/freertos_plus_tcp/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ void app_main(void) {

printf("Declaring publisher for '%s'...\n", KEYEXPR);
z_owned_publisher_t pub;
if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(KEYEXPR), NULL) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
return;
}
Expand Down
4 changes: 3 additions & 1 deletion examples/freertos_plus_tcp/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ void app_main(void) {
// z_closure(&callback, data_handler);
printf("Declaring Subscriber on '%s'...\n", KEYEXPR);
// @TODO
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL);
// z_view_keyexpr_t ke;
// z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_loan(ke), z_move(callback), NULL);
// if (!z_check(sub)) {
// printf("Unable to declare subscriber.\n");
// return;
Expand Down
4 changes: 3 additions & 1 deletion examples/freertos_plus_tcp/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ void app_main(void) {

printf("Declaring key expression '%s'...\n", KEYEXPR);
z_owned_keyexpr_t ke;
if (z_declare_keyexpr(&ke, z_loan(s), z_keyexpr(KEYEXPR)) < 0) {
z_view_keyexpr_t vke;
z_view_keyexpr_from_string_unchecked(&vke, KEYEXPR);
if (z_declare_keyexpr(&ke, z_loan(s), z_loan(vke)) < 0) {
printf("Unable to declare key expression!\n");
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
Expand Down
12 changes: 6 additions & 6 deletions examples/freertos_plus_tcp/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) {
z_query_reply_options_t options;
z_query_reply_options_default(&options);
options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL);
z_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), &options);
z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)VALUE, strlen(VALUE), &options);
z_drop(z_move(keystr));
}

Expand All @@ -68,17 +68,17 @@ void app_main(void) {
return;
}

z_keyexpr_t ke = z_keyexpr(KEYEXPR);
if (!z_check(ke)) {
printf("%s is not a valid key expression\n", KEYEXPR);
return;
z_view_keyexpr_t ke;
if (z_view_keyexpr_from_string(&ke, KEYEXPR) < 0) {
printf("%s is not a valid key expression", keyexpr);
return -1;
}

printf("Creating Queryable on '%s'...\n", KEYEXPR);
z_owned_closure_query_t callback;
z_closure(&callback, query_handler);
z_owned_queryable_t qable;
if (z_declare_queryable(&qable, z_loan(s), ke, z_move(callback), NULL) < 0) {
if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to create queryable.\n");
return;
}
Expand Down
4 changes: 3 additions & 1 deletion examples/freertos_plus_tcp/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ void app_main(void) {
z_owned_closure_sample_t callback;
z_closure(&callback, data_handler);
printf("Declaring Subscriber on '%s'...\n", KEYEXPR);
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
z_owned_subscriber_t sub;
if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) {
if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to declare subscriber.\n");
return;
}
Expand Down
4 changes: 3 additions & 1 deletion examples/freertos_plus_tcp/z_sub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ void app_main(void) {
z_owned_closure_sample_t callback;
z_closure(&callback, data_handler);
printf("Declaring Subscriber on '%s'...\n", KEYEXPR);
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
z_owned_subscriber_t sub;
if (z_declare_subscriber(&sub, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) {
if (z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
printf("Unable to declare subscriber.\n");
return;
}
Expand Down
4 changes: 3 additions & 1 deletion examples/mbed/z_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ int main(int argc, char **argv) {
}
z_owned_closure_reply_t callback;
z_closure_reply(&callback, reply_handler, reply_dropper, NULL);
if (z_get(z_session_loan(&s), z_keyexpr(KEYEXPR), "", z_closure_reply_move(&callback), &opts) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_get(z_session_loan(&s), z_view_keyexpr_loan(&ke), "", z_closure_reply_move(&callback), &opts) < 0) {
printf("Unable to send query.\n");
exit(-1);
}
Expand Down
4 changes: 3 additions & 1 deletion examples/mbed/z_pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ int main(int argc, char **argv) {

printf("Declaring publisher for '%s'...", KEYEXPR);
z_owned_publisher_t pub;
if (z_declare_publisher(&pub, z_session_loan(&s), z_keyexpr(KEYEXPR), NULL) < 0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_publisher(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) {
printf("Unable to declare publisher for key expression!\n");
exit(-1);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/mbed/z_pull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char **argv) {
printf("Declaring Subscriber on '%s'...", KEYEXPR);
// @TODO
// z_owned_pull_subscriber_t sub =
// z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL);
// z_declare_pull_subscriber(z_session_loan(&s), z_loan(ke), z_closure_sample_move(&callback), NULL);
// if (!z_pull_subscriber_check(&sub)) {
// printf("Unable to declare subscriber.\n");
// exit(-1);
Expand Down
8 changes: 5 additions & 3 deletions examples/mbed/z_queryable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void query_handler(const z_loaned_query_t *query, void *ctx) {
z_query_parameters(query, &pred);
printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_str_loan(&keystr)),
(int)z_view_str_loan(&pred)->len, z_view_str_loan(&pred)->val);
z_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), NULL);
z_query_reply(query, z_query_keyexpr(query), (const unsigned char *)VALUE, strlen(VALUE), NULL);
z_str_drop(z_str_move(&keystr));
}

Expand Down Expand Up @@ -76,8 +76,10 @@ int main(int argc, char **argv) {
z_owned_closure_query_t callback;
z_closure_query(&callback, query_handler, NULL, NULL);
z_owned_queryable_t qable;
if (z_declare_queryable(&qable, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_query_move(&callback), NULL) <
0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_queryable(&qable, z_session_loan(&s), z_view_keyepr_loan(&ke), z_closure_query_move(&callback),
NULL) < 0) {
printf("Unable to declare queryable.\n");
exit(-1);
}
Expand Down
6 changes: 4 additions & 2 deletions examples/mbed/z_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ int main(int argc, char **argv) {
z_owned_closure_sample_t callback;
z_closure_sample(&callback, data_handler, NULL, NULL);
z_owned_subscriber_t sub;
if (z_declare_subscriber(&sub, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL) <
0) {
z_view_keyexpr_t ke;
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
if (z_declare_subscriber(&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 Down
13 changes: 6 additions & 7 deletions examples/unix/c11/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ int main(int argc, char **argv) {
return -1;
}

// TODO(sashacmc):
// z_keyexpr_t ke = z_keyexpr(keyexpr);
// if (!z_check(ke)) {
// printf("%s is not a valid key expression", keyexpr);
// return -1;
// }
z_view_keyexpr_t ke;
if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) {
printf("%s is not a valid key expression", keyexpr);
return -1;
}

z_mutex_lock(&mutex);
printf("Sending Query '%s'...\n", keyexpr);
Expand All @@ -143,7 +142,7 @@ int main(int argc, char **argv) {

z_owned_closure_reply_t callback;
z_closure(&callback, reply_handler, reply_dropper);
if (z_get(z_loan(s), z_keyexpr(keyexpr), "", z_move(callback), &opts) < 0) {
if (z_get(z_loan(s), z_loan(ke), "", z_move(callback), &opts) < 0) {
printf("Unable to send query.\n");
return -1;
}
Expand Down
13 changes: 6 additions & 7 deletions examples/unix/c11/z_get_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ int main(int argc, char **argv) {
return -1;
}

// TODO(sashacmc):
// z_keyexpr_t ke = z_keyexpr(keyexpr);
// if (!z_check(ke)) {
// printf("%s is not a valid key expression", keyexpr);
// return -1;
// }
z_view_keyexpr_t ke;
if (z_view_keyexpr_from_string(&ke, keyexpr) < 0) {
printf("%s is not a valid key expression", keyexpr);
return -1;
}

printf("Sending Query '%s'...\n", keyexpr);
z_get_options_t opts;
Expand All @@ -96,7 +95,7 @@ int main(int argc, char **argv) {
}
z_owned_reply_ring_channel_t channel;
z_reply_ring_channel_new(&channel, 1);
if (z_get(z_loan(s), z_keyexpr(keyexpr), "", z_move(channel.send), &opts) < 0) {
if (z_get(z_loan(s), z_loan(ke), "", z_move(channel.send), &opts) < 0) {
printf("Unable to send query.\n");
return -1;
}
Expand Down
Loading

0 comments on commit 07499d5

Please sign in to comment.