summaryrefslogtreecommitdiffstats
path: root/lldb/source/API/SBCommunication.cpp
blob: e2a791750a8d9ad63b85199335e8880f0450ab13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//===-- SBCommunication.cpp -------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/API/SBCommunication.h"
#include "lldb/API/SBBroadcaster.h"
#include "lldb/Core/Communication.h"
#include "lldb/Core/ConnectionFileDescriptor.h"

using namespace lldb;
using namespace lldb_private;



SBCommunication::SBCommunication() :
    m_lldb_object (NULL),
    m_lldb_object_owned (false)
{
}

SBCommunication::SBCommunication(const char * broadcaster_name) :
    m_lldb_object (new Communication (broadcaster_name)),
    m_lldb_object_owned (true)
{
}

SBCommunication::~SBCommunication()
{
    if (m_lldb_object && m_lldb_object_owned)
        delete m_lldb_object;
    m_lldb_object = NULL;
    m_lldb_object_owned = false;
}

ConnectionStatus
SBCommunication::CheckIfBytesAvailable ()
{
    if (m_lldb_object)
        return m_lldb_object->BytesAvailable (0, NULL);
    return eConnectionStatusNoConnection;
}

ConnectionStatus
SBCommunication::WaitForBytesAvailableInfinite ()
{
    if (m_lldb_object)
        return m_lldb_object->BytesAvailable (UINT32_MAX, NULL);
    return eConnectionStatusNoConnection;
}

ConnectionStatus
SBCommunication::WaitForBytesAvailableWithTimeout (uint32_t timeout_usec)
{
    if (m_lldb_object)
        return m_lldb_object->BytesAvailable (timeout_usec, NULL);
    return eConnectionStatusNoConnection;
}

ConnectionStatus
SBCommunication::Connect (const char *url)
{
    if (m_lldb_object)
    {
        if (!m_lldb_object->HasConnection ())
            m_lldb_object->SetConnection (new ConnectionFileDescriptor());
        return m_lldb_object->Connect (url, NULL);
    }
    return eConnectionStatusNoConnection;
}

ConnectionStatus
SBCommunication::AdoptFileDesriptor (int fd, bool owns_fd)
{
    if (m_lldb_object)
    {
        if (m_lldb_object->HasConnection ())
        {
            if (m_lldb_object->IsConnected())
                m_lldb_object->Disconnect ();
        }
        m_lldb_object->SetConnection (new ConnectionFileDescriptor (fd, owns_fd));
        if (m_lldb_object->IsConnected())
            return eConnectionStatusSuccess;
        else
            return eConnectionStatusLostConnection;
    }
    return eConnectionStatusNoConnection;
}


ConnectionStatus
SBCommunication::Disconnect ()
{
    if (m_lldb_object)
        return m_lldb_object->Disconnect ();
    return eConnectionStatusNoConnection;
}

bool
SBCommunication::IsConnected () const
{
    if (m_lldb_object)
        return m_lldb_object->IsConnected ();
    return false;
}

size_t
SBCommunication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, ConnectionStatus &status)
{
    if (m_lldb_object)
        return m_lldb_object->Read (dst, dst_len, timeout_usec, status, NULL);
    status = eConnectionStatusNoConnection;
    return 0;
}


size_t
SBCommunication::Write (const void *src, size_t src_len, ConnectionStatus &status)
{
    if (m_lldb_object)
        return m_lldb_object->Write (src, src_len, status, NULL);
    status = eConnectionStatusNoConnection;
    return 0;
}

bool
SBCommunication::ReadThreadStart ()
{
    if (m_lldb_object)
        return m_lldb_object->StartReadThread ();
    return false;
}


bool
SBCommunication::ReadThreadStop ()
{
    if (m_lldb_object)
        return m_lldb_object->StopReadThread ();
    return false;
}

bool
SBCommunication::ReadThreadIsRunning ()
{
    if (m_lldb_object)
        return m_lldb_object->ReadThreadIsRunning ();
    return false;
}

bool
SBCommunication::SetReadThreadBytesReceivedCallback
(
    ReadThreadBytesReceived callback,
    void *callback_baton
)
{
    if (m_lldb_object)
    {
        m_lldb_object->SetReadThreadBytesReceivedCallback (callback, callback_baton);
        return true;
    }
    return false;
}

SBBroadcaster
SBCommunication::GetBroadcaster ()
{
    SBBroadcaster broadcaster (m_lldb_object, false);
    return broadcaster;
}


//
//void
//SBCommunication::CreateIfNeeded ()
//{
//    if (m_lldb_object == NULL)
//    {
//        static uint32_t g_broadcaster_num;
//        char broadcaster_name[256];
//        ::snprintf (name, broadcaster_name, "%p SBCommunication", this);
//        m_lldb_object = new Communication (broadcaster_name);
//        m_lldb_object_owned = true;
//    }
//    assert (m_lldb_object);
//}
//
//
OpenPOWER on IntegriCloud