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