X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-user-daemon.c;h=732c1c65bc189aa39d96d9b18cc88e6169e603fd;hb=7553044c59814c33763bb4b1c34664dceed68735;hp=aa5ed838f47b1f146c2b837c36226792265ff0a1;hpb=f551ac4966543b360e3458a61615626d71f55a6e;p=src%2Fapp-framework-main.git diff --git a/src/afm-user-daemon.c b/src/afm-user-daemon.c index aa5ed83..732c1c6 100644 --- a/src/afm-user-daemon.c +++ b/src/afm-user-daemon.c @@ -1,5 +1,5 @@ /* - Copyright 2015, 2016, 2017 IoT.bzh + Copyright (C) 2015-2019 IoT.bzh author: José Bollo @@ -30,11 +30,12 @@ #include #include -#include "afm.h" #include "verbose.h" #include "utils-jbus.h" #include "utils-json.h" +#define AFM_USER_DBUS_PATH "/org/AGL/afm/user" + /* * name of the application */ @@ -47,7 +48,7 @@ static const char versionstr[] = "\n" " %s version="AFM_VERSION"\n" "\n" - " Copyright (C) 2015, 2016, 2017 \"IoT.bzh\"\n" + " Copyright (C) 2015-2019 \"IoT.bzh\"\n" " AFB comes with ABSOLUTELY NO WARRANTY.\n" " Licence Apache 2\n" "\n"; @@ -112,14 +113,23 @@ static const char *uri; * */ static void on_pws_hangup(void *closure); -static void on_pws_reply_success(void *closure, void *request, struct json_object *result, const char *info); -static void on_pws_reply_fail(void *closure, void *request, const char *status, const char *info); +static void on_pws_reply(void *closure, void *request, struct json_object *obj, const char *error, const char *info); +#if !defined(AFB_PROTO_WS_VERSION) || (AFB_PROTO_WS_VERSION < 3) +static void on_pws_reply_success(void *closure, void *request, struct json_object *result, const char *info) + { on_pws_reply(closure, request, result, NULL, info); } +static void on_pws_reply_fail(void *closure, void *request, const char *error, const char *info) + { on_pws_reply(closure, request, NULL, error, info); } +#endif static void on_pws_event_broadcast(void *closure, const char *event_name, struct json_object *data); /* the callback interface for pws */ static struct afb_proto_ws_client_itf pws_itf = { +#if !defined(AFB_PROTO_WS_VERSION) || (AFB_PROTO_WS_VERSION < 3) .on_reply_success = on_pws_reply_success, .on_reply_fail = on_pws_reply_fail, +#else + .on_reply = on_pws_reply, +#endif .on_event_broadcast = on_pws_event_broadcast, }; @@ -155,16 +165,13 @@ static void attempt_connect_pws(int count) } } -static void on_pws_reply_success(void *closure, void *request, struct json_object *result, const char *info) -{ - struct sd_bus_message *smsg = request; - jbus_reply_j(smsg, result); -} - -static void on_pws_reply_fail(void *closure, void *request, const char *status, const char *info) +static void on_pws_reply(void *closure, void *request, struct json_object *obj, const char *error, const char *info) { struct sd_bus_message *smsg = request; - jbus_reply_error_s(smsg, status); + if (error) + jbus_reply_error_s(smsg, error); + else + jbus_reply_j(smsg, obj); } static void on_pws_event_broadcast(void *closure, const char *event_name, struct json_object *data) @@ -186,12 +193,17 @@ static void propagate(struct sd_bus_message *smsg, struct json_object *obj, void { int rc; const char *verb = closure; + const char *onbehalf = NULL; /* TODO: on behalf of the client */ INFO("method %s propagated for %s", verb, json_object_to_json_string(obj)); if (!pws) jbus_reply_error_s(smsg, "disconnected"); else { +#if defined(AFB_PROTO_WS_VERSION) && (AFB_PROTO_WS_VERSION >= 3) + rc = afb_proto_ws_client_call(pws, verb, obj, sessionid, smsg, onbehalf); +#else rc = afb_proto_ws_client_call(pws, verb, obj, sessionid, smsg); +#endif if (rc < 0) ERROR("calling %s(%s) failed: %m\n", verb, json_object_to_json_string(obj)); }