summaryrefslogtreecommitdiffstats
path: root/lldb/include/lldb/Core/InputReader.h
blob: 2d876240c1d7c38bef0a60af2f0abea2838c12ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//===-- InputReader.h -------------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_InputReader_h_
#define liblldb_InputReader_h_

#include <termios.h>

#include "lldb/lldb-include.h"
#include "lldb/lldb-enumerations.h"
#include "lldb/Core/Debugger.h"


namespace lldb_private {

class InputReader
{
public:

    typedef size_t (*Callback) (void *baton, 
                                InputReader *reader, 
                                lldb::InputReaderAction notification,
                                const char *bytes, 
                                size_t bytes_len);

    InputReader ();

    virtual
    ~InputReader ();

    virtual Error
    Initialize (Callback callback, 
                void *baton,
                lldb::InputReaderGranularity token_size,
                const char *end_token,
                const char *prompt,
                bool echo);
    
    bool
    IsDone () const
    {
        return m_done;
    }

    void
    SetIsDone (bool b)
    {
        m_done = b;
    }

    lldb::InputReaderGranularity
    GetGranularity () const
    {
        return m_granularity;
    }

    bool
    GetEcho () const
    {
        return m_echo;
    }

    // Subclasses _can_ override this function to get input as it comes in
    // without any granularity
    virtual size_t
    HandleRawBytes (const char *bytes, size_t bytes_len);

    FILE *
    GetInputFileHandle ();

    FILE *
    GetOutputFileHandle ();

    bool 
    IsActive () const
    {
        return m_active;
    }

    const char *
    GetPrompt () const;

    void
    RefreshPrompt();

protected:
    friend class Debugger;

    void
    Notify (lldb::InputReaderAction notification);

    Callback m_callback;
    void *m_callback_baton;
    std::string m_end_token;
    std::string m_prompt;
    lldb::InputReaderGranularity m_granularity;
    bool m_done;
    bool m_echo;
    bool m_active;

private:
    DISALLOW_COPY_AND_ASSIGN (InputReader);

};

} // namespace lldb_private

#endif // #ifndef liblldb_InputReader_h_
OpenPOWER on IntegriCloud