]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygwin/tty.h
* environ.cc (environ_init): Avoid a compiler warning.
[newlib-cygwin.git] / winsup / cygwin / tty.h
1 /* tty.h: shared tty info for cygwin
2
3 Copyright 2000, 2001, 2002 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11
12 /* tty tables */
13
14 #define INP_BUFFER_SIZE 256
15 #define OUT_BUFFER_SIZE 256
16 #define NTTYS 128
17 #define real_tty_attached(p) ((p)->ctty >= 0 && (p)->ctty != TTY_CONSOLE)
18
19 /* Input/Output/ioctl events */
20
21 #define OUTPUT_DONE_EVENT "cygtty%d.output.done"
22 #define IOCTL_REQUEST_EVENT "cygtty%d.ioctl.request"
23 #define IOCTL_DONE_EVENT "cygtty%d.ioctl.done"
24 #define RESTART_OUTPUT_EVENT "cygtty%d.output.restart"
25 #define INPUT_AVAILABLE_EVENT "cygtty%d.input.avail"
26 #define OUTPUT_MUTEX "cygtty%d.output.mutex"
27 #define INPUT_MUTEX "cygtty%d.input.mutex"
28 #define TTY_SLAVE_ALIVE "cygtty%x.slave_alive"
29 #define TTY_MASTER_ALIVE "cygtty%x.master_alive"
30
31 #include <sys/termios.h>
32
33 enum
34 {
35 TTY_INITIALIZED = 1, /* Set if tty is initialized */
36 TTY_RSTCONS = 2 /* Set if console needs to be set to "non-cooked" */
37 };
38
39 #define TTYISSETF(x) __ISSETF (tc, x, TTY)
40 #define TTYSETF(x) __SETF (tc, x, TTY)
41 #define TTYCLEARF(x) __CLEARF (tc, x, TTY)
42 #define TTYCONDSETF(n, x) __CONDSETF(n, tc, x, TTY)
43
44 #ifndef MIN_CTRL_C_SLOP
45 #define MIN_CTRL_C_SLOP 50
46 #endif
47
48 class tty_min
49 {
50 pid_t sid; /* Session ID of tty */
51 public:
52 DWORD status;
53 pid_t pgid;
54 int output_stopped;
55 int ntty;
56 DWORD last_ctrl_c; // tick count of last ctrl-c
57
58 tty_min (int t = -1, pid_t s = -1) : sid (s), ntty (t) {}
59 void setntty (int n) {ntty = n;}
60 pid_t getpgid () {return pgid;}
61 void setpgid (int pid) {pgid = pid;}
62 int getsid () {return sid;}
63 void setsid (pid_t tsid) {sid = tsid;}
64 void set_ctty (int ttynum, int flags);
65 void kill_pgrp (int sig);
66 struct termios ti;
67 struct winsize winsize;
68
69 /* ioctl requests buffer */
70 int cmd;
71 union
72 {
73 struct termios termios;
74 struct winsize winsize;
75 int value;
76 pid_t pid;
77 } arg;
78 /* XXX_retval variables holds master's completion codes. Error are stored as
79 * -ERRNO
80 */
81 int ioctl_retval;
82
83 int write_error;
84 };
85
86 class fhandler_pty_master;
87
88 class tty: public tty_min
89 {
90 HANDLE get_event (const char *fmt, BOOL manual_reset = FALSE)
91 __attribute__ ((regparm (2)));
92 public:
93 HWND hwnd; /* Console window handle tty belongs to */
94
95 DWORD master_pid; /* Win32 PID of tty master process */
96
97 HANDLE from_master, to_slave;
98 HANDLE from_slave, to_master;
99
100 int read_retval;
101 BOOL was_opened; /* True if opened at least once. */
102
103 void init ();
104 HANDLE create_inuse (const char *);
105 BOOL common_init (fhandler_pty_master *);
106 BOOL alive (const char *fmt);
107 BOOL slave_alive ();
108 BOOL master_alive ();
109 HWND gethwnd () {return hwnd;}
110 void sethwnd (HWND wnd) {hwnd = wnd;}
111 int make_pipes (fhandler_pty_master *ptym);
112 HANDLE open_output_mutex ()
113 {
114 char buf[80];
115 __small_sprintf (buf, OUTPUT_MUTEX, ntty);
116 return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
117 }
118 HANDLE open_input_mutex ()
119 {
120 char buf[80];
121 __small_sprintf (buf, INPUT_MUTEX, ntty);
122 return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
123 }
124 BOOL exists ()
125 {
126 HANDLE h = open_output_mutex ();
127 if (h)
128 {
129 CloseHandle (h);
130 return 1;
131 }
132 return slave_alive ();
133 }
134 };
135
136 class tty_list
137 {
138 tty ttys[NTTYS];
139
140 public:
141 tty * operator [](int n) {return ttys + n;}
142 int allocate_tty (int n); /* n non zero if allocate a tty, pty otherwise */
143 int connect_tty (int);
144 void terminate ();
145 void init ();
146 tty_min *get_tty (int n);
147 };
148
149 void __stdcall tty_init ();
150 void __stdcall tty_terminate ();
151 int __stdcall attach_tty (int);
152 void __stdcall create_tty_master (int);
153 extern "C" int ttyslot (void);
This page took 0.043119 seconds and 5 git commands to generate.