Class: OpenC3::PacketBase

Inherits:
Object show all
Defined in:
lib/openc3/microservices/trigger_group_microservice.rb

Overview

Stored in the TriggerGroupShare this should be a thread safe hash that triggers will be added, updated, and removed from

Instance Method Summary collapse

Constructor Details

#initialize(scope:) ⇒ PacketBase

Returns a new instance of PacketBase.



38
39
40
41
42
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 38

def initialize(scope:)
  @scope = scope
  @mutex = Mutex.new
  @packets = Hash.new
end

Instance Method Details

#add(topic:, packet:) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 62

def add(topic:, packet:)
  @mutex.synchronize do
    @packets[topic] ||= []
    if @packets[topic].length == 2
      @packets[topic].shift
    end
    @packets[topic].push(packet)
  end
end

#packet(target:, packet:) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 44

def packet(target:, packet:)
  topic = "#{@scope}__DECOM__{#{target}}__#{packet}"
  @mutex.synchronize do
    return nil unless @packets[topic]
    # Deep copy the packet so it doesn't change under us
    return Marshal.load( Marshal.dump(@packets[topic][-1]) )
  end
end

#previous_packet(target:, packet:) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 53

def previous_packet(target:, packet:)
  topic = "#{@scope}__DECOM__{#{target}}__#{packet}"
  @mutex.synchronize do
    return nil unless @packets[topic] and @packets[topic].length == 2
    # Deep copy the packet so it doesn't change under us
    return Marshal.load( Marshal.dump(@packets[topic][0]) )
  end
end

#remove(topic:) ⇒ Object



72
73
74
75
76
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 72

def remove(topic:)
  @mutex.synchronize do
    @packets.delete(topic)
  end
end