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

#command_collector_list(command_list) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rsmp/proxy/site/modules/commands.rb', line 48

def command_collector_list(command_list)
  list = JSON.parse(JSON.generate(command_list))
  resolved = RSMP::Schema.resolve_sxl({ 'type' => 'CommandRequest', 'arg' => list }, schemas: schemas)
  return list unless resolved

  type, version = resolved
  list.each do |item|
    next unless item.key?('v')

    descriptor = RSMP::Schema.sxl_argument_descriptor(type, version, :commands, item['cCI'], item['n'])
    next unless descriptor

    encoded = RSMP::Message.encode_sxl_value(item['v'], descriptor)
    item['v'] = RSMP::Message.decode_sxl_value(encoded, descriptor)
  end
  list
rescue RSMP::Schema::Error
  list
end

#process_command_response(message) ⇒ Object



68
69
70
71
72
73
# File 'lib/rsmp/proxy/site/modules/commands.rb', line 68

def process_command_response(message)
  return reject_multiple_command_codes(message) if core_3_3? && multiple_command_codes?(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 Result.



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

def send_command(command_list, component: nil, validate: true)
  readiness = validate_ready 'send command'
  return readiness if readiness.failure?

  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).map(&:message)
end

#send_command!Object



22
23
24
# File 'lib/rsmp/proxy/site/modules/commands.rb', line 22

def send_command!(...)
  send_command(...).value!
end

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

Build, send a CommandRequest and collect its responses. Returns Result.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rsmp/proxy/site/modules/commands.rb', line 27

def send_command_and_collect(command_list, within:, component: nil, validate: true)
  readiness = validate_ready 'send command'
  return readiness if readiness.failure?

  component ||= main.c_id
  m_id = RSMP::Message.make_m_id
  collector_list = command_collector_list(command_list)
  message = RSMP::CommandRequest.new({
                                       'cId' => component,
                                       'arg' => command_list,
                                       'mId' => m_id
                                     })
  apply_nts_message_attributes message
  collector = CommandResponseCollector.new(self, collector_list, timeout: within, initiator: message)
  send_message_and_collect(message, collector, validate: validate)
end

#send_command_and_collect!Object



44
45
46
# File 'lib/rsmp/proxy/site/modules/commands.rb', line 44

def send_command_and_collect!(...)
  send_command_and_collect(...).value!
end