1 //===-- Connection.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Connection_h_
11 #define liblldb_Connection_h_
16 // Other libraries and framework includes
18 #include "lldb/lldb-private.h"
20 namespace lldb_private {
22 //----------------------------------------------------------------------
23 /// @class Connection Connection.h "lldb/Core/Connection.h"
24 /// @brief A communication connection class.
26 /// A class that implements that actual communication functions for
27 /// connecting/disconnecting, reading/writing, and waiting for bytes
28 /// to become available from a two way communication connection.
30 /// This class is designed to only do very simple communication
31 /// functions. Instances can be instantiated and given to a
32 /// Communication class to perform communications where clients can
33 /// listen for broadcasts, and perform other higher level communications.
34 //----------------------------------------------------------------------
38 //------------------------------------------------------------------
39 /// Default constructor
40 //------------------------------------------------------------------
43 //------------------------------------------------------------------
44 /// Virtual destructor since this class gets subclassed and handed
45 /// to a Communication object.
46 //------------------------------------------------------------------
50 static Connection *CreateDefaultConnection(const char *url);
52 //------------------------------------------------------------------
53 /// Connect using the connect string \a url.
56 /// A string that contains all information needed by the
57 /// subclass to connect to another client.
59 /// @param[out] error_ptr
60 /// A pointer to an error object that should be given an
61 /// approriate error value if this method returns false. This
62 /// value can be NULL if the error value should be ignored.
65 /// \b True if the connect succeeded, \b false otherwise. The
66 /// internal error object should be filled in with an
67 /// appropriate value based on the result of this function.
69 /// @see Error& Communication::GetError ();
70 //------------------------------------------------------------------
71 virtual lldb::ConnectionStatus
72 Connect (const char *url, Error *error_ptr) = 0;
74 //------------------------------------------------------------------
75 /// Disconnect the communications connection if one is currently
78 /// @param[out] error_ptr
79 /// A pointer to an error object that should be given an
80 /// approriate error value if this method returns false. This
81 /// value can be NULL if the error value should be ignored.
84 /// \b True if the disconnect succeeded, \b false otherwise. The
85 /// internal error object should be filled in with an
86 /// appropriate value based on the result of this function.
88 /// @see Error& Communication::GetError ();
89 //------------------------------------------------------------------
90 virtual lldb::ConnectionStatus
91 Disconnect (Error *error_ptr) = 0;
93 //------------------------------------------------------------------
94 /// Check if the connection is valid.
97 /// \b True if this object is currently connected, \b false
99 //------------------------------------------------------------------
101 IsConnected () const = 0;
103 //------------------------------------------------------------------
104 /// The read function that attempts to read from the connection.
107 /// A destination buffer that must be at least \a dst_len bytes
110 /// @param[in] dst_len
111 /// The number of bytes to attempt to read, and also the max
112 /// number of bytes that can be placed into \a dst.
114 /// @param[in] timeout_usec
115 /// The number of microseconds to wait for the data.
117 /// @param[out] status
118 /// On return, indicates whether the call was sucessful or terminated
119 /// due to some error condition.
121 /// @param[out] error_ptr
122 /// A pointer to an error object that should be given an
123 /// approriate error value if this method returns zero. This
124 /// value can be NULL if the error value should be ignored.
127 /// The number of bytes actually read.
129 /// @see size_t Communication::Read (void *, size_t, uint32_t);
130 //------------------------------------------------------------------
134 uint32_t timeout_usec,
135 lldb::ConnectionStatus &status,
136 Error *error_ptr) = 0;
138 //------------------------------------------------------------------
139 /// The actual write function that attempts to write to the
140 /// communications protocol.
142 /// Subclasses must override this function.
145 /// A desination buffer that must be at least \a dst_len bytes
148 /// @param[in] dst_len
149 /// The number of bytes to attempt to write, and also the
150 /// number of bytes are currently available in \a dst.
152 /// @param[out] error_ptr
153 /// A pointer to an error object that should be given an
154 /// approriate error value if this method returns zero. This
155 /// value can be NULL if the error value should be ignored.
158 /// The number of bytes actually Written.
159 //------------------------------------------------------------------
161 Write (const void *dst, size_t dst_len, lldb::ConnectionStatus &status, Error *error_ptr) = 0;
163 //------------------------------------------------------------------
164 /// Returns a URI that describes this connection object
166 /// Subclasses may override this function.
169 /// Returns URI or an empty string if disconnecteds
170 //------------------------------------------------------------------
174 //------------------------------------------------------------------
175 /// Interrupts an ongoing Read() operation.
177 /// If there is an ongoing read operation in another thread, this operation
178 /// return with status == eConnectionStatusInterrupted. Note that if there
179 /// data waiting to be read and an interrupt request is issued, the Read()
180 /// function will return the data immediately without processing the
181 /// interrupt request (which will remain queued for the next Read()
185 /// Returns true is the interrupt request was sucessful.
186 //------------------------------------------------------------------
190 //------------------------------------------------------------------
191 /// Returns the underlying IOObject used by the Connection.
193 /// The IOObject can be used to wait for data to become available
194 /// on the connection. If the Connection does not use IOObjects (and
195 /// hence does not support waiting) this function should return a
199 /// The underlying IOObject used for reading.
200 //------------------------------------------------------------------
201 virtual lldb::IOObjectSP
202 GetReadObject() { return lldb::IOObjectSP(); }
205 //------------------------------------------------------------------
206 // For Connection only
207 //------------------------------------------------------------------
208 DISALLOW_COPY_AND_ASSIGN (Connection);
211 } // namespace lldb_private
213 #endif // liblldb_Connection_h_