µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
char-device.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) 2015-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_CHAR_DEVICE_H_
13#define CMSIS_PLUS_POSIX_IO_CHAR_DEVICE_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
26
27// ----------------------------------------------------------------------------
28
29#pragma GCC diagnostic push
30#if defined(__clang__)
31#pragma clang diagnostic ignored "-Wc++98-compat"
32#endif
33
34// ----------------------------------------------------------------------------
35
36namespace os
37{
38 namespace posix
39 {
40 // ------------------------------------------------------------------------
41
42 class char_device_impl;
43
44 // ========================================================================
45
51 class char_device : public device
52 {
53 // ----------------------------------------------------------------------
54
60 public:
61 char_device (char_device_impl& impl, const char* name);
62
67 // The rule of five.
68 char_device (const char_device&) = delete;
69 char_device (char_device&&) = delete;
71 operator= (const char_device&)
72 = delete;
74 operator= (char_device&&)
75 = delete;
76
81 virtual ~char_device () override;
82
87 // ----------------------------------------------------------------------
93 public:
94 // Support functions.
95
97 impl (void) const;
98
102 };
103
104 // ========================================================================
105
106#pragma GCC diagnostic push
107#if defined(__clang__)
108#pragma clang diagnostic ignored "-Wpadded"
109#elif defined(__GNUC__)
110#pragma GCC diagnostic ignored "-Wpadded"
111#endif
112
114 {
115 // ----------------------------------------------------------------------
116
117 friend class char_device;
118
124 public:
125 char_device_impl (void);
126
131 // The rule of five.
132 char_device_impl (const char_device_impl&) = delete;
135 operator= (const char_device_impl&)
136 = delete;
138 operator= (char_device_impl&&)
139 = delete;
140
145 virtual ~char_device_impl () override;
146
151 // ----------------------------------------------------------------------
157 public:
158 // Implementations
159
160 virtual off_t
161 do_lseek (off_t offset, int whence) override;
162
163 virtual void
164 do_sync (void) override;
165
169 };
170
171#pragma GCC diagnostic pop
172
173 // ========================================================================
174
175 template <typename T>
177 {
178 // ----------------------------------------------------------------------
179
180 public:
181 using value_type = T;
182
183 // ----------------------------------------------------------------------
184
190 public:
191 template <typename... Args>
192 char_device_implementable (const char* name, Args&&... args);
193
198 // The rule of five.
202 operator= (const char_device_implementable&)
203 = delete;
205 operator= (char_device_implementable&&)
206 = delete;
207
212 virtual ~char_device_implementable () override;
213
218 // ----------------------------------------------------------------------
224 public:
225 // Support functions.
226
228 impl (void) const;
229
234 // ----------------------------------------------------------------------
235 protected:
240 value_type impl_instance_;
241
245 };
246
247 // ========================================================================
248 } /* namespace posix */
249} /* namespace os */
250
251// ===== Inline & template implementations ====================================
252
253namespace os
254{
255 namespace posix
256 {
257 // ========================================================================
258
259 inline char_device_impl&
260 char_device::impl (void) const
261 {
262 return static_cast<char_device_impl&> (impl_);
263 }
264
265 // ========================================================================
266
267 template <typename T>
268 template <typename... Args>
270 Args&&... args)
271 : char_device{ impl_instance_, name }, //
272 impl_instance_{ std::forward<Args> (args)... }
273 {
274#if defined(OS_TRACE_POSIX_IO_CHAR_DEVICE)
275 trace::printf ("char_device_implementable::%s(\"%s\")=@%p\n", __func__,
276 name_, this);
277#endif
278 }
279
280 template <typename T>
282 {
283#if defined(OS_TRACE_POSIX_IO_CHAR_DEVICE)
284 trace::printf ("char_device_implementable::%s() @%p %s\n", __func__,
285 this, name_);
286#endif
287 }
288
289 template <typename T>
292 {
293 return static_cast<value_type&> (impl_);
294 }
295
296 // ========================================================================
297 } /* namespace posix */
298} /* namespace os */
299
300#pragma GCC diagnostic pop
301
302// ----------------------------------------------------------------------------
303
304#endif /* __cplusplus */
305
306// ----------------------------------------------------------------------------
307
308#endif /* CMSIS_PLUS_POSIX_IO_CHAR_DEVICE_H_ */
virtual off_t do_lseek(off_t offset, int whence) override
virtual ~char_device_impl() override
virtual void do_sync(void) override
virtual ~char_device_implementable() override
value_type & impl(void) const
char_device_implementable(const char *name, Args &&... args)
Char device class.
Definition char-device.h:52
char_device_impl & impl(void) const
virtual ~char_device() override
Base device class.
Definition device.h:67
const char * name(void) const
Definition device.h:304
off_t offset(void)
Definition io.h:472
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
System namespace.
Standard std namespace.