µ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++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2018-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_BLOCK_H_
13#define CMSIS_PLUS_POSIX_IO_BLOCK_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
27#include <mutex>
28
29// ----------------------------------------------------------------------------
30
31#if !defined(OS_STRING_POSIX_DEVICE_PREFIX)
32#define OS_STRING_POSIX_DEVICE_PREFIX "/dev/"
33#endif
34
35// ----------------------------------------------------------------------------
36
37#pragma GCC diagnostic push
38#if defined(__clang__)
39#pragma clang diagnostic ignored "-Wc++98-compat"
40#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
41#endif
42
43// ----------------------------------------------------------------------------
44
45namespace os
46{
47 namespace posix
48 {
49 // ------------------------------------------------------------------------
50
51 class device_impl;
52
53 // ========================================================================
54
60#pragma GCC diagnostic push
61#if defined(__clang__)
62#elif defined(__GNUC__)
63#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
64#pragma GCC diagnostic ignored "-Wsuggest-final-types"
65#endif
66 class device : public io
67 {
68 // ----------------------------------------------------------------------
69
75 public:
76 device (device_impl& impl, type t, const char* name);
77
82 // The rule of five.
83 device (const device&) = delete;
84 device (device&&) = delete;
85 device&
86 operator= (const device&)
87 = delete;
88 device&
89 operator= (device&&)
90 = delete;
91
96 virtual ~device () override;
97
102 // ----------------------------------------------------------------------
108 public:
114 int
115 open (const char* path = nullptr, int oflag = 0, ...);
116
123 int
124 vopen (const char* path, int oflag, std::va_list args);
125
126 virtual int
127 close (void) override;
128
129 int
130 ioctl (int request, ...);
131
132 virtual int
133 vioctl (int request, std::va_list args);
134
135 virtual void
136 sync (void);
137
138 // ----------------------------------------------------------------------
139
140 virtual bool
141 match_name (const char* name) const;
142
143 const char*
144 name (void) const;
145
146 static const char*
147 device_prefix (void);
148
149 // ----------------------------------------------------------------------
150 // Support functions.
151
153 impl (void) const;
154
159 // ----------------------------------------------------------------------
160 protected:
165 const char* name_ = nullptr;
166
171 // ----------------------------------------------------------------------
172 public:
177 // Intrusive node used to link this device to the registry list.
178 // Must be public.
179 utils::double_list_links registry_links_;
180
184 };
185#pragma GCC diagnostic pop
186
187 // ========================================================================
188
189#pragma GCC diagnostic push
190#if defined(__clang__)
191#pragma clang diagnostic ignored "-Wpadded"
192#elif defined(__GNUC__)
193#pragma GCC diagnostic ignored "-Wpadded"
194#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
195#pragma GCC diagnostic ignored "-Wsuggest-final-types"
196#endif
197
198 class device_impl : public io_impl
199 {
200 // ----------------------------------------------------------------------
201
206 friend class device;
207
212 // ----------------------------------------------------------------------
218 public:
219 device_impl (void);
220
225 // The rule of five.
226 device_impl (const device_impl&) = delete;
227 device_impl (device_impl&&) = delete;
229 operator= (const device_impl&)
230 = delete;
232 operator= (device_impl&&)
233 = delete;
234
239 virtual ~device_impl () override;
240
245 // ----------------------------------------------------------------------
251 public:
252 virtual bool
253 do_is_opened (void) override;
254
255 virtual int
256 do_vopen (const char* path, int oflag, std::va_list args)
257 = 0;
258
259 virtual int
260 do_vioctl (int request, std::va_list args)
261 = 0;
262
263 virtual void
264 do_sync (void)
265 = 0;
266
267 // ----------------------------------------------------------------------
268
269 int
270 open_count (void);
271
276 // ----------------------------------------------------------------------
277 protected:
282 int open_count_ = 0;
283
287 };
288
289#pragma GCC diagnostic pop
290
291 // ========================================================================
292 } /* namespace posix */
293} /* namespace os */
294
295// ===== Inline & template implementations ====================================
296
297namespace os
298{
299 namespace posix
300 {
301 // ========================================================================
302
303 inline const char*
304 device::name (void) const
305 {
306 return name_;
307 }
308
309 inline device_impl&
310 device::impl (void) const
311 {
312 return static_cast<device_impl&> (impl_);
313 }
314
315 inline const char*
317 {
319 }
320
321 // ========================================================================
322
323 inline int
325 {
326 return open_count_;
327 }
328
329 // ========================================================================
330 } /* namespace posix */
331} /* namespace os */
332
333#pragma GCC diagnostic pop
334
335// ----------------------------------------------------------------------------
336
337#endif /* __cplusplus */
338
339// ----------------------------------------------------------------------------
340
341#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:206
virtual bool do_is_opened(void) override
Definition device.cpp:216
int open_count(void)
Definition device.h:324
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:67
device_impl & impl(void) const
Definition device.h:310
static const char * device_prefix(void)
Definition device.h:316
virtual int close(void) override
Definition device.cpp:111
virtual bool match_name(const char *name) const
Definition device.cpp:189
int vopen(const char *path, int oflag, std::va_list args)
Definition device.cpp:74
virtual int vioctl(int request, std::va_list args)
Definition device.cpp:152
int ioctl(int request,...)
Definition device.cpp:135
virtual ~device() override
Definition device.cpp:48
int open(const char *path=nullptr, int oflag=0,...)
Definition device.cpp:62
virtual void sync(void)
Definition device.cpp:171
const char * name(void) const
Definition device.h:304
Base I/O class.
Definition io.h:86
#define OS_STRING_POSIX_DEVICE_PREFIX
Definition device.h:32
System namespace.