dfb6fbad399ddb67b0766f88280f4789a7b01493
[src/app-framework-binder.git] / include / afb-plugin.h
1 /*
2  * Copyright 2016 IoT.bzh
3  * Author: José Bollo <jose.bollo@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #pragma once
19
20 #include "afb-req-itf.h"
21 #include "afb-pollmgr-itf.h"
22 #include "afb-evmgr-itf.h"
23
24 /* Plugin Type */
25 enum  AFB_pluginE
26 {
27         AFB_PLUGIN_JSON = 123456789,
28 /*      AFB_PLUGIN_JSCRIPT = 987654321, */
29         AFB_PLUGIN_RAW = 987123546
30 };
31
32 /* Enum for Session/Token/Authentication middleware */
33 enum AFB_sessionE
34 {
35         AFB_SESSION_NONE,
36         AFB_SESSION_CREATE,
37         AFB_SESSION_CLOSE,
38         AFB_SESSION_RENEW,
39         AFB_SESSION_CHECK
40 };
41
42 /* API definition */
43 struct AFB_restapi
44 {
45         const char *name;
46         enum AFB_sessionE session;
47         void (*callback)(struct afb_req req);
48         const char *info;
49 };
50
51 /* Plugin definition */
52 struct AFB_plugin
53 {
54         enum AFB_pluginE type;  
55         const char *info;
56         const char *prefix;
57         const struct AFB_restapi *apis;
58 };
59
60 /* config mode */
61 enum AFB_Mode {
62         AFB_MODE_LOCAL = 0,
63         AFB_MODE_REMOTE,
64         AFB_MODE_GLOBAL
65 };
66
67 struct afb_daemon_itf {
68         struct afb_evmgr (*get_evmgr)(void *closure);
69         struct afb_pollmgr (*get_pollmgr)(void *closure);
70 };
71
72 struct afb_daemon {
73         const struct afb_daemon_itf *itf;
74         void *closure;
75 };
76
77 struct AFB_interface
78 {
79         int verbosity;
80         enum AFB_Mode mode;
81         struct afb_daemon daemon;
82 };
83
84 extern const struct AFB_plugin *pluginRegister (const struct AFB_interface *interface);
85
86 static inline struct afb_evmgr afb_daemon_get_evmgr(struct afb_daemon daemon)
87 {
88         return daemon.itf->get_evmgr(daemon.closure);
89 }
90
91 static inline struct afb_pollmgr afb_daemon_get_pollmgr(struct afb_daemon daemon)
92 {
93         return daemon.itf->get_pollmgr(daemon.closure);
94 }
95
96