Update date of copyright notices
[src/app-framework-binder.git] / bindings / samples / DemoContext.c
index 0427a4d..bf35ab1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015, 2016 "IoT.bzh"
+ * Copyright (C) 2015-2018 "IoT.bzh"
  * Author "Fulup Ar Foll"
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <json-c/json.h>
 
+#define AFB_BINDING_VERSION 1
 #include <afb/afb-binding.h>
 
 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);