X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-dbus.c;h=905c723d75f1942165938cd4bb8cd9e77a536518;hb=6518887513840471ea9c5af7e534787717e6bd82;hp=f4fd0eba12d55f6654a03381790b65659577d1de;hpb=be4e0e2d3855ccbd3b683bfe6cc4c7f9d3254314;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-dbus.c b/src/afb-api-dbus.c index f4fd0eba..905c723d 100644 --- a/src/afb-api-dbus.c +++ b/src/afb-api-dbus.c @@ -35,6 +35,8 @@ #include "afb-apis.h" #include "afb-api-so.h" #include "afb-context.h" +#include "afb-evt.h" +#include "afb-subcall.h" #include "verbose.h" static const char DEFAULT_PATH_PREFIX[] = "/org/agl/afb/api/"; @@ -52,6 +54,7 @@ struct api_dbus char *path; /* path of the object for the API */ char *name; /* name/interface of the object */ char *api; /* api name of the interface */ + struct afb_evt_listener *listener; }; #define RETOK 1 @@ -302,7 +305,7 @@ static int api_dbus_client_on_event(sd_bus_message *m, void *userdata, sd_bus_er ERROR("unreadable event"); else { object = json_tokener_parse(data); - ctxClientEventSend(NULL, event, object); + afb_evt_broadcast(event, object); json_object_put(object); } return 1; @@ -423,7 +426,7 @@ static void dbus_req_reply(struct dbus_req *dreq, uint8_t type, const char *firs static void dbus_req_success(struct dbus_req *dreq, struct json_object *obj, const char *info) { - dbus_req_reply(dreq, RETOK, json_object_to_json_string(obj), info); + dbus_req_reply(dreq, RETOK, json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN), info); } static void dbus_req_fail(struct dbus_req *dreq, const char *status, const char *info) @@ -444,7 +447,19 @@ static void dbus_req_send(struct dbus_req *dreq, const char *buffer, size_t size dbus_req_reply(dreq, RETRAW, buffer, ""); } -struct afb_req_itf dbus_req_itf = { +static int dbus_req_subscribe(struct dbus_req *dreq, struct afb_event event) +{ + return -1; +} + +static int dbus_req_unsubscribe(struct dbus_req *dreq, struct afb_event event) +{ + return -1; +} + +static void dbus_req_subcall(struct dbus_req *dreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure); + +const struct afb_req_itf afb_api_dbus_req_itf = { .json = (void*)dbus_req_json, .get = (void*)dbus_req_get, .success = (void*)dbus_req_success, @@ -454,9 +469,19 @@ struct afb_req_itf dbus_req_itf = { .context_get = (void*)afb_context_get, .context_set = (void*)afb_context_set, .addref = (void*)dbus_req_addref, - .unref = (void*)dbus_req_unref + .unref = (void*)dbus_req_unref, + .session_close = (void*)afb_context_close, + .session_set_LOA = (void*)afb_context_change_loa, + .subscribe = (void*)dbus_req_subscribe, + .unsubscribe = (void*)dbus_req_unsubscribe, + .subcall = (void*)dbus_req_subcall }; +static void dbus_req_subcall(struct dbus_req *dreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure) +{ + afb_subcall(&dreq->context, api, verb, args, callback, closure, (struct afb_req){ .itf = &afb_api_dbus_req_itf, .closure = dreq }); +} + /******************* server part **********************************/ /* called when the object for the service is called */ @@ -504,7 +529,7 @@ static int api_dbus_server_on_object_called(sd_bus_message *message, void *userd dreq->message = sd_bus_message_ref(message); dreq->json = NULL; dreq->refcount = 1; - areq.itf = &dbus_req_itf; + areq.itf = &afb_api_dbus_req_itf; areq.closure = dreq; afb_apis_call_(areq, &dreq->context, api->api, method); dbus_req_unref(dreq); @@ -516,25 +541,12 @@ static void afb_api_dbus_server_send_event(struct api_dbus *api, const char *eve int rc; rc = sd_bus_emit_signal(api->sdbus, api->path, api->name, - "event", "ss", event, json_object_to_json_string(object)); + "event", "ss", event, json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN)); if (rc < 0) ERROR("error while emiting event %s", event); json_object_put(object); } -static int afb_api_dbus_server_expects_event(struct api_dbus *api, const char *event) -{ - size_t len = strlen(api->api); - if (strncasecmp(event, api->api, len) != 0) - return 0; - return event[len] == '.'; -} - -static struct afb_event_listener_itf evitf = { - .send = (void*)afb_api_dbus_server_send_event, - .expects = (void*)afb_api_dbus_server_expects_event -}; - /* create the service */ int afb_api_dbus_add_server(const char *path) { @@ -563,7 +575,7 @@ int afb_api_dbus_add_server(const char *path) } INFO("afb service over dbus installed, name %s, path %s", api->name, api->path); - ctxClientEventListenerAdd(NULL, (struct afb_event_listener){ .itf = &evitf, .closure = api }); + api->listener = afb_evt_listener_create((void*)afb_api_dbus_server_send_event, api); return 0; error3: