aboutsummaryrefslogtreecommitdiffstats
path: root/bindings/samples/HelloWorld.c
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/samples/HelloWorld.c')
-rw-r--r--bindings/samples/HelloWorld.c32
1 files changed, 10 insertions, 22 deletions
diff --git a/bindings/samples/HelloWorld.c b/bindings/samples/HelloWorld.c
index 92d7c4d2..844aa1b2 100644
--- a/bindings/samples/HelloWorld.c
+++ b/bindings/samples/HelloWorld.c
@@ -282,13 +282,10 @@ static void eventpush (afb_req_t request)
json_object_put(object);
}
-static void callcb (void *prequest, int status, json_object *object, afb_api_t api)
+static void callcb (void *prequest, json_object *object, const char *error, const char *info, afb_api_t api)
{
afb_req_t request = prequest;
- 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_reply(request, json_object_get(object), error, info);
afb_req_unref(request);
}
@@ -299,31 +296,22 @@ static void call (afb_req_t request)
const char *args = afb_req_value(request, "args");
json_object *object = api && verb && args ? json_tokener_parse(args) : NULL;
- if (object == NULL)
- afb_req_fail(request, "failed", "bad arguments");
- else
- afb_service_call(api, verb, object, callcb, afb_req_addref(request));
+ afb_service_call(api, verb, object, callcb, afb_req_addref(request));
}
static void callsync (afb_req_t request)
{
- int rc;
const char *api = afb_req_value(request, "api");
const char *verb = afb_req_value(request, "verb");
const char *args = afb_req_value(request, "args");
- json_object *result, *object = api && verb && args ? json_tokener_parse(args) : NULL;
+ json_object *object = api && verb && args ? json_tokener_parse(args) : NULL;
+ json_object *result;
+ char *error, *info;
- if (object == NULL)
- afb_req_fail(request, "failed", "bad arguments");
- else {
- rc = afb_service_call_sync(api, verb, object, &result);
- if (rc >= 0)
- afb_req_success(request, result, NULL);
- else {
- afb_req_fail(request, "failed", json_object_to_json_string(result));
- json_object_put(result);
- }
- }
+ afb_service_call_sync(api, verb, object, &result, &error, &info);
+ afb_req_reply(request, result, error, info);
+ free(error);
+ free(info);
}
static void verbose (afb_req_t request)
220'>220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303