1 //===-- IOChannel.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 lldb_IOChannel_h_
11 #define lldb_IOChannel_h_
16 #if defined(__FreeBSD__)
17 #include <readline/readline.h>
19 #include <editline/readline.h>
27 class IOChannel : public lldb::SBBroadcaster
31 eBroadcastBitHasUserInput = (1 << 0),
32 eBroadcastBitUserInterrupt = (1 << 1),
33 eBroadcastBitThreadShouldExit = (1 << 2),
34 eBroadcastBitThreadDidExit = (1 << 3),
35 eBroadcastBitThreadDidStart = (1 << 4),
36 eBroadcastBitsSTDOUT = (1 << 5),
37 eBroadcastBitsSTDERR = (1 << 6),
38 eBroadcastBitsSTDIN = (1 << 7),
39 eAllEventBits = 0xffffffff
42 enum LibeditGetInputResult
44 eLibeditGetInputEOF = 0,
45 eLibeditGetInputValid = 1,
46 eLibeditGetInputEmpty = 2,
47 eLibeditGetInputResultError = 4,
48 eLibeditGetInputResultUnknown = 0xffffffff
51 IOChannel (FILE *editline_in,
55 Driver *driver = NULL);
67 IOReadThread (void *);
73 OutWrite (const char *buffer, size_t len, bool asynchronous);
76 ErrWrite (const char *buffer, size_t len, bool asynchronous);
79 LibeditGetInput (std::string &);
82 LibeditOutputBytesReceived (void *baton, const void *src,size_t src_len);
91 AddCommandToQueue (const char *command);
94 GetCommandFromQueue (std::string &cmd);
97 CommandQueueSize () const;
100 ClearCommandQueue ();
103 CommandQueueIsEmpty () const;
109 EditLineHasCharacters ();
112 EraseCharsBeforeCursor ();
115 ElCompletionFn (EditLine *e, int ch);
123 IsGettingCommand () const;
126 SetGettingCommand (bool new_value);
130 pthread_mutex_t m_output_mutex;
131 struct timeval m_enter_elgets_time;
134 lldb::thread_t m_read_thread;
135 bool m_read_thread_should_exit;
138 std::queue<std::string> m_command_queue;
139 const char *m_completion_key;
141 EditLine *m_edit_line;
143 HistEvent m_history_event;
144 bool m_getting_command;
145 bool m_expecting_prompt;
146 std::string m_prompt_str; // for accumlating the prompt as it gets written out by editline
147 bool m_refresh_request_pending;
150 HistorySaveLoad (bool save);
153 HandleCompletion (EditLine *e, int ch);
160 IOLocker (pthread_mutex_t &mutex);
166 pthread_mutex_t *m_mutex_ptr;
170 IOLocker (const IOLocker&);
171 const IOLocker& operator= (const IOLocker&);
174 #endif // lldb_IOChannel_h_