Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
linux_virtual_terminal.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17  */
18 
19 #ifndef MIR_GRAPHICS_GBM_LINUX_VIRTUAL_TERMINAL_H_
20 #define MIR_GRAPHICS_GBM_LINUX_VIRTUAL_TERMINAL_H_
21 
22 #include "virtual_terminal.h"
23 
24 #include <memory>
25 
26 #include <linux/vt.h>
27 #include <termios.h>
28 #include <unistd.h>
29 
30 namespace mir
31 {
32 namespace graphics
33 {
34 
35 class DisplayReport;
36 
37 namespace gbm
38 {
39 
41 {
42 public:
43  virtual ~VTFileOperations() = default;
44 
45  virtual int open(char const* pathname, int flags) = 0;
46  virtual int close(int fd) = 0;
47  virtual int ioctl(int d, int request, int val) = 0;
48  virtual int ioctl(int d, int request, void* p_val) = 0;
49  virtual int tcsetattr(int d, int acts, const struct termios *tcattr) = 0;
50  virtual int tcgetattr(int d, struct termios *tcattr) = 0;
51 
52 protected:
53  VTFileOperations() = default;
54  VTFileOperations(VTFileOperations const&) = delete;
56 };
57 
59 {
60 public:
61  LinuxVirtualTerminal(std::shared_ptr<VTFileOperations> const& fops,
62  int vt_number,
63  std::shared_ptr<DisplayReport> const& report);
64  ~LinuxVirtualTerminal() noexcept(true);
65 
66  void set_graphics_mode();
68  EventHandlerRegister& handlers,
69  std::function<bool()> const& switch_away,
70  std::function<bool()> const& switch_back);
71 
72 private:
73  class FDWrapper
74  {
75  public:
76  FDWrapper(std::shared_ptr<VTFileOperations> const& fops, int fd)
77  : fops{fops}, fd_{fd}
78  {
79  }
80  ~FDWrapper() { if (fd_ >= 0) fops->close(fd_); }
81  int fd() const { return fd_; }
82  private:
83  std::shared_ptr<VTFileOperations> const fops;
84  int const fd_;
85  };
86 
87  int find_active_vt_number();
88  int open_vt(int vt_number);
89 
90 
91  std::shared_ptr<VTFileOperations> const fops;
92  std::shared_ptr<DisplayReport> const report;
93  FDWrapper const vt_fd;
94  int prev_kd_mode;
95  struct vt_mode prev_vt_mode;
96  int prev_tty_mode;
97  struct termios prev_tcattr;
98  bool active;
99 };
100 
101 }
102 }
103 }
104 
105 #endif /* MIR_GRAPHICS_GBM_LINUX_VIRTUAL_TERMINAL_H_ */

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Oct 15 00:23:28 UTC 2013