class Twib::ActiveRequest

A request to be sent to a remote device.

Public Class Methods

new(tc, device_id, object_id, command_id, tag, payload, &block) click to toggle source
# File lib/twib.rb, line 55
def initialize(tc, device_id, object_id, command_id, tag, payload, &block)
  @tc = tc
  @device_id = device_id
  @object_id = object_id
  @command_id = command_id
  @tag = tag
  @payload = payload
  @condvar = ConditionVariable.new
  @cb = block
  @response = nil
end

Public Instance Methods

respond(response) click to toggle source

@api private

# File lib/twib.rb, line 68
def respond(response) # expects to be synchronized by @tc.mutex
  @response = response
  @condvar.broadcast
  if @cb then
    @tc.cb_queue.push([@cb, response])
  end
end
wait() click to toggle source

Waits for this request to receive a response. @return [Response]

# File lib/twib.rb, line 78
def wait
  @tc.mutex.synchronize do
    while @response == nil do
      @condvar.wait(@tc.mutex)
    end
  end
  return @response
end
wait_ok() click to toggle source

Waits for this request to receive a response, and raises if the response is not OK. @raise [ResultError] @return [Response]

# File lib/twib.rb, line 90
def wait_ok
  wait.assert_ok
end