rustorb-dds 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +26 -0
- data/ext/rustorb_dds_ext/extconf.rb +36 -0
- data/ext/rustorb_dds_ext/rustorb_dds_ext.c +2184 -0
- data/lib/rustorb/dds/core.rb +523 -0
- data/lib/rustorb/dds/domain.rb +133 -0
- data/lib/rustorb/dds/native.rb +140 -0
- data/lib/rustorb/dds/pub.rb +181 -0
- data/lib/rustorb/dds/qos.rb +343 -0
- data/lib/rustorb/dds/sub.rb +273 -0
- data/lib/rustorb/dds/topic.rb +115 -0
- data/lib/rustorb/dds/types.rb +780 -0
- data/lib/rustorb/dds/version.rb +8 -0
- data/lib/rustorb/dds.rb +32 -0
- data/vendor/include/rustorb/dds.h +955 -0
- data/vendor/linux-aarch64/librustorb_dds_ffi.a +4 -0
- data/vendor/linux-x86_64/librustorb_dds_ffi.a +4 -0
- data/vendor/macos-aarch64/librustorb_dds_ffi.a +0 -0
- data/vendor/macos-x86_64/librustorb_dds_ffi.a +0 -0
- metadata +64 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The Ruby side of DDS::Native (rustorb_dds_ext): the dispatcher threads
|
|
4
|
+
# that run listeners, and the registry of listeners the extension calls by
|
|
5
|
+
# id.
|
|
6
|
+
#
|
|
7
|
+
# Licensed under MIT OR Apache-2.0, like the rest of rustorb-dds.
|
|
8
|
+
|
|
9
|
+
module DDS
|
|
10
|
+
module Native
|
|
11
|
+
@listeners = {}
|
|
12
|
+
@next_id = 0
|
|
13
|
+
@lock = Mutex.new
|
|
14
|
+
@dispatcher_lock = Mutex.new
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
# Starts a dispatcher thread (the extension asks for one more when
|
|
18
|
+
# every dispatcher is busy).
|
|
19
|
+
def spawn_dispatcher
|
|
20
|
+
t = Thread.new { dispatcher_loop }
|
|
21
|
+
t.name = "rustorb-dds-dispatcher" if t.respond_to?(:name=)
|
|
22
|
+
t.report_on_exception = true
|
|
23
|
+
t
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Starts dispatchers until n are running.
|
|
27
|
+
def ensure_dispatchers(n = 2)
|
|
28
|
+
@dispatcher_lock.synchronize do
|
|
29
|
+
return if dispatchers >= n
|
|
30
|
+
|
|
31
|
+
(n - dispatchers).times { spawn_dispatcher }
|
|
32
|
+
Thread.pass until dispatchers >= n
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Registers a listener for target, which gets its calls
|
|
37
|
+
# (target.deliver(event, endpoint, arg, listener)); returns its id.
|
|
38
|
+
def listener(target, listener)
|
|
39
|
+
ensure_dispatchers
|
|
40
|
+
@lock.synchronize do
|
|
41
|
+
@next_id += 1
|
|
42
|
+
@listeners[@next_id] = [target, listener]
|
|
43
|
+
@next_id
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def forget_listener(id)
|
|
48
|
+
@lock.synchronize { @listeners.delete(id) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Called by the extension, with the GVL, for each listener call:
|
|
52
|
+
# event is the name of the call (or :release), endpoint the GUID of
|
|
53
|
+
# the writer or reader the status is of (or the topic's name), arg
|
|
54
|
+
# the status as an Array (or a subscriber's handle).
|
|
55
|
+
def dispatch(id, event, endpoint, arg)
|
|
56
|
+
if event == :release
|
|
57
|
+
forget_listener(id)
|
|
58
|
+
return
|
|
59
|
+
end
|
|
60
|
+
target, listener = @lock.synchronize { @listeners[id] }
|
|
61
|
+
if target
|
|
62
|
+
target.deliver(event, endpoint, arg, listener)
|
|
63
|
+
elsif arg.is_a?(Handle)
|
|
64
|
+
release(arg)
|
|
65
|
+
end
|
|
66
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
67
|
+
warn "rustorb-dds: the listener's #{event} raised #{e.class}: #{e.message}"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# The target of the listener a writer or reader is made with: its calls
|
|
72
|
+
# wait until the writer or reader is there.
|
|
73
|
+
class Slot
|
|
74
|
+
def initialize
|
|
75
|
+
@lock = Mutex.new
|
|
76
|
+
@entity = nil
|
|
77
|
+
@pending = []
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def entity=(entity)
|
|
81
|
+
pending = @lock.synchronize do
|
|
82
|
+
@entity = entity
|
|
83
|
+
p = @pending
|
|
84
|
+
@pending = []
|
|
85
|
+
p
|
|
86
|
+
end
|
|
87
|
+
pending.each { |args| entity.deliver(*args) }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def deliver(*args)
|
|
91
|
+
entity = @lock.synchronize do
|
|
92
|
+
@pending << args unless @entity
|
|
93
|
+
@entity
|
|
94
|
+
end
|
|
95
|
+
entity&.deliver(*args)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Writers and readers by GUID, for the listeners of their participant,
|
|
100
|
+
# publisher, subscriber: a status of one not yet known waits (up to 10
|
|
101
|
+
# s) until it is.
|
|
102
|
+
class Endpoints
|
|
103
|
+
def initialize
|
|
104
|
+
@lock = Mutex.new
|
|
105
|
+
@by_guid = {}
|
|
106
|
+
@pending = {}
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def add(guid, entity)
|
|
110
|
+
pending = @lock.synchronize do
|
|
111
|
+
@by_guid[guid] = entity
|
|
112
|
+
@pending.delete(guid) || []
|
|
113
|
+
end
|
|
114
|
+
pending.each do |_, blk|
|
|
115
|
+
blk.call(entity)
|
|
116
|
+
rescue StandardError => e
|
|
117
|
+
warn "rustorb-dds: a listener raised #{e.class}: #{e.message}"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def remove(guid)
|
|
122
|
+
@lock.synchronize { @by_guid.delete(guid) }
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def deliver(guid, &blk)
|
|
126
|
+
entity = @lock.synchronize do
|
|
127
|
+
e = @by_guid[guid]
|
|
128
|
+
unless e
|
|
129
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
130
|
+
@pending.each_value { |q| q.reject! { |t, _| now - t > 10 } }
|
|
131
|
+
@pending.delete_if { |_, q| q.empty? }
|
|
132
|
+
(@pending[guid] ||= []) << [now, blk]
|
|
133
|
+
end
|
|
134
|
+
e
|
|
135
|
+
end
|
|
136
|
+
blk.call(entity) if entity
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# DDS::Pub::Publisher and DataWriter (dds::pub of the C++ PSM).
|
|
4
|
+
#
|
|
5
|
+
# Licensed under MIT OR Apache-2.0, like the rest of rustorb-dds.
|
|
6
|
+
|
|
7
|
+
module DDS
|
|
8
|
+
module Pub
|
|
9
|
+
# The listener of a writer.
|
|
10
|
+
module DataWriterListener
|
|
11
|
+
def on_offered_deadline_missed(writer, status); end
|
|
12
|
+
def on_offered_incompatible_qos(writer, status); end
|
|
13
|
+
def on_liveliness_lost(writer, status); end
|
|
14
|
+
def on_publication_matched(writer, status); end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# The listener of a publisher: the calls of its writers' listeners.
|
|
18
|
+
module PublisherListener
|
|
19
|
+
include DataWriterListener
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Makes writers, which close with it.
|
|
23
|
+
class Publisher < Core::Entity
|
|
24
|
+
attr_reader :participant, :qos
|
|
25
|
+
|
|
26
|
+
def initialize(participant, qos = nil, listener = nil, mask = Core::Status::StatusMask::ALL)
|
|
27
|
+
super()
|
|
28
|
+
@participant = participant
|
|
29
|
+
@qos = (qos || PublisherQos.new).dup.freeze
|
|
30
|
+
@handle = Native.create_publisher(participant.handle, @qos.partition.name)
|
|
31
|
+
@parent = participant
|
|
32
|
+
participant.adopt(self)
|
|
33
|
+
set_listener(listener, mask) if listener
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def default_datawriter_qos = DataWriterQos.new
|
|
37
|
+
|
|
38
|
+
def deliver(event, endpoint, arg, listener)
|
|
39
|
+
deliver_group(@participant, event, endpoint, arg, listener)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Waits until the writers' samples are acknowledged.
|
|
43
|
+
def wait_for_acknowledgments(timeout)
|
|
44
|
+
(@contained || []).each { |w| w.wait_for_acknowledgments(timeout) if w.is_a?(DataWriter) }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def inspect
|
|
48
|
+
"#<DDS::Pub::Publisher #{@qos.partition.name.inspect}>"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Writes the samples of a topic.
|
|
53
|
+
class DataWriter < Core::Entity
|
|
54
|
+
attr_reader :publisher, :topic, :qos
|
|
55
|
+
|
|
56
|
+
def initialize(publisher, topic, qos = nil, listener = nil, mask = Core::Status::StatusMask::ALL)
|
|
57
|
+
super()
|
|
58
|
+
@publisher = publisher
|
|
59
|
+
@topic = topic
|
|
60
|
+
@type = topic.type
|
|
61
|
+
@qos = (qos || DataWriterQos.new).dup.freeze
|
|
62
|
+
slot = listener ? Native::Slot.new : nil
|
|
63
|
+
id = slot ? Native.listener(slot, listener) : nil
|
|
64
|
+
begin
|
|
65
|
+
@handle = Native.create_writer(publisher.handle, topic.handle, @qos.to_native, id, mask)
|
|
66
|
+
rescue StandardError
|
|
67
|
+
Native.forget_listener(id) if id
|
|
68
|
+
raise
|
|
69
|
+
end
|
|
70
|
+
@listener = listener
|
|
71
|
+
@guid = Native.writer_guid(@handle)
|
|
72
|
+
@parent = publisher
|
|
73
|
+
publisher.adopt(self)
|
|
74
|
+
participant.endpoints.add(@guid, self)
|
|
75
|
+
slot.entity = self if slot
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def participant
|
|
79
|
+
@publisher.participant
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def instance_handle
|
|
83
|
+
Core::InstanceHandle.new(@guid)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Writes a sample (timestamp: a DDS::Core::Time, a ::Time, or nil for
|
|
87
|
+
# now).
|
|
88
|
+
def write(sample, timestamp = nil)
|
|
89
|
+
op(0, sample, timestamp)
|
|
90
|
+
self
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def <<(sample)
|
|
94
|
+
write(sample)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# The handle of the instance of the sample's key, registered.
|
|
98
|
+
def register_instance(sample)
|
|
99
|
+
Core::InstanceHandle.new(op(3, sample, nil))
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# The handle of the instance of the sample's key, or the nil handle.
|
|
103
|
+
def lookup_instance(sample)
|
|
104
|
+
Core::InstanceHandle.new(op(4, sample, nil))
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Unregisters the instance of the sample's key.
|
|
108
|
+
def unregister_instance(sample, timestamp = nil)
|
|
109
|
+
op(2, sample, timestamp)
|
|
110
|
+
self
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Disposes of the instance of the sample's key.
|
|
114
|
+
def dispose_instance(sample, timestamp = nil)
|
|
115
|
+
op(1, sample, timestamp)
|
|
116
|
+
self
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Waits until the samples written are acknowledged by the reliable
|
|
120
|
+
# readers (DDS::Core::TimeoutError after timeout).
|
|
121
|
+
def wait_for_acknowledgments(timeout)
|
|
122
|
+
check_open
|
|
123
|
+
Native.wait(@handle, 0, 0, Core::Duration.of(timeout).to_native)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Waits until count readers match (a rustorb-dds extension).
|
|
127
|
+
def wait_for_subscriptions(count = 1, timeout = Core::Duration.infinite)
|
|
128
|
+
check_open
|
|
129
|
+
Native.wait(@handle, 1, count, Core::Duration.of(timeout).to_native)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def matched_subscriptions
|
|
133
|
+
check_open
|
|
134
|
+
Native.matched(@handle).map { |g| Core::InstanceHandle.new(g) }
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def assert_liveliness
|
|
138
|
+
check_open
|
|
139
|
+
Native.assert_liveliness(@handle)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def publication_matched_status = status(:publication_matched, Core::Status::PublicationMatchedStatus)
|
|
143
|
+
def offered_incompatible_qos_status = status(:offered_incompatible_qos,
|
|
144
|
+
Core::Status::OfferedIncompatibleQosStatus)
|
|
145
|
+
def liveliness_lost_status = status(:liveliness_lost, Core::Status::LivelinessLostStatus)
|
|
146
|
+
def offered_deadline_missed_status = status(:offered_deadline_missed,
|
|
147
|
+
Core::Status::OfferedDeadlineMissedStatus)
|
|
148
|
+
|
|
149
|
+
def deliver(event, _endpoint, arg, listener)
|
|
150
|
+
deliver_own(event, arg, listener)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def close
|
|
154
|
+
participant.endpoints.remove(@guid) unless closed?
|
|
155
|
+
super
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def close_from_parent
|
|
159
|
+
participant.endpoints.remove(@guid) unless closed?
|
|
160
|
+
super
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def inspect
|
|
164
|
+
"#<DDS::Pub::DataWriter of #{@topic.name}>"
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
private
|
|
168
|
+
|
|
169
|
+
def status(name, cls)
|
|
170
|
+
check_open
|
|
171
|
+
cls.of(Native.status(@handle, name))
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def op(code, sample, timestamp)
|
|
175
|
+
check_open
|
|
176
|
+
out = Types.out(@type, sample)
|
|
177
|
+
Native.writer_op(@handle, code, out, timestamp.nil? ? nil : Core::Time.of(timestamp).to_native)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The QoS policies (dds::core::policy of the C++ PSM) and the QoS of the
|
|
4
|
+
# entities. A policy is a frozen value; a QoS holds one of each of its
|
|
5
|
+
# policies: start from the default (DDS::Pub::Publisher#default_datawriter_qos,
|
|
6
|
+
# DDS::Pub::DataWriterQos.new...) and set policies with <<.
|
|
7
|
+
#
|
|
8
|
+
# Licensed under MIT OR Apache-2.0, like the rest of rustorb-dds.
|
|
9
|
+
|
|
10
|
+
module DDS
|
|
11
|
+
module Core
|
|
12
|
+
module Policy
|
|
13
|
+
# Freezes a policy once it is made.
|
|
14
|
+
module Frozen
|
|
15
|
+
def initialize(*)
|
|
16
|
+
super
|
|
17
|
+
freeze
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# A Struct whose values cannot change.
|
|
22
|
+
def self.value(*members, &blk)
|
|
23
|
+
cls = ::Struct.new(*members)
|
|
24
|
+
cls.class_eval(&blk) if blk
|
|
25
|
+
cls.prepend(Frozen)
|
|
26
|
+
cls
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
module ReliabilityKind
|
|
30
|
+
BEST_EFFORT = 0
|
|
31
|
+
RELIABLE = 1
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Reliability = value(:kind, :max_blocking_time) do
|
|
35
|
+
def self.best_effort = new(ReliabilityKind::BEST_EFFORT, Duration.from_millisecs(100))
|
|
36
|
+
def self.reliable(max_blocking_time = Duration.from_millisecs(100))
|
|
37
|
+
new(ReliabilityKind::RELIABLE, Duration.of(max_blocking_time))
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
module HistoryKind
|
|
42
|
+
KEEP_LAST = 0
|
|
43
|
+
KEEP_ALL = 1
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
History = value(:kind, :depth) do
|
|
47
|
+
def self.keep_last(depth = 1) = new(HistoryKind::KEEP_LAST, depth)
|
|
48
|
+
def self.keep_all = new(HistoryKind::KEEP_ALL, 1)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
LENGTH_UNLIMITED = -1
|
|
52
|
+
|
|
53
|
+
ResourceLimits = value(:max_samples, :max_instances, :max_samples_per_instance) do
|
|
54
|
+
def self.unlimited = new(LENGTH_UNLIMITED, LENGTH_UNLIMITED, LENGTH_UNLIMITED)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
module DurabilityKind
|
|
58
|
+
VOLATILE = 0
|
|
59
|
+
TRANSIENT_LOCAL = 1
|
|
60
|
+
TRANSIENT = 2
|
|
61
|
+
PERSISTENT = 3
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
Durability = value(:kind) do
|
|
65
|
+
def self.volatile = new(DurabilityKind::VOLATILE)
|
|
66
|
+
def self.transient_local = new(DurabilityKind::TRANSIENT_LOCAL)
|
|
67
|
+
def self.transient = new(DurabilityKind::TRANSIENT)
|
|
68
|
+
def self.persistent = new(DurabilityKind::PERSISTENT)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
Deadline = value(:period)
|
|
72
|
+
|
|
73
|
+
module LivelinessKind
|
|
74
|
+
AUTOMATIC = 0
|
|
75
|
+
MANUAL_BY_PARTICIPANT = 1
|
|
76
|
+
MANUAL_BY_TOPIC = 2
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
Liveliness = value(:kind, :lease_duration) do
|
|
80
|
+
def self.automatic(lease = Duration.infinite) = new(LivelinessKind::AUTOMATIC, Duration.of(lease))
|
|
81
|
+
def self.manual_by_participant(lease = Duration.infinite)
|
|
82
|
+
new(LivelinessKind::MANUAL_BY_PARTICIPANT, Duration.of(lease))
|
|
83
|
+
end
|
|
84
|
+
def self.manual_by_topic(lease = Duration.infinite) = new(LivelinessKind::MANUAL_BY_TOPIC, Duration.of(lease))
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# The octets of USER_DATA, as a binary String.
|
|
88
|
+
UserData = value(:value) do
|
|
89
|
+
def initialize(value = "")
|
|
90
|
+
super(value.b.freeze)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
module DataRepresentationId
|
|
95
|
+
XCDR = 0
|
|
96
|
+
XML = 1
|
|
97
|
+
XCDR2 = 2
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
DataRepresentation = value(:value) do
|
|
101
|
+
def initialize(value = [])
|
|
102
|
+
super(Array(value).dup.freeze)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.xcdr = new([DataRepresentationId::XCDR])
|
|
106
|
+
def self.xcdr2 = new([DataRepresentationId::XCDR2])
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
WriterDataLifecycle = value(:autodispose_unregistered_instances) do
|
|
110
|
+
def self.auto_dispose_unregistered_instances = new(true)
|
|
111
|
+
def self.manually_dispose_unregistered_instances = new(false)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# DURABILITY_SERVICE of a TRANSIENT or PERSISTENT writer.
|
|
115
|
+
DurabilityService = value(:service_cleanup_delay, :history_kind, :history_depth, :max_samples, :max_instances,
|
|
116
|
+
:max_samples_per_instance)
|
|
117
|
+
|
|
118
|
+
module TypeConsistencyKind
|
|
119
|
+
DISALLOW_TYPE_COERCION = 0
|
|
120
|
+
ALLOW_TYPE_COERCION = 1
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
TypeConsistencyEnforcement = value(:kind, :ignore_sequence_bounds, :ignore_string_bounds,
|
|
124
|
+
:ignore_member_names, :prevent_type_widening, :force_type_validation)
|
|
125
|
+
|
|
126
|
+
# The partitions of a publisher or subscriber.
|
|
127
|
+
Partition = value(:name) do
|
|
128
|
+
def initialize(name = [])
|
|
129
|
+
super(Array(name).map { |n| n.to_s.dup.freeze }.freeze)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# The PROPERTY QoS (DDS Security 1.2, 7.2.5): names and values. The
|
|
134
|
+
# dds.sec.* properties turn on DDS Security.
|
|
135
|
+
Property = value(:value) do
|
|
136
|
+
def initialize(value = {})
|
|
137
|
+
super(value.to_h { |k, v| [k.to_s.dup.freeze, v.to_s.dup.freeze] }.freeze)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# A QoS: one of each of its policies (Class => policy).
|
|
143
|
+
class EntityQos
|
|
144
|
+
include Policy
|
|
145
|
+
|
|
146
|
+
def initialize(policies)
|
|
147
|
+
@policies = policies
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def self.policies(*names)
|
|
151
|
+
names.each do |cls, name|
|
|
152
|
+
define_method(name) { @policies.fetch(cls) }
|
|
153
|
+
define_method("#{name}=") { |v| self << v }
|
|
154
|
+
end
|
|
155
|
+
const_set(:POLICIES, names.map(&:first).freeze)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Sets a policy of this QoS; returns self.
|
|
159
|
+
def <<(policy)
|
|
160
|
+
unless self.class::POLICIES.include?(policy.class)
|
|
161
|
+
raise ArgumentError, "a #{self.class.name.split('::').last} has no #{policy.class.name.split('::').last}"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
@policies[policy.class] = policy
|
|
165
|
+
self
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def policy(cls)
|
|
169
|
+
@policies.fetch(cls)
|
|
170
|
+
end
|
|
171
|
+
alias [] policy
|
|
172
|
+
|
|
173
|
+
def initialize_copy(other)
|
|
174
|
+
super
|
|
175
|
+
@policies = other.instance_variable_get(:@policies).dup
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def ==(other)
|
|
179
|
+
other.class == self.class && other.instance_variable_get(:@policies) == @policies
|
|
180
|
+
end
|
|
181
|
+
alias eql? ==
|
|
182
|
+
|
|
183
|
+
def hash
|
|
184
|
+
@policies.hash
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def inspect
|
|
188
|
+
"#<#{self.class.name} #{@policies.values.map(&:inspect).join(', ')}>"
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# What the QoS of writers and readers share, from and to the C ABI's
|
|
193
|
+
# struct (as a Hash).
|
|
194
|
+
module EndpointQos
|
|
195
|
+
include Policy
|
|
196
|
+
|
|
197
|
+
def self.from_native(h)
|
|
198
|
+
d = ->(v) { Duration.new(*v) }
|
|
199
|
+
{
|
|
200
|
+
Reliability => Reliability.new(h[:reliability_kind], d.call(h[:max_blocking_time])),
|
|
201
|
+
History => History.new(h[:history_kind], h[:history_depth]),
|
|
202
|
+
ResourceLimits => ResourceLimits.new(h[:max_samples], h[:max_instances], h[:max_samples_per_instance]),
|
|
203
|
+
Durability => Durability.new(h[:durability_kind]),
|
|
204
|
+
Deadline => Deadline.new(d.call(h[:deadline_period])),
|
|
205
|
+
Liveliness => Liveliness.new(h[:liveliness_kind], d.call(h[:lease_duration])),
|
|
206
|
+
UserData => UserData.new(h[:user_data]),
|
|
207
|
+
DataRepresentation => DataRepresentation.new(h[:data_representation])
|
|
208
|
+
}
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def self.to_native(q)
|
|
212
|
+
r = q.reliability
|
|
213
|
+
hi = q.history
|
|
214
|
+
rl = q.resource_limits
|
|
215
|
+
lv = q.liveliness
|
|
216
|
+
{
|
|
217
|
+
reliability_kind: r.kind, max_blocking_time: Duration.of(r.max_blocking_time).to_native,
|
|
218
|
+
history_kind: hi.kind, history_depth: hi.depth,
|
|
219
|
+
max_samples: rl.max_samples, max_instances: rl.max_instances,
|
|
220
|
+
max_samples_per_instance: rl.max_samples_per_instance,
|
|
221
|
+
durability_kind: q.durability.kind,
|
|
222
|
+
deadline_period: Duration.of(q.deadline.period).to_native,
|
|
223
|
+
liveliness_kind: lv.kind, lease_duration: Duration.of(lv.lease_duration).to_native,
|
|
224
|
+
user_data: q.user_data.value, data_representation: q.data_representation.value
|
|
225
|
+
}
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
module Pub
|
|
231
|
+
# The QoS of a writer (rustorb-dds's default to start from).
|
|
232
|
+
class DataWriterQos < Core::EntityQos
|
|
233
|
+
include Core::Policy
|
|
234
|
+
|
|
235
|
+
policies [Reliability, :reliability], [History, :history], [ResourceLimits, :resource_limits],
|
|
236
|
+
[Durability, :durability], [Deadline, :deadline], [Liveliness, :liveliness],
|
|
237
|
+
[UserData, :user_data], [DataRepresentation, :data_representation],
|
|
238
|
+
[WriterDataLifecycle, :writer_data_lifecycle], [DurabilityService, :durability_service]
|
|
239
|
+
|
|
240
|
+
def initialize
|
|
241
|
+
h = Native.writer_qos_default
|
|
242
|
+
p = Core::EndpointQos.from_native(h)
|
|
243
|
+
p[WriterDataLifecycle] = WriterDataLifecycle.new(h[:autodispose_unregistered_instances])
|
|
244
|
+
p[DurabilityService] = DurabilityService.new(
|
|
245
|
+
Core::Duration.new(*h[:service_cleanup_delay]), h[:service_history_kind], h[:service_history_depth],
|
|
246
|
+
h[:service_max_samples], h[:service_max_instances], h[:service_max_samples_per_instance]
|
|
247
|
+
)
|
|
248
|
+
super(p)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def to_native
|
|
252
|
+
ds = durability_service
|
|
253
|
+
Core::EndpointQos.to_native(self).merge(
|
|
254
|
+
autodispose_unregistered_instances: writer_data_lifecycle.autodispose_unregistered_instances ? true : false,
|
|
255
|
+
service_cleanup_delay: Core::Duration.of(ds.service_cleanup_delay).to_native,
|
|
256
|
+
service_history_kind: ds.history_kind, service_history_depth: ds.history_depth,
|
|
257
|
+
service_max_samples: ds.max_samples, service_max_instances: ds.max_instances,
|
|
258
|
+
service_max_samples_per_instance: ds.max_samples_per_instance
|
|
259
|
+
)
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# The QoS of a publisher: its partitions.
|
|
264
|
+
class PublisherQos < Core::EntityQos
|
|
265
|
+
include Core::Policy
|
|
266
|
+
|
|
267
|
+
policies [Partition, :partition]
|
|
268
|
+
|
|
269
|
+
def initialize
|
|
270
|
+
super({ Partition => Partition.new })
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
module Sub
|
|
276
|
+
# The QoS of a reader (rustorb-dds's default to start from).
|
|
277
|
+
class DataReaderQos < Core::EntityQos
|
|
278
|
+
include Core::Policy
|
|
279
|
+
|
|
280
|
+
policies [Reliability, :reliability], [History, :history], [ResourceLimits, :resource_limits],
|
|
281
|
+
[Durability, :durability], [Deadline, :deadline], [Liveliness, :liveliness],
|
|
282
|
+
[UserData, :user_data], [DataRepresentation, :data_representation],
|
|
283
|
+
[TypeConsistencyEnforcement, :type_consistency]
|
|
284
|
+
|
|
285
|
+
def initialize
|
|
286
|
+
h = Native.reader_qos_default
|
|
287
|
+
p = Core::EndpointQos.from_native(h)
|
|
288
|
+
p[TypeConsistencyEnforcement] = TypeConsistencyEnforcement.new(
|
|
289
|
+
h[:type_consistency_kind], h[:ignore_sequence_bounds], h[:ignore_string_bounds], h[:ignore_member_names],
|
|
290
|
+
h[:prevent_type_widening], h[:force_type_validation]
|
|
291
|
+
)
|
|
292
|
+
super(p)
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def to_native
|
|
296
|
+
t = type_consistency
|
|
297
|
+
Core::EndpointQos.to_native(self).merge(
|
|
298
|
+
type_consistency_kind: t.kind, ignore_sequence_bounds: t.ignore_sequence_bounds ? true : false,
|
|
299
|
+
ignore_string_bounds: t.ignore_string_bounds ? true : false,
|
|
300
|
+
ignore_member_names: t.ignore_member_names ? true : false,
|
|
301
|
+
prevent_type_widening: t.prevent_type_widening ? true : false,
|
|
302
|
+
force_type_validation: t.force_type_validation ? true : false
|
|
303
|
+
)
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# The QoS of a subscriber: its partitions.
|
|
308
|
+
class SubscriberQos < Core::EntityQos
|
|
309
|
+
include Core::Policy
|
|
310
|
+
|
|
311
|
+
policies [Partition, :partition]
|
|
312
|
+
|
|
313
|
+
def initialize
|
|
314
|
+
super({ Partition => Partition.new })
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
module Domain
|
|
320
|
+
# The QoS of a participant: USER_DATA and PROPERTY.
|
|
321
|
+
class DomainParticipantQos < Core::EntityQos
|
|
322
|
+
include Core::Policy
|
|
323
|
+
|
|
324
|
+
policies [UserData, :user_data], [Property, :property]
|
|
325
|
+
|
|
326
|
+
def initialize
|
|
327
|
+
super({ UserData => UserData.new, Property => Property.new })
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
module Topic
|
|
333
|
+
# The QoS of a topic: rustorb-dds takes none (the writers' and
|
|
334
|
+
# readers' QoS are their own).
|
|
335
|
+
class TopicQos < Core::EntityQos
|
|
336
|
+
policies
|
|
337
|
+
|
|
338
|
+
def initialize
|
|
339
|
+
super({})
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
end
|