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