blob: ee626a698242e461b340e4ba5bbedcc45115fda9 [file] [log] [blame]
Greg Claytonf9765ac2011-07-15 03:27:12 +00001//===-- CommunicationKDP.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 liblldb_CommunicationKDP_h_
11#define liblldb_CommunicationKDP_h_
12
13// C Includes
14// C++ Includes
15#include <list>
16#include <string>
17
18// Other libraries and framework includes
19// Project includes
20#include "lldb/lldb-private.h"
21#include "lldb/Core/Communication.h"
22#include "lldb/Core/Listener.h"
23#include "lldb/Host/Mutex.h"
24#include "lldb/Host/Predicate.h"
25#include "lldb/Host/TimeValue.h"
26
27class StringExtractor;
28
29class CommunicationKDP : public lldb_private::Communication
30{
31public:
32 enum
33 {
34 eBroadcastBitRunPacketSent = kLoUserBroadcastBit
35 };
36 //------------------------------------------------------------------
37 // Constructors and Destructors
38 //------------------------------------------------------------------
39 CommunicationKDP (const char *comm_name);
40
41 virtual
42 ~CommunicationKDP();
43
44 size_t
45 SendPacket (const char *payload);
46
47 size_t
48 SendPacket (const char *payload,
49 size_t payload_length);
50
51 size_t
52 SendPacket (lldb_private::StreamString &response);
53
54 // Wait for a packet within 'nsec' seconds
55 size_t
56 WaitForPacketWithTimeoutMicroSeconds (StringExtractor &response,
57 uint32_t usec);
58
59 char
60 GetAck ();
61
62 size_t
63 SendAck ();
64
65 size_t
66 SendNack ();
67
68 char
69 CalculcateChecksum (const char *payload,
70 size_t payload_length);
71
72 bool
73 GetSequenceMutex(lldb_private::Mutex::Locker& locker);
74
75 bool
76 CheckForPacket (const uint8_t *src,
77 size_t src_len,
78 StringExtractor &packet);
79 bool
80 IsRunning() const
81 {
82 return m_public_is_running.GetValue();
83 }
84
85 bool
86 GetSendAcks ()
87 {
88 return m_send_acks;
89 }
90
91 //------------------------------------------------------------------
92 // Set the global packet timeout.
93 //
94 // For clients, this is the timeout that gets used when sending
95 // packets and waiting for responses. For servers, this might not
96 // get used, and if it doesn't this should be moved to the
97 // CommunicationKDPClient.
98 //------------------------------------------------------------------
99 uint32_t
100 SetPacketTimeout (uint32_t packet_timeout)
101 {
102 const uint32_t old_packet_timeout = m_packet_timeout;
103 m_packet_timeout = packet_timeout;
104 return old_packet_timeout;
105 }
106
107 uint32_t
108 GetPacketTimeoutInMicroSeconds () const
109 {
110 return m_packet_timeout * lldb_private::TimeValue::MicroSecPerSec;
111 }
112 //------------------------------------------------------------------
113 // Start a debugserver instance on the current host using the
114 // supplied connection URL.
115 //------------------------------------------------------------------
116 lldb_private::Error
117 StartDebugserverProcess (const char *connect_url,
118 const char *unix_socket_name,
119 lldb_private::ProcessLaunchInfo &launch_info);
120
121
122protected:
123 typedef std::list<std::string> packet_collection;
124
125 size_t
126 SendPacketNoLock (const char *payload,
127 size_t payload_length);
128
129 size_t
130 WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractor &response,
131 uint32_t timeout_usec);
132
133 bool
134 WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr);
135
136 //------------------------------------------------------------------
137 // Classes that inherit from CommunicationKDP can see and modify these
138 //------------------------------------------------------------------
139 uint32_t m_packet_timeout;
140 lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
141 lldb_private::Predicate<bool> m_public_is_running;
142 lldb_private::Predicate<bool> m_private_is_running;
143 bool m_send_acks;
144
145private:
146 //------------------------------------------------------------------
147 // For CommunicationKDP only
148 //------------------------------------------------------------------
149 DISALLOW_COPY_AND_ASSIGN (CommunicationKDP);
150};
151
152#endif // liblldb_CommunicationKDP_h_