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 : public CMICmnBase, public CMIUtilThreadActiveObjBase, public MI::ISingleton<CMICmnStreamStdin>
42 // Give singleton access to private constructors
43 friend MI::ISingleton<CMICmnStreamStdin>;
48 // Description: Visitor pattern. Driver(s) use this interface to get a callback
49 // on each new line of data received from stdin.
54 virtual bool ReadLine(const CMIUtilString &vStdInBuffer, bool &vrwbYesExit) = 0;
56 /* dtor */ virtual ~IStreamStdin(void){};
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.
67 virtual bool InputAvailable(bool &vwbAvail) = 0;
68 virtual const MIchar *ReadLine(CMIUtilString &vwErrMsg) = 0;
69 virtual void InterruptReadLine(void){};
71 /* dtor */ virtual ~IOSStdinHandler(void){};
76 bool Initialize(void);
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);
90 // From CMIUtilThreadActiveObjBase
91 virtual const CMIUtilString &ThreadGetName(void) const;
95 // From CMIUtilThreadActiveObjBase
96 virtual bool ThreadRun(bool &vrIsAlive);
98 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);
109 InputAvailable(bool &vbAvail); // Bytes are available on stdin
114 /* dtor */ virtual ~CMICmnStreamStdin(void);
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;