1 //===-- TTYState.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 //===----------------------------------------------------------------------===//
10 // Created by Greg Clayton on 3/26/07.
12 //===----------------------------------------------------------------------===//
14 #ifndef __TTYState_h__
15 #define __TTYState_h__
26 bool GetTTYState (int fd, bool saveProcessGroup);
27 bool SetTTYState () const;
29 bool IsValid() const { return FileDescriptorValid() && TFlagsValid() && TTYStateValid(); }
30 bool FileDescriptorValid() const { return m_fd >= 0; }
31 bool TFlagsValid() const { return m_tflags != -1; }
32 bool TTYStateValid() const { return m_ttystateErr == 0; }
33 bool ProcessGroupValid() const { return m_processGroup != -1; }
36 int m_fd; // File descriptor
39 struct termios m_ttystate;
45 class TTYStateSwitcher
51 bool GetState(uint32_t idx, int fd, bool saveProcessGroup);
52 bool SetState(uint32_t idx) const;
53 uint32_t NumStates() const { return sizeof(m_ttystates)/sizeof(TTYState); }
54 bool ValidStateIndex(uint32_t idx) const { return idx < NumStates(); }
57 mutable uint32_t m_currentState;
58 TTYState m_ttystates[2];