µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
tty.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2017 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
29
31
32// ----------------------------------------------------------------------------
33
34#if defined(__clang__)
35#pragma clang diagnostic ignored "-Wc++98-compat"
36#endif
37
38// ----------------------------------------------------------------------------
39
40namespace os
41{
42 namespace posix
43 {
44 // ========================================================================
45
46 tty::tty (tty_impl& impl, const char* name) :
48 { impl, name }
49 {
50 type_ |= type::tty;
51#if defined(OS_TRACE_POSIX_IO_TTY)
52 trace::printf ("tty::%s(\"%s\")=@%p\n", __func__, name_, this);
53#endif
54 }
55
56 tty::~tty () noexcept
57 {
58#if defined(OS_TRACE_POSIX_IO_TTY)
59 trace::printf ("tty::%s() @%p %s\n", __func__, this, name_);
60#endif
61 }
62
63 // ------------------------------------------------------------------------
64
65 inline int
66 tty::tcsendbreak (int duration)
67 {
68 return impl ().do_tcsendbreak (duration);
69 }
70
71 inline int
72 tty::tcgetattr (struct termios *ptio)
73 {
74 return impl ().do_tcgetattr (ptio);
75 }
76
77 inline int
78 tty::tcsetattr (int options, const struct termios *ptio)
79 {
80 return impl ().do_tcsetattr (options, ptio);
81 }
82
83 inline int
84 tty::tcflush (int queue_selector)
85 {
86 return impl ().do_tcflush (queue_selector);
87 }
88
89 inline int
91 {
92 return impl ().do_tcdrain ();
93 }
94
95 // ========================================================================
96
98 {
99#if defined(OS_TRACE_POSIX_IO_TTY)
100 trace::printf ("tty_impl::%s()=@%p\n", __func__, this);
101#endif
102 }
103
105 {
106#if defined(OS_TRACE_POSIX_IO_TTY)
107 trace::printf ("tty_impl::%s() @%p\n", __func__, this);
108#endif
109 }
110
111 int
113 {
114 return 1; // Yes!
115 }
116
117 // ==========================================================================
118 } /* namespace posix */
119} /* namespace os */
120
121// ----------------------------------------------------------------------------
Char device class.
Definition char-device.h:69
const char * name(void) const
Definition device.h:310
virtual ~tty_impl() override
Definition tty.cpp:104
virtual int do_tcsendbreak(int duration)=0
virtual int do_tcsetattr(int options, const struct termios *ptio)=0
virtual int do_tcflush(int queue_selector)=0
virtual int do_isatty(void) final
Definition tty.cpp:112
virtual int do_tcdrain(void)=0
virtual int do_tcgetattr(struct termios *ptio)=0
virtual int tcdrain(void)
Definition tty.cpp:90
virtual int tcsendbreak(int duration)
Definition tty.cpp:66
virtual int tcsetattr(int options, const struct termios *ptio)
Definition tty.cpp:78
virtual int tcflush(int queue_selector)
Definition tty.cpp:84
tty_impl & impl(void) const
Definition tty.h:302
virtual int tcgetattr(struct termios *ptio)
Definition tty.cpp:72
virtual ~tty() noexcept override
Definition tty.cpp:56
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
System namespace.