-
Notifications
You must be signed in to change notification settings - Fork 3
/
airscan-init.c
87 lines (74 loc) · 1.79 KB
/
airscan-init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* AirScan (a.k.a. eSCL) backend for SANE
*
* Copyright (C) 2019 and up by Alexander Pevzner ([email protected])
* See LICENSE for license terms and conditions
*
* Initialization/cleanup
*/
#include "airscan.h"
/* Initialize airscan
*/
SANE_Status
airscan_init (AIRSCAN_INIT_FLAGS flags, const char *log_msg)
{
SANE_Status status;
/* Initialize logging -- do it early */
log_init();
trace_init();
if (log_msg != NULL) {
log_debug(NULL, "%s", log_msg);
}
if ((flags & AIRSCAN_INIT_NO_CONF) == 0) {
conf_load();
}
log_configure(); /* As soon, as configuration is available */
/* Initialize all parts */
devid_init();
status = eloop_init();
if (status == SANE_STATUS_GOOD) {
status = rand_init();
}
if (status == SANE_STATUS_GOOD) {
status = http_init();
}
if (status == SANE_STATUS_GOOD) {
status = netif_init();
}
if (status == SANE_STATUS_GOOD) {
status = zeroconf_init();
}
if (status == SANE_STATUS_GOOD) {
status = mdns_init();
}
if (status == SANE_STATUS_GOOD) {
status = wsdd_init();
}
if (status != SANE_STATUS_GOOD) {
airscan_cleanup(NULL);
} else if ((flags & AIRSCAN_INIT_NO_THREAD) == 0) {
eloop_thread_start();
}
return status;
}
/* Cleanup airscan
* If log_msg is not NULL, it is written to the log as late as possible
*/
void
airscan_cleanup (const char *log_msg)
{
mdns_cleanup();
wsdd_cleanup();
zeroconf_cleanup();
netif_cleanup();
http_cleanup();
rand_cleanup();
eloop_cleanup();
if (log_msg != NULL) {
log_debug(NULL, "%s", log_msg);
}
conf_unload();
trace_cleanup();
log_cleanup(); /* Must be the last thing to do */
}
/* vim:ts=8:sw=4:et
*/