Improve documentation of api v3
[src/app-framework-binder.git] / docs / reference-v3 / func-daemon.md
1 Functions of class **afb_daemon**
2 ============================
3
4 All the functions of the class **afb_daemon** use the default api.
5 This are internally aliased to the corresponding function of class afb_api_t.
6
7 ```C
8 /**
9  * Retrieves the common systemd's event loop of AFB
10  */
11 struct sd_event *afb_daemon_get_event_loop();
12
13 /**
14  * Retrieves the common systemd's user/session d-bus of AFB
15  */
16 struct sd_bus *afb_daemon_get_user_bus();
17
18 /**
19  * Retrieves the common systemd's system d-bus of AFB
20  */
21 struct sd_bus *afb_daemon_get_system_bus();
22
23 /**
24  * Broadcasts widely the event of 'name' with the data 'object'.
25  * 'object' can be NULL.
26  *
27  * For convenience, the function calls 'json_object_put' for 'object'.
28  * Thus, in the case where 'object' should remain available after
29  * the function returns, the function 'json_object_get' shall be used.
30  *
31  * Calling this function is only forbidden during preinit.
32  *
33  * Returns the count of clients that received the event.
34  */
35 int afb_daemon_broadcast_event(
36                         const char *name,
37                         struct json_object *object);
38
39 /**
40  * Creates an event of 'name' and returns it.
41  *
42  * Calling this function is only forbidden during preinit.
43  *
44  * See afb_event_is_valid to check if there is an error.
45  */
46 afb_event_t afb_daemon_make_event(
47                         const char *name);
48
49 /**
50  * @deprecated use bindings version 3
51  *
52  * Send a message described by 'fmt' and following parameters
53  * to the journal for the verbosity 'level'.
54  *
55  * 'file', 'line' and 'func' are indicators of position of the code in source files
56  * (see macros __FILE__, __LINE__ and __func__).
57  *
58  * 'level' is defined by syslog standard:
59  *      EMERGENCY         0        System is unusable
60  *      ALERT             1        Action must be taken immediately
61  *      CRITICAL          2        Critical conditions
62  *      ERROR             3        Error conditions
63  *      WARNING           4        Warning conditions
64  *      NOTICE            5        Normal but significant condition
65  *      INFO              6        Informational
66  *      DEBUG             7        Debug-level messages
67  */
68 void afb_daemon_verbose(
69                         int level,
70                         const char *file,
71                         int line,
72                         const char * func,
73                         const char *fmt,
74                         ...);
75
76 /**
77  * @deprecated use bindings version 3
78  *
79  * Get the root directory file descriptor. This file descriptor can
80  * be used with functions 'openat', 'fstatat', ...
81  *
82  * Returns the file descriptor or -1 in case of error.
83  */
84 int afb_daemon_rootdir_get_fd();
85
86 /**
87  * Opens 'filename' within the root directory with 'flags' (see function openat)
88  * using the 'locale' definition (example: "jp,en-US") that can be NULL.
89  *
90  * Returns the file descriptor or -1 in case of error.
91  */
92 int afb_daemon_rootdir_open_locale(
93                         const char *filename,
94                         int flags,
95                         const char *locale);
96
97 /**
98  * Queue the job defined by 'callback' and 'argument' for being executed asynchronously
99  * in this thread (later) or in an other thread.
100  * If 'group' is not NUL, the jobs queued with a same value (as the pointer value 'group')
101  * are executed in sequence in the order of there submission.
102  * If 'timeout' is not 0, it represent the maximum execution time for the job in seconds.
103  * At first, the job is called with 0 as signum and the given argument.
104  * The job is executed with the monitoring of its time and some signals like SIGSEGV and
105  * SIGFPE. When a such signal is catched, the job is terminated and reexecuted but with
106  * signum being the signal number (SIGALRM when timeout expired).
107  *
108  * Returns 0 in case of success or -1 in case of error.
109  */
110 int afb_daemon_queue_job(
111                         void (*callback)(int signum, void *arg),
112                         void *argument,
113                         void *group,
114                         int timeout);
115
116 /**
117  * Tells that it requires the API of "name" to exist
118  * and if 'initialized' is not null to be initialized.
119  * Calling this function is only allowed within init.
120  *
121  * Returns 0 in case of success or -1 in case of error.
122  */
123 int afb_daemon_require_api(
124                         const char *name,
125                         int initialized);
126
127 /**
128  * Create an aliased name 'as_name' for the api 'name'.
129  * Calling this function is only allowed within preinit.
130  *
131  * Returns 0 in case of success or -1 in case of error.
132  */
133 int afb_daemon_add_alias(const char *name, const char *as_name);
134
135 /**
136  * Creates a new api of name 'api' with brief 'info'.
137  *
138  * Returns 0 in case of success or -1 in case of error.
139  */
140 int afb_daemon_new_api(
141                         const char *api,
142                         const char *info,
143                         int noconcurrency,
144                         int (*preinit)(void*, struct afb_api_x3 *),
145                         void *closure);
146 ```