µ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++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2015-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_CHAR_DEVICE_H_
14#define CMSIS_PLUS_POSIX_IO_CHAR_DEVICE_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
27
28// ----------------------------------------------------------------------------
29
30#pragma GCC diagnostic push
31#if defined(__clang__)
32#pragma clang diagnostic ignored "-Wc++98-compat"
33#endif
34
35// ----------------------------------------------------------------------------
36
37namespace os
38{
39 namespace posix
40 {
41 // ------------------------------------------------------------------------
42
43 class char_device_impl;
44
45 // ========================================================================
46
52 class char_device : public device
53 {
54 // ----------------------------------------------------------------------
55
61 public:
62
63 char_device (char_device_impl& impl, const char* name);
64
69 // The rule of five.
70 char_device (const char_device&) = delete;
71 char_device (char_device&&) = delete;
73 operator= (const char_device&) = delete;
75 operator= (char_device&&) = delete;
76
81 virtual
82 ~char_device () override;
83
88 // ----------------------------------------------------------------------
94 public:
95
96 // Support functions.
97
99 impl (void) const;
100
104 };
105
106 // ========================================================================
107
108#pragma GCC diagnostic push
109#if defined(__clang__)
110#pragma clang diagnostic ignored "-Wpadded"
111#elif defined(__GNUC__)
112#pragma GCC diagnostic ignored "-Wpadded"
113#endif
114
116 {
117 // ----------------------------------------------------------------------
118
119 friend class char_device;
120
126 public:
127
128 char_device_impl (void);
129
134 // The rule of five.
135 char_device_impl (const char_device_impl&) = delete;
138 operator= (const char_device_impl&) = delete;
140 operator= (char_device_impl&&) = delete;
141
146 virtual
147 ~char_device_impl () override;
148
153 // ----------------------------------------------------------------------
159 public:
160
161 // Implementations
162
163 virtual off_t
164 do_lseek (off_t offset, int whence) override;
165
166 virtual void
167 do_sync (void) override;
168
172 };
173
174#pragma GCC diagnostic pop
175
176 // ========================================================================
177
178 template<typename T>
180 {
181 // --------------------------------------------------------------------
182
183 public:
184
185 using value_type = T;
186
187 // --------------------------------------------------------------------
188
194 public:
195
196 template<typename ... Args>
197 char_device_implementable (const char* name, Args&&... args);
198
203 // The rule of five.
207 operator= (const char_device_implementable&) = delete;
209 operator= (char_device_implementable&&) = delete;
210
215 virtual
216 ~char_device_implementable () override;
217
222 // --------------------------------------------------------------------
228 public:
229
230 // Support functions.
231
233 impl (void) const;
234
239 // --------------------------------------------------------------------
240 protected:
241
246 value_type impl_instance_;
247
251 };
252
253 // ==========================================================================
254 } /* namespace posix */
255} /* namespace os */
256
257// ===== Inline & template implementations ====================================
258
259namespace os
260{
261 namespace posix
262 {
263 // ========================================================================
264
265 inline char_device_impl&
266 char_device::impl (void) const
267 {
268 return static_cast<char_device_impl&> (impl_);
269 }
270
271 // ========================================================================
272
273 template<typename T>
274 template<typename ... Args>
276 const char* name, Args&&... args) :
278 { impl_instance_, name }, //
279 impl_instance_
280 { std::forward<Args>(args)... }
281 {
282#if defined(OS_TRACE_POSIX_IO_CHAR_DEVICE)
283 trace::printf ("char_device_implementable::%s(\"%s\")=@%p\n",
284 __func__, name_, this);
285#endif
286 }
287
288 template<typename T>
290 {
291#if defined(OS_TRACE_POSIX_IO_CHAR_DEVICE)
292 trace::printf ("char_device_implementable::%s() @%p %s\n", __func__,
293 this, name_);
294#endif
295 }
296
297 template<typename T>
300 {
301 return static_cast<value_type&> (impl_);
302 }
303
304 // ==========================================================================
305 } /* namespace posix */
306} /* namespace os */
307
308#pragma GCC diagnostic pop
309
310// ----------------------------------------------------------------------------
311
312#endif /* __cplusplus */
313
314// ----------------------------------------------------------------------------
315
316#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:53
char_device_impl & impl(void) const
virtual ~char_device() override
Base device class.
Definition device.h:68
const char * name(void) const
Definition device.h:307
off_t offset(void)
Definition io.h:476
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:60
System namespace.