feat: owloysius - dynamic init function invocator
[lunaix-os.git] / lunaix-os / includes / hal / term.h
1 #ifndef __LUNAIX_TERM_H
2 #define __LUNAIX_TERM_H
3
4 #include <lunaix/device.h>
5 #include <lunaix/ds/rbuffer.h>
6 #include <lunaix/signal_defs.h>
7
8 #include <usr/lunaix/term.h>
9
10 struct term;
11
12 struct linebuffer
13 {
14     struct rbuffer* next;
15     struct rbuffer* current;
16     short sflags;
17     short sz_hlf;
18 };
19 #define LSTATE_EOL (1)
20 #define LSTATE_EOF (1 << 1)
21 #define LSTATE_SIGRAISE (1 << 2)
22
23 typedef struct rbuffer** lbuf_ref_t;
24 #define ref_current(lbuf) (&(lbuf)->current)
25 #define ref_next(lbuf) (&(lbuf)->next)
26 #define deref(bref) (*(bref))
27
28 struct term_lcntl
29 {
30     struct term* term;
31     int (*process_and_put)(struct term*, struct linebuffer*, char);
32 };
33
34 struct term
35 {
36     struct device* dev;
37     struct device* chdev;
38     struct term_lcntl* lcntl;
39     struct linebuffer line_out;
40     struct linebuffer line_in;
41     pid_t fggrp;
42
43     struct
44     {
45         int (*set_speed)(struct device*, speed_t);
46     } chdev_ops;
47
48     /* -- POSIX.1-2008 compliant fields -- */
49     tcflag_t iflags;
50     tcflag_t oflags;
51     tcflag_t lflags;
52     cc_t cc[_NCCS];
53     speed_t iospeed;
54 };
55
56 extern struct device* sysconsole;
57
58 struct term*
59 term_create(struct device* chardev, char* suffix);
60
61 int
62 term_bind(struct term* tdev, struct device* chdev);
63
64 int
65 term_push_lcntl(struct term* tdev, struct term_lcntl* lcntl);
66
67 int
68 term_pop_lcntl(struct term* tdev);
69
70 struct term_lcntl*
71 term_get_lcntl(u32_t lcntl_index);
72
73 static inline void
74 line_flip(struct linebuffer* lbf)
75 {
76     struct rbuffer* tmp = lbf->current;
77     lbf->current = lbf->next;
78     lbf->next = tmp;
79 }
80
81 void
82 line_alloc(struct linebuffer* lbf, size_t sz_hlf);
83
84 void
85 line_free(struct linebuffer* lbf, size_t sz_hlf);
86
87 void
88 term_sendsig(struct term* tdev, int signal);
89
90 int
91 term_flush(struct term* tdev);
92
93 int
94 term_read(struct term* tdev);
95
96 int
97 lcntl_transform_inseq(struct term* tdev);
98
99 int
100 lcntl_transform_outseq(struct term* tdev);
101
102 #endif /* __LUNAIX_TERM_H */