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