µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
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) 2018-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_BLOCK_H_
14#define CMSIS_PLUS_POSIX_IO_BLOCK_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
28#include <mutex>
29
30// ----------------------------------------------------------------------------
31
32#if ! defined(OS_STRING_POSIX_DEVICE_PREFIX)
33#define OS_STRING_POSIX_DEVICE_PREFIX "/dev/"
34#endif
35
36// ----------------------------------------------------------------------------
37
38#pragma GCC diagnostic push
39#if defined(__clang__)
40#pragma clang diagnostic ignored "-Wc++98-compat"
41#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
42#endif
43
44// ----------------------------------------------------------------------------
45
46namespace os
47{
48 namespace posix
49 {
50 // ------------------------------------------------------------------------
51
52 class device_impl;
53
54 // ========================================================================
55
61#pragma GCC diagnostic push
62#if defined(__clang__)
63#elif defined(__GNUC__)
64#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
65#pragma GCC diagnostic ignored "-Wsuggest-final-types"
66#endif
67 class device : public io
68 {
69 // ----------------------------------------------------------------------
70
76 public:
77
78 device (device_impl& impl, type t, const char* name);
79
84 // The rule of five.
85 device (const device&) = delete;
86 device (device&&) = delete;
87 device&
88 operator= (const device&) = delete;
89 device&
90 operator= (device&&) = delete;
91
96 virtual
97 ~device () override;
98
103 // ----------------------------------------------------------------------
109 public:
110
116 int
117 open (const char* path = nullptr, int oflag = 0, ...);
118
125 int
126 vopen (const char* path, int oflag, std::va_list args);
127
128 virtual int
129 close (void) override;
130
131 int
132 ioctl (int request, ...);
133
134 virtual int
135 vioctl (int request, std::va_list args);
136
137 virtual void
138 sync (void);
139
140 // ----------------------------------------------------------------------
141
142 virtual bool
143 match_name (const char* name) const;
144
145 const char*
146 name (void) const;
147
148 static const char*
149 device_prefix (void);
150
151 // ----------------------------------------------------------------------
152 // Support functions.
153
155 impl (void) const;
156
161 // ----------------------------------------------------------------------
162 protected:
163
168 const char* name_ = nullptr;
169
174 // ----------------------------------------------------------------------
175 public:
176
181 // Intrusive node used to link this device to the registry list.
182 // Must be public.
183 utils::double_list_links registry_links_;
184
188 };
189#pragma GCC diagnostic pop
190
191 // ========================================================================
192
193#pragma GCC diagnostic push
194#if defined(__clang__)
195#pragma clang diagnostic ignored "-Wpadded"
196#elif defined(__GNUC__)
197#pragma GCC diagnostic ignored "-Wpadded"
198#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
199#pragma GCC diagnostic ignored "-Wsuggest-final-types"
200#endif
201
202 class device_impl : public io_impl
203 {
204 // ----------------------------------------------------------------------
205
210 friend class device;
211
216 // ----------------------------------------------------------------------
222 public:
223
224 device_impl (void);
225
230 // The rule of five.
231 device_impl (const device_impl&) = delete;
232 device_impl (device_impl&&) = delete;
234 operator= (const device_impl&) = delete;
236 operator= (device_impl&&) = delete;
237
242 virtual
243 ~device_impl () override;
244
249 // ----------------------------------------------------------------------
255 public:
256
257 virtual bool
258 do_is_opened (void) override;
259
260 virtual int
261 do_vopen (const char* path, int oflag, std::va_list args) = 0;
262
263 virtual int
264 do_vioctl (int request, std::va_list args) = 0;
265
266 virtual void
267 do_sync (void) = 0;
268
269 // ----------------------------------------------------------------------
270
271 int
272 open_count (void);
273
278 // ----------------------------------------------------------------------
279 protected:
280
285 int open_count_ = 0;
286
290 };
291
292#pragma GCC diagnostic pop
293
294 // ==========================================================================
295 } /* namespace posix */
296} /* namespace os */
297
298// ===== Inline & template implementations ====================================
299
300namespace os
301{
302 namespace posix
303 {
304 // ========================================================================
305
306 inline const char*
307 device::name (void) const
308 {
309 return name_;
310 }
311
312 inline device_impl&
313 device::impl (void) const
314 {
315 return static_cast<device_impl&> (impl_);
316 }
317
318 inline const char*
320 {
322 }
323
324 // ========================================================================
325
326 inline int
328 {
329 return open_count_;
330 }
331
332 // ==========================================================================
333 } /* namespace posix */
334} /* namespace os */
335
336#pragma GCC diagnostic pop
337
338// ----------------------------------------------------------------------------
339
340#endif /* __cplusplus */
341
342// ----------------------------------------------------------------------------
343
344#endif /* CMSIS_PLUS_POSIX_IO_BLOCK_H_ */
virtual int do_vioctl(int request, std::va_list args)=0
virtual ~device_impl() override
Definition device.cpp:209
virtual bool do_is_opened(void) override
Definition device.cpp:219
int open_count(void)
Definition device.h:327
virtual void do_sync(void)=0
virtual int do_vopen(const char *path, int oflag, std::va_list args)=0
Base device class.
Definition device.h:68
device_impl & impl(void) const
Definition device.h:313
static const char * device_prefix(void)
Definition device.h:319
virtual int close(void) override
Definition device.cpp:114
virtual bool match_name(const char *name) const
Definition device.cpp:192
int vopen(const char *path, int oflag, std::va_list args)
Definition device.cpp:76
virtual int vioctl(int request, std::va_list args)
Definition device.cpp:155
int ioctl(int request,...)
Definition device.cpp:138
virtual ~device() override
Definition device.cpp:50
int open(const char *path=nullptr, int oflag=0,...)
Definition device.cpp:64
virtual void sync(void)
Definition device.cpp:174
const char * name(void) const
Definition device.h:307
Base I/O class.
Definition io.h:87
#define OS_STRING_POSIX_DEVICE_PREFIX
Definition device.h:33
System namespace.