X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fafb-subcall.c;h=65bef2ff33c46475ca54e3912da9941b76e6eaaa;hb=6797f9722dd3e5463e0f7c118397955bb59a40c7;hp=bf6417384e5eea1b0e8bd317b5dcfa1ac8c39a86;hpb=b69290c369ba67ee804bc5a0a440210c0e5d37a3;p=src%2Fapp-framework-binder.git diff --git a/src/afb-subcall.c b/src/afb-subcall.c index bf641738..65bef2ff 100644 --- a/src/afb-subcall.c +++ b/src/afb-subcall.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"); @@ -159,13 +159,23 @@ static void subcall_subcall(struct afb_subcall *subcall, const char *api, const afb_subcall(&subcall->context, api, verb, args, callback, closure, (struct afb_req){ .itf = &afb_subcall_req_itf, .closure = subcall }); } +void afb_subcall_internal_error(void (*callback)(void*, int, struct json_object*), void *closure) +{ + static struct json_object *obj; + + if (obj == NULL) + obj = afb_msg_json_reply_error("failed", "internal error", NULL, NULL); + + callback(closure, 1, obj); +} + void afb_subcall(struct afb_context *context, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure, struct afb_req req) { struct afb_subcall *subcall; subcall = calloc(1, sizeof *subcall); if (subcall == NULL) { - callback(closure, 1, afb_msg_json_reply_error("failed", "out of memory", NULL, NULL)); + afb_subcall_internal_error(callback, closure); return; } @@ -177,7 +187,7 @@ void afb_subcall(struct afb_context *context, const char *api, const char *verb, subcall->closure = closure; subcall->context = *context; afb_req_addref(req); - afb_apis_call_((struct afb_req){ .itf = &afb_subcall_req_itf, .closure = subcall }, &subcall->context, api, verb); + afb_apis_call((struct afb_req){ .itf = &afb_subcall_req_itf, .closure = subcall }, &subcall->context, api, verb); subcall_unref(subcall); }