rustorb 0.7.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 +42 -0
- data/ext/rustorb_ext/extconf.rb +33 -0
- data/ext/rustorb_ext/rustorb_ext.c +3805 -0
- data/lib/CosNamingC.rb +275 -0
- data/lib/CosNamingS.rb +74 -0
- data/lib/corba.rb +4 -0
- data/lib/rustorb/dii.rb +337 -0
- data/lib/rustorb/dynamic_any.rb +285 -0
- data/lib/rustorb/exceptions.rb +112 -0
- data/lib/rustorb/marshal.rb +405 -0
- data/lib/rustorb/messaging.rb +207 -0
- data/lib/rustorb/object.rb +278 -0
- data/lib/rustorb/orb.rb +152 -0
- data/lib/rustorb/pi.rb +526 -0
- data/lib/rustorb/portable_server.rb +453 -0
- data/lib/rustorb/servant_managers.rb +172 -0
- data/lib/rustorb/typecode.rb +448 -0
- data/lib/rustorb/types.rb +324 -0
- data/lib/rustorb/values.rb +389 -0
- data/lib/rustorb/version.rb +5 -0
- data/lib/rustorb.rb +30 -0
- data/vendor/include/rustorb/rustorb.h +1429 -0
- data/vendor/linux-aarch64/librustorb_ffi.a +4 -0
- data/vendor/linux-x86_64/librustorb_ffi.a +4 -0
- data/vendor/macos-aarch64/librustorb_ffi.a +0 -0
- metadata +84 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# PortableServer: the POA, its POAManager, the policies, Current and the
|
|
4
|
+
# servant base class. Object ids are binary Strings.
|
|
5
|
+
#
|
|
6
|
+
# Requests reach Ruby servants on a pool of Ruby threads (the
|
|
7
|
+
# dispatchers), which grows by one whenever every dispatcher is busy.
|
|
8
|
+
#
|
|
9
|
+
# Licensed under MIT OR Apache-2.0, like the rest of the rustorb core.
|
|
10
|
+
|
|
11
|
+
module Rustorb
|
|
12
|
+
module Native
|
|
13
|
+
def self.spawn_dispatcher
|
|
14
|
+
t = Thread.new { Native.dispatcher_loop }
|
|
15
|
+
t.name = "rustorb-dispatcher" if t.respond_to?(:name=)
|
|
16
|
+
t.report_on_exception = true
|
|
17
|
+
t
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module PortableServer
|
|
23
|
+
@dispatch_lock = Mutex.new
|
|
24
|
+
|
|
25
|
+
# Starts dispatchers until n are running.
|
|
26
|
+
def self.ensure_dispatchers(n = 2)
|
|
27
|
+
@dispatch_lock.synchronize do
|
|
28
|
+
return if Rustorb::Native.dispatchers >= n
|
|
29
|
+
|
|
30
|
+
(n - Rustorb::Native.dispatchers).times { Rustorb::Native.spawn_dispatcher }
|
|
31
|
+
Thread.pass until Rustorb::Native.dispatchers >= n
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# --- policies ---
|
|
36
|
+
|
|
37
|
+
THREAD_POLICY_ID = 16
|
|
38
|
+
LIFESPAN_POLICY_ID = 17
|
|
39
|
+
ID_UNIQUENESS_POLICY_ID = 18
|
|
40
|
+
ID_ASSIGNMENT_POLICY_ID = 19
|
|
41
|
+
IMPLICIT_ACTIVATION_POLICY_ID = 20
|
|
42
|
+
SERVANT_RETENTION_POLICY_ID = 21
|
|
43
|
+
REQUEST_PROCESSING_POLICY_ID = 22
|
|
44
|
+
|
|
45
|
+
ORB_CTRL_MODEL = 0
|
|
46
|
+
SINGLE_THREAD_MODEL = 1
|
|
47
|
+
MAIN_THREAD_MODEL = 2
|
|
48
|
+
TRANSIENT = 0
|
|
49
|
+
PERSISTENT = 1
|
|
50
|
+
UNIQUE_ID = 0
|
|
51
|
+
MULTIPLE_ID = 1
|
|
52
|
+
USER_ID = 0
|
|
53
|
+
SYSTEM_ID = 1
|
|
54
|
+
IMPLICIT_ACTIVATION = 0
|
|
55
|
+
NO_IMPLICIT_ACTIVATION = 1
|
|
56
|
+
RETAIN = 0
|
|
57
|
+
NON_RETAIN = 1
|
|
58
|
+
USE_ACTIVE_OBJECT_MAP_ONLY = 0
|
|
59
|
+
USE_DEFAULT_SERVANT = 1
|
|
60
|
+
USE_SERVANT_MANAGER = 2
|
|
61
|
+
|
|
62
|
+
# A POA policy: its type and value (a local object).
|
|
63
|
+
class Policy
|
|
64
|
+
attr_reader :policy_type, :value
|
|
65
|
+
|
|
66
|
+
def initialize(policy_type, value)
|
|
67
|
+
@policy_type = policy_type
|
|
68
|
+
@value = value
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def copy
|
|
72
|
+
self.class.new(@policy_type, @value)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def destroy; end
|
|
76
|
+
|
|
77
|
+
def ==(other)
|
|
78
|
+
other.is_a?(Policy) && other.policy_type == @policy_type && other.value == @value
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class ThreadPolicy < Policy; end
|
|
83
|
+
class LifespanPolicy < Policy; end
|
|
84
|
+
class IdUniquenessPolicy < Policy; end
|
|
85
|
+
class IdAssignmentPolicy < Policy; end
|
|
86
|
+
class ImplicitActivationPolicy < Policy; end
|
|
87
|
+
class ServantRetentionPolicy < Policy; end
|
|
88
|
+
class RequestProcessingPolicy < Policy; end
|
|
89
|
+
|
|
90
|
+
POLICY_CLASSES = [ThreadPolicy, LifespanPolicy, IdUniquenessPolicy, IdAssignmentPolicy,
|
|
91
|
+
ImplicitActivationPolicy, ServantRetentionPolicy, RequestProcessingPolicy].freeze
|
|
92
|
+
|
|
93
|
+
# --- exceptions of the POA, the POAManager and Current ---
|
|
94
|
+
|
|
95
|
+
def self.local_exception(container, name, code, members = [])
|
|
96
|
+
klass = Class.new(CORBA::UserException)
|
|
97
|
+
container.const_set(name, klass)
|
|
98
|
+
klass.const_set(:ID, "IDL:omg.org/#{container.name.gsub('::', '/')}/#{name}:1.0")
|
|
99
|
+
klass.const_set(:MEMBERS, members.freeze)
|
|
100
|
+
members.each { |m| klass.attr_accessor(m) }
|
|
101
|
+
Rustorb::Native::LOCAL_EXCEPTIONS[code] = members.empty? ? ->(_) { klass.new } : ->(i) { klass.new(i) }
|
|
102
|
+
klass
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
class POA
|
|
106
|
+
PortableServer.local_exception(self, :AdapterAlreadyExists, 1)
|
|
107
|
+
PortableServer.local_exception(self, :AdapterNonExistent, 2)
|
|
108
|
+
PortableServer.local_exception(self, :InvalidPolicy, 3, %w[index])
|
|
109
|
+
PortableServer.local_exception(self, :ServantAlreadyActive, 4)
|
|
110
|
+
PortableServer.local_exception(self, :ObjectAlreadyActive, 5)
|
|
111
|
+
PortableServer.local_exception(self, :ServantNotActive, 6)
|
|
112
|
+
PortableServer.local_exception(self, :ObjectNotActive, 7)
|
|
113
|
+
PortableServer.local_exception(self, :WrongPolicy, 8)
|
|
114
|
+
PortableServer.local_exception(self, :WrongAdapter, 9)
|
|
115
|
+
PortableServer.local_exception(self, :NoServant, 11)
|
|
116
|
+
|
|
117
|
+
def self._wrap(native)
|
|
118
|
+
native && new(native)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def self._narrow(obj)
|
|
122
|
+
return obj if obj.nil? || obj.is_a?(POA)
|
|
123
|
+
|
|
124
|
+
raise CORBA::BAD_PARAM.new("not a PortableServer::POA")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def initialize(native)
|
|
128
|
+
@native = native
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def _native
|
|
132
|
+
@native
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def the_name
|
|
136
|
+
@native.name
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def the_parent
|
|
140
|
+
POA._wrap(@native.parent)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def the_children
|
|
144
|
+
@native.children.map { |c| POA.new(c) }
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def the_POAManager
|
|
148
|
+
POAManager.new(@native.manager)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# The seven policies of the POA.
|
|
152
|
+
def the_policies
|
|
153
|
+
@native.policies.each_with_index.map do |v, i|
|
|
154
|
+
POLICY_CLASSES[i].new(THREAD_POLICY_ID + i, v)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def create_POA(name, manager, policies)
|
|
159
|
+
list = policies.map do |p|
|
|
160
|
+
raise CORBA::BAD_PARAM.new("#{p.inspect} is not a policy") unless p.respond_to?(:policy_type)
|
|
161
|
+
|
|
162
|
+
[p.policy_type, p.value]
|
|
163
|
+
end
|
|
164
|
+
POA.new(@native.create_poa(name, manager&._native, list))
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def find_POA(name, activate_it)
|
|
168
|
+
POA.new(@native.find_poa(name, activate_it))
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def destroy(etherealize_objects, wait_for_completion)
|
|
172
|
+
@native.destroy(etherealize_objects, wait_for_completion)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
{ create_thread_policy: [ThreadPolicy, THREAD_POLICY_ID],
|
|
176
|
+
create_lifespan_policy: [LifespanPolicy, LIFESPAN_POLICY_ID],
|
|
177
|
+
create_id_uniqueness_policy: [IdUniquenessPolicy, ID_UNIQUENESS_POLICY_ID],
|
|
178
|
+
create_id_assignment_policy: [IdAssignmentPolicy, ID_ASSIGNMENT_POLICY_ID],
|
|
179
|
+
create_implicit_activation_policy: [ImplicitActivationPolicy, IMPLICIT_ACTIVATION_POLICY_ID],
|
|
180
|
+
create_servant_retention_policy: [ServantRetentionPolicy, SERVANT_RETENTION_POLICY_ID],
|
|
181
|
+
create_request_processing_policy: [RequestProcessingPolicy, REQUEST_PROCESSING_POLICY_ID] }
|
|
182
|
+
.each do |m, (klass, type)|
|
|
183
|
+
define_method(m) { |value| klass.new(type, value) }
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def activate_object(servant)
|
|
187
|
+
@native.activate_object(servant._servant_ref)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def activate_object_with_id(oid, servant)
|
|
191
|
+
@native.activate_object_with_id(oid, servant._servant_ref)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def deactivate_object(oid)
|
|
195
|
+
@native.deactivate_object(oid)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def servant_to_id(servant)
|
|
199
|
+
@native.servant_to_id(servant._servant_ref)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def servant_to_reference(servant)
|
|
203
|
+
servant._narrow_ref(@native.servant_to_reference(servant._servant_ref))
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def id_to_servant(oid)
|
|
207
|
+
@native.id_to_servant(oid)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def id_to_reference(oid)
|
|
211
|
+
CORBA::Object._from_ref(@native.id_to_reference(oid))
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def reference_to_id(obj)
|
|
215
|
+
@native.reference_to_id(obj._native_ref)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def reference_to_servant(obj)
|
|
219
|
+
@native.reference_to_servant(obj._native_ref)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def create_reference(intf)
|
|
223
|
+
ref_for(intf, @native.create_reference(intf))
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def create_reference_with_id(oid, intf)
|
|
227
|
+
ref_for(intf, @native.create_reference_with_id(oid, intf))
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def get_servant
|
|
231
|
+
@native.get_servant
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def set_servant(servant)
|
|
235
|
+
@native.set_servant(servant._servant_ref)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def ==(other)
|
|
239
|
+
other.is_a?(POA) && other.the_name == the_name && other.the_POAManager == the_POAManager
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
private
|
|
243
|
+
|
|
244
|
+
def ref_for(intf, ref)
|
|
245
|
+
mod = Rustorb.find_interface(intf)
|
|
246
|
+
mod ? mod::Stub._from_ref(ref) : CORBA::Object._from_ref(ref)
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
class POAManager
|
|
251
|
+
HOLDING = 0
|
|
252
|
+
ACTIVE = 1
|
|
253
|
+
DISCARDING = 2
|
|
254
|
+
INACTIVE = 3
|
|
255
|
+
|
|
256
|
+
PortableServer.local_exception(self, :AdapterInactive, 10)
|
|
257
|
+
|
|
258
|
+
def initialize(native)
|
|
259
|
+
@native = native
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def _native
|
|
263
|
+
@native
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def activate
|
|
267
|
+
@native.activate
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def hold_requests(wait_for_completion)
|
|
271
|
+
@native.hold_requests(wait_for_completion)
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def discard_requests(wait_for_completion)
|
|
275
|
+
@native.discard_requests(wait_for_completion)
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def deactivate(etherealize_objects, wait_for_completion)
|
|
279
|
+
@native.deactivate(etherealize_objects, wait_for_completion)
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def get_state
|
|
283
|
+
@native.state
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def get_id
|
|
287
|
+
@native.id
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def ==(other)
|
|
291
|
+
other.is_a?(POAManager) && @native.equal(other._native)
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# PortableServer::Current: the POA and object of the request this thread
|
|
296
|
+
# is serving.
|
|
297
|
+
class Current
|
|
298
|
+
PortableServer.local_exception(self, :NoContext, 12)
|
|
299
|
+
|
|
300
|
+
def self.instance
|
|
301
|
+
@instance ||= new
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
def get_POA
|
|
305
|
+
POA.new(Rustorb::Native.current_poa)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def get_object_id
|
|
309
|
+
Rustorb::Native.current_object_id
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def get_reference
|
|
313
|
+
CORBA::Object._from_ref(Rustorb::Native.current_reference)
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
def get_servant
|
|
317
|
+
Rustorb::Native.current_servant
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# The base of every servant. A generated skeleton class (POA::Mod::Iface)
|
|
322
|
+
# sets IDS (its repository ids, its own first) and OPERATIONS (wire name
|
|
323
|
+
# => [method name, Rustorb::Operation], inherited ones included).
|
|
324
|
+
class Servant
|
|
325
|
+
IDS = [].freeze
|
|
326
|
+
OPERATIONS = {}.freeze
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
# What a servant is made of, for Servant and the valuetypes that support
|
|
330
|
+
# an interface (an instance is activated like a servant). The class has
|
|
331
|
+
# IDS and _operations.
|
|
332
|
+
module ServantMethods
|
|
333
|
+
def _default_POA
|
|
334
|
+
PortableServer::POA.new(Rustorb::Native.default_root_poa)
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# The reference of the servant, activating it in its default POA if it
|
|
338
|
+
# is not active there (implicit activation).
|
|
339
|
+
def _this
|
|
340
|
+
# Inside a request on this servant: the reference it was called on.
|
|
341
|
+
current = @__rustorb_servant_ref&.current_reference
|
|
342
|
+
return _narrow_ref(current) if current
|
|
343
|
+
|
|
344
|
+
_default_POA.servant_to_reference(self)
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
def _is_a?(id)
|
|
348
|
+
self.class::IDS.include?(id) || id == "IDL:omg.org/CORBA/Object:1.0"
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
def _repository_id
|
|
352
|
+
self.class::IDS.first
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
def _non_existent
|
|
356
|
+
false
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# --- what the POA and the generated code use ---
|
|
360
|
+
|
|
361
|
+
def _servant_ref
|
|
362
|
+
PortableServer.ensure_dispatchers
|
|
363
|
+
@__rustorb_servant_ref ||= Rustorb::Native.servant_ref(self, self.class::IDS)
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
def _narrow_ref(ref)
|
|
367
|
+
mod = Rustorb.find_interface(self.class::IDS.first)
|
|
368
|
+
mod ? mod::Stub._from_ref(ref) : CORBA::Object._from_ref(ref)
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
BAD_OPERATION_MINOR = 0x4f4d0002
|
|
372
|
+
|
|
373
|
+
# Called (on a dispatcher) for each request: reads the arguments, calls
|
|
374
|
+
# the method and writes the reply. Returns true when the reply is a
|
|
375
|
+
# result or a user exception, false when it is a system exception.
|
|
376
|
+
def _rustorb_dispatch(op_name, inp, reply)
|
|
377
|
+
entry = self.class._operations[op_name]
|
|
378
|
+
unless entry
|
|
379
|
+
return _system_reply(reply, CORBA::BAD_OPERATION.new("", BAD_OPERATION_MINOR, CORBA::COMPLETED_NO))
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
meth, op = entry
|
|
383
|
+
begin
|
|
384
|
+
args = op.in_params.map { |p| Rustorb::Marshal.read(inp, p[1]) }
|
|
385
|
+
raise CORBA::MARSHAL.new("bad arguments of #{op_name}", 0, CORBA::COMPLETED_NO) if inp.failed?
|
|
386
|
+
rescue CORBA::SystemException => e
|
|
387
|
+
return _system_reply(reply, e)
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
begin
|
|
391
|
+
unless respond_to?(meth)
|
|
392
|
+
raise CORBA::NO_IMPLEMENT.new("#{self.class}##{meth}", 0, CORBA::COMPLETED_NO)
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
r = public_send(meth, *args)
|
|
396
|
+
rescue CORBA::UserException => e
|
|
397
|
+
return _user_reply(reply, op, e)
|
|
398
|
+
rescue CORBA::SystemException => e
|
|
399
|
+
return _system_reply(reply, e)
|
|
400
|
+
rescue StandardError, ScriptError => e
|
|
401
|
+
warn "rustorb: #{self.class}##{meth} raised #{e.class}: #{e.message}" if $VERBOSE
|
|
402
|
+
return _system_reply(reply, CORBA::UNKNOWN.new(e.message, 0, CORBA::COMPLETED_MAYBE))
|
|
403
|
+
end
|
|
404
|
+
return true if op.oneway
|
|
405
|
+
|
|
406
|
+
begin
|
|
407
|
+
out = reply.output
|
|
408
|
+
n = (op.result ? 1 : 0) + op.out_params.size
|
|
409
|
+
values = n > 1 ? Array(r) : [r]
|
|
410
|
+
if n > 1 && values.size != n
|
|
411
|
+
raise CORBA::BAD_PARAM.new("#{self.class}##{meth} must return #{n} values", 0,
|
|
412
|
+
CORBA::COMPLETED_YES)
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
i = 0
|
|
416
|
+
if op.result
|
|
417
|
+
Rustorb::Marshal.write(out, op.result, values[0])
|
|
418
|
+
i = 1
|
|
419
|
+
end
|
|
420
|
+
op.out_params.each_with_index { |p, k| Rustorb::Marshal.write(out, p[1], values[i + k]) }
|
|
421
|
+
true
|
|
422
|
+
rescue CORBA::SystemException => e
|
|
423
|
+
_system_reply(reply, e.class.new("", e.minor, CORBA::COMPLETED_YES))
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
private
|
|
428
|
+
|
|
429
|
+
def _user_reply(reply, op, exc)
|
|
430
|
+
klass = op.find_exception(exc._id)
|
|
431
|
+
unless klass
|
|
432
|
+
return _system_reply(reply, CORBA::UNKNOWN.new("undeclared #{exc._id}", 0, CORBA::COMPLETED_MAYBE))
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
begin
|
|
436
|
+
out = reply.user_exception(exc._id)
|
|
437
|
+
Rustorb::Marshal.write(out, klass._tc, exc)
|
|
438
|
+
true
|
|
439
|
+
rescue CORBA::SystemException => e
|
|
440
|
+
_system_reply(reply, e.class.new("", e.minor, CORBA::COMPLETED_YES))
|
|
441
|
+
end
|
|
442
|
+
end
|
|
443
|
+
|
|
444
|
+
def _system_reply(reply, exc)
|
|
445
|
+
reply.system_exception(exc._id, exc.minor, exc.completed)
|
|
446
|
+
false
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
class Servant
|
|
451
|
+
include ServantMethods
|
|
452
|
+
end
|
|
453
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Servant managers (PortableServer::ServantActivator, ServantLocator) and
|
|
4
|
+
# adapter activators (PortableServer::AdapterActivator): local objects the
|
|
5
|
+
# application derives from, which the POA calls on its upcall threads
|
|
6
|
+
# (through the rustorb_ext callbacks, with the GVL).
|
|
7
|
+
#
|
|
8
|
+
# Licensed under MIT OR Apache-2.0, like the rest of the rustorb core.
|
|
9
|
+
|
|
10
|
+
module PortableServer
|
|
11
|
+
# Raised by incarnate or preinvoke to send the client to another object.
|
|
12
|
+
class ForwardRequest < CORBA::UserException
|
|
13
|
+
ID = "IDL:omg.org/PortableServer/ForwardRequest:1.0"
|
|
14
|
+
MEMBERS = %w[forward_reference].freeze
|
|
15
|
+
attr_accessor :forward_reference
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# What the C side makes of a servant manager's answer.
|
|
19
|
+
module ManagerOutcome
|
|
20
|
+
module_function
|
|
21
|
+
|
|
22
|
+
def servant(s, key = nil)
|
|
23
|
+
unless s.is_a?(ServantMethods)
|
|
24
|
+
return [:system, CORBA::OBJ_ADAPTER::ID, 0, CORBA::COMPLETED_NO] if s.nil?
|
|
25
|
+
|
|
26
|
+
return [:system, CORBA::BAD_PARAM::ID, 0, CORBA::COMPLETED_NO]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
PortableServer.ensure_dispatchers
|
|
30
|
+
ids = s.respond_to?(:_ids) ? s._ids : s.class::IDS
|
|
31
|
+
[:servant, s, ids, key || 0]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def raised(e)
|
|
35
|
+
case e
|
|
36
|
+
when ForwardRequest
|
|
37
|
+
ref = e.forward_reference
|
|
38
|
+
return [:system, CORBA::BAD_PARAM::ID, 0, CORBA::COMPLETED_NO] unless ref.is_a?(CORBA::Object)
|
|
39
|
+
|
|
40
|
+
[:forward, ref._native_ref]
|
|
41
|
+
when CORBA::SystemException then [:system, e._id, e.minor, e.completed]
|
|
42
|
+
else
|
|
43
|
+
warn "rustorb: servant manager raised #{e.class}: #{e.message}" if $VERBOSE
|
|
44
|
+
[:system, CORBA::UNKNOWN::ID, 0, CORBA::COMPLETED_MAYBE]
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# The base of ServantActivator and ServantLocator.
|
|
50
|
+
class ServantManager
|
|
51
|
+
def _is_a?(id) = self.class.ancestors.any? { |k| k.const_defined?(:ID, false) && k::ID == id }
|
|
52
|
+
alias _is_a _is_a?
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# incarnate(oid, adapter) returns the servant of the object (or raises
|
|
56
|
+
# ForwardRequest or a system exception); etherealize(oid, adapter,
|
|
57
|
+
# servant, cleanup_in_progress, remaining_activations) is told when the
|
|
58
|
+
# POA lets it go. For a POA with USE_SERVANT_MANAGER and RETAIN.
|
|
59
|
+
class ServantActivator < ServantManager
|
|
60
|
+
ID = "IDL:omg.org/PortableServer/ServantActivator:1.0"
|
|
61
|
+
|
|
62
|
+
def incarnate(_oid, _adapter)
|
|
63
|
+
raise CORBA::NO_IMPLEMENT.new("#{self.class}#incarnate", 0, CORBA::COMPLETED_NO)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def etherealize(_oid, _adapter, _servant, _cleanup_in_progress, _remaining_activations); end
|
|
67
|
+
|
|
68
|
+
def _rustorb_incarnate(oid, poa)
|
|
69
|
+
ManagerOutcome.servant(incarnate(oid, POA._wrap(poa)))
|
|
70
|
+
rescue ::Exception => e # rubocop:disable Lint/RescueException - every failure is an answer
|
|
71
|
+
raise if e.is_a?(SystemExit) || e.is_a?(Interrupt)
|
|
72
|
+
|
|
73
|
+
ManagerOutcome.raised(e)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def _rustorb_etherealize(oid, poa, servant, cleanup, remaining)
|
|
77
|
+
etherealize(oid, POA._wrap(poa), servant, cleanup, remaining)
|
|
78
|
+
rescue StandardError => e
|
|
79
|
+
warn "rustorb: etherealize raised #{e.class}: #{e.message}" if $VERBOSE
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# preinvoke(oid, adapter, operation) returns the servant of this request
|
|
84
|
+
# and a cookie ([servant, cookie], or the servant alone for a nil
|
|
85
|
+
# cookie), or raises ForwardRequest or a system exception;
|
|
86
|
+
# postinvoke(oid, adapter, operation, cookie, servant) follows the
|
|
87
|
+
# request. For a POA with USE_SERVANT_MANAGER and NON_RETAIN.
|
|
88
|
+
class ServantLocator < ServantManager
|
|
89
|
+
ID = "IDL:omg.org/PortableServer/ServantLocator:1.0"
|
|
90
|
+
|
|
91
|
+
def preinvoke(_oid, _adapter, _operation)
|
|
92
|
+
raise CORBA::NO_IMPLEMENT.new("#{self.class}#preinvoke", 0, CORBA::COMPLETED_NO)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def postinvoke(_oid, _adapter, _operation, _cookie, _servant); end
|
|
96
|
+
|
|
97
|
+
def _rustorb_preinvoke(oid, poa, operation)
|
|
98
|
+
r = preinvoke(oid, POA._wrap(poa), operation)
|
|
99
|
+
servant, cookie = r.is_a?(Array) ? r : [r, nil]
|
|
100
|
+
key = 0
|
|
101
|
+
unless cookie.nil?
|
|
102
|
+
@__rustorb_cookie_lock ||= Mutex.new
|
|
103
|
+
@__rustorb_cookie_lock.synchronize do
|
|
104
|
+
@__rustorb_cookies ||= {}
|
|
105
|
+
@__rustorb_cookie_next = (@__rustorb_cookie_next || 0) + 1
|
|
106
|
+
key = @__rustorb_cookie_next
|
|
107
|
+
@__rustorb_cookies[key] = cookie
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
ManagerOutcome.servant(servant, key)
|
|
111
|
+
rescue ::Exception => e # rubocop:disable Lint/RescueException - every failure is an answer
|
|
112
|
+
raise if e.is_a?(SystemExit) || e.is_a?(Interrupt)
|
|
113
|
+
|
|
114
|
+
ManagerOutcome.raised(e)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def _rustorb_postinvoke(oid, poa, operation, key, servant)
|
|
118
|
+
cookie = nil
|
|
119
|
+
if key != 0
|
|
120
|
+
@__rustorb_cookie_lock.synchronize { cookie = @__rustorb_cookies.delete(key) }
|
|
121
|
+
end
|
|
122
|
+
postinvoke(oid, POA._wrap(poa), operation, cookie, servant)
|
|
123
|
+
rescue StandardError => e
|
|
124
|
+
warn "rustorb: postinvoke raised #{e.class}: #{e.message}" if $VERBOSE
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# unknown_adapter(parent, name) creates the POA name under parent and
|
|
129
|
+
# returns true, or returns false.
|
|
130
|
+
class AdapterActivator
|
|
131
|
+
ID = "IDL:omg.org/PortableServer/AdapterActivator:1.0"
|
|
132
|
+
|
|
133
|
+
def _is_a?(id) = id == ID
|
|
134
|
+
alias _is_a _is_a?
|
|
135
|
+
|
|
136
|
+
def unknown_adapter(_parent, _name) = false
|
|
137
|
+
|
|
138
|
+
def _rustorb_unknown_adapter(parent, name)
|
|
139
|
+
unknown_adapter(POA._wrap(parent), name) ? true : false
|
|
140
|
+
rescue StandardError => e
|
|
141
|
+
warn "rustorb: unknown_adapter raised #{e.class}: #{e.message}" if $VERBOSE
|
|
142
|
+
false
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
class POA
|
|
147
|
+
# A ServantActivator (RETAIN) or ServantLocator (NON_RETAIN).
|
|
148
|
+
def set_servant_manager(manager)
|
|
149
|
+
PortableServer.ensure_dispatchers
|
|
150
|
+
case manager
|
|
151
|
+
when ServantActivator then @native.set_servant_activator(manager)
|
|
152
|
+
when ServantLocator then @native.set_servant_locator(manager)
|
|
153
|
+
else raise CORBA::BAD_PARAM.new("not a ServantActivator or ServantLocator", 0, CORBA::COMPLETED_NO)
|
|
154
|
+
end
|
|
155
|
+
nil
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def get_servant_manager = @native.get_servant_manager
|
|
159
|
+
|
|
160
|
+
def the_activator = @native.the_activator
|
|
161
|
+
|
|
162
|
+
def the_activator=(activator)
|
|
163
|
+
unless activator.nil? || activator.is_a?(AdapterActivator)
|
|
164
|
+
raise CORBA::BAD_PARAM.new("not an AdapterActivator", 0, CORBA::COMPLETED_NO)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
PortableServer.ensure_dispatchers
|
|
168
|
+
@native.set_the_activator(activator)
|
|
169
|
+
end
|
|
170
|
+
alias _set_the_activator the_activator=
|
|
171
|
+
end
|
|
172
|
+
end
|