Module: RSMP::SiteProxy::Modules::Commands

Included in:
RSMP::SiteProxy
Defined in:
lib/rsmp/proxy/site/modules/commands.rb

Overview

Handles command requests and responses

Instance Method Summary collapse

Instance Method Details

#process_command_response(message) ⇒ Object



37
38
39
40
# File 'lib/rsmp/proxy/site/modules/commands.rb', line 37

def process_command_response(message)
  log "Received #{message.type}", message: message, level: :log
  acknowledge message
end

#send_command(command_list, component: nil, validate: true) ⇒ Object

Build and send a CommandRequest. Returns the CommandRequest message.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rsmp/proxy/site/modules/commands.rb', line 7

def send_command(command_list, component: nil, validate: true)
  validate_ready 'send command'
  component ||= main.c_id
  m_id = RSMP::Message.make_m_id
  message = RSMP::CommandRequest.new({
                                       'cId' => component,
                                       'arg' => command_list,
                                       'mId' => m_id
                                     })
  apply_nts_message_attributes message
  send_message message, validate: validate
  message
end

#send_command_and_collect(command_list, within:, component: nil, validate: true) ⇒ Object

Build, send a CommandRequest and collect the CommandResponse. Returns the collector. Raises on NotAck or timeout if ok! is called on the result.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rsmp/proxy/site/modules/commands.rb', line 23

def send_command_and_collect(command_list, within:, component: nil, validate: true)
  validate_ready 'send command'
  component ||= main.c_id
  m_id = RSMP::Message.make_m_id
  message = RSMP::CommandRequest.new({
                                       'cId' => component,
                                       'arg' => command_list,
                                       'mId' => m_id
                                     })
  apply_nts_message_attributes message
  collector = CommandResponseCollector.new(self, command_list, timeout: within, initiator: message)
  send_message_and_collect(message, collector, validate: validate)[:collector]
end