40b26cfa69c4889a74a4dfc2fa3b94cb37881233
[src/app-framework-binder.git] / include / afb-plugin.h
1 /*
2  * Copyright (C) 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-evmgr-itf.h"
22
23 /* Plugin Type */
24 enum  AFB_pluginE
25 {
26         AFB_PLUGIN_JSON = 123456789,
27 /*      AFB_PLUGIN_JSCRIPT = 987654321, */
28         AFB_PLUGIN_RAW = 987123546
29 };
30
31 /* Enum for Session/Token/Authentication middleware */
32 enum AFB_sessionE
33 {
34         AFB_SESSION_NONE = 0,
35         AFB_SESSION_CREATE = 1,
36         AFB_SESSION_CLOSE = 2,
37         AFB_SESSION_RENEW = 4,
38         AFB_SESSION_CHECK = 8,
39         AFB_SESSION_MASK = 15
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 sd_event;
68 struct sd_bus;
69
70 struct afb_daemon_itf {
71         struct afb_evmgr (*get_evmgr)(void *closure);
72         struct sd_event *(*get_event_loop)(void *closure);
73         struct sd_bus *(*get_user_bus)(void *closure);
74         struct sd_bus *(*get_system_bus)(void *closure);
75 };
76
77 struct afb_daemon {
78         const struct afb_daemon_itf *itf;
79         void *closure;
80 };
81
82 struct AFB_interface
83 {
84         int verbosity;
85         enum AFB_Mode mode;
86         struct afb_daemon daemon;
87 };
88
89 extern const struct AFB_plugin *pluginRegister (const struct AFB_interface *interface);
90
91 static inline struct afb_evmgr afb_daemon_get_evmgr(struct afb_daemon daemon)
92 {
93         return daemon.itf->get_evmgr(daemon.closure);
94 }
95
96 static inline struct sd_event *afb_daemon_get_event_loop(struct afb_daemon daemon)
97 {
98         return daemon.itf->get_event_loop(daemon.closure);
99 }
100
101 static inline struct sd_bus *afb_daemon_get_user_bus(struct afb_daemon daemon)
102 {
103         return daemon.itf->get_user_bus(daemon.closure);
104 }
105
106 static inline struct sd_bus *afb_daemon_get_system_bus(struct afb_daemon daemon)
107 {
108         return daemon.itf->get_system_bus(daemon.closure);
109 }
110
111