1 //===-- TTYState.h ----------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Created by Greg Clayton on 3/26/07.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_TTYSTATE_H
14 #define LLDB_TOOLS_DEBUGSERVER_SOURCE_TTYSTATE_H
24 bool GetTTYState(int fd
, bool saveProcessGroup
);
25 bool SetTTYState() const;
27 bool IsValid() const {
28 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
;
43 class TTYStateSwitcher
{
48 bool GetState(uint32_t idx
, int fd
, bool saveProcessGroup
);
49 bool SetState(uint32_t idx
) const;
50 uint32_t NumStates() const { return sizeof(m_ttystates
) / sizeof(TTYState
); }
51 bool ValidStateIndex(uint32_t idx
) const { return idx
< NumStates(); }
54 mutable uint32_t m_currentState
;
55 TTYState m_ttystates
[2];