1/* Definitions used by the GDB event loop.
2   Copyright (C) 1999, 2000, 2007 Free Software Foundation, Inc.
3   Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
4
5   This file is part of GDB.
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 3 of the License, or
10   (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20/* An event loop listens for events from multiple event sources. When
21   an event arrives, it is queued and processed by calling the
22   appropriate event handler. The event loop then continues to listen
23   for more events. An event loop completes when there are no event
24   sources to listen on.  External event sources can be plugged into
25   the loop.
26
27   There are 3 main components:
28   - a list of file descriptors to be monitored, GDB_NOTIFIER.
29   - a list of events that have occurred, EVENT_QUEUE.
30   - a list of signal handling functions, SIGHANDLER_LIST.
31
32   GDB_NOTIFIER keeps track of the event sources. Event sources for
33   gdb are currently the UI and the target.  Gdb communicates with the
34   command line user interface via the readline library and usually
35   communicates with remote targets via a serial port. Serial ports
36   are represented in GDB as file descriptors and select/poll calls.
37   For native targets instead, the communication consists of calls to
38   ptrace and waits (via signals) or calls to poll/select (via file
39   descriptors). In the current gdb, the code handling events related
40   to the target resides in the wait_for_inferior function and in
41   various target specific files (*-tdep.c).
42
43   EVENT_QUEUE keeps track of the events that have happened during the
44   last iteration of the event loop, and need to be processed.  An
45   event is represented by a procedure to be invoked in order to
46   process the event.  The queue is scanned head to tail.  If the
47   event of interest is a change of state in a file descriptor, then a
48   call to poll or select will be made to detect it.
49
50   If the events generate signals, they are also queued by special
51   functions that are invoked through traditional signal handlers.
52   The actions to be taken is response to such events will be executed
53   when the SIGHANDLER_LIST is scanned, the next time through the
54   infinite loop.
55
56   Corollary tasks are the creation and deletion of event sources. */
57
58typedef void *gdb_client_data;
59struct async_signal_handler;
60typedef void (handler_func) (int, gdb_client_data);
61typedef void (sig_handler_func) (gdb_client_data);
62typedef void (timer_handler_func) (gdb_client_data);
63
64/* Where to add an event onto the event queue, by queue_event. */
65typedef enum
66  {
67    /* Add at tail of queue. It will be processed in first in first
68       out order. */
69    TAIL,
70    /* Add at head of queue. It will be processed in last in first out
71       order. */
72    HEAD
73  }
74queue_position;
75
76/* Tell create_file_handler what events we are interested in.
77   This is used by the select version of the event loop. */
78
79#define GDB_READABLE	(1<<1)
80#define GDB_WRITABLE	(1<<2)
81#define GDB_EXCEPTION	(1<<3)
82
83/* Exported functions from event-loop.c */
84
85extern void start_event_loop (void);
86extern int gdb_do_one_event (void *data);
87extern void delete_file_handler (int fd);
88extern void add_file_handler (int fd, handler_func * proc, gdb_client_data client_data);
89extern void mark_async_signal_handler (struct async_signal_handler *async_handler_ptr);
90extern struct async_signal_handler *
91  create_async_signal_handler (sig_handler_func * proc, gdb_client_data client_data);
92extern void delete_async_signal_handler (struct async_signal_handler **async_handler_ptr);
93extern int create_timer (int milliseconds, timer_handler_func * proc, gdb_client_data client_data);
94extern void delete_timer (int id);
95