1 //===-- MIUtilStreamStdin.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 //===----------------------------------------------------------------------===//
11 // File: MIUtilStreamStdin.h
13 // Overview: CMICmnStreamStdin interface.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
25 #include "MIUtilString.h"
26 #include "MIUtilThreadBaseStd.h"
27 #include "MICmnBase.h"
28 #include "MIUtilSingletonBase.h"
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.
37 // Authors: Illya Rudkin 10/02/2014.
38 // Changes: Factored out OS specific handling of reading stdin - IOR 16/06/2014.
40 class CMICmnStreamStdin
42 , public CMIUtilThreadActiveObjBase
43 , public MI::ISingleton< CMICmnStreamStdin >
45 // Give singleton access to private constructors
46 friend MI::ISingleton< CMICmnStreamStdin >;
51 // Description: Visitor pattern. Driver(s) use this interface to get a callback
52 // on each new line of data received from stdin.
57 virtual bool ReadLine( const CMIUtilString & vStdInBuffer, bool & vrwbYesExit ) = 0;
59 /* dtor */ virtual ~IStreamStdin( void ) {};
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.
70 virtual bool InputAvailable( bool & vwbAvail ) = 0;
71 virtual const MIchar * ReadLine( CMIUtilString & vwErrMsg ) = 0;
73 /* dtor */ virtual ~IOSStdinHandler( void ) {};
78 bool Initialize( void );
79 bool Shutdown( void );
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 );
91 // From CMIUtilThreadActiveObjBase
92 virtual const CMIUtilString & ThreadGetName( void ) const;
96 // From CMIUtilThreadActiveObjBase
97 virtual bool ThreadRun( bool & vrIsAlive );
98 virtual bool ThreadFinish( void ); // Let this thread clean up after itself
102 /* ctor */ CMICmnStreamStdin( void );
103 /* ctor */ CMICmnStreamStdin( const CMICmnStreamStdin & );
104 void operator=( const CMICmnStreamStdin & );
106 bool MonitorStdin( bool & vrwbYesExit );
107 const MIchar * ReadLine( CMIUtilString & vwErrMsg );
108 bool InputAvailable( bool & vbAvail ); // Bytes are available on stdin
113 /* dtor */ virtual ~CMICmnStreamStdin( void );
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;