aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/devices/error.cpp
blob: 9d814fbec8fbe08a56e8893221a7206cdf3d6021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <kapi/devices/error.hpp>

#include <kstd/system_error.hpp>

#include <string_view>
#include <utility>

namespace kapi::devices
{

  namespace
  {
    struct driver_match_category_t final : kstd::error_category
    {
      [[nodiscard]] auto name() const noexcept -> std::string_view override
      {
        return "driver_match";
      }

      [[nodiscard]] auto message(int value) const noexcept -> std::string_view override
      {
        switch (static_cast<driver_match_errc>(value))
        {
          case driver_match_errc::no_match:
            return "driver does not match this device";
          default:
            return "unknown driver matching error";
        }
      }

      [[nodiscard]] auto default_error_condition(int value) const noexcept -> kstd::error_condition override
      {
        if (value == std::to_underlying(driver_match_errc::no_match))
        {
          return make_error_condition(kstd::errc::not_supported);
        }
        return kstd::error_category::default_error_condition(value);
      }

    } constexpr driver_match_category_instance{};
  }  // namespace

  auto driver_match_category() noexcept -> kstd::error_category const &
  {
    return driver_match_category_instance;
  }

}  // namespace kapi::devices