µ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.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2017-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#ifndef CMSIS_PLUS_POSIX_IO_TTY_H_
13#define CMSIS_PLUS_POSIX_IO_TTY_H_
14
15// ----------------------------------------------------------------------------
16
17#if defined(__cplusplus)
18
19// ----------------------------------------------------------------------------
20
21#if defined(OS_USE_OS_APP_CONFIG_H)
22#include <cmsis-plus/os-app-config.h>
23#endif
24
25#include <cmsis-plus/rtos/os.h>
28
29// ----------------------------------------------------------------------------
30
31#pragma GCC diagnostic push
32#if defined(__clang__)
33#pragma clang diagnostic ignored "-Wc++98-compat"
34#endif
35
36// ----------------------------------------------------------------------------
37
38namespace os
39{
40 namespace posix
41 {
42 // ------------------------------------------------------------------------
43
44 class tty_impl;
45
46 // ========================================================================
47
48#pragma GCC diagnostic push
49#if defined(__clang__)
50#elif defined(__GNUC__)
51#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
52#pragma GCC diagnostic ignored "-Wsuggest-final-types"
53#endif
54 class tty : public char_device
55 {
56 // ----------------------------------------------------------------------
57
63 public:
64 tty (tty_impl& impl, const char* name);
65
70 // The rule of five.
71 tty (const tty&) = delete;
72 tty (tty&&) = delete;
73 tty&
74 operator= (const tty&)
75 = delete;
76 tty&
77 operator= (tty&&)
78 = delete;
79
84 virtual ~tty () noexcept override;
85
90 // ----------------------------------------------------------------------
96 public:
97 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetattr.html
98 virtual int
99 tcgetattr (/* struct */ termios* ptio);
100
101 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetattr.html
102 virtual int
103 tcsetattr (int options, const /* struct */ termios* ptio);
104
105 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcflush.html
106 virtual int
107 tcflush (int queue_selector);
108
109 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsendbreak.html
110 virtual int
111 tcsendbreak (int duration);
112
113 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcdrain.html
114 virtual int
115 tcdrain (void);
116
117 // ----------------------------------------------------------------------
118 // Support functions.
119
120 tty_impl&
121 impl (void) const;
122 };
123#pragma GCC diagnostic pop
124
125 // ========================================================================
126
127#pragma GCC diagnostic push
128#if defined(__clang__)
129#pragma clang diagnostic ignored "-Wpadded"
130#elif defined(__GNUC__)
131#pragma GCC diagnostic ignored "-Wpadded"
132#endif
133
135 {
136 // ----------------------------------------------------------------------
137
138 friend class tty;
139
145 public:
146 tty_impl (void);
147
152 // The rule of five.
153 tty_impl (const tty_impl&) = delete;
154 tty_impl (tty_impl&&) = delete;
155 tty_impl&
156 operator= (const tty_impl&)
157 = delete;
158 tty_impl&
159 operator= (tty_impl&&)
160 = delete;
161
166 virtual ~tty_impl () override;
167
172 // ----------------------------------------------------------------------
178 public:
179 virtual int
180 do_tcgetattr (/* struct */ termios* ptio)
181 = 0;
182
183 virtual int
184 do_tcsetattr (int options, const /* struct */ termios* ptio)
185 = 0;
186
187 virtual int
188 do_tcflush (int queue_selector)
189 = 0;
190
191 virtual int
192 do_tcsendbreak (int duration)
193 = 0;
194
195 virtual int
197 = 0;
198
199 virtual int
200 do_isatty (void) final;
201
205 };
206
207#pragma GCC diagnostic pop
208
209 // ========================================================================
210
211 template <typename T>
212 class tty_implementable : public tty
213 {
214 // ----------------------------------------------------------------------
215
216 public:
217 using value_type = T;
218
219 // ----------------------------------------------------------------------
220
226 public:
227 template <typename... Args>
228 tty_implementable (const char* name, Args&&... args);
229
234 // The rule of five.
235 tty_implementable (const tty_implementable&) = delete;
238 operator= (const tty_implementable&)
239 = delete;
241 operator= (tty_implementable&&)
242 = delete;
243
248 virtual ~tty_implementable ();
249
254 // ----------------------------------------------------------------------
260 public:
261 // Support functions.
262
264 impl (void) const;
265
270 // ----------------------------------------------------------------------
271 protected:
276 value_type impl_instance_;
277
281 };
282
283 // ========================================================================
284 } /* namespace posix */
285} /* namespace os */
286
287// ===== Inline & template implementations ====================================
288
289namespace os
290{
291 namespace posix
292 {
293 // ========================================================================
294
295 inline tty_impl&
296 tty::impl (void) const
297 {
298 return static_cast<tty_impl&> (impl_);
299 }
300
301 // ========================================================================
302
303 template <typename T>
304 template <typename... Args>
305 tty_implementable<T>::tty_implementable (const char* name, Args&&... args)
306 : tty{ impl_instance_, name }, //
307 impl_instance_{ std::forward<Args> (args)... }
308 {
309#if defined(OS_TRACE_POSIX_IO_TTY)
310 trace::printf ("tty_implementable::%s(\"%s\")=@%p\n", __func__, name_,
311 this);
312#endif
313 }
314
315 template <typename T>
317 {
318#if defined(OS_TRACE_POSIX_IO_TTY)
319 trace::printf ("tty_implementable::%s() @%p %s\n", __func__, this,
320 name_);
321#endif
322 }
323
324 template <typename T>
327 {
328 return static_cast<value_type&> (impl_);
329 }
330
331 // ========================================================================
332 } /* namespace posix */
333} /* namespace os */
334
335#pragma GCC diagnostic pop
336
337// ----------------------------------------------------------------------------
338
339#endif /* __cplusplus */
340
341// ----------------------------------------------------------------------------
342
343#endif /* CMSIS_PLUS_POSIX_IO_TTY_H_ */
Char device class.
Definition char-device.h:52
const char * name(void) const
Definition device.h:304
virtual ~tty_impl() override
Definition tty.cpp:90
virtual int do_tcsendbreak(int duration)=0
virtual int do_tcgetattr(termios *ptio)=0
virtual int do_tcflush(int queue_selector)=0
virtual int do_isatty(void) final
Definition tty.cpp:98
virtual int do_tcsetattr(int options, const termios *ptio)=0
virtual int do_tcdrain(void)=0
tty_implementable(const char *name, Args &&... args)
Definition tty.h:305
virtual ~tty_implementable()
Definition tty.h:316
value_type & impl(void) const
Definition tty.h:326
virtual int tcdrain(void)
Definition tty.cpp:76
virtual int tcsendbreak(int duration)
Definition tty.cpp:52
virtual int tcgetattr(termios *ptio)
Definition tty.cpp:58
virtual int tcflush(int queue_selector)
Definition tty.cpp:70
virtual int tcsetattr(int options, const termios *ptio)
Definition tty.cpp:64
tty_impl & impl(void) const
Definition tty.h:296
virtual ~tty() noexcept override
Definition tty.cpp:42
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
System namespace.
Standard std namespace.
Single file µOS++ RTOS definitions.