Cygwin: strptime: add release note
[newlib-cygwin.git] / winsup / cygwin / local_includes / tty.h
blobdf3bf60bf4b26578f4f8f2e61a278e78e56a814c
1 /* tty.h: shared tty info for cygwin
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
9 #ifndef _TTY_H
10 #define _TTY_H
11 /* tty tables */
13 #define INP_BUFFER_SIZE 256
14 #define OUT_BUFFER_SIZE 256
15 #define NTTYS 128
16 #define real_tty_attached(p) (CTTY_IS_VALID ((p)->ctty) && !iscons_dev ((p)->ctty))
18 /* Input/Output/ioctl events */
20 #define INPUT_AVAILABLE_EVENT "cygtty.input.avail"
21 #define OUTPUT_MUTEX "cygtty.output.mutex"
22 #define INPUT_MUTEX "cygtty.input.mutex"
23 #define PIPE_SW_MUTEX "cygtty.pipe_sw.mutex"
24 #define TTY_SLAVE_ALIVE "cygtty.slave_alive"
25 #define TTY_SLAVE_READING "cygtty.slave_reading"
27 #include <sys/termios.h>
29 #ifndef MIN_CTRL_C_SLOP
30 #define MIN_CTRL_C_SLOP 50
31 #endif
33 typedef void *HPCON;
35 #include "devices.h"
36 class tty_min
38 pid_t sid; /* Session ID of tty */
39 struct status_flags
41 unsigned initialized : 1; /* Set if tty is initialized */
42 } status;
44 public:
45 pid_t pgid;
46 bool output_stopped; /* FIXME: Maybe do this with a mutex someday? */
47 fh_devices ntty;
48 ULONGLONG last_ctrl_c; /* tick count of last ctrl-c */
49 bool is_console;
50 int last_sig;
52 IMPLEMENT_STATUS_FLAG (bool, initialized)
54 struct termios ti;
55 struct winsize winsize;
57 /* ioctl requests buffer */
58 int cmd;
59 union
61 struct termios termios;
62 struct winsize winsize;
63 int value;
64 pid_t pid;
65 } arg;
66 /* XXX_retval variables holds master's completion codes. Error are stored as
67 * -ERRNO
69 int ioctl_retval;
71 void setntty (_major_t t, _minor_t n) {ntty = (fh_devices) FHDEV (t, n);}
72 dev_t getntty () const {return ntty;}
73 _minor_t get_minor () const {return device::minor (ntty);}
74 pid_t getpgid () const {return pgid;}
75 void setpgid (int pid);
76 int getsid () const {return sid;}
77 void setsid (pid_t tsid) {sid = tsid;}
78 void kill_pgrp (int, pid_t target_pgid = 0);
79 int is_orphaned_process_group (int);
80 const char *ttyname () __attribute (());
84 /* The name *nat* comes from 'native' which means non-cygwin
85 (native windows). They are used for non-cygwin process. */
87 class fhandler_pty_master;
89 class tty: public tty_min
91 HANDLE get_event (const char *fmt, PSECURITY_ATTRIBUTES sa,
92 BOOL manual_reset = FALSE);
93 public:
94 pid_t master_pid; /* PID of tty master process */
96 /* Transfer direction for fhandler_pty_slave::transfer_input() */
97 enum xfer_dir
99 to_cyg,
100 to_nat
102 enum cons_mode
104 restore, /* For restoring when exit from cygwin. */
105 cygwin, /* For cygwin apps */
106 native /* For native apps executed from cygwin. */
109 private:
110 HANDLE _from_master_nat;
111 HANDLE _from_master;
112 HANDLE _to_master_nat;
113 HANDLE _to_master;
114 HANDLE _to_slave_nat;
115 HANDLE _to_slave;
116 bool pcon_activated;
117 bool pcon_start;
118 pid_t pcon_start_pid;
119 bool switch_to_nat_pipe;
120 DWORD nat_pipe_owner_pid;
121 UINT term_code_page;
122 ULONGLONG fwd_last_time;
123 bool fwd_not_empty;
124 HANDLE h_pcon_write_pipe;
125 HANDLE h_pcon_condrv_reference;
126 HANDLE h_pcon_conhost_process;
127 HANDLE h_pcon_in;
128 HANDLE h_pcon_out;
129 bool pcon_cap_checked;
130 bool has_csi6n;
131 bool need_invisible_console;
132 pid_t invisible_console_pid;
133 UINT previous_code_page;
134 UINT previous_output_code_page;
135 bool master_is_running_as_service;
136 bool req_xfer_input;
137 xfer_dir pty_input_state;
138 bool mask_flusho;
139 bool discard_input;
140 bool stop_fwd_thread;
142 public:
143 HANDLE from_master_nat () const { return _from_master_nat; }
144 HANDLE from_master () const { return _from_master; }
145 HANDLE to_master_nat () const { return _to_master_nat; }
146 HANDLE to_master () const { return _to_master; }
147 HANDLE to_slave_nat () const { return _to_slave_nat; }
148 HANDLE to_slave () const { return _to_slave; }
149 void set_from_master_nat (HANDLE h) { _from_master_nat = h; }
150 void set_from_master (HANDLE h) { _from_master = h; }
151 void set_to_master_nat (HANDLE h) { _to_master_nat = h; }
152 void set_to_master (HANDLE h) { _to_master = h; }
153 void set_to_slave_nat (HANDLE h) { _to_slave_nat = h; }
154 void set_to_slave (HANDLE h) { _to_slave = h; }
156 int read_retval;
157 bool was_opened; /* True if opened at least once. */
158 int column; /* Current Column */
160 void init ();
161 HANDLE open_inuse (ACCESS_MASK access);
162 HANDLE create_inuse (PSECURITY_ATTRIBUTES);
163 bool slave_alive ();
164 HANDLE open_mutex (const char *mutex, ACCESS_MASK access);
165 inline HANDLE open_output_mutex (ACCESS_MASK access)
166 { return open_mutex (OUTPUT_MUTEX, access); }
167 inline HANDLE open_input_mutex (ACCESS_MASK access)
168 { return open_mutex (INPUT_MUTEX, access); }
169 bool exists ();
170 bool not_allocated (HANDLE&, HANDLE&);
171 void set_master_ctl_closed () {master_pid = -1;}
172 static void create_master (int);
173 static void init_session ();
174 void wait_fwd ();
175 bool pty_input_state_eq (xfer_dir x) { return pty_input_state == x; }
176 bool nat_fg (pid_t pgid);
177 friend class fhandler_pty_common;
178 friend class fhandler_pty_master;
179 friend class fhandler_pty_slave;
180 friend class tty_min;
183 class tty_list
185 tty ttys[NTTYS];
186 static HANDLE mutex;
188 public:
189 tty * operator [](int n) {return ttys + device::minor (n);}
190 int allocate (HANDLE& r, HANDLE& w); /* allocate a pty */
191 int connect (int);
192 void init ();
193 tty_min *get_cttyp ();
194 int attach (int n);
195 static void init_session ();
196 friend class lock_ttys;
199 class lock_ttys
201 bool release_me;
202 public:
203 lock_ttys (DWORD = INFINITE);
204 static void release ();
205 void dont_release () {release_me = false;}
206 ~lock_ttys ()
208 if (release_me)
209 release ();
213 extern "C" int ttyslot (void);
214 #endif /*_TTY_H*/