c7252d640bd58cb4c172f5285c211b1d9a962172
[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         void (*freeCtxCB)(void*);  // callback to free application context [null for standard free]
59 };
60
61 /* config mode */
62 enum AFB_Mode {
63         AFB_MODE_LOCAL = 0,
64         AFB_MODE_REMOTE,
65         AFB_MODE_GLOBAL
66 };
67
68 struct afb_daemon_itf {
69         struct afb_evmgr (*get_evmgr)(void *closure);
70         struct afb_pollmgr (*get_pollmgr)(void *closure);
71 };
72
73 struct afb_daemon {
74         const struct afb_daemon_itf *itf;
75         void *closure;
76 };
77
78 struct AFB_interface
79 {
80         int verbosity;
81         enum AFB_Mode mode;
82         struct afb_daemon daemon;
83 };
84
85 extern const struct AFB_plugin *pluginRegister (const struct AFB_interface *interface);
86
87 static inline struct afb_evmgr afb_daemon_get_evmgr(struct afb_daemon daemon)
88 {
89         return daemon.itf->get_evmgr(daemon.closure);
90 }
91
92 static inline struct afb_pollmgr afb_daemon_get_pollmgr(struct afb_daemon daemon)
93 {
94         return daemon.itf->get_pollmgr(daemon.closure);
95 }
96
97