1 //===-- SBInputReader.cpp ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "lldb/lldb-enumerations.h"
13 #include "lldb/API/SBDebugger.h"
14 #include "lldb/API/SBError.h"
15 #include "lldb/API/SBInputReader.h"
16 #include "lldb/API/SBStream.h"
17 #include "lldb/API/SBStringList.h"
18 #include "lldb/Core/InputReader.h"
19 #include "lldb/Core/Log.h"
23 using namespace lldb_private;
25 SBInputReader::SBInputReader () :
27 m_callback_function (NULL),
28 m_callback_baton (NULL)
33 SBInputReader::SBInputReader (const lldb::InputReaderSP &reader_sp) :
34 m_opaque_sp (reader_sp)
36 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
39 log->Printf ("SBInputReader::SBInputReader (reader_sp=%p) => SBInputReader(%p)", reader_sp.get(),
43 SBInputReader::SBInputReader (const SBInputReader &rhs) :
44 m_opaque_sp (rhs.m_opaque_sp)
46 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
49 log->Printf("SBInputReader::SBInputReader (rhs.sp=%p) => SBInputReader(%p)",
50 rhs.m_opaque_sp.get(), m_opaque_sp.get());
53 SBInputReader::~SBInputReader ()
58 SBInputReader::PrivateCallback
62 lldb::InputReaderAction notification,
67 SBInputReader *sb_reader = (SBInputReader *)baton;
68 return sb_reader->m_callback_function (sb_reader->m_callback_baton,
76 SBInputReader::Initialize
79 Callback callback_function,
81 lldb::InputReaderGranularity granularity,
82 const char *end_token,
87 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
90 log->Printf("SBInputReader(%p)::Initialize (SBDebugger(%p), callback_function=%p, callback_baton=%p, "
91 "granularity=%s, end_token=\"%s\", prompt=\"%s\", echo=%i)",
96 InputReader::GranularityAsCString (granularity), end_token, prompt,
100 m_opaque_sp.reset (new InputReader (debugger.ref()));
102 m_callback_function = callback_function;
103 m_callback_baton = callback_baton;
107 sb_error.SetError (m_opaque_sp->Initialize (SBInputReader::PrivateCallback,
117 m_opaque_sp.reset ();
118 m_callback_function = NULL;
119 m_callback_baton = NULL;
125 sb_error.GetDescription (sstr);
126 log->Printf ("SBInputReader(%p)::Initialize (...) => SBError(%p): %s", m_opaque_sp.get(),
127 sb_error.get(), sstr.GetData());
134 SBInputReader::IsValid () const
136 return (m_opaque_sp.get() != NULL);
139 const SBInputReader &
140 SBInputReader::operator = (const SBInputReader &rhs)
143 m_opaque_sp = rhs.m_opaque_sp;
148 SBInputReader::operator->() const
150 return m_opaque_sp.get();
153 lldb::InputReaderSP &
154 SBInputReader::operator *()
159 const lldb::InputReaderSP &
160 SBInputReader::operator *() const
166 SBInputReader::get() const
168 return m_opaque_sp.get();
172 SBInputReader::ref() const
174 assert (m_opaque_sp.get());
179 SBInputReader::IsDone () const
182 return m_opaque_sp->IsDone();
188 SBInputReader::SetIsDone (bool value)
191 m_opaque_sp->SetIsDone (value);
195 SBInputReader::IsActive () const
197 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
199 bool ret_value = false;
201 ret_value = m_opaque_sp->IsActive();
204 log->Printf ("SBInputReader(%p)::IsActive () => %i", m_opaque_sp.get(), ret_value);
209 InputReaderGranularity
210 SBInputReader::GetGranularity ()
213 return m_opaque_sp->GetGranularity();
215 return eInputReaderGranularityInvalid;