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