Class: Freenect::Context
- Inherits:
-
Object
- Object
- Freenect::Context
- Defined in:
- lib/freenect/context.rb
Instance Method Summary collapse
- #close ⇒ Object (also: #shutdown)
- #closed? ⇒ Boolean
- #context ⇒ Object
-
#initialize(usb_ctx = nil) ⇒ Context
constructor
A new instance of Context.
- #num_devices ⇒ Object
- #open_device(idx) ⇒ Object (also: #[])
- #process_events ⇒ Object
- #set_log_callback(&block) ⇒ Object
- #set_log_level(loglevel) ⇒ Object (also: #log_level=)
Constructor Details
#initialize(usb_ctx = nil) ⇒ Context
9 10 11 12 13 14 15 16 17 |
# File 'lib/freenect/context.rb', line 9 def initialize(usb_ctx=nil) ctx_p = FFI::MemoryPointer.new(:pointer) if ::FFI::Freenect.freenect_init(ctx_p, usb_ctx) != 0 raise ContextError, "freenect_init() returned nonzero" elsif ctx_p.null? raise ContextError, "freenect_init() produced a NULL context" end @ctx = ctx_p.read_pointer end |
Instance Method Details
#close ⇒ Object Also known as: shutdown
51 52 53 54 55 56 57 58 |
# File 'lib/freenect/context.rb', line 51 def close unless closed? if ::FFI::Freenect.freenect_shutdown(@ctx) != 0 raise ContextError, "freenect_shutdown() returned nonzero" end @ctx_closed = true end end |
#closed? ⇒ Boolean
62 63 64 |
# File 'lib/freenect/context.rb', line 62 def closed? @ctx_closed == true end |
#context ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/freenect/context.rb', line 19 def context if @ctx_closed raise ContextError, "This context has been shut down and can no longer be used" else return @ctx end end |
#num_devices ⇒ Object
27 28 29 |
# File 'lib/freenect/context.rb', line 27 def num_devices ::FFI::Freenect.freenect_num_devices(self.context) end |
#open_device(idx) ⇒ Object Also known as: []
31 32 33 |
# File 'lib/freenect/context.rb', line 31 def open_device(idx) return Device.new(self, idx) end |
#process_events ⇒ Object
47 48 49 |
# File 'lib/freenect/context.rb', line 47 def process_events ::FFI::Freenect.freenect_process_events(self.context) end |
#set_log_callback(&block) ⇒ Object
43 44 45 |
# File 'lib/freenect/context.rb', line 43 def set_log_callback(&block) ::FFI::Freenect.freenect_set_log_callback(self.context, block) end |
#set_log_level(loglevel) ⇒ Object Also known as: log_level=
37 38 39 |
# File 'lib/freenect/context.rb', line 37 def set_log_level(loglevel) ::FFI::Freenect.freenect_set_log_level(self.context, loglevel) end |