Exception: Ragweed::Wraposx::KernelCallError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/ragweed/wraposx/kernelerrorx.rb

Overview

Exception class for mach kernel calls. Works mostly like SystemCallError. Subclasses are individual error conditions and case equality (===) is done by class then error number (KErrno)

Constant Summary collapse

DEFAULT_MESSAGE =
"Unknown Error"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg) ⇒ KernelCallError

Returns a new instance of KernelCallError.



115
116
117
# File 'lib/ragweed/wraposx/kernelerrorx.rb', line 115

def initialize(msg)
  super msg
end

Instance Attribute Details

#kerrnoObject (readonly)

Returns the value of attribute kerrno.



71
72
73
# File 'lib/ragweed/wraposx/kernelerrorx.rb', line 71

def kerrno
  @kerrno
end

Class Method Details

.===(other) ⇒ Object

Case equality. Returns true if self and other are KernelCallError or when error numbers match.



104
105
106
107
108
109
110
111
112
113
# File 'lib/ragweed/wraposx/kernelerrorx.rb', line 104

def self.===(other)
  return false if not other.kind_of?(Ragweed::Wraposx::KernelCallError)
  return true if self == Ragweed::Wraposx::KernelCallError
  
  begin
    return self.const_get("KErrno") == other.const_get("KErrno")
  rescue
    return false
  end
end

.new(msg = "", err = nil) ⇒ Object

Returns a subclass of KernelCallError based on the KernelReturn value err



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ragweed/wraposx/kernelerrorx.rb', line 74

def self.new(msg = "", err = nil)
  if msg.kind_of? Fixnum
    err = msg
    msg = ""
  end
  mesg = ""

  klass = Ragweed::Wraposx::KErrno.constants.detect{|x| Ragweed::Wraposx::KErrno.const_get(x).const_get("KErrno") == err}
  if (klass.nil? or klass.empty?)
    o = self.allocate
    o.instance_variable_set("@kerrno", err)
    mesg = "Unknown kernel error"
  else
    o = Ragweed::Wraposx::KErrno.const_get(klass).allocate
    mesg = Ragweed::Wraposx::KernelReturn.const_get(klass)[:message]
  end
  
  if o.class.const_defined?("KErrno")
    o.instance_variable_set("@kerrno", o.class.const_get("KErrno"))
  else
    o.instance_variable_set("@kerrno", err)
    mesg = "#{mesg}: #{err}" if err
  end

  mesg = "#{mesg} - #{msg}" if !(msg.nil? or msg.to_s.empty?)  
  o.send(:initialize, mesg)
  return o
end