Code Review
/
src
/
app-framework-binder.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Add gitreview file for Kooky Koi branch
[src/app-framework-binder.git]
/
src
/
afb-proto-ws.c
diff --git
a/src/afb-proto-ws.c
b/src/afb-proto-ws.c
index
f19924f
..
3365d60
100644
(file)
--- a/
src/afb-proto-ws.c
+++ b/
src/afb-proto-ws.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2015-20
19
"IoT.bzh"
+ * Copyright (C) 2015-20
20
"IoT.bzh"
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@
-67,6
+67,8
@@
For the purpose of handling events the server can:
- push or broadcast data as an event
- push or broadcast data as an event
+ - signal unexpected event
+
*/
/************** constants for protocol definition *************************/
*/
/************** constants for protocol definition *************************/
@@
-78,6
+80,7
@@
For the purpose of handling events the server can:
#define CHAR_FOR_EVT_PUSH 'P' /* server -> client */
#define CHAR_FOR_EVT_SUBSCRIBE 'X' /* server -> client */
#define CHAR_FOR_EVT_UNSUBSCRIBE 'x' /* server -> client */
#define CHAR_FOR_EVT_PUSH 'P' /* server -> client */
#define CHAR_FOR_EVT_SUBSCRIBE 'X' /* server -> client */
#define CHAR_FOR_EVT_UNSUBSCRIBE 'x' /* server -> client */
+#define CHAR_FOR_EVT_UNEXPECTED 'U' /* client -> server */
#define CHAR_FOR_DESCRIBE 'D' /* client -> server */
#define CHAR_FOR_DESCRIPTION 'd' /* server -> client */
#define CHAR_FOR_TOKEN_ADD 'T' /* client -> server */
#define CHAR_FOR_DESCRIBE 'D' /* client -> server */
#define CHAR_FOR_DESCRIPTION 'd' /* server -> client */
#define CHAR_FOR_TOKEN_ADD 'T' /* client -> server */
@@
-667,11
+670,11
@@
static void client_on_reply(struct afb_proto_ws *protows, struct readbuf *rb)
static void client_on_description(struct afb_proto_ws *protows, struct readbuf *rb)
{
static void client_on_description(struct afb_proto_ws *protows, struct readbuf *rb)
{
- uint
32
_t descid;
+ uint
16
_t descid;
struct client_describe *desc, **prv;
struct json_object *object;
struct client_describe *desc, **prv;
struct json_object *object;
- if (readbuf_uint
32
(rb, &descid)) {
+ if (readbuf_uint
16
(rb, &descid)) {
pthread_mutex_lock(&protows->mutex);
prv = &protows->describes;
while ((desc = *prv) && desc->descid != descid)
pthread_mutex_lock(&protows->mutex);
prv = &protows->describes;
while ((desc = *prv) && desc->descid != descid)
@@
-790,6
+793,11
@@
int afb_proto_ws_client_token_remove(struct afb_proto_ws *protows, uint16_t toke
return client_send_cmd_id16_optstr(protows, CHAR_FOR_TOKEN_DROP, tokenid, NULL);
}
return client_send_cmd_id16_optstr(protows, CHAR_FOR_TOKEN_DROP, tokenid, NULL);
}
+int afb_proto_ws_client_event_unexpected(struct afb_proto_ws *protows, uint16_t eventid)
+{
+ return client_send_cmd_id16_optstr(protows, CHAR_FOR_EVT_UNEXPECTED, eventid, NULL);
+}
+
int afb_proto_ws_client_call(
struct afb_proto_ws *protows,
const char *verb,
int afb_proto_ws_client_call(
struct afb_proto_ws *protows,
const char *verb,
@@
-962,13
+970,13
@@
overflow:
afb_proto_ws_unref(protows);
}
afb_proto_ws_unref(protows);
}
-static int server_send_description(struct afb_proto_ws *protows, uint
32
_t descid, struct json_object *descobj)
+static int server_send_description(struct afb_proto_ws *protows, uint
16
_t descid, struct json_object *descobj)
{
int rc = -1;
struct writebuf wb = { .iovcount = 0, .bufcount = 0 };
if (writebuf_char(&wb, CHAR_FOR_DESCRIPTION)
{
int rc = -1;
struct writebuf wb = { .iovcount = 0, .bufcount = 0 };
if (writebuf_char(&wb, CHAR_FOR_DESCRIPTION)
- && writebuf_uint
32
(&wb, descid)
+ && writebuf_uint
16
(&wb, descid)
&& writebuf_object(&wb, descobj))
rc = proto_write(protows, &wb);
return rc;
&& writebuf_object(&wb, descobj))
rc = proto_write(protows, &wb);
return rc;
@@
-1039,6
+1047,14
@@
static void server_on_token_drop(struct afb_proto_ws *protows, struct readbuf *r
protows->server_itf->on_token_remove(protows->closure, tokenid);
}
protows->server_itf->on_token_remove(protows->closure, tokenid);
}
+static void server_on_event_unexpected(struct afb_proto_ws *protows, struct readbuf *rb)
+{
+ uint16_t eventid;
+
+ if (readbuf_uint16(rb, &eventid))
+ protows->server_itf->on_event_unexpected(protows->closure, eventid);
+}
+
/* on version offer */
static void server_on_version_offer(struct afb_proto_ws *protows, struct readbuf *rb)
{
/* on version offer */
static void server_on_version_offer(struct afb_proto_ws *protows, struct readbuf *rb)
{
@@
-1097,6
+1113,9
@@
static void server_on_binary_job(int sig, void *closure)
case CHAR_FOR_TOKEN_DROP:
server_on_token_drop(binary->protows, &binary->rb);
break;
case CHAR_FOR_TOKEN_DROP:
server_on_token_drop(binary->protows, &binary->rb);
break;
+ case CHAR_FOR_EVT_UNEXPECTED:
+ server_on_event_unexpected(binary->protows, &binary->rb);
+ break;
case CHAR_FOR_VERSION_OFFER:
server_on_version_offer(binary->protows, &binary->rb);
break;
case CHAR_FOR_VERSION_OFFER:
server_on_version_offer(binary->protows, &binary->rb);
break;