]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmnStreamStdin.h
Merge llvm 3.6.0rc2 from ^/vendor/llvm/dist, merge clang 3.6.0rc2 from
[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
41 :       public CMICmnBase
42 ,       public CMIUtilThreadActiveObjBase
43 ,       public MI::ISingleton< CMICmnStreamStdin >
44 {
45         // Give singleton access to private constructors
46         friend MI::ISingleton< CMICmnStreamStdin >;
47
48 // Class:
49 public:
50         //++
51         // Description: Visitor pattern. Driver(s) use this interface to get a callback
52         //                              on each new line of data received from stdin.
53         //--
54         class IStreamStdin
55         {
56         public:
57                 virtual bool ReadLine( const CMIUtilString & vStdInBuffer, bool & vrwbYesExit ) = 0;
58
59                 /* dtor */ virtual ~IStreamStdin( void ) {};
60         };
61
62         //++
63         // Description: Specific OS stdin handling implementations are created and used by *this
64         //                              class. Seperates out functionality and enables handler to be set 
65         //                              dynamically depended on the OS detected. 
66         //--
67         class IOSStdinHandler
68         {
69         public:
70                 virtual bool                    InputAvailable( bool & vwbAvail ) = 0;
71                 virtual const MIchar *  ReadLine( CMIUtilString & vwErrMsg ) = 0;
72
73                 /* dtor */ virtual ~IOSStdinHandler( void ) {};
74         };
75                 
76 // Methods:
77 public:
78         bool    Initialize( void );
79         bool    Shutdown( void );
80         //
81         const CMIUtilString &   GetPrompt( void ) const;
82         bool                                    SetPrompt( const CMIUtilString & vNewPrompt );
83         void                                    SetEnablePrompt( const bool vbYes );
84         bool                                    GetEnablePrompt( void ) const;
85         void                                    SetCtrlCHit( void );
86         bool                                    SetVisitor( IStreamStdin & vrVisitor );
87         bool                                    SetOSStdinHandler( IOSStdinHandler & vrHandler );
88         
89 // Overridden:
90 public:
91         // From CMIUtilThreadActiveObjBase
92         virtual const CMIUtilString & ThreadGetName( void ) const;
93         
94 // Overridden:
95 protected:
96         // From CMIUtilThreadActiveObjBase
97         virtual bool ThreadRun( bool & vrIsAlive );
98         virtual bool 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                    InputAvailable( bool & vbAvail );                                       // Bytes are available on stdin
109
110 // Overridden:
111 private:
112         // From CMICmnBase
113         /* dtor */ virtual ~CMICmnStreamStdin( void );
114
115 // Attributes:
116 private:
117         const CMIUtilString     m_constStrThisThreadname;
118         IStreamStdin *          m_pVisitor;
119         CMIUtilString           m_strPromptCurrent;             // Command line prompt as shown to the user
120         volatile bool           m_bKeyCtrlCHit;                 // True = User hit Ctrl-C, false = has not yet
121         bool                            m_bShowPrompt;                  // True = Yes prompt is shown/output to the user (stdout), false = no prompt
122         bool                            m_bRedrawPrompt;                // True = Prompt needs to be redrawn
123         IOSStdinHandler *       m_pStdinReadHandler;
124 };
125