1 //===-- SBCommunication.h ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_API_SBCOMMUNICATION_H
10 #define LLDB_API_SBCOMMUNICATION_H
11 
12 #include "lldb/API/SBDefines.h"
13 #include "lldb/API/SBError.h"
14 
15 namespace lldb {
16 
17 class LLDB_API SBCommunication {
18 public:
19   FLAGS_ANONYMOUS_ENUM(){
20       eBroadcastBitDisconnected =
21           (1 << 0), ///< Sent when the communications connection is lost.
22       eBroadcastBitReadThreadGotBytes =
23           (1 << 1), ///< Sent by the read thread when bytes become available.
24       eBroadcastBitReadThreadDidExit =
25           (1
26            << 2), ///< Sent by the read thread when it exits to inform clients.
27       eBroadcastBitReadThreadShouldExit =
28           (1 << 3), ///< Sent by clients that need to cancel the read thread.
29       eBroadcastBitPacketAvailable =
30           (1 << 4), ///< Sent when data received makes a complete packet.
31       eAllEventBits = 0xffffffff};
32 
33   typedef void (*ReadThreadBytesReceived)(void *baton, const void *src,
34                                           size_t src_len);
35 
36   SBCommunication();
37   SBCommunication(const char *broadcaster_name);
38   ~SBCommunication();
39 
40   explicit operator bool() const;
41 
42   bool IsValid() const;
43 
44   lldb::SBBroadcaster GetBroadcaster();
45 
46   static const char *GetBroadcasterClass();
47 
48   lldb::ConnectionStatus AdoptFileDesriptor(int fd, bool owns_fd);
49 
50   lldb::ConnectionStatus Connect(const char *url);
51 
52   lldb::ConnectionStatus Disconnect();
53 
54   bool IsConnected() const;
55 
56   bool GetCloseOnEOF();
57 
58   void SetCloseOnEOF(bool b);
59 
60   size_t Read(void *dst, size_t dst_len, uint32_t timeout_usec,
61               lldb::ConnectionStatus &status);
62 
63   size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status);
64 
65   bool ReadThreadStart();
66 
67   bool ReadThreadStop();
68 
69   bool ReadThreadIsRunning();
70 
71   bool SetReadThreadBytesReceivedCallback(ReadThreadBytesReceived callback,
72                                           void *callback_baton);
73 
74 private:
75   SBCommunication(const SBCommunication &) = delete;
76   const SBCommunication &operator=(const SBCommunication &) = delete;
77 
78   lldb_private::ThreadedCommunication *m_opaque = nullptr;
79   bool m_opaque_owned = false;
80 };
81 
82 } // namespace lldb
83 
84 #endif // LLDB_API_SBCOMMUNICATION_H
85