2 * Copyright (C) 2016 "IoT.bzh"
3 * Author: José Bollo <jose.bollo@iot.bzh>
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 /*****************************************************************************
21 * This files is the main file to include for writing plugins dedicated to
25 * Functions of plugins of afb-daemon are accessible by authorized clients
26 * through the apis module of afb-daemon.
28 * A plugin is a shared library. This shared library must have at least one
29 * exported symbol for being registered in afb-daemon.
30 * For the current version of afb-daemon, the function exported MUST be named
36 * Some function of the library are exported to afb-daemon.
39 #include <afb/afb-req-itf.h>
40 #include <afb/afb-event-sender-itf.h>
43 * Definition of the versions of the plugin.
44 * The definition uses hashes.
46 enum AFB_plugin_version
48 AFB_PLUGIN_VERSION_1 = 123456789 /* version 1 */
52 * Enum for Session/Token/Authentication middleware.
53 * This enumeration is valid for plugins of type 1
57 AFB_SESSION_NONE = 0, /* no session and no authentification required */
58 AFB_SESSION_CREATE = 1, /* requires authentification and first call of the session */
59 AFB_SESSION_CLOSE = 2, /* closes the session after authentification */
60 AFB_SESSION_RENEW = 4, /* refreshes the token after authentification */
61 AFB_SESSION_CHECK = 8, /* enforce authentification */
62 AFB_SESSION_MASK = 15 /* convenient mask used internally, bit-or of the previous masks */
66 * Description of one verb of the API provided by the plugin
67 * This enumeration is valid for plugins of type 1
69 struct AFB_verb_desc_v1
71 const char *name; /* name of the verb */
72 enum AFB_session_v1 session; /* authorisation and session requirements of the verb */
73 void (*callback)(struct afb_req req); /* callback function implementing the verb */
74 const char *info; /* textual description of the verb */
78 * Description of the plugins of type 1
80 struct AFB_plugin_desc_v1
82 const char *info; /* textual information about the plugin */
83 const char *prefix; /* required prefix name for the plugin */
84 const struct AFB_verb_desc_v1 *verbs; /* array of descriptions of verbs terminated by a NULL name */
88 * Description of a plugin
92 enum AFB_plugin_version type; /* type of the plugin */
94 struct AFB_plugin_desc_v1 v1; /* description of the plugin of type 1 */
102 AFB_MODE_LOCAL = 0, /* run locally */
103 AFB_MODE_REMOTE, /* run remotely */
104 AFB_MODE_GLOBAL /* run either remotely or locally (DONT USE! reserved for future) */
107 /* declaration of features of libsystemd */
112 * Definition of the facilities provided by the daemon.
114 struct afb_daemon_itf {
115 struct afb_event_sender (*get_event_sender)(void *closure); /* get the event manager */
116 struct sd_event *(*get_event_loop)(void *closure); /* get the common systemd's event loop */
117 struct sd_bus *(*get_user_bus)(void *closure); /* get the common systemd's user d-bus */
118 struct sd_bus *(*get_system_bus)(void *closure); /* get the common systemd's system d-bus */
122 * Structure for accessing daemon.
123 * See also: afb_daemon_get_event_sender, afb_daemon_get_event_loop, afb_daemon_get_user_bus, afb_daemon_get_system_bus
126 const struct afb_daemon_itf *itf; /* the interfacing functions */
127 void *closure; /* the closure when calling these functions */
131 * Interface between the daemon and the plugin.
135 struct afb_daemon daemon; /* access to the daemon facilies */
136 int verbosity; /* level of verbosity */
137 enum AFB_Mode mode; /* run mode (local or remote) */
141 * Function for registering the plugin
143 extern const struct AFB_plugin *pluginAfbV1Register (const struct AFB_interface *interface);
146 * Retrieves the event sender of AFB
147 * 'daemon' MUST be the daemon given in interface when activating the plugin.
149 static inline struct afb_event_sender afb_daemon_get_event_sender(struct afb_daemon daemon)
151 return daemon.itf->get_event_sender(daemon.closure);
155 * Retrieves the common systemd's event loop of AFB
156 * 'daemon' MUST be the daemon given in interface when activating the plugin.
158 static inline struct sd_event *afb_daemon_get_event_loop(struct afb_daemon daemon)
160 return daemon.itf->get_event_loop(daemon.closure);
164 * Retrieves the common systemd's user/session d-bus of AFB
165 * 'daemon' MUST be the daemon given in interface when activating the plugin.
167 static inline struct sd_bus *afb_daemon_get_user_bus(struct afb_daemon daemon)
169 return daemon.itf->get_user_bus(daemon.closure);
173 * Retrieves the common systemd's system d-bus of AFB
174 * 'daemon' MUST be the daemon given in interface when activating the plugin.
176 static inline struct sd_bus *afb_daemon_get_system_bus(struct afb_daemon daemon)
178 return daemon.itf->get_system_bus(daemon.closure);