Class: Twib::ActiveRequest
- Inherits:
-
Object
- Object
- Twib::ActiveRequest
- Defined in:
- lib/twib.rb
Overview
A request to be sent to a remote device.
Instance Method Summary collapse
-
#initialize(tc, device_id, object_id, command_id, tag, payload, &block) ⇒ ActiveRequest
constructor
A new instance of ActiveRequest.
- #respond(response) ⇒ Object private
-
#wait ⇒ Response
Waits for this request to receive a response.
-
#wait_ok ⇒ Response
Waits for this request to receive a response, and raises if the response is not OK.
Constructor Details
#initialize(tc, device_id, object_id, command_id, tag, payload, &block) ⇒ ActiveRequest
Returns a new instance of ActiveRequest.
55 56 57 58 59 60 61 62 63 64 65 |
# 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 |
Instance Method Details
#respond(response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 |
# 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 ⇒ Response
Waits for this request to receive a response.
78 79 80 81 82 83 84 85 |
# 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 ⇒ Response
Waits for this request to receive a response, and raises if the response is not OK.
90 91 92 |
# File 'lib/twib.rb', line 90 def wait_ok wait.assert_ok end |