-
Notifications
You must be signed in to change notification settings - Fork 8
/
frontend.h
86 lines (66 loc) · 2.87 KB
/
frontend.h
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
#ifndef _FRONTEND_H_
#define _FRONTEND_H_
#include <stdbool.h>
struct frontend;
#include "framebuffer.h"
#include "llist.h"
#define FRONTEND_ALLOC(name) int (*name)(struct frontend** res, struct fb* fb, void* priv)
#define FRONTEND_START(name) int (*name)(struct frontend* front)
#define FRONTEND_FREE(name) void (*name)(struct frontend* front)
#define FRONTEND_UPDATE(name) int (*name)(struct frontend* front)
#define FRONTEND_DRAW_STRING(name) int (*name)(struct frontend* front, unsigned x, unsigned y, char* str)
typedef int (*frontend_alloc)(struct frontend** res, struct fb* fb, void* priv);
typedef int (*frontend_start)(struct frontend* front);
typedef void (*frontend_free)(struct frontend* front);
typedef int (*frontend_update)(struct frontend* front);
typedef int (*frontend_draw_string)(struct frontend* front, unsigned x, unsigned y, char* str);
struct frontend_ops {
FRONTEND_ALLOC(alloc);
FRONTEND_START(start);
FRONTEND_FREE(free);
FRONTEND_UPDATE(update);
FRONTEND_DRAW_STRING(draw_string);
};
struct frontend_arg {
char* name;
int (*configure)(struct frontend* front, char* value);
};
struct frontend_def {
char* name;
const struct frontend_ops* ops;
bool handles_signals;
const struct frontend_arg* args;
};
#define DECLARE_FRONTEND(name, frontname, frontops, sig) \
struct frontend_def name = {frontname, frontops, sig, NULL}
#define DECLARE_FRONTEND_SIG(name, frontname, frontops) \
DECLARE_FRONTEND(name, frontname, frontops, true)
#define DECLARE_FRONTEND_NOSIG(name, frontname, frontops) \
DECLARE_FRONTEND(name, frontname, frontops, false)
#define DECLARE_FRONTEND_ARGS(name, frontname, frontops, sig, arg_names) \
struct frontend_def name = {frontname, frontops, sig, arg_names}
#define DECLARE_FRONTEND_SIG_ARGS(name, frontname, frontops, arg_names) \
DECLARE_FRONTEND_ARGS(name, frontname, frontops, true, arg_names)
#define DECLARE_FRONTEND_NOSIG_ARGS(name, frontname, frontops, arg_names) \
DECLARE_FRONTEND_ARGS(name, frontname, frontops, false, arg_names)
#define frontend_alloc(def, front, fb, priv) ((def)->ops->alloc((front), (fb), (priv)))
#define frontend_start(front) ((front)->def->ops->start((front)))
#define frontend_free(front) ((front)->def->ops->free((front)))
#define frontend_update(front) ((front)->def->ops->update((front)))
#define frontend_draw_string(front, x, y, str) ((front)->def->ops->draw_string((front), (x), (y), (str)))
#define frontend_can_configure(front) (!!(front)->def->args)
#define frontend_can_start(front) (!!(front)->def->ops->start)
#define frontend_can_draw_string(front) (!!(front)->def->ops->draw_string)
struct frontend {
struct frontend_def* def;
struct llist_entry list;
bool sync_overlay_draw;
};
struct frontend_id {
char* id;
struct frontend_def* def;
};
struct frontend_def* frontend_get_def(char* id);
char* frontend_spec_extract_name(char* spec);
int frontend_configure(struct frontend* front, char* options);
#endif