annotate libcc1/connection.hh @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Plugin connection declarations
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2014-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #ifndef CC1_PLUGIN_CONNECTION_HH
kono
parents:
diff changeset
21 #define CC1_PLUGIN_CONNECTION_HH
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 #include "status.hh"
kono
parents:
diff changeset
24 #include "callbacks.hh"
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 namespace cc1_plugin
kono
parents:
diff changeset
27 {
kono
parents:
diff changeset
28 // The connection class represents one side of the connection
kono
parents:
diff changeset
29 // between the gdb-side library and the gcc plugin. It handles the
kono
parents:
diff changeset
30 // low-level details of reading and writing data.
kono
parents:
diff changeset
31 class connection
kono
parents:
diff changeset
32 {
kono
parents:
diff changeset
33 public:
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 connection (int fd)
kono
parents:
diff changeset
36 : m_fd (fd),
kono
parents:
diff changeset
37 m_aux_fd (-1),
kono
parents:
diff changeset
38 m_callbacks ()
kono
parents:
diff changeset
39 {
kono
parents:
diff changeset
40 }
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 connection (int fd, int aux_fd)
kono
parents:
diff changeset
43 : m_fd (fd),
kono
parents:
diff changeset
44 m_aux_fd (aux_fd),
kono
parents:
diff changeset
45 m_callbacks ()
kono
parents:
diff changeset
46 {
kono
parents:
diff changeset
47 }
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 virtual ~connection ();
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 // Send a single character. This is used to introduce various
kono
parents:
diff changeset
52 // higher-level protocol elements.
kono
parents:
diff changeset
53 status send (char c);
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 // Send data in bulk.
kono
parents:
diff changeset
56 status send (const void *buf, int len);
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 // Read a single byte from the connection and verify that it
kono
parents:
diff changeset
59 // matches the argument C.
kono
parents:
diff changeset
60 status require (char c);
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 // Read data in bulk.
kono
parents:
diff changeset
63 status get (void *buf, int len);
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 // This is called after a query (remote function call) has been
kono
parents:
diff changeset
66 // sent to the remote. It waits for a response packet. The
kono
parents:
diff changeset
67 // response character is read before returning. Any query packets
kono
parents:
diff changeset
68 // sent from the remote while waiting for a response are handled
kono
parents:
diff changeset
69 // by this function.
kono
parents:
diff changeset
70 status wait_for_result ()
kono
parents:
diff changeset
71 {
kono
parents:
diff changeset
72 return do_wait (true);
kono
parents:
diff changeset
73 }
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 // Read and respond to query packets sent by the remote. This
kono
parents:
diff changeset
76 // function returns when the connection is closed.
kono
parents:
diff changeset
77 status wait_for_query ()
kono
parents:
diff changeset
78 {
kono
parents:
diff changeset
79 return do_wait (false);
kono
parents:
diff changeset
80 }
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 // Register a callback with this connection. NAME is the name of
kono
parents:
diff changeset
83 // the method being registered. FUNC is the function. It must
kono
parents:
diff changeset
84 // know how to decode its own arguments. When a query packet is
kono
parents:
diff changeset
85 // received by one of the wait_* methods, the corresponding
kono
parents:
diff changeset
86 // callback is invoked.
kono
parents:
diff changeset
87 void add_callback (const char *name, callback_ftype *func)
kono
parents:
diff changeset
88 {
kono
parents:
diff changeset
89 m_callbacks.add_callback (name, func);
kono
parents:
diff changeset
90 }
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 virtual void print (const char *);
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 private:
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 // Declared but not defined, to prevent use.
kono
parents:
diff changeset
97 connection (const connection &);
kono
parents:
diff changeset
98 connection &operator= (const connection &);
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 // Helper function for the wait_* methods.
kono
parents:
diff changeset
101 status do_wait (bool);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 // The file descriptor.
kono
parents:
diff changeset
104 int m_fd;
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 // An auxiliary file descriptor, or -1 if none.
kono
parents:
diff changeset
107 int m_aux_fd;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 // Callbacks associated with this connection.
kono
parents:
diff changeset
110 callbacks m_callbacks;
kono
parents:
diff changeset
111 };
kono
parents:
diff changeset
112 }
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 #endif // CC1_PLUGIN_CONNECTION_HH