µ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 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_CHAR_DEVICE_H_
29#define CMSIS_PLUS_POSIX_IO_CHAR_DEVICE_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
42
43// ----------------------------------------------------------------------------
44
45#pragma GCC diagnostic push
46
47#if defined(__clang__)
48#pragma clang diagnostic ignored "-Wc++98-compat"
49#endif
50
51// ----------------------------------------------------------------------------
52
53namespace os
54{
55 namespace posix
56 {
57 // ------------------------------------------------------------------------
58
59 class char_device_impl;
60
61 // ========================================================================
62
68 class char_device : public device
69 {
70 // ----------------------------------------------------------------------
71
77 public:
78
79 char_device (char_device_impl& impl, const char* name);
80
85 // The rule of five.
86 char_device (const char_device&) = delete;
87 char_device (char_device&&) = delete;
89 operator= (const char_device&) = delete;
91 operator= (char_device&&) = delete;
92
97 virtual
98 ~char_device () override;
99
104 // ----------------------------------------------------------------------
110 public:
111
112 // Support functions.
113
115 impl (void) const;
116
120 };
121
122 // ========================================================================
123
124#pragma GCC diagnostic push
125#pragma GCC diagnostic ignored "-Wpadded"
126
128 {
129 // ----------------------------------------------------------------------
130
131 friend class char_device;
132
138 public:
139
140 char_device_impl (void);
141
146 // The rule of five.
147 char_device_impl (const char_device_impl&) = delete;
150 operator= (const char_device_impl&) = delete;
152 operator= (char_device_impl&&) = delete;
153
158 virtual
159 ~char_device_impl () override;
160
165 // ----------------------------------------------------------------------
171 public:
172
173 // Implementations
174
175 virtual off_t
176 do_lseek (off_t offset, int whence) override;
177
178 virtual void
179 do_sync (void) override;
180
184 };
185
186#pragma GCC diagnostic pop
187
188 // ========================================================================
189
190 template<typename T>
192 {
193 // --------------------------------------------------------------------
194
195 public:
196
197 using value_type = T;
198
199 // --------------------------------------------------------------------
200
206 public:
207
208 template<typename ... Args>
209 char_device_implementable (const char* name, Args&&... args);
210
215 // The rule of five.
219 operator= (const char_device_implementable&) = delete;
221 operator= (char_device_implementable&&) = delete;
222
227 virtual
228 ~char_device_implementable () override;
229
234 // --------------------------------------------------------------------
240 public:
241
242 // Support functions.
243
245 impl (void) const;
246
251 // --------------------------------------------------------------------
252 protected:
253
258 value_type impl_instance_;
259
263 };
264
265 // ==========================================================================
266 } /* namespace posix */
267} /* namespace os */
268
269// ===== Inline & template implementations ====================================
270
271namespace os
272{
273 namespace posix
274 {
275 // ========================================================================
276
277 inline char_device_impl&
278 char_device::impl (void) const
279 {
280 return static_cast<char_device_impl&> (impl_);
281 }
282
283 // ========================================================================
284
285 template<typename T>
286 template<typename ... Args>
288 const char* name, Args&&... args) :
290 { impl_instance_, name }, //
291 impl_instance_
292 { std::forward<Args>(args)... }
293 {
294#if defined(OS_TRACE_POSIX_IO_CHAR_DEVICE)
295 trace::printf ("char_device_implementable::%s(\"%s\")=@%p\n",
296 __func__, name_, this);
297#endif
298 }
299
300 template<typename T>
302 {
303#if defined(OS_TRACE_POSIX_IO_CHAR_DEVICE)
304 trace::printf ("char_device_implementable::%s() @%p %s\n", __func__,
305 this, name_);
306#endif
307 }
308
309 template<typename T>
312 {
313 return static_cast<value_type&> (impl_);
314 }
315
316 // ==========================================================================
317 } /* namespace posix */
318} /* namespace os */
319
320#pragma GCC diagnostic pop
321
322// ----------------------------------------------------------------------------
323
324#endif /* __cplusplus */
325
326// ----------------------------------------------------------------------------
327
328#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:69
char_device_impl & impl(void) const
virtual ~char_device() override
Base device class.
Definition device.h:78
const char * name(void) const
Definition device.h:310
off_t offset(void)
Definition io.h:461
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
System namespace.