SBCommunication.h revision 63094e0bb161580564954dee512955c1c79d3476
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    size_t
62    Read (void *dst,
63          size_t dst_len,
64          uint32_t timeout_usec,
65          lldb::ConnectionStatus &status);
66
67    size_t
68    Write (const void *src,
69           size_t src_len,
70           lldb::ConnectionStatus &status);
71
72    bool
73    ReadThreadStart ();
74
75    bool
76    ReadThreadStop ();
77
78    bool
79    ReadThreadIsRunning ();
80
81    bool
82    SetReadThreadBytesReceivedCallback (ReadThreadBytesReceived callback,
83                                        void *callback_baton);
84
85
86private:
87//    void
88//    CreateIfNeeded ();
89
90    lldb_private::Communication *m_opaque;
91    bool m_opaque_owned;
92};
93
94
95} // namespace lldb
96
97#endif // LLDB_SBCommunication_h_
98