log: Allow runtime selection of 'debug' log level
[petitboot] / discover / device-handler.h
1 #ifndef _DEVICE_HANDLER_H
2 #define _DEVICE_HANDLER_H
3
4 #include <stdbool.h>
5
6 #include <list/list.h>
7
8 struct device_handler;
9 struct discover_device;
10 struct discover_server;
11 struct boot_option;
12 struct boot_command;
13 struct event;
14 struct device;
15 struct waitset;
16 struct config;
17
18 struct discover_device {
19         struct device           *device;
20
21         char                    **links;
22         int                     n_links;
23
24         const char              *uuid;
25         const char              *label;
26
27         char                    *mount_path;
28         const char              *device_path;
29         bool                    mounted;
30         bool                    mounted_rw;
31         bool                    unmount;
32
33         bool                    notified;
34
35         struct list             boot_options;
36         struct list             params;
37 };
38
39 struct discover_boot_option {
40         struct parser           *source;
41         struct discover_device  *device;
42         struct boot_option      *option;
43         struct list_item        list;
44
45         struct resource         *boot_image;
46         struct resource         *initrd;
47         struct resource         *dtb;
48         struct resource         *icon;
49 };
50
51
52 struct discover_context {
53         struct parser           *parser;
54         struct event            *event;
55         struct discover_device  *device;
56         struct list             boot_options;
57         struct pb_url           *conf_url;
58         void                    *test_data;
59 };
60
61 struct device_handler *device_handler_init(struct discover_server *server,
62                 struct waitset *waitset, int dry_run);
63
64 void device_handler_destroy(struct device_handler *devices);
65
66 int device_handler_get_device_count(const struct device_handler *handler);
67 const struct discover_device *device_handler_get_device(
68         const struct device_handler *handler, unsigned int index);
69
70 struct discover_device *discover_device_create(struct device_handler *handler,
71                 const char *id);
72 void device_handler_add_device(struct device_handler *handler,
73                 struct discover_device *device);
74 int device_handler_discover(struct device_handler *handler,
75                 struct discover_device *dev);
76 int device_handler_dhcp(struct device_handler *handler,
77                 struct discover_device *dev, struct event *event);
78 int device_handler_conf(struct device_handler *handler,
79                 struct discover_device *dev, struct pb_url *url);
80 void device_handler_remove(struct device_handler *handler,
81                 struct discover_device *device);
82
83 struct discover_context *device_handler_discover_context_create(
84                 struct device_handler *handler,
85                 struct discover_device *device);
86 void device_handler_discover_context_commit(struct device_handler *handler,
87                 struct discover_context *ctx);
88
89 struct discover_boot_option *discover_boot_option_create(
90                 struct discover_context *ctx,
91                 struct discover_device *dev);
92 void discover_context_add_boot_option(struct discover_context *ctx,
93                 struct discover_boot_option *opt);
94
95 int device_handler_user_event(struct device_handler *handler,
96                                 struct event *event);
97
98 struct discover_device *device_lookup_by_name(struct device_handler *handler,
99                 const char *name);
100 struct discover_device *device_lookup_by_uuid(struct device_handler *handler,
101                 const char *uuid);
102 struct discover_device *device_lookup_by_label(struct device_handler *handler,
103                 const char *label);
104 struct discover_device *device_lookup_by_id(struct device_handler *handler,
105                 const char *id);
106 struct discover_device *device_lookup_by_serial(
107                 struct device_handler *device_handler,
108                 const char *serial);
109
110 void discover_device_set_param(struct discover_device *device,
111                 const char *name, const char *value);
112 const char *discover_device_get_param(struct discover_device *device,
113                 const char *name);
114
115 void device_handler_boot(struct device_handler *handler,
116                 struct boot_command *cmd);
117 void device_handler_cancel_default(struct device_handler *handler);
118 void device_handler_update_config(struct device_handler *handler,
119                 struct config *config);
120 void device_handler_reinit(struct device_handler *handler);
121
122 int device_request_write(struct discover_device *dev, bool *release);
123 void device_release_write(struct discover_device *dev, bool release);
124
125 #endif /* _DEVICE_HANDLER_H */