]> git.ozlabs.org Git - petitboot/blob - discover/parser.h
discover/grub2: Rework config state
[petitboot] / discover / parser.h
1 #ifndef _PARSER_H
2 #define _PARSER_H
3
4 #include <stdbool.h>
5
6 #include "device-handler.h"
7
8 struct discover_context;
9 struct device_handler;
10 struct resource;
11
12 /**
13  * Our config parser.
14  *
15  * Each parser is responsible for creating discover_boot_options from config
16  * files found on new devices. The boot items discovered during parse will have
17  * 'resources' attached (see @discover_boot_option), which may already be
18  * resolved (in the case of a device-local filename, or a URL), or unresolved
19  * (in the case of a filename on another device).
20  *
21  * If the boot option contains references to unresolved resources, the
22  * device handler will not inform clients about the boot options, as
23  * they're not properly "available" at this stage. The handler will attempt to
24  * resolve them whenever new devices are discovered, by calling the parser's
25  * resolve_resource function. Once a boot option's resources are full resolved,
26  * the option can be sent to clients.
27  */
28 struct parser {
29         char                    *name;
30         enum conf_method        method;
31         const char * const      *filenames;
32         int                     (*parse)(struct discover_context *ctx,
33                                                 char *buf, int len);
34         bool                    (*resolve_resource)(
35                                                 struct device_handler *handler,
36                                                 struct resource *res);
37 };
38
39 enum generic_icon_type {
40         ICON_TYPE_DISK,
41         ICON_TYPE_USB,
42         ICON_TYPE_OPTICAL,
43         ICON_TYPE_NETWORK,
44         ICON_TYPE_UNKNOWN
45 };
46
47 #define streq(a,b) (!strcasecmp((a),(b)))
48
49 void parser_init(void);
50
51 void iterate_parsers(struct discover_context *ctx, enum conf_method method);
52 int parse_user_event(struct discover_context *ctx, struct event *event);
53
54 #endif /* _PARSER_H */