InputReader.h revision 63094e0bb161580564954dee512955c1c79d3476
1//===-- InputReader.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_InputReader_h_ 11#define liblldb_InputReader_h_ 12 13#include <termios.h> 14 15#include "lldb/lldb-include.h" 16#include "lldb/lldb-enumerations.h" 17#include "lldb/Core/Debugger.h" 18 19 20namespace lldb_private { 21 22class InputReader 23{ 24public: 25 26 typedef size_t (*Callback) (void *baton, 27 InputReader &reader, 28 lldb::InputReaderAction notification, 29 const char *bytes, 30 size_t bytes_len); 31 32 InputReader (Debugger &debugger); 33 34 virtual 35 ~InputReader (); 36 37 virtual Error 38 Initialize (Callback callback, 39 void *baton, 40 lldb::InputReaderGranularity token_size, 41 const char *end_token, 42 const char *prompt, 43 bool echo); 44 45 bool 46 IsDone () const 47 { 48 return m_done; 49 } 50 51 void 52 SetIsDone (bool b) 53 { 54 m_done = b; 55 } 56 57 lldb::InputReaderGranularity 58 GetGranularity () const 59 { 60 return m_granularity; 61 } 62 63 bool 64 GetEcho () const 65 { 66 return m_echo; 67 } 68 69 // Subclasses _can_ override this function to get input as it comes in 70 // without any granularity 71 virtual size_t 72 HandleRawBytes (const char *bytes, size_t bytes_len); 73 74 Debugger & 75 GetDebugger() 76 { 77 return m_debugger; 78 } 79 80 bool 81 IsActive () const 82 { 83 return m_active; 84 } 85 86 const char * 87 GetPrompt () const; 88 89 void 90 RefreshPrompt(); 91 92protected: 93 friend class Debugger; 94 95 void 96 Notify (lldb::InputReaderAction notification); 97 98 Debugger &m_debugger; 99 Callback m_callback; 100 void *m_callback_baton; 101 std::string m_end_token; 102 std::string m_prompt; 103 lldb::InputReaderGranularity m_granularity; 104 bool m_done; 105 bool m_echo; 106 bool m_active; 107 108private: 109 DISALLOW_COPY_AND_ASSIGN (InputReader); 110 111}; 112 113} // namespace lldb_private 114 115#endif // #ifndef liblldb_InputReader_h_ 116