ping(request, jresp, "pingJson");
}
-static void subcallcb (void *prequest, int iserror, json_object *object)
+static void subcallcb (void *prequest, int status, json_object *object)
{
afb_req request = afb_req_unstore(prequest);
- if (iserror)
+ if (status < 0)
afb_req_fail(request, "failed", json_object_to_json_string(object));
else
afb_req_success(request, json_object_get(object), NULL);
afb_req_fail(request, "failed", "bad arguments");
else {
rc = afb_req_subcall_sync(request, api, verb, object, &result);
- if (rc)
+ if (rc >= 0)
afb_req_success(request, result, NULL);
else {
afb_req_fail(request, "failed", json_object_to_json_string(result));
json_object_put(object);
}
-static void callcb (void *prequest, int iserror, json_object *object)
+static void callcb (void *prequest, int status, json_object *object)
{
afb_req request = afb_req_unstore(prequest);
- if (iserror)
+ if (status < 0)
afb_req_fail(request, "failed", json_object_to_json_string(object));
else
afb_req_success(request, json_object_get(object), NULL);
afb_req_fail(request, "failed", "bad arguments");
else {
rc = afb_service_call_sync(api, verb, object, &result);
- if (rc)
+ if (rc >= 0)
afb_req_success(request, result, NULL);
else {
afb_req_fail(request, "failed", json_object_to_json_string(result));
*
* The 'callback' receives 3 arguments:
* 1. 'closure' the user defined closure pointer 'callback_closure',
- * 2. 'iserror' a boolean status being true (not null) when an error occured,
+ * 2. 'status' a status being 0 on success or negative when an error occured,
* 2. 'result' the resulting data as a JSON object.
*
* @param api The api name of the method to call
const char *api,
const char *verb,
struct json_object *args,
- void (*callback)(void*closure, int iserror, struct json_object *result),
+ void (*callback)(void*closure, int status, struct json_object *result),
void *callback_closure);
/**
* @param args The arguments to pass to the method
* @param result Where to store the result - should call json_object_put on it -
*
- * @returns 1 in case of success or 0 in case of error.
+ * @returns 0 in case of success or a negative value in case of error.
*
* @see also 'afb_req_subcall'
*/
* This call is made in the context of the request 'req'.
* On completion, the function 'callback' is invoked with the
* 'closure' given at call and two other parameters: 'iserror' and 'result'.
- * 'iserror' is a boolean that indicates if the reply is an error reply.
+ * 'status' is 0 on success or negative when on an error reply.
* 'result' is the json object of the reply, you must not call json_object_put
* on the result.
*
const char *api,
const char *verb,
struct json_object *args,
- void (*callback)(void *closure, int iserror, struct json_object *result),
+ void (*callback)(void *closure, int status, struct json_object *result),
void *closure);
/*
* Makes a call to the method of name 'api' / 'verb' with the object 'args'.
* This call is made in the context of the request 'req'.
* This call is synchronous, it waits untill completion of the request.
- * It returns 0 on an error answer and returns 1 when no error was detected.
+ * It returns 0 on success or a negative value on error answer.
* The object pointed by 'result' is filled and must be released by the caller
* after its use by calling 'json_object_put'.
*
* This call is made in the context of the request 'req'.
* On completion, the function 'callback' is invoked with the
* 'closure' given at call and two other parameters: 'iserror' and 'result'.
- * 'iserror' is a boolean that indicates if the reply is an error reply.
+ * 'status' is 0 on success or negative when on an error reply.
* 'result' is the json object of the reply, you must not call json_object_put
* on the result.
*
* Makes a call to the method of name 'api' / 'verb' with the object 'args'.
* This call is made in the context of the request 'req'.
* This call is synchronous, it waits untill completion of the request.
- * It returns 0 on an error answer and returns 1 when no error was detected.
+ * It returns 0 on success or a negative value on error answer.
* The object pointed by 'result' is filled and must be released by the caller
* after its use by calling 'json_object_put'.
*
*
* The 'callback' receives 3 arguments:
* 1. 'closure' the user defined closure pointer 'callback_closure',
- * 2. 'iserror' a boolean status being true (not null) when an error occured,
+ * 2. 'status' a status being 0 on success or negative when an error occured,
* 2. 'result' the resulting data as a JSON object.
*
* @param service The service as received during initialisation
const char *api,
const char *verb,
struct json_object *args,
- void (*callback)(void*closure, int iserror, struct json_object *result),
+ void (*callback)(void*closure, int status, struct json_object *result),
void *callback_closure)
{
service.itf->call(service.closure, api, verb, args, callback, callback_closure);
* @param args The arguments to pass to the method
* @param result Where to store the result - should call json_object_put on it -
*
- * @returns 1 in case of success or 0 in case of error.
+ * @returns 0 in case of success or a negative value in case of error.
*
* @see also 'afb_req_subcall'
*/
*
* The 'callback' receives 3 arguments:
* 1. 'closure' the user defined closure pointer 'callback_closure',
- * 2. 'iserror' a boolean status being true (not null) when an error occured,
+ * 2. 'status' a status being 0 on success or negative when an error occured,
* 2. 'result' the resulting data as a JSON object.
*
* @param api The api name of the method to call
const char *api,
const char *verb,
struct json_object *args,
- void (*callback)(void*closure, int iserror, struct json_object *result),
+ void (*callback)(void*closure, int status, struct json_object *result),
void *callback_closure)
{
afb_get_service_v2().itf->call(afb_get_service_v2().closure, api, verb, args, callback, callback_closure);
* @param args The arguments to pass to the method
* @param result Where to store the result - should call json_object_put on it -
*
- * @returns 1 in case of success or 0 in case of error.
+ * @returns 0 in case of success or a negative value in case of error.
*
* @see also 'afb_req_subcall'
*/
}
/* send a subcall reply */
-static void client_send_subcall_reply(struct client_subcall *subcall, int iserror, json_object *object)
+static void client_send_subcall_reply(struct client_subcall *subcall, int status, json_object *object)
{
int rc;
struct writebuf wb = { .count = 0 };
- char ie = (char)!!iserror;
+ char ie = status < 0;
if (!writebuf_char(&wb, CHAR_FOR_SUBCALL_REPLY)
|| !writebuf_uint32(&wb, subcall->subcallid)
}
/* callback for subcall reply */
-static void client_subcall_reply_cb(void *closure, int iserror, json_object *object)
+static void client_subcall_reply_cb(void *closure, int status, json_object *object)
{
- client_send_subcall_reply(closure, iserror, object);
+ client_send_subcall_reply(closure, status, object);
free(closure);
}
/* on subcall reply */
static void server_on_subcall_reply(struct afb_stub_ws *stubws, struct readbuf *rb)
{
- char iserror;
+ char ie;
uint32_t subcallid;
struct json_object *object;
struct server_subcall *sc, **psc;
/* reads the call message data */
if (!readbuf_uint32(rb, &subcallid)
- || !readbuf_char(rb, &iserror)
+ || !readbuf_char(rb, &ie)
|| !readbuf_object(rb, &object)) {
/* TODO bad protocol */
return;
} else {
*psc = sc->next;
pthread_mutex_unlock(&stubws->mutex);
- sc->callback(sc->closure, (int)iserror, object);
+ sc->callback(sc->closure, -(int)ie, object);
free(sc);
}
json_object_put(object);
free(subcall);
}
-static void subcall_reply(struct afb_xreq *xreq, int iserror, struct json_object *obj)
+static void subcall_reply(struct afb_xreq *xreq, int status, struct json_object *obj)
{
struct subcall *subcall = CONTAINER_OF_XREQ(struct subcall, xreq);
- subcall->callback(subcall->closure, iserror, obj);
+ subcall->callback(subcall->closure, status, obj);
json_object_put(obj);
}
/* sync */
struct jobloop *jobloop;
struct json_object *result;
- int iserror;
+ int status;
};
/* functions for services */
/* functions for requests of services */
static void svcreq_destroy(struct afb_xreq *xreq);
-static void svcreq_reply(struct afb_xreq *xreq, int iserror, json_object *obj);
+static void svcreq_reply(struct afb_xreq *xreq, int status, json_object *obj);
/* interface for requests of services */
const struct afb_xreq_query_itf afb_svc_xreq_itf = {
}
}
-static void svcreq_reply(struct afb_xreq *xreq, int iserror, json_object *obj)
+static void svcreq_reply(struct afb_xreq *xreq, int status, json_object *obj)
{
struct svc_req *svcreq = CONTAINER_OF_XREQ(struct svc_req, xreq);
if (svcreq->callback) {
struct afb_svc *svc = svcreq->svc;
- svcreq->callback(svcreq->closure, iserror, obj);
- HOOK(call_result, svc, iserror, obj);
+ svcreq->callback(svcreq->closure, status, obj);
+ HOOK(call_result, svc, status, obj);
json_object_put(obj);
} else {
- svcreq->iserror = iserror;
+ svcreq->status = status;
svcreq->result = obj;
svcreq_sync_leave(svcreq);
}
afb_xreq_process(&svcreq->xreq, svcreq->svc->apiset);
} else {
svcreq->result = afb_msg_json_internal_error();
- svcreq->iserror = 1;
+ svcreq->status = -1;
svcreq_sync_leave(svcreq);
}
}
ERROR("out of memory");
json_object_put(args);
ierr = afb_msg_json_internal_error();
- callback(cbclosure, 1, ierr);
- HOOK(call_result, svc, 1, ierr);
+ callback(cbclosure, -1, ierr);
+ HOOK(call_result, svc, -1, ierr);
json_object_put(ierr);
return;
}
errno = ENOMEM;
json_object_put(args);
*result = afb_msg_json_internal_error();
- rc = 0;
+ rc = -1;
} else {
/* initialises the request */
svcreq->jobloop = NULL;
svcreq->callback = NULL;
svcreq->result = NULL;
- svcreq->iserror = 1;
+ svcreq->status = 0;
afb_xreq_addref(&svcreq->xreq);
rc = jobs_enter(NULL, 0, svcreq_sync_enter, svcreq);
- rc = rc >= 0 && !svcreq->iserror;
- *result = (rc || svcreq->result) ? svcreq->result : afb_msg_json_internal_error();
+ if (rc >= 0)
+ rc = svcreq->status;
+ *result = (rc >= 0 || svcreq->result) ? svcreq->result : afb_msg_json_internal_error();
afb_xreq_unref(&svcreq->xreq);
}
HOOK(callsync_result, svc, rc, *result);
/* predeclaration of wsreq callbacks */
static void wsreq_destroy(struct afb_xreq *xreq);
-static void wsreq_reply(struct afb_xreq *xreq, int iserror, json_object *obj);
+static void wsreq_reply(struct afb_xreq *xreq, int status, json_object *obj);
/* declaration of websocket structure */
struct afb_ws_json1
free(wsreq);
}
-static void wsreq_reply(struct afb_xreq *xreq, int iserror, json_object *obj)
+static void wsreq_reply(struct afb_xreq *xreq, int status, json_object *obj)
{
struct afb_wsreq *wsreq = CONTAINER_OF_XREQ(struct afb_wsreq, xreq);
int rc;
- rc = (iserror ? afb_wsj1_reply_error_j : afb_wsj1_reply_ok_j)(
+ rc = (status < 0 ? afb_wsj1_reply_error_j : afb_wsj1_reply_ok_j)(
wsreq->msgj1, obj, afb_context_sent_token(&wsreq->xreq.context));
if (rc)
ERROR("Can't send reply: %m");
if (xreq->queryitf->fail)
xreq->queryitf->fail(xreq, status, info);
else
- xreq->queryitf->reply(xreq, 1, afb_msg_json_reply_error(status, info, &xreq->context, NULL));
+ xreq->queryitf->reply(xreq, -1, afb_msg_json_reply_error(status, info, &xreq->context, NULL));
}
}
struct json_object *args;
struct jobloop *jobloop;
struct json_object *result;
- int iserror;
+ int status;
};
static void xreq_sync_leave(struct xreq_sync *sync)
}
}
-static void xreq_sync_reply(void *closure, int iserror, struct json_object *obj)
+static void xreq_sync_reply(void *closure, int status, struct json_object *obj)
{
struct xreq_sync *sync = closure;
- sync->iserror = iserror;
+ sync->status = status;
sync->result = json_object_get(obj);
xreq_sync_leave(sync);
}
sync->jobloop = jobloop;
xreq_subcall_cb(sync->caller, sync->api, sync->verb, json_object_get(sync->args), xreq_sync_reply, sync);
} else {
- sync->iserror = 1;
+ sync->status = -1;
xreq_sync_leave(sync);
}
}
sync.args = args;
sync.jobloop = NULL;
sync.result = NULL;
- sync.iserror = 1;
+ sync.status = 0;
rc = jobs_enter(NULL, 0, xreq_sync_enter, &sync);
json_object_put(args);
- if (rc < 0 || sync.iserror) {
+ if (rc < 0 || sync.status < 0) {
*result = sync.result ? : afb_msg_json_internal_error();
- return 0;
+ return -1;
}
*result = sync.result;
- return 1;
+ return 0;
}
static void xreq_vverbose_cb(void*closure, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
void *closure;
};
-static void xreq_hooked_subcall_reply_cb(void *closure, int iserror, struct json_object *result)
+static void xreq_hooked_subcall_reply_cb(void *closure, int status, struct json_object *result)
{
struct reply *reply = closure;
- afb_hook_xreq_subcall_result(reply->xreq, iserror, result);
- reply->callback(reply->closure, iserror, result);
+ afb_hook_xreq_subcall_result(reply->xreq, status, result);
+ reply->callback(reply->closure, status, result);
free(reply);
}
struct afb_arg (*get)(struct afb_xreq *xreq, const char *name);
void (*success)(struct afb_xreq *xreq, struct json_object *obj, const char *info);
void (*fail)(struct afb_xreq *xreq, const char *status, const char *info);
- void (*reply)(struct afb_xreq *xreq, int iserror, struct json_object *obj);
+ void (*reply)(struct afb_xreq *xreq, int status, struct json_object *obj);
void (*unref)(struct afb_xreq *xreq);
int (*subscribe)(struct afb_xreq *xreq, struct afb_event event);
int (*unsubscribe)(struct afb_xreq *xreq, struct afb_event event);
struct afb_session *session;
};
-static void startup_call_reply(struct afb_xreq *xreq, int iserror, struct json_object *obj)
+static void startup_call_reply(struct afb_xreq *xreq, int status, struct json_object *obj)
{
struct startup_req *sreq = CONTAINER_OF_XREQ(struct startup_req, xreq);
- if (!iserror)
+ if (status >= 0)
NOTICE("startup call %s returned %s", sreq->current->value, json_object_get_string(obj));
else {
ERROR("startup call %s ERROR! %s", sreq->current->value, json_object_get_string(obj));