1 //===-- InputReader.h -------------------------------------------*- 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 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_InputReader_h_
11 #define liblldb_InputReader_h_
15 #include "lldb/lldb-public.h"
16 #include "lldb/lldb-enumerations.h"
17 #include "lldb/Core/Error.h"
18 #include "lldb/Core/StringList.h"
19 #include "lldb/Host/Predicate.h"
22 namespace lldb_private {
28 typedef size_t (*Callback) (void *baton,
30 lldb::InputReaderAction notification,
41 HandlerData(InputReader& r,
59 struct InitializationParameters
63 lldb::InputReaderGranularity m_token_size;
67 bool m_save_user_input;
69 InitializationParameters() :
71 m_token_size(lldb::eInputReaderGranularityLine),
73 m_save_user_input(false)
79 InitializationParameters&
86 InitializationParameters&
87 SetSaveUserInput(bool s)
89 m_save_user_input = s;
93 InitializationParameters&
100 InitializationParameters&
101 SetGranularity(lldb::InputReaderGranularity g)
107 InitializationParameters&
108 SetEndToken(const char* e)
110 m_end_token = new char[strlen(e)+1];
111 ::strcpy(m_end_token,e);
115 InitializationParameters&
116 SetPrompt(const char* p)
118 m_prompt = new char[strlen(p)+1];
119 ::strcpy(m_prompt,p);
123 friend class InputReaderEZ;
127 InputReader (Debugger &debugger);
133 Initialize (Callback callback,
135 lldb::InputReaderGranularity token_size,
136 const char *end_token,
140 virtual Error Initialize(void* baton,
141 lldb::InputReaderGranularity token_size = lldb::eInputReaderGranularityLine,
142 const char* end_token = "DONE",
143 const char *prompt = "> ",
146 return Error("unimplemented");
150 Initialize(InitializationParameters& params)
152 return Error("unimplemented");
155 // to use these handlers instead of the Callback function, you must subclass
156 // InputReaderEZ, and redefine the handlers for the events you care about
158 ActivateHandler(HandlerData&) {}
161 DeactivateHandler(HandlerData&) {}
164 ReactivateHandler(HandlerData&) {}
167 AsynchronousOutputWrittenHandler(HandlerData&) {}
170 GotTokenHandler(HandlerData&) {}
173 InterruptHandler(HandlerData&) {}
176 EOFHandler(HandlerData&) {}
179 DoneHandler(HandlerData&) {}
193 lldb::InputReaderGranularity
194 GetGranularity () const
196 return m_granularity;
217 // Subclasses _can_ override this function to get input as it comes in
218 // without any granularity
220 HandleRawBytes (const char *bytes, size_t bytes_len);
240 // If you want to read from an input reader synchronously, then just initialize the
241 // reader and then call WaitOnReaderIsDone, which will return when the reader is popped.
243 WaitOnReaderIsDone ();
246 GranularityAsCString (lldb::InputReaderGranularity granularity);
249 friend class Debugger;
252 Notify (lldb::InputReaderAction notification);
254 Debugger &m_debugger;
256 void *m_callback_baton;
257 std::string m_end_token;
258 std::string m_prompt;
259 lldb::InputReaderGranularity m_granularity;
263 Predicate<bool> m_reader_done;
264 StringList m_user_input;
265 bool m_save_user_input;
268 DISALLOW_COPY_AND_ASSIGN (InputReader);
272 } // namespace lldb_private
274 #endif // #ifndef liblldb_InputReader_h_