feat: input device subsystem to resolve race condition on polling input
[lunaix-os.git] / lunaix-os / includes / lunaix / device.h
1 #ifndef __LUNAIX_DEVICE_H
2 #define __LUNAIX_DEVICE_H
3
4 #define DEVICE_NAME_SIZE 32
5
6 #include <lunaix/ds/hstr.h>
7 #include <lunaix/ds/llist.h>
8 #include <lunaix/types.h>
9
10 #define DEV_MSKIF 0x00000003
11
12 #define DEV_IFVOL 0x0 // volumetric (block) device
13 #define DEV_IFSEQ 0x1 // sequential (character) device
14 #define DEV_IFCAT 0x2 // a device category (as device groupping)
15
16 typedef unsigned int dev_t;
17
18 struct device
19 {
20     struct llist_header siblings;
21     struct device* parent;
22     struct hstr name;
23     dev_t dev_id;
24     int dev_type;
25     char name_val[DEVICE_NAME_SIZE];
26     void* underlay;
27     int (*read)(struct device* dev, void* buf, size_t offset, size_t len);
28     int (*write)(struct device* dev, void* buf, size_t offset, size_t len);
29 };
30
31 struct device*
32 device_add(struct device* parent,
33            void* underlay,
34            char* name_fmt,
35            uint32_t type,
36            va_list args);
37
38 struct device*
39 device_addseq(struct device* parent, void* underlay, char* name_fmt, ...);
40
41 struct device*
42 device_addvol(struct device* parent, void* underlay, char* name_fmt, ...);
43
44 struct device*
45 device_addcat(struct device* parent, char* name_fmt, ...);
46
47 void
48 device_remove(struct device* dev);
49
50 struct device*
51 device_getbyid(struct llist_header* devlist, dev_t id);
52
53 struct device*
54 device_getbyhname(struct llist_header* devlist, struct hstr* name);
55
56 struct device*
57 device_getbyname(struct llist_header* devlist, const char* name, size_t len);
58
59 struct device*
60 device_getbyoffset(struct llist_header* devlist, int pos);
61
62 #endif /* __LUNAIX_DEVICE_H */