Switch to libsystemd events
[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-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,
35         AFB_SESSION_CREATE,
36         AFB_SESSION_CLOSE,
37         AFB_SESSION_RENEW,
38         AFB_SESSION_CHECK
39 };
40
41 /* API definition */
42 struct AFB_restapi
43 {
44         const char *name;
45         enum AFB_sessionE session;
46         void (*callback)(struct afb_req req);
47         const char *info;
48 };
49
50 /* Plugin definition */
51 struct AFB_plugin
52 {
53         enum AFB_pluginE type;  
54         const char *info;
55         const char *prefix;
56         const struct AFB_restapi *apis;
57 };
58
59 /* config mode */
60 enum AFB_Mode {
61         AFB_MODE_LOCAL = 0,
62         AFB_MODE_REMOTE,
63         AFB_MODE_GLOBAL
64 };
65
66 struct sd_event;
67 struct sd_bus;
68
69 struct afb_daemon_itf {
70         struct afb_evmgr (*get_evmgr)(void *closure);
71         struct sd_event *(*get_event_loop)(void *closure);
72         struct sd_bus *(*get_user_bus)(void *closure);
73         struct sd_bus *(*get_system_bus)(void *closure);
74 };
75
76 struct afb_daemon {
77         const struct afb_daemon_itf *itf;
78         void *closure;
79 };
80
81 struct AFB_interface
82 {
83         int verbosity;
84         enum AFB_Mode mode;
85         struct afb_daemon daemon;
86 };
87
88 extern const struct AFB_plugin *pluginRegister (const struct AFB_interface *interface);
89
90 static inline struct afb_evmgr afb_daemon_get_evmgr(struct afb_daemon daemon)
91 {
92         return daemon.itf->get_evmgr(daemon.closure);
93 }
94
95 static inline struct sd_event *afb_daemon_get_event_loop(struct afb_daemon daemon)
96 {
97         return daemon.itf->get_event_loop(daemon.closure);
98 }
99
100 static inline struct sd_bus *afb_daemon_get_user_bus(struct afb_daemon daemon)
101 {
102         return daemon.itf->get_user_bus(daemon.closure);
103 }
104
105 static inline struct sd_bus *afb_daemon_get_system_bus(struct afb_daemon daemon)
106 {
107         return daemon.itf->get_system_bus(daemon.closure);
108 }
109
110