1254721Semaste//===-- Connection.h --------------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#ifndef liblldb_Connection_h_
11254721Semaste#define liblldb_Connection_h_
12254721Semaste
13254721Semaste// C Includes
14254721Semaste// C++ Includes
15254721Semaste// Other libraries and framework includes
16254721Semaste// Project includes
17254721Semaste#include "lldb/lldb-private.h"
18254721Semaste
19254721Semastenamespace lldb_private {
20254721Semaste
21254721Semaste//----------------------------------------------------------------------
22254721Semaste/// @class Connection Connection.h "lldb/Core/Connection.h"
23254721Semaste/// @brief A communication connection class.
24254721Semaste///
25254721Semaste/// A class that implements that actual communication functions for
26254721Semaste/// connecting/disconnecting, reading/writing, and waiting for bytes
27254721Semaste/// to become available from a two way communication connection.
28254721Semaste///
29254721Semaste/// This class is designed to only do very simple communication
30254721Semaste/// functions. Instances can be instantiated and given to a
31254721Semaste/// Communication class to perform communications where clients can
32254721Semaste/// listen for broadcasts, and perform other higher level communications.
33254721Semaste//----------------------------------------------------------------------
34254721Semasteclass Connection
35254721Semaste{
36254721Semastepublic:
37254721Semaste    //------------------------------------------------------------------
38254721Semaste    /// Default constructor
39254721Semaste    //------------------------------------------------------------------
40254721Semaste    Connection ();
41254721Semaste
42254721Semaste    //------------------------------------------------------------------
43254721Semaste    /// Virtual destructor since this class gets subclassed and handed
44254721Semaste    /// to a Communication object.
45254721Semaste    //------------------------------------------------------------------
46254721Semaste    virtual
47254721Semaste    ~Connection ();
48254721Semaste
49254721Semaste    //------------------------------------------------------------------
50254721Semaste    /// Connect using the connect string \a url.
51254721Semaste    ///
52254721Semaste    /// @param[in] url
53254721Semaste    ///     A string that contains all information needed by the
54254721Semaste    ///     subclass to connect to another client.
55254721Semaste    ///
56254721Semaste    /// @param[out] error_ptr
57254721Semaste    ///     A pointer to an error object that should be given an
58254721Semaste    ///     approriate error value if this method returns false. This
59254721Semaste    ///     value can be NULL if the error value should be ignored.
60254721Semaste    ///
61254721Semaste    /// @return
62254721Semaste    ///     \b True if the connect succeeded, \b false otherwise. The
63254721Semaste    ///     internal error object should be filled in with an
64254721Semaste    ///     appropriate value based on the result of this function.
65254721Semaste    ///
66254721Semaste    /// @see Error& Communication::GetError ();
67254721Semaste    //------------------------------------------------------------------
68254721Semaste    virtual lldb::ConnectionStatus
69254721Semaste    Connect (const char *url, Error *error_ptr) = 0;
70254721Semaste
71254721Semaste    //------------------------------------------------------------------
72254721Semaste    /// Disconnect the communications connection if one is currently
73254721Semaste    /// connected.
74254721Semaste    ///
75254721Semaste    /// @param[out] error_ptr
76254721Semaste    ///     A pointer to an error object that should be given an
77254721Semaste    ///     approriate error value if this method returns false. This
78254721Semaste    ///     value can be NULL if the error value should be ignored.
79254721Semaste    ///
80254721Semaste    /// @return
81254721Semaste    ///     \b True if the disconnect succeeded, \b false otherwise. The
82254721Semaste    ///     internal error object should be filled in with an
83254721Semaste    ///     appropriate value based on the result of this function.
84254721Semaste    ///
85254721Semaste    /// @see Error& Communication::GetError ();
86254721Semaste    //------------------------------------------------------------------
87254721Semaste    virtual lldb::ConnectionStatus
88254721Semaste    Disconnect (Error *error_ptr) = 0;
89254721Semaste
90254721Semaste    //------------------------------------------------------------------
91254721Semaste    /// Check if the connection is valid.
92254721Semaste    ///
93254721Semaste    /// @return
94254721Semaste    ///     \b True if this object is currently connected, \b false
95254721Semaste    ///     otherwise.
96254721Semaste    //------------------------------------------------------------------
97254721Semaste    virtual bool
98254721Semaste    IsConnected () const = 0;
99254721Semaste
100254721Semaste    //------------------------------------------------------------------
101254721Semaste    /// The read function that attempts to read from the connection.
102254721Semaste    ///
103254721Semaste    /// @param[in] dst
104254721Semaste    ///     A destination buffer that must be at least \a dst_len bytes
105254721Semaste    ///     long.
106254721Semaste    ///
107254721Semaste    /// @param[in] dst_len
108254721Semaste    ///     The number of bytes to attempt to read, and also the max
109254721Semaste    ///     number of bytes that can be placed into \a dst.
110254721Semaste    ///
111254721Semaste    /// @param[out] error_ptr
112254721Semaste    ///     A pointer to an error object that should be given an
113254721Semaste    ///     approriate error value if this method returns zero. This
114254721Semaste    ///     value can be NULL if the error value should be ignored.
115254721Semaste    ///
116254721Semaste    /// @return
117254721Semaste    ///     The number of bytes actually read.
118254721Semaste    ///
119254721Semaste    /// @see size_t Communication::Read (void *, size_t, uint32_t);
120254721Semaste    //------------------------------------------------------------------
121254721Semaste    virtual size_t
122254721Semaste    Read (void *dst,
123254721Semaste          size_t dst_len,
124254721Semaste          uint32_t timeout_usec,
125254721Semaste          lldb::ConnectionStatus &status,
126254721Semaste          Error *error_ptr) = 0;
127254721Semaste
128254721Semaste    //------------------------------------------------------------------
129254721Semaste    /// The actual write function that attempts to write to the
130254721Semaste    /// communications protocol.
131254721Semaste    ///
132254721Semaste    /// Subclasses must override this function.
133254721Semaste    ///
134254721Semaste    /// @param[in] src
135254721Semaste    ///     A source buffer that must be at least \a src_len bytes
136254721Semaste    ///     long.
137254721Semaste    ///
138254721Semaste    /// @param[in] src_len
139254721Semaste    ///     The number of bytes to attempt to write, and also the
140254721Semaste    ///     number of bytes are currently available in \a src.
141254721Semaste    ///
142254721Semaste    /// @param[out] error_ptr
143254721Semaste    ///     A pointer to an error object that should be given an
144254721Semaste    ///     approriate error value if this method returns zero. This
145254721Semaste    ///     value can be NULL if the error value should be ignored.
146254721Semaste    ///
147254721Semaste    /// @return
148254721Semaste    ///     The number of bytes actually Written.
149254721Semaste    //------------------------------------------------------------------
150254721Semaste    virtual size_t
151254721Semaste    Write (const void *buffer, size_t length, lldb::ConnectionStatus &status, Error *error_ptr) = 0;
152254721Semaste
153254721Semasteprivate:
154254721Semaste    //------------------------------------------------------------------
155254721Semaste    // For Connection only
156254721Semaste    //------------------------------------------------------------------
157254721Semaste    DISALLOW_COPY_AND_ASSIGN (Connection);
158254721Semaste};
159254721Semaste
160254721Semaste} // namespace lldb_private
161254721Semaste
162254721Semaste#endif  // liblldb_Connection_h_
163