]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/abi/l4_error.cpp
update
[l4.git] / kernel / fiasco / src / abi / l4_error.cpp
1 INTERFACE:
2
3 #include "types.h"
4
5 class L4_error
6 {
7 public:
8   enum Error_code
9   {
10     None            = 0,
11     Timeout         = 2,
12     R_timeout       = 3,
13     Not_existent    = 4,
14     Canceled        = 6,
15     R_canceled      = 7,
16     Overflow        = 8,
17     Snd_xfertimeout = 10,
18     Rcv_xfertimeout = 12,
19     Aborted         = 14,
20     R_aborted       = 15,
21     Map_failed      = 16,
22   };
23
24   enum Phase
25   {
26     Snd = 0,
27     Rcv = 1
28   };
29
30   L4_error(Error_code ec = None, Phase p = Snd) : _raw(ec | p) {}
31   L4_error(L4_error const &e, Phase p = Snd) : _raw(e._raw | p) {}
32
33   bool ok() const { return _raw == 0; }
34
35   Error_code error() const { return Error_code(_raw & 0x1e); }
36   Mword raw() const { return _raw; }
37   bool snd_phase() const { return !(_raw & Rcv); }
38
39   static L4_error from_raw(Mword raw) { return L4_error(true, raw); }
40
41 private:
42   L4_error(bool, Mword raw) : _raw(raw) {}
43   Mword _raw;
44 };
45
46
47 //----------------------------------------------------------------------------
48 IMPLEMENTATION [debug]:
49
50 static char const *__errors[] =
51 { "OK", "timeout", "not existent", "canceled", "overflow",
52   "xfer snd", "xfer rcv", "aborted", "map failed" };
53
54
55
56 PUBLIC
57 char const *
58 L4_error::str_error()
59 {
60   return __errors[(_raw >> 1) & 0xf];
61 }
62