Change of vterm handling logic on backend chardev input event (#40)
[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/ds/waitq.h>
7 #include <lunaix/signal_defs.h>
8
9 #include <usr/lunaix/term.h>
10
11 struct term;
12
13 struct linebuffer
14 {
15     struct rbuffer* next;
16     struct rbuffer* current;
17     short sflags;
18     short sz_hlf;
19 };
20 #define LEVT_EOL (1)
21 #define LEVT_EOF (1 << 1)
22 #define LEVT_SIGRAISE (1 << 2)
23
24 typedef struct rbuffer** lbuf_ref_t;
25 #define ref_current(lbuf) (&(lbuf)->current)
26 #define ref_next(lbuf) (&(lbuf)->next)
27 #define deref(bref) (*(bref))
28
29 /**
30  * @brief Communication port capability that a device is supported natively, 
31  *          or able to emulate low level serial transmission behaviour specify 
32  *          by POSIX1-2008, section 11.
33  * 
34  */
35 #define TERMPORT_CAP 0x4d524554U
36
37 /**
38  * @brief A termios capability that a device provide interfaces which is 
39  *          compliant to POSIX1-2008
40  * 
41  */
42 #define TERMIOS_CAP 0x534f4954U
43
44 struct term;
45
46 struct termport_cap_ops
47 {
48     void (*set_speed)(struct device*, speed_t);
49     void (*set_clkbase)(struct device*, unsigned int);
50     void (*set_cntrl_mode)(struct device*, tcflag_t);
51 };
52
53 struct termport_capability
54 {
55     CAPABILITY_META;
56     struct termport_cap_ops* cap_ops;
57     struct term* term;
58 };
59
60 struct term
61 {
62     struct device* dev;
63     struct device* chdev;
64     struct linebuffer line_out;
65     struct linebuffer line_in;
66     char* scratch_pad;
67     pid_t fggrp;
68
69     struct termport_capability* tp_cap;
70     waitq_t line_in_event;
71
72     /* -- POSIX.1-2008 compliant fields -- */
73     tcflag_t iflags;
74     tcflag_t oflags;
75     tcflag_t lflags;
76     tcflag_t cflags;
77     cc_t cc[_NCCS];
78
79     /* -- END POSIX.1-2008 compliant fields -- */
80     speed_t iospeed;
81     speed_t clkbase;
82     tcflag_t tflags;    // temp flags
83 };
84
85 extern struct device* sysconsole;
86
87 struct term*
88 term_create(struct device* chardev, char* suffix);
89
90 int
91 term_bind(struct term* tdev, struct device* chdev);
92
93 static inline void
94 line_flip(struct linebuffer* lbf)
95 {
96     struct rbuffer* tmp = lbf->current;
97     lbf->current = lbf->next;
98     lbf->next = tmp;
99 }
100
101 void
102 line_alloc(struct linebuffer* lbf, size_t sz_hlf);
103
104 void
105 line_free(struct linebuffer* lbf, size_t sz_hlf);
106
107 void
108 term_sendsig(struct term* tdev, int signal);
109
110 int
111 term_flush(struct term* tdev);
112
113 int
114 term_read(struct term* tdev);
115
116 int
117 lcntl_transform_inseq(struct term* tdev);
118
119 int
120 lcntl_transform_outseq(struct term* tdev);
121
122 static inline void
123 term_cap_set_operations(struct termport_capability* cap, 
124                         struct termport_cap_ops* ops)
125 {
126     cap->cap_ops = ops;
127 }
128
129 void
130 term_notify_data_avaliable(struct termport_capability* cap);
131
132 #define termport_default_ops                                    \
133     ({                                                          \
134         extern struct termport_cap_ops default_termport_cap_ops;\
135         &default_termport_cap_ops;                              \
136     })
137
138 #endif /* __LUNAIX_TERM_H */