connection.hh revision 1.1.1.3 1 1.1 mrg /* Plugin connection declarations
2 1.1.1.3 mrg Copyright (C) 2014-2018 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 mrg virtual ~connection ();
50 1.1 mrg
51 1.1 mrg // Send a single character. This is used to introduce various
52 1.1 mrg // higher-level protocol elements.
53 1.1 mrg status send (char c);
54 1.1 mrg
55 1.1 mrg // Send data in bulk.
56 1.1 mrg status send (const void *buf, int len);
57 1.1 mrg
58 1.1 mrg // Read a single byte from the connection and verify that it
59 1.1 mrg // matches the argument C.
60 1.1 mrg status require (char c);
61 1.1 mrg
62 1.1 mrg // Read data in bulk.
63 1.1 mrg status get (void *buf, int len);
64 1.1 mrg
65 1.1 mrg // This is called after a query (remote function call) has been
66 1.1 mrg // sent to the remote. It waits for a response packet. The
67 1.1 mrg // response character is read before returning. Any query packets
68 1.1 mrg // sent from the remote while waiting for a response are handled
69 1.1 mrg // by this function.
70 1.1 mrg status wait_for_result ()
71 1.1 mrg {
72 1.1 mrg return do_wait (true);
73 1.1 mrg }
74 1.1 mrg
75 1.1 mrg // Read and respond to query packets sent by the remote. This
76 1.1 mrg // function returns when the connection is closed.
77 1.1 mrg status wait_for_query ()
78 1.1 mrg {
79 1.1 mrg return do_wait (false);
80 1.1 mrg }
81 1.1 mrg
82 1.1 mrg // Register a callback with this connection. NAME is the name of
83 1.1 mrg // the method being registered. FUNC is the function. It must
84 1.1 mrg // know how to decode its own arguments. When a query packet is
85 1.1 mrg // received by one of the wait_* methods, the corresponding
86 1.1 mrg // callback is invoked.
87 1.1 mrg void add_callback (const char *name, callback_ftype *func)
88 1.1 mrg {
89 1.1 mrg m_callbacks.add_callback (name, func);
90 1.1 mrg }
91 1.1 mrg
92 1.1 mrg virtual void print (const char *);
93 1.1 mrg
94 1.1 mrg private:
95 1.1 mrg
96 1.1 mrg // Declared but not defined, to prevent use.
97 1.1 mrg connection (const connection &);
98 1.1 mrg connection &operator= (const connection &);
99 1.1 mrg
100 1.1 mrg // Helper function for the wait_* methods.
101 1.1 mrg status do_wait (bool);
102 1.1 mrg
103 1.1 mrg // The file descriptor.
104 1.1 mrg int m_fd;
105 1.1 mrg
106 1.1 mrg // An auxiliary file descriptor, or -1 if none.
107 1.1 mrg int m_aux_fd;
108 1.1 mrg
109 1.1 mrg // Callbacks associated with this connection.
110 1.1 mrg callbacks m_callbacks;
111 1.1 mrg };
112 1.1 mrg }
113 1.1 mrg
114 1.1 mrg #endif // CC1_PLUGIN_CONNECTION_HH
115