Mir
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 Lesser 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser 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_MESA_LINUX_VIRTUAL_TERMINAL_H_
20 #define MIR_GRAPHICS_MESA_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 mesa
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  virtual ~PosixProcessOperations() = default;
62 
63  virtual pid_t getpid() const = 0;
64  virtual pid_t getppid() const = 0;
65  virtual pid_t getpgid(pid_t process) const = 0;
66  virtual pid_t getsid(pid_t process) const = 0;
67 
68  virtual int setpgid(pid_t process, pid_t group) = 0;
69  virtual pid_t setsid() = 0;
70 
71 protected:
72  PosixProcessOperations() = default;
75 };
76 
78 {
79 public:
80  LinuxVirtualTerminal(std::shared_ptr<VTFileOperations> const& fops,
81  std::unique_ptr<PosixProcessOperations> pops,
82  int vt_number,
83  std::shared_ptr<DisplayReport> const& report);
84  ~LinuxVirtualTerminal() noexcept(true);
85 
86  void set_graphics_mode() override;
87  void register_switch_handlers(
88  EventHandlerRegister& handlers,
89  std::function<bool()> const& switch_away,
90  std::function<bool()> const& switch_back) override;
91  void restore() override;
92 
93 private:
94  class FDWrapper
95  {
96  public:
97  FDWrapper(std::shared_ptr<VTFileOperations> const& fops, int fd)
98  : fops{fops}, fd_{fd}
99  {
100  }
101  ~FDWrapper() { if (fd_ >= 0) fops->close(fd_); }
102  int fd() const { return fd_; }
103  private:
104  std::shared_ptr<VTFileOperations> const fops;
105  int const fd_;
106  };
107 
108  int find_active_vt_number();
109  int open_vt(int vt_number);
110 
111 
112  std::shared_ptr<VTFileOperations> const fops;
113  std::unique_ptr<PosixProcessOperations> const pops;
114  std::shared_ptr<DisplayReport> const report;
115  FDWrapper const vt_fd;
116  int prev_kd_mode;
117  struct vt_mode prev_vt_mode;
118  int prev_tty_mode;
119  struct termios prev_tcattr;
120  bool active;
121 };
122 
123 }
124 }
125 }
126 
127 #endif /* MIR_GRAPHICS_MESA_LINUX_VIRTUAL_TERMINAL_H_ */
All things Mir.
Definition: atomic_callback.h:25
VTFileOperations & operator=(VTFileOperations const &)=delete
virtual int tcsetattr(int d, int acts, const struct termios *tcattr)=0
Definition: linux_virtual_terminal.h:40
virtual int ioctl(int d, int request, int val)=0
Definition: virtual_terminal.h:33
virtual int tcgetattr(int d, struct termios *tcattr)=0
Definition: linux_virtual_terminal.h:58
Definition: linux_virtual_terminal.h:77
virtual int open(char const *pathname, int flags)=0
Definition: event_handler_register.h:32

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016