µ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 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
28#ifndef CMSIS_PLUS_POSIX_IO_TTY_H_
29#define CMSIS_PLUS_POSIX_IO_TTY_H_
30
31// ----------------------------------------------------------------------------
32
33#if defined (__cplusplus)
34
35// ----------------------------------------------------------------------------
36
37#if defined(OS_USE_OS_APP_CONFIG_H)
38#include <cmsis-plus/os-app-config.h>
39#endif
40
41#include <cmsis-plus/rtos/os.h>
44
45// ----------------------------------------------------------------------------
46
47#pragma GCC diagnostic push
48
49#if defined(__clang__)
50#pragma clang diagnostic ignored "-Wc++98-compat"
51#endif
52
53// ----------------------------------------------------------------------------
54
55namespace os
56{
57 namespace posix
58 {
59 // ------------------------------------------------------------------------
60
61 class tty_impl;
62
63 // ========================================================================
64
65 class tty : public char_device
66 {
67 // ----------------------------------------------------------------------
68
74 public:
75
76 tty (tty_impl& impl, const char* name);
77
82 // The rule of five.
83 tty (const tty&) = delete;
84 tty (tty&&) = delete;
85 tty&
86 operator= (const tty&) = delete;
87 tty&
88 operator= (tty&&) = delete;
89
94 virtual
95 ~tty () noexcept override;
96
101 // ----------------------------------------------------------------------
107 public:
108
109 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetattr.html
110 virtual int
111 tcgetattr (struct termios *ptio);
112
113 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetattr.html
114 virtual int
115 tcsetattr (int options, const struct termios *ptio);
116
117 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcflush.html
118 virtual int
119 tcflush (int queue_selector);
120
121 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsendbreak.html
122 virtual int
123 tcsendbreak (int duration);
124
125 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcdrain.html
126 virtual int
127 tcdrain (void);
128
129 // ----------------------------------------------------------------------
130 // Support functions.
131
132 tty_impl&
133 impl (void) const;
134 };
135
136 // ========================================================================
137
138#pragma GCC diagnostic push
139#pragma GCC diagnostic ignored "-Wpadded"
140
142 {
143 // ----------------------------------------------------------------------
144
145 friend class tty;
146
152 public:
153
154 tty_impl (void);
155
160 // The rule of five.
161 tty_impl (const tty_impl&) = delete;
162 tty_impl (tty_impl&&) = delete;
163 tty_impl&
164 operator= (const tty_impl&) = delete;
165 tty_impl&
166 operator= (tty_impl&&) = delete;
167
172 virtual
173 ~tty_impl () override;
174
179 // ----------------------------------------------------------------------
185 public:
186
187 virtual int
188 do_tcgetattr (struct termios *ptio) = 0;
189
190 virtual int
191 do_tcsetattr (int options, const struct termios *ptio) = 0;
192
193 virtual int
194 do_tcflush (int queue_selector) = 0;
195
196 virtual int
197 do_tcsendbreak (int duration) = 0;
198
199 virtual int
200 do_tcdrain (void) = 0;
201
202 virtual int
203 do_isatty (void) final;
204
208 };
209
210#pragma GCC diagnostic pop
211
212 // ========================================================================
213
214 template<typename T>
215 class tty_implementable : public tty
216 {
217 // --------------------------------------------------------------------
218
219 public:
220
221 using value_type = T;
222
223 // --------------------------------------------------------------------
224
230 public:
231
232 template<typename ... Args>
233 tty_implementable (const char* name, Args&&... args);
234
239 // The rule of five.
240 tty_implementable (const tty_implementable&) = delete;
243 operator= (const tty_implementable&) = delete;
245 operator= (tty_implementable&&) = delete;
246
251 virtual
253
258 // --------------------------------------------------------------------
264 public:
265
266 // Support functions.
267
269 impl (void) const;
270
275 // --------------------------------------------------------------------
276 protected:
277
282 value_type impl_instance_;
283
287 };
288
289 // ==========================================================================
290 } /* namespace posix */
291} /* namespace os */
292
293// ===== Inline & template implementations ====================================
294
295namespace os
296{
297 namespace posix
298 {
299 // ========================================================================
300
301 inline tty_impl&
302 tty::impl (void) const
303 {
304 return static_cast<tty_impl&> (impl_);
305 }
306
307 // ========================================================================
308
309 template<typename T>
310 template<typename ... Args>
312 Args&&... args) :
313 tty
314 { impl_instance_, name }, //
315 impl_instance_
316 { std::forward<Args>(args)... }
317 {
318#if defined(OS_TRACE_POSIX_IO_TTY)
319 trace::printf ("tty_implementable::%s(\"%s\")=@%p\n", __func__, name_,
320 this);
321#endif
322 }
323
324 template<typename T>
326 {
327#if defined(OS_TRACE_POSIX_IO_TTY)
328 trace::printf ("tty_implementable::%s() @%p %s\n", __func__, this,
329 name_);
330#endif
331 }
332
333 template<typename T>
336 {
337 return static_cast<value_type&> (impl_);
338 }
339
340 // ==========================================================================
341 } /* namespace posix */
342} /* namespace os */
343
344#pragma GCC diagnostic pop
345
346// ----------------------------------------------------------------------------
347
348#endif /* __cplusplus */
349
350// ----------------------------------------------------------------------------
351
352#endif /* CMSIS_PLUS_POSIX_IO_TTY_H_ */
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
tty_implementable(const char *name, Args &&... args)
Definition tty.h:311
virtual ~tty_implementable()
Definition tty.h:325
value_type & impl(void) const
Definition tty.h:335
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.
Single file µOS++ RTOS definitions.