µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
system-error.cpp
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) 2016-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#include <cmsis-plus/rtos/os.h>
14
15#if defined(__EXCEPTIONS)
16#include <string>
17#include <system_error>
18#endif
19
20// ----------------------------------------------------------------------------
21
22#if defined(__clang__)
23#pragma clang diagnostic ignored "-Wc++98-compat"
24#pragma clang diagnostic ignored "-Wc++98-compat-bind-to-temporary-copy"
25#endif
26
27// ----------------------------------------------------------------------------
28
29using namespace os;
30
31// ----------------------------------------------------------------------------
32
33namespace os
34{
35 namespace estd
36 {
37 // ========================================================================
38
39#if defined(__EXCEPTIONS)
40
41 struct system_error_category : public std::error_category
42 {
43 virtual const char*
44 name () const noexcept override;
45
46 virtual std::string
47 message (int i) const override;
48
49 };
50
51 const char*
52 system_error_category::name () const noexcept
53 {
54 return "system";
55 }
56
57#pragma GCC diagnostic push
58#if defined(__clang__)
59#pragma clang diagnostic ignored "-Wunused-parameter"
60#elif defined(__GNUC__)
61#pragma GCC diagnostic ignored "-Wunused-parameter"
62#endif
63
64 std::string
65 system_error_category::message (int i) const
66 {
67#if defined(DEBUG)
68 return std::string (strerror (i));
69#else
70 return std::string ("");
71#endif
72 }
73
74 struct cmsis_error_category : public std::error_category
75 {
76 virtual const char*
77 name () const noexcept override;
78
79 virtual std::string
80 message (int i) const override;
81 };
82
83 const char*
84 cmsis_error_category::name () const noexcept
85 {
86 return "cmsis";
87 }
88
89#pragma GCC diagnostic push
90#if defined(__clang__)
91#pragma clang diagnostic ignored "-Wunused-parameter"
92#elif defined(__GNUC__)
93#pragma GCC diagnostic ignored "-Wunused-parameter"
94#endif
95
96 std::string
97 cmsis_error_category::message (int i) const
98 {
99#if defined(DEBUG)
100 return std::string (strerror (i));
101#else
102 return std::string ("");
103#endif
104 }
105
106#pragma GCC diagnostic pop
107
108#endif
109
110 void
111 __throw_system_error (int ev, const char* what_arg)
112 {
113#if defined(__EXCEPTIONS)
114 // error: copying parameter of type 'os::estd::system_error_category' when binding a reference to a temporary would invoke a deleted constructor in C++98 [-Werror,-Wc++98-compat-bind-to-temporary-copy]
115 throw std::system_error (std::error_code (ev, system_error_category ()),
116 what_arg);
117#else
118 trace_printf ("system_error(%d, %s)\n", ev, what_arg);
119 std::abort ();
120#endif
121 }
122
123 void
124 __throw_cmsis_error (int ev, const char* what_arg)
125 {
126#if defined(__EXCEPTIONS)
127 // error: copying parameter of type 'os::estd::cmsis_error_category' when binding a reference to a temporary would invoke a deleted constructor in C++98 [-Werror,-Wc++98-compat-bind-to-temporary-copy]
128 throw std::system_error (std::error_code (ev, cmsis_error_category ()),
129 what_arg);
130#else
131 trace_printf ("system_error(%d, %s)\n", ev, what_arg);
132 std::abort ();
133#endif
134 }
135
136 // --------------------------------------------------------------------------
137
138 } /* namespace estd */
139} /* namespace os */
140
141// ----------------------------------------------------------------------------
void __throw_system_error(int ev, const char *what_arg)
void __throw_cmsis_error(int ev, const char *what_arg)
System namespace.
Standard std namespace.
Single file µOS++ RTOS definitions.
int trace_printf(const char *format,...)