X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-binder.git;a=blobdiff_plain;f=src%2Fafb-proto-ws.c;fp=src%2Fafb-proto-ws.c;h=ea95110a45d24ce7ccb3f77664c532a3b81cc5c2;hp=f40708604d0548c2a86d17e40b83509c5ed2efc4;hb=037157919df0a7ee90837037748a6456431e6469;hpb=a445694bda8773cb80566808b5dcb56f033dee58 diff --git a/src/afb-proto-ws.c b/src/afb-proto-ws.c index f4070860..ea95110a 100644 --- a/src/afb-proto-ws.c +++ b/src/afb-proto-ws.c @@ -560,11 +560,12 @@ static void client_on_event_unsubscribe(struct afb_proto_ws *protows, struct rea /* receives broadcasted events */ static void client_on_event_broadcast(struct afb_proto_ws *protows, struct readbuf *rb) { - const char *event_name; + const char *event_name, *uuid; + char hop; struct json_object *object; - if (protows->client_itf->on_event_broadcast && readbuf_string(rb, &event_name, NULL) && readbuf_object(rb, &object)) - protows->client_itf->on_event_broadcast(protows->closure, event_name, object); + if (protows->client_itf->on_event_broadcast && readbuf_string(rb, &event_name, NULL) && readbuf_object(rb, &object) && (uuid = readbuf_get(rb, 16)) && readbuf_char(rb, &hop)) + protows->client_itf->on_event_broadcast(protows->closure, event_name, object, (unsigned char*)uuid, (uint8_t)hop); else ERROR("Ignoring broadcast of event"); } @@ -909,9 +910,9 @@ static int server_event_send(struct afb_proto_ws *protows, char order, const cha int rc; if (writebuf_char(&wb, order) - && (order == CHAR_FOR_EVT_BROADCAST || writebuf_uint32(&wb, event_id)) + && writebuf_uint32(&wb, event_id) && writebuf_string(&wb, event_name) - && (order == CHAR_FOR_EVT_ADD || order == CHAR_FOR_EVT_DEL || writebuf_object(&wb, data))) { + && (order != CHAR_FOR_EVT_PUSH || writebuf_object(&wb, data))) { pthread_mutex_lock(&protows->mutex); rc = afb_ws_binary_v(protows->ws, wb.iovec, wb.count); pthread_mutex_unlock(&protows->mutex); @@ -936,9 +937,26 @@ int afb_proto_ws_server_event_push(struct afb_proto_ws *protows, const char *eve return server_event_send(protows, CHAR_FOR_EVT_PUSH, event_name, event_id, data); } -int afb_proto_ws_server_event_broadcast(struct afb_proto_ws *protows, const char *event_name, struct json_object *data) +int afb_proto_ws_server_event_broadcast(struct afb_proto_ws *protows, const char *event_name, struct json_object *data, const unsigned char uuid[16], uint8_t hop) { - return server_event_send(protows, CHAR_FOR_EVT_BROADCAST, event_name, 0, data); + struct writebuf wb = { .count = 0 }; + int rc; + + if (!hop--) + return 0; + + if (writebuf_char(&wb, CHAR_FOR_EVT_BROADCAST) + && writebuf_string(&wb, event_name) + && writebuf_object(&wb, data) + && writebuf_put(&wb, uuid, 16) + && writebuf_char(&wb, (char)hop)) { + pthread_mutex_lock(&protows->mutex); + rc = afb_ws_binary_v(protows->ws, wb.iovec, wb.count); + pthread_mutex_unlock(&protows->mutex); + if (rc >= 0) + return 0; + } + return -1; } /*****************************************************/