Skip to content

Commit eb95230

Browse files
committed
Keyexpr rework
1 parent d226db9 commit eb95230

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+441
-318
lines changed

examples/arduino/z_get.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void reply_handler(z_owned_reply_t *oreply, void *ctx) {
5151
std::string val((const char *)z_sample_payload(sample)->start, z_sample_payload(sample)->len);
5252

5353
Serial.print(" >> [Get listener] Received (");
54-
Serial.print(z_str_loan(&keystr));
54+
Serial.print(z_str_data(z_str_loan(&keystr)));
5555
Serial.print(", ");
5656
Serial.print(val.c_str());
5757
Serial.println(")");
@@ -118,7 +118,9 @@ void loop() {
118118
}
119119
z_owned_closure_reply_t callback;
120120
z_closure_reply(&callback, reply_handler, reply_dropper, NULL);
121-
if (z_get(z_session_loan(&s), z_keyexpr(KEYEXPR), "", z_closure_reply_move(&callback), &opts) < 0) {
121+
z_view_keyexpr_t ke;
122+
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
123+
if (z_get(z_session_loan(&s), z_view_keyexpr_loan(&ke), "", z_closure_reply_move(&callback), &opts) < 0) {
122124
Serial.println("Unable to send query.");
123125
}
124126
}

examples/arduino/z_pub.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ void setup() {
8181
Serial.print("Declaring publisher for ");
8282
Serial.print(KEYEXPR);
8383
Serial.println("...");
84-
if (z_declare_publisher(&pub, z_session_loan(&s), z_keyexpr(KEYEXPR), NULL) < 0) {
84+
z_view_keyexpr_t ke;
85+
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
86+
if (z_declare_publisher(&pub, z_session_loan(&s), z_view_keyexpr_loan(&ke), NULL) < 0) {
8587
Serial.println("Unable to declare publisher for key expression!");
8688
while (1) {
8789
;

examples/arduino/z_pull.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
// std::string val((const char *)sample->payload.start, sample->payload.len);
4545

4646
// Serial.print(" >> [Subscription listener] Received (");
47-
// Serial.print(z_str_loan(&keystr));
47+
// Serial.print(z_str_data(z_str_loan(&keystr)));
4848
// Serial.print(", ");
4949
// Serial.print(val.c_str());
5050
// Serial.println(")");
@@ -99,8 +99,10 @@ void setup() {
9999
// z_owned_closure_sample_t callback;
100100
// z_closure_sample(&callback, data_handler, NULL, NULL);
101101
// @TODO
102-
// sub = z_declare_pull_subscriber(z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL);
103-
// if (!z_pull_subscriber_check(&sub)) {
102+
// z_view_keyexpr_t ke;
103+
// z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
104+
// sub = z_declare_pull_subscriber(z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback),
105+
// NULL); if (!z_pull_subscriber_check(&sub)) {
104106
// Serial.println("Unable to declare subscriber.");
105107
// while (1) {
106108
// ;

examples/arduino/z_queryable.ino

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ void query_handler(const z_loaned_query_t *query, void *arg) {
4040
z_keyexpr_to_string(z_query_keyexpr(query), &keystr);
4141

4242
Serial.print(" >> [Queryable handler] Replying Data ('");
43-
Serial.print(z_str_loan(&keystr));
43+
Serial.print(z_str_data(z_str_loan(&keystr)));
4444
Serial.print("': '");
4545
Serial.print(VALUE);
4646
Serial.println("')");
4747

48-
z_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), NULL);
48+
z_view_keyexpr_t ke;
49+
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
50+
z_query_reply(query, z_view_keyexpr_loan(&ke), (const unsigned char *)VALUE, strlen(VALUE), NULL);
4951

5052
z_str_drop(z_str_move(&keystr));
5153
}
@@ -96,8 +98,10 @@ void setup() {
9698
z_owned_closure_query_t callback;
9799
z_closure_query(&callback, query_handler, NULL, NULL);
98100
z_owned_queryable_t qable;
99-
if (z_declare_queryable(&qable, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_query_move(&callback), NULL) <
100-
0) {
101+
z_view_keyexpr_t ke;
102+
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
103+
if (z_declare_queryable(&qable, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_query_move(&callback),
104+
NULL) < 0) {
101105
Serial.println("Unable to declare queryable.");
102106
while (1) {
103107
;

examples/arduino/z_scout.ino

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,27 @@ void fprintwhatami(unsigned int whatami) {
5656

5757
void fprintlocators(const z_str_array_t *locs) {
5858
Serial.print("[");
59-
size_t len = z_str_array_len(locs);
60-
for (unsigned int i = 0; i < len; i++) {
61-
Serial.print("'");
62-
Serial.print(*z_str_array_get(locs, i));
63-
Serial.print("'");
64-
if (i < len - 1) {
65-
Serial.print(", ");
66-
}
67-
}
59+
(void)locs;
60+
// TODO(sashacmc): z_str_array_t
61+
// size_t len = z_str_array_len(locs);
62+
// for (unsigned int i = 0; i < len; i++) {
63+
// Serial.print("'");
64+
// Serial.print(*z_str_array_get(locs, i));
65+
// Serial.print("'");
66+
// if (i < len - 1) {
67+
// Serial.print(", ");
68+
// }
69+
//}
6870
Serial.print("]");
6971
}
7072

71-
void fprinthello(const z_hello_t hello) {
73+
void fprinthello(const z_loaned_hello_t *hello) {
7274
Serial.print(" >> Hello { zid: ");
73-
fprintzid(hello.zid);
75+
fprintzid(hello->zid);
7476
Serial.print(", whatami: ");
75-
fprintwhatami(hello.whatami);
77+
fprintwhatami(hello->whatami);
7678
Serial.print(", locators: ");
77-
fprintlocators(&hello.locators);
79+
fprintlocators(&hello->locators);
7880
Serial.println(" }");
7981
}
8082

examples/arduino/z_sub.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void data_handler(const z_loaned_sample_t *sample, void *arg) {
4040
std::string val((const char *)z_sample_payload(sample)->start, z_sample_payload(sample)->len);
4141

4242
Serial.print(" >> [Subscription listener] Received (");
43-
Serial.print(z_str_loan(&keystr));
43+
Serial.print(z_str_data(z_str_loan(&keystr)));
4444
Serial.print(", ");
4545
Serial.print(val.c_str());
4646
Serial.println(")");
@@ -94,8 +94,10 @@ void setup() {
9494
z_owned_closure_sample_t callback;
9595
z_closure_sample(&callback, data_handler, NULL, NULL);
9696
z_owned_subscriber_t sub;
97-
if (z_declare_subscriber(&sub, z_session_loan(&s), z_keyexpr(KEYEXPR), z_closure_sample_move(&callback), NULL) <
98-
0) {
97+
z_view_keyexpr_t ke;
98+
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
99+
if (z_declare_subscriber(&sub, z_session_loan(&s), z_view_keyexpr_loan(&ke), z_closure_sample_move(&callback),
100+
NULL) < 0) {
99101
Serial.println("Unable to declare subscriber.");
100102
while (1) {
101103
;

examples/espidf/z_get.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ void app_main() {
165165
}
166166
z_owned_closure_reply_t callback;
167167
z_closure(&callback, reply_handler, reply_dropper);
168-
if (z_get(z_loan(s), z_keyexpr(KEYEXPR), "", z_move(callback), &opts) < 0) {
168+
z_view_keyexpr_t ke;
169+
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
170+
if (z_get(z_loan(s), z_loan(ke), "", z_move(callback), &opts) < 0) {
169171
printf("Unable to send query.\n");
170172
exit(-1);
171173
}

examples/espidf/z_pub.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ void app_main() {
141141

142142
printf("Declaring publisher for '%s'...", KEYEXPR);
143143
z_owned_publisher_t pub;
144-
if (z_declare_publisher(&pub, z_loan(s), z_keyexpr(KEYEXPR), NULL) < 0) {
144+
z_view_keyexpr_t ke;
145+
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
146+
if (z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL) < 0) {
145147
printf("Unable to declare publisher for key expression!\n");
146148
exit(-1);
147149
}

examples/espidf/z_pull.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ void app_main() {
153153
// z_closure(&callback, data_handler);
154154
printf("Declaring Subscriber on '%s'...", KEYEXPR);
155155
// @TODO
156-
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL);
156+
// z_view_keyexpr_t ke;
157+
// z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
158+
// z_owned_pull_subscriber_t sub = z_declare_pull_subscriber(z_loan(s), z_loan(ke), z_move(callback), NULL);
157159
// if (!z_check(sub)) {
158160
// printf("Unable to declare subscriber.\n");
159161
// exit(-1);

examples/espidf/z_queryable.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ void wifi_init_sta(void) {
101101
vEventGroupDelete(s_event_group_handler);
102102
}
103103

104-
void query_handler(z_query_t *query, void *ctx) {
104+
void query_handler(const z_loaned_query_t *query, void *ctx) {
105105
(void)(ctx);
106106
z_owned_str_t keystr;
107-
z_keyexpr_to_string(z_query_keyexpr(query), &keystr);
108-
z_bytes_t pred = z_query_parameters(query);
109-
printf(">> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), (int)pred.len, pred.start);
110-
z_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), NULL);
107+
// TODO(sashacmc): z_query_parameters
108+
// z_keyexpr_to_string(z_query_keyexpr(query), &keystr);
109+
// z_bytes_t pred = z_query_parameters(query);
110+
// printf(">> [Queryable handler] Received Query '%s%.*s'\n", z_str_data(z_loan(keystr)), (int)pred.len,
111+
// pred.start);
112+
z_view_keyexpr_t ke;
113+
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
114+
z_query_reply(query, z_loan(ke), (const unsigned char *)VALUE, strlen(VALUE), NULL);
111115
z_drop(z_move(keystr));
112116
}
113117

@@ -154,7 +158,9 @@ void app_main() {
154158
z_owned_closure_query_t callback;
155159
z_closure(&callback, query_handler);
156160
z_owned_queryable_t qable;
157-
if (z_declare_queryable(&qable, z_loan(s), z_keyexpr(KEYEXPR), z_move(callback), NULL) < 0) {
161+
z_view_keyexpr_t ke;
162+
z_view_keyexpr_from_string_unchecked(&ke, KEYEXPR);
163+
if (z_declare_queryable(&qable, z_loan(s), z_loan(ke), z_move(callback), NULL) < 0) {
158164
printf("Unable to declare queryable.\n");
159165
exit(-1);
160166
}

0 commit comments

Comments
 (0)