b78f9af98d8535a6d53d2b7ccbced56cded84307
[src/app-framework-binder.git] / include / afb / afb-daemon-itf.h
1 /*
2  * Copyright (C) 2016, 2017 "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 <stdarg.h>
21
22 /* declaration of features of libsystemd */
23 struct sd_event;
24 struct sd_bus;
25 struct afb_stored_req;
26 struct afb_req;
27 struct afb_dynapi;
28
29 /*
30  * Definition of the facilities provided by the daemon.
31  */
32 struct afb_daemon_itf
33 {
34         int (*event_broadcast)(void *closure, const char *name, struct json_object *object); /* broadcasts evant 'name' with 'object' */
35         struct sd_event *(*get_event_loop)(void *closure);      /* gets the common systemd's event loop */
36         struct sd_bus *(*get_user_bus)(void *closure);          /* gets the common systemd's user d-bus */
37         struct sd_bus *(*get_system_bus)(void *closure);        /* gets the common systemd's system d-bus */
38         void (*vverbose_v1)(void*closure, int level, const char *file, int line, const char *fmt, va_list args);
39         struct afb_event (*event_make)(void *closure, const char *name); /* creates an event of 'name' */
40         int (*rootdir_get_fd)(void *closure);
41         int (*rootdir_open_locale)(void *closure, const char *filename, int flags, const char *locale);
42         int (*queue_job)(void *closure, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout);
43         void (*vverbose_v2)(void*closure, int level, const char *file, int line, const char * func, const char *fmt, va_list args);
44         struct afb_req (*unstore_req)(void*closure, struct afb_stored_req *sreq);
45         int (*require_api)(void*closure, const char *name, int initialized);
46         int (*rename_api)(void*closure, const char *name);
47         int (*new_api)(void *closure, const char *api, const char *info, int (*preinit)(void*, struct afb_dynapi *), void *preinit_closure);
48 };
49
50 /*
51  * Structure for accessing daemon.
52  * See also: afb_daemon_get_event_sender, afb_daemon_get_event_loop, afb_daemon_get_user_bus, afb_daemon_get_system_bus
53  */
54 struct afb_daemon
55 {
56         const struct afb_daemon_itf *itf;       /* the interfacing functions */
57         void *closure;                          /* the closure when calling these functions */
58 };
59