X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-ws-json1.c;h=f383868ac0619c37b15b6394812b9ad1559f6678;hb=f83e7ca61af4c49d4f5f878973e508e18963c186;hp=4cfc918149da2a3c53d0aa41048060d1b06e5694;hpb=7a322e20bde6e9bfbc7e98aa5a7b376ba53dccb4;p=src%2Fapp-framework-binder.git diff --git a/src/afb-ws-json1.c b/src/afb-ws-json1.c index 4cfc9181..f383868a 100644 --- a/src/afb-ws-json1.c +++ b/src/afb-ws-json1.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 "IoT.bzh" + * Copyright (C) 2016, 2017 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,8 +29,9 @@ #include "afb-wsj1.h" #include "afb-ws-json1.h" +#include "afb-common.h" #include "afb-msg-json.h" -#include "session.h" +#include "afb-session.h" #include "afb-apis.h" #include "afb-context.h" #include "afb-evt.h" @@ -44,7 +45,7 @@ struct afb_wsreq; /* predeclaration of websocket callbacks */ static void aws_on_hangup(struct afb_ws_json1 *ws, struct afb_wsj1 *wsj1); static void aws_on_call(struct afb_ws_json1 *ws, const char *api, const char *verb, struct afb_wsj1_msg *msg); -static void aws_on_event(struct afb_ws_json1 *ws, const char *event, struct json_object *object); +static void aws_on_event(struct afb_ws_json1 *ws, const char *event, int eventid, struct json_object *object); /* predeclaration of wsreq callbacks */ static void wsreq_addref(struct afb_wsreq *wsreq); @@ -65,7 +66,7 @@ struct afb_ws_json1 int refcount; void (*cleanup)(void*); void *cleanup_closure; - struct AFB_clientCtx *session; + struct afb_session *session; struct afb_evt_listener *listener; struct afb_wsj1 *wsj1; int new_session; @@ -110,6 +111,12 @@ const struct afb_req_itf afb_ws_json1_req_itf = { .subcall = (void*)wsreq_subcall }; +/* the interface for events */ +static const struct afb_evt_itf evt_itf = { + .broadcast = (void*)aws_on_event, + .push = (void*)aws_on_event +}; + /*************************************************************** **************************************************************** ** @@ -132,16 +139,16 @@ struct afb_ws_json1 *afb_ws_json1_create(int fd, struct afb_context *context, vo result->refcount = 1; result->cleanup = cleanup; result->cleanup_closure = cleanup_closure; - result->session = ctxClientAddRef(context->session); + result->session = afb_session_addref(context->session); result->new_session = context->created != 0; if (result->session == NULL) goto error2; - result->wsj1 = afb_wsj1_create(fd, &wsj1_itf, result); + result->wsj1 = afb_wsj1_create(afb_common_get_event_loop(), fd, &wsj1_itf, result); if (result->wsj1 == NULL) goto error3; - result->listener = afb_evt_listener_create((void*)aws_on_event, result); + result->listener = afb_evt_listener_create(&evt_itf, result); if (result->listener == NULL) goto error4; @@ -150,7 +157,7 @@ struct afb_ws_json1 *afb_ws_json1_create(int fd, struct afb_context *context, vo error4: afb_wsj1_unref(result->wsj1); error3: - ctxClientUnref(result->session); + afb_session_unref(result->session); error2: free(result); error: @@ -171,7 +178,7 @@ static void aws_unref(struct afb_ws_json1 *ws) afb_wsj1_unref(ws->wsj1); if (ws->cleanup != NULL) ws->cleanup(ws->cleanup_closure); - ctxClientUnref(ws->session); + afb_session_unref(ws->session); free(ws); } } @@ -217,7 +224,7 @@ static void aws_on_call(struct afb_ws_json1 *ws, const char *api, const char *ve wsreq_unref(wsreq); } -static void aws_on_event(struct afb_ws_json1 *aws, const char *event, struct json_object *object) +static void aws_on_event(struct afb_ws_json1 *aws, const char *event, int eventid, struct json_object *object) { afb_wsj1_send_event_j(aws->wsj1, event, afb_msg_json_event(event, object)); }