OSDN Git Service

* cygheap.h (struct init_cygheap): Remove shared_h and mt_h members.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / tty.h
1 /* tty.h: shared tty info for cygwin
2
3    Copyright 2000, 2001, 2002, 2003, 2004, 2006 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 /* tty tables */
12
13 #define INP_BUFFER_SIZE 256
14 #define OUT_BUFFER_SIZE 256
15 #define NTTYS           128
16 #define real_tty_attached(p)    ((p)->ctty >= 0 && (p)->ctty != TTY_CONSOLE)
17
18 /* Input/Output/ioctl events */
19
20 #define OUTPUT_DONE_EVENT       "cygtty.output.done"
21 #define IOCTL_REQUEST_EVENT     "cygtty.ioctl.request"
22 #define IOCTL_DONE_EVENT        "cygtty.ioctl.done"
23 #define RESTART_OUTPUT_EVENT    "cygtty.output.restart"
24 #define INPUT_AVAILABLE_EVENT   "cygtty.input.avail"
25 #define OUTPUT_MUTEX            "cygtty.output.mutex"
26 #define INPUT_MUTEX             "cygtty.input.mutex"
27 #define TTY_SLAVE_ALIVE         "cygtty.slave_alive"
28 #define TTY_MASTER_ALIVE        "cygtty.master_alive"
29
30 #include <sys/termios.h>
31
32 #ifndef MIN_CTRL_C_SLOP
33 #define MIN_CTRL_C_SLOP 50
34 #endif
35
36 class tty_min
37 {
38   pid_t sid;    /* Session ID of tty */
39   struct status_flags
40   {
41     unsigned initialized : 1; /* Set if tty is initialized */
42     unsigned rstcons     : 1; /* Set if console needs to be set to "non-cooked" */
43   } status;
44
45 public:
46   pid_t pgid;
47   int output_stopped;
48   int ntty;
49   DWORD last_ctrl_c;    /* tick count of last ctrl-c */
50   HWND hwnd;            /* Console window handle tty belongs to */
51
52   IMPLEMENT_STATUS_FLAG (bool, initialized)
53   IMPLEMENT_STATUS_FLAG (bool, rstcons)
54
55   struct termios ti;
56   struct winsize winsize;
57
58   /* ioctl requests buffer */
59   int cmd;
60   union
61   {
62     struct termios termios;
63     struct winsize winsize;
64     int value;
65     pid_t pid;
66   } arg;
67   /* XXX_retval variables holds master's completion codes. Error are stored as
68    * -ERRNO
69    */
70   int ioctl_retval;
71   int write_error;
72
73   void setntty (int n) {ntty = n;}
74   pid_t getpgid () {return pgid;}
75   void setpgid (int pid) {pgid = pid;}
76   int getsid () {return sid;}
77   void setsid (pid_t tsid) {sid = tsid;}
78   void kill_pgrp (int sig);
79   HWND gethwnd () {return hwnd;}
80   void sethwnd (HWND wnd) {hwnd = wnd;}
81 };
82
83 class fhandler_pty_master;
84
85 class tty: public tty_min
86 {
87   HANDLE get_event (const char *fmt, BOOL manual_reset = FALSE)
88     __attribute__ ((regparm (3)));
89 public:
90   pid_t master_pid;     /* PID of tty master process */
91
92   HANDLE from_master, to_master;
93
94   int read_retval;
95   bool was_opened;      /* True if opened at least once. */
96
97   void init ();
98   HANDLE create_inuse (const char *);
99   bool alive (const char *fmt);
100   bool slave_alive ();
101   bool master_alive ();
102   HANDLE open_mutex (const char *mutex);
103   HANDLE open_output_mutex ();
104   HANDLE open_input_mutex ();
105   bool exists ()
106   {
107     if (!master_pid)
108       return false;
109     HANDLE h = open_output_mutex ();
110     if (h)
111       {
112         CloseHandle (h);
113         return 1;
114       }
115     return slave_alive ();
116   }
117   void set_master_closed () {master_pid = -1;}
118   static void __stdcall create_master (int);
119   static void __stdcall init_session ();
120   friend class fhandler_pty_master;
121 };
122
123 class tty_list
124 {
125   tty ttys[NTTYS];
126   static HANDLE mutex;
127
128 public:
129   tty * operator [](int n) {return ttys + n;}
130   int allocate (bool); /* true if allocate a tty, pty otherwise */
131   int connect (int);
132   void terminate ();
133   void init ();
134   tty_min *get_tty (int n);
135   int __stdcall attach (int);
136   static void __stdcall init_session ();
137   friend class lock_ttys;
138 };
139
140 class lock_ttys
141 {
142   bool release_me;
143 public:
144   lock_ttys (DWORD = INFINITE);
145   static void release ();
146   void dont_release () {release_me = false;}
147   ~lock_ttys ()
148   {
149     if (release_me)
150       release ();
151   }
152 };
153
154 extern "C" int ttyslot (void);