SBCommunication.h revision eecb0f3b5021e37311f9588f14bcab38a35b8e9a
1//===-- SBCommunication.h ---------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLDB_SBCommunication_h_
11#define LLDB_SBCommunication_h_
12
13#include "lldb/API/SBDefines.h"
14#include "lldb/API/SBError.h"
15
16namespace lldb {
17
18class SBCommunication
19{
20public:
21    enum {
22        eBroadcastBitDisconnected           = (1 << 0), ///< Sent when the communications connection is lost.
23        eBroadcastBitReadThreadGotBytes     = (1 << 1), ///< Sent by the read thread when bytes become available.
24        eBroadcastBitReadThreadDidExit      = (1 << 2), ///< Sent by the read thread when it exits to inform clients.
25        eBroadcastBitReadThreadShouldExit   = (1 << 3), ///< Sent by clients that need to cancel the read thread.
26        eBroadcastBitPacketAvailable        = (1 << 4), ///< Sent when data received makes a complete packet.
27        eAllEventBits                       = 0xffffffff
28    };
29
30    typedef void (*ReadThreadBytesReceived) (void *baton, const void *src, size_t src_len);
31
32    SBCommunication ();
33    SBCommunication (const char * broadcaster_name);
34   ~SBCommunication ();
35
36
37    lldb::SBBroadcaster
38    GetBroadcaster ();
39
40    lldb::ConnectionStatus
41    AdoptFileDesriptor (int fd, bool owns_fd);
42
43    lldb::ConnectionStatus
44    CheckIfBytesAvailable ();
45
46    lldb::ConnectionStatus
47    WaitForBytesAvailableInfinite ();
48
49    lldb::ConnectionStatus
50    WaitForBytesAvailableWithTimeout (uint32_t timeout_usec);
51
52    lldb::ConnectionStatus
53    Connect (const char *url);
54
55    lldb::ConnectionStatus
56    Disconnect ();
57
58    bool
59    IsConnected () const;
60
61    bool
62    GetCloseOnEOF ();
63
64    void
65    SetCloseOnEOF (bool b);
66
67    size_t
68    Read (void *dst,
69          size_t dst_len,
70          uint32_t timeout_usec,
71          lldb::ConnectionStatus &status);
72
73    size_t
74    Write (const void *src,
75           size_t src_len,
76           lldb::ConnectionStatus &status);
77
78    bool
79    ReadThreadStart ();
80
81    bool
82    ReadThreadStop ();
83
84    bool
85    ReadThreadIsRunning ();
86
87    bool
88    SetReadThreadBytesReceivedCallback (ReadThreadBytesReceived callback,
89                                        void *callback_baton);
90
91
92private:
93
94    DISALLOW_COPY_AND_ASSIGN (SBCommunication);
95
96    lldb_private::Communication *m_opaque;
97    bool m_opaque_owned;
98};
99
100
101} // namespace lldb
102
103#endif // LLDB_SBCommunication_h_
104