summaryrefslogtreecommitdiffstats
path: root/lldb/source/API/SBInputReader.cpp
blob: 022d73207ad24627ca19ed8b1904dad9d6b0614c (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
//===-- SBInputReader.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/lldb-enumerations.h"

#include "lldb/API/SBInputReader.h"
#include "lldb/API/SBError.h"
#include "lldb/API/SBStringList.h"
#include "lldb/Core/InputReader.h"


using namespace lldb;
using namespace lldb_private;

SBInputReader::SBInputReader ()  :
    m_reader_sp (),
    m_callback_function (NULL),
    m_callback_baton (NULL)

{
}

SBInputReader::SBInputReader (const lldb::InputReaderSP &reader_sp) :
    m_reader_sp (reader_sp)
{
}

SBInputReader::SBInputReader (const SBInputReader &rhs) :
    m_reader_sp (rhs.m_reader_sp)
{
}

SBInputReader::~SBInputReader ()
{
}

size_t
SBInputReader::PrivateCallback 
(
    void *baton, 
    InputReader *reader, 
    lldb::InputReaderAction notification,
    const char *bytes, 
    size_t bytes_len
)
{
    SBInputReader *sb_reader = (SBInputReader *)baton;
    return sb_reader->m_callback_function (sb_reader->m_callback_baton, 
                                           sb_reader, 
                                           notification,
                                           bytes,
                                           bytes_len);
}

SBError
SBInputReader::Initialize 
(
    Callback callback_function,
    void *callback_baton,
    lldb::InputReaderGranularity granularity,
    const char *end_token,
    const char *prompt,
    bool echo
)
{
    SBError sb_error;
    m_reader_sp.reset (new InputReader ());
    
    m_callback_function = callback_function;
    m_callback_baton = callback_baton;

    if (m_reader_sp)
    {
        sb_error.SetError (m_reader_sp->Initialize (SBInputReader::PrivateCallback,
                                                    this,
                                                    granularity,
                                                    end_token,
                                                    prompt,
                                                    echo));
    }

    if (sb_error.Fail())
    {
        m_reader_sp.reset ();
        m_callback_function = NULL;
        m_callback_baton = NULL;
    }

    return sb_error;
}

bool
SBInputReader::IsValid () const
{
    return (m_reader_sp.get() != NULL);
}

const SBInputReader &
SBInputReader::operator = (const SBInputReader &rhs)
{
    if (this != &rhs)
        m_reader_sp = rhs.m_reader_sp;
    return *this;
}

lldb_private::InputReader *
SBInputReader::operator->() const
{
    return m_reader_sp.get();
}

lldb::InputReaderSP &
SBInputReader::operator *()
{
    return m_reader_sp;
}

const lldb::InputReaderSP &
SBInputReader::operator *() const
{
    return m_reader_sp;
}

lldb_private::InputReader *
SBInputReader::get() const
{
    return m_reader_sp.get();
}

bool
SBInputReader::IsDone () const
{
    if (m_reader_sp)
        return m_reader_sp->IsDone();
    else
        return true;
}

void
SBInputReader::SetIsDone (bool value)
{
    if (m_reader_sp)
        m_reader_sp->SetIsDone (value);
}

bool
SBInputReader::IsActive () const
{
    if (m_reader_sp)
        return m_reader_sp->IsActive();
    else
        return false;
}

InputReaderGranularity
SBInputReader::GetGranularity ()
{
    if (m_reader_sp)
        return m_reader_sp->GetGranularity();
    else
        return eInputReaderGranularityInvalid;
}
OpenPOWER on IntegriCloud