aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/devices/error.cpp
blob: 403205518229ecb166c8c9325c889383c3db425d (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
49
50
51
52
53
54
55
56
57
#include <kapi/devices/error.hpp>

#include <kstd/system_error.hpp>

#include <string_view>

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";
          case driver_match_errc::no_device_signature:
            return "missing device signature";
          case driver_match_errc::invalid_device_signature:
            return "device signature is invalid";
          default:
            return "unknown driver matching error";
        }
      }

      [[nodiscard]] auto default_error_condition(int value) const noexcept -> kstd::error_condition override
      {
        switch (static_cast<driver_match_errc>(value))
        {
          case driver_match_errc::no_match:
          case driver_match_errc::no_device_signature:
            return make_error_condition(kstd::errc::not_supported);
            break;
          case driver_match_errc::invalid_device_signature:
            return make_error_condition(kstd::errc::invalid_argument);
          default:
            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