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