00fe32b04a074ebd40a236a11ee26367b3fcd913
[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 llist_header lcntls;
31     struct term* term;
32     size_t (*process_and_put)(struct term*, struct linebuffer*, char);
33 };
34
35 struct term
36 {
37     struct device* dev;
38     struct device* chdev;
39     struct llist_header lcntl_stack;
40     struct linebuffer line_out;
41     struct linebuffer line_in;
42     pid_t fggrp;
43
44     struct
45     {
46         int (*set_speed)(struct device*, speed_t);
47     } chdev_ops;
48
49     /* -- POSIX.1-2008 compliant fields -- */
50     tcflag_t iflags;
51     tcflag_t oflags;
52     tcflag_t lflags;
53     cc_t cc[_NCCS];
54     speed_t iospeed;
55 };
56
57 struct term*
58 term_create(struct device* chardev, char* suffix);
59
60 int
61 term_bind(struct term* tdev, struct device* chdev);
62
63 int
64 term_push_lcntl(struct term* tdev, struct term_lcntl* lcntl);
65
66 int
67 term_pop_lcntl(struct term* tdev);
68
69 struct term_lcntl*
70 term_get_lcntl(u32_t lcntl_index);
71
72 static inline void
73 line_flip(struct linebuffer* lbf) {
74     struct rbuffer* tmp = lbf->current;
75     lbf->current = lbf->next;
76     lbf->next = tmp;
77 }
78
79 void
80 line_alloc(struct linebuffer* lbf, size_t sz_hlf);
81
82 void
83 line_free(struct linebuffer* lbf, size_t sz_hlf);
84
85 void
86 term_sendsig(struct term* tdev, int signal);
87
88 int
89 term_flush(struct term* tdev);
90
91 int
92 term_read(struct term* tdev);
93
94 int
95 lcntl_transform_inseq(struct term* tdev);
96
97 int
98 lcntl_transform_outseq(struct term* tdev);
99
100 #endif /* __LUNAIX_TERM_H */