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,3805 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* rustorb_ext: the native part of the rustorb gem, on the C ABI of
|
|
3
|
+
* librustorb_ffi (rustorb.h). It wraps the handles (ORB, object references,
|
|
4
|
+
* POAs, TypeCodes, anys, servants) and the CDR streams for lib/rustorb, which
|
|
5
|
+
* does the mapping (docs/ruby-binding.md).
|
|
6
|
+
*
|
|
7
|
+
* Threads. Ruby code runs only on Ruby threads holding the GVL. Calls that
|
|
8
|
+
* block (an invocation, ORB#run) release the GVL; their callbacks take it
|
|
9
|
+
* back with rb_thread_call_with_gvl. Upcalls (a servant's dispatch) come on
|
|
10
|
+
* rustorb's own threads, which cannot take the GVL: they hand the work to a
|
|
11
|
+
* pool of Ruby dispatcher threads (Rustorb::Native.dispatcher_loop) and wait.
|
|
12
|
+
* The pool grows by one whenever a dispatcher takes the last idle slot, so a
|
|
13
|
+
* servant that calls out and is called back in still finds one.
|
|
14
|
+
*
|
|
15
|
+
* Licensed under MIT OR Apache-2.0, like the rest of the rustorb core.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include <ruby.h>
|
|
19
|
+
#include <ruby/encoding.h>
|
|
20
|
+
#include <ruby/thread.h>
|
|
21
|
+
|
|
22
|
+
#include <pthread.h>
|
|
23
|
+
#include <stdlib.h>
|
|
24
|
+
#include <string.h>
|
|
25
|
+
|
|
26
|
+
#include <rustorb/rustorb.h>
|
|
27
|
+
|
|
28
|
+
static VALUE mRustorb, mNative;
|
|
29
|
+
static VALUE cORB, cRef, cOut, cIn, cTC, cAny, cPOA, cPOAManager, cServantRef, cReply, cPeer;
|
|
30
|
+
static ID id_call, id_system_exception, id_local_exception, id_dispatch, id_spawn_dispatcher,
|
|
31
|
+
id_peer_ivar;
|
|
32
|
+
|
|
33
|
+
/* --- exceptions ------------------------------------------------------------- */
|
|
34
|
+
|
|
35
|
+
/* Raises the exception of status/exc (freeing exc), through
|
|
36
|
+
Rustorb::Native.system_exception / local_exception, which make the
|
|
37
|
+
CORBA exception objects. */
|
|
38
|
+
static void raise_status(rorb_status st, rorb_exception* exc) {
|
|
39
|
+
VALUE e;
|
|
40
|
+
if (st == RORB_SYSTEM_EXCEPTION) {
|
|
41
|
+
VALUE id = rb_utf8_str_new(exc->repository_id ? exc->repository_id : "",
|
|
42
|
+
(long)exc->repository_id_len);
|
|
43
|
+
VALUE minor = UINT2NUM(exc->minor), completed = UINT2NUM(exc->completed);
|
|
44
|
+
rorb_exception_clear(exc);
|
|
45
|
+
e = rb_funcall(mNative, id_system_exception, 3, id, minor, completed);
|
|
46
|
+
} else if (st == RORB_LOCAL_EXCEPTION) {
|
|
47
|
+
VALUE local = UINT2NUM(exc->local), index = UINT2NUM(exc->index);
|
|
48
|
+
rorb_exception_clear(exc);
|
|
49
|
+
e = rb_funcall(mNative, id_local_exception, 2, local, index);
|
|
50
|
+
} else {
|
|
51
|
+
rorb_exception_clear(exc);
|
|
52
|
+
e = rb_funcall(mNative, id_system_exception, 3,
|
|
53
|
+
rb_str_new_cstr("IDL:omg.org/CORBA/INTERNAL:1.0"), INT2FIX(0), INT2FIX(2));
|
|
54
|
+
}
|
|
55
|
+
rb_exc_raise(e);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#define CHECK(call) \
|
|
59
|
+
do { \
|
|
60
|
+
rorb_exception exc_; \
|
|
61
|
+
rorb_status st_; \
|
|
62
|
+
memset(&exc_, 0, sizeof exc_); \
|
|
63
|
+
st_ = (call); \
|
|
64
|
+
if (st_ != RORB_OK) raise_status(st_, &exc_); \
|
|
65
|
+
} while (0)
|
|
66
|
+
#define EXC (&exc_)
|
|
67
|
+
|
|
68
|
+
static void raise_bad_inv_order(const char* why) {
|
|
69
|
+
VALUE e = rb_funcall(mNative, id_system_exception, 3,
|
|
70
|
+
rb_str_new_cstr("IDL:omg.org/CORBA/BAD_INV_ORDER:1.0"), INT2FIX(0),
|
|
71
|
+
INT2FIX(RORB_COMPLETED_NO));
|
|
72
|
+
(void)why;
|
|
73
|
+
rb_exc_raise(e);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* --- the GVL ---------------------------------------------------------------- */
|
|
77
|
+
|
|
78
|
+
/* Whether this thread is a Ruby thread that released the GVL with
|
|
79
|
+
without_gvl below (then callbacks use rb_thread_call_with_gvl). */
|
|
80
|
+
static __thread int tls_released;
|
|
81
|
+
|
|
82
|
+
typedef void* (*gvl_fn)(void*);
|
|
83
|
+
|
|
84
|
+
struct nogvl_call {
|
|
85
|
+
gvl_fn fn;
|
|
86
|
+
void* arg;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
static void* nogvl_trampoline(void* p) {
|
|
90
|
+
struct nogvl_call* c = p;
|
|
91
|
+
void* r;
|
|
92
|
+
tls_released = 1;
|
|
93
|
+
r = c->fn(c->arg);
|
|
94
|
+
tls_released = 0;
|
|
95
|
+
return r;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Runs fn(arg) without the GVL. */
|
|
99
|
+
static void* without_gvl(gvl_fn fn, void* arg) {
|
|
100
|
+
struct nogvl_call c;
|
|
101
|
+
c.fn = fn;
|
|
102
|
+
c.arg = arg;
|
|
103
|
+
return rb_thread_call_without_gvl(nogvl_trampoline, &c, NULL, NULL);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* The hand-off to the dispatcher threads. */
|
|
107
|
+
typedef struct job {
|
|
108
|
+
gvl_fn fn;
|
|
109
|
+
void* arg;
|
|
110
|
+
void* result;
|
|
111
|
+
int done;
|
|
112
|
+
/* A call the dispatcher running this job asks the waiting thread to make
|
|
113
|
+
(at_home below): 1 asked, 2 running, 0 answered. */
|
|
114
|
+
gvl_fn home_fn;
|
|
115
|
+
void* home_arg;
|
|
116
|
+
void* home_result;
|
|
117
|
+
int home_pending;
|
|
118
|
+
pthread_cond_t cond;
|
|
119
|
+
struct job* next;
|
|
120
|
+
} job;
|
|
121
|
+
|
|
122
|
+
/* The job a dispatcher thread is running. */
|
|
123
|
+
static __thread job* tls_job;
|
|
124
|
+
|
|
125
|
+
static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
126
|
+
static pthread_cond_t queue_cond = PTHREAD_COND_INITIALIZER;
|
|
127
|
+
static job *queue_head, *queue_tail;
|
|
128
|
+
static int idle_dispatchers, dispatchers, interrupt_dispatchers, shutting_down;
|
|
129
|
+
|
|
130
|
+
static void* with_gvl_trampoline(void* p) {
|
|
131
|
+
struct nogvl_call* c = p;
|
|
132
|
+
void* r;
|
|
133
|
+
tls_released = 0;
|
|
134
|
+
r = c->fn(c->arg);
|
|
135
|
+
tls_released = 1;
|
|
136
|
+
return r;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* Runs fn(arg) with the GVL, from any thread: on a Ruby thread that released
|
|
140
|
+
it, by taking it back; on another thread, on a dispatcher thread. Returns
|
|
141
|
+
NULL without running fn when that cannot be done (shutting down). */
|
|
142
|
+
static void* with_gvl(gvl_fn fn, void* arg) {
|
|
143
|
+
job j;
|
|
144
|
+
if (tls_released) {
|
|
145
|
+
struct nogvl_call c;
|
|
146
|
+
c.fn = fn;
|
|
147
|
+
c.arg = arg;
|
|
148
|
+
return rb_thread_call_with_gvl(with_gvl_trampoline, &c);
|
|
149
|
+
}
|
|
150
|
+
if (ruby_native_thread_p()) return fn(arg); /* holds the GVL */
|
|
151
|
+
memset(&j, 0, sizeof j);
|
|
152
|
+
j.fn = fn;
|
|
153
|
+
j.arg = arg;
|
|
154
|
+
pthread_cond_init(&j.cond, NULL);
|
|
155
|
+
pthread_mutex_lock(&queue_lock);
|
|
156
|
+
if (shutting_down || dispatchers == 0) {
|
|
157
|
+
pthread_mutex_unlock(&queue_lock);
|
|
158
|
+
pthread_cond_destroy(&j.cond);
|
|
159
|
+
return NULL;
|
|
160
|
+
}
|
|
161
|
+
if (queue_tail)
|
|
162
|
+
queue_tail->next = &j;
|
|
163
|
+
else
|
|
164
|
+
queue_head = &j;
|
|
165
|
+
queue_tail = &j;
|
|
166
|
+
pthread_cond_signal(&queue_cond);
|
|
167
|
+
while (!j.done) {
|
|
168
|
+
pthread_cond_wait(&j.cond, &queue_lock);
|
|
169
|
+
if (j.home_pending == 1) {
|
|
170
|
+
gvl_fn f = j.home_fn;
|
|
171
|
+
void* a = j.home_arg;
|
|
172
|
+
void* r;
|
|
173
|
+
j.home_pending = 2;
|
|
174
|
+
pthread_mutex_unlock(&queue_lock);
|
|
175
|
+
r = f(a);
|
|
176
|
+
pthread_mutex_lock(&queue_lock);
|
|
177
|
+
j.home_result = r;
|
|
178
|
+
j.home_pending = 0;
|
|
179
|
+
pthread_cond_signal(&j.cond);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
pthread_mutex_unlock(&queue_lock);
|
|
183
|
+
pthread_cond_destroy(&j.cond);
|
|
184
|
+
return j.result;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
static void* home_nogvl(void* p) {
|
|
188
|
+
job* j = tls_job;
|
|
189
|
+
void* r;
|
|
190
|
+
struct nogvl_call* c = p;
|
|
191
|
+
pthread_mutex_lock(&queue_lock);
|
|
192
|
+
j->home_fn = c->fn;
|
|
193
|
+
j->home_arg = c->arg;
|
|
194
|
+
j->home_pending = 1;
|
|
195
|
+
pthread_cond_signal(&j->cond);
|
|
196
|
+
while (j->home_pending) pthread_cond_wait(&j->cond, &queue_lock);
|
|
197
|
+
r = j->home_result;
|
|
198
|
+
pthread_mutex_unlock(&queue_lock);
|
|
199
|
+
return r;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/* Runs fn(arg) (which must not call Ruby) on the rustorb thread whose upcall
|
|
203
|
+
this dispatcher is running, or here if it runs none: what rustorb keeps
|
|
204
|
+
per thread about the request being served (PortableServer::Current, the
|
|
205
|
+
servant's current reference) is on that thread. */
|
|
206
|
+
static void* at_home(gvl_fn fn, void* arg) {
|
|
207
|
+
struct nogvl_call c;
|
|
208
|
+
if (!tls_job) return fn(arg);
|
|
209
|
+
c.fn = fn;
|
|
210
|
+
c.arg = arg;
|
|
211
|
+
return without_gvl(home_nogvl, &c);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* Runs fn(arg) (a rustorb call, which must not call Ruby) without the GVL:
|
|
215
|
+
on the rustorb thread whose upcall this dispatcher runs, when it runs
|
|
216
|
+
one, so that the core sees the call made inside that upcall (a nested
|
|
217
|
+
call to a SINGLE_THREAD POA, ORB::shutdown(true) in an upcall...). */
|
|
218
|
+
static void* blocking(gvl_fn fn, void* arg) {
|
|
219
|
+
return tls_job ? at_home(fn, arg) : without_gvl(fn, arg);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static void* wait_job(void* unused) {
|
|
223
|
+
job* j = NULL;
|
|
224
|
+
(void)unused;
|
|
225
|
+
pthread_mutex_lock(&queue_lock);
|
|
226
|
+
++idle_dispatchers;
|
|
227
|
+
while (!queue_head && !interrupt_dispatchers && !shutting_down)
|
|
228
|
+
pthread_cond_wait(&queue_cond, &queue_lock);
|
|
229
|
+
if (queue_head) {
|
|
230
|
+
j = queue_head;
|
|
231
|
+
queue_head = j->next;
|
|
232
|
+
if (!queue_head) queue_tail = NULL;
|
|
233
|
+
}
|
|
234
|
+
interrupt_dispatchers = 0;
|
|
235
|
+
--idle_dispatchers;
|
|
236
|
+
pthread_mutex_unlock(&queue_lock);
|
|
237
|
+
return j;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
static void wake_dispatchers(void* unused) {
|
|
241
|
+
(void)unused;
|
|
242
|
+
pthread_mutex_lock(&queue_lock);
|
|
243
|
+
interrupt_dispatchers = 1;
|
|
244
|
+
pthread_cond_broadcast(&queue_cond);
|
|
245
|
+
pthread_mutex_unlock(&queue_lock);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* Rustorb::Native.dispatcher_loop: runs upcalls until the process ends. */
|
|
249
|
+
static VALUE native_dispatcher_loop(VALUE self) {
|
|
250
|
+
(void)self;
|
|
251
|
+
pthread_mutex_lock(&queue_lock);
|
|
252
|
+
++dispatchers;
|
|
253
|
+
pthread_mutex_unlock(&queue_lock);
|
|
254
|
+
for (;;) {
|
|
255
|
+
job* j = rb_thread_call_without_gvl(wait_job, NULL, wake_dispatchers, NULL);
|
|
256
|
+
int spawn;
|
|
257
|
+
if (!j) {
|
|
258
|
+
rb_thread_check_ints();
|
|
259
|
+
pthread_mutex_lock(&queue_lock);
|
|
260
|
+
if (shutting_down) {
|
|
261
|
+
--dispatchers;
|
|
262
|
+
pthread_mutex_unlock(&queue_lock);
|
|
263
|
+
return Qnil;
|
|
264
|
+
}
|
|
265
|
+
pthread_mutex_unlock(&queue_lock);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
pthread_mutex_lock(&queue_lock);
|
|
269
|
+
spawn = idle_dispatchers == 0;
|
|
270
|
+
pthread_mutex_unlock(&queue_lock);
|
|
271
|
+
if (spawn) rb_funcall(mNative, id_spawn_dispatcher, 0);
|
|
272
|
+
tls_job = j;
|
|
273
|
+
j->result = j->fn(j->arg);
|
|
274
|
+
tls_job = NULL;
|
|
275
|
+
pthread_mutex_lock(&queue_lock);
|
|
276
|
+
j->done = 1;
|
|
277
|
+
pthread_cond_signal(&j->cond);
|
|
278
|
+
pthread_mutex_unlock(&queue_lock);
|
|
279
|
+
}
|
|
280
|
+
return Qnil;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
static void at_exit_dispatchers(VALUE unused) {
|
|
284
|
+
job* j;
|
|
285
|
+
(void)unused;
|
|
286
|
+
pthread_mutex_lock(&queue_lock);
|
|
287
|
+
shutting_down = 1;
|
|
288
|
+
/* Jobs nobody will run: they return NULL. */
|
|
289
|
+
for (j = queue_head; j; j = j->next) {
|
|
290
|
+
j->result = NULL;
|
|
291
|
+
j->done = 1;
|
|
292
|
+
pthread_cond_signal(&j->cond);
|
|
293
|
+
}
|
|
294
|
+
queue_head = queue_tail = NULL;
|
|
295
|
+
pthread_cond_broadcast(&queue_cond);
|
|
296
|
+
pthread_mutex_unlock(&queue_lock);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/* --- handles ---------------------------------------------------------------- */
|
|
300
|
+
|
|
301
|
+
typedef struct handle {
|
|
302
|
+
void* p;
|
|
303
|
+
void (*release)(void*);
|
|
304
|
+
} handle;
|
|
305
|
+
|
|
306
|
+
static void handle_free(void* ptr) {
|
|
307
|
+
handle* h = ptr;
|
|
308
|
+
if (h->p && h->release) h->release(h->p);
|
|
309
|
+
xfree(h);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
static size_t handle_size(const void* ptr) {
|
|
313
|
+
(void)ptr;
|
|
314
|
+
return sizeof(handle);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
static const rb_data_type_t handle_type = {
|
|
318
|
+
"rustorb_handle", {NULL, handle_free, handle_size, NULL, {0}}, NULL, NULL,
|
|
319
|
+
RUBY_TYPED_FREE_IMMEDIATELY};
|
|
320
|
+
|
|
321
|
+
static void rel_orb(void* p) { rorb_orb_release(p); }
|
|
322
|
+
static void rel_obj(void* p) { rorb_object_release(p); }
|
|
323
|
+
static void rel_tc(void* p) { rorb_tc_release(p); }
|
|
324
|
+
static void rel_any(void* p) { rorb_any_release(p); }
|
|
325
|
+
static void rel_poa(void* p) { rorb_poa_release(p); }
|
|
326
|
+
static void rel_mgr(void* p) { rorb_poa_manager_release(p); }
|
|
327
|
+
static void rel_servant(void* p) { rorb_servant_release(p); }
|
|
328
|
+
|
|
329
|
+
/* Wraps p (taking its reference); nil for NULL. */
|
|
330
|
+
static VALUE wrap(VALUE klass, void* p, void (*release)(void*)) {
|
|
331
|
+
handle* h;
|
|
332
|
+
VALUE v;
|
|
333
|
+
if (!p) return Qnil;
|
|
334
|
+
v = TypedData_Make_Struct(klass, handle, &handle_type, h);
|
|
335
|
+
h->p = p;
|
|
336
|
+
h->release = release;
|
|
337
|
+
return v;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
static void* unwrap(VALUE v, VALUE klass) {
|
|
341
|
+
handle* h;
|
|
342
|
+
if (!rb_obj_is_kind_of(v, klass))
|
|
343
|
+
rb_raise(rb_eTypeError, "expected %s", rb_class2name(klass));
|
|
344
|
+
TypedData_Get_Struct(v, handle, &handle_type, h);
|
|
345
|
+
if (!h->p) raise_bad_inv_order("stale handle");
|
|
346
|
+
return h->p;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/* nil or a handle of klass. */
|
|
350
|
+
static void* unwrap_opt(VALUE v, VALUE klass) { return NIL_P(v) ? NULL : unwrap(v, klass); }
|
|
351
|
+
|
|
352
|
+
#define W_ORB(p) wrap(cORB, (p), rel_orb)
|
|
353
|
+
#define W_OBJ(p) wrap(cRef, (p), rel_obj)
|
|
354
|
+
#define W_TC(p) wrap(cTC, (p), rel_tc)
|
|
355
|
+
#define W_ANY(p) wrap(cAny, (p), rel_any)
|
|
356
|
+
#define W_POA(p) wrap(cPOA, (p), rel_poa)
|
|
357
|
+
#define W_MGR(p) wrap(cPOAManager, (p), rel_mgr)
|
|
358
|
+
#define ORB(v) ((rorb_orb*)unwrap((v), cORB))
|
|
359
|
+
#define OBJ(v) ((rorb_object*)unwrap((v), cRef))
|
|
360
|
+
#define TC(v) ((rorb_typecode*)unwrap((v), cTC))
|
|
361
|
+
#define ANY(v) ((rorb_any*)unwrap((v), cAny))
|
|
362
|
+
#define POA(v) ((rorb_poa*)unwrap((v), cPOA))
|
|
363
|
+
#define MGR(v) ((rorb_poa_manager*)unwrap((v), cPOAManager))
|
|
364
|
+
|
|
365
|
+
/* Streams and replies: valid only during the callback that has them, then
|
|
366
|
+
invalidated (using them raises BAD_INV_ORDER). */
|
|
367
|
+
static VALUE wrap_borrowed(VALUE klass, void* p) {
|
|
368
|
+
handle* h;
|
|
369
|
+
VALUE v = TypedData_Make_Struct(klass, handle, &handle_type, h);
|
|
370
|
+
h->p = p;
|
|
371
|
+
h->release = NULL;
|
|
372
|
+
return v;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
static void invalidate(VALUE v) {
|
|
376
|
+
handle* h;
|
|
377
|
+
if (NIL_P(v)) return;
|
|
378
|
+
TypedData_Get_Struct(v, handle, &handle_type, h);
|
|
379
|
+
h->p = NULL;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/* An owned input stream (released with the Ruby object). */
|
|
383
|
+
static void rel_in(void* p) { rorb_in_release(p); }
|
|
384
|
+
|
|
385
|
+
static VALUE bytes_str(rorb_bytes b) {
|
|
386
|
+
VALUE s = rb_str_new((const char*)b.data, (long)b.len);
|
|
387
|
+
rorb_bytes_free(b);
|
|
388
|
+
return s;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
static VALUE utf8(const char* s, size_t len) { return rb_utf8_str_new(s ? s : "", (long)len); }
|
|
392
|
+
|
|
393
|
+
/* A String argument as UTF-8 bytes. */
|
|
394
|
+
static VALUE utf8_arg(VALUE s) {
|
|
395
|
+
StringValue(s);
|
|
396
|
+
if (rb_enc_get_index(s) != rb_utf8_encindex() && rb_enc_get_index(s) != rb_usascii_encindex())
|
|
397
|
+
s = rb_str_export_to_enc(s, rb_utf8_encoding());
|
|
398
|
+
return s;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/* --- ORB ---------------------------------------------------------------- */
|
|
402
|
+
|
|
403
|
+
/* Rustorb::Native.orb_init(args): [orb, args left]. args[0] is not an
|
|
404
|
+
option (the program name). */
|
|
405
|
+
static VALUE native_orb_init(VALUE self, VALUE args) {
|
|
406
|
+
long n, i;
|
|
407
|
+
int argc;
|
|
408
|
+
char** argv;
|
|
409
|
+
rorb_orb* orb = NULL;
|
|
410
|
+
VALUE rest, strs;
|
|
411
|
+
rorb_exception exc;
|
|
412
|
+
rorb_status st;
|
|
413
|
+
(void)self;
|
|
414
|
+
Check_Type(args, T_ARRAY);
|
|
415
|
+
n = RARRAY_LEN(args);
|
|
416
|
+
strs = rb_ary_new_capa(n);
|
|
417
|
+
argv = ALLOCA_N(char*, n + 1);
|
|
418
|
+
for (i = 0; i < n; ++i) {
|
|
419
|
+
VALUE s = rb_str_dup(utf8_arg(rb_ary_entry(args, i)));
|
|
420
|
+
rb_ary_push(strs, s);
|
|
421
|
+
argv[i] = StringValueCStr(s);
|
|
422
|
+
}
|
|
423
|
+
argv[n] = NULL;
|
|
424
|
+
argc = (int)n;
|
|
425
|
+
memset(&exc, 0, sizeof exc);
|
|
426
|
+
if (rorb_abi_version() != RORB_ABI_VERSION) {
|
|
427
|
+
VALUE e = rb_funcall(mNative, id_system_exception, 3,
|
|
428
|
+
rb_str_new_cstr("IDL:omg.org/CORBA/INITIALIZE:1.0"), INT2FIX(0),
|
|
429
|
+
INT2FIX(RORB_COMPLETED_NO));
|
|
430
|
+
rb_exc_raise(e);
|
|
431
|
+
}
|
|
432
|
+
st = rorb_orb_init(&argc, argv, &orb, &exc);
|
|
433
|
+
if (st != RORB_OK) raise_status(st, &exc);
|
|
434
|
+
rest = rb_ary_new_capa(argc);
|
|
435
|
+
for (i = 0; i < argc; ++i) rb_ary_push(rest, rb_utf8_str_new_cstr(argv[i]));
|
|
436
|
+
RB_GC_GUARD(strs);
|
|
437
|
+
return rb_assoc_new(W_ORB(orb), rest);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
static VALUE native_default_orb(VALUE self) {
|
|
441
|
+
(void)self;
|
|
442
|
+
return W_ORB(rorb_default_orb());
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
static VALUE native_default_root_poa(VALUE self) {
|
|
446
|
+
rorb_poa* poa = NULL;
|
|
447
|
+
(void)self;
|
|
448
|
+
CHECK(rorb_default_root_poa(&poa, EXC));
|
|
449
|
+
return W_POA(poa);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
static VALUE orb_string_to_object(VALUE self, VALUE s) {
|
|
453
|
+
rorb_object* obj = NULL;
|
|
454
|
+
s = utf8_arg(s);
|
|
455
|
+
CHECK(rorb_orb_string_to_object(ORB(self), RSTRING_PTR(s), (size_t)RSTRING_LEN(s), &obj, EXC));
|
|
456
|
+
return W_OBJ(obj);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
static VALUE orb_object_to_string(VALUE self, VALUE obj) {
|
|
460
|
+
rorb_bytes b;
|
|
461
|
+
CHECK(rorb_orb_object_to_string(ORB(self), unwrap_opt(obj, cRef), &b, EXC));
|
|
462
|
+
return rb_enc_associate(bytes_str(b), rb_utf8_encoding());
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
static VALUE orb_resolve(VALUE self, VALUE name) {
|
|
466
|
+
rorb_object* obj = NULL;
|
|
467
|
+
name = utf8_arg(name);
|
|
468
|
+
CHECK(rorb_orb_resolve_initial_references(ORB(self), RSTRING_PTR(name),
|
|
469
|
+
(size_t)RSTRING_LEN(name), &obj, EXC));
|
|
470
|
+
return W_OBJ(obj);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
static void each_service(void* ctx, const char* name, size_t len) {
|
|
474
|
+
rb_ary_push((VALUE)ctx, utf8(name, len));
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
static VALUE orb_list_initial_services(VALUE self) {
|
|
478
|
+
VALUE a = rb_ary_new();
|
|
479
|
+
rorb_orb_list_initial_services(ORB(self), (void*)a, each_service);
|
|
480
|
+
return a;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
static VALUE orb_root_poa(VALUE self) {
|
|
484
|
+
rorb_poa* poa = NULL;
|
|
485
|
+
CHECK(rorb_orb_root_poa(ORB(self), &poa, EXC));
|
|
486
|
+
return W_POA(poa);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
static void* run_nogvl(void* orb) {
|
|
490
|
+
rorb_orb_run(orb);
|
|
491
|
+
return NULL;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
static VALUE orb_run(VALUE self) {
|
|
495
|
+
rorb_orb* orb = ORB(self);
|
|
496
|
+
without_gvl(run_nogvl, orb);
|
|
497
|
+
return Qnil;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
struct orb_op {
|
|
501
|
+
rorb_orb* orb;
|
|
502
|
+
int32_t wait;
|
|
503
|
+
rorb_status st;
|
|
504
|
+
rorb_exception exc;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
static void* shutdown_nogvl(void* p) {
|
|
508
|
+
struct orb_op* o = p;
|
|
509
|
+
o->st = rorb_orb_shutdown(o->orb, o->wait, &o->exc);
|
|
510
|
+
return NULL;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
static void* destroy_nogvl(void* p) {
|
|
514
|
+
struct orb_op* o = p;
|
|
515
|
+
o->st = rorb_orb_destroy(o->orb, &o->exc);
|
|
516
|
+
return NULL;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
static void* perform_work_nogvl(void* p) {
|
|
520
|
+
struct orb_op* o = p;
|
|
521
|
+
o->st = rorb_orb_perform_work(o->orb, &o->exc);
|
|
522
|
+
return NULL;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
static VALUE orb_shutdown(VALUE self, VALUE wait) {
|
|
526
|
+
struct orb_op o;
|
|
527
|
+
memset(&o, 0, sizeof o);
|
|
528
|
+
o.orb = ORB(self);
|
|
529
|
+
o.wait = RTEST(wait);
|
|
530
|
+
blocking(shutdown_nogvl, &o);
|
|
531
|
+
if (o.st != RORB_OK) raise_status(o.st, &o.exc);
|
|
532
|
+
return Qnil;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
static VALUE orb_destroy(VALUE self) {
|
|
536
|
+
struct orb_op o;
|
|
537
|
+
memset(&o, 0, sizeof o);
|
|
538
|
+
o.orb = ORB(self);
|
|
539
|
+
blocking(destroy_nogvl, &o);
|
|
540
|
+
if (o.st != RORB_OK) raise_status(o.st, &o.exc);
|
|
541
|
+
return Qnil;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
static VALUE orb_work_pending(VALUE self) {
|
|
545
|
+
int32_t pending = 0;
|
|
546
|
+
CHECK(rorb_orb_work_pending(ORB(self), &pending, EXC));
|
|
547
|
+
return pending ? Qtrue : Qfalse;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
static VALUE orb_perform_work(VALUE self) {
|
|
551
|
+
struct orb_op o;
|
|
552
|
+
memset(&o, 0, sizeof o);
|
|
553
|
+
o.orb = ORB(self);
|
|
554
|
+
blocking(perform_work_nogvl, &o);
|
|
555
|
+
if (o.st != RORB_OK) raise_status(o.st, &o.exc);
|
|
556
|
+
return Qnil;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
static VALUE orb_set_call_timeout(VALUE self, VALUE us) {
|
|
560
|
+
rorb_orb_set_call_timeout(ORB(self), NUM2LL(us));
|
|
561
|
+
return Qnil;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
static VALUE orb_call_timeout(VALUE self) { return LL2NUM(rorb_orb_call_timeout(ORB(self))); }
|
|
565
|
+
|
|
566
|
+
static VALUE orb_set_connect_timeout(VALUE self, VALUE us) {
|
|
567
|
+
rorb_orb_set_connect_timeout(ORB(self), NUM2LL(us));
|
|
568
|
+
return Qnil;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
static VALUE orb_register_initial_reference(VALUE self, VALUE name, VALUE obj) {
|
|
572
|
+
name = utf8_arg(name);
|
|
573
|
+
CHECK(rorb_orb_register_initial_reference(ORB(self), RSTRING_PTR(name),
|
|
574
|
+
(size_t)RSTRING_LEN(name), unwrap_opt(obj, cRef),
|
|
575
|
+
EXC));
|
|
576
|
+
return Qnil;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
static VALUE native_set_thread_call_timeout(VALUE self, VALUE us) {
|
|
580
|
+
(void)self;
|
|
581
|
+
rorb_set_thread_call_timeout(NUM2LL(us));
|
|
582
|
+
return Qnil;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
static VALUE native_thread_call_timeout(VALUE self) {
|
|
586
|
+
(void)self;
|
|
587
|
+
return LL2NUM(rorb_thread_call_timeout());
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/* --- object references ------------------------------------------------------- */
|
|
591
|
+
|
|
592
|
+
struct ref_op {
|
|
593
|
+
rorb_object* obj;
|
|
594
|
+
const char* s;
|
|
595
|
+
size_t len;
|
|
596
|
+
int32_t result;
|
|
597
|
+
rorb_status st;
|
|
598
|
+
rorb_exception exc;
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
static void* is_a_nogvl(void* p) {
|
|
602
|
+
struct ref_op* o = p;
|
|
603
|
+
o->st = rorb_object_is_a(o->obj, o->s, o->len, &o->result, &o->exc);
|
|
604
|
+
return NULL;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
static void* non_existent_nogvl(void* p) {
|
|
608
|
+
struct ref_op* o = p;
|
|
609
|
+
o->st = rorb_object_non_existent(o->obj, &o->result, &o->exc);
|
|
610
|
+
return NULL;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
static void* validate_nogvl(void* p) {
|
|
614
|
+
struct ref_op* o = p;
|
|
615
|
+
o->st = rorb_object_validate_connection(o->obj, &o->result, &o->exc);
|
|
616
|
+
return NULL;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
static VALUE ref_call(VALUE self, gvl_fn fn, VALUE s) {
|
|
620
|
+
struct ref_op o;
|
|
621
|
+
memset(&o, 0, sizeof o);
|
|
622
|
+
o.obj = OBJ(self);
|
|
623
|
+
if (!NIL_P(s)) {
|
|
624
|
+
s = utf8_arg(s);
|
|
625
|
+
o.s = RSTRING_PTR(s);
|
|
626
|
+
o.len = (size_t)RSTRING_LEN(s);
|
|
627
|
+
}
|
|
628
|
+
blocking(fn, &o);
|
|
629
|
+
RB_GC_GUARD(s);
|
|
630
|
+
if (o.st != RORB_OK) raise_status(o.st, &o.exc);
|
|
631
|
+
return o.result ? Qtrue : Qfalse;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
static VALUE ref_is_a(VALUE self, VALUE id) { return ref_call(self, is_a_nogvl, id); }
|
|
635
|
+
static VALUE ref_non_existent(VALUE self) { return ref_call(self, non_existent_nogvl, Qnil); }
|
|
636
|
+
static VALUE ref_validate_connection(VALUE self) { return ref_call(self, validate_nogvl, Qnil); }
|
|
637
|
+
|
|
638
|
+
static VALUE ref_equivalent(VALUE self, VALUE other) {
|
|
639
|
+
return rorb_object_is_equivalent(OBJ(self), OBJ(other)) ? Qtrue : Qfalse;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
static VALUE ref_hash(VALUE self, VALUE max) {
|
|
643
|
+
return UINT2NUM(rorb_object_hash(OBJ(self), NUM2UINT(max)));
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
static VALUE ref_type_id(VALUE self) {
|
|
647
|
+
size_t len = 0;
|
|
648
|
+
const char* s = rorb_object_type_id(OBJ(self), &len);
|
|
649
|
+
return utf8(s, len);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
static VALUE ref_orb(VALUE self) { return W_ORB(rorb_object_orb(OBJ(self))); }
|
|
653
|
+
|
|
654
|
+
static VALUE ref_dup(VALUE self) { return W_OBJ(rorb_object_clone(OBJ(self))); }
|
|
655
|
+
|
|
656
|
+
static VALUE ref_set_call_timeout(VALUE self, VALUE us) {
|
|
657
|
+
rorb_object_set_call_timeout(OBJ(self), NUM2LL(us));
|
|
658
|
+
return Qnil;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
static VALUE ref_call_timeout(VALUE self) { return LL2NUM(rorb_object_call_timeout(OBJ(self))); }
|
|
662
|
+
|
|
663
|
+
/* The context of an invocation: the Ruby procs and the error a callback
|
|
664
|
+
raised. On the stack of the invoking Ruby thread (so its VALUEs are
|
|
665
|
+
marked). */
|
|
666
|
+
struct invoke_ctx {
|
|
667
|
+
VALUE writer, reader, user_exc;
|
|
668
|
+
VALUE error, user_error;
|
|
669
|
+
rorb_out* out;
|
|
670
|
+
rorb_in* in;
|
|
671
|
+
const char* exc_id;
|
|
672
|
+
size_t exc_id_len;
|
|
673
|
+
rorb_object* obj;
|
|
674
|
+
rorb_invocation inv;
|
|
675
|
+
rorb_status st;
|
|
676
|
+
rorb_exception exc;
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
struct protect_call {
|
|
680
|
+
VALUE proc;
|
|
681
|
+
int argc;
|
|
682
|
+
VALUE argv[2];
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
static VALUE protect_body(VALUE p) {
|
|
686
|
+
struct protect_call* c = (struct protect_call*)p;
|
|
687
|
+
return rb_funcallv(c->proc, id_call, c->argc, c->argv);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/* Calls proc with the arguments; on an exception keeps it in *error and
|
|
691
|
+
returns Qundef. */
|
|
692
|
+
static VALUE call_protected(VALUE proc, int argc, VALUE* argv, VALUE* error) {
|
|
693
|
+
struct protect_call c;
|
|
694
|
+
int state = 0;
|
|
695
|
+
VALUE r;
|
|
696
|
+
c.proc = proc;
|
|
697
|
+
c.argc = argc;
|
|
698
|
+
c.argv[0] = argc > 0 ? argv[0] : Qnil;
|
|
699
|
+
c.argv[1] = argc > 1 ? argv[1] : Qnil;
|
|
700
|
+
r = rb_protect(protect_body, (VALUE)&c, &state);
|
|
701
|
+
if (state) {
|
|
702
|
+
*error = rb_errinfo();
|
|
703
|
+
rb_set_errinfo(Qnil);
|
|
704
|
+
return Qundef;
|
|
705
|
+
}
|
|
706
|
+
return r;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
static void* cb_write(void* p) {
|
|
710
|
+
struct invoke_ctx* c = p;
|
|
711
|
+
VALUE out = wrap_borrowed(cOut, c->out);
|
|
712
|
+
VALUE r = call_protected(c->writer, 1, &out, &c->error);
|
|
713
|
+
invalidate(out);
|
|
714
|
+
return r == Qundef ? (void*)1 : NULL;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
static void* cb_read(void* p) {
|
|
718
|
+
struct invoke_ctx* c = p;
|
|
719
|
+
VALUE in = wrap_borrowed(cIn, c->in);
|
|
720
|
+
VALUE r = call_protected(c->reader, 1, &in, &c->error);
|
|
721
|
+
invalidate(in);
|
|
722
|
+
return r == Qundef ? (void*)1 : NULL;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/* Returns 1 (failed), 2 (taken) or 3 (not declared). */
|
|
726
|
+
static void* cb_user_exc(void* p) {
|
|
727
|
+
struct invoke_ctx* c = p;
|
|
728
|
+
VALUE argv[2];
|
|
729
|
+
VALUE r;
|
|
730
|
+
argv[0] = utf8(c->exc_id, c->exc_id_len);
|
|
731
|
+
argv[1] = wrap_borrowed(cIn, c->in);
|
|
732
|
+
r = call_protected(c->user_exc, 2, argv, &c->error);
|
|
733
|
+
invalidate(argv[1]);
|
|
734
|
+
if (r == Qundef) return (void*)1;
|
|
735
|
+
if (NIL_P(r)) return (void*)3;
|
|
736
|
+
c->user_error = r;
|
|
737
|
+
return (void*)2;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
static rorb_status write_args(void* ctx, rorb_out* out) {
|
|
741
|
+
struct invoke_ctx* c = ctx;
|
|
742
|
+
if (NIL_P(c->writer)) return RORB_OK;
|
|
743
|
+
c->out = out;
|
|
744
|
+
return with_gvl(cb_write, c) ? RORB_CALLBACK_FAILED : RORB_OK;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
static rorb_status read_reply(void* ctx, rorb_in* in) {
|
|
748
|
+
struct invoke_ctx* c = ctx;
|
|
749
|
+
if (NIL_P(c->reader)) return RORB_OK;
|
|
750
|
+
c->in = in;
|
|
751
|
+
return with_gvl(cb_read, c) ? RORB_CALLBACK_FAILED : RORB_OK;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
static rorb_status read_user_exception(void* ctx, const char* id, size_t len, rorb_in* in) {
|
|
755
|
+
struct invoke_ctx* c = ctx;
|
|
756
|
+
void* r;
|
|
757
|
+
if (NIL_P(c->user_exc)) return RORB_SYSTEM_EXCEPTION;
|
|
758
|
+
c->in = in;
|
|
759
|
+
c->exc_id = id;
|
|
760
|
+
c->exc_id_len = len;
|
|
761
|
+
r = with_gvl(cb_user_exc, c);
|
|
762
|
+
if (r == (void*)2) return RORB_USER_EXCEPTION;
|
|
763
|
+
if (r == (void*)3) return RORB_SYSTEM_EXCEPTION;
|
|
764
|
+
return RORB_CALLBACK_FAILED;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
static void* invoke_nogvl(void* p) {
|
|
768
|
+
struct invoke_ctx* c = p;
|
|
769
|
+
c->st = rorb_object_invoke(c->obj, &c->inv, &c->exc);
|
|
770
|
+
return NULL;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/* Ref#invoke(op, oneway, timeout_us, writer, reader, user_exc): calls the
|
|
774
|
+
operation. writer.call(out) writes the arguments, reader.call(in) reads
|
|
775
|
+
the reply, user_exc.call(id, in) reads a user exception and returns it,
|
|
776
|
+
or nil when the operation does not declare it (the call then raises
|
|
777
|
+
UNKNOWN). The user exception, or an error a proc raised, is raised
|
|
778
|
+
here. Returns nil. */
|
|
779
|
+
static VALUE ref_invoke(VALUE self, VALUE op, VALUE oneway, VALUE timeout, VALUE writer,
|
|
780
|
+
VALUE reader, VALUE user_exc) {
|
|
781
|
+
struct invoke_ctx c;
|
|
782
|
+
memset(&c, 0, sizeof c);
|
|
783
|
+
op = utf8_arg(op);
|
|
784
|
+
c.writer = writer;
|
|
785
|
+
c.reader = reader;
|
|
786
|
+
c.user_exc = user_exc;
|
|
787
|
+
c.error = Qnil;
|
|
788
|
+
c.user_error = Qnil;
|
|
789
|
+
c.obj = OBJ(self);
|
|
790
|
+
c.inv.operation = RSTRING_PTR(op);
|
|
791
|
+
c.inv.operation_len = (size_t)RSTRING_LEN(op);
|
|
792
|
+
c.inv.oneway = RTEST(oneway);
|
|
793
|
+
c.inv.timeout_us = NIL_P(timeout) ? -1 : NUM2LL(timeout);
|
|
794
|
+
c.inv.context = &c;
|
|
795
|
+
c.inv.write_args = write_args;
|
|
796
|
+
c.inv.read_reply = read_reply;
|
|
797
|
+
c.inv.read_user_exception = read_user_exception;
|
|
798
|
+
blocking(invoke_nogvl, &c);
|
|
799
|
+
RB_GC_GUARD(op);
|
|
800
|
+
RB_GC_GUARD(writer);
|
|
801
|
+
RB_GC_GUARD(reader);
|
|
802
|
+
RB_GC_GUARD(user_exc);
|
|
803
|
+
if (!NIL_P(c.error)) {
|
|
804
|
+
rorb_exception_clear(&c.exc);
|
|
805
|
+
rb_exc_raise(c.error);
|
|
806
|
+
}
|
|
807
|
+
if (c.st == RORB_USER_EXCEPTION && !NIL_P(c.user_error)) rb_exc_raise(c.user_error);
|
|
808
|
+
if (c.st == RORB_CALLBACK_FAILED || c.st == RORB_USER_EXCEPTION) {
|
|
809
|
+
rorb_exception_clear(&c.exc);
|
|
810
|
+
raise_bad_inv_order("callback failed without an error");
|
|
811
|
+
}
|
|
812
|
+
if (c.st != RORB_OK) raise_status(c.st, &c.exc);
|
|
813
|
+
return Qnil;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/* --- output streams ------------------------------------------------------------ */
|
|
817
|
+
|
|
818
|
+
#define OUT(v) ((rorb_out*)unwrap((v), cOut))
|
|
819
|
+
#define IN(v) ((rorb_in*)unwrap((v), cIn))
|
|
820
|
+
|
|
821
|
+
static VALUE out_write_boolean(VALUE self, VALUE v) {
|
|
822
|
+
rorb_out_write_boolean(OUT(self), RTEST(v));
|
|
823
|
+
return self;
|
|
824
|
+
}
|
|
825
|
+
static VALUE out_write_octet(VALUE self, VALUE v) {
|
|
826
|
+
rorb_out_write_octet(OUT(self), (uint8_t)NUM2UINT(v));
|
|
827
|
+
return self;
|
|
828
|
+
}
|
|
829
|
+
static VALUE out_write_char(VALUE self, VALUE v) {
|
|
830
|
+
rorb_out_write_char(OUT(self), (char)NUM2INT(v));
|
|
831
|
+
return self;
|
|
832
|
+
}
|
|
833
|
+
static VALUE out_write_wchar(VALUE self, VALUE v) {
|
|
834
|
+
rorb_out_write_wchar(OUT(self), (uint16_t)NUM2UINT(v));
|
|
835
|
+
return self;
|
|
836
|
+
}
|
|
837
|
+
static VALUE out_write_short(VALUE self, VALUE v) {
|
|
838
|
+
rorb_out_write_short(OUT(self), (int16_t)NUM2INT(v));
|
|
839
|
+
return self;
|
|
840
|
+
}
|
|
841
|
+
static VALUE out_write_ushort(VALUE self, VALUE v) {
|
|
842
|
+
rorb_out_write_ushort(OUT(self), (uint16_t)NUM2UINT(v));
|
|
843
|
+
return self;
|
|
844
|
+
}
|
|
845
|
+
static VALUE out_write_long(VALUE self, VALUE v) {
|
|
846
|
+
rorb_out_write_long(OUT(self), (int32_t)NUM2LONG(v));
|
|
847
|
+
return self;
|
|
848
|
+
}
|
|
849
|
+
static VALUE out_write_ulong(VALUE self, VALUE v) {
|
|
850
|
+
rorb_out_write_ulong(OUT(self), (uint32_t)NUM2ULONG(v));
|
|
851
|
+
return self;
|
|
852
|
+
}
|
|
853
|
+
static VALUE out_write_longlong(VALUE self, VALUE v) {
|
|
854
|
+
rorb_out_write_longlong(OUT(self), (int64_t)NUM2LL(v));
|
|
855
|
+
return self;
|
|
856
|
+
}
|
|
857
|
+
static VALUE out_write_ulonglong(VALUE self, VALUE v) {
|
|
858
|
+
rorb_out_write_ulonglong(OUT(self), (uint64_t)NUM2ULL(v));
|
|
859
|
+
return self;
|
|
860
|
+
}
|
|
861
|
+
static VALUE out_write_float(VALUE self, VALUE v) {
|
|
862
|
+
rorb_out_write_float(OUT(self), (float)NUM2DBL(v));
|
|
863
|
+
return self;
|
|
864
|
+
}
|
|
865
|
+
static VALUE out_write_double(VALUE self, VALUE v) {
|
|
866
|
+
rorb_out_write_double(OUT(self), NUM2DBL(v));
|
|
867
|
+
return self;
|
|
868
|
+
}
|
|
869
|
+
static VALUE out_write_string(VALUE self, VALUE v) {
|
|
870
|
+
v = utf8_arg(v);
|
|
871
|
+
rorb_out_write_string(OUT(self), RSTRING_PTR(v), (size_t)RSTRING_LEN(v));
|
|
872
|
+
return self;
|
|
873
|
+
}
|
|
874
|
+
/* A wstring as a String of UTF-16LE code units. */
|
|
875
|
+
static VALUE out_write_wstring(VALUE self, VALUE units) {
|
|
876
|
+
StringValue(units);
|
|
877
|
+
rorb_out_write_wstring(OUT(self), (const uint16_t*)RSTRING_PTR(units),
|
|
878
|
+
(size_t)RSTRING_LEN(units) / 2);
|
|
879
|
+
return self;
|
|
880
|
+
}
|
|
881
|
+
static VALUE out_write_object(VALUE self, VALUE ref) {
|
|
882
|
+
rorb_out_write_object(OUT(self), unwrap_opt(ref, cRef));
|
|
883
|
+
return self;
|
|
884
|
+
}
|
|
885
|
+
static VALUE out_write_typecode(VALUE self, VALUE tc) {
|
|
886
|
+
rorb_out_write_typecode(OUT(self), TC(tc));
|
|
887
|
+
return self;
|
|
888
|
+
}
|
|
889
|
+
static VALUE out_write_any(VALUE self, VALUE any) {
|
|
890
|
+
rorb_out_write_any(OUT(self), ANY(any));
|
|
891
|
+
return self;
|
|
892
|
+
}
|
|
893
|
+
static VALUE out_write_any_value(VALUE self, VALUE any) {
|
|
894
|
+
rorb_out_write_any_value(OUT(self), ANY(any));
|
|
895
|
+
return self;
|
|
896
|
+
}
|
|
897
|
+
static VALUE out_write_longdouble(VALUE self, VALUE hi, VALUE lo) {
|
|
898
|
+
rorb_out_write_longdouble(OUT(self), NUM2ULL(hi), NUM2ULL(lo));
|
|
899
|
+
return self;
|
|
900
|
+
}
|
|
901
|
+
/* digits: a String of digit values 0 to 9, most significant first. */
|
|
902
|
+
static VALUE out_write_fixed(VALUE self, VALUE digits, VALUE negative) {
|
|
903
|
+
StringValue(digits);
|
|
904
|
+
rorb_out_write_fixed(OUT(self), (const uint8_t*)RSTRING_PTR(digits),
|
|
905
|
+
(size_t)RSTRING_LEN(digits), RTEST(negative));
|
|
906
|
+
return self;
|
|
907
|
+
}
|
|
908
|
+
static const size_t prim_size[] = {1, 2, 2, 4, 4, 8, 8, 4, 8};
|
|
909
|
+
/* data: the elements packed in the host's representation. */
|
|
910
|
+
static VALUE out_write_array(VALUE self, VALUE kind, VALUE data) {
|
|
911
|
+
int k = NUM2INT(kind);
|
|
912
|
+
if (k < 0 || k > RORB_PRIM_DOUBLE) rb_raise(rb_eArgError, "bad element kind");
|
|
913
|
+
StringValue(data);
|
|
914
|
+
rorb_out_write_array(OUT(self), k, RSTRING_PTR(data), (size_t)RSTRING_LEN(data) / prim_size[k]);
|
|
915
|
+
return self;
|
|
916
|
+
}
|
|
917
|
+
static VALUE out_failed(VALUE self) { return rorb_out_failed(OUT(self)) ? Qtrue : Qfalse; }
|
|
918
|
+
static VALUE out_keeps_hosts(VALUE self) {
|
|
919
|
+
return rorb_out_keeps_hosts(OUT(self)) ? Qtrue : Qfalse;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/* --- input streams --------------------------------------------------------------- */
|
|
923
|
+
|
|
924
|
+
static VALUE in_read_boolean(VALUE self) { return rorb_in_read_boolean(IN(self)) ? Qtrue : Qfalse; }
|
|
925
|
+
static VALUE in_read_octet(VALUE self) { return UINT2NUM(rorb_in_read_octet(IN(self))); }
|
|
926
|
+
static VALUE in_read_char(VALUE self) { return INT2FIX((unsigned char)rorb_in_read_char(IN(self))); }
|
|
927
|
+
static VALUE in_read_wchar(VALUE self) { return UINT2NUM(rorb_in_read_wchar(IN(self))); }
|
|
928
|
+
static VALUE in_read_short(VALUE self) { return INT2FIX(rorb_in_read_short(IN(self))); }
|
|
929
|
+
static VALUE in_read_ushort(VALUE self) { return UINT2NUM(rorb_in_read_ushort(IN(self))); }
|
|
930
|
+
static VALUE in_read_long(VALUE self) { return LONG2NUM(rorb_in_read_long(IN(self))); }
|
|
931
|
+
static VALUE in_read_ulong(VALUE self) { return ULONG2NUM(rorb_in_read_ulong(IN(self))); }
|
|
932
|
+
static VALUE in_read_longlong(VALUE self) { return LL2NUM(rorb_in_read_longlong(IN(self))); }
|
|
933
|
+
static VALUE in_read_ulonglong(VALUE self) { return ULL2NUM(rorb_in_read_ulonglong(IN(self))); }
|
|
934
|
+
static VALUE in_read_float(VALUE self) { return DBL2NUM(rorb_in_read_float(IN(self))); }
|
|
935
|
+
static VALUE in_read_double(VALUE self) { return DBL2NUM(rorb_in_read_double(IN(self))); }
|
|
936
|
+
static VALUE in_read_longdouble(VALUE self) {
|
|
937
|
+
uint64_t hi = 0, lo = 0;
|
|
938
|
+
rorb_in_read_longdouble(IN(self), &hi, &lo);
|
|
939
|
+
return rb_assoc_new(ULL2NUM(hi), ULL2NUM(lo));
|
|
940
|
+
}
|
|
941
|
+
static VALUE in_read_string(VALUE self) {
|
|
942
|
+
size_t len = 0;
|
|
943
|
+
const char* s = rorb_in_read_string(IN(self), &len);
|
|
944
|
+
return utf8(s, len);
|
|
945
|
+
}
|
|
946
|
+
/* A wstring as a String of UTF-16LE code units. */
|
|
947
|
+
static VALUE in_read_wstring(VALUE self) {
|
|
948
|
+
size_t len = 0;
|
|
949
|
+
const uint16_t* s = rorb_in_read_wstring(IN(self), &len);
|
|
950
|
+
return rb_str_new((const char*)s, (long)(len * 2));
|
|
951
|
+
}
|
|
952
|
+
static VALUE in_read_object(VALUE self) { return W_OBJ(rorb_in_read_object(IN(self))); }
|
|
953
|
+
static VALUE in_read_typecode(VALUE self) { return W_TC(rorb_in_read_typecode(IN(self))); }
|
|
954
|
+
static VALUE in_read_any(VALUE self) { return W_ANY(rorb_in_read_any(IN(self))); }
|
|
955
|
+
static VALUE in_read_any_value(VALUE self, VALUE tc) {
|
|
956
|
+
return W_ANY(rorb_in_read_any_value(IN(self), TC(tc)));
|
|
957
|
+
}
|
|
958
|
+
static VALUE in_read_array(VALUE self, VALUE kind, VALUE count) {
|
|
959
|
+
int k = NUM2INT(kind);
|
|
960
|
+
size_t n = NUM2SIZET(count);
|
|
961
|
+
VALUE s;
|
|
962
|
+
if (k < 0 || k > RORB_PRIM_DOUBLE) rb_raise(rb_eArgError, "bad element kind");
|
|
963
|
+
s = rb_str_new(NULL, (long)(n * prim_size[k]));
|
|
964
|
+
rorb_in_read_array(IN(self), k, RSTRING_PTR(s), n);
|
|
965
|
+
return s;
|
|
966
|
+
}
|
|
967
|
+
/* [digits, negative]: count digit values. */
|
|
968
|
+
static VALUE in_read_fixed(VALUE self, VALUE count) {
|
|
969
|
+
size_t n = NUM2SIZET(count);
|
|
970
|
+
VALUE s = rb_str_new(NULL, (long)n);
|
|
971
|
+
int32_t neg = rorb_in_read_fixed(IN(self), (uint8_t*)RSTRING_PTR(s), n);
|
|
972
|
+
return rb_assoc_new(s, neg ? Qtrue : Qfalse);
|
|
973
|
+
}
|
|
974
|
+
static VALUE in_read_length(VALUE self, VALUE min) {
|
|
975
|
+
return UINT2NUM(rorb_in_read_length(IN(self), NUM2SIZET(min)));
|
|
976
|
+
}
|
|
977
|
+
static VALUE in_fail(VALUE self) {
|
|
978
|
+
rorb_in_fail(IN(self));
|
|
979
|
+
return self;
|
|
980
|
+
}
|
|
981
|
+
static VALUE in_failed(VALUE self) { return rorb_in_failed(IN(self)) ? Qtrue : Qfalse; }
|
|
982
|
+
|
|
983
|
+
/* --- valuetypes ----------------------------------------------------------------- */
|
|
984
|
+
|
|
985
|
+
/* The Ruby instances rustorb keeps (in the streams of one message, in the
|
|
986
|
+
core instances of anys): one host per instance, counted, released from
|
|
987
|
+
any thread. The GC marks (and pins) the instances while they are kept,
|
|
988
|
+
and the same instance always has the same host, whose address is the key
|
|
989
|
+
the core knows it by. */
|
|
990
|
+
typedef struct host {
|
|
991
|
+
VALUE obj;
|
|
992
|
+
long count;
|
|
993
|
+
struct host* next;
|
|
994
|
+
} host;
|
|
995
|
+
|
|
996
|
+
#define HOST_BUCKETS 4096
|
|
997
|
+
static host* host_buckets[HOST_BUCKETS];
|
|
998
|
+
static pthread_mutex_t host_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
999
|
+
|
|
1000
|
+
static size_t host_bucket(VALUE obj) { return (size_t)(((uintptr_t)obj >> 3) % HOST_BUCKETS); }
|
|
1001
|
+
|
|
1002
|
+
/* With the GVL. */
|
|
1003
|
+
static host* host_retain(VALUE obj) {
|
|
1004
|
+
host* h;
|
|
1005
|
+
size_t b = host_bucket(obj);
|
|
1006
|
+
pthread_mutex_lock(&host_lock);
|
|
1007
|
+
for (h = host_buckets[b]; h; h = h->next)
|
|
1008
|
+
if (h->obj == obj) break;
|
|
1009
|
+
if (!h) {
|
|
1010
|
+
h = calloc(1, sizeof *h);
|
|
1011
|
+
if (!h) {
|
|
1012
|
+
pthread_mutex_unlock(&host_lock);
|
|
1013
|
+
rb_raise(rb_eNoMemError, "rustorb: no memory for a value");
|
|
1014
|
+
}
|
|
1015
|
+
h->obj = obj;
|
|
1016
|
+
h->next = host_buckets[b];
|
|
1017
|
+
host_buckets[b] = h;
|
|
1018
|
+
}
|
|
1019
|
+
++h->count;
|
|
1020
|
+
pthread_mutex_unlock(&host_lock);
|
|
1021
|
+
return h;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
/* From any thread. */
|
|
1025
|
+
static void host_release(void* p) {
|
|
1026
|
+
host* h = p;
|
|
1027
|
+
host** link;
|
|
1028
|
+
pthread_mutex_lock(&host_lock);
|
|
1029
|
+
if (--h->count == 0) {
|
|
1030
|
+
for (link = &host_buckets[host_bucket(h->obj)]; *link; link = &(*link)->next)
|
|
1031
|
+
if (*link == h) {
|
|
1032
|
+
*link = h->next;
|
|
1033
|
+
break;
|
|
1034
|
+
}
|
|
1035
|
+
free(h);
|
|
1036
|
+
}
|
|
1037
|
+
pthread_mutex_unlock(&host_lock);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
static void hosts_mark(void* unused) {
|
|
1041
|
+
size_t b;
|
|
1042
|
+
host* h;
|
|
1043
|
+
(void)unused;
|
|
1044
|
+
pthread_mutex_lock(&host_lock);
|
|
1045
|
+
for (b = 0; b < HOST_BUCKETS; ++b)
|
|
1046
|
+
for (h = host_buckets[b]; h; h = h->next) rb_gc_mark(h->obj);
|
|
1047
|
+
pthread_mutex_unlock(&host_lock);
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
static const rb_data_type_t hosts_type = {
|
|
1051
|
+
"rustorb_hosts", {hosts_mark, NULL, NULL, NULL, {0}}, NULL, NULL, 0};
|
|
1052
|
+
|
|
1053
|
+
static VALUE native_kept_values(VALUE self) {
|
|
1054
|
+
size_t b, n = 0;
|
|
1055
|
+
host* h;
|
|
1056
|
+
(void)self;
|
|
1057
|
+
pthread_mutex_lock(&host_lock);
|
|
1058
|
+
for (b = 0; b < HOST_BUCKETS; ++b)
|
|
1059
|
+
for (h = host_buckets[b]; h; h = h->next) ++n;
|
|
1060
|
+
pthread_mutex_unlock(&host_lock);
|
|
1061
|
+
return SIZET2NUM(n);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
static VALUE out_write_null_value(VALUE self) {
|
|
1065
|
+
rorb_out_write_null_value(OUT(self));
|
|
1066
|
+
return self;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/* begin_value(obj, ids, chunked): true when the caller now writes the
|
|
1070
|
+
state (then end_value), false when an indirection was written. */
|
|
1071
|
+
static VALUE out_begin_value(VALUE self, VALUE obj, VALUE ids, VALUE chunked) {
|
|
1072
|
+
rorb_out* out = OUT(self);
|
|
1073
|
+
size_t n, i;
|
|
1074
|
+
const char** cp;
|
|
1075
|
+
size_t* cl;
|
|
1076
|
+
int32_t r;
|
|
1077
|
+
Check_Type(ids, T_ARRAY);
|
|
1078
|
+
n = (size_t)RARRAY_LEN(ids);
|
|
1079
|
+
cp = ALLOCA_N(const char*, n + 1);
|
|
1080
|
+
cl = ALLOCA_N(size_t, n + 1);
|
|
1081
|
+
ids = rb_ary_dup(ids);
|
|
1082
|
+
for (i = 0; i < n; ++i) {
|
|
1083
|
+
VALUE s = utf8_arg(rb_ary_entry(ids, (long)i));
|
|
1084
|
+
rb_ary_store(ids, (long)i, s);
|
|
1085
|
+
cp[i] = RSTRING_PTR(s);
|
|
1086
|
+
cl[i] = (size_t)RSTRING_LEN(s);
|
|
1087
|
+
}
|
|
1088
|
+
if (rorb_out_keeps_hosts(out)) {
|
|
1089
|
+
host* h = host_retain(obj);
|
|
1090
|
+
r = rorb_out_begin_host_value(out, (uint64_t)(uintptr_t)h, h, host_release, n, cp, cl,
|
|
1091
|
+
RTEST(chunked));
|
|
1092
|
+
} else {
|
|
1093
|
+
uint64_t key = ((uint64_t)1 << 62) | (NUM2ULL(rb_obj_id(obj)) & (((uint64_t)1 << 62) - 1));
|
|
1094
|
+
r = rorb_out_begin_value(out, key, n, cp, cl, RTEST(chunked));
|
|
1095
|
+
}
|
|
1096
|
+
RB_GC_GUARD(ids);
|
|
1097
|
+
return r ? Qtrue : Qfalse;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
static VALUE out_end_value(VALUE self) {
|
|
1101
|
+
rorb_out_end_value(OUT(self));
|
|
1102
|
+
return self;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/* [kind, slot, ids]: kind 0 null, 1 an indirection (value_at(slot)), 2 a
|
|
1106
|
+
new value (keep_value(slot, obj), read its state, end_value). */
|
|
1107
|
+
static VALUE in_read_value_header(VALUE self) {
|
|
1108
|
+
rorb_in* in = IN(self);
|
|
1109
|
+
size_t slot = 0, count = 0, i;
|
|
1110
|
+
int32_t kind = rorb_in_read_value_header(in, &slot, &count);
|
|
1111
|
+
VALUE ids = rb_ary_new();
|
|
1112
|
+
for (i = 0; kind == RORB_VALUE_NEW && i < count; ++i) {
|
|
1113
|
+
size_t len = 0;
|
|
1114
|
+
const char* id = rorb_in_value_id(in, i, &len);
|
|
1115
|
+
rb_ary_push(ids, utf8(id, len));
|
|
1116
|
+
}
|
|
1117
|
+
return rb_ary_new_from_args(3, INT2NUM(kind), SIZET2NUM(slot), ids);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
static VALUE in_value_at(VALUE self, VALUE slot) {
|
|
1121
|
+
host* h = rorb_in_get_value(IN(self), NUM2SIZET(slot));
|
|
1122
|
+
return h ? h->obj : Qnil;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
static VALUE in_keep_value(VALUE self, VALUE slot, VALUE obj) {
|
|
1126
|
+
rorb_in* in = IN(self);
|
|
1127
|
+
host* h = host_retain(obj);
|
|
1128
|
+
if (rorb_in_keeps_hosts(in))
|
|
1129
|
+
rorb_in_set_host_value(in, NUM2SIZET(slot), (uint64_t)(uintptr_t)h, h, host_release);
|
|
1130
|
+
else
|
|
1131
|
+
rorb_in_set_value(in, NUM2SIZET(slot), h, host_release);
|
|
1132
|
+
return obj;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
static VALUE in_end_value(VALUE self) {
|
|
1136
|
+
rorb_in_end_value(IN(self));
|
|
1137
|
+
return self;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/* The valuetypes the core reads in anys and does not know:
|
|
1141
|
+
Rustorb.resolve_value_tc(id) gives their TypeCode. */
|
|
1142
|
+
struct resolve_call {
|
|
1143
|
+
const char* id;
|
|
1144
|
+
size_t len;
|
|
1145
|
+
rorb_typecode* tc;
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
static VALUE resolve_body(VALUE p) {
|
|
1149
|
+
struct resolve_call* c = (struct resolve_call*)p;
|
|
1150
|
+
VALUE tc = rb_funcall(mRustorb, rb_intern("resolve_value_tc"), 1, utf8(c->id, c->len));
|
|
1151
|
+
if (!NIL_P(tc)) c->tc = rorb_tc_clone(TC(tc));
|
|
1152
|
+
return Qnil;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
static void* resolve_gvl(void* p) {
|
|
1156
|
+
int state = 0;
|
|
1157
|
+
rb_protect(resolve_body, (VALUE)p, &state);
|
|
1158
|
+
if (state) rb_set_errinfo(Qnil);
|
|
1159
|
+
return NULL;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
static rorb_typecode* resolve_value_type(void* context, const char* id, size_t len) {
|
|
1163
|
+
struct resolve_call c;
|
|
1164
|
+
(void)context;
|
|
1165
|
+
c.id = id;
|
|
1166
|
+
c.len = len;
|
|
1167
|
+
c.tc = NULL;
|
|
1168
|
+
with_gvl(resolve_gvl, &c);
|
|
1169
|
+
return c.tc;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/* --- callback AMI ----------------------------------------------------------------- */
|
|
1173
|
+
|
|
1174
|
+
/* A request rorb_object_sendc sent: the arguments, written into anys when
|
|
1175
|
+
sendc_ was called (rorb_out_write_any_value writes them, without the
|
|
1176
|
+
GVL, as often as the core asks); the procs, kept alive by the host of
|
|
1177
|
+
keep until done. */
|
|
1178
|
+
struct sendc_ctx {
|
|
1179
|
+
struct invoke_ctx c;
|
|
1180
|
+
host* keep;
|
|
1181
|
+
rorb_any** anys;
|
|
1182
|
+
size_t count;
|
|
1183
|
+
VALUE done;
|
|
1184
|
+
};
|
|
1185
|
+
|
|
1186
|
+
static rorb_status sendc_write(void* ctx, rorb_out* out) {
|
|
1187
|
+
struct sendc_ctx* s = ctx;
|
|
1188
|
+
size_t i;
|
|
1189
|
+
for (i = 0; i < s->count; ++i) rorb_out_write_any_value(out, s->anys[i]);
|
|
1190
|
+
return RORB_OK;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
struct sendc_done_call {
|
|
1194
|
+
struct sendc_ctx* s;
|
|
1195
|
+
rorb_status st;
|
|
1196
|
+
const rorb_exception* exc;
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
static void* sendc_done_gvl(void* p) {
|
|
1200
|
+
struct sendc_done_call* d = p;
|
|
1201
|
+
VALUE argv[2], error = Qnil;
|
|
1202
|
+
argv[0] = INT2NUM(d->st);
|
|
1203
|
+
argv[1] = Qnil;
|
|
1204
|
+
if (d->st == RORB_SYSTEM_EXCEPTION && d->exc)
|
|
1205
|
+
argv[1] = rb_ary_new_from_args(
|
|
1206
|
+
3, utf8(d->exc->repository_id, d->exc->repository_id_len), UINT2NUM(d->exc->minor),
|
|
1207
|
+
UINT2NUM(d->exc->completed));
|
|
1208
|
+
call_protected(d->s->done, 2, argv, &error);
|
|
1209
|
+
return NULL;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
static void sendc_done(void* ctx, rorb_status st, const rorb_exception* exc) {
|
|
1213
|
+
struct sendc_done_call d;
|
|
1214
|
+
struct sendc_ctx* s = ctx;
|
|
1215
|
+
d.s = s;
|
|
1216
|
+
d.st = st;
|
|
1217
|
+
d.exc = exc;
|
|
1218
|
+
with_gvl(sendc_done_gvl, &d);
|
|
1219
|
+
host_release(s->keep);
|
|
1220
|
+
free(s->anys);
|
|
1221
|
+
free(s);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
struct sendc_call {
|
|
1225
|
+
rorb_object* obj;
|
|
1226
|
+
struct sendc_ctx* s;
|
|
1227
|
+
rorb_status st;
|
|
1228
|
+
rorb_exception exc;
|
|
1229
|
+
};
|
|
1230
|
+
|
|
1231
|
+
static void* sendc_nogvl(void* p) {
|
|
1232
|
+
struct sendc_call* c = p;
|
|
1233
|
+
c->st = rorb_object_sendc(c->obj, &c->s->c.inv, sendc_done, &c->exc);
|
|
1234
|
+
return NULL;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/* Ref#sendc(op, anys, timeout_us, reader, user_exc, done): sends the
|
|
1238
|
+
request without waiting. anys are the in and inout arguments (Native::Any
|
|
1239
|
+
values of their types); reader.call(in) reads the reply and
|
|
1240
|
+
user_exc.call(id, in) a user exception (as for invoke, on a thread of the
|
|
1241
|
+
reply pool); done.call(status, [id, minor, completed] or nil) follows
|
|
1242
|
+
(RORB_OK, RORB_USER_EXCEPTION, RORB_SYSTEM_EXCEPTION or
|
|
1243
|
+
RORB_CALLBACK_FAILED). Errors the procs raise go nowhere: they keep
|
|
1244
|
+
them. */
|
|
1245
|
+
static VALUE ref_sendc(VALUE self, VALUE op, VALUE anys, VALUE timeout, VALUE reader,
|
|
1246
|
+
VALUE user_exc, VALUE done) {
|
|
1247
|
+
struct sendc_call c;
|
|
1248
|
+
struct sendc_ctx* s;
|
|
1249
|
+
size_t i, n;
|
|
1250
|
+
VALUE keep;
|
|
1251
|
+
Check_Type(anys, T_ARRAY);
|
|
1252
|
+
op = utf8_arg(op);
|
|
1253
|
+
n = (size_t)RARRAY_LEN(anys);
|
|
1254
|
+
for (i = 0; i < n; ++i) ANY(rb_ary_entry(anys, (long)i)); /* type checks */
|
|
1255
|
+
s = calloc(1, sizeof *s);
|
|
1256
|
+
if (!s) rb_raise(rb_eNoMemError, "rustorb: no memory for a request");
|
|
1257
|
+
s->anys = calloc(n + 1, sizeof *s->anys);
|
|
1258
|
+
if (!s->anys) {
|
|
1259
|
+
free(s);
|
|
1260
|
+
rb_raise(rb_eNoMemError, "rustorb: no memory for a request");
|
|
1261
|
+
}
|
|
1262
|
+
for (i = 0; i < n; ++i) s->anys[i] = ANY(rb_ary_entry(anys, (long)i));
|
|
1263
|
+
s->count = n;
|
|
1264
|
+
keep = rb_ary_new_from_args(4, rb_ary_dup(anys), reader, user_exc, done);
|
|
1265
|
+
s->keep = host_retain(keep);
|
|
1266
|
+
s->done = done;
|
|
1267
|
+
s->c.writer = Qnil;
|
|
1268
|
+
s->c.reader = reader;
|
|
1269
|
+
s->c.user_exc = user_exc;
|
|
1270
|
+
s->c.error = Qnil;
|
|
1271
|
+
s->c.user_error = Qnil;
|
|
1272
|
+
s->c.inv.operation = RSTRING_PTR(op);
|
|
1273
|
+
s->c.inv.operation_len = (size_t)RSTRING_LEN(op);
|
|
1274
|
+
s->c.inv.timeout_us = NIL_P(timeout) ? -1 : NUM2LL(timeout);
|
|
1275
|
+
s->c.inv.context = s;
|
|
1276
|
+
s->c.inv.write_args = sendc_write;
|
|
1277
|
+
s->c.inv.read_reply = read_reply;
|
|
1278
|
+
s->c.inv.read_user_exception = read_user_exception;
|
|
1279
|
+
memset(&c, 0, sizeof c);
|
|
1280
|
+
c.obj = OBJ(self);
|
|
1281
|
+
c.s = s;
|
|
1282
|
+
blocking(sendc_nogvl, &c);
|
|
1283
|
+
RB_GC_GUARD(op);
|
|
1284
|
+
RB_GC_GUARD(keep);
|
|
1285
|
+
if (c.st != RORB_OK) {
|
|
1286
|
+
host_release(s->keep);
|
|
1287
|
+
free(s->anys);
|
|
1288
|
+
free(s);
|
|
1289
|
+
raise_status(c.st, &c.exc);
|
|
1290
|
+
}
|
|
1291
|
+
return Qnil;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/* Native.cdr_encode(little_endian, writer): the bytes writer.call(out)
|
|
1295
|
+
writes on a standalone stream (rorb_cdr_encode). */
|
|
1296
|
+
struct cdr_ctx {
|
|
1297
|
+
VALUE proc;
|
|
1298
|
+
VALUE error;
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
static rorb_status cdr_write(void* ctx, rorb_out* out) {
|
|
1302
|
+
struct cdr_ctx* c = ctx;
|
|
1303
|
+
VALUE o = wrap_borrowed(cOut, out);
|
|
1304
|
+
VALUE r = call_protected(c->proc, 1, &o, &c->error);
|
|
1305
|
+
invalidate(o);
|
|
1306
|
+
return r == Qundef ? RORB_CALLBACK_FAILED : RORB_OK;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
static VALUE native_cdr_encode(VALUE self, VALUE little, VALUE writer) {
|
|
1310
|
+
struct cdr_ctx c;
|
|
1311
|
+
rorb_bytes bytes;
|
|
1312
|
+
rorb_exception exc;
|
|
1313
|
+
rorb_status st;
|
|
1314
|
+
VALUE r;
|
|
1315
|
+
(void)self;
|
|
1316
|
+
c.proc = writer;
|
|
1317
|
+
c.error = Qnil;
|
|
1318
|
+
memset(&bytes, 0, sizeof bytes);
|
|
1319
|
+
memset(&exc, 0, sizeof exc);
|
|
1320
|
+
st = rorb_cdr_encode(cdr_write, &c, RTEST(little), &bytes, &exc);
|
|
1321
|
+
if (!NIL_P(c.error)) {
|
|
1322
|
+
rorb_exception_clear(&exc);
|
|
1323
|
+
rb_exc_raise(c.error);
|
|
1324
|
+
}
|
|
1325
|
+
if (st != RORB_OK) raise_status(st, &exc);
|
|
1326
|
+
r = rb_str_new((const char*)bytes.data, (long)bytes.len);
|
|
1327
|
+
rorb_bytes_free(bytes);
|
|
1328
|
+
return r;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
/* Native.cdr_decode(bytes, little_endian, reader): reader.call(in) on a
|
|
1332
|
+
stream over bytes (rorb_in_from_bytes); returns what it returns. */
|
|
1333
|
+
static VALUE native_cdr_decode(VALUE self, VALUE bytes, VALUE little, VALUE reader) {
|
|
1334
|
+
rorb_in* in = NULL;
|
|
1335
|
+
VALUE i, r, error = Qnil;
|
|
1336
|
+
(void)self;
|
|
1337
|
+
StringValue(bytes);
|
|
1338
|
+
CHECK(rorb_in_from_bytes((const uint8_t*)RSTRING_PTR(bytes), (size_t)RSTRING_LEN(bytes),
|
|
1339
|
+
RTEST(little), NULL, &in, EXC));
|
|
1340
|
+
i = wrap_borrowed(cIn, in);
|
|
1341
|
+
r = call_protected(reader, 1, &i, &error);
|
|
1342
|
+
invalidate(i);
|
|
1343
|
+
rorb_in_release(in);
|
|
1344
|
+
RB_GC_GUARD(bytes);
|
|
1345
|
+
if (r == Qundef) rb_exc_raise(error);
|
|
1346
|
+
return r;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/* --- TypeCodes ------------------------------------------------------------------- */
|
|
1350
|
+
|
|
1351
|
+
static VALUE tc_simple(VALUE klass, VALUE kind) {
|
|
1352
|
+
rorb_typecode* tc = NULL;
|
|
1353
|
+
(void)klass;
|
|
1354
|
+
CHECK(rorb_tc_simple(NUM2UINT(kind), &tc, EXC));
|
|
1355
|
+
return W_TC(tc);
|
|
1356
|
+
}
|
|
1357
|
+
static VALUE tc_string(VALUE klass, VALUE wide, VALUE bound) {
|
|
1358
|
+
rorb_typecode* tc = NULL;
|
|
1359
|
+
(void)klass;
|
|
1360
|
+
CHECK(rorb_tc_string(RTEST(wide), NUM2UINT(bound), &tc, EXC));
|
|
1361
|
+
return W_TC(tc);
|
|
1362
|
+
}
|
|
1363
|
+
static VALUE tc_fixed(VALUE klass, VALUE digits, VALUE scale) {
|
|
1364
|
+
rorb_typecode* tc = NULL;
|
|
1365
|
+
(void)klass;
|
|
1366
|
+
CHECK(rorb_tc_fixed((uint16_t)NUM2UINT(digits), (int16_t)NUM2INT(scale), &tc, EXC));
|
|
1367
|
+
return W_TC(tc);
|
|
1368
|
+
}
|
|
1369
|
+
static VALUE tc_sequence(VALUE klass, VALUE content, VALUE bound) {
|
|
1370
|
+
rorb_typecode* tc = NULL;
|
|
1371
|
+
(void)klass;
|
|
1372
|
+
CHECK(rorb_tc_sequence(TC(content), NUM2UINT(bound), &tc, EXC));
|
|
1373
|
+
return W_TC(tc);
|
|
1374
|
+
}
|
|
1375
|
+
static VALUE tc_array(VALUE klass, VALUE content, VALUE length) {
|
|
1376
|
+
rorb_typecode* tc = NULL;
|
|
1377
|
+
(void)klass;
|
|
1378
|
+
CHECK(rorb_tc_array(TC(content), NUM2UINT(length), &tc, EXC));
|
|
1379
|
+
return W_TC(tc);
|
|
1380
|
+
}
|
|
1381
|
+
static VALUE tc_alias(VALUE klass, VALUE kind, VALUE id, VALUE name, VALUE content) {
|
|
1382
|
+
rorb_typecode* tc = NULL;
|
|
1383
|
+
(void)klass;
|
|
1384
|
+
id = utf8_arg(id);
|
|
1385
|
+
name = utf8_arg(name);
|
|
1386
|
+
CHECK(rorb_tc_alias(NUM2UINT(kind), RSTRING_PTR(id), (size_t)RSTRING_LEN(id),
|
|
1387
|
+
RSTRING_PTR(name), (size_t)RSTRING_LEN(name), TC(content), &tc, EXC));
|
|
1388
|
+
return W_TC(tc);
|
|
1389
|
+
}
|
|
1390
|
+
static VALUE tc_interface(VALUE klass, VALUE kind, VALUE id, VALUE name) {
|
|
1391
|
+
rorb_typecode* tc = NULL;
|
|
1392
|
+
(void)klass;
|
|
1393
|
+
id = utf8_arg(id);
|
|
1394
|
+
name = utf8_arg(name);
|
|
1395
|
+
CHECK(rorb_tc_interface(NUM2UINT(kind), RSTRING_PTR(id), (size_t)RSTRING_LEN(id),
|
|
1396
|
+
RSTRING_PTR(name), (size_t)RSTRING_LEN(name), &tc, EXC));
|
|
1397
|
+
return W_TC(tc);
|
|
1398
|
+
}
|
|
1399
|
+
static VALUE tc_recursive(VALUE klass, VALUE id) {
|
|
1400
|
+
rorb_typecode* tc = NULL;
|
|
1401
|
+
(void)klass;
|
|
1402
|
+
id = utf8_arg(id);
|
|
1403
|
+
CHECK(rorb_tc_recursive(RSTRING_PTR(id), (size_t)RSTRING_LEN(id), &tc, EXC));
|
|
1404
|
+
return W_TC(tc);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
/* Names (Strings) and TypeCodes as C arrays; the Strings stay in keep. */
|
|
1408
|
+
static void member_arrays(VALUE names, VALUE types, size_t n, const char** cn, size_t* cl,
|
|
1409
|
+
const rorb_typecode** ct, VALUE keep) {
|
|
1410
|
+
size_t i;
|
|
1411
|
+
for (i = 0; i < n; ++i) {
|
|
1412
|
+
VALUE s = utf8_arg(rb_ary_entry(names, (long)i));
|
|
1413
|
+
rb_ary_push(keep, s);
|
|
1414
|
+
cn[i] = RSTRING_PTR(s);
|
|
1415
|
+
cl[i] = (size_t)RSTRING_LEN(s);
|
|
1416
|
+
if (ct) ct[i] = TC(rb_ary_entry(types, (long)i));
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
static VALUE tc_struct(VALUE klass, VALUE kind, VALUE id, VALUE name, VALUE names, VALUE types) {
|
|
1421
|
+
rorb_typecode* tc = NULL;
|
|
1422
|
+
size_t n;
|
|
1423
|
+
const char** cn;
|
|
1424
|
+
size_t* cl;
|
|
1425
|
+
const rorb_typecode** ct;
|
|
1426
|
+
VALUE keep = rb_ary_new();
|
|
1427
|
+
(void)klass;
|
|
1428
|
+
Check_Type(names, T_ARRAY);
|
|
1429
|
+
Check_Type(types, T_ARRAY);
|
|
1430
|
+
n = (size_t)RARRAY_LEN(names);
|
|
1431
|
+
cn = ALLOCA_N(const char*, n + 1);
|
|
1432
|
+
cl = ALLOCA_N(size_t, n + 1);
|
|
1433
|
+
ct = ALLOCA_N(const rorb_typecode*, n + 1);
|
|
1434
|
+
member_arrays(names, types, n, cn, cl, ct, keep);
|
|
1435
|
+
id = utf8_arg(id);
|
|
1436
|
+
name = utf8_arg(name);
|
|
1437
|
+
CHECK(rorb_tc_struct(NUM2UINT(kind), RSTRING_PTR(id), (size_t)RSTRING_LEN(id),
|
|
1438
|
+
RSTRING_PTR(name), (size_t)RSTRING_LEN(name), n, cn, cl, ct, &tc, EXC));
|
|
1439
|
+
RB_GC_GUARD(keep);
|
|
1440
|
+
return W_TC(tc);
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
/* TC.value(kind, id, name, modifier, base, names, types, visibilities):
|
|
1444
|
+
a valuetype (TK_VALUE) or eventtype (TK_EVENT); base nil for none. */
|
|
1445
|
+
static VALUE tc_value(int argc, VALUE* argv, VALUE klass) {
|
|
1446
|
+
VALUE kind, id, name, modifier, base, names, types, vis;
|
|
1447
|
+
rorb_typecode* tc = NULL;
|
|
1448
|
+
size_t n, i;
|
|
1449
|
+
const char** cn;
|
|
1450
|
+
size_t* cl;
|
|
1451
|
+
const rorb_typecode** ct;
|
|
1452
|
+
int16_t* cv;
|
|
1453
|
+
VALUE keep = rb_ary_new();
|
|
1454
|
+
(void)klass;
|
|
1455
|
+
rb_scan_args(argc, argv, "8", &kind, &id, &name, &modifier, &base, &names, &types, &vis);
|
|
1456
|
+
Check_Type(names, T_ARRAY);
|
|
1457
|
+
Check_Type(types, T_ARRAY);
|
|
1458
|
+
Check_Type(vis, T_ARRAY);
|
|
1459
|
+
n = (size_t)RARRAY_LEN(names);
|
|
1460
|
+
if ((size_t)RARRAY_LEN(types) != n || (size_t)RARRAY_LEN(vis) != n)
|
|
1461
|
+
rb_raise(rb_eArgError, "names, types and visibilities differ in length");
|
|
1462
|
+
cn = ALLOCA_N(const char*, n + 1);
|
|
1463
|
+
cl = ALLOCA_N(size_t, n + 1);
|
|
1464
|
+
ct = ALLOCA_N(const rorb_typecode*, n + 1);
|
|
1465
|
+
cv = ALLOCA_N(int16_t, n + 1);
|
|
1466
|
+
member_arrays(names, types, n, cn, cl, ct, keep);
|
|
1467
|
+
for (i = 0; i < n; i++) cv[i] = (int16_t)NUM2INT(rb_ary_entry(vis, (long)i));
|
|
1468
|
+
id = utf8_arg(id);
|
|
1469
|
+
name = utf8_arg(name);
|
|
1470
|
+
CHECK(rorb_tc_value(NUM2UINT(kind), RSTRING_PTR(id), (size_t)RSTRING_LEN(id), RSTRING_PTR(name),
|
|
1471
|
+
(size_t)RSTRING_LEN(name), (int16_t)NUM2INT(modifier),
|
|
1472
|
+
NIL_P(base) ? NULL : TC(base), n, cn, cl, ct, cv, &tc, EXC));
|
|
1473
|
+
RB_GC_GUARD(keep);
|
|
1474
|
+
return W_TC(tc);
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
static VALUE tc_union(VALUE klass, VALUE id, VALUE name, VALUE disc, VALUE labels,
|
|
1478
|
+
VALUE default_index, VALUE names, VALUE types) {
|
|
1479
|
+
rorb_typecode* tc = NULL;
|
|
1480
|
+
size_t n, i;
|
|
1481
|
+
const char** cn;
|
|
1482
|
+
size_t* cl;
|
|
1483
|
+
const rorb_typecode** ct;
|
|
1484
|
+
uint64_t* lb;
|
|
1485
|
+
VALUE keep = rb_ary_new();
|
|
1486
|
+
(void)klass;
|
|
1487
|
+
Check_Type(names, T_ARRAY);
|
|
1488
|
+
Check_Type(types, T_ARRAY);
|
|
1489
|
+
Check_Type(labels, T_ARRAY);
|
|
1490
|
+
n = (size_t)RARRAY_LEN(names);
|
|
1491
|
+
cn = ALLOCA_N(const char*, n + 1);
|
|
1492
|
+
cl = ALLOCA_N(size_t, n + 1);
|
|
1493
|
+
ct = ALLOCA_N(const rorb_typecode*, n + 1);
|
|
1494
|
+
lb = ALLOCA_N(uint64_t, n + 1);
|
|
1495
|
+
member_arrays(names, types, n, cn, cl, ct, keep);
|
|
1496
|
+
for (i = 0; i < n; ++i) lb[i] = NUM2ULL(rb_ary_entry(labels, (long)i));
|
|
1497
|
+
id = utf8_arg(id);
|
|
1498
|
+
name = utf8_arg(name);
|
|
1499
|
+
CHECK(rorb_tc_union(RSTRING_PTR(id), (size_t)RSTRING_LEN(id), RSTRING_PTR(name),
|
|
1500
|
+
(size_t)RSTRING_LEN(name), TC(disc), n, lb, NUM2INT(default_index), cn, cl,
|
|
1501
|
+
ct, &tc, EXC));
|
|
1502
|
+
RB_GC_GUARD(keep);
|
|
1503
|
+
return W_TC(tc);
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
static VALUE tc_enum(VALUE klass, VALUE id, VALUE name, VALUE names) {
|
|
1507
|
+
rorb_typecode* tc = NULL;
|
|
1508
|
+
size_t n;
|
|
1509
|
+
const char** cn;
|
|
1510
|
+
size_t* cl;
|
|
1511
|
+
VALUE keep = rb_ary_new();
|
|
1512
|
+
(void)klass;
|
|
1513
|
+
Check_Type(names, T_ARRAY);
|
|
1514
|
+
n = (size_t)RARRAY_LEN(names);
|
|
1515
|
+
cn = ALLOCA_N(const char*, n + 1);
|
|
1516
|
+
cl = ALLOCA_N(size_t, n + 1);
|
|
1517
|
+
member_arrays(names, Qnil, n, cn, cl, NULL, keep);
|
|
1518
|
+
id = utf8_arg(id);
|
|
1519
|
+
name = utf8_arg(name);
|
|
1520
|
+
CHECK(rorb_tc_enum(RSTRING_PTR(id), (size_t)RSTRING_LEN(id), RSTRING_PTR(name),
|
|
1521
|
+
(size_t)RSTRING_LEN(name), n, cn, cl, &tc, EXC));
|
|
1522
|
+
RB_GC_GUARD(keep);
|
|
1523
|
+
return W_TC(tc);
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
static VALUE tc_kind(VALUE self) { return UINT2NUM(rorb_tc_kind(TC(self))); }
|
|
1527
|
+
static VALUE tc_id(VALUE self) {
|
|
1528
|
+
const char* s = NULL;
|
|
1529
|
+
size_t len = 0;
|
|
1530
|
+
CHECK(rorb_tc_id(TC(self), &s, &len, EXC));
|
|
1531
|
+
return utf8(s, len);
|
|
1532
|
+
}
|
|
1533
|
+
static VALUE tc_name(VALUE self) {
|
|
1534
|
+
const char* s = NULL;
|
|
1535
|
+
size_t len = 0;
|
|
1536
|
+
CHECK(rorb_tc_name(TC(self), &s, &len, EXC));
|
|
1537
|
+
return utf8(s, len);
|
|
1538
|
+
}
|
|
1539
|
+
static VALUE tc_member_count(VALUE self) {
|
|
1540
|
+
uint32_t n = 0;
|
|
1541
|
+
CHECK(rorb_tc_member_count(TC(self), &n, EXC));
|
|
1542
|
+
return UINT2NUM(n);
|
|
1543
|
+
}
|
|
1544
|
+
static VALUE tc_member_name(VALUE self, VALUE i) {
|
|
1545
|
+
const char* s = NULL;
|
|
1546
|
+
size_t len = 0;
|
|
1547
|
+
CHECK(rorb_tc_member_name(TC(self), NUM2UINT(i), &s, &len, EXC));
|
|
1548
|
+
return utf8(s, len);
|
|
1549
|
+
}
|
|
1550
|
+
static VALUE tc_member_type(VALUE self, VALUE i) {
|
|
1551
|
+
rorb_typecode* tc = NULL;
|
|
1552
|
+
CHECK(rorb_tc_member_type(TC(self), NUM2UINT(i), &tc, EXC));
|
|
1553
|
+
return W_TC(tc);
|
|
1554
|
+
}
|
|
1555
|
+
static VALUE tc_member_label(VALUE self, VALUE i) {
|
|
1556
|
+
rorb_any* a = NULL;
|
|
1557
|
+
CHECK(rorb_tc_member_label(TC(self), NUM2UINT(i), &a, EXC));
|
|
1558
|
+
return W_ANY(a);
|
|
1559
|
+
}
|
|
1560
|
+
static VALUE tc_discriminator_type(VALUE self) {
|
|
1561
|
+
rorb_typecode* tc = NULL;
|
|
1562
|
+
CHECK(rorb_tc_discriminator_type(TC(self), &tc, EXC));
|
|
1563
|
+
return W_TC(tc);
|
|
1564
|
+
}
|
|
1565
|
+
static VALUE tc_default_index(VALUE self) {
|
|
1566
|
+
int32_t i = -1;
|
|
1567
|
+
CHECK(rorb_tc_default_index(TC(self), &i, EXC));
|
|
1568
|
+
return INT2NUM(i);
|
|
1569
|
+
}
|
|
1570
|
+
static VALUE tc_length(VALUE self) {
|
|
1571
|
+
uint32_t n = 0;
|
|
1572
|
+
CHECK(rorb_tc_length(TC(self), &n, EXC));
|
|
1573
|
+
return UINT2NUM(n);
|
|
1574
|
+
}
|
|
1575
|
+
static VALUE tc_content_type(VALUE self) {
|
|
1576
|
+
rorb_typecode* tc = NULL;
|
|
1577
|
+
CHECK(rorb_tc_content_type(TC(self), &tc, EXC));
|
|
1578
|
+
return W_TC(tc);
|
|
1579
|
+
}
|
|
1580
|
+
static VALUE tc_type_modifier(VALUE self) {
|
|
1581
|
+
int16_t v = 0;
|
|
1582
|
+
CHECK(rorb_tc_type_modifier(TC(self), &v, EXC));
|
|
1583
|
+
return INT2NUM(v);
|
|
1584
|
+
}
|
|
1585
|
+
static VALUE tc_member_visibility(VALUE self, VALUE index) {
|
|
1586
|
+
int16_t v = 0;
|
|
1587
|
+
CHECK(rorb_tc_member_visibility(TC(self), NUM2UINT(index), &v, EXC));
|
|
1588
|
+
return INT2NUM(v);
|
|
1589
|
+
}
|
|
1590
|
+
static VALUE tc_concrete_base_type(VALUE self) {
|
|
1591
|
+
rorb_typecode* tc = NULL;
|
|
1592
|
+
CHECK(rorb_tc_concrete_base_type(TC(self), &tc, EXC));
|
|
1593
|
+
return W_TC(tc);
|
|
1594
|
+
}
|
|
1595
|
+
static VALUE tc_fixed_digits(VALUE self) {
|
|
1596
|
+
uint16_t d = 0;
|
|
1597
|
+
CHECK(rorb_tc_fixed_digits(TC(self), &d, EXC));
|
|
1598
|
+
return UINT2NUM(d);
|
|
1599
|
+
}
|
|
1600
|
+
static VALUE tc_fixed_scale(VALUE self) {
|
|
1601
|
+
int16_t s = 0;
|
|
1602
|
+
CHECK(rorb_tc_fixed_scale(TC(self), &s, EXC));
|
|
1603
|
+
return INT2NUM(s);
|
|
1604
|
+
}
|
|
1605
|
+
static VALUE tc_equal(VALUE self, VALUE other) {
|
|
1606
|
+
return rorb_tc_equal(TC(self), TC(other)) ? Qtrue : Qfalse;
|
|
1607
|
+
}
|
|
1608
|
+
static VALUE tc_equivalent(VALUE self, VALUE other) {
|
|
1609
|
+
return rorb_tc_equivalent(TC(self), TC(other)) ? Qtrue : Qfalse;
|
|
1610
|
+
}
|
|
1611
|
+
static VALUE tc_unaliased(VALUE self) { return W_TC(rorb_tc_unaliased(TC(self))); }
|
|
1612
|
+
static VALUE tc_compact(VALUE self) { return W_TC(rorb_tc_compact(TC(self))); }
|
|
1613
|
+
|
|
1614
|
+
/* --- anys -------------------------------------------------------------------------- */
|
|
1615
|
+
|
|
1616
|
+
struct any_ctx {
|
|
1617
|
+
VALUE proc;
|
|
1618
|
+
VALUE error;
|
|
1619
|
+
rorb_out* out;
|
|
1620
|
+
rorb_in* in;
|
|
1621
|
+
};
|
|
1622
|
+
|
|
1623
|
+
static void* cb_any_write(void* p) {
|
|
1624
|
+
struct any_ctx* c = p;
|
|
1625
|
+
VALUE out = wrap_borrowed(cOut, c->out);
|
|
1626
|
+
VALUE r = call_protected(c->proc, 1, &out, &c->error);
|
|
1627
|
+
invalidate(out);
|
|
1628
|
+
return r == Qundef ? (void*)1 : NULL;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
static void* cb_any_read(void* p) {
|
|
1632
|
+
struct any_ctx* c = p;
|
|
1633
|
+
VALUE in = wrap_borrowed(cIn, c->in);
|
|
1634
|
+
VALUE r = call_protected(c->proc, 1, &in, &c->error);
|
|
1635
|
+
invalidate(in);
|
|
1636
|
+
return r == Qundef ? (void*)1 : NULL;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
static rorb_status any_write(void* ctx, rorb_out* out) {
|
|
1640
|
+
struct any_ctx* c = ctx;
|
|
1641
|
+
c->out = out;
|
|
1642
|
+
return with_gvl(cb_any_write, c) ? RORB_CALLBACK_FAILED : RORB_OK;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
static rorb_status any_read(void* ctx, rorb_in* in) {
|
|
1646
|
+
struct any_ctx* c = ctx;
|
|
1647
|
+
c->in = in;
|
|
1648
|
+
return with_gvl(cb_any_read, c) ? RORB_CALLBACK_FAILED : RORB_OK;
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
static VALUE any_new(VALUE klass) {
|
|
1652
|
+
(void)klass;
|
|
1653
|
+
return W_ANY(rorb_any_new());
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
/* Any.insert(tc, writer): an any of type tc with what writer.call(out)
|
|
1657
|
+
writes. */
|
|
1658
|
+
static VALUE any_insert(VALUE klass, VALUE tc, VALUE writer) {
|
|
1659
|
+
struct any_ctx c;
|
|
1660
|
+
rorb_any* a = NULL;
|
|
1661
|
+
rorb_exception exc;
|
|
1662
|
+
rorb_status st;
|
|
1663
|
+
(void)klass;
|
|
1664
|
+
memset(&c, 0, sizeof c);
|
|
1665
|
+
memset(&exc, 0, sizeof exc);
|
|
1666
|
+
c.proc = writer;
|
|
1667
|
+
c.error = Qnil;
|
|
1668
|
+
st = rorb_any_insert(TC(tc), any_write, &c, &a, &exc);
|
|
1669
|
+
RB_GC_GUARD(writer);
|
|
1670
|
+
if (!NIL_P(c.error)) {
|
|
1671
|
+
rorb_exception_clear(&exc);
|
|
1672
|
+
rb_exc_raise(c.error);
|
|
1673
|
+
}
|
|
1674
|
+
if (st != RORB_OK) raise_status(st, &exc);
|
|
1675
|
+
return W_ANY(a);
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
static VALUE any_typed(VALUE klass, VALUE tc) {
|
|
1679
|
+
(void)klass;
|
|
1680
|
+
return W_ANY(rorb_any_typed(TC(tc)));
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
/* any.extract(reader): reader.call(in) reads the value. */
|
|
1684
|
+
static VALUE any_extract(VALUE self, VALUE reader) {
|
|
1685
|
+
struct any_ctx c;
|
|
1686
|
+
rorb_exception exc;
|
|
1687
|
+
rorb_status st;
|
|
1688
|
+
memset(&c, 0, sizeof c);
|
|
1689
|
+
memset(&exc, 0, sizeof exc);
|
|
1690
|
+
c.proc = reader;
|
|
1691
|
+
c.error = Qnil;
|
|
1692
|
+
st = rorb_any_extract(ANY(self), any_read, &c, &exc);
|
|
1693
|
+
RB_GC_GUARD(reader);
|
|
1694
|
+
if (!NIL_P(c.error)) {
|
|
1695
|
+
rorb_exception_clear(&exc);
|
|
1696
|
+
rb_exc_raise(c.error);
|
|
1697
|
+
}
|
|
1698
|
+
if (st != RORB_OK) raise_status(st, &exc);
|
|
1699
|
+
return Qnil;
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
static VALUE any_type(VALUE self) { return W_TC(rorb_any_type(ANY(self))); }
|
|
1703
|
+
static VALUE any_set_type(VALUE self, VALUE tc) {
|
|
1704
|
+
CHECK(rorb_any_set_type(ANY(self), TC(tc), EXC));
|
|
1705
|
+
return self;
|
|
1706
|
+
}
|
|
1707
|
+
static VALUE any_equal(VALUE self, VALUE other) {
|
|
1708
|
+
return rorb_any_equal(ANY(self), ANY(other)) ? Qtrue : Qfalse;
|
|
1709
|
+
}
|
|
1710
|
+
static VALUE any_label(VALUE self) {
|
|
1711
|
+
uint64_t l = 0;
|
|
1712
|
+
return rorb_any_label(ANY(self), &l) ? ULL2NUM(l) : Qnil;
|
|
1713
|
+
}
|
|
1714
|
+
static VALUE any_dup(VALUE self) { return W_ANY(rorb_any_clone(ANY(self))); }
|
|
1715
|
+
|
|
1716
|
+
/* --- servants ------------------------------------------------------------------------ */
|
|
1717
|
+
|
|
1718
|
+
/* The C side of a Ruby servant: what rustorb holds as self. The Ruby object
|
|
1719
|
+
is kept alive while rustorb holds a reference (refs > 0): the registry's
|
|
1720
|
+
mark function marks it. The peer is freed with the Ruby object (the
|
|
1721
|
+
Rustorb::Native::Peer in its ivar), which then is not referenced from
|
|
1722
|
+
rustorb any more, except at exit, when Ruby frees every object: then the
|
|
1723
|
+
peer is left as an orphan (PEER_ORPHAN added to refs) and freed by the
|
|
1724
|
+
last servant_remove_ref. */
|
|
1725
|
+
typedef struct peer {
|
|
1726
|
+
VALUE obj;
|
|
1727
|
+
int refs; /* atomic */
|
|
1728
|
+
char** ids;
|
|
1729
|
+
size_t* id_lens;
|
|
1730
|
+
size_t id_count;
|
|
1731
|
+
struct peer *prev, *next;
|
|
1732
|
+
} peer;
|
|
1733
|
+
|
|
1734
|
+
static peer* peers;
|
|
1735
|
+
|
|
1736
|
+
static void registry_mark(void* unused) {
|
|
1737
|
+
peer* p;
|
|
1738
|
+
(void)unused;
|
|
1739
|
+
for (p = peers; p; p = p->next)
|
|
1740
|
+
if (__atomic_load_n(&p->refs, __ATOMIC_SEQ_CST) > 0) rb_gc_mark(p->obj);
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
#define PEER_ORPHAN (1 << 30)
|
|
1744
|
+
|
|
1745
|
+
static void peer_delete(peer* p) {
|
|
1746
|
+
size_t i;
|
|
1747
|
+
for (i = 0; i < p->id_count; ++i) free(p->ids[i]);
|
|
1748
|
+
free(p->ids);
|
|
1749
|
+
free(p->id_lens);
|
|
1750
|
+
free(p);
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
static void peer_free(void* ptr) {
|
|
1754
|
+
peer* p = ptr;
|
|
1755
|
+
if (p->prev)
|
|
1756
|
+
p->prev->next = p->next;
|
|
1757
|
+
else
|
|
1758
|
+
peers = p->next;
|
|
1759
|
+
if (p->next) p->next->prev = p->prev;
|
|
1760
|
+
if (__atomic_add_fetch(&p->refs, PEER_ORPHAN, __ATOMIC_SEQ_CST) == PEER_ORPHAN) peer_delete(p);
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
static size_t peer_size(const void* ptr) {
|
|
1764
|
+
(void)ptr;
|
|
1765
|
+
return sizeof(peer);
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
static const rb_data_type_t peer_type = {
|
|
1769
|
+
"rustorb_peer", {NULL, peer_free, peer_size, NULL, {0}}, NULL, NULL, 0};
|
|
1770
|
+
|
|
1771
|
+
static void servant_add_ref(void* self) {
|
|
1772
|
+
__atomic_add_fetch(&((peer*)self)->refs, 1, __ATOMIC_SEQ_CST);
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
static void servant_remove_ref(void* self) {
|
|
1776
|
+
if (__atomic_sub_fetch(&((peer*)self)->refs, 1, __ATOMIC_SEQ_CST) == PEER_ORPHAN)
|
|
1777
|
+
peer_delete(self);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
static int32_t servant_is_a(void* self, const char* id, size_t len) {
|
|
1781
|
+
peer* p = self;
|
|
1782
|
+
size_t i;
|
|
1783
|
+
for (i = 0; i < p->id_count; ++i)
|
|
1784
|
+
if (p->id_lens[i] == len && memcmp(p->ids[i], id, len) == 0) return 1;
|
|
1785
|
+
return len == 28 && memcmp(id, "IDL:omg.org/CORBA/Object:1.0", 28) == 0;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
struct dispatch_ctx {
|
|
1789
|
+
peer* p;
|
|
1790
|
+
const char* op;
|
|
1791
|
+
size_t op_len;
|
|
1792
|
+
rorb_in* in;
|
|
1793
|
+
rorb_server_reply* reply;
|
|
1794
|
+
rorb_status st;
|
|
1795
|
+
};
|
|
1796
|
+
|
|
1797
|
+
static VALUE dispatch_body(VALUE arg) {
|
|
1798
|
+
struct dispatch_ctx* c = (struct dispatch_ctx*)arg;
|
|
1799
|
+
VALUE in = wrap_borrowed(cIn, c->in);
|
|
1800
|
+
VALUE reply = wrap_borrowed(cReply, c->reply);
|
|
1801
|
+
VALUE r;
|
|
1802
|
+
r = rb_funcall(c->p->obj, id_dispatch, 3, utf8(c->op, c->op_len), in, reply);
|
|
1803
|
+
invalidate(in);
|
|
1804
|
+
invalidate(reply);
|
|
1805
|
+
return r;
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
static void* do_dispatch(void* arg) {
|
|
1809
|
+
struct dispatch_ctx* c = arg;
|
|
1810
|
+
int state = 0;
|
|
1811
|
+
VALUE r = rb_protect(dispatch_body, (VALUE)c, &state);
|
|
1812
|
+
if (state) {
|
|
1813
|
+
/* The Ruby side answers every exception of the servant; this is one of
|
|
1814
|
+
its own. */
|
|
1815
|
+
VALUE e = rb_errinfo();
|
|
1816
|
+
rb_set_errinfo(Qnil);
|
|
1817
|
+
rb_funcall(rb_stderr, rb_intern("puts"), 1,
|
|
1818
|
+
rb_str_concat(rb_str_new_cstr("rustorb: upcall failed: "), rb_inspect(e)));
|
|
1819
|
+
rorb_server_reply_system_exception(c->reply, "IDL:omg.org/CORBA/UNKNOWN:1.0", 29, 0,
|
|
1820
|
+
RORB_COMPLETED_MAYBE);
|
|
1821
|
+
c->st = RORB_SYSTEM_EXCEPTION;
|
|
1822
|
+
} else {
|
|
1823
|
+
c->st = RTEST(r) ? RORB_OK : RORB_SYSTEM_EXCEPTION;
|
|
1824
|
+
}
|
|
1825
|
+
return c;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
static rorb_status servant_dispatch(void* self, const char* op, size_t op_len, rorb_in* in,
|
|
1829
|
+
rorb_server_reply* reply) {
|
|
1830
|
+
struct dispatch_ctx c;
|
|
1831
|
+
c.p = self;
|
|
1832
|
+
c.op = op;
|
|
1833
|
+
c.op_len = op_len;
|
|
1834
|
+
c.in = in;
|
|
1835
|
+
c.reply = reply;
|
|
1836
|
+
c.st = RORB_OK;
|
|
1837
|
+
if (!with_gvl(do_dispatch, &c)) {
|
|
1838
|
+
rorb_server_reply_system_exception(reply, "IDL:omg.org/CORBA/TRANSIENT:1.0", 31, 0,
|
|
1839
|
+
RORB_COMPLETED_NO);
|
|
1840
|
+
return RORB_SYSTEM_EXCEPTION;
|
|
1841
|
+
}
|
|
1842
|
+
return c.st;
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
static const rorb_servant_vtable servant_vtable = {servant_dispatch, servant_is_a,
|
|
1846
|
+
servant_add_ref, servant_remove_ref};
|
|
1847
|
+
|
|
1848
|
+
static peer* peer_of(VALUE servant, VALUE ids) {
|
|
1849
|
+
VALUE holder = rb_ivar_get(servant, id_peer_ivar);
|
|
1850
|
+
peer* p;
|
|
1851
|
+
long i;
|
|
1852
|
+
if (!NIL_P(holder)) {
|
|
1853
|
+
TypedData_Get_Struct(holder, peer, &peer_type, p);
|
|
1854
|
+
return p;
|
|
1855
|
+
}
|
|
1856
|
+
Check_Type(ids, T_ARRAY);
|
|
1857
|
+
p = calloc(1, sizeof *p);
|
|
1858
|
+
if (!p) rb_memerror();
|
|
1859
|
+
p->obj = servant;
|
|
1860
|
+
p->id_count = (size_t)RARRAY_LEN(ids);
|
|
1861
|
+
p->ids = calloc(p->id_count + 1, sizeof(char*));
|
|
1862
|
+
p->id_lens = calloc(p->id_count + 1, sizeof(size_t));
|
|
1863
|
+
for (i = 0; i < RARRAY_LEN(ids); ++i) {
|
|
1864
|
+
VALUE s = utf8_arg(rb_ary_entry(ids, i));
|
|
1865
|
+
p->id_lens[i] = (size_t)RSTRING_LEN(s);
|
|
1866
|
+
p->ids[i] = malloc(p->id_lens[i] + 1);
|
|
1867
|
+
memcpy(p->ids[i], RSTRING_PTR(s), p->id_lens[i]);
|
|
1868
|
+
p->ids[i][p->id_lens[i]] = 0;
|
|
1869
|
+
}
|
|
1870
|
+
p->next = peers;
|
|
1871
|
+
if (peers) peers->prev = p;
|
|
1872
|
+
peers = p;
|
|
1873
|
+
holder = TypedData_Wrap_Struct(cPeer, &peer_type, p);
|
|
1874
|
+
rb_ivar_set(servant, id_peer_ivar, holder);
|
|
1875
|
+
return p;
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
/* Rustorb::Native.servant_ref(servant, ids): the rustorb servant of a Ruby
|
|
1879
|
+
servant; ids are its repository ids, its own first. */
|
|
1880
|
+
static VALUE native_servant_ref(VALUE self, VALUE servant, VALUE ids) {
|
|
1881
|
+
peer* p = peer_of(servant, ids);
|
|
1882
|
+
(void)self;
|
|
1883
|
+
return wrap(cServantRef,
|
|
1884
|
+
rorb_servant_get(p, p->ids[0] ? p->ids[0] : "", p->id_lens[0], &servant_vtable),
|
|
1885
|
+
rel_servant);
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
#define SERVANT(v) ((rorb_servant*)unwrap((v), cServantRef))
|
|
1889
|
+
|
|
1890
|
+
/* The PortableServer::Current queries, made by at_home. */
|
|
1891
|
+
struct current_call {
|
|
1892
|
+
int what;
|
|
1893
|
+
rorb_servant* servant;
|
|
1894
|
+
rorb_poa* poa;
|
|
1895
|
+
rorb_bytes id;
|
|
1896
|
+
rorb_object* obj;
|
|
1897
|
+
void* self;
|
|
1898
|
+
int32_t found;
|
|
1899
|
+
rorb_status st;
|
|
1900
|
+
rorb_exception exc;
|
|
1901
|
+
};
|
|
1902
|
+
|
|
1903
|
+
static void* current_nogvl(void* p) {
|
|
1904
|
+
struct current_call* c = p;
|
|
1905
|
+
switch (c->what) {
|
|
1906
|
+
case 0: c->found = rorb_servant_current_reference(c->servant, &c->obj); break;
|
|
1907
|
+
case 1: c->st = rorb_current_get_poa(&c->poa, &c->exc); break;
|
|
1908
|
+
case 2: c->st = rorb_current_get_object_id(&c->id, &c->exc); break;
|
|
1909
|
+
case 3: c->st = rorb_current_get_reference(&c->obj, &c->exc); break;
|
|
1910
|
+
default: c->st = rorb_current_get_servant(&c->self, &c->exc); break;
|
|
1911
|
+
}
|
|
1912
|
+
return NULL;
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
static void current_call(struct current_call* c, int what) {
|
|
1916
|
+
memset(c, 0, sizeof *c);
|
|
1917
|
+
c->what = what;
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
static VALUE servant_ref_current_reference(VALUE self) {
|
|
1921
|
+
struct current_call c;
|
|
1922
|
+
current_call(&c, 0);
|
|
1923
|
+
c.servant = SERVANT(self);
|
|
1924
|
+
at_home(current_nogvl, &c);
|
|
1925
|
+
if (!c.found) return Qfalse;
|
|
1926
|
+
return W_OBJ(c.obj);
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
/* The Ruby servant of a self rustorb gave with a reference added. */
|
|
1930
|
+
static VALUE servant_of(void* self) {
|
|
1931
|
+
peer* p = self;
|
|
1932
|
+
VALUE obj;
|
|
1933
|
+
if (!p) return Qnil;
|
|
1934
|
+
obj = p->obj;
|
|
1935
|
+
servant_remove_ref(p);
|
|
1936
|
+
return obj;
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
static VALUE reply_output(VALUE self) {
|
|
1940
|
+
return wrap_borrowed(cOut, rorb_server_reply_output(unwrap(self, cReply)));
|
|
1941
|
+
}
|
|
1942
|
+
static VALUE reply_user_exception(VALUE self, VALUE id) {
|
|
1943
|
+
id = utf8_arg(id);
|
|
1944
|
+
return wrap_borrowed(cOut, rorb_server_reply_user_exception(unwrap(self, cReply), RSTRING_PTR(id),
|
|
1945
|
+
(size_t)RSTRING_LEN(id)));
|
|
1946
|
+
}
|
|
1947
|
+
static VALUE reply_system_exception(VALUE self, VALUE id, VALUE minor, VALUE completed) {
|
|
1948
|
+
id = utf8_arg(id);
|
|
1949
|
+
rorb_server_reply_system_exception(unwrap(self, cReply), RSTRING_PTR(id),
|
|
1950
|
+
(size_t)RSTRING_LEN(id), NUM2UINT(minor), NUM2UINT(completed));
|
|
1951
|
+
return Qnil;
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
/* --- POA ------------------------------------------------------------------------------ */
|
|
1955
|
+
|
|
1956
|
+
static VALUE poa_name(VALUE self) {
|
|
1957
|
+
size_t len = 0;
|
|
1958
|
+
const char* s = rorb_poa_name(POA(self), &len);
|
|
1959
|
+
return utf8(s, len);
|
|
1960
|
+
}
|
|
1961
|
+
static VALUE poa_parent(VALUE self) { return W_POA(rorb_poa_parent(POA(self))); }
|
|
1962
|
+
static void each_child(void* ctx, rorb_poa* child) {
|
|
1963
|
+
rb_ary_push((VALUE)ctx, W_POA(rorb_poa_clone(child)));
|
|
1964
|
+
}
|
|
1965
|
+
static VALUE poa_children(VALUE self) {
|
|
1966
|
+
VALUE a = rb_ary_new();
|
|
1967
|
+
rorb_poa_children(POA(self), (void*)a, each_child);
|
|
1968
|
+
return a;
|
|
1969
|
+
}
|
|
1970
|
+
static VALUE poa_manager(VALUE self) { return W_MGR(rorb_poa_the_manager(POA(self))); }
|
|
1971
|
+
static VALUE poa_policies(VALUE self) {
|
|
1972
|
+
rorb_policy ps[7];
|
|
1973
|
+
VALUE a = rb_ary_new();
|
|
1974
|
+
int i;
|
|
1975
|
+
rorb_poa_policies(POA(self), ps);
|
|
1976
|
+
for (i = 0; i < 7; ++i) rb_ary_push(a, UINT2NUM(ps[i].value));
|
|
1977
|
+
return a;
|
|
1978
|
+
}
|
|
1979
|
+
/* policies: [[type, value], ...] */
|
|
1980
|
+
static VALUE poa_create_poa(VALUE self, VALUE name, VALUE mgr, VALUE policies) {
|
|
1981
|
+
rorb_poa* child = NULL;
|
|
1982
|
+
rorb_policy* ps;
|
|
1983
|
+
long i, n;
|
|
1984
|
+
Check_Type(policies, T_ARRAY);
|
|
1985
|
+
n = RARRAY_LEN(policies);
|
|
1986
|
+
ps = ALLOCA_N(rorb_policy, n + 1);
|
|
1987
|
+
for (i = 0; i < n; ++i) {
|
|
1988
|
+
VALUE pv = rb_ary_entry(policies, i);
|
|
1989
|
+
ps[i].type = NUM2UINT(rb_ary_entry(pv, 0));
|
|
1990
|
+
ps[i].value = NUM2UINT(rb_ary_entry(pv, 1));
|
|
1991
|
+
}
|
|
1992
|
+
name = utf8_arg(name);
|
|
1993
|
+
CHECK(rorb_poa_create_poa(POA(self), RSTRING_PTR(name), (size_t)RSTRING_LEN(name),
|
|
1994
|
+
unwrap_opt(mgr, cPOAManager), ps, (size_t)n, &child, EXC));
|
|
1995
|
+
return W_POA(child);
|
|
1996
|
+
}
|
|
1997
|
+
static VALUE poa_find_poa(VALUE self, VALUE name, VALUE activate) {
|
|
1998
|
+
rorb_poa* child = NULL;
|
|
1999
|
+
name = utf8_arg(name);
|
|
2000
|
+
CHECK(rorb_poa_find_poa(POA(self), RSTRING_PTR(name), (size_t)RSTRING_LEN(name),
|
|
2001
|
+
RTEST(activate), &child, EXC));
|
|
2002
|
+
return W_POA(child);
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
struct poa_op {
|
|
2006
|
+
rorb_poa* poa;
|
|
2007
|
+
int32_t a, b;
|
|
2008
|
+
rorb_status st;
|
|
2009
|
+
rorb_exception exc;
|
|
2010
|
+
};
|
|
2011
|
+
static void* poa_destroy_nogvl(void* p) {
|
|
2012
|
+
struct poa_op* o = p;
|
|
2013
|
+
o->st = rorb_poa_destroy(o->poa, o->a, o->b, &o->exc);
|
|
2014
|
+
return NULL;
|
|
2015
|
+
}
|
|
2016
|
+
static VALUE poa_destroy(VALUE self, VALUE etherealize, VALUE wait) {
|
|
2017
|
+
struct poa_op o;
|
|
2018
|
+
memset(&o, 0, sizeof o);
|
|
2019
|
+
o.poa = POA(self);
|
|
2020
|
+
o.a = RTEST(etherealize);
|
|
2021
|
+
o.b = RTEST(wait);
|
|
2022
|
+
blocking(poa_destroy_nogvl, &o);
|
|
2023
|
+
if (o.st != RORB_OK) raise_status(o.st, &o.exc);
|
|
2024
|
+
return Qnil;
|
|
2025
|
+
}
|
|
2026
|
+
static VALUE poa_activate_object(VALUE self, VALUE servant) {
|
|
2027
|
+
rorb_bytes id;
|
|
2028
|
+
CHECK(rorb_poa_activate_object(POA(self), SERVANT(servant), &id, EXC));
|
|
2029
|
+
return bytes_str(id);
|
|
2030
|
+
}
|
|
2031
|
+
static VALUE poa_activate_object_with_id(VALUE self, VALUE id, VALUE servant) {
|
|
2032
|
+
StringValue(id);
|
|
2033
|
+
CHECK(rorb_poa_activate_object_with_id(POA(self), (const uint8_t*)RSTRING_PTR(id),
|
|
2034
|
+
(size_t)RSTRING_LEN(id), SERVANT(servant), EXC));
|
|
2035
|
+
return Qnil;
|
|
2036
|
+
}
|
|
2037
|
+
static VALUE poa_deactivate_object(VALUE self, VALUE id) {
|
|
2038
|
+
StringValue(id);
|
|
2039
|
+
CHECK(rorb_poa_deactivate_object(POA(self), (const uint8_t*)RSTRING_PTR(id),
|
|
2040
|
+
(size_t)RSTRING_LEN(id), EXC));
|
|
2041
|
+
return Qnil;
|
|
2042
|
+
}
|
|
2043
|
+
static VALUE poa_servant_to_id(VALUE self, VALUE servant) {
|
|
2044
|
+
rorb_bytes id;
|
|
2045
|
+
CHECK(rorb_poa_servant_to_id(POA(self), SERVANT(servant), &id, EXC));
|
|
2046
|
+
return bytes_str(id);
|
|
2047
|
+
}
|
|
2048
|
+
static VALUE poa_servant_to_reference(VALUE self, VALUE servant) {
|
|
2049
|
+
rorb_object* obj = NULL;
|
|
2050
|
+
CHECK(rorb_poa_servant_to_reference(POA(self), SERVANT(servant), &obj, EXC));
|
|
2051
|
+
return W_OBJ(obj);
|
|
2052
|
+
}
|
|
2053
|
+
static VALUE poa_id_to_servant(VALUE self, VALUE id) {
|
|
2054
|
+
void* s = NULL;
|
|
2055
|
+
StringValue(id);
|
|
2056
|
+
CHECK(rorb_poa_id_to_servant(POA(self), (const uint8_t*)RSTRING_PTR(id), (size_t)RSTRING_LEN(id),
|
|
2057
|
+
&s, EXC));
|
|
2058
|
+
return servant_of(s);
|
|
2059
|
+
}
|
|
2060
|
+
static VALUE poa_id_to_reference(VALUE self, VALUE id) {
|
|
2061
|
+
rorb_object* obj = NULL;
|
|
2062
|
+
StringValue(id);
|
|
2063
|
+
CHECK(rorb_poa_id_to_reference(POA(self), (const uint8_t*)RSTRING_PTR(id),
|
|
2064
|
+
(size_t)RSTRING_LEN(id), &obj, EXC));
|
|
2065
|
+
return W_OBJ(obj);
|
|
2066
|
+
}
|
|
2067
|
+
static VALUE poa_reference_to_id(VALUE self, VALUE ref) {
|
|
2068
|
+
rorb_bytes id;
|
|
2069
|
+
CHECK(rorb_poa_reference_to_id(POA(self), OBJ(ref), &id, EXC));
|
|
2070
|
+
return bytes_str(id);
|
|
2071
|
+
}
|
|
2072
|
+
static VALUE poa_reference_to_servant(VALUE self, VALUE ref) {
|
|
2073
|
+
void* s = NULL;
|
|
2074
|
+
CHECK(rorb_poa_reference_to_servant(POA(self), OBJ(ref), &s, EXC));
|
|
2075
|
+
return servant_of(s);
|
|
2076
|
+
}
|
|
2077
|
+
static VALUE poa_create_reference(VALUE self, VALUE intf) {
|
|
2078
|
+
rorb_object* obj = NULL;
|
|
2079
|
+
intf = utf8_arg(intf);
|
|
2080
|
+
CHECK(rorb_poa_create_reference(POA(self), RSTRING_PTR(intf), (size_t)RSTRING_LEN(intf), &obj,
|
|
2081
|
+
EXC));
|
|
2082
|
+
return W_OBJ(obj);
|
|
2083
|
+
}
|
|
2084
|
+
static VALUE poa_create_reference_with_id(VALUE self, VALUE id, VALUE intf) {
|
|
2085
|
+
rorb_object* obj = NULL;
|
|
2086
|
+
StringValue(id);
|
|
2087
|
+
intf = utf8_arg(intf);
|
|
2088
|
+
CHECK(rorb_poa_create_reference_with_id(POA(self), (const uint8_t*)RSTRING_PTR(id),
|
|
2089
|
+
(size_t)RSTRING_LEN(id), RSTRING_PTR(intf),
|
|
2090
|
+
(size_t)RSTRING_LEN(intf), &obj, EXC));
|
|
2091
|
+
return W_OBJ(obj);
|
|
2092
|
+
}
|
|
2093
|
+
static VALUE poa_get_servant(VALUE self) {
|
|
2094
|
+
void* s = NULL;
|
|
2095
|
+
CHECK(rorb_poa_get_servant(POA(self), &s, EXC));
|
|
2096
|
+
return servant_of(s);
|
|
2097
|
+
}
|
|
2098
|
+
static VALUE poa_set_servant(VALUE self, VALUE servant) {
|
|
2099
|
+
CHECK(rorb_poa_set_servant(POA(self), SERVANT(servant), EXC));
|
|
2100
|
+
return Qnil;
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
/* --- POAManager ------------------------------------------------------------------------ */
|
|
2104
|
+
|
|
2105
|
+
struct mgr_op {
|
|
2106
|
+
rorb_poa_manager* m;
|
|
2107
|
+
int what;
|
|
2108
|
+
int32_t a, b;
|
|
2109
|
+
rorb_status st;
|
|
2110
|
+
rorb_exception exc;
|
|
2111
|
+
};
|
|
2112
|
+
static void* mgr_nogvl(void* p) {
|
|
2113
|
+
struct mgr_op* o = p;
|
|
2114
|
+
switch (o->what) {
|
|
2115
|
+
case 0: o->st = rorb_poa_manager_activate(o->m, &o->exc); break;
|
|
2116
|
+
case 1: o->st = rorb_poa_manager_hold_requests(o->m, o->a, &o->exc); break;
|
|
2117
|
+
case 2: o->st = rorb_poa_manager_discard_requests(o->m, o->a, &o->exc); break;
|
|
2118
|
+
default: o->st = rorb_poa_manager_deactivate(o->m, o->a, o->b, &o->exc); break;
|
|
2119
|
+
}
|
|
2120
|
+
return NULL;
|
|
2121
|
+
}
|
|
2122
|
+
static VALUE mgr_call(VALUE self, int what, VALUE a, VALUE b) {
|
|
2123
|
+
struct mgr_op o;
|
|
2124
|
+
memset(&o, 0, sizeof o);
|
|
2125
|
+
o.m = MGR(self);
|
|
2126
|
+
o.what = what;
|
|
2127
|
+
o.a = RTEST(a);
|
|
2128
|
+
o.b = RTEST(b);
|
|
2129
|
+
blocking(mgr_nogvl, &o);
|
|
2130
|
+
if (o.st != RORB_OK) raise_status(o.st, &o.exc);
|
|
2131
|
+
return Qnil;
|
|
2132
|
+
}
|
|
2133
|
+
static VALUE mgr_activate(VALUE self) { return mgr_call(self, 0, Qfalse, Qfalse); }
|
|
2134
|
+
static VALUE mgr_hold(VALUE self, VALUE w) { return mgr_call(self, 1, w, Qfalse); }
|
|
2135
|
+
static VALUE mgr_discard(VALUE self, VALUE w) { return mgr_call(self, 2, w, Qfalse); }
|
|
2136
|
+
static VALUE mgr_deactivate(VALUE self, VALUE e, VALUE w) { return mgr_call(self, 3, e, w); }
|
|
2137
|
+
static VALUE mgr_state(VALUE self) { return UINT2NUM(rorb_poa_manager_get_state(MGR(self))); }
|
|
2138
|
+
static VALUE mgr_id(VALUE self) {
|
|
2139
|
+
size_t len = 0;
|
|
2140
|
+
const char* s = rorb_poa_manager_get_id(MGR(self), &len);
|
|
2141
|
+
return utf8(s, len);
|
|
2142
|
+
}
|
|
2143
|
+
static VALUE mgr_equal(VALUE self, VALUE other) {
|
|
2144
|
+
return rorb_poa_manager_equal(MGR(self), MGR(other)) ? Qtrue : Qfalse;
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
/* --- PortableServer::Current ------------------------------------------------------------ */
|
|
2148
|
+
|
|
2149
|
+
static VALUE native_current_poa(VALUE self) {
|
|
2150
|
+
struct current_call c;
|
|
2151
|
+
(void)self;
|
|
2152
|
+
current_call(&c, 1);
|
|
2153
|
+
at_home(current_nogvl, &c);
|
|
2154
|
+
if (c.st != RORB_OK) raise_status(c.st, &c.exc);
|
|
2155
|
+
return W_POA(c.poa);
|
|
2156
|
+
}
|
|
2157
|
+
static VALUE native_current_object_id(VALUE self) {
|
|
2158
|
+
struct current_call c;
|
|
2159
|
+
(void)self;
|
|
2160
|
+
current_call(&c, 2);
|
|
2161
|
+
at_home(current_nogvl, &c);
|
|
2162
|
+
if (c.st != RORB_OK) raise_status(c.st, &c.exc);
|
|
2163
|
+
return bytes_str(c.id);
|
|
2164
|
+
}
|
|
2165
|
+
static VALUE native_current_reference(VALUE self) {
|
|
2166
|
+
struct current_call c;
|
|
2167
|
+
(void)self;
|
|
2168
|
+
current_call(&c, 3);
|
|
2169
|
+
at_home(current_nogvl, &c);
|
|
2170
|
+
if (c.st != RORB_OK) raise_status(c.st, &c.exc);
|
|
2171
|
+
return W_OBJ(c.obj);
|
|
2172
|
+
}
|
|
2173
|
+
static VALUE native_current_servant(VALUE self) {
|
|
2174
|
+
struct current_call c;
|
|
2175
|
+
(void)self;
|
|
2176
|
+
current_call(&c, 4);
|
|
2177
|
+
at_home(current_nogvl, &c);
|
|
2178
|
+
if (c.st != RORB_OK) raise_status(c.st, &c.exc);
|
|
2179
|
+
return servant_of(c.self);
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
static VALUE native_longdouble_from_double(VALUE self, VALUE v) {
|
|
2183
|
+
uint64_t hi, lo;
|
|
2184
|
+
(void)self;
|
|
2185
|
+
rorb_longdouble_from_double(NUM2DBL(v), &hi, &lo);
|
|
2186
|
+
return rb_assoc_new(ULL2NUM(hi), ULL2NUM(lo));
|
|
2187
|
+
}
|
|
2188
|
+
static VALUE native_longdouble_to_double(VALUE self, VALUE hi, VALUE lo) {
|
|
2189
|
+
(void)self;
|
|
2190
|
+
return DBL2NUM(rorb_longdouble_to_double(NUM2ULL(hi), NUM2ULL(lo)));
|
|
2191
|
+
}
|
|
2192
|
+
static VALUE native_dispatchers(VALUE self) {
|
|
2193
|
+
int n;
|
|
2194
|
+
(void)self;
|
|
2195
|
+
pthread_mutex_lock(&queue_lock);
|
|
2196
|
+
n = dispatchers;
|
|
2197
|
+
pthread_mutex_unlock(&queue_lock);
|
|
2198
|
+
return INT2FIX(n);
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
/* --- Init ----------------------------------------------------------------------------------- */
|
|
2202
|
+
|
|
2203
|
+
static const rb_data_type_t registry_type = {
|
|
2204
|
+
"rustorb_registry", {registry_mark, NULL, NULL, NULL, {0}}, NULL, NULL, 0};
|
|
2205
|
+
|
|
2206
|
+
/* --- DynamicAny ------------------------------------------------------------------------- */
|
|
2207
|
+
|
|
2208
|
+
/* Rustorb::Native::DynAny: one rorb_dynany handle. Values go in and out as
|
|
2209
|
+
Rustorb::Native::Any; DynamicAny.rb makes the IDL interfaces. */
|
|
2210
|
+
static VALUE cDynAny;
|
|
2211
|
+
static void rel_dyn(void* p) { rorb_dynany_release(p); }
|
|
2212
|
+
#define W_DYN(p) wrap(cDynAny, (p), rel_dyn)
|
|
2213
|
+
#define DYN(v) ((rorb_dynany*)unwrap((v), cDynAny))
|
|
2214
|
+
|
|
2215
|
+
static VALUE dyn_create(VALUE klass, VALUE any, VALUE truncate) {
|
|
2216
|
+
rorb_dynany* d = NULL;
|
|
2217
|
+
(void)klass;
|
|
2218
|
+
CHECK(rorb_dynany_create(ANY(any), RTEST(truncate) ? 1 : 0, &d, EXC));
|
|
2219
|
+
return W_DYN(d);
|
|
2220
|
+
}
|
|
2221
|
+
static VALUE dyn_from_typecode(VALUE klass, VALUE tc) {
|
|
2222
|
+
rorb_dynany* d = NULL;
|
|
2223
|
+
(void)klass;
|
|
2224
|
+
CHECK(rorb_dynany_from_typecode(TC(tc), &d, EXC));
|
|
2225
|
+
return W_DYN(d);
|
|
2226
|
+
}
|
|
2227
|
+
static VALUE dyn_kind(VALUE self) { return UINT2NUM(rorb_dynany_kind(DYN(self))); }
|
|
2228
|
+
static VALUE dyn_same(VALUE self, VALUE other) {
|
|
2229
|
+
return rorb_dynany_same(DYN(self), DYN(other)) ? Qtrue : Qfalse;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
#define DYN_TC(name, fn) \
|
|
2233
|
+
static VALUE name(VALUE self) { \
|
|
2234
|
+
rorb_typecode* t = NULL; \
|
|
2235
|
+
CHECK(fn(DYN(self), &t, EXC)); \
|
|
2236
|
+
return W_TC(t); \
|
|
2237
|
+
}
|
|
2238
|
+
#define DYN_ANY(name, fn) \
|
|
2239
|
+
static VALUE name(VALUE self) { \
|
|
2240
|
+
rorb_any* a = NULL; \
|
|
2241
|
+
CHECK(fn(DYN(self), &a, EXC)); \
|
|
2242
|
+
return W_ANY(a); \
|
|
2243
|
+
}
|
|
2244
|
+
#define DYN_DYN(name, fn) \
|
|
2245
|
+
static VALUE name(VALUE self) { \
|
|
2246
|
+
rorb_dynany* d = NULL; \
|
|
2247
|
+
CHECK(fn(DYN(self), &d, EXC)); \
|
|
2248
|
+
return W_DYN(d); \
|
|
2249
|
+
}
|
|
2250
|
+
#define DYN_VOID(name, fn) \
|
|
2251
|
+
static VALUE name(VALUE self) { \
|
|
2252
|
+
CHECK(fn(DYN(self), EXC)); \
|
|
2253
|
+
return Qnil; \
|
|
2254
|
+
}
|
|
2255
|
+
#define DYN_BOOL(name, fn) \
|
|
2256
|
+
static VALUE name(VALUE self) { \
|
|
2257
|
+
int32_t b = 0; \
|
|
2258
|
+
CHECK(fn(DYN(self), &b, EXC)); \
|
|
2259
|
+
return b ? Qtrue : Qfalse; \
|
|
2260
|
+
}
|
|
2261
|
+
#define DYN_U32(name, fn) \
|
|
2262
|
+
static VALUE name(VALUE self) { \
|
|
2263
|
+
uint32_t u = 0; \
|
|
2264
|
+
CHECK(fn(DYN(self), &u, EXC)); \
|
|
2265
|
+
return UINT2NUM(u); \
|
|
2266
|
+
}
|
|
2267
|
+
#define DYN_STR(name, fn) \
|
|
2268
|
+
static VALUE name(VALUE self) { \
|
|
2269
|
+
rorb_bytes b; \
|
|
2270
|
+
VALUE s; \
|
|
2271
|
+
memset(&b, 0, sizeof b); \
|
|
2272
|
+
CHECK(fn(DYN(self), &b, EXC)); \
|
|
2273
|
+
s = utf8((const char*)b.data, b.len); \
|
|
2274
|
+
rorb_bytes_free(b); \
|
|
2275
|
+
return s; \
|
|
2276
|
+
}
|
|
2277
|
+
#define DYN_SET_ANY(name, fn) \
|
|
2278
|
+
static VALUE name(VALUE self, VALUE a) { \
|
|
2279
|
+
CHECK(fn(DYN(self), ANY(a), EXC)); \
|
|
2280
|
+
return Qnil; \
|
|
2281
|
+
}
|
|
2282
|
+
#define DYN_SET_DYN(name, fn) \
|
|
2283
|
+
static VALUE name(VALUE self, VALUE d) { \
|
|
2284
|
+
CHECK(fn(DYN(self), DYN(d), EXC)); \
|
|
2285
|
+
return Qnil; \
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
DYN_TC(dyn_type, rorb_dynany_type)
|
|
2289
|
+
DYN_TC(dyn_target_type, rorb_dynany_target_type)
|
|
2290
|
+
DYN_SET_DYN(dyn_assign, rorb_dynany_assign)
|
|
2291
|
+
DYN_SET_ANY(dyn_from_any, rorb_dynany_from_any)
|
|
2292
|
+
DYN_ANY(dyn_to_any, rorb_dynany_to_any)
|
|
2293
|
+
DYN_VOID(dyn_destroy, rorb_dynany_destroy)
|
|
2294
|
+
DYN_DYN(dyn_copy, rorb_dynany_copy)
|
|
2295
|
+
DYN_SET_DYN(dyn_insert_dyn_any, rorb_dynany_insert_dyn_any)
|
|
2296
|
+
DYN_DYN(dyn_get_dyn_any, rorb_dynany_get_dyn_any)
|
|
2297
|
+
DYN_VOID(dyn_no_implement, rorb_dynany_no_implement)
|
|
2298
|
+
DYN_VOID(dyn_rewind, rorb_dynany_rewind)
|
|
2299
|
+
DYN_BOOL(dyn_next, rorb_dynany_next)
|
|
2300
|
+
DYN_U32(dyn_component_count, rorb_dynany_component_count)
|
|
2301
|
+
DYN_DYN(dyn_current_component, rorb_dynany_current_component)
|
|
2302
|
+
DYN_STR(dyn_get_fixed_value, rorb_dynany_get_fixed_value)
|
|
2303
|
+
DYN_STR(dyn_get_as_string, rorb_dynany_get_as_string)
|
|
2304
|
+
DYN_U32(dyn_get_as_ulong, rorb_dynany_get_as_ulong)
|
|
2305
|
+
DYN_STR(dyn_current_member_name, rorb_dynany_current_member_name)
|
|
2306
|
+
DYN_U32(dyn_current_member_kind, rorb_dynany_current_member_kind)
|
|
2307
|
+
DYN_U32(dyn_member_count, rorb_dynany_member_count)
|
|
2308
|
+
DYN_DYN(dyn_get_discriminator, rorb_dynany_get_discriminator)
|
|
2309
|
+
DYN_SET_DYN(dyn_set_discriminator, rorb_dynany_set_discriminator)
|
|
2310
|
+
DYN_VOID(dyn_set_to_default_member, rorb_dynany_set_to_default_member)
|
|
2311
|
+
DYN_VOID(dyn_set_to_no_active_member, rorb_dynany_set_to_no_active_member)
|
|
2312
|
+
DYN_BOOL(dyn_has_no_active_member, rorb_dynany_has_no_active_member)
|
|
2313
|
+
DYN_U32(dyn_discriminator_kind, rorb_dynany_discriminator_kind)
|
|
2314
|
+
DYN_DYN(dyn_member, rorb_dynany_member)
|
|
2315
|
+
DYN_STR(dyn_member_name, rorb_dynany_member_name)
|
|
2316
|
+
DYN_U32(dyn_member_kind, rorb_dynany_member_kind)
|
|
2317
|
+
DYN_U32(dyn_get_length, rorb_dynany_get_length)
|
|
2318
|
+
DYN_U32(dyn_element_count, rorb_dynany_element_count)
|
|
2319
|
+
DYN_BOOL(dyn_is_null, rorb_dynany_is_null)
|
|
2320
|
+
DYN_VOID(dyn_set_to_null, rorb_dynany_set_to_null)
|
|
2321
|
+
DYN_VOID(dyn_set_to_value, rorb_dynany_set_to_value)
|
|
2322
|
+
DYN_ANY(dyn_get_boxed_value, rorb_dynany_get_boxed_value)
|
|
2323
|
+
DYN_SET_ANY(dyn_set_boxed_value, rorb_dynany_set_boxed_value)
|
|
2324
|
+
DYN_DYN(dyn_get_boxed_value_as_dyn_any, rorb_dynany_get_boxed_value_as_dyn_any)
|
|
2325
|
+
DYN_SET_DYN(dyn_set_boxed_value_as_dyn_any, rorb_dynany_set_boxed_value_as_dyn_any)
|
|
2326
|
+
|
|
2327
|
+
static VALUE dyn_equal(VALUE self, VALUE other) {
|
|
2328
|
+
int32_t b = 0;
|
|
2329
|
+
CHECK(rorb_dynany_equal(DYN(self), DYN(other), &b, EXC));
|
|
2330
|
+
return b ? Qtrue : Qfalse;
|
|
2331
|
+
}
|
|
2332
|
+
static VALUE dyn_insert(VALUE self, VALUE kind, VALUE a) {
|
|
2333
|
+
CHECK(rorb_dynany_insert(DYN(self), NUM2UINT(kind), ANY(a), EXC));
|
|
2334
|
+
return Qnil;
|
|
2335
|
+
}
|
|
2336
|
+
static VALUE dyn_get(VALUE self, VALUE kind) {
|
|
2337
|
+
rorb_any* a = NULL;
|
|
2338
|
+
CHECK(rorb_dynany_get(DYN(self), NUM2UINT(kind), &a, EXC));
|
|
2339
|
+
return W_ANY(a);
|
|
2340
|
+
}
|
|
2341
|
+
static VALUE dyn_insert_seq(VALUE self, VALUE kind, VALUE a) {
|
|
2342
|
+
CHECK(rorb_dynany_insert_seq(DYN(self), NUM2UINT(kind), ANY(a), EXC));
|
|
2343
|
+
return Qnil;
|
|
2344
|
+
}
|
|
2345
|
+
static VALUE dyn_get_seq(VALUE self, VALUE kind) {
|
|
2346
|
+
rorb_any* a = NULL;
|
|
2347
|
+
CHECK(rorb_dynany_get_seq(DYN(self), NUM2UINT(kind), &a, EXC));
|
|
2348
|
+
return W_ANY(a);
|
|
2349
|
+
}
|
|
2350
|
+
static VALUE dyn_seek(VALUE self, VALUE index) {
|
|
2351
|
+
int32_t b = 0;
|
|
2352
|
+
CHECK(rorb_dynany_seek(DYN(self), NUM2INT(index), &b, EXC));
|
|
2353
|
+
return b ? Qtrue : Qfalse;
|
|
2354
|
+
}
|
|
2355
|
+
static VALUE dyn_set_fixed_value(VALUE self, VALUE s) {
|
|
2356
|
+
int32_t b = 0;
|
|
2357
|
+
s = utf8_arg(s);
|
|
2358
|
+
CHECK(rorb_dynany_set_fixed_value(DYN(self), RSTRING_PTR(s), (size_t)RSTRING_LEN(s), &b, EXC));
|
|
2359
|
+
RB_GC_GUARD(s);
|
|
2360
|
+
return b ? Qtrue : Qfalse;
|
|
2361
|
+
}
|
|
2362
|
+
static VALUE dyn_set_as_string(VALUE self, VALUE s) {
|
|
2363
|
+
s = utf8_arg(s);
|
|
2364
|
+
CHECK(rorb_dynany_set_as_string(DYN(self), RSTRING_PTR(s), (size_t)RSTRING_LEN(s), EXC));
|
|
2365
|
+
RB_GC_GUARD(s);
|
|
2366
|
+
return Qnil;
|
|
2367
|
+
}
|
|
2368
|
+
static VALUE dyn_set_as_ulong(VALUE self, VALUE u) {
|
|
2369
|
+
CHECK(rorb_dynany_set_as_ulong(DYN(self), NUM2UINT(u), EXC));
|
|
2370
|
+
return Qnil;
|
|
2371
|
+
}
|
|
2372
|
+
static VALUE dyn_set_length(VALUE self, VALUE n) {
|
|
2373
|
+
CHECK(rorb_dynany_set_length(DYN(self), NUM2UINT(n), EXC));
|
|
2374
|
+
return Qnil;
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
/* [name, DynAny] of member index. */
|
|
2378
|
+
static VALUE dyn_member_at(VALUE self, VALUE index) {
|
|
2379
|
+
rorb_bytes b;
|
|
2380
|
+
rorb_dynany* d = NULL;
|
|
2381
|
+
VALUE name;
|
|
2382
|
+
memset(&b, 0, sizeof b);
|
|
2383
|
+
CHECK(rorb_dynany_member_at(DYN(self), NUM2UINT(index), &b, &d, EXC));
|
|
2384
|
+
name = utf8((const char*)b.data, b.len);
|
|
2385
|
+
rorb_bytes_free(b);
|
|
2386
|
+
return rb_assoc_new(name, W_DYN(d));
|
|
2387
|
+
}
|
|
2388
|
+
static VALUE dyn_element_at(VALUE self, VALUE index) {
|
|
2389
|
+
rorb_dynany* d = NULL;
|
|
2390
|
+
CHECK(rorb_dynany_element_at(DYN(self), NUM2UINT(index), &d, EXC));
|
|
2391
|
+
return W_DYN(d);
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
/* set_members / set_members_as_dyn_any: names (Strings) and values
|
|
2395
|
+
(Native::Any, or Native::DynAny when dyn). */
|
|
2396
|
+
static VALUE dyn_set_members_common(VALUE self, VALUE names, VALUE values, int dyn) {
|
|
2397
|
+
long n, i;
|
|
2398
|
+
const char** cn;
|
|
2399
|
+
size_t* cl;
|
|
2400
|
+
const void** cv;
|
|
2401
|
+
rorb_exception exc;
|
|
2402
|
+
rorb_status st;
|
|
2403
|
+
Check_Type(names, T_ARRAY);
|
|
2404
|
+
Check_Type(values, T_ARRAY);
|
|
2405
|
+
n = RARRAY_LEN(names);
|
|
2406
|
+
if (RARRAY_LEN(values) != n) rb_raise(rb_eArgError, "names and values differ in length");
|
|
2407
|
+
names = rb_ary_dup(names);
|
|
2408
|
+
for (i = 0; i < n; i++) rb_ary_store(names, i, utf8_arg(rb_ary_entry(names, i)));
|
|
2409
|
+
cn = ALLOCA_N(const char*, n ? n : 1);
|
|
2410
|
+
cl = ALLOCA_N(size_t, n ? n : 1);
|
|
2411
|
+
cv = ALLOCA_N(const void*, n ? n : 1);
|
|
2412
|
+
for (i = 0; i < n; i++) {
|
|
2413
|
+
VALUE s = rb_ary_entry(names, i);
|
|
2414
|
+
cn[i] = RSTRING_PTR(s);
|
|
2415
|
+
cl[i] = (size_t)RSTRING_LEN(s);
|
|
2416
|
+
cv[i] = dyn ? (const void*)DYN(rb_ary_entry(values, i)) : (const void*)ANY(rb_ary_entry(values, i));
|
|
2417
|
+
}
|
|
2418
|
+
memset(&exc, 0, sizeof exc);
|
|
2419
|
+
st = dyn ? rorb_dynany_set_members_as_dyn_any(DYN(self), (size_t)n, cn, cl,
|
|
2420
|
+
(const rorb_dynany* const*)cv, &exc)
|
|
2421
|
+
: rorb_dynany_set_members(DYN(self), (size_t)n, cn, cl, (const rorb_any* const*)cv, &exc);
|
|
2422
|
+
RB_GC_GUARD(names);
|
|
2423
|
+
RB_GC_GUARD(values);
|
|
2424
|
+
if (st != RORB_OK) raise_status(st, &exc);
|
|
2425
|
+
return Qnil;
|
|
2426
|
+
}
|
|
2427
|
+
static VALUE dyn_set_members(VALUE self, VALUE names, VALUE values) {
|
|
2428
|
+
return dyn_set_members_common(self, names, values, 0);
|
|
2429
|
+
}
|
|
2430
|
+
static VALUE dyn_set_members_as_dyn_any(VALUE self, VALUE names, VALUE values) {
|
|
2431
|
+
return dyn_set_members_common(self, names, values, 1);
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
static VALUE dyn_set_elements_common(VALUE self, VALUE values, int dyn) {
|
|
2435
|
+
long n, i;
|
|
2436
|
+
const void** cv;
|
|
2437
|
+
rorb_exception exc;
|
|
2438
|
+
rorb_status st;
|
|
2439
|
+
Check_Type(values, T_ARRAY);
|
|
2440
|
+
n = RARRAY_LEN(values);
|
|
2441
|
+
cv = ALLOCA_N(const void*, n ? n : 1);
|
|
2442
|
+
for (i = 0; i < n; i++)
|
|
2443
|
+
cv[i] = dyn ? (const void*)DYN(rb_ary_entry(values, i)) : (const void*)ANY(rb_ary_entry(values, i));
|
|
2444
|
+
memset(&exc, 0, sizeof exc);
|
|
2445
|
+
st = dyn ? rorb_dynany_set_elements_as_dyn_any(DYN(self), (size_t)n, (const rorb_dynany* const*)cv, &exc)
|
|
2446
|
+
: rorb_dynany_set_elements(DYN(self), (size_t)n, (const rorb_any* const*)cv, &exc);
|
|
2447
|
+
RB_GC_GUARD(values);
|
|
2448
|
+
if (st != RORB_OK) raise_status(st, &exc);
|
|
2449
|
+
return Qnil;
|
|
2450
|
+
}
|
|
2451
|
+
static VALUE dyn_set_elements(VALUE self, VALUE values) {
|
|
2452
|
+
return dyn_set_elements_common(self, values, 0);
|
|
2453
|
+
}
|
|
2454
|
+
static VALUE dyn_set_elements_as_dyn_any(VALUE self, VALUE values) {
|
|
2455
|
+
return dyn_set_elements_common(self, values, 1);
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2458
|
+
static void init_dynany(void) {
|
|
2459
|
+
cDynAny = rb_define_class_under(mNative, "DynAny", rb_cObject);
|
|
2460
|
+
rb_undef_alloc_func(cDynAny);
|
|
2461
|
+
rb_define_singleton_method(cDynAny, "create", RUBY_METHOD_FUNC(dyn_create), 2);
|
|
2462
|
+
rb_define_singleton_method(cDynAny, "from_type_code", RUBY_METHOD_FUNC(dyn_from_typecode), 1);
|
|
2463
|
+
#define D(name, fn, n) rb_define_method(cDynAny, name, RUBY_METHOD_FUNC(fn), n)
|
|
2464
|
+
D("kind", dyn_kind, 0);
|
|
2465
|
+
D("same", dyn_same, 1);
|
|
2466
|
+
D("type", dyn_type, 0);
|
|
2467
|
+
D("target_type", dyn_target_type, 0);
|
|
2468
|
+
D("assign", dyn_assign, 1);
|
|
2469
|
+
D("from_any", dyn_from_any, 1);
|
|
2470
|
+
D("to_any", dyn_to_any, 0);
|
|
2471
|
+
D("equal", dyn_equal, 1);
|
|
2472
|
+
D("destroy", dyn_destroy, 0);
|
|
2473
|
+
D("copy", dyn_copy, 0);
|
|
2474
|
+
D("insert", dyn_insert, 2);
|
|
2475
|
+
D("get", dyn_get, 1);
|
|
2476
|
+
D("insert_seq", dyn_insert_seq, 2);
|
|
2477
|
+
D("get_seq", dyn_get_seq, 1);
|
|
2478
|
+
D("insert_dyn_any", dyn_insert_dyn_any, 1);
|
|
2479
|
+
D("get_dyn_any", dyn_get_dyn_any, 0);
|
|
2480
|
+
D("no_implement", dyn_no_implement, 0);
|
|
2481
|
+
D("seek", dyn_seek, 1);
|
|
2482
|
+
D("rewind", dyn_rewind, 0);
|
|
2483
|
+
D("next", dyn_next, 0);
|
|
2484
|
+
D("component_count", dyn_component_count, 0);
|
|
2485
|
+
D("current_component", dyn_current_component, 0);
|
|
2486
|
+
D("get_fixed_value", dyn_get_fixed_value, 0);
|
|
2487
|
+
D("set_fixed_value", dyn_set_fixed_value, 1);
|
|
2488
|
+
D("get_as_string", dyn_get_as_string, 0);
|
|
2489
|
+
D("set_as_string", dyn_set_as_string, 1);
|
|
2490
|
+
D("get_as_ulong", dyn_get_as_ulong, 0);
|
|
2491
|
+
D("set_as_ulong", dyn_set_as_ulong, 1);
|
|
2492
|
+
D("current_member_name", dyn_current_member_name, 0);
|
|
2493
|
+
D("current_member_kind", dyn_current_member_kind, 0);
|
|
2494
|
+
D("member_count", dyn_member_count, 0);
|
|
2495
|
+
D("member_at", dyn_member_at, 1);
|
|
2496
|
+
D("set_members", dyn_set_members, 2);
|
|
2497
|
+
D("set_members_as_dyn_any", dyn_set_members_as_dyn_any, 2);
|
|
2498
|
+
D("get_discriminator", dyn_get_discriminator, 0);
|
|
2499
|
+
D("set_discriminator", dyn_set_discriminator, 1);
|
|
2500
|
+
D("set_to_default_member", dyn_set_to_default_member, 0);
|
|
2501
|
+
D("set_to_no_active_member", dyn_set_to_no_active_member, 0);
|
|
2502
|
+
D("has_no_active_member", dyn_has_no_active_member, 0);
|
|
2503
|
+
D("discriminator_kind", dyn_discriminator_kind, 0);
|
|
2504
|
+
D("member", dyn_member, 0);
|
|
2505
|
+
D("member_name", dyn_member_name, 0);
|
|
2506
|
+
D("member_kind", dyn_member_kind, 0);
|
|
2507
|
+
D("get_length", dyn_get_length, 0);
|
|
2508
|
+
D("set_length", dyn_set_length, 1);
|
|
2509
|
+
D("element_count", dyn_element_count, 0);
|
|
2510
|
+
D("element_at", dyn_element_at, 1);
|
|
2511
|
+
D("set_elements", dyn_set_elements, 1);
|
|
2512
|
+
D("set_elements_as_dyn_any", dyn_set_elements_as_dyn_any, 1);
|
|
2513
|
+
D("is_null", dyn_is_null, 0);
|
|
2514
|
+
D("set_to_null", dyn_set_to_null, 0);
|
|
2515
|
+
D("set_to_value", dyn_set_to_value, 0);
|
|
2516
|
+
D("get_boxed_value", dyn_get_boxed_value, 0);
|
|
2517
|
+
D("set_boxed_value", dyn_set_boxed_value, 1);
|
|
2518
|
+
D("get_boxed_value_as_dyn_any", dyn_get_boxed_value_as_dyn_any, 0);
|
|
2519
|
+
D("set_boxed_value_as_dyn_any", dyn_set_boxed_value_as_dyn_any, 1);
|
|
2520
|
+
#undef D
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
#define DEF(klass, name, fn, n) rb_define_method(klass, name, RUBY_METHOD_FUNC(fn), n)
|
|
2524
|
+
#define SDEF(klass, name, fn, n) rb_define_singleton_method(klass, name, RUBY_METHOD_FUNC(fn), n)
|
|
2525
|
+
|
|
2526
|
+
/* --- the DII and the DSI ------------------------------------------------------------- */
|
|
2527
|
+
|
|
2528
|
+
/* Rustorb::Native::Request (one rorb_request) and ServerRequest (one
|
|
2529
|
+
rorb_server_request); values are Rustorb::Native::Any. CORBA::Request
|
|
2530
|
+
and CORBA::ServerRequest (dii.rb) are built on them. */
|
|
2531
|
+
static VALUE cRequest, cServerRequest;
|
|
2532
|
+
static void rel_request(void* p) { rorb_request_release(p); }
|
|
2533
|
+
static void rel_server_request(void* p) { rorb_server_request_release(p); }
|
|
2534
|
+
#define REQ(v) ((rorb_request*)unwrap((v), cRequest))
|
|
2535
|
+
#define SREQ(v) ((rorb_server_request*)unwrap((v), cServerRequest))
|
|
2536
|
+
|
|
2537
|
+
static VALUE request_new(VALUE klass, VALUE target, VALUE op) {
|
|
2538
|
+
rorb_request* r = NULL;
|
|
2539
|
+
(void)klass;
|
|
2540
|
+
op = utf8_arg(op);
|
|
2541
|
+
CHECK(rorb_request_new(OBJ(target), RSTRING_PTR(op), (size_t)RSTRING_LEN(op), &r, EXC));
|
|
2542
|
+
RB_GC_GUARD(op);
|
|
2543
|
+
return wrap(cRequest, r, rel_request);
|
|
2544
|
+
}
|
|
2545
|
+
static VALUE request_add_arg(VALUE self, VALUE name, VALUE flags, VALUE any) {
|
|
2546
|
+
name = utf8_arg(name);
|
|
2547
|
+
CHECK(rorb_request_add_arg(REQ(self), RSTRING_PTR(name), (size_t)RSTRING_LEN(name), NUM2UINT(flags),
|
|
2548
|
+
ANY(any), EXC));
|
|
2549
|
+
RB_GC_GUARD(name);
|
|
2550
|
+
return Qnil;
|
|
2551
|
+
}
|
|
2552
|
+
static VALUE request_set_return_type(VALUE self, VALUE tc) {
|
|
2553
|
+
rorb_request_set_return_type(REQ(self), TC(tc));
|
|
2554
|
+
return Qnil;
|
|
2555
|
+
}
|
|
2556
|
+
static VALUE request_add_exception(VALUE self, VALUE tc) {
|
|
2557
|
+
rorb_request_add_exception(REQ(self), TC(tc));
|
|
2558
|
+
return Qnil;
|
|
2559
|
+
}
|
|
2560
|
+
static VALUE request_set_timeout(VALUE self, VALUE us) {
|
|
2561
|
+
rorb_request_set_timeout(REQ(self), NUM2LL(us));
|
|
2562
|
+
return Qnil;
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
struct request_call {
|
|
2566
|
+
rorb_request* r;
|
|
2567
|
+
int what;
|
|
2568
|
+
int32_t ready;
|
|
2569
|
+
rorb_status st;
|
|
2570
|
+
rorb_exception exc;
|
|
2571
|
+
};
|
|
2572
|
+
|
|
2573
|
+
static void* request_nogvl(void* p) {
|
|
2574
|
+
struct request_call* c = p;
|
|
2575
|
+
switch (c->what) {
|
|
2576
|
+
case 0: c->st = rorb_request_invoke(c->r, &c->exc); break;
|
|
2577
|
+
case 1: c->st = rorb_request_send_oneway(c->r, &c->exc); break;
|
|
2578
|
+
case 2: c->st = rorb_request_send_deferred(c->r, &c->exc); break;
|
|
2579
|
+
default: c->st = rorb_request_get_response(c->r, &c->exc); break;
|
|
2580
|
+
}
|
|
2581
|
+
return NULL;
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
/* true, or false when the operation raised a user exception of the list
|
|
2585
|
+
(Request#exception has it). */
|
|
2586
|
+
static VALUE request_call(VALUE self, int what) {
|
|
2587
|
+
struct request_call c;
|
|
2588
|
+
memset(&c, 0, sizeof c);
|
|
2589
|
+
c.r = REQ(self);
|
|
2590
|
+
c.what = what;
|
|
2591
|
+
blocking(request_nogvl, &c);
|
|
2592
|
+
if (c.st == RORB_USER_EXCEPTION) {
|
|
2593
|
+
rorb_exception_clear(&c.exc);
|
|
2594
|
+
return Qfalse;
|
|
2595
|
+
}
|
|
2596
|
+
if (c.st != RORB_OK) raise_status(c.st, &c.exc);
|
|
2597
|
+
return Qtrue;
|
|
2598
|
+
}
|
|
2599
|
+
static VALUE request_invoke(VALUE self) { return request_call(self, 0); }
|
|
2600
|
+
static VALUE request_send_oneway(VALUE self) { return request_call(self, 1); }
|
|
2601
|
+
static VALUE request_send_deferred(VALUE self) { return request_call(self, 2); }
|
|
2602
|
+
static VALUE request_get_response(VALUE self) { return request_call(self, 3); }
|
|
2603
|
+
static VALUE request_poll_response(VALUE self) {
|
|
2604
|
+
int32_t ready = 0;
|
|
2605
|
+
CHECK(rorb_request_poll_response(REQ(self), &ready, EXC));
|
|
2606
|
+
return ready ? Qtrue : Qfalse;
|
|
2607
|
+
}
|
|
2608
|
+
static VALUE request_result(VALUE self) { return W_ANY(rorb_request_result(REQ(self))); }
|
|
2609
|
+
static VALUE request_argument(VALUE self, VALUE i) {
|
|
2610
|
+
return W_ANY(rorb_request_argument(REQ(self), NUM2SIZET(i)));
|
|
2611
|
+
}
|
|
2612
|
+
static VALUE request_exception(VALUE self) { return W_ANY(rorb_request_exception(REQ(self))); }
|
|
2613
|
+
|
|
2614
|
+
/* ServerRequest.new(in, op): the request of the dispatch whose input
|
|
2615
|
+
stream is in (nothing read from it yet). */
|
|
2616
|
+
static VALUE server_request_new(VALUE klass, VALUE in, VALUE op) {
|
|
2617
|
+
rorb_server_request* r = NULL;
|
|
2618
|
+
(void)klass;
|
|
2619
|
+
op = utf8_arg(op);
|
|
2620
|
+
CHECK(rorb_server_request_new(IN(in), RSTRING_PTR(op), (size_t)RSTRING_LEN(op), &r, EXC));
|
|
2621
|
+
RB_GC_GUARD(op);
|
|
2622
|
+
return wrap(cServerRequest, r, rel_server_request);
|
|
2623
|
+
}
|
|
2624
|
+
static VALUE server_request_add_param(VALUE self, VALUE name, VALUE flags, VALUE tc) {
|
|
2625
|
+
name = utf8_arg(name);
|
|
2626
|
+
CHECK(rorb_server_request_add_param(SREQ(self), RSTRING_PTR(name), (size_t)RSTRING_LEN(name),
|
|
2627
|
+
NUM2UINT(flags), TC(tc), EXC));
|
|
2628
|
+
RB_GC_GUARD(name);
|
|
2629
|
+
return Qnil;
|
|
2630
|
+
}
|
|
2631
|
+
static VALUE server_request_arguments(VALUE self) {
|
|
2632
|
+
CHECK(rorb_server_request_arguments(SREQ(self), EXC));
|
|
2633
|
+
return Qnil;
|
|
2634
|
+
}
|
|
2635
|
+
static VALUE server_request_argument(VALUE self, VALUE i) {
|
|
2636
|
+
return W_ANY(rorb_server_request_argument(SREQ(self), NUM2SIZET(i)));
|
|
2637
|
+
}
|
|
2638
|
+
static VALUE server_request_set_argument(VALUE self, VALUE i, VALUE any) {
|
|
2639
|
+
CHECK(rorb_server_request_set_argument(SREQ(self), NUM2SIZET(i), ANY(any), EXC));
|
|
2640
|
+
return Qnil;
|
|
2641
|
+
}
|
|
2642
|
+
static VALUE server_request_set_result(VALUE self, VALUE any) {
|
|
2643
|
+
CHECK(rorb_server_request_set_result(SREQ(self), ANY(any), EXC));
|
|
2644
|
+
return Qnil;
|
|
2645
|
+
}
|
|
2646
|
+
static VALUE server_request_set_exception(VALUE self, VALUE any) {
|
|
2647
|
+
CHECK(rorb_server_request_set_exception(SREQ(self), ANY(any), EXC));
|
|
2648
|
+
return Qnil;
|
|
2649
|
+
}
|
|
2650
|
+
struct sreq_reply {
|
|
2651
|
+
rorb_server_request* r;
|
|
2652
|
+
rorb_server_reply* reply;
|
|
2653
|
+
rorb_status st;
|
|
2654
|
+
rorb_exception exc;
|
|
2655
|
+
};
|
|
2656
|
+
static void* sreq_reply_nogvl(void* p) {
|
|
2657
|
+
struct sreq_reply* c = p;
|
|
2658
|
+
c->st = rorb_server_request_reply(c->r, c->reply, &c->exc);
|
|
2659
|
+
return NULL;
|
|
2660
|
+
}
|
|
2661
|
+
/* On the thread rustorb runs the upcall on (at_home), where the server
|
|
2662
|
+
interceptors look for what the servant set. */
|
|
2663
|
+
static VALUE server_request_reply(VALUE self, VALUE reply) {
|
|
2664
|
+
struct sreq_reply c;
|
|
2665
|
+
memset(&c, 0, sizeof c);
|
|
2666
|
+
c.r = SREQ(self);
|
|
2667
|
+
c.reply = unwrap(reply, cReply);
|
|
2668
|
+
at_home(sreq_reply_nogvl, &c);
|
|
2669
|
+
if (c.st != RORB_OK) raise_status(c.st, &c.exc);
|
|
2670
|
+
return Qnil;
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
static void init_dii(void) {
|
|
2674
|
+
cRequest = rb_define_class_under(mNative, "Request", rb_cObject);
|
|
2675
|
+
rb_undef_alloc_func(cRequest);
|
|
2676
|
+
rb_define_singleton_method(cRequest, "create", RUBY_METHOD_FUNC(request_new), 2);
|
|
2677
|
+
DEF(cRequest, "add_arg", request_add_arg, 3);
|
|
2678
|
+
DEF(cRequest, "set_return_type", request_set_return_type, 1);
|
|
2679
|
+
DEF(cRequest, "add_exception", request_add_exception, 1);
|
|
2680
|
+
DEF(cRequest, "set_timeout", request_set_timeout, 1);
|
|
2681
|
+
DEF(cRequest, "invoke", request_invoke, 0);
|
|
2682
|
+
DEF(cRequest, "send_oneway", request_send_oneway, 0);
|
|
2683
|
+
DEF(cRequest, "send_deferred", request_send_deferred, 0);
|
|
2684
|
+
DEF(cRequest, "get_response", request_get_response, 0);
|
|
2685
|
+
DEF(cRequest, "poll_response", request_poll_response, 0);
|
|
2686
|
+
DEF(cRequest, "result", request_result, 0);
|
|
2687
|
+
DEF(cRequest, "argument", request_argument, 1);
|
|
2688
|
+
DEF(cRequest, "exception", request_exception, 0);
|
|
2689
|
+
|
|
2690
|
+
cServerRequest = rb_define_class_under(mNative, "ServerRequest", rb_cObject);
|
|
2691
|
+
rb_undef_alloc_func(cServerRequest);
|
|
2692
|
+
rb_define_singleton_method(cServerRequest, "create", RUBY_METHOD_FUNC(server_request_new), 2);
|
|
2693
|
+
DEF(cServerRequest, "add_param", server_request_add_param, 3);
|
|
2694
|
+
DEF(cServerRequest, "arguments", server_request_arguments, 0);
|
|
2695
|
+
DEF(cServerRequest, "argument", server_request_argument, 1);
|
|
2696
|
+
DEF(cServerRequest, "set_argument", server_request_set_argument, 2);
|
|
2697
|
+
DEF(cServerRequest, "set_result", server_request_set_result, 1);
|
|
2698
|
+
DEF(cServerRequest, "set_exception", server_request_set_exception, 1);
|
|
2699
|
+
DEF(cServerRequest, "reply", server_request_reply, 1);
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
/* --- servant managers and adapter activators ------------------------------------------ */
|
|
2703
|
+
|
|
2704
|
+
/* A Ruby ServantActivator, ServantLocator or AdapterActivator is a peer
|
|
2705
|
+
too (kept alive while the POA holds it). The callbacks run its
|
|
2706
|
+
_rustorb_* methods (portable_server.rb) with the GVL:
|
|
2707
|
+
|
|
2708
|
+
_rustorb_incarnate(oid, poa) -> outcome
|
|
2709
|
+
_rustorb_etherealize(oid, poa, servant, cleanup, remaining)
|
|
2710
|
+
_rustorb_preinvoke(oid, poa, op) -> outcome (with a cookie key)
|
|
2711
|
+
_rustorb_postinvoke(oid, poa, op, key, servant)
|
|
2712
|
+
_rustorb_unknown_adapter(parent, name) -> true / false
|
|
2713
|
+
|
|
2714
|
+
An outcome is [:servant, servant, ids(, key)], [:forward, Native::Ref]
|
|
2715
|
+
or [:system, id, minor, completed]. */
|
|
2716
|
+
static ID id_incarnate, id_etherealize, id_preinvoke, id_postinvoke, id_unknown_adapter;
|
|
2717
|
+
static VALUE sym_servant, sym_forward;
|
|
2718
|
+
|
|
2719
|
+
struct mgr_cb {
|
|
2720
|
+
peer* p;
|
|
2721
|
+
const uint8_t* id;
|
|
2722
|
+
size_t id_len;
|
|
2723
|
+
rorb_poa* adapter;
|
|
2724
|
+
const char* op;
|
|
2725
|
+
size_t op_len;
|
|
2726
|
+
void* servant_self;
|
|
2727
|
+
int32_t a, b;
|
|
2728
|
+
void* cookie;
|
|
2729
|
+
rorb_servant** servant;
|
|
2730
|
+
void** cookie_out;
|
|
2731
|
+
rorb_manager_error* error;
|
|
2732
|
+
int what;
|
|
2733
|
+
rorb_status st;
|
|
2734
|
+
int32_t answer;
|
|
2735
|
+
};
|
|
2736
|
+
|
|
2737
|
+
static VALUE mgr_poa(rorb_poa* poa) { return W_POA(rorb_poa_clone(poa)); }
|
|
2738
|
+
|
|
2739
|
+
/* Applies an outcome; returns its status. */
|
|
2740
|
+
static rorb_status mgr_outcome(struct mgr_cb* c, VALUE r) {
|
|
2741
|
+
VALUE kind;
|
|
2742
|
+
if (!RB_TYPE_P(r, T_ARRAY) || RARRAY_LEN(r) < 2) return RORB_SYSTEM_EXCEPTION;
|
|
2743
|
+
kind = rb_ary_entry(r, 0);
|
|
2744
|
+
if (kind == sym_servant) {
|
|
2745
|
+
VALUE servant = rb_ary_entry(r, 1);
|
|
2746
|
+
peer* sp = peer_of(servant, rb_ary_entry(r, 2));
|
|
2747
|
+
*c->servant = rorb_servant_get(sp, sp->ids[0] ? sp->ids[0] : "", sp->id_lens[0], &servant_vtable);
|
|
2748
|
+
if (c->cookie_out) *c->cookie_out = (void*)(uintptr_t)NUM2ULL(rb_ary_entry(r, 3));
|
|
2749
|
+
return RORB_OK;
|
|
2750
|
+
}
|
|
2751
|
+
if (kind == sym_forward) {
|
|
2752
|
+
rorb_manager_error_forward(c->error, OBJ(rb_ary_entry(r, 1)));
|
|
2753
|
+
return RORB_SYSTEM_EXCEPTION;
|
|
2754
|
+
}
|
|
2755
|
+
{
|
|
2756
|
+
VALUE id = utf8_arg(rb_ary_entry(r, 1));
|
|
2757
|
+
rorb_manager_error_system(c->error, RSTRING_PTR(id), (size_t)RSTRING_LEN(id),
|
|
2758
|
+
NUM2UINT(rb_ary_entry(r, 2)), NUM2UINT(rb_ary_entry(r, 3)));
|
|
2759
|
+
return RORB_SYSTEM_EXCEPTION;
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
static VALUE mgr_body(VALUE arg) {
|
|
2764
|
+
struct mgr_cb* c = (struct mgr_cb*)arg;
|
|
2765
|
+
VALUE oid = c->id ? rb_str_new((const char*)c->id, (long)c->id_len) : Qnil;
|
|
2766
|
+
VALUE poa = mgr_poa(c->adapter);
|
|
2767
|
+
VALUE servant = c->servant_self ? ((peer*)c->servant_self)->obj : Qnil;
|
|
2768
|
+
VALUE r;
|
|
2769
|
+
switch (c->what) {
|
|
2770
|
+
case 0:
|
|
2771
|
+
r = rb_funcall(c->p->obj, id_incarnate, 2, oid, poa);
|
|
2772
|
+
c->st = mgr_outcome(c, r);
|
|
2773
|
+
break;
|
|
2774
|
+
case 1:
|
|
2775
|
+
rb_funcall(c->p->obj, id_etherealize, 5, oid, poa, servant, c->a ? Qtrue : Qfalse,
|
|
2776
|
+
c->b ? Qtrue : Qfalse);
|
|
2777
|
+
break;
|
|
2778
|
+
case 2:
|
|
2779
|
+
r = rb_funcall(c->p->obj, id_preinvoke, 3, oid, poa, utf8(c->op, c->op_len));
|
|
2780
|
+
c->st = mgr_outcome(c, r);
|
|
2781
|
+
break;
|
|
2782
|
+
case 3:
|
|
2783
|
+
rb_funcall(c->p->obj, id_postinvoke, 5, oid, poa, utf8(c->op, c->op_len),
|
|
2784
|
+
ULL2NUM((uintptr_t)c->cookie), servant);
|
|
2785
|
+
break;
|
|
2786
|
+
default:
|
|
2787
|
+
r = rb_funcall(c->p->obj, id_unknown_adapter, 2, poa, utf8(c->op, c->op_len));
|
|
2788
|
+
c->answer = RTEST(r) ? 1 : 0;
|
|
2789
|
+
break;
|
|
2790
|
+
}
|
|
2791
|
+
return Qnil;
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2794
|
+
static void* mgr_gvl(void* arg) {
|
|
2795
|
+
struct mgr_cb* c = arg;
|
|
2796
|
+
int state = 0;
|
|
2797
|
+
rb_protect(mgr_body, (VALUE)c, &state);
|
|
2798
|
+
if (state) {
|
|
2799
|
+
VALUE e = rb_errinfo();
|
|
2800
|
+
rb_set_errinfo(Qnil);
|
|
2801
|
+
rb_funcall(rb_stderr, rb_intern("puts"), 1,
|
|
2802
|
+
rb_str_concat(rb_str_new_cstr("rustorb: servant manager failed: "), rb_inspect(e)));
|
|
2803
|
+
if (c->error) {
|
|
2804
|
+
rorb_manager_error_system(c->error, "IDL:omg.org/CORBA/UNKNOWN:1.0", 29, 0, RORB_COMPLETED_NO);
|
|
2805
|
+
c->st = RORB_SYSTEM_EXCEPTION;
|
|
2806
|
+
}
|
|
2807
|
+
c->answer = 0;
|
|
2808
|
+
}
|
|
2809
|
+
return c;
|
|
2810
|
+
}
|
|
2811
|
+
|
|
2812
|
+
static void mgr_run(struct mgr_cb* c) {
|
|
2813
|
+
if (!with_gvl(mgr_gvl, c) && c->error) {
|
|
2814
|
+
rorb_manager_error_system(c->error, "IDL:omg.org/CORBA/TRANSIENT:1.0", 31, 0, RORB_COMPLETED_NO);
|
|
2815
|
+
c->st = RORB_SYSTEM_EXCEPTION;
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
static rorb_status act_incarnate(void* self, const uint8_t* id, size_t id_len, rorb_poa* adapter,
|
|
2820
|
+
rorb_servant** servant, rorb_manager_error* error) {
|
|
2821
|
+
struct mgr_cb c;
|
|
2822
|
+
memset(&c, 0, sizeof c);
|
|
2823
|
+
c.p = self, c.id = id, c.id_len = id_len, c.adapter = adapter, c.servant = servant;
|
|
2824
|
+
c.error = error, c.what = 0, c.st = RORB_SYSTEM_EXCEPTION;
|
|
2825
|
+
mgr_run(&c);
|
|
2826
|
+
return c.st;
|
|
2827
|
+
}
|
|
2828
|
+
static void act_etherealize(void* self, const uint8_t* id, size_t id_len, rorb_poa* adapter,
|
|
2829
|
+
void* servant, int32_t cleanup, int32_t remaining) {
|
|
2830
|
+
struct mgr_cb c;
|
|
2831
|
+
memset(&c, 0, sizeof c);
|
|
2832
|
+
c.p = self, c.id = id, c.id_len = id_len, c.adapter = adapter, c.servant_self = servant;
|
|
2833
|
+
c.a = cleanup, c.b = remaining, c.what = 1;
|
|
2834
|
+
mgr_run(&c);
|
|
2835
|
+
}
|
|
2836
|
+
static rorb_status loc_preinvoke(void* self, const uint8_t* id, size_t id_len, rorb_poa* adapter,
|
|
2837
|
+
const char* op, size_t op_len, rorb_servant** servant,
|
|
2838
|
+
void** cookie, rorb_manager_error* error) {
|
|
2839
|
+
struct mgr_cb c;
|
|
2840
|
+
memset(&c, 0, sizeof c);
|
|
2841
|
+
c.p = self, c.id = id, c.id_len = id_len, c.adapter = adapter, c.op = op, c.op_len = op_len;
|
|
2842
|
+
c.servant = servant, c.cookie_out = cookie, c.error = error, c.what = 2;
|
|
2843
|
+
c.st = RORB_SYSTEM_EXCEPTION;
|
|
2844
|
+
mgr_run(&c);
|
|
2845
|
+
return c.st;
|
|
2846
|
+
}
|
|
2847
|
+
static void loc_postinvoke(void* self, const uint8_t* id, size_t id_len, rorb_poa* adapter,
|
|
2848
|
+
const char* op, size_t op_len, void* cookie, void* servant) {
|
|
2849
|
+
struct mgr_cb c;
|
|
2850
|
+
memset(&c, 0, sizeof c);
|
|
2851
|
+
c.p = self, c.id = id, c.id_len = id_len, c.adapter = adapter, c.op = op, c.op_len = op_len;
|
|
2852
|
+
c.cookie = cookie, c.servant_self = servant, c.what = 3;
|
|
2853
|
+
mgr_run(&c);
|
|
2854
|
+
}
|
|
2855
|
+
static int32_t aa_unknown_adapter(void* self, rorb_poa* parent, const char* name, size_t len) {
|
|
2856
|
+
struct mgr_cb c;
|
|
2857
|
+
memset(&c, 0, sizeof c);
|
|
2858
|
+
c.p = self, c.adapter = parent, c.op = name, c.op_len = len, c.what = 4;
|
|
2859
|
+
mgr_run(&c);
|
|
2860
|
+
return c.answer;
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
static const rorb_servant_activator_vtable activator_vtable = {
|
|
2864
|
+
act_incarnate, act_etherealize, servant_add_ref, servant_remove_ref};
|
|
2865
|
+
static const rorb_servant_locator_vtable locator_vtable = {loc_preinvoke, loc_postinvoke,
|
|
2866
|
+
servant_add_ref, servant_remove_ref};
|
|
2867
|
+
static const rorb_adapter_activator_vtable adapter_activator_vtable = {
|
|
2868
|
+
aa_unknown_adapter, servant_add_ref, servant_remove_ref};
|
|
2869
|
+
|
|
2870
|
+
static VALUE poa_set_servant_activator(VALUE self, VALUE obj) {
|
|
2871
|
+
peer* p = peer_of(obj, rb_ary_new());
|
|
2872
|
+
CHECK(rorb_poa_set_servant_activator(POA(self), p, &activator_vtable, EXC));
|
|
2873
|
+
return Qnil;
|
|
2874
|
+
}
|
|
2875
|
+
static VALUE poa_set_servant_locator(VALUE self, VALUE obj) {
|
|
2876
|
+
peer* p = peer_of(obj, rb_ary_new());
|
|
2877
|
+
CHECK(rorb_poa_set_servant_locator(POA(self), p, &locator_vtable, EXC));
|
|
2878
|
+
return Qnil;
|
|
2879
|
+
}
|
|
2880
|
+
static VALUE poa_get_servant_manager(VALUE self) {
|
|
2881
|
+
int32_t kind = 0;
|
|
2882
|
+
void* s = NULL;
|
|
2883
|
+
CHECK(rorb_poa_get_servant_manager(POA(self), &kind, &s, EXC));
|
|
2884
|
+
return servant_of(s);
|
|
2885
|
+
}
|
|
2886
|
+
static VALUE poa_set_the_activator(VALUE self, VALUE obj) {
|
|
2887
|
+
if (NIL_P(obj)) {
|
|
2888
|
+
CHECK(rorb_poa_set_the_activator(POA(self), NULL, &adapter_activator_vtable, EXC));
|
|
2889
|
+
} else {
|
|
2890
|
+
peer* p = peer_of(obj, rb_ary_new());
|
|
2891
|
+
CHECK(rorb_poa_set_the_activator(POA(self), p, &adapter_activator_vtable, EXC));
|
|
2892
|
+
}
|
|
2893
|
+
return Qnil;
|
|
2894
|
+
}
|
|
2895
|
+
static VALUE poa_the_activator(VALUE self) { return servant_of(rorb_poa_the_activator(POA(self))); }
|
|
2896
|
+
|
|
2897
|
+
static void init_managers(void) {
|
|
2898
|
+
id_incarnate = rb_intern("_rustorb_incarnate");
|
|
2899
|
+
id_etherealize = rb_intern("_rustorb_etherealize");
|
|
2900
|
+
id_preinvoke = rb_intern("_rustorb_preinvoke");
|
|
2901
|
+
id_postinvoke = rb_intern("_rustorb_postinvoke");
|
|
2902
|
+
id_unknown_adapter = rb_intern("_rustorb_unknown_adapter");
|
|
2903
|
+
sym_servant = ID2SYM(rb_intern("servant"));
|
|
2904
|
+
sym_forward = ID2SYM(rb_intern("forward"));
|
|
2905
|
+
DEF(cPOA, "set_servant_activator", poa_set_servant_activator, 1);
|
|
2906
|
+
DEF(cPOA, "set_servant_locator", poa_set_servant_locator, 1);
|
|
2907
|
+
DEF(cPOA, "get_servant_manager", poa_get_servant_manager, 0);
|
|
2908
|
+
DEF(cPOA, "set_the_activator", poa_set_the_activator, 1);
|
|
2909
|
+
DEF(cPOA, "the_activator", poa_the_activator, 0);
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2912
|
+
/* --- Portable Interceptors and IOP::Codec ------------------------------------------- */
|
|
2913
|
+
|
|
2914
|
+
/* An interceptor or ORB initializer is a host of its Ruby object (the ORB's
|
|
2915
|
+
add_ref / remove_ref count on it). A point runs, with the GVL,
|
|
2916
|
+
Rustorb::PI.point(obj, point, info): info is a Native::ClientRequestInfo,
|
|
2917
|
+
ServerRequestInfo, IORInfo or ORBInitInfo, valid only during the point;
|
|
2918
|
+
it returns nil, [:forward, Native::Ref] or [:system, id, minor,
|
|
2919
|
+
completed]. The info calls are made here, on the thread that runs the
|
|
2920
|
+
point, while the thread rustorb called the point on waits for it. */
|
|
2921
|
+
static VALUE cCRInfo, cSRInfo, cIORInfo, cInitInfo, cPICurrent, cCodec, mPI;
|
|
2922
|
+
static ID id_point, id_destroy_interceptor;
|
|
2923
|
+
static VALUE sym_system;
|
|
2924
|
+
|
|
2925
|
+
static void rel_pi_current(void* p) { rorb_pi_current_release(p); }
|
|
2926
|
+
static void rel_codec(void* p) { rorb_codec_release(p); }
|
|
2927
|
+
#define CRI(v) ((const rorb_client_request_info*)unwrap((v), cCRInfo))
|
|
2928
|
+
#define SRI(v) ((const rorb_server_request_info*)unwrap((v), cSRInfo))
|
|
2929
|
+
#define IORI(v) ((const rorb_ior_info*)unwrap((v), cIORInfo))
|
|
2930
|
+
#define INITI(v) ((rorb_orb_init_info*)unwrap((v), cInitInfo))
|
|
2931
|
+
#define PICUR(v) ((rorb_pi_current*)unwrap((v), cPICurrent))
|
|
2932
|
+
#define CODEC(v) ((rorb_codec*)unwrap((v), cCodec))
|
|
2933
|
+
|
|
2934
|
+
static void pi_add_ref(void* self) {
|
|
2935
|
+
host* h = self;
|
|
2936
|
+
pthread_mutex_lock(&host_lock);
|
|
2937
|
+
++h->count;
|
|
2938
|
+
pthread_mutex_unlock(&host_lock);
|
|
2939
|
+
}
|
|
2940
|
+
static void pi_remove_ref(void* self) { host_release(self); }
|
|
2941
|
+
|
|
2942
|
+
struct pi_point {
|
|
2943
|
+
host* h;
|
|
2944
|
+
const char* point;
|
|
2945
|
+
VALUE* klass;
|
|
2946
|
+
void* info;
|
|
2947
|
+
rorb_pi_error* error;
|
|
2948
|
+
rorb_status st;
|
|
2949
|
+
VALUE info_v;
|
|
2950
|
+
};
|
|
2951
|
+
|
|
2952
|
+
static VALUE pi_point_body(VALUE p) {
|
|
2953
|
+
struct pi_point* c = (struct pi_point*)p;
|
|
2954
|
+
return rb_funcall(mPI, id_point, 3, c->h->obj, ID2SYM(rb_intern(c->point)), c->info_v);
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
static void pi_unknown(struct pi_point* c) {
|
|
2958
|
+
rorb_pi_error_system(c->error, "IDL:omg.org/CORBA/UNKNOWN:1.0", 29, 0, RORB_COMPLETED_MAYBE);
|
|
2959
|
+
c->st = RORB_SYSTEM_EXCEPTION;
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
static void* pi_point_gvl(void* p) {
|
|
2963
|
+
struct pi_point* c = p;
|
|
2964
|
+
int state = 0;
|
|
2965
|
+
VALUE r, info = wrap_borrowed(*c->klass, c->info);
|
|
2966
|
+
c->info_v = info;
|
|
2967
|
+
r = rb_protect(pi_point_body, (VALUE)c, &state);
|
|
2968
|
+
invalidate(info);
|
|
2969
|
+
RB_GC_GUARD(info);
|
|
2970
|
+
if (state) {
|
|
2971
|
+
rb_set_errinfo(Qnil);
|
|
2972
|
+
pi_unknown(c);
|
|
2973
|
+
return c;
|
|
2974
|
+
}
|
|
2975
|
+
if (NIL_P(r)) return c;
|
|
2976
|
+
if (!RB_TYPE_P(r, T_ARRAY) || RARRAY_LEN(r) < 2) {
|
|
2977
|
+
pi_unknown(c);
|
|
2978
|
+
} else if (rb_ary_entry(r, 0) == sym_forward) {
|
|
2979
|
+
VALUE ref = rb_ary_entry(r, 1);
|
|
2980
|
+
if (!rb_obj_is_kind_of(ref, cRef)) {
|
|
2981
|
+
pi_unknown(c);
|
|
2982
|
+
return c;
|
|
2983
|
+
}
|
|
2984
|
+
rorb_pi_error_forward(c->error, OBJ(ref));
|
|
2985
|
+
c->st = RORB_SYSTEM_EXCEPTION;
|
|
2986
|
+
} else if (RARRAY_LEN(r) >= 4) {
|
|
2987
|
+
VALUE id = rb_ary_entry(r, 1);
|
|
2988
|
+
if (!RB_TYPE_P(id, T_STRING)) {
|
|
2989
|
+
pi_unknown(c);
|
|
2990
|
+
return c;
|
|
2991
|
+
}
|
|
2992
|
+
rorb_pi_error_system(c->error, RSTRING_PTR(id), (size_t)RSTRING_LEN(id),
|
|
2993
|
+
NUM2UINT(rb_ary_entry(r, 2)), NUM2UINT(rb_ary_entry(r, 3)));
|
|
2994
|
+
c->st = RORB_SYSTEM_EXCEPTION;
|
|
2995
|
+
} else {
|
|
2996
|
+
pi_unknown(c);
|
|
2997
|
+
}
|
|
2998
|
+
return c;
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
static int ruby_ending(void) {
|
|
3002
|
+
int r;
|
|
3003
|
+
pthread_mutex_lock(&queue_lock);
|
|
3004
|
+
r = shutting_down;
|
|
3005
|
+
pthread_mutex_unlock(&queue_lock);
|
|
3006
|
+
return r;
|
|
3007
|
+
}
|
|
3008
|
+
|
|
3009
|
+
static rorb_status pi_run(void* self, const char* point, VALUE* klass, const void* info,
|
|
3010
|
+
rorb_pi_error* error) {
|
|
3011
|
+
struct pi_point c;
|
|
3012
|
+
memset(&c, 0, sizeof c);
|
|
3013
|
+
c.h = self;
|
|
3014
|
+
c.point = point;
|
|
3015
|
+
c.klass = klass;
|
|
3016
|
+
c.info = (void*)info;
|
|
3017
|
+
c.error = error;
|
|
3018
|
+
c.st = RORB_OK;
|
|
3019
|
+
c.info_v = Qnil;
|
|
3020
|
+
if (!ruby_ending()) with_gvl(pi_point_gvl, &c);
|
|
3021
|
+
return c.st;
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
static VALUE pi_destroy_body(VALUE obj) { return rb_funcall(mPI, id_destroy_interceptor, 1, obj); }
|
|
3025
|
+
static void* pi_destroy_gvl(void* p) {
|
|
3026
|
+
int state = 0;
|
|
3027
|
+
rb_protect(pi_destroy_body, ((host*)p)->obj, &state);
|
|
3028
|
+
if (state) rb_set_errinfo(Qnil);
|
|
3029
|
+
return p;
|
|
3030
|
+
}
|
|
3031
|
+
/* At exit the ORBs are released while Ruby frees its objects, so an
|
|
3032
|
+
interceptor's object may be gone: no Ruby then. */
|
|
3033
|
+
static void pi_destroy(void* self) {
|
|
3034
|
+
if (!ruby_ending()) with_gvl(pi_destroy_gvl, self);
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
#define PI_POINT(fn, name, T, klass) \
|
|
3038
|
+
static rorb_status fn(void* self, const T* ri, rorb_pi_error* error) { \
|
|
3039
|
+
return pi_run(self, name, &klass, ri, error); \
|
|
3040
|
+
}
|
|
3041
|
+
PI_POINT(pi_send_request, "send_request", rorb_client_request_info, cCRInfo)
|
|
3042
|
+
PI_POINT(pi_receive_reply, "receive_reply", rorb_client_request_info, cCRInfo)
|
|
3043
|
+
PI_POINT(pi_receive_exception, "receive_exception", rorb_client_request_info, cCRInfo)
|
|
3044
|
+
PI_POINT(pi_receive_other, "receive_other", rorb_client_request_info, cCRInfo)
|
|
3045
|
+
PI_POINT(pi_receive_request_service_contexts, "receive_request_service_contexts",
|
|
3046
|
+
rorb_server_request_info, cSRInfo)
|
|
3047
|
+
PI_POINT(pi_receive_request, "receive_request", rorb_server_request_info, cSRInfo)
|
|
3048
|
+
PI_POINT(pi_send_reply, "send_reply", rorb_server_request_info, cSRInfo)
|
|
3049
|
+
PI_POINT(pi_send_exception, "send_exception", rorb_server_request_info, cSRInfo)
|
|
3050
|
+
PI_POINT(pi_send_other, "send_other", rorb_server_request_info, cSRInfo)
|
|
3051
|
+
PI_POINT(pi_establish_components, "establish_components", rorb_ior_info, cIORInfo)
|
|
3052
|
+
|
|
3053
|
+
static rorb_status pi_pre_init(void* self, rorb_orb_init_info* info, rorb_pi_error* error) {
|
|
3054
|
+
return pi_run(self, "pre_init", &cInitInfo, info, error);
|
|
3055
|
+
}
|
|
3056
|
+
static rorb_status pi_post_init(void* self, rorb_orb_init_info* info, rorb_pi_error* error) {
|
|
3057
|
+
return pi_run(self, "post_init", &cInitInfo, info, error);
|
|
3058
|
+
}
|
|
3059
|
+
|
|
3060
|
+
static const rorb_client_interceptor_vtable client_interceptor_vtable = {
|
|
3061
|
+
pi_send_request, pi_receive_reply, pi_receive_exception, pi_receive_other,
|
|
3062
|
+
pi_destroy, pi_add_ref, pi_remove_ref};
|
|
3063
|
+
static const rorb_server_interceptor_vtable server_interceptor_vtable = {
|
|
3064
|
+
pi_receive_request_service_contexts, pi_receive_request, pi_send_reply, pi_send_exception,
|
|
3065
|
+
pi_send_other, pi_destroy, pi_add_ref, pi_remove_ref};
|
|
3066
|
+
static const rorb_ior_interceptor_vtable ior_interceptor_vtable = {
|
|
3067
|
+
pi_establish_components, pi_destroy, pi_add_ref, pi_remove_ref};
|
|
3068
|
+
static const rorb_orb_initializer_vtable orb_initializer_vtable = {pi_pre_init, pi_post_init,
|
|
3069
|
+
pi_add_ref, pi_remove_ref};
|
|
3070
|
+
|
|
3071
|
+
/* Native.register_orb_initializer(obj). */
|
|
3072
|
+
static VALUE native_register_orb_initializer(VALUE self, VALUE obj) {
|
|
3073
|
+
host* h = host_retain(obj);
|
|
3074
|
+
(void)self;
|
|
3075
|
+
rorb_register_orb_initializer(h, &orb_initializer_vtable);
|
|
3076
|
+
host_release(h);
|
|
3077
|
+
return Qnil;
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
/* Native.orb_init_pi(args, orb_id, initializers): [orb, args left], an ORB
|
|
3081
|
+
of its own with these initializers too (rorb_orb_init_pi). */
|
|
3082
|
+
static VALUE native_orb_init_pi(VALUE self, VALUE args, VALUE orb_id, VALUE inits) {
|
|
3083
|
+
long n, i, k;
|
|
3084
|
+
int argc;
|
|
3085
|
+
char** argv;
|
|
3086
|
+
rorb_orb* orb = NULL;
|
|
3087
|
+
rorb_orb_initializer* entries;
|
|
3088
|
+
VALUE rest, strs;
|
|
3089
|
+
rorb_exception exc;
|
|
3090
|
+
rorb_status st;
|
|
3091
|
+
(void)self;
|
|
3092
|
+
Check_Type(args, T_ARRAY);
|
|
3093
|
+
Check_Type(inits, T_ARRAY);
|
|
3094
|
+
orb_id = utf8_arg(orb_id);
|
|
3095
|
+
n = RARRAY_LEN(args);
|
|
3096
|
+
strs = rb_ary_new_capa(n);
|
|
3097
|
+
argv = ALLOCA_N(char*, n + 1);
|
|
3098
|
+
for (i = 0; i < n; ++i) {
|
|
3099
|
+
VALUE s = rb_str_dup(utf8_arg(rb_ary_entry(args, i)));
|
|
3100
|
+
rb_ary_push(strs, s);
|
|
3101
|
+
argv[i] = StringValueCStr(s);
|
|
3102
|
+
}
|
|
3103
|
+
argv[n] = NULL;
|
|
3104
|
+
argc = (int)n;
|
|
3105
|
+
k = RARRAY_LEN(inits);
|
|
3106
|
+
entries = ALLOCA_N(rorb_orb_initializer, k + 1);
|
|
3107
|
+
for (i = 0; i < k; ++i) {
|
|
3108
|
+
entries[i].self = host_retain(rb_ary_entry(inits, i));
|
|
3109
|
+
entries[i].vtable = &orb_initializer_vtable;
|
|
3110
|
+
}
|
|
3111
|
+
memset(&exc, 0, sizeof exc);
|
|
3112
|
+
st = rorb_orb_init_pi(&argc, argv, RSTRING_PTR(orb_id), (size_t)RSTRING_LEN(orb_id), entries,
|
|
3113
|
+
(size_t)k, &orb, &exc);
|
|
3114
|
+
for (i = 0; i < k; ++i) host_release(entries[i].self);
|
|
3115
|
+
if (st != RORB_OK) raise_status(st, &exc);
|
|
3116
|
+
rest = rb_ary_new_capa(argc);
|
|
3117
|
+
for (i = 0; i < argc; ++i) rb_ary_push(rest, rb_utf8_str_new_cstr(argv[i]));
|
|
3118
|
+
RB_GC_GUARD(strs);
|
|
3119
|
+
RB_GC_GUARD(orb_id);
|
|
3120
|
+
RB_GC_GUARD(inits);
|
|
3121
|
+
return rb_assoc_new(W_ORB(orb), rest);
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3124
|
+
/* --- the each callbacks (called on this thread, with the GVL) ------------------------- */
|
|
3125
|
+
|
|
3126
|
+
static void pi_each_string(void* ctx, const char* s, size_t len) {
|
|
3127
|
+
rb_ary_push(*(VALUE*)ctx, utf8(s, len));
|
|
3128
|
+
}
|
|
3129
|
+
static void pi_each_component(void* ctx, uint32_t tag, const uint8_t* data, size_t len) {
|
|
3130
|
+
rb_ary_push(*(VALUE*)ctx, rb_assoc_new(UINT2NUM(tag), rb_str_new((const char*)data, (long)len)));
|
|
3131
|
+
}
|
|
3132
|
+
static void pi_each_parameter(void* ctx, rorb_any* any, uint32_t mode) {
|
|
3133
|
+
rb_ary_push(*(VALUE*)ctx, rb_assoc_new(W_ANY(any), UINT2NUM(mode)));
|
|
3134
|
+
}
|
|
3135
|
+
static void pi_each_typecode(void* ctx, rorb_typecode* tc) { rb_ary_push(*(VALUE*)ctx, W_TC(tc)); }
|
|
3136
|
+
|
|
3137
|
+
static VALUE utf8_bytes(rorb_bytes b) { return rb_enc_associate(bytes_str(b), rb_utf8_encoding()); }
|
|
3138
|
+
|
|
3139
|
+
/* --- RequestInfo: what ClientRequestInfo (cri) and ServerRequestInfo (sri) share --- */
|
|
3140
|
+
|
|
3141
|
+
#define RI_COMMON(P, R) \
|
|
3142
|
+
static VALUE P##_request_id(VALUE self) { return UINT2NUM(rorb_##P##_request_id(R(self))); } \
|
|
3143
|
+
static VALUE P##_operation(VALUE self) { \
|
|
3144
|
+
size_t len = 0; \
|
|
3145
|
+
const char* s = rorb_##P##_operation(R(self), &len); \
|
|
3146
|
+
return utf8(s, len); \
|
|
3147
|
+
} \
|
|
3148
|
+
static VALUE P##_response_expected(VALUE self) { \
|
|
3149
|
+
return rorb_##P##_response_expected(R(self)) ? Qtrue : Qfalse; \
|
|
3150
|
+
} \
|
|
3151
|
+
static VALUE P##_sync_scope(VALUE self) { return INT2FIX(rorb_##P##_sync_scope(R(self))); } \
|
|
3152
|
+
static VALUE P##_reply_status(VALUE self) { \
|
|
3153
|
+
int16_t s = 0; \
|
|
3154
|
+
CHECK(rorb_##P##_reply_status(R(self), &s, EXC)); \
|
|
3155
|
+
return INT2FIX(s); \
|
|
3156
|
+
} \
|
|
3157
|
+
static VALUE P##_forward_reference(VALUE self) { \
|
|
3158
|
+
rorb_object* o = NULL; \
|
|
3159
|
+
CHECK(rorb_##P##_forward_reference(R(self), &o, EXC)); \
|
|
3160
|
+
return W_OBJ(o); \
|
|
3161
|
+
} \
|
|
3162
|
+
static VALUE P##_get_slot(VALUE self, VALUE id) { \
|
|
3163
|
+
rorb_any* a = NULL; \
|
|
3164
|
+
CHECK(rorb_##P##_get_slot(R(self), NUM2UINT(id), &a, EXC)); \
|
|
3165
|
+
return W_ANY(a); \
|
|
3166
|
+
} \
|
|
3167
|
+
static VALUE P##_get_request_service_context(VALUE self, VALUE id) { \
|
|
3168
|
+
rorb_bytes b; \
|
|
3169
|
+
memset(&b, 0, sizeof b); \
|
|
3170
|
+
CHECK(rorb_##P##_get_request_service_context(R(self), NUM2UINT(id), &b, EXC)); \
|
|
3171
|
+
return bytes_str(b); \
|
|
3172
|
+
} \
|
|
3173
|
+
static VALUE P##_get_reply_service_context(VALUE self, VALUE id) { \
|
|
3174
|
+
rorb_bytes b; \
|
|
3175
|
+
memset(&b, 0, sizeof b); \
|
|
3176
|
+
CHECK(rorb_##P##_get_reply_service_context(R(self), NUM2UINT(id), &b, EXC)); \
|
|
3177
|
+
return bytes_str(b); \
|
|
3178
|
+
} \
|
|
3179
|
+
static VALUE P##_arguments(VALUE self) { \
|
|
3180
|
+
VALUE r = rb_ary_new(); \
|
|
3181
|
+
CHECK(rorb_##P##_arguments(R(self), &r, pi_each_parameter, EXC)); \
|
|
3182
|
+
return r; \
|
|
3183
|
+
} \
|
|
3184
|
+
static VALUE P##_exceptions(VALUE self) { \
|
|
3185
|
+
VALUE r = rb_ary_new(); \
|
|
3186
|
+
CHECK(rorb_##P##_exceptions(R(self), &r, pi_each_typecode, EXC)); \
|
|
3187
|
+
return r; \
|
|
3188
|
+
} \
|
|
3189
|
+
static VALUE P##_result(VALUE self) { \
|
|
3190
|
+
rorb_any* a = NULL; \
|
|
3191
|
+
CHECK(rorb_##P##_result(R(self), &a, EXC)); \
|
|
3192
|
+
return W_ANY(a); \
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3195
|
+
RI_COMMON(cri, CRI)
|
|
3196
|
+
RI_COMMON(sri, SRI)
|
|
3197
|
+
|
|
3198
|
+
static VALUE cri_target(VALUE self) { return W_OBJ(rorb_cri_target(CRI(self))); }
|
|
3199
|
+
static VALUE cri_effective_target(VALUE self) { return W_OBJ(rorb_cri_effective_target(CRI(self))); }
|
|
3200
|
+
static VALUE cri_effective_profile(VALUE self) {
|
|
3201
|
+
rorb_bytes b;
|
|
3202
|
+
uint32_t tag;
|
|
3203
|
+
memset(&b, 0, sizeof b);
|
|
3204
|
+
tag = rorb_cri_effective_profile(CRI(self), &b);
|
|
3205
|
+
return rb_assoc_new(UINT2NUM(tag), bytes_str(b));
|
|
3206
|
+
}
|
|
3207
|
+
static VALUE cri_received_exception(VALUE self) {
|
|
3208
|
+
rorb_any* a = NULL;
|
|
3209
|
+
CHECK(rorb_cri_received_exception(CRI(self), &a, EXC));
|
|
3210
|
+
return W_ANY(a);
|
|
3211
|
+
}
|
|
3212
|
+
static VALUE cri_received_exception_id(VALUE self) {
|
|
3213
|
+
rorb_bytes b;
|
|
3214
|
+
memset(&b, 0, sizeof b);
|
|
3215
|
+
CHECK(rorb_cri_received_exception_id(CRI(self), &b, EXC));
|
|
3216
|
+
return utf8_bytes(b);
|
|
3217
|
+
}
|
|
3218
|
+
static VALUE cri_get_effective_component(VALUE self, VALUE tag) {
|
|
3219
|
+
rorb_bytes b;
|
|
3220
|
+
memset(&b, 0, sizeof b);
|
|
3221
|
+
CHECK(rorb_cri_get_effective_component(CRI(self), NUM2UINT(tag), &b, EXC));
|
|
3222
|
+
return bytes_str(b);
|
|
3223
|
+
}
|
|
3224
|
+
static VALUE cri_get_effective_components(VALUE self, VALUE tag) {
|
|
3225
|
+
VALUE r = rb_ary_new();
|
|
3226
|
+
CHECK(rorb_cri_get_effective_components(CRI(self), NUM2UINT(tag), &r, pi_each_component, EXC));
|
|
3227
|
+
return r;
|
|
3228
|
+
}
|
|
3229
|
+
/* The raw value of the policy, or nil. */
|
|
3230
|
+
static VALUE cri_get_request_policy(VALUE self, VALUE type) {
|
|
3231
|
+
int32_t found = 0;
|
|
3232
|
+
uint64_t raw = 0;
|
|
3233
|
+
CHECK(rorb_cri_get_request_policy(CRI(self), NUM2UINT(type), &found, &raw, EXC));
|
|
3234
|
+
return found ? ULL2NUM(raw) : Qnil;
|
|
3235
|
+
}
|
|
3236
|
+
static VALUE cri_add_request_service_context(VALUE self, VALUE id, VALUE data, VALUE replace) {
|
|
3237
|
+
StringValue(data);
|
|
3238
|
+
CHECK(rorb_cri_add_request_service_context(CRI(self), NUM2UINT(id),
|
|
3239
|
+
(const uint8_t*)RSTRING_PTR(data),
|
|
3240
|
+
(size_t)RSTRING_LEN(data), RTEST(replace), EXC));
|
|
3241
|
+
RB_GC_GUARD(data);
|
|
3242
|
+
return Qnil;
|
|
3243
|
+
}
|
|
3244
|
+
|
|
3245
|
+
static VALUE sri_set_slot(VALUE self, VALUE id, VALUE any) {
|
|
3246
|
+
CHECK(rorb_sri_set_slot(SRI(self), NUM2UINT(id), ANY(any), EXC));
|
|
3247
|
+
return Qnil;
|
|
3248
|
+
}
|
|
3249
|
+
static VALUE sri_add_reply_service_context(VALUE self, VALUE id, VALUE data, VALUE replace) {
|
|
3250
|
+
StringValue(data);
|
|
3251
|
+
CHECK(rorb_sri_add_reply_service_context(SRI(self), NUM2UINT(id),
|
|
3252
|
+
(const uint8_t*)RSTRING_PTR(data),
|
|
3253
|
+
(size_t)RSTRING_LEN(data), RTEST(replace), EXC));
|
|
3254
|
+
RB_GC_GUARD(data);
|
|
3255
|
+
return Qnil;
|
|
3256
|
+
}
|
|
3257
|
+
static VALUE sri_sending_exception(VALUE self) {
|
|
3258
|
+
rorb_any* a = NULL;
|
|
3259
|
+
CHECK(rorb_sri_sending_exception(SRI(self), &a, EXC));
|
|
3260
|
+
return W_ANY(a);
|
|
3261
|
+
}
|
|
3262
|
+
static VALUE sri_sending_exception_id(VALUE self) {
|
|
3263
|
+
rorb_bytes b;
|
|
3264
|
+
memset(&b, 0, sizeof b);
|
|
3265
|
+
CHECK(rorb_sri_sending_exception_id(SRI(self), &b, EXC));
|
|
3266
|
+
return utf8_bytes(b);
|
|
3267
|
+
}
|
|
3268
|
+
static VALUE sri_object_id(VALUE self) {
|
|
3269
|
+
rorb_bytes b;
|
|
3270
|
+
memset(&b, 0, sizeof b);
|
|
3271
|
+
CHECK(rorb_sri_object_id(SRI(self), &b, EXC));
|
|
3272
|
+
return bytes_str(b);
|
|
3273
|
+
}
|
|
3274
|
+
static VALUE sri_adapter_id(VALUE self) {
|
|
3275
|
+
rorb_bytes b;
|
|
3276
|
+
memset(&b, 0, sizeof b);
|
|
3277
|
+
CHECK(rorb_sri_adapter_id(SRI(self), &b, EXC));
|
|
3278
|
+
return bytes_str(b);
|
|
3279
|
+
}
|
|
3280
|
+
static VALUE sri_adapter_name(VALUE self) {
|
|
3281
|
+
VALUE r = rb_ary_new();
|
|
3282
|
+
CHECK(rorb_sri_adapter_name(SRI(self), &r, pi_each_string, EXC));
|
|
3283
|
+
return r;
|
|
3284
|
+
}
|
|
3285
|
+
static VALUE sri_orb_id(VALUE self) {
|
|
3286
|
+
size_t len = 0;
|
|
3287
|
+
const char* s = rorb_sri_orb_id(SRI(self), &len);
|
|
3288
|
+
return utf8(s, len);
|
|
3289
|
+
}
|
|
3290
|
+
static VALUE sri_server_id(VALUE self) {
|
|
3291
|
+
size_t len = 0;
|
|
3292
|
+
const char* s = rorb_sri_server_id(SRI(self), &len);
|
|
3293
|
+
return utf8(s, len);
|
|
3294
|
+
}
|
|
3295
|
+
static VALUE sri_target_most_derived_interface(VALUE self) {
|
|
3296
|
+
rorb_bytes b;
|
|
3297
|
+
memset(&b, 0, sizeof b);
|
|
3298
|
+
CHECK(rorb_sri_target_most_derived_interface(SRI(self), &b, EXC));
|
|
3299
|
+
return utf8_bytes(b);
|
|
3300
|
+
}
|
|
3301
|
+
static VALUE sri_target_is_a(VALUE self, VALUE id) {
|
|
3302
|
+
int32_t is_a = 0;
|
|
3303
|
+
id = utf8_arg(id);
|
|
3304
|
+
CHECK(rorb_sri_target_is_a(SRI(self), RSTRING_PTR(id), (size_t)RSTRING_LEN(id), &is_a, EXC));
|
|
3305
|
+
RB_GC_GUARD(id);
|
|
3306
|
+
return is_a ? Qtrue : Qfalse;
|
|
3307
|
+
}
|
|
3308
|
+
static VALUE sri_get_server_policy(VALUE self, VALUE type) {
|
|
3309
|
+
uint64_t raw = 0;
|
|
3310
|
+
CHECK(rorb_sri_get_server_policy(SRI(self), NUM2UINT(type), &raw, EXC));
|
|
3311
|
+
return ULL2NUM(raw);
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3314
|
+
/* --- IORInfo ------------------------------------------------------------------------ */
|
|
3315
|
+
|
|
3316
|
+
static VALUE iori_get_effective_policy(VALUE self, VALUE type) {
|
|
3317
|
+
uint64_t raw = 0;
|
|
3318
|
+
CHECK(rorb_ior_info_get_effective_policy(IORI(self), NUM2UINT(type), &raw, EXC));
|
|
3319
|
+
return ULL2NUM(raw);
|
|
3320
|
+
}
|
|
3321
|
+
static VALUE iori_adapter_name(VALUE self) {
|
|
3322
|
+
VALUE r = rb_ary_new();
|
|
3323
|
+
rorb_ior_info_adapter_name(IORI(self), &r, pi_each_string);
|
|
3324
|
+
return r;
|
|
3325
|
+
}
|
|
3326
|
+
static VALUE iori_add_ior_component(VALUE self, VALUE tag, VALUE data) {
|
|
3327
|
+
StringValue(data);
|
|
3328
|
+
rorb_ior_info_add_ior_component(IORI(self), NUM2UINT(tag), (const uint8_t*)RSTRING_PTR(data),
|
|
3329
|
+
(size_t)RSTRING_LEN(data));
|
|
3330
|
+
RB_GC_GUARD(data);
|
|
3331
|
+
return Qnil;
|
|
3332
|
+
}
|
|
3333
|
+
static VALUE iori_add_ior_component_to_profile(VALUE self, VALUE tag, VALUE data, VALUE profile) {
|
|
3334
|
+
StringValue(data);
|
|
3335
|
+
CHECK(rorb_ior_info_add_ior_component_to_profile(IORI(self), NUM2UINT(tag),
|
|
3336
|
+
(const uint8_t*)RSTRING_PTR(data),
|
|
3337
|
+
(size_t)RSTRING_LEN(data), NUM2UINT(profile),
|
|
3338
|
+
EXC));
|
|
3339
|
+
RB_GC_GUARD(data);
|
|
3340
|
+
return Qnil;
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
/* --- ORBInitInfo ---------------------------------------------------------------------- */
|
|
3344
|
+
|
|
3345
|
+
static VALUE initi_arguments(VALUE self) {
|
|
3346
|
+
VALUE r = rb_ary_new();
|
|
3347
|
+
rorb_init_info_arguments(INITI(self), &r, pi_each_string);
|
|
3348
|
+
return r;
|
|
3349
|
+
}
|
|
3350
|
+
static VALUE initi_orb_id(VALUE self) {
|
|
3351
|
+
size_t len = 0;
|
|
3352
|
+
const char* s = rorb_init_info_orb_id(INITI(self), &len);
|
|
3353
|
+
return utf8(s, len);
|
|
3354
|
+
}
|
|
3355
|
+
static VALUE initi_orb(VALUE self) { return W_ORB(rorb_init_info_orb(INITI(self))); }
|
|
3356
|
+
static VALUE initi_register_initial_reference(VALUE self, VALUE name, VALUE obj) {
|
|
3357
|
+
name = utf8_arg(name);
|
|
3358
|
+
CHECK(rorb_init_info_register_initial_reference(INITI(self), RSTRING_PTR(name),
|
|
3359
|
+
(size_t)RSTRING_LEN(name), unwrap_opt(obj, cRef),
|
|
3360
|
+
EXC));
|
|
3361
|
+
RB_GC_GUARD(name);
|
|
3362
|
+
return Qnil;
|
|
3363
|
+
}
|
|
3364
|
+
static VALUE initi_resolve_initial_references(VALUE self, VALUE name) {
|
|
3365
|
+
rorb_object* o = NULL;
|
|
3366
|
+
name = utf8_arg(name);
|
|
3367
|
+
CHECK(rorb_init_info_resolve_initial_references(INITI(self), RSTRING_PTR(name),
|
|
3368
|
+
(size_t)RSTRING_LEN(name), &o, EXC));
|
|
3369
|
+
RB_GC_GUARD(name);
|
|
3370
|
+
return W_OBJ(o);
|
|
3371
|
+
}
|
|
3372
|
+
|
|
3373
|
+
/* add_*_interceptor(name, obj): RORB_DUPLICATE_NAME raises the local
|
|
3374
|
+
exception 22. */
|
|
3375
|
+
#define INIT_ADD(fn, cfn, vt) \
|
|
3376
|
+
static VALUE fn(VALUE self, VALUE name, VALUE obj) { \
|
|
3377
|
+
host* h; \
|
|
3378
|
+
rorb_exception exc; \
|
|
3379
|
+
rorb_status st; \
|
|
3380
|
+
rorb_orb_init_info* info = INITI(self); \
|
|
3381
|
+
name = utf8_arg(name); \
|
|
3382
|
+
h = host_retain(obj); \
|
|
3383
|
+
memset(&exc, 0, sizeof exc); \
|
|
3384
|
+
st = cfn(info, RSTRING_PTR(name), (size_t)RSTRING_LEN(name), h, &vt, &exc); \
|
|
3385
|
+
host_release(h); \
|
|
3386
|
+
RB_GC_GUARD(name); \
|
|
3387
|
+
if (st != RORB_OK) raise_status(st, &exc); \
|
|
3388
|
+
return Qnil; \
|
|
3389
|
+
}
|
|
3390
|
+
INIT_ADD(initi_add_client_request_interceptor, rorb_init_info_add_client_request_interceptor,
|
|
3391
|
+
client_interceptor_vtable)
|
|
3392
|
+
INIT_ADD(initi_add_server_request_interceptor, rorb_init_info_add_server_request_interceptor,
|
|
3393
|
+
server_interceptor_vtable)
|
|
3394
|
+
INIT_ADD(initi_add_ior_interceptor, rorb_init_info_add_ior_interceptor, ior_interceptor_vtable)
|
|
3395
|
+
|
|
3396
|
+
static VALUE initi_allocate_slot_id(VALUE self) {
|
|
3397
|
+
return UINT2NUM(rorb_init_info_allocate_slot_id(INITI(self)));
|
|
3398
|
+
}
|
|
3399
|
+
static VALUE initi_pi_current(VALUE self) {
|
|
3400
|
+
return wrap(cPICurrent, rorb_init_info_pi_current(INITI(self)), rel_pi_current);
|
|
3401
|
+
}
|
|
3402
|
+
static VALUE initi_create_codec(VALUE self, VALUE format, VALUE major, VALUE minor) {
|
|
3403
|
+
rorb_codec* c = NULL;
|
|
3404
|
+
CHECK(rorb_init_info_create_codec(INITI(self), (int16_t)NUM2INT(format), (uint8_t)NUM2UINT(major),
|
|
3405
|
+
(uint8_t)NUM2UINT(minor), &c, EXC));
|
|
3406
|
+
return wrap(cCodec, c, rel_codec);
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
/* --- PICurrent and the codecs --------------------------------------------------------- */
|
|
3410
|
+
|
|
3411
|
+
static VALUE orb_pi_current(VALUE self) {
|
|
3412
|
+
return wrap(cPICurrent, rorb_orb_pi_current(ORB(self)), rel_pi_current);
|
|
3413
|
+
}
|
|
3414
|
+
|
|
3415
|
+
/* The slots are per thread: in an upcall, those of the thread rustorb runs
|
|
3416
|
+
it on (at_home). */
|
|
3417
|
+
struct slot_call {
|
|
3418
|
+
rorb_pi_current* current;
|
|
3419
|
+
uint32_t id;
|
|
3420
|
+
rorb_any* any;
|
|
3421
|
+
int set;
|
|
3422
|
+
rorb_status st;
|
|
3423
|
+
rorb_exception exc;
|
|
3424
|
+
};
|
|
3425
|
+
static void* slot_nogvl(void* p) {
|
|
3426
|
+
struct slot_call* c = p;
|
|
3427
|
+
c->st = c->set ? rorb_pi_current_set_slot(c->current, c->id, c->any, &c->exc)
|
|
3428
|
+
: rorb_pi_current_get_slot(c->current, c->id, &c->any, &c->exc);
|
|
3429
|
+
return NULL;
|
|
3430
|
+
}
|
|
3431
|
+
static VALUE picur_get_slot(VALUE self, VALUE id) {
|
|
3432
|
+
struct slot_call c;
|
|
3433
|
+
memset(&c, 0, sizeof c);
|
|
3434
|
+
c.current = PICUR(self);
|
|
3435
|
+
c.id = NUM2UINT(id);
|
|
3436
|
+
at_home(slot_nogvl, &c);
|
|
3437
|
+
if (c.st != RORB_OK) raise_status(c.st, &c.exc);
|
|
3438
|
+
return W_ANY(c.any);
|
|
3439
|
+
}
|
|
3440
|
+
static VALUE picur_set_slot(VALUE self, VALUE id, VALUE any) {
|
|
3441
|
+
struct slot_call c;
|
|
3442
|
+
memset(&c, 0, sizeof c);
|
|
3443
|
+
c.current = PICUR(self);
|
|
3444
|
+
c.id = NUM2UINT(id);
|
|
3445
|
+
c.any = ANY(any);
|
|
3446
|
+
c.set = 1;
|
|
3447
|
+
at_home(slot_nogvl, &c);
|
|
3448
|
+
RB_GC_GUARD(any);
|
|
3449
|
+
if (c.st != RORB_OK) raise_status(c.st, &c.exc);
|
|
3450
|
+
return Qnil;
|
|
3451
|
+
}
|
|
3452
|
+
|
|
3453
|
+
static VALUE orb_create_codec(VALUE self, VALUE format, VALUE major, VALUE minor) {
|
|
3454
|
+
rorb_codec* c = NULL;
|
|
3455
|
+
CHECK(rorb_orb_create_codec(ORB(self), (int16_t)NUM2INT(format), (uint8_t)NUM2UINT(major),
|
|
3456
|
+
(uint8_t)NUM2UINT(minor), &c, EXC));
|
|
3457
|
+
return wrap(cCodec, c, rel_codec);
|
|
3458
|
+
}
|
|
3459
|
+
static VALUE codec_encode(VALUE self, VALUE any, VALUE value_only) {
|
|
3460
|
+
rorb_bytes b;
|
|
3461
|
+
memset(&b, 0, sizeof b);
|
|
3462
|
+
CHECK(rorb_codec_encode(CODEC(self), ANY(any), RTEST(value_only), &b, EXC));
|
|
3463
|
+
return bytes_str(b);
|
|
3464
|
+
}
|
|
3465
|
+
static VALUE codec_decode(VALUE self, VALUE data, VALUE tc) {
|
|
3466
|
+
rorb_any* a = NULL;
|
|
3467
|
+
StringValue(data);
|
|
3468
|
+
CHECK(rorb_codec_decode(CODEC(self), (const uint8_t*)RSTRING_PTR(data), (size_t)RSTRING_LEN(data),
|
|
3469
|
+
NIL_P(tc) ? NULL : TC(tc), &a, EXC));
|
|
3470
|
+
RB_GC_GUARD(data);
|
|
3471
|
+
return W_ANY(a);
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
static VALUE pi_class(const char* name) {
|
|
3475
|
+
VALUE k = rb_define_class_under(mNative, name, rb_cObject);
|
|
3476
|
+
rb_undef_alloc_func(k);
|
|
3477
|
+
return k;
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3480
|
+
static void init_pi(void) {
|
|
3481
|
+
id_point = rb_intern("point");
|
|
3482
|
+
id_destroy_interceptor = rb_intern("destroy_interceptor");
|
|
3483
|
+
sym_system = ID2SYM(rb_intern("system"));
|
|
3484
|
+
mPI = rb_define_module_under(mRustorb, "PI");
|
|
3485
|
+
SDEF(mNative, "register_orb_initializer", native_register_orb_initializer, 1);
|
|
3486
|
+
SDEF(mNative, "orb_init_pi", native_orb_init_pi, 3);
|
|
3487
|
+
DEF(cORB, "pi_current", orb_pi_current, 0);
|
|
3488
|
+
DEF(cORB, "create_codec", orb_create_codec, 3);
|
|
3489
|
+
|
|
3490
|
+
#define RI_DEFS(k, P) \
|
|
3491
|
+
DEF(k, "request_id", P##_request_id, 0); \
|
|
3492
|
+
DEF(k, "operation", P##_operation, 0); \
|
|
3493
|
+
DEF(k, "response_expected", P##_response_expected, 0); \
|
|
3494
|
+
DEF(k, "sync_scope", P##_sync_scope, 0); \
|
|
3495
|
+
DEF(k, "reply_status", P##_reply_status, 0); \
|
|
3496
|
+
DEF(k, "forward_reference", P##_forward_reference, 0); \
|
|
3497
|
+
DEF(k, "get_slot", P##_get_slot, 1); \
|
|
3498
|
+
DEF(k, "get_request_service_context", P##_get_request_service_context, 1); \
|
|
3499
|
+
DEF(k, "get_reply_service_context", P##_get_reply_service_context, 1); \
|
|
3500
|
+
DEF(k, "arguments", P##_arguments, 0); \
|
|
3501
|
+
DEF(k, "exceptions", P##_exceptions, 0); \
|
|
3502
|
+
DEF(k, "result", P##_result, 0)
|
|
3503
|
+
cCRInfo = pi_class("ClientRequestInfo");
|
|
3504
|
+
RI_DEFS(cCRInfo, cri);
|
|
3505
|
+
DEF(cCRInfo, "target", cri_target, 0);
|
|
3506
|
+
DEF(cCRInfo, "effective_target", cri_effective_target, 0);
|
|
3507
|
+
DEF(cCRInfo, "effective_profile", cri_effective_profile, 0);
|
|
3508
|
+
DEF(cCRInfo, "received_exception", cri_received_exception, 0);
|
|
3509
|
+
DEF(cCRInfo, "received_exception_id", cri_received_exception_id, 0);
|
|
3510
|
+
DEF(cCRInfo, "get_effective_component", cri_get_effective_component, 1);
|
|
3511
|
+
DEF(cCRInfo, "get_effective_components", cri_get_effective_components, 1);
|
|
3512
|
+
DEF(cCRInfo, "get_request_policy", cri_get_request_policy, 1);
|
|
3513
|
+
DEF(cCRInfo, "add_request_service_context", cri_add_request_service_context, 3);
|
|
3514
|
+
|
|
3515
|
+
cSRInfo = pi_class("ServerRequestInfo");
|
|
3516
|
+
RI_DEFS(cSRInfo, sri);
|
|
3517
|
+
DEF(cSRInfo, "set_slot", sri_set_slot, 2);
|
|
3518
|
+
DEF(cSRInfo, "add_reply_service_context", sri_add_reply_service_context, 3);
|
|
3519
|
+
DEF(cSRInfo, "sending_exception", sri_sending_exception, 0);
|
|
3520
|
+
DEF(cSRInfo, "sending_exception_id", sri_sending_exception_id, 0);
|
|
3521
|
+
DEF(cSRInfo, "object_id", sri_object_id, 0);
|
|
3522
|
+
DEF(cSRInfo, "adapter_id", sri_adapter_id, 0);
|
|
3523
|
+
DEF(cSRInfo, "adapter_name", sri_adapter_name, 0);
|
|
3524
|
+
DEF(cSRInfo, "orb_id", sri_orb_id, 0);
|
|
3525
|
+
DEF(cSRInfo, "server_id", sri_server_id, 0);
|
|
3526
|
+
DEF(cSRInfo, "target_most_derived_interface", sri_target_most_derived_interface, 0);
|
|
3527
|
+
DEF(cSRInfo, "target_is_a", sri_target_is_a, 1);
|
|
3528
|
+
DEF(cSRInfo, "get_server_policy", sri_get_server_policy, 1);
|
|
3529
|
+
#undef RI_DEFS
|
|
3530
|
+
|
|
3531
|
+
cIORInfo = pi_class("IORInfo");
|
|
3532
|
+
DEF(cIORInfo, "get_effective_policy", iori_get_effective_policy, 1);
|
|
3533
|
+
DEF(cIORInfo, "adapter_name", iori_adapter_name, 0);
|
|
3534
|
+
DEF(cIORInfo, "add_ior_component", iori_add_ior_component, 2);
|
|
3535
|
+
DEF(cIORInfo, "add_ior_component_to_profile", iori_add_ior_component_to_profile, 3);
|
|
3536
|
+
|
|
3537
|
+
cInitInfo = pi_class("ORBInitInfo");
|
|
3538
|
+
DEF(cInitInfo, "arguments", initi_arguments, 0);
|
|
3539
|
+
DEF(cInitInfo, "orb_id", initi_orb_id, 0);
|
|
3540
|
+
DEF(cInitInfo, "orb", initi_orb, 0);
|
|
3541
|
+
DEF(cInitInfo, "register_initial_reference", initi_register_initial_reference, 2);
|
|
3542
|
+
DEF(cInitInfo, "resolve_initial_references", initi_resolve_initial_references, 1);
|
|
3543
|
+
DEF(cInitInfo, "add_client_request_interceptor", initi_add_client_request_interceptor, 2);
|
|
3544
|
+
DEF(cInitInfo, "add_server_request_interceptor", initi_add_server_request_interceptor, 2);
|
|
3545
|
+
DEF(cInitInfo, "add_ior_interceptor", initi_add_ior_interceptor, 2);
|
|
3546
|
+
DEF(cInitInfo, "allocate_slot_id", initi_allocate_slot_id, 0);
|
|
3547
|
+
DEF(cInitInfo, "pi_current", initi_pi_current, 0);
|
|
3548
|
+
DEF(cInitInfo, "create_codec", initi_create_codec, 3);
|
|
3549
|
+
|
|
3550
|
+
cPICurrent = pi_class("PICurrent");
|
|
3551
|
+
DEF(cPICurrent, "get_slot", picur_get_slot, 1);
|
|
3552
|
+
DEF(cPICurrent, "set_slot", picur_set_slot, 2);
|
|
3553
|
+
|
|
3554
|
+
cCodec = pi_class("Codec");
|
|
3555
|
+
DEF(cCodec, "encode", codec_encode, 2);
|
|
3556
|
+
DEF(cCodec, "decode", codec_decode, 2);
|
|
3557
|
+
}
|
|
3558
|
+
|
|
3559
|
+
/* Rustorb::Native.upcall_thread: an Integer that names the native thread
|
|
3560
|
+
rustorb runs the current upcall on (the thread waiting for this
|
|
3561
|
+
dispatcher), or this thread outside an upcall; main_thread: that of the
|
|
3562
|
+
thread that loaded the extension. For probes of the thread model. */
|
|
3563
|
+
static pthread_t main_pthread;
|
|
3564
|
+
static void* self_thread(void* out) {
|
|
3565
|
+
*(pthread_t*)out = pthread_self();
|
|
3566
|
+
return NULL;
|
|
3567
|
+
}
|
|
3568
|
+
static VALUE native_upcall_thread(VALUE self) {
|
|
3569
|
+
pthread_t t;
|
|
3570
|
+
(void)self;
|
|
3571
|
+
at_home(self_thread, &t);
|
|
3572
|
+
return ULL2NUM((unsigned long long)(uintptr_t)t);
|
|
3573
|
+
}
|
|
3574
|
+
static VALUE native_main_thread(VALUE self) {
|
|
3575
|
+
(void)self;
|
|
3576
|
+
return ULL2NUM((unsigned long long)(uintptr_t)main_pthread);
|
|
3577
|
+
}
|
|
3578
|
+
|
|
3579
|
+
static VALUE handle_class(const char* name) {
|
|
3580
|
+
VALUE k = rb_define_class_under(mNative, name, rb_cObject);
|
|
3581
|
+
rb_undef_alloc_func(k);
|
|
3582
|
+
return k;
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
void Init_rustorb_ext(void) {
|
|
3586
|
+
VALUE registry;
|
|
3587
|
+
id_call = rb_intern("call");
|
|
3588
|
+
id_system_exception = rb_intern("system_exception");
|
|
3589
|
+
id_local_exception = rb_intern("local_exception");
|
|
3590
|
+
id_dispatch = rb_intern("_rustorb_dispatch");
|
|
3591
|
+
id_spawn_dispatcher = rb_intern("spawn_dispatcher");
|
|
3592
|
+
id_peer_ivar = rb_intern("@__rustorb_peer");
|
|
3593
|
+
|
|
3594
|
+
mRustorb = rb_define_module("Rustorb");
|
|
3595
|
+
mNative = rb_define_module_under(mRustorb, "Native");
|
|
3596
|
+
rb_define_const(mNative, "ABI_VERSION", INT2FIX(RORB_ABI_VERSION));
|
|
3597
|
+
|
|
3598
|
+
/* Not NULL: the GC calls the mark function of data only when it has a
|
|
3599
|
+
pointer. */
|
|
3600
|
+
registry = TypedData_Wrap_Struct(rb_cObject, ®istry_type, &peers);
|
|
3601
|
+
rb_gc_register_mark_object(registry);
|
|
3602
|
+
rb_gc_register_mark_object(TypedData_Wrap_Struct(rb_cObject, &hosts_type, host_buckets));
|
|
3603
|
+
rorb_set_value_type_resolver(resolve_value_type, NULL);
|
|
3604
|
+
rb_define_module_function(mNative, "kept_values", native_kept_values, 0);
|
|
3605
|
+
rb_define_module_function(mNative, "cdr_encode", native_cdr_encode, 2);
|
|
3606
|
+
rb_define_module_function(mNative, "cdr_decode", native_cdr_decode, 3);
|
|
3607
|
+
rb_set_end_proc(at_exit_dispatchers, Qnil);
|
|
3608
|
+
|
|
3609
|
+
SDEF(mNative, "orb_init", native_orb_init, 1);
|
|
3610
|
+
SDEF(mNative, "default_orb", native_default_orb, 0);
|
|
3611
|
+
SDEF(mNative, "default_root_poa", native_default_root_poa, 0);
|
|
3612
|
+
SDEF(mNative, "set_thread_call_timeout", native_set_thread_call_timeout, 1);
|
|
3613
|
+
SDEF(mNative, "thread_call_timeout", native_thread_call_timeout, 0);
|
|
3614
|
+
SDEF(mNative, "dispatcher_loop", native_dispatcher_loop, 0);
|
|
3615
|
+
SDEF(mNative, "dispatchers", native_dispatchers, 0);
|
|
3616
|
+
SDEF(mNative, "servant_ref", native_servant_ref, 2);
|
|
3617
|
+
SDEF(mNative, "current_poa", native_current_poa, 0);
|
|
3618
|
+
SDEF(mNative, "current_object_id", native_current_object_id, 0);
|
|
3619
|
+
SDEF(mNative, "current_reference", native_current_reference, 0);
|
|
3620
|
+
SDEF(mNative, "current_servant", native_current_servant, 0);
|
|
3621
|
+
SDEF(mNative, "longdouble_from_double", native_longdouble_from_double, 1);
|
|
3622
|
+
SDEF(mNative, "longdouble_to_double", native_longdouble_to_double, 2);
|
|
3623
|
+
|
|
3624
|
+
cORB = handle_class("ORB");
|
|
3625
|
+
DEF(cORB, "string_to_object", orb_string_to_object, 1);
|
|
3626
|
+
DEF(cORB, "object_to_string", orb_object_to_string, 1);
|
|
3627
|
+
DEF(cORB, "resolve_initial_references", orb_resolve, 1);
|
|
3628
|
+
DEF(cORB, "list_initial_services", orb_list_initial_services, 0);
|
|
3629
|
+
DEF(cORB, "root_poa", orb_root_poa, 0);
|
|
3630
|
+
DEF(cORB, "run", orb_run, 0);
|
|
3631
|
+
DEF(cORB, "shutdown", orb_shutdown, 1);
|
|
3632
|
+
DEF(cORB, "destroy", orb_destroy, 0);
|
|
3633
|
+
DEF(cORB, "work_pending", orb_work_pending, 0);
|
|
3634
|
+
DEF(cORB, "perform_work", orb_perform_work, 0);
|
|
3635
|
+
DEF(cORB, "set_call_timeout", orb_set_call_timeout, 1);
|
|
3636
|
+
DEF(cORB, "call_timeout", orb_call_timeout, 0);
|
|
3637
|
+
DEF(cORB, "set_connect_timeout", orb_set_connect_timeout, 1);
|
|
3638
|
+
DEF(cORB, "register_initial_reference", orb_register_initial_reference, 2);
|
|
3639
|
+
|
|
3640
|
+
cRef = handle_class("Ref");
|
|
3641
|
+
DEF(cRef, "is_a", ref_is_a, 1);
|
|
3642
|
+
DEF(cRef, "non_existent", ref_non_existent, 0);
|
|
3643
|
+
DEF(cRef, "validate_connection", ref_validate_connection, 0);
|
|
3644
|
+
DEF(cRef, "equivalent", ref_equivalent, 1);
|
|
3645
|
+
DEF(cRef, "hash_value", ref_hash, 1);
|
|
3646
|
+
DEF(cRef, "type_id", ref_type_id, 0);
|
|
3647
|
+
DEF(cRef, "orb", ref_orb, 0);
|
|
3648
|
+
DEF(cRef, "dup", ref_dup, 0);
|
|
3649
|
+
DEF(cRef, "set_call_timeout", ref_set_call_timeout, 1);
|
|
3650
|
+
DEF(cRef, "call_timeout", ref_call_timeout, 0);
|
|
3651
|
+
DEF(cRef, "invoke", ref_invoke, 6);
|
|
3652
|
+
DEF(cRef, "sendc", ref_sendc, 6);
|
|
3653
|
+
|
|
3654
|
+
cOut = handle_class("Out");
|
|
3655
|
+
DEF(cOut, "write_boolean", out_write_boolean, 1);
|
|
3656
|
+
DEF(cOut, "write_octet", out_write_octet, 1);
|
|
3657
|
+
DEF(cOut, "write_char", out_write_char, 1);
|
|
3658
|
+
DEF(cOut, "write_wchar", out_write_wchar, 1);
|
|
3659
|
+
DEF(cOut, "write_short", out_write_short, 1);
|
|
3660
|
+
DEF(cOut, "write_ushort", out_write_ushort, 1);
|
|
3661
|
+
DEF(cOut, "write_long", out_write_long, 1);
|
|
3662
|
+
DEF(cOut, "write_ulong", out_write_ulong, 1);
|
|
3663
|
+
DEF(cOut, "write_longlong", out_write_longlong, 1);
|
|
3664
|
+
DEF(cOut, "write_ulonglong", out_write_ulonglong, 1);
|
|
3665
|
+
DEF(cOut, "write_float", out_write_float, 1);
|
|
3666
|
+
DEF(cOut, "write_double", out_write_double, 1);
|
|
3667
|
+
DEF(cOut, "write_string", out_write_string, 1);
|
|
3668
|
+
DEF(cOut, "write_wstring", out_write_wstring, 1);
|
|
3669
|
+
DEF(cOut, "write_object", out_write_object, 1);
|
|
3670
|
+
DEF(cOut, "write_typecode", out_write_typecode, 1);
|
|
3671
|
+
DEF(cOut, "write_any", out_write_any, 1);
|
|
3672
|
+
DEF(cOut, "write_any_value", out_write_any_value, 1);
|
|
3673
|
+
DEF(cOut, "write_longdouble", out_write_longdouble, 2);
|
|
3674
|
+
DEF(cOut, "write_fixed", out_write_fixed, 2);
|
|
3675
|
+
DEF(cOut, "write_array", out_write_array, 2);
|
|
3676
|
+
DEF(cOut, "failed?", out_failed, 0);
|
|
3677
|
+
DEF(cOut, "keeps_hosts?", out_keeps_hosts, 0);
|
|
3678
|
+
DEF(cOut, "write_null_value", out_write_null_value, 0);
|
|
3679
|
+
DEF(cOut, "begin_value", out_begin_value, 3);
|
|
3680
|
+
DEF(cOut, "end_value", out_end_value, 0);
|
|
3681
|
+
|
|
3682
|
+
cIn = handle_class("In");
|
|
3683
|
+
DEF(cIn, "read_boolean", in_read_boolean, 0);
|
|
3684
|
+
DEF(cIn, "read_octet", in_read_octet, 0);
|
|
3685
|
+
DEF(cIn, "read_char", in_read_char, 0);
|
|
3686
|
+
DEF(cIn, "read_wchar", in_read_wchar, 0);
|
|
3687
|
+
DEF(cIn, "read_short", in_read_short, 0);
|
|
3688
|
+
DEF(cIn, "read_ushort", in_read_ushort, 0);
|
|
3689
|
+
DEF(cIn, "read_long", in_read_long, 0);
|
|
3690
|
+
DEF(cIn, "read_ulong", in_read_ulong, 0);
|
|
3691
|
+
DEF(cIn, "read_longlong", in_read_longlong, 0);
|
|
3692
|
+
DEF(cIn, "read_ulonglong", in_read_ulonglong, 0);
|
|
3693
|
+
DEF(cIn, "read_float", in_read_float, 0);
|
|
3694
|
+
DEF(cIn, "read_double", in_read_double, 0);
|
|
3695
|
+
DEF(cIn, "read_longdouble", in_read_longdouble, 0);
|
|
3696
|
+
DEF(cIn, "read_string", in_read_string, 0);
|
|
3697
|
+
DEF(cIn, "read_wstring", in_read_wstring, 0);
|
|
3698
|
+
DEF(cIn, "read_object", in_read_object, 0);
|
|
3699
|
+
DEF(cIn, "read_typecode", in_read_typecode, 0);
|
|
3700
|
+
DEF(cIn, "read_any", in_read_any, 0);
|
|
3701
|
+
DEF(cIn, "read_any_value", in_read_any_value, 1);
|
|
3702
|
+
DEF(cIn, "read_array", in_read_array, 2);
|
|
3703
|
+
DEF(cIn, "read_fixed", in_read_fixed, 1);
|
|
3704
|
+
DEF(cIn, "read_length", in_read_length, 1);
|
|
3705
|
+
DEF(cIn, "fail", in_fail, 0);
|
|
3706
|
+
DEF(cIn, "failed?", in_failed, 0);
|
|
3707
|
+
DEF(cIn, "read_value_header", in_read_value_header, 0);
|
|
3708
|
+
DEF(cIn, "value_at", in_value_at, 1);
|
|
3709
|
+
DEF(cIn, "keep_value", in_keep_value, 2);
|
|
3710
|
+
DEF(cIn, "end_value", in_end_value, 0);
|
|
3711
|
+
(void)rel_in;
|
|
3712
|
+
|
|
3713
|
+
cTC = handle_class("TC");
|
|
3714
|
+
SDEF(cTC, "simple", tc_simple, 1);
|
|
3715
|
+
SDEF(cTC, "string", tc_string, 2);
|
|
3716
|
+
SDEF(cTC, "fixed", tc_fixed, 2);
|
|
3717
|
+
SDEF(cTC, "sequence", tc_sequence, 2);
|
|
3718
|
+
SDEF(cTC, "array", tc_array, 2);
|
|
3719
|
+
SDEF(cTC, "alias", tc_alias, 4);
|
|
3720
|
+
SDEF(cTC, "interface", tc_interface, 3);
|
|
3721
|
+
SDEF(cTC, "struct", tc_struct, 5);
|
|
3722
|
+
SDEF(cTC, "value", tc_value, -1);
|
|
3723
|
+
SDEF(cTC, "union", tc_union, 7);
|
|
3724
|
+
SDEF(cTC, "enum", tc_enum, 3);
|
|
3725
|
+
SDEF(cTC, "recursive", tc_recursive, 1);
|
|
3726
|
+
DEF(cTC, "kind", tc_kind, 0);
|
|
3727
|
+
DEF(cTC, "id", tc_id, 0);
|
|
3728
|
+
DEF(cTC, "name", tc_name, 0);
|
|
3729
|
+
DEF(cTC, "member_count", tc_member_count, 0);
|
|
3730
|
+
DEF(cTC, "member_name", tc_member_name, 1);
|
|
3731
|
+
DEF(cTC, "member_type", tc_member_type, 1);
|
|
3732
|
+
DEF(cTC, "member_label", tc_member_label, 1);
|
|
3733
|
+
DEF(cTC, "discriminator_type", tc_discriminator_type, 0);
|
|
3734
|
+
DEF(cTC, "default_index", tc_default_index, 0);
|
|
3735
|
+
DEF(cTC, "length", tc_length, 0);
|
|
3736
|
+
DEF(cTC, "content_type", tc_content_type, 0);
|
|
3737
|
+
DEF(cTC, "fixed_digits", tc_fixed_digits, 0);
|
|
3738
|
+
DEF(cTC, "type_modifier", tc_type_modifier, 0);
|
|
3739
|
+
DEF(cTC, "member_visibility", tc_member_visibility, 1);
|
|
3740
|
+
DEF(cTC, "concrete_base_type", tc_concrete_base_type, 0);
|
|
3741
|
+
DEF(cTC, "fixed_scale", tc_fixed_scale, 0);
|
|
3742
|
+
DEF(cTC, "equal", tc_equal, 1);
|
|
3743
|
+
DEF(cTC, "equivalent", tc_equivalent, 1);
|
|
3744
|
+
DEF(cTC, "unaliased", tc_unaliased, 0);
|
|
3745
|
+
DEF(cTC, "compact", tc_compact, 0);
|
|
3746
|
+
|
|
3747
|
+
cAny = handle_class("Any");
|
|
3748
|
+
SDEF(cAny, "empty", any_new, 0);
|
|
3749
|
+
SDEF(cAny, "insert", any_insert, 2);
|
|
3750
|
+
SDEF(cAny, "typed", any_typed, 1);
|
|
3751
|
+
DEF(cAny, "extract", any_extract, 1);
|
|
3752
|
+
DEF(cAny, "type", any_type, 0);
|
|
3753
|
+
DEF(cAny, "set_type", any_set_type, 1);
|
|
3754
|
+
DEF(cAny, "equal", any_equal, 1);
|
|
3755
|
+
DEF(cAny, "label", any_label, 0);
|
|
3756
|
+
DEF(cAny, "dup", any_dup, 0);
|
|
3757
|
+
|
|
3758
|
+
cPeer = handle_class("Peer");
|
|
3759
|
+
cServantRef = handle_class("ServantRef");
|
|
3760
|
+
DEF(cServantRef, "current_reference", servant_ref_current_reference, 0);
|
|
3761
|
+
cReply = handle_class("Reply");
|
|
3762
|
+
DEF(cReply, "output", reply_output, 0);
|
|
3763
|
+
DEF(cReply, "user_exception", reply_user_exception, 1);
|
|
3764
|
+
DEF(cReply, "system_exception", reply_system_exception, 3);
|
|
3765
|
+
|
|
3766
|
+
cPOA = handle_class("POA");
|
|
3767
|
+
DEF(cPOA, "name", poa_name, 0);
|
|
3768
|
+
DEF(cPOA, "parent", poa_parent, 0);
|
|
3769
|
+
DEF(cPOA, "children", poa_children, 0);
|
|
3770
|
+
DEF(cPOA, "manager", poa_manager, 0);
|
|
3771
|
+
DEF(cPOA, "policies", poa_policies, 0);
|
|
3772
|
+
DEF(cPOA, "create_poa", poa_create_poa, 3);
|
|
3773
|
+
DEF(cPOA, "find_poa", poa_find_poa, 2);
|
|
3774
|
+
DEF(cPOA, "destroy", poa_destroy, 2);
|
|
3775
|
+
DEF(cPOA, "activate_object", poa_activate_object, 1);
|
|
3776
|
+
DEF(cPOA, "activate_object_with_id", poa_activate_object_with_id, 2);
|
|
3777
|
+
DEF(cPOA, "deactivate_object", poa_deactivate_object, 1);
|
|
3778
|
+
DEF(cPOA, "servant_to_id", poa_servant_to_id, 1);
|
|
3779
|
+
DEF(cPOA, "servant_to_reference", poa_servant_to_reference, 1);
|
|
3780
|
+
DEF(cPOA, "id_to_servant", poa_id_to_servant, 1);
|
|
3781
|
+
DEF(cPOA, "id_to_reference", poa_id_to_reference, 1);
|
|
3782
|
+
DEF(cPOA, "reference_to_id", poa_reference_to_id, 1);
|
|
3783
|
+
DEF(cPOA, "reference_to_servant", poa_reference_to_servant, 1);
|
|
3784
|
+
DEF(cPOA, "create_reference", poa_create_reference, 1);
|
|
3785
|
+
DEF(cPOA, "create_reference_with_id", poa_create_reference_with_id, 2);
|
|
3786
|
+
DEF(cPOA, "get_servant", poa_get_servant, 0);
|
|
3787
|
+
DEF(cPOA, "set_servant", poa_set_servant, 1);
|
|
3788
|
+
|
|
3789
|
+
cPOAManager = handle_class("POAManager");
|
|
3790
|
+
DEF(cPOAManager, "activate", mgr_activate, 0);
|
|
3791
|
+
DEF(cPOAManager, "hold_requests", mgr_hold, 1);
|
|
3792
|
+
DEF(cPOAManager, "discard_requests", mgr_discard, 1);
|
|
3793
|
+
DEF(cPOAManager, "deactivate", mgr_deactivate, 2);
|
|
3794
|
+
DEF(cPOAManager, "state", mgr_state, 0);
|
|
3795
|
+
DEF(cPOAManager, "id", mgr_id, 0);
|
|
3796
|
+
DEF(cPOAManager, "equal", mgr_equal, 1);
|
|
3797
|
+
|
|
3798
|
+
init_dynany();
|
|
3799
|
+
init_dii();
|
|
3800
|
+
init_managers();
|
|
3801
|
+
init_pi();
|
|
3802
|
+
main_pthread = pthread_self();
|
|
3803
|
+
rb_define_singleton_method(mNative, "upcall_thread", RUBY_METHOD_FUNC(native_upcall_thread), 0);
|
|
3804
|
+
rb_define_singleton_method(mNative, "main_thread", RUBY_METHOD_FUNC(native_main_thread), 0);
|
|
3805
|
+
}
|