summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2018-10-11 17:37:02 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2018-10-12 14:33:44 +0200
commitdeaf20980bcacd8731e9228c86f528ac480c7f55 (patch)
treec06032da1cb75f739418fdfc7943e31b81af4ea8 /bindings
parent86e4c175b0c35d38c8a214ae1c6afce6ad6aac4c (diff)
APIv3: Allow to write application binding
This enable a binding version 3 to declare no API. This is used to start a job that will will run after initialisation. The tutorial tuto-app1 shows how. Run it with: afb-daemon --binding tuto-app1.so A further option could be add to close stdin even if running in foreground, as it was the case before. Change-Id: I2b384d125accb4642eed8e004642ba959326878f Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'bindings')
-rw-r--r--bindings/tutorial/CMakeLists.txt2
-rw-r--r--bindings/tutorial/tuto-app1.c30
2 files changed, 32 insertions, 0 deletions
diff --git a/bindings/tutorial/CMakeLists.txt b/bindings/tutorial/CMakeLists.txt
index 2860c8c9..5c19bb85 100644
--- a/bindings/tutorial/CMakeLists.txt
+++ b/bindings/tutorial/CMakeLists.txt
@@ -32,3 +32,5 @@ ENDMACRO(tuto)
tuto(1 c)
tuto(2 c)
tuto(3 cpp)
+
+tuto(app1 c)
diff --git a/bindings/tutorial/tuto-app1.c b/bindings/tutorial/tuto-app1.c
new file mode 100644
index 00000000..93747cdd
--- /dev/null
+++ b/bindings/tutorial/tuto-app1.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+#define AFB_BINDING_VERSION 3
+#include <afb/afb-binding.h>
+
+static int appmain(void *arg)
+{
+ const char *name = arg;
+ char buffer[50];
+
+ AFB_API_NOTICE(afbBindingV3root, "Entering Application main");
+ printf("Hello, I'm %s!\n", name);
+ printf("What's your name? ");
+ scanf("%s", buffer);
+ printf("Hi %s! Nice to meet you. OOOOPS I'm late bye bye\n", buffer);
+ return 0;
+}
+
+static void application(int signum, void *arg)
+{
+ if (signum)
+ exit(127);
+ exit(appmain(arg));
+}
+
+int afbBindingV3entry(struct afb_api_x3 *rootapi)
+{
+ return afb_api_queue_job(rootapi, application, "BOB", NULL, 0);
+}
+