]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnStreamStdin.h
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmnStreamStdin.h
1 //===-- MIUtilStreamStdin.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 //++
11 // File:        MIUtilStreamStdin.h
12 //
13 // Overview:    CMICmnStreamStdin interface.
14 //
15 // Environment: Compilers:  Visual C++ 12.
16 //                          gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //              Libraries:  See MIReadmetxt.
18 //
19 // Copyright:   None.
20 //--
21
22 #pragma once
23
24 // In-house headers:
25 #include "MIUtilString.h"
26 #include "MIUtilThreadBaseStd.h"
27 #include "MICmnBase.h"
28 #include "MIUtilSingletonBase.h"
29
30 //++ ============================================================================
31 // Details: MI common code class. Used to handle stream data from Stdin.
32 //          Singleton class using the Visitor pattern. A driver using the interface
33 //          provide can receive callbacks when a new line of data is received.
34 //          Each line is determined by a carriage return.
35 //          A singleton class.
36 // Gotchas: None.
37 // Authors: Illya Rudkin 10/02/2014.
38 // Changes: Factored out OS specific handling of reading stdin  - IOR 16/06/2014.
39 //--
40 class CMICmnStreamStdin : public CMICmnBase, public CMIUtilThreadActiveObjBase, public MI::ISingleton<CMICmnStreamStdin>
41 {
42     // Give singleton access to private constructors
43     friend MI::ISingleton<CMICmnStreamStdin>;
44
45     // Class:
46   public:
47     //++
48     // Description: Visitor pattern. Driver(s) use this interface to get a callback
49     //              on each new line of data received from stdin.
50     //--
51     class IStreamStdin
52     {
53       public:
54         virtual bool ReadLine(const CMIUtilString &vStdInBuffer, bool &vrwbYesExit) = 0;
55
56         /* dtor */ virtual ~IStreamStdin(void){};
57     };
58
59     //++
60     // Description: Specific OS stdin handling implementations are created and used by *this
61     //              class. Seperates out functionality and enables handler to be set
62     //              dynamically depended on the OS detected.
63     //--
64     class IOSStdinHandler
65     {
66       public:
67         virtual bool InputAvailable(bool &vwbAvail) = 0;
68         virtual const MIchar *ReadLine(CMIUtilString &vwErrMsg) = 0;
69         virtual void InterruptReadLine(void){};
70
71         /* dtor */ virtual ~IOSStdinHandler(void){};
72     };
73
74     // Methods:
75   public:
76     bool Initialize(void);
77     bool Shutdown(void);
78     //
79     const CMIUtilString &GetPrompt(void) const;
80     bool SetPrompt(const CMIUtilString &vNewPrompt);
81     void SetEnablePrompt(const bool vbYes);
82     bool GetEnablePrompt(void) const;
83     void SetCtrlCHit(void);
84     bool SetVisitor(IStreamStdin &vrVisitor);
85     bool SetOSStdinHandler(IOSStdinHandler &vrHandler);
86     void OnExitHandler(void);
87
88     // Overridden:
89   public:
90     // From CMIUtilThreadActiveObjBase
91     virtual const CMIUtilString &ThreadGetName(void) const;
92
93     // Overridden:
94   protected:
95     // From CMIUtilThreadActiveObjBase
96     virtual bool ThreadRun(bool &vrIsAlive);
97     virtual bool
98     ThreadFinish(void); // Let this thread clean up after itself
99
100     // Methods:
101   private:
102     /* ctor */ CMICmnStreamStdin(void);
103     /* ctor */ CMICmnStreamStdin(const CMICmnStreamStdin &);
104     void operator=(const CMICmnStreamStdin &);
105
106     bool MonitorStdin(bool &vrwbYesExit);
107     const MIchar *ReadLine(CMIUtilString &vwErrMsg);
108     bool
109     InputAvailable(bool &vbAvail); // Bytes are available on stdin
110
111     // Overridden:
112   private:
113     // From CMICmnBase
114     /* dtor */ virtual ~CMICmnStreamStdin(void);
115
116     // Attributes:
117   private:
118     const CMIUtilString m_constStrThisThreadname;
119     IStreamStdin *m_pVisitor;
120     CMIUtilString m_strPromptCurrent; // Command line prompt as shown to the user
121     volatile bool m_bKeyCtrlCHit;     // True = User hit Ctrl-C, false = has not yet
122     bool m_bShowPrompt;               // True = Yes prompt is shown/output to the user (stdout), false = no prompt
123     bool m_bRedrawPrompt;             // True = Prompt needs to be redrawn
124     IOSStdinHandler *m_pStdinReadHandler;
125 };