µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
file-descriptors-manager.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_FILE_DESCRIPTORS_MANAGER_H_
29#define CMSIS_PLUS_POSIX_IO_FILE_DESCRIPTORS_MANAGER_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#include <cstddef>
44#include <cassert>
45
46// ----------------------------------------------------------------------------
47
48#pragma GCC diagnostic push
49
50#if defined(__clang__)
51#pragma clang diagnostic ignored "-Wc++98-compat"
52#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
53#endif
54
55// ----------------------------------------------------------------------------
56
57namespace os
58{
59 namespace posix
60 {
61
62 // ------------------------------------------------------------------------
63
64 class io;
65 class socket;
66
67 // ========================================================================
68
75 {
76 // ----------------------------------------------------------------------
77
83 public:
84
85 file_descriptors_manager (std::size_t size);
86
91 // The rule of five.
95 operator= (const file_descriptors_manager&) = delete;
97 operator= (file_descriptors_manager&&) = delete;
98
104
109 // ----------------------------------------------------------------------
115 public:
116
117 static size_t
118 size (void);
119
120 static bool
121 valid (int fildes);
122
123 static class io*
124 io (int fildes);
125
126 static class socket*
127 socket (int fildes);
128
129 static int
130 allocate (class io* io);
131
132 static int
133 assign (file_descriptor_t fildes, class io* io);
134
135 static int
137
138 static size_t
139 used (void);
140
145 // ----------------------------------------------------------------------
146 private:
147
152 // Reserve 0, 1, 2 (stdin, stdout, stderr).
153 static constexpr std::size_t reserved__ = 3;
154
155 static std::size_t size__;
156
157 static class io** descriptors_array__;
158
162 };
163
164 // ==========================================================================
165 } /* namespace posix */
166} /* namespace os */
167
168// ===== Inline & template implementations ====================================
169
170namespace os
171{
172 namespace posix
173 {
174 // ========================================================================
175
176 inline size_t
178 {
179 return size__;
180 }
181
182 // ==========================================================================
183 } /* namespace posix */
184} /* namespace os */
185
186#pragma GCC diagnostic pop
187
188// ----------------------------------------------------------------------------
189
190#endif /* __cplusplus */
191
192// ----------------------------------------------------------------------------
193
194#endif /* CMSIS_PLUS_POSIX_IO_FILE_DESCRIPTORS_MANAGER_H_ */
File descriptors manager static class.
static int deallocate(file_descriptor_t fildes)
static int assign(file_descriptor_t fildes, class io *io)
Base I/O class.
Definition io.h:98
Network socket.
int socket(int domain, int type, int protocol)
int file_descriptor_t
Definition types.h:59
System namespace.