µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::posix::device_registry< T > Class Template Reference

Devices registry static class. More...

#include <cmsis-plus/posix-io/device-registry.h>

Public Types

using pointer = T *
 
using reference = T &
 
using value_type = T
 

Public Member Functions

Constructors & Destructor
 device_registry ()=delete
 
 ~device_registry ()=delete
 

Static Public Member Functions

Public Static Member Functions
static void link (value_type *device)
 
static value_typeidentify_device (const char *path)
 

Detailed Description

template<typename T>
class os::posix::device_registry< T >

Definition at line 53 of file device-registry.h.

Member Typedef Documentation

◆ pointer

template<typename T >
using os::posix::device_registry< T >::pointer = T*

Definition at line 57 of file device-registry.h.

◆ reference

template<typename T >
using os::posix::device_registry< T >::reference = T&

Definition at line 58 of file device-registry.h.

◆ value_type

template<typename T >
using os::posix::device_registry< T >::value_type = T

Definition at line 56 of file device-registry.h.

Constructor & Destructor Documentation

◆ device_registry()

template<typename T >
os::posix::device_registry< T >::device_registry ( )
delete

◆ ~device_registry()

template<typename T >
os::posix::device_registry< T >::~device_registry ( )
delete

Member Function Documentation

◆ identify_device()

template<typename T >
T * os::posix::device_registry< T >::identify_device ( const char *  path)
static

return pointer to device or nullptr if not found.

Definition at line 186 of file device-registry.h.

187 {
188 assert (path != nullptr);
189
190 auto prefix = value_type::device_prefix ();
191 if (std::strncmp (prefix, path, std::strlen (prefix)) != 0)
192 {
193 // The device prefix does not match, not a device.
194 return nullptr;
195 }
196
197#pragma GCC diagnostic push
198#if defined(__clang__)
199#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
200#endif
201 // The prefix was identified; try to match the rest of the path.
202 auto name = path + std::strlen (prefix);
203#pragma GCC diagnostic pop
204
205 for (auto&& p : registry_list__)
206 {
207 if (p.match_name (name))
208 {
209 return static_cast<value_type*> (&p);
210 }
211 }
212
213 // Not a known device.
214 return nullptr;
215 }

Referenced by os::posix::opendir(), and os::posix::vopen().

◆ link()

template<typename T >
void os::posix::device_registry< T >::link ( value_type device)
static

Definition at line 153 of file device-registry.h.

154 {
155#if defined(DEBUG)
156
157#pragma GCC diagnostic push
158#if defined(__clang__)
159#elif defined(__GNUC__)
160#pragma GCC diagnostic ignored "-Waggregate-return"
161#endif
162 for (auto&& d : registry_list__)
163 {
164 // Validate the device name by checking duplicates.
165 if (std::strcmp (device->name (), d.name ()) == 0)
166 {
167 trace::puts ("Duplicate device name. Abort.");
168 std::abort ();
169 }
170 }
171#pragma GCC diagnostic push
172
173#endif // DEBUG
174
175 registry_list__.link (*device);
176
177 trace::printf ("Device '%s%s' linked\n", value_type::device_prefix (),
178 device->name ());
179 }
int puts(const char *s)
Write the string and a line terminator to the trace device.
Definition trace.cpp:102
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59

References os::posix::device::name(), os::trace::printf(), and os::trace::puts().

Referenced by os::posix::block_device::block_device(), and os::posix::char_device::char_device().


The documentation for this class was generated from the following file: