Class: Mycel::Channel::Command

Inherits:
Context
  • Object
show all
Includes:
Mycel::Callbacks
Defined in:
lib/mycel.rb

Constant Summary

Constants inherited from Context

Mycel::Channel::Context::STATE_INIT, Mycel::Channel::Context::STATE_RUNNING, Mycel::Channel::Context::STATE_STOPPED

Instance Attribute Summary

Attributes inherited from Context

#session

Instance Method Summary collapse

Methods included from Mycel::Callbacks

#__mycel_callback_handlers__, #callback, #on

Methods inherited from Context

#wait

Constructor Details

#initialize(session) ⇒ Command

Returns a new instance of Command.



450
451
452
453
# File 'lib/mycel.rb', line 450

def initialize(session)
  super
  @id = @session.generate_and_register_out_id(self)
end

Instance Method Details

#advise(payload) ⇒ Object



462
463
464
465
466
# File 'lib/mycel.rb', line 462

def advise(payload)
  guard_assert_state(STATE_RUNNING) {
    @session.send(Message.generate_payload_msg('advise', @id, payload))
  }
end

#request(payload) ⇒ Object



455
456
457
458
459
460
# File 'lib/mycel.rb', line 455

def request(payload)
  guard_assert_state(STATE_INIT) {
    @session.send(Message.generate_payload_msg('request', @id, payload))
    change_state(STATE_RUNNING)
  }
end

#they_abortObject



476
477
478
479
480
481
482
# File 'lib/mycel.rb', line 476

def they_abort
  guard_assert_state(STATE_RUNNING) {
    callback(:abort)
    @session.unregister_id(DIR_COMMAND, @id)
    change_state(STATE_STOPPED)
  }
end

#they_progress(payload) ⇒ Object



484
485
486
487
488
# File 'lib/mycel.rb', line 484

def they_progress(payload)
  guard_assert_state(STATE_RUNNING) {
    callback(:progress, payload)
  }
end

#they_respond(payload) ⇒ Object



468
469
470
471
472
473
474
# File 'lib/mycel.rb', line 468

def they_respond(payload)
  guard_assert_state(STATE_RUNNING) {
    callback(:response, payload)
    @session.unregister_id(DIR_COMMAND, @id)
    change_state(STATE_STOPPED)
  }
end