blob: 90e76fbbc65ce6bf972163b7009af2899da4a403 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- IOChannel.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 lldb_IOChannel_h_
11#define lldb_IOChannel_h_
12
13#include <string>
14#include <queue>
15
16#include <editline/readline.h>
17#include <histedit.h>
18
19#include "Driver.h"
20
21class IOChannel : public lldb::SBBroadcaster
22{
23public:
24 enum {
25 eBroadcastBitHasUserInput = (1 << 0),
26 eBroadcastBitUserInterrupt = (1 << 1),
27 eBroadcastBitThreadShouldExit = (1 << 2),
28 eBroadcastBitThreadDidExit = (1 << 3),
29 eBroadcastBitThreadDidStart = (1 << 4),
30 eBroadcastBitsSTDOUT = (1 << 5),
31 eBroadcastBitsSTDERR = (1 << 6),
32 eBroadcastBitsSTDIN = (1 << 7),
33 eAllEventBits = 0xffffffff
34 };
35
36 IOChannel (FILE *in,
37 FILE *out,
38 FILE *err,
39 Driver *driver = NULL);
40
41 virtual
42 ~IOChannel ();
43
44 bool
45 Start ();
46
47 bool
48 Stop ();
49
50 static void *
51 IOReadThread (void *);
52
53 void
54 Run ();
55
56 void
57 OutWrite (const char *buffer, size_t len);
58
59 void
60 ErrWrite (const char *buffer, size_t len);
61
62 bool
63 LibeditGetInput (std::string &);
64
65 void
66 SetPrompt ();
67
68 void
69 RefreshPrompt ();
70
71 void
72 AddCommandToQueue (const char *command);
73
74 bool
75 GetCommandFromQueue (std::string &cmd);
76
77 int
78 CommandQueueSize () const;
79
80 void
81 ClearCommandQueue ();
82
83 bool
84 CommandQueueIsEmpty () const;
85
86 const char *
87 GetPrompt ();
88
Greg Claytonc982c762010-07-09 20:39:50 +000089 static unsigned char
90 ElCompletionFn (EditLine *e, int ch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091
92 bool
93 IsGettingCommand () const;
94
95private:
96
97 Driver *m_driver;
98 lldb::thread_t m_read_thread;
99 bool m_read_thread_should_exit;
100 FILE *m_out_file;
101 FILE *m_err_file;
102 std::queue<std::string> m_command_queue;
103 const char *m_completion_key;
104
105 EditLine *m_edit_line;
106 History *m_history;
107 HistEvent m_history_event;
108 bool m_getting_command;
Greg Claytonc982c762010-07-09 20:39:50 +0000109
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110 void
111 HistorySaveLoad (bool save);
Greg Claytonc982c762010-07-09 20:39:50 +0000112
113 unsigned char
114 HandleCompletion (EditLine *e, int ch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115};
116
117#endif // lldb_IOChannel_h_