X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=bindings%2Fsamples%2FDemoContext.c;h=a2fec7502f541448ebf4798241470926f1059211;hb=33e615ea0cc26131532f4615ef4a2034488fa48e;hp=243ed687c18c89f7898dd57d9581de475c8989dd;hpb=bbddc1e584dd01b60042f622f8cecfc69361020b;p=src%2Fapp-framework-binder.git diff --git a/bindings/samples/DemoContext.c b/bindings/samples/DemoContext.c index 243ed687..a2fec750 100644 --- a/bindings/samples/DemoContext.c +++ b/bindings/samples/DemoContext.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, 2016 "IoT.bzh" + * Copyright (C) 2015, 2016, 2017 "IoT.bzh" * Author "Fulup Ar Foll" * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,8 @@ #include #include -#include +#define AFB_BINDING_VERSION 1 +#include typedef struct { /* @@ -67,6 +68,10 @@ static void myAction (struct afb_req request) { MyClientContextT *ctx = (MyClientContextT*) afb_req_context_get(request); + if (!ctx) { + afb_req_fail(request, "invalid-state", "Can't perform action"); + return; + } // store something in our plugin private client context ctx->count++; afb_req_success_f(request, NULL, "SUCCESS: plugin [%s] Check=[%d]\n", ctx->abcd, ctx->count); @@ -80,6 +85,10 @@ static void myClose (struct afb_req request) { MyClientContextT *ctx = (MyClientContextT*) afb_req_context_get(request); + if (!ctx) { + afb_req_success(request, NULL, NULL); + return; + } // store something in our plugin private client context ctx->count++; afb_req_success_f(request, NULL, "SUCCESS: plugin [%s] Close=[%d]\n", ctx->abcd, ctx->count); @@ -121,7 +130,7 @@ static void clientCheckLOA(struct afb_req request) // NOTE: this sample does not use session to keep test a basic as possible // in real application most APIs should be protected with AFB_SESSION_CHECK -static const struct AFB_verb_desc_v1 verbs[]= { +static const struct afb_verb_desc_v1 verbs[]= { {"create", AFB_SESSION_CREATE, myCreate , "Create a new session"}, {"action", AFB_SESSION_CHECK , myAction , "Use Session Context"}, {"close" , AFB_SESSION_CLOSE , myClose , "Free Context"}, @@ -144,8 +153,8 @@ static const struct AFB_verb_desc_v1 verbs[]= { {NULL} }; -static const struct AFB_plugin plugin_desc = { - .type = AFB_PLUGIN_VERSION_1, +static const struct afb_binding plugin_desc = { + .type = AFB_BINDING_VERSION_1, .v1 = { .info = "Sample of Client Context Usage", .prefix = "context", @@ -153,7 +162,7 @@ static const struct AFB_plugin plugin_desc = { } }; -const struct AFB_plugin *pluginAfbV1Register (const struct AFB_interface *itf) +const struct afb_binding *afbBindingV1Register (const struct afb_binding_interface *itf) { return &plugin_desc; }