rustorb-dds 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +26 -0
- data/ext/rustorb_dds_ext/extconf.rb +36 -0
- data/ext/rustorb_dds_ext/rustorb_dds_ext.c +2184 -0
- data/lib/rustorb/dds/core.rb +523 -0
- data/lib/rustorb/dds/domain.rb +133 -0
- data/lib/rustorb/dds/native.rb +140 -0
- data/lib/rustorb/dds/pub.rb +181 -0
- data/lib/rustorb/dds/qos.rb +343 -0
- data/lib/rustorb/dds/sub.rb +273 -0
- data/lib/rustorb/dds/topic.rb +115 -0
- data/lib/rustorb/dds/types.rb +780 -0
- data/lib/rustorb/dds/version.rb +8 -0
- data/lib/rustorb/dds.rb +32 -0
- data/vendor/include/rustorb/dds.h +955 -0
- data/vendor/linux-aarch64/librustorb_dds_ffi.a +4 -0
- data/vendor/linux-x86_64/librustorb_dds_ffi.a +4 -0
- data/vendor/macos-aarch64/librustorb_dds_ffi.a +0 -0
- data/vendor/macos-x86_64/librustorb_dds_ffi.a +0 -0
- metadata +64 -0
|
@@ -0,0 +1,2184 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* rustorb_dds_ext: the native part of the rustorb-dds gem, on the C ABI of
|
|
3
|
+
* librustorb_dds_ffi (rustorb/dds.h). It wraps the handles (types,
|
|
4
|
+
* entities, conditions), the sample streams (rdds_out, rdds_in), the QoS
|
|
5
|
+
* and the listeners for lib/rustorb/dds, which does the rest
|
|
6
|
+
* (docs/ruby.md).
|
|
7
|
+
*
|
|
8
|
+
* Threads, as in rustorb's gem. Ruby code runs only on Ruby threads holding
|
|
9
|
+
* the GVL. Calls that can wait (writes, waits, deleting entities, setting
|
|
10
|
+
* listeners) release the GVL. Listeners are called on rustorb-dds's
|
|
11
|
+
* threads, which cannot take the GVL: they hand the call to a pool of Ruby
|
|
12
|
+
* dispatcher threads (DDS::Native.dispatcher_loop) and wait for it; a
|
|
13
|
+
* listener called inside a call of a Ruby thread (a write to a reader of
|
|
14
|
+
* the same participant) runs on that thread. The pool grows by one
|
|
15
|
+
* whenever a dispatcher takes the last idle slot.
|
|
16
|
+
*
|
|
17
|
+
* Handles the garbage collector frees are released on a thread of this
|
|
18
|
+
* extension, without the GVL, since deleting an entity can wait for a
|
|
19
|
+
* listener that waits for the GVL.
|
|
20
|
+
*
|
|
21
|
+
* Licensed under MIT OR Apache-2.0, like the rest of rustorb-dds.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#include <ruby.h>
|
|
25
|
+
#include <ruby/encoding.h>
|
|
26
|
+
#include <ruby/thread.h>
|
|
27
|
+
#include <ruby/vm.h>
|
|
28
|
+
|
|
29
|
+
#include <pthread.h>
|
|
30
|
+
#include <stdlib.h>
|
|
31
|
+
#include <string.h>
|
|
32
|
+
|
|
33
|
+
#include <rustorb/dds.h>
|
|
34
|
+
|
|
35
|
+
static VALUE mDDS, mNative, cHandle, cOut, cIn;
|
|
36
|
+
static VALUE errors; /* the exception classes, by return code */
|
|
37
|
+
static ID id_dispatch, id_spawn_dispatcher, id_negative_p;
|
|
38
|
+
|
|
39
|
+
/* --- errors ----------------------------------------------------------------- */
|
|
40
|
+
|
|
41
|
+
static VALUE error_class(rdds_status st) {
|
|
42
|
+
VALUE e = Qnil;
|
|
43
|
+
if (errors != Qnil && st >= 0 && st < RARRAY_LEN(errors)) e = rb_ary_entry(errors, st);
|
|
44
|
+
return NIL_P(e) ? rb_eRuntimeError : e;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static void raise_status(rdds_status st) {
|
|
48
|
+
const char* msg = rdds_last_error_message();
|
|
49
|
+
rb_raise(error_class(st), "%s", msg && *msg ? msg : "rustorb-dds call failed");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#define CHECK(call) \
|
|
53
|
+
do { \
|
|
54
|
+
rdds_status st_ = (call); \
|
|
55
|
+
if (st_ != RDDS_RETCODE_OK) raise_status(st_); \
|
|
56
|
+
} while (0)
|
|
57
|
+
|
|
58
|
+
static void invalid(const char* fmt, VALUE v) {
|
|
59
|
+
rb_raise(error_class(RDDS_RETCODE_BAD_PARAMETER), fmt, rb_obj_classname(v));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* --- the GVL and the dispatchers --------------------------------------------- */
|
|
63
|
+
|
|
64
|
+
/* Whether this thread is a Ruby thread that released the GVL with
|
|
65
|
+
without_gvl below (then listeners use rb_thread_call_with_gvl). */
|
|
66
|
+
static __thread int tls_released;
|
|
67
|
+
|
|
68
|
+
typedef void* (*gvl_fn)(void*);
|
|
69
|
+
|
|
70
|
+
struct nogvl_call {
|
|
71
|
+
gvl_fn fn;
|
|
72
|
+
void* arg;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
static void* nogvl_trampoline(void* p) {
|
|
76
|
+
struct nogvl_call* c = p;
|
|
77
|
+
void* r;
|
|
78
|
+
tls_released = 1;
|
|
79
|
+
r = c->fn(c->arg);
|
|
80
|
+
tls_released = 0;
|
|
81
|
+
return r;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static void* without_gvl(gvl_fn fn, void* arg) {
|
|
85
|
+
struct nogvl_call c;
|
|
86
|
+
c.fn = fn;
|
|
87
|
+
c.arg = arg;
|
|
88
|
+
return rb_thread_call_without_gvl(nogvl_trampoline, &c, NULL, NULL);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
typedef struct job {
|
|
92
|
+
gvl_fn fn;
|
|
93
|
+
void* arg;
|
|
94
|
+
void* result;
|
|
95
|
+
int done;
|
|
96
|
+
pthread_cond_t cond;
|
|
97
|
+
struct job* next;
|
|
98
|
+
} job;
|
|
99
|
+
|
|
100
|
+
static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
101
|
+
static pthread_cond_t queue_cond = PTHREAD_COND_INITIALIZER;
|
|
102
|
+
static job *queue_head, *queue_tail;
|
|
103
|
+
static int idle_dispatchers, dispatchers, shutting_down;
|
|
104
|
+
|
|
105
|
+
static void* with_gvl_trampoline(void* p) {
|
|
106
|
+
struct nogvl_call* c = p;
|
|
107
|
+
void* r;
|
|
108
|
+
tls_released = 0;
|
|
109
|
+
r = c->fn(c->arg);
|
|
110
|
+
tls_released = 1;
|
|
111
|
+
return r;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Runs fn(arg) with the GVL, from any thread: on a Ruby thread that released
|
|
115
|
+
it, by taking it back; on another thread, on a dispatcher thread. Returns
|
|
116
|
+
NULL without running fn when that cannot be done (shutting down, or no
|
|
117
|
+
dispatcher). */
|
|
118
|
+
static void* with_gvl(gvl_fn fn, void* arg) {
|
|
119
|
+
job j;
|
|
120
|
+
if (tls_released) {
|
|
121
|
+
struct nogvl_call c;
|
|
122
|
+
c.fn = fn;
|
|
123
|
+
c.arg = arg;
|
|
124
|
+
return rb_thread_call_with_gvl(with_gvl_trampoline, &c);
|
|
125
|
+
}
|
|
126
|
+
if (ruby_native_thread_p()) return fn(arg); /* holds the GVL */
|
|
127
|
+
memset(&j, 0, sizeof j);
|
|
128
|
+
j.fn = fn;
|
|
129
|
+
j.arg = arg;
|
|
130
|
+
pthread_cond_init(&j.cond, NULL);
|
|
131
|
+
pthread_mutex_lock(&queue_lock);
|
|
132
|
+
if (shutting_down || dispatchers == 0) {
|
|
133
|
+
pthread_mutex_unlock(&queue_lock);
|
|
134
|
+
pthread_cond_destroy(&j.cond);
|
|
135
|
+
return NULL;
|
|
136
|
+
}
|
|
137
|
+
if (queue_tail)
|
|
138
|
+
queue_tail->next = &j;
|
|
139
|
+
else
|
|
140
|
+
queue_head = &j;
|
|
141
|
+
queue_tail = &j;
|
|
142
|
+
pthread_cond_signal(&queue_cond);
|
|
143
|
+
while (!j.done) pthread_cond_wait(&j.cond, &queue_lock);
|
|
144
|
+
pthread_mutex_unlock(&queue_lock);
|
|
145
|
+
pthread_cond_destroy(&j.cond);
|
|
146
|
+
return j.result;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* Waits for a job, or until the dispatcher's own interrupt flag (one per
|
|
150
|
+
dispatcher: a shared one could be taken by another dispatcher, and the
|
|
151
|
+
thread Ruby wants to kill at exit would never wake). */
|
|
152
|
+
static void* wait_job(void* p) {
|
|
153
|
+
int* interrupted = p;
|
|
154
|
+
job* j = NULL;
|
|
155
|
+
pthread_mutex_lock(&queue_lock);
|
|
156
|
+
++idle_dispatchers;
|
|
157
|
+
while (!queue_head && !*interrupted && !shutting_down)
|
|
158
|
+
pthread_cond_wait(&queue_cond, &queue_lock);
|
|
159
|
+
if (queue_head) {
|
|
160
|
+
j = queue_head;
|
|
161
|
+
queue_head = j->next;
|
|
162
|
+
if (!queue_head) queue_tail = NULL;
|
|
163
|
+
}
|
|
164
|
+
*interrupted = 0;
|
|
165
|
+
--idle_dispatchers;
|
|
166
|
+
pthread_mutex_unlock(&queue_lock);
|
|
167
|
+
return j;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static void wake_dispatcher(void* p) {
|
|
171
|
+
pthread_mutex_lock(&queue_lock);
|
|
172
|
+
*(int*)p = 1;
|
|
173
|
+
pthread_cond_broadcast(&queue_cond);
|
|
174
|
+
pthread_mutex_unlock(&queue_lock);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* Fails the queued jobs (they return NULL). Called with queue_lock held. */
|
|
178
|
+
static void fail_queued_jobs(void) {
|
|
179
|
+
job* j;
|
|
180
|
+
for (j = queue_head; j; j = j->next) {
|
|
181
|
+
j->result = NULL;
|
|
182
|
+
j->done = 1;
|
|
183
|
+
pthread_cond_signal(&j->cond);
|
|
184
|
+
}
|
|
185
|
+
queue_head = queue_tail = NULL;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* The job a dispatcher runs, so that its end (when Ruby kills the thread at
|
|
189
|
+
exit, which an end proc cannot be ordered against) still answers it. */
|
|
190
|
+
typedef struct {
|
|
191
|
+
job* current;
|
|
192
|
+
int interrupted;
|
|
193
|
+
} dispatcher_state;
|
|
194
|
+
|
|
195
|
+
static VALUE dispatcher_run(VALUE p) {
|
|
196
|
+
dispatcher_state* st = (dispatcher_state*)p;
|
|
197
|
+
for (;;) {
|
|
198
|
+
job* j = rb_thread_call_without_gvl(wait_job, &st->interrupted, wake_dispatcher, &st->interrupted);
|
|
199
|
+
int spawn;
|
|
200
|
+
if (!j) {
|
|
201
|
+
rb_thread_check_ints();
|
|
202
|
+
pthread_mutex_lock(&queue_lock);
|
|
203
|
+
if (shutting_down) {
|
|
204
|
+
pthread_mutex_unlock(&queue_lock);
|
|
205
|
+
return Qnil;
|
|
206
|
+
}
|
|
207
|
+
pthread_mutex_unlock(&queue_lock);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
st->current = j;
|
|
211
|
+
pthread_mutex_lock(&queue_lock);
|
|
212
|
+
spawn = idle_dispatchers == 0;
|
|
213
|
+
pthread_mutex_unlock(&queue_lock);
|
|
214
|
+
if (spawn) rb_funcall(mNative, id_spawn_dispatcher, 0);
|
|
215
|
+
j->result = j->fn(j->arg);
|
|
216
|
+
pthread_mutex_lock(&queue_lock);
|
|
217
|
+
j->done = 1;
|
|
218
|
+
st->current = NULL;
|
|
219
|
+
pthread_cond_signal(&j->cond);
|
|
220
|
+
pthread_mutex_unlock(&queue_lock);
|
|
221
|
+
}
|
|
222
|
+
return Qnil;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* However the dispatcher ends: it is no longer counted, its job is
|
|
226
|
+
answered, and when it was the last one, the queued jobs fail rather than
|
|
227
|
+
wait for a dispatcher that will not come. */
|
|
228
|
+
static VALUE dispatcher_end(VALUE p) {
|
|
229
|
+
dispatcher_state* st = (dispatcher_state*)p;
|
|
230
|
+
pthread_mutex_lock(&queue_lock);
|
|
231
|
+
--dispatchers;
|
|
232
|
+
if (st->current && !st->current->done) {
|
|
233
|
+
st->current->result = NULL;
|
|
234
|
+
st->current->done = 1;
|
|
235
|
+
pthread_cond_signal(&st->current->cond);
|
|
236
|
+
}
|
|
237
|
+
st->current = NULL;
|
|
238
|
+
if (dispatchers == 0) fail_queued_jobs();
|
|
239
|
+
pthread_mutex_unlock(&queue_lock);
|
|
240
|
+
return Qnil;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* DDS::Native.dispatcher_loop: runs listener calls until the process ends. */
|
|
244
|
+
static VALUE native_dispatcher_loop(VALUE self) {
|
|
245
|
+
dispatcher_state st;
|
|
246
|
+
(void)self;
|
|
247
|
+
st.current = NULL;
|
|
248
|
+
st.interrupted = 0;
|
|
249
|
+
pthread_mutex_lock(&queue_lock);
|
|
250
|
+
++dispatchers;
|
|
251
|
+
pthread_mutex_unlock(&queue_lock);
|
|
252
|
+
return rb_ensure(dispatcher_run, (VALUE)&st, dispatcher_end, (VALUE)&st);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
static VALUE native_dispatchers(VALUE self) {
|
|
256
|
+
int n;
|
|
257
|
+
(void)self;
|
|
258
|
+
pthread_mutex_lock(&queue_lock);
|
|
259
|
+
n = dispatchers;
|
|
260
|
+
pthread_mutex_unlock(&queue_lock);
|
|
261
|
+
return INT2NUM(n);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* When the VM is gone (after its threads), no listener call can run any
|
|
265
|
+
more. Not an end proc: those run before or after minitest's autorun
|
|
266
|
+
(which runs the tests in an end proc) depending on the Ruby version. */
|
|
267
|
+
static void at_exit_dispatchers(ruby_vm_t* vm) {
|
|
268
|
+
(void)vm;
|
|
269
|
+
pthread_mutex_lock(&queue_lock);
|
|
270
|
+
shutting_down = 1;
|
|
271
|
+
fail_queued_jobs();
|
|
272
|
+
pthread_cond_broadcast(&queue_cond);
|
|
273
|
+
pthread_mutex_unlock(&queue_lock);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/* --- calls without the GVL ---------------------------------------------------- */
|
|
277
|
+
|
|
278
|
+
typedef struct call {
|
|
279
|
+
rdds_status (*f)(struct call*);
|
|
280
|
+
const void *a, *b, *c, *d, *e;
|
|
281
|
+
void* out;
|
|
282
|
+
uint32_t u;
|
|
283
|
+
int32_t i;
|
|
284
|
+
size_t n, cap;
|
|
285
|
+
size_t* len;
|
|
286
|
+
rdds_duration dur;
|
|
287
|
+
rdds_status r;
|
|
288
|
+
} call;
|
|
289
|
+
|
|
290
|
+
static void* run_call(void* p) {
|
|
291
|
+
call* c = p;
|
|
292
|
+
c->r = c->f(c);
|
|
293
|
+
return NULL;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* Runs c->f without the GVL and raises its failure. */
|
|
297
|
+
static void nogvl(call* c) {
|
|
298
|
+
without_gvl(run_call, c);
|
|
299
|
+
if (c->r != RDDS_RETCODE_OK) raise_status(c->r);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/* --- releasing handles ---------------------------------------------------------- */
|
|
303
|
+
|
|
304
|
+
enum kind {
|
|
305
|
+
K_TYPE,
|
|
306
|
+
K_PARTICIPANT,
|
|
307
|
+
K_TOPIC,
|
|
308
|
+
K_CFTOPIC,
|
|
309
|
+
K_PUBLISHER,
|
|
310
|
+
K_SUBSCRIBER,
|
|
311
|
+
K_WRITER,
|
|
312
|
+
K_READER,
|
|
313
|
+
K_CONDITION,
|
|
314
|
+
K_WAITSET,
|
|
315
|
+
K_COUNT
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
static const char* const kind_names[K_COUNT] = {"type", "participant", "topic", "content filtered topic",
|
|
319
|
+
"publisher", "subscriber", "writer", "reader",
|
|
320
|
+
"condition", "waitset"};
|
|
321
|
+
|
|
322
|
+
static void rel_type(void* p) { rdds_type_release(p); }
|
|
323
|
+
static void rel_participant(void* p) { rdds_participant_release(p); }
|
|
324
|
+
static void rel_topic(void* p) { rdds_topic_release(p); }
|
|
325
|
+
static void rel_cftopic(void* p) { rdds_cftopic_release(p); }
|
|
326
|
+
static void rel_publisher(void* p) { rdds_publisher_release(p); }
|
|
327
|
+
static void rel_subscriber(void* p) { rdds_subscriber_release(p); }
|
|
328
|
+
static void rel_writer(void* p) { rdds_writer_release(p); }
|
|
329
|
+
static void rel_reader(void* p) { rdds_reader_release(p); }
|
|
330
|
+
static void rel_condition(void* p) { rdds_condition_release(p); }
|
|
331
|
+
static void rel_waitset(void* p) { rdds_waitset_release(p); }
|
|
332
|
+
|
|
333
|
+
static void (*const releases[K_COUNT])(void*) = {rel_type, rel_participant, rel_topic, rel_cftopic,
|
|
334
|
+
rel_publisher, rel_subscriber, rel_writer, rel_reader,
|
|
335
|
+
rel_condition, rel_waitset};
|
|
336
|
+
|
|
337
|
+
/* The reaper: a thread that releases what the garbage collector freed. */
|
|
338
|
+
typedef struct reap {
|
|
339
|
+
void (*release)(void*);
|
|
340
|
+
void* p;
|
|
341
|
+
struct reap* next;
|
|
342
|
+
} reap;
|
|
343
|
+
|
|
344
|
+
static pthread_mutex_t reap_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
345
|
+
static pthread_cond_t reap_cond = PTHREAD_COND_INITIALIZER;
|
|
346
|
+
static reap* reap_head;
|
|
347
|
+
static int reaper_started;
|
|
348
|
+
|
|
349
|
+
static void* reaper(void* unused) {
|
|
350
|
+
(void)unused;
|
|
351
|
+
for (;;) {
|
|
352
|
+
reap* r;
|
|
353
|
+
pthread_mutex_lock(&reap_lock);
|
|
354
|
+
while (!reap_head) pthread_cond_wait(&reap_cond, &reap_lock);
|
|
355
|
+
r = reap_head;
|
|
356
|
+
reap_head = r->next;
|
|
357
|
+
pthread_mutex_unlock(&reap_lock);
|
|
358
|
+
r->release(r->p);
|
|
359
|
+
free(r);
|
|
360
|
+
}
|
|
361
|
+
return NULL;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
static void reap_later(void (*release)(void*), void* p) {
|
|
365
|
+
reap* r = malloc(sizeof *r);
|
|
366
|
+
if (!r) return; /* leaks the handle */
|
|
367
|
+
r->release = release;
|
|
368
|
+
r->p = p;
|
|
369
|
+
pthread_mutex_lock(&reap_lock);
|
|
370
|
+
if (!reaper_started) {
|
|
371
|
+
pthread_t t;
|
|
372
|
+
pthread_attr_t attr;
|
|
373
|
+
pthread_attr_init(&attr);
|
|
374
|
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
375
|
+
if (pthread_create(&t, &attr, reaper, NULL) == 0) reaper_started = 1;
|
|
376
|
+
pthread_attr_destroy(&attr);
|
|
377
|
+
if (!reaper_started) {
|
|
378
|
+
pthread_mutex_unlock(&reap_lock);
|
|
379
|
+
free(r);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
r->next = reap_head;
|
|
384
|
+
reap_head = r;
|
|
385
|
+
pthread_cond_signal(&reap_cond);
|
|
386
|
+
pthread_mutex_unlock(&reap_lock);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/* --- handles ---------------------------------------------------------------- */
|
|
390
|
+
|
|
391
|
+
typedef struct handle {
|
|
392
|
+
void* p;
|
|
393
|
+
int kind;
|
|
394
|
+
} handle;
|
|
395
|
+
|
|
396
|
+
static void handle_free(void* ptr) {
|
|
397
|
+
handle* h = ptr;
|
|
398
|
+
if (h->p) {
|
|
399
|
+
if (h->kind == K_TYPE)
|
|
400
|
+
releases[h->kind](h->p);
|
|
401
|
+
else
|
|
402
|
+
reap_later(releases[h->kind], h->p);
|
|
403
|
+
}
|
|
404
|
+
xfree(h);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
static size_t handle_size(const void* ptr) {
|
|
408
|
+
(void)ptr;
|
|
409
|
+
return sizeof(handle);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
static const rb_data_type_t handle_type = {
|
|
413
|
+
"rustorb_dds_handle", {NULL, handle_free, handle_size, NULL, {0}}, NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY};
|
|
414
|
+
|
|
415
|
+
static VALUE wrap(int kind, void* p) {
|
|
416
|
+
handle* h;
|
|
417
|
+
VALUE v = TypedData_Make_Struct(cHandle, handle, &handle_type, h);
|
|
418
|
+
h->p = p;
|
|
419
|
+
h->kind = kind;
|
|
420
|
+
return v;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
static void* unwrap(VALUE v, int kind) {
|
|
424
|
+
handle* h = rb_check_typeddata(v, &handle_type);
|
|
425
|
+
if (h->kind != kind)
|
|
426
|
+
rb_raise(rb_eTypeError, "a %s expected, got a %s", kind_names[kind], kind_names[h->kind]);
|
|
427
|
+
if (!h->p) rb_raise(error_class(RDDS_RETCODE_ALREADY_DELETED), "the %s is closed", kind_names[kind]);
|
|
428
|
+
return h->p;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
static int handle_kind(VALUE v) {
|
|
432
|
+
handle* h = rb_check_typeddata(v, &handle_type);
|
|
433
|
+
return h->kind;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
static rdds_status op_release(call* c) {
|
|
437
|
+
releases[c->i]((void*)c->a);
|
|
438
|
+
return RDDS_RETCODE_OK;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/* DDS::Native.release(handle): releases it now (deletes the entity). */
|
|
442
|
+
static VALUE native_release(VALUE self, VALUE v) {
|
|
443
|
+
handle* h = rb_check_typeddata(v, &handle_type);
|
|
444
|
+
void* p = h->p;
|
|
445
|
+
call c;
|
|
446
|
+
(void)self;
|
|
447
|
+
if (!p) return Qnil;
|
|
448
|
+
h->p = NULL;
|
|
449
|
+
memset(&c, 0, sizeof c);
|
|
450
|
+
c.f = op_release;
|
|
451
|
+
c.a = p;
|
|
452
|
+
c.i = h->kind;
|
|
453
|
+
nogvl(&c);
|
|
454
|
+
return Qnil;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
static VALUE handle_closed_p(VALUE self) {
|
|
458
|
+
handle* h = rb_check_typeddata(self, &handle_type);
|
|
459
|
+
return h->p ? Qfalse : Qtrue;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/* --- values ------------------------------------------------------------------- */
|
|
463
|
+
|
|
464
|
+
static void out_of_range(VALUE v) {
|
|
465
|
+
rb_raise(error_class(RDDS_RETCODE_BAD_PARAMETER), "%" PRIsVALUE " is out of range", v);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
static long long int_in(VALUE v, long long lo, long long hi) {
|
|
469
|
+
long long x;
|
|
470
|
+
if (!RB_INTEGER_TYPE_P(v)) invalid("an Integer expected, got %s", v);
|
|
471
|
+
if (!FIXNUM_P(v) &&
|
|
472
|
+
(rb_big_cmp(v, LL2NUM(lo)) == INT2FIX(-1) || rb_big_cmp(v, LL2NUM(hi)) == INT2FIX(1)))
|
|
473
|
+
out_of_range(v);
|
|
474
|
+
x = NUM2LL(v);
|
|
475
|
+
if (x < lo || x > hi) out_of_range(v);
|
|
476
|
+
return x;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
static uint64_t uint64_in(VALUE v) {
|
|
480
|
+
if (!RB_INTEGER_TYPE_P(v)) invalid("an Integer expected, got %s", v);
|
|
481
|
+
if (RTEST(rb_funcall(v, id_negative_p, 0))) out_of_range(v);
|
|
482
|
+
if (!FIXNUM_P(v) && rb_big_cmp(v, rb_ull2inum(UINT64_MAX)) == INT2FIX(1)) out_of_range(v);
|
|
483
|
+
return NUM2ULL(v);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
static double float_in(VALUE v) {
|
|
487
|
+
if (!RB_FLOAT_TYPE_P(v) && !RB_INTEGER_TYPE_P(v) && !rb_obj_is_kind_of(v, rb_cNumeric))
|
|
488
|
+
invalid("a Numeric expected, got %s", v);
|
|
489
|
+
return NUM2DBL(v);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
static bool bool_in(VALUE v) {
|
|
493
|
+
if (v == Qtrue) return true;
|
|
494
|
+
if (v == Qfalse) return false;
|
|
495
|
+
invalid("true or false expected, got %s", v);
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/* A character: an Integer, or a String of one character, up to max. */
|
|
500
|
+
static uint32_t char_in(VALUE v, uint32_t max) {
|
|
501
|
+
long long code;
|
|
502
|
+
if (RB_TYPE_P(v, T_STRING)) {
|
|
503
|
+
if (rb_str_strlen(v) != 1) rb_raise(error_class(RDDS_RETCODE_BAD_PARAMETER), "one character expected");
|
|
504
|
+
code = NUM2LL(rb_funcall(v, rb_intern("ord"), 0));
|
|
505
|
+
} else {
|
|
506
|
+
code = int_in(v, 0, max);
|
|
507
|
+
}
|
|
508
|
+
if (code < 0 || code > (long long)max)
|
|
509
|
+
rb_raise(error_class(RDDS_RETCODE_BAD_PARAMETER), "the character %lld does not fit", code);
|
|
510
|
+
return (uint32_t)code;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
static const char* cstr(VALUE v) {
|
|
514
|
+
StringValue(v);
|
|
515
|
+
return StringValueCStr(v);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
static rdds_duration duration_in(VALUE v) {
|
|
519
|
+
rdds_duration d;
|
|
520
|
+
Check_Type(v, T_ARRAY);
|
|
521
|
+
if (RARRAY_LEN(v) != 2) rb_raise(rb_eArgError, "a duration is [sec, nanosec]");
|
|
522
|
+
d.sec = (int32_t)int_in(rb_ary_entry(v, 0), INT32_MIN, INT32_MAX);
|
|
523
|
+
d.nanosec = (uint32_t)int_in(rb_ary_entry(v, 1), 0, UINT32_MAX);
|
|
524
|
+
return d;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
static VALUE duration_out(rdds_duration d) { return rb_ary_new_from_args(2, INT2NUM(d.sec), UINT2NUM(d.nanosec)); }
|
|
528
|
+
|
|
529
|
+
static VALUE bytes16(const uint8_t* p) { return rb_str_new((const char*)p, 16); }
|
|
530
|
+
|
|
531
|
+
static void bytes16_in(VALUE v, uint8_t* out) {
|
|
532
|
+
StringValue(v);
|
|
533
|
+
if (RSTRING_LEN(v) != 16) rb_raise(rb_eArgError, "16 octets expected");
|
|
534
|
+
memcpy(out, RSTRING_PTR(v), 16);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/* --- types ------------------------------------------------------------------ */
|
|
538
|
+
|
|
539
|
+
static int ext_in(VALUE v) {
|
|
540
|
+
ID id = SYM2ID(v);
|
|
541
|
+
if (id == rb_intern("final")) return RDDS_FINAL;
|
|
542
|
+
if (id == rb_intern("appendable")) return RDDS_APPENDABLE;
|
|
543
|
+
if (id == rb_intern("mutable")) return RDDS_MUTABLE;
|
|
544
|
+
rb_raise(rb_eArgError, "unknown extensibility %" PRIsVALUE, v);
|
|
545
|
+
return 0;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
static VALUE native_type_primitive(VALUE self, VALUE kind) {
|
|
549
|
+
rdds_type* t;
|
|
550
|
+
(void)self;
|
|
551
|
+
CHECK(rdds_type_primitive((uint8_t)NUM2UINT(kind), &t));
|
|
552
|
+
return wrap(K_TYPE, t);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
static VALUE native_type_string(VALUE self, VALUE wide, VALUE bound) {
|
|
556
|
+
rdds_type* t;
|
|
557
|
+
(void)self;
|
|
558
|
+
CHECK(rdds_type_string(RTEST(wide), NUM2UINT(bound), &t));
|
|
559
|
+
return wrap(K_TYPE, t);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
static VALUE native_type_sequence(VALUE self, VALUE element, VALUE bound) {
|
|
563
|
+
rdds_type* t;
|
|
564
|
+
(void)self;
|
|
565
|
+
CHECK(rdds_type_sequence(unwrap(element, K_TYPE), NUM2UINT(bound), &t));
|
|
566
|
+
return wrap(K_TYPE, t);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
static VALUE native_type_array(VALUE self, VALUE element, VALUE dims) {
|
|
570
|
+
rdds_type* t;
|
|
571
|
+
uint32_t d[16];
|
|
572
|
+
long i, n;
|
|
573
|
+
(void)self;
|
|
574
|
+
Check_Type(dims, T_ARRAY);
|
|
575
|
+
n = RARRAY_LEN(dims);
|
|
576
|
+
if (n < 1 || n > 16) rb_raise(rb_eArgError, "1 to 16 dimensions");
|
|
577
|
+
for (i = 0; i < n; i++) d[i] = NUM2UINT(rb_ary_entry(dims, i));
|
|
578
|
+
CHECK(rdds_type_array(unwrap(element, K_TYPE), d, (size_t)n, &t));
|
|
579
|
+
return wrap(K_TYPE, t);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
static VALUE native_type_alias(VALUE self, VALUE name, VALUE related) {
|
|
583
|
+
rdds_type* t;
|
|
584
|
+
(void)self;
|
|
585
|
+
CHECK(rdds_type_alias(cstr(name), unwrap(related, K_TYPE), &t));
|
|
586
|
+
return wrap(K_TYPE, t);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/* literals: [[name, value, default?], ...] */
|
|
590
|
+
static VALUE native_type_enum(VALUE self, VALUE name, VALUE bits, VALUE ext, VALUE literals) {
|
|
591
|
+
rdds_enum_builder* b;
|
|
592
|
+
rdds_type* t;
|
|
593
|
+
rdds_status st = RDDS_RETCODE_OK;
|
|
594
|
+
long i;
|
|
595
|
+
(void)self;
|
|
596
|
+
Check_Type(literals, T_ARRAY);
|
|
597
|
+
for (i = 0; i < RARRAY_LEN(literals); i++) Check_Type(rb_ary_entry(rb_ary_entry(literals, i), 0), T_STRING);
|
|
598
|
+
CHECK(rdds_enum_builder_new(cstr(name), (uint16_t)NUM2UINT(bits), ext_in(ext), &b));
|
|
599
|
+
for (i = 0; st == RDDS_RETCODE_OK && i < RARRAY_LEN(literals); i++) {
|
|
600
|
+
VALUE l = rb_ary_entry(literals, i);
|
|
601
|
+
st = rdds_enum_builder_add_literal(b, RSTRING_PTR(rb_ary_entry(l, 0)), NUM2INT(rb_ary_entry(l, 1)),
|
|
602
|
+
RTEST(rb_ary_entry(l, 2)));
|
|
603
|
+
}
|
|
604
|
+
if (st == RDDS_RETCODE_OK) st = rdds_enum_builder_build(b, &t);
|
|
605
|
+
rdds_enum_builder_release(b);
|
|
606
|
+
if (st != RDDS_RETCODE_OK) raise_status(st);
|
|
607
|
+
return wrap(K_TYPE, t);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/* flags: [[name, position], ...] */
|
|
611
|
+
static VALUE native_type_bitmask(VALUE self, VALUE name, VALUE bits, VALUE ext, VALUE flags) {
|
|
612
|
+
rdds_bitmask_builder* b;
|
|
613
|
+
rdds_type* t;
|
|
614
|
+
rdds_status st = RDDS_RETCODE_OK;
|
|
615
|
+
long i;
|
|
616
|
+
(void)self;
|
|
617
|
+
Check_Type(flags, T_ARRAY);
|
|
618
|
+
for (i = 0; i < RARRAY_LEN(flags); i++) Check_Type(rb_ary_entry(rb_ary_entry(flags, i), 0), T_STRING);
|
|
619
|
+
CHECK(rdds_bitmask_builder_new(cstr(name), (uint16_t)NUM2UINT(bits), ext_in(ext), &b));
|
|
620
|
+
for (i = 0; st == RDDS_RETCODE_OK && i < RARRAY_LEN(flags); i++) {
|
|
621
|
+
VALUE f = rb_ary_entry(flags, i);
|
|
622
|
+
st = rdds_bitmask_builder_add_flag(b, RSTRING_PTR(rb_ary_entry(f, 0)), (uint16_t)NUM2UINT(rb_ary_entry(f, 1)));
|
|
623
|
+
}
|
|
624
|
+
if (st == RDDS_RETCODE_OK) st = rdds_bitmask_builder_build(b, &t);
|
|
625
|
+
rdds_bitmask_builder_release(b);
|
|
626
|
+
if (st != RDDS_RETCODE_OK) raise_status(st);
|
|
627
|
+
return wrap(K_TYPE, t);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
static const char* hash_id_in(VALUE v) { return NIL_P(v) ? NULL : RSTRING_PTR(v); }
|
|
631
|
+
|
|
632
|
+
/* members: [[name, id, type handle, flags, hash_id or nil], ...] */
|
|
633
|
+
static VALUE native_type_struct(VALUE self, VALUE name, VALUE ext, VALUE flags, VALUE members) {
|
|
634
|
+
rdds_struct_builder* b;
|
|
635
|
+
rdds_type* t;
|
|
636
|
+
rdds_status st = RDDS_RETCODE_OK;
|
|
637
|
+
long i;
|
|
638
|
+
(void)self;
|
|
639
|
+
Check_Type(members, T_ARRAY);
|
|
640
|
+
for (i = 0; i < RARRAY_LEN(members); i++) {
|
|
641
|
+
VALUE m = rb_ary_entry(members, i);
|
|
642
|
+
Check_Type(m, T_ARRAY);
|
|
643
|
+
Check_Type(rb_ary_entry(m, 0), T_STRING);
|
|
644
|
+
unwrap(rb_ary_entry(m, 2), K_TYPE);
|
|
645
|
+
if (!NIL_P(rb_ary_entry(m, 4))) Check_Type(rb_ary_entry(m, 4), T_STRING);
|
|
646
|
+
}
|
|
647
|
+
CHECK(rdds_struct_builder_new(cstr(name), ext_in(ext), NUM2UINT(flags), NULL, &b));
|
|
648
|
+
for (i = 0; st == RDDS_RETCODE_OK && i < RARRAY_LEN(members); i++) {
|
|
649
|
+
VALUE m = rb_ary_entry(members, i);
|
|
650
|
+
st = rdds_struct_builder_add_member(b, RSTRING_PTR(rb_ary_entry(m, 0)), NUM2UINT(rb_ary_entry(m, 1)),
|
|
651
|
+
unwrap(rb_ary_entry(m, 2), K_TYPE), NUM2UINT(rb_ary_entry(m, 3)),
|
|
652
|
+
hash_id_in(rb_ary_entry(m, 4)));
|
|
653
|
+
}
|
|
654
|
+
if (st == RDDS_RETCODE_OK) st = rdds_struct_builder_build(b, &t);
|
|
655
|
+
rdds_struct_builder_release(b);
|
|
656
|
+
if (st != RDDS_RETCODE_OK) raise_status(st);
|
|
657
|
+
return wrap(K_TYPE, t);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/* members: [[name, id, type handle, labels, flags, hash_id or nil], ...] */
|
|
661
|
+
static VALUE native_type_union(VALUE self, VALUE name, VALUE ext, VALUE flags, VALUE disc, VALUE members) {
|
|
662
|
+
rdds_union_builder* b;
|
|
663
|
+
rdds_type* t;
|
|
664
|
+
rdds_status st = RDDS_RETCODE_OK;
|
|
665
|
+
long i, j;
|
|
666
|
+
(void)self;
|
|
667
|
+
Check_Type(members, T_ARRAY);
|
|
668
|
+
for (i = 0; i < RARRAY_LEN(members); i++) {
|
|
669
|
+
VALUE m = rb_ary_entry(members, i);
|
|
670
|
+
Check_Type(m, T_ARRAY);
|
|
671
|
+
Check_Type(rb_ary_entry(m, 0), T_STRING);
|
|
672
|
+
unwrap(rb_ary_entry(m, 2), K_TYPE);
|
|
673
|
+
Check_Type(rb_ary_entry(m, 3), T_ARRAY);
|
|
674
|
+
for (j = 0; j < RARRAY_LEN(rb_ary_entry(m, 3)); j++) NUM2INT(rb_ary_entry(rb_ary_entry(m, 3), j));
|
|
675
|
+
if (!NIL_P(rb_ary_entry(m, 5))) Check_Type(rb_ary_entry(m, 5), T_STRING);
|
|
676
|
+
}
|
|
677
|
+
CHECK(rdds_union_builder_new(cstr(name), ext_in(ext), NUM2UINT(flags), unwrap(disc, K_TYPE), 0, &b));
|
|
678
|
+
for (i = 0; st == RDDS_RETCODE_OK && i < RARRAY_LEN(members); i++) {
|
|
679
|
+
VALUE m = rb_ary_entry(members, i);
|
|
680
|
+
VALUE ls = rb_ary_entry(m, 3);
|
|
681
|
+
long n = RARRAY_LEN(ls);
|
|
682
|
+
int32_t* labels = ALLOC_N(int32_t, n > 0 ? n : 1);
|
|
683
|
+
for (j = 0; j < n; j++) labels[j] = NUM2INT(rb_ary_entry(ls, j));
|
|
684
|
+
st = rdds_union_builder_add_member(b, RSTRING_PTR(rb_ary_entry(m, 0)), NUM2UINT(rb_ary_entry(m, 1)),
|
|
685
|
+
unwrap(rb_ary_entry(m, 2), K_TYPE), labels, (size_t)n,
|
|
686
|
+
NUM2UINT(rb_ary_entry(m, 4)), hash_id_in(rb_ary_entry(m, 5)));
|
|
687
|
+
xfree(labels);
|
|
688
|
+
}
|
|
689
|
+
if (st == RDDS_RETCODE_OK) st = rdds_union_builder_build(b, &t);
|
|
690
|
+
rdds_union_builder_release(b);
|
|
691
|
+
if (st != RDDS_RETCODE_OK) raise_status(st);
|
|
692
|
+
return wrap(K_TYPE, t);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/* [minimal, complete]: the 14-octet hashes. */
|
|
696
|
+
static VALUE native_type_hashes(VALUE self, VALUE type) {
|
|
697
|
+
uint8_t m[14], c[14];
|
|
698
|
+
(void)self;
|
|
699
|
+
CHECK(rdds_type_hashes(unwrap(type, K_TYPE), m, c));
|
|
700
|
+
return rb_ary_new_from_args(2, rb_str_new((const char*)m, 14), rb_str_new((const char*)c, 14));
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/* --- sample streams ----------------------------------------------------------- */
|
|
704
|
+
|
|
705
|
+
static void out_free(void* p) {
|
|
706
|
+
if (p) rdds_out_release(p);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
static size_t ptr_size(const void* p) {
|
|
710
|
+
(void)p;
|
|
711
|
+
return sizeof(void*);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
static const rb_data_type_t out_type = {"rustorb_dds_out", {NULL, out_free, ptr_size, NULL, {0}}, NULL, NULL,
|
|
715
|
+
RUBY_TYPED_FREE_IMMEDIATELY};
|
|
716
|
+
|
|
717
|
+
static void in_free(void* p) {
|
|
718
|
+
if (p) rdds_in_release(p);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
static const rb_data_type_t in_type = {"rustorb_dds_in", {NULL, in_free, ptr_size, NULL, {0}}, NULL, NULL,
|
|
722
|
+
RUBY_TYPED_FREE_IMMEDIATELY};
|
|
723
|
+
|
|
724
|
+
static VALUE out_alloc(VALUE klass) { return TypedData_Wrap_Struct(klass, &out_type, NULL); }
|
|
725
|
+
|
|
726
|
+
static VALUE out_initialize(VALUE self) {
|
|
727
|
+
rdds_out* o;
|
|
728
|
+
CHECK(rdds_out_new(&o));
|
|
729
|
+
DATA_PTR(self) = o;
|
|
730
|
+
return self;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
static rdds_out* out_of(VALUE v) {
|
|
734
|
+
rdds_out* o = rb_check_typeddata(v, &out_type);
|
|
735
|
+
if (!o) rb_raise(rb_eRuntimeError, "uninitialized DDS::Native::Out");
|
|
736
|
+
return o;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
static VALUE wrap_in(rdds_in* in) { return TypedData_Wrap_Struct(cIn, &in_type, in); }
|
|
740
|
+
|
|
741
|
+
static rdds_in* in_of(VALUE v) {
|
|
742
|
+
rdds_in* i = rb_check_typeddata(v, &in_type);
|
|
743
|
+
if (!i) rb_raise(rb_eRuntimeError, "a released DDS::Native::In");
|
|
744
|
+
return i;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
static VALUE out_clear(VALUE self) {
|
|
748
|
+
rdds_out_clear(out_of(self));
|
|
749
|
+
return self;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
#define OUT_INT(name, ctype, lo, hi) \
|
|
753
|
+
static VALUE out_##name(VALUE self, VALUE v) { \
|
|
754
|
+
rdds_out_##name(out_of(self), (ctype)int_in(v, lo, hi)); \
|
|
755
|
+
return self; \
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
OUT_INT(octet, uint8_t, 0, UINT8_MAX)
|
|
759
|
+
OUT_INT(int8, int8_t, INT8_MIN, INT8_MAX)
|
|
760
|
+
OUT_INT(uint8, uint8_t, 0, UINT8_MAX)
|
|
761
|
+
OUT_INT(int16, int16_t, INT16_MIN, INT16_MAX)
|
|
762
|
+
OUT_INT(uint16, uint16_t, 0, UINT16_MAX)
|
|
763
|
+
OUT_INT(int32, int32_t, INT32_MIN, INT32_MAX)
|
|
764
|
+
OUT_INT(uint32, uint32_t, 0, UINT32_MAX)
|
|
765
|
+
OUT_INT(int64, int64_t, INT64_MIN, INT64_MAX)
|
|
766
|
+
OUT_INT(enum, int32_t, INT32_MIN, INT32_MAX)
|
|
767
|
+
OUT_INT(discriminator, int64_t, INT64_MIN, INT64_MAX)
|
|
768
|
+
|
|
769
|
+
static VALUE out_uint64(VALUE self, VALUE v) {
|
|
770
|
+
rdds_out_uint64(out_of(self), uint64_in(v));
|
|
771
|
+
return self;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
static VALUE out_bitmask(VALUE self, VALUE v) {
|
|
775
|
+
rdds_out_bitmask(out_of(self), uint64_in(v));
|
|
776
|
+
return self;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
static VALUE out_boolean(VALUE self, VALUE v) {
|
|
780
|
+
rdds_out_boolean(out_of(self), bool_in(v));
|
|
781
|
+
return self;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
static VALUE out_present(VALUE self, VALUE v) {
|
|
785
|
+
rdds_out_present(out_of(self), RTEST(v));
|
|
786
|
+
return self;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
static VALUE out_float32(VALUE self, VALUE v) {
|
|
790
|
+
rdds_out_float32(out_of(self), (float)float_in(v));
|
|
791
|
+
return self;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
static VALUE out_float64(VALUE self, VALUE v) {
|
|
795
|
+
rdds_out_float64(out_of(self), float_in(v));
|
|
796
|
+
return self;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
static VALUE out_float128(VALUE self, VALUE hi, VALUE lo) {
|
|
800
|
+
rdds_out_float128(out_of(self), uint64_in(hi), uint64_in(lo));
|
|
801
|
+
return self;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
static VALUE out_char8(VALUE self, VALUE v) {
|
|
805
|
+
rdds_out_char8(out_of(self), (char)(unsigned char)char_in(v, 0xFF));
|
|
806
|
+
return self;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
static VALUE out_char16(VALUE self, VALUE v) {
|
|
810
|
+
rdds_out_char16(out_of(self), (uint16_t)char_in(v, 0xFFFF));
|
|
811
|
+
return self;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
static VALUE out_string(VALUE self, VALUE v) {
|
|
815
|
+
if (!RB_TYPE_P(v, T_STRING)) invalid("a String expected, got %s", v);
|
|
816
|
+
if (ENCODING_GET(v) != rb_utf8_encindex() && ENCODING_GET(v) != rb_usascii_encindex() &&
|
|
817
|
+
ENCODING_GET(v) != rb_ascii8bit_encindex())
|
|
818
|
+
v = rb_str_export_to_enc(v, rb_utf8_encoding());
|
|
819
|
+
if (memchr(RSTRING_PTR(v), 0, (size_t)RSTRING_LEN(v)))
|
|
820
|
+
rb_raise(error_class(RDDS_RETCODE_BAD_PARAMETER), "a string with a NUL character");
|
|
821
|
+
rdds_out_string(out_of(self), RSTRING_PTR(v), (size_t)RSTRING_LEN(v));
|
|
822
|
+
RB_GC_GUARD(v);
|
|
823
|
+
return self;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/* A wide string: an Array of UTF-16 code units. */
|
|
827
|
+
static VALUE out_wstring(VALUE self, VALUE v) {
|
|
828
|
+
long i, n;
|
|
829
|
+
uint16_t* u;
|
|
830
|
+
if (!RB_TYPE_P(v, T_ARRAY)) invalid("an Array of UTF-16 code units expected, got %s", v);
|
|
831
|
+
n = RARRAY_LEN(v);
|
|
832
|
+
u = ALLOC_N(uint16_t, n > 0 ? n : 1);
|
|
833
|
+
for (i = 0; i < n; i++) {
|
|
834
|
+
VALUE e = rb_ary_entry(v, i);
|
|
835
|
+
if (!RB_INTEGER_TYPE_P(e) || NUM2LL(e) < 0 || NUM2LL(e) > 0xFFFF) {
|
|
836
|
+
xfree(u);
|
|
837
|
+
rb_raise(error_class(RDDS_RETCODE_BAD_PARAMETER), "a UTF-16 code unit expected");
|
|
838
|
+
}
|
|
839
|
+
u[i] = (uint16_t)NUM2UINT(e);
|
|
840
|
+
}
|
|
841
|
+
rdds_out_wstring(out_of(self), u, (size_t)n);
|
|
842
|
+
xfree(u);
|
|
843
|
+
return self;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
static VALUE out_length(VALUE self, VALUE v) {
|
|
847
|
+
rdds_out_length(out_of(self), (uint32_t)int_in(v, 0, UINT32_MAX));
|
|
848
|
+
return self;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/* Out#array(kind, values): the elements of a sequence or array of a
|
|
852
|
+
primitive type (RDDS_TK_* but float128), from an Array (or, for octets,
|
|
853
|
+
a String). */
|
|
854
|
+
static VALUE out_array(VALUE self, VALUE kind, VALUE v) {
|
|
855
|
+
rdds_out* o = out_of(self);
|
|
856
|
+
int k = NUM2INT(kind);
|
|
857
|
+
long i, n;
|
|
858
|
+
if (k == RDDS_TK_BYTE && RB_TYPE_P(v, T_STRING)) {
|
|
859
|
+
rdds_out_octet_array(o, (const uint8_t*)RSTRING_PTR(v), (size_t)RSTRING_LEN(v));
|
|
860
|
+
return self;
|
|
861
|
+
}
|
|
862
|
+
if (!RB_TYPE_P(v, T_ARRAY)) invalid("an Array expected, got %s", v);
|
|
863
|
+
n = RARRAY_LEN(v);
|
|
864
|
+
{
|
|
865
|
+
size_t size;
|
|
866
|
+
VALUE buf;
|
|
867
|
+
char* p;
|
|
868
|
+
switch (k) {
|
|
869
|
+
case RDDS_TK_BOOLEAN: size = sizeof(bool); break;
|
|
870
|
+
case RDDS_TK_BYTE: case RDDS_TK_INT8: case RDDS_TK_UINT8: case RDDS_TK_CHAR8: size = 1; break;
|
|
871
|
+
case RDDS_TK_INT16: case RDDS_TK_UINT16: case RDDS_TK_CHAR16: size = 2; break;
|
|
872
|
+
case RDDS_TK_INT32: case RDDS_TK_UINT32: case RDDS_TK_FLOAT32: size = 4; break;
|
|
873
|
+
case RDDS_TK_INT64: case RDDS_TK_UINT64: case RDDS_TK_FLOAT64: size = 8; break;
|
|
874
|
+
default: rb_raise(rb_eArgError, "no arrays of the kind %d", k);
|
|
875
|
+
}
|
|
876
|
+
buf = rb_str_buf_new((long)size * (n > 0 ? n : 1));
|
|
877
|
+
p = RSTRING_PTR(buf);
|
|
878
|
+
for (i = 0; i < n; i++) {
|
|
879
|
+
VALUE e = rb_ary_entry(v, i);
|
|
880
|
+
void* at = p + (size_t)i * size;
|
|
881
|
+
switch (k) {
|
|
882
|
+
case RDDS_TK_BOOLEAN: *(bool*)at = bool_in(e); break;
|
|
883
|
+
case RDDS_TK_BYTE: case RDDS_TK_UINT8: *(uint8_t*)at = (uint8_t)int_in(e, 0, UINT8_MAX); break;
|
|
884
|
+
case RDDS_TK_INT8: *(int8_t*)at = (int8_t)int_in(e, INT8_MIN, INT8_MAX); break;
|
|
885
|
+
case RDDS_TK_CHAR8: *(char*)at = (char)(unsigned char)char_in(e, 0xFF); break;
|
|
886
|
+
case RDDS_TK_INT16: *(int16_t*)at = (int16_t)int_in(e, INT16_MIN, INT16_MAX); break;
|
|
887
|
+
case RDDS_TK_UINT16: *(uint16_t*)at = (uint16_t)int_in(e, 0, UINT16_MAX); break;
|
|
888
|
+
case RDDS_TK_CHAR16: *(uint16_t*)at = (uint16_t)char_in(e, 0xFFFF); break;
|
|
889
|
+
case RDDS_TK_INT32: *(int32_t*)at = (int32_t)int_in(e, INT32_MIN, INT32_MAX); break;
|
|
890
|
+
case RDDS_TK_UINT32: *(uint32_t*)at = (uint32_t)int_in(e, 0, UINT32_MAX); break;
|
|
891
|
+
case RDDS_TK_FLOAT32: *(float*)at = (float)float_in(e); break;
|
|
892
|
+
case RDDS_TK_INT64: *(int64_t*)at = (int64_t)int_in(e, INT64_MIN, INT64_MAX); break;
|
|
893
|
+
case RDDS_TK_UINT64: *(uint64_t*)at = uint64_in(e); break;
|
|
894
|
+
case RDDS_TK_FLOAT64: *(double*)at = float_in(e); break;
|
|
895
|
+
}
|
|
896
|
+
p = RSTRING_PTR(buf); /* the conversions may call Ruby */
|
|
897
|
+
}
|
|
898
|
+
switch (k) {
|
|
899
|
+
case RDDS_TK_BOOLEAN: rdds_out_boolean_array(o, (const bool*)p, (size_t)n); break;
|
|
900
|
+
case RDDS_TK_BYTE: rdds_out_octet_array(o, (const uint8_t*)p, (size_t)n); break;
|
|
901
|
+
case RDDS_TK_UINT8: rdds_out_uint8_array(o, (const uint8_t*)p, (size_t)n); break;
|
|
902
|
+
case RDDS_TK_INT8: rdds_out_int8_array(o, (const int8_t*)p, (size_t)n); break;
|
|
903
|
+
case RDDS_TK_CHAR8: rdds_out_char8_array(o, (const char*)p, (size_t)n); break;
|
|
904
|
+
case RDDS_TK_INT16: rdds_out_int16_array(o, (const int16_t*)p, (size_t)n); break;
|
|
905
|
+
case RDDS_TK_UINT16: rdds_out_uint16_array(o, (const uint16_t*)p, (size_t)n); break;
|
|
906
|
+
case RDDS_TK_CHAR16: rdds_out_char16_array(o, (const uint16_t*)p, (size_t)n); break;
|
|
907
|
+
case RDDS_TK_INT32: rdds_out_int32_array(o, (const int32_t*)p, (size_t)n); break;
|
|
908
|
+
case RDDS_TK_UINT32: rdds_out_uint32_array(o, (const uint32_t*)p, (size_t)n); break;
|
|
909
|
+
case RDDS_TK_FLOAT32: rdds_out_float32_array(o, (const float*)p, (size_t)n); break;
|
|
910
|
+
case RDDS_TK_INT64: rdds_out_int64_array(o, (const int64_t*)p, (size_t)n); break;
|
|
911
|
+
case RDDS_TK_UINT64: rdds_out_uint64_array(o, (const uint64_t*)p, (size_t)n); break;
|
|
912
|
+
case RDDS_TK_FLOAT64: rdds_out_float64_array(o, (const double*)p, (size_t)n); break;
|
|
913
|
+
}
|
|
914
|
+
RB_GC_GUARD(buf);
|
|
915
|
+
}
|
|
916
|
+
return self;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/* In: the readers raise nothing; In#check raises the stream's failure. */
|
|
920
|
+
static VALUE in_check(VALUE self) {
|
|
921
|
+
rdds_status st = rdds_in_status(in_of(self));
|
|
922
|
+
if (st != RDDS_RETCODE_OK) raise_status(st);
|
|
923
|
+
return self;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
static VALUE in_at_end_p(VALUE self) { return rdds_in_at_end(in_of(self)) ? Qtrue : Qfalse; }
|
|
927
|
+
|
|
928
|
+
static VALUE in_release(VALUE self) {
|
|
929
|
+
rdds_in* i = rb_check_typeddata(self, &in_type);
|
|
930
|
+
if (i) {
|
|
931
|
+
DATA_PTR(self) = NULL;
|
|
932
|
+
rdds_in_release(i);
|
|
933
|
+
}
|
|
934
|
+
return Qnil;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
static VALUE in_boolean(VALUE self) { return rdds_in_boolean(in_of(self)) ? Qtrue : Qfalse; }
|
|
938
|
+
static VALUE in_present(VALUE self) { return rdds_in_present(in_of(self)) ? Qtrue : Qfalse; }
|
|
939
|
+
static VALUE in_octet(VALUE self) { return UINT2NUM(rdds_in_octet(in_of(self))); }
|
|
940
|
+
static VALUE in_int8(VALUE self) { return INT2NUM(rdds_in_int8(in_of(self))); }
|
|
941
|
+
static VALUE in_uint8(VALUE self) { return UINT2NUM(rdds_in_uint8(in_of(self))); }
|
|
942
|
+
static VALUE in_int16(VALUE self) { return INT2NUM(rdds_in_int16(in_of(self))); }
|
|
943
|
+
static VALUE in_uint16(VALUE self) { return UINT2NUM(rdds_in_uint16(in_of(self))); }
|
|
944
|
+
static VALUE in_int32(VALUE self) { return INT2NUM(rdds_in_int32(in_of(self))); }
|
|
945
|
+
static VALUE in_uint32(VALUE self) { return UINT2NUM(rdds_in_uint32(in_of(self))); }
|
|
946
|
+
static VALUE in_int64(VALUE self) { return LL2NUM(rdds_in_int64(in_of(self))); }
|
|
947
|
+
static VALUE in_uint64(VALUE self) { return ULL2NUM(rdds_in_uint64(in_of(self))); }
|
|
948
|
+
static VALUE in_float32(VALUE self) { return DBL2NUM(rdds_in_float32(in_of(self))); }
|
|
949
|
+
static VALUE in_float64(VALUE self) { return DBL2NUM(rdds_in_float64(in_of(self))); }
|
|
950
|
+
static VALUE in_char8(VALUE self) { return UINT2NUM((unsigned char)rdds_in_char8(in_of(self))); }
|
|
951
|
+
static VALUE in_char16(VALUE self) { return UINT2NUM(rdds_in_char16(in_of(self))); }
|
|
952
|
+
static VALUE in_length(VALUE self) { return UINT2NUM(rdds_in_length(in_of(self))); }
|
|
953
|
+
static VALUE in_discriminator(VALUE self) { return LL2NUM(rdds_in_discriminator(in_of(self))); }
|
|
954
|
+
static VALUE in_enum(VALUE self) { return INT2NUM(rdds_in_enum(in_of(self))); }
|
|
955
|
+
static VALUE in_bitmask(VALUE self) { return ULL2NUM(rdds_in_bitmask(in_of(self))); }
|
|
956
|
+
|
|
957
|
+
static VALUE in_float128(VALUE self) {
|
|
958
|
+
uint64_t hi = 0, lo = 0;
|
|
959
|
+
rdds_in_float128(in_of(self), &hi, &lo);
|
|
960
|
+
return rb_ary_new_from_args(2, ULL2NUM(hi), ULL2NUM(lo));
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
static VALUE in_string(VALUE self) {
|
|
964
|
+
const char* p = NULL;
|
|
965
|
+
size_t n = 0;
|
|
966
|
+
rdds_in_string(in_of(self), &p, &n);
|
|
967
|
+
return rb_utf8_str_new(p ? p : "", (long)n);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
static VALUE in_wstring(VALUE self) {
|
|
971
|
+
const uint16_t* p = NULL;
|
|
972
|
+
size_t n = 0, i;
|
|
973
|
+
VALUE a;
|
|
974
|
+
rdds_in_wstring(in_of(self), &p, &n);
|
|
975
|
+
a = rb_ary_new_capa((long)n);
|
|
976
|
+
for (i = 0; i < n; i++) rb_ary_push(a, UINT2NUM(p[i]));
|
|
977
|
+
return a;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
/* In#array(kind, n): n elements of a primitive kind, as an Array. */
|
|
981
|
+
static VALUE in_array(VALUE self, VALUE kind, VALUE count) {
|
|
982
|
+
rdds_in* in = in_of(self);
|
|
983
|
+
int k = NUM2INT(kind);
|
|
984
|
+
long n = NUM2LONG(count), i;
|
|
985
|
+
VALUE a;
|
|
986
|
+
if (n < 0) rb_raise(rb_eArgError, "a negative count");
|
|
987
|
+
a = rb_ary_new_capa(n);
|
|
988
|
+
#define READ_ARR(ctype, fn, conv) \
|
|
989
|
+
do { \
|
|
990
|
+
VALUE buf = rb_str_buf_new((long)sizeof(ctype) * (n > 0 ? n : 1)); \
|
|
991
|
+
ctype* p = (ctype*)RSTRING_PTR(buf); \
|
|
992
|
+
fn(in, p, (size_t)n); \
|
|
993
|
+
for (i = 0; i < n; i++) rb_ary_push(a, conv(p[i])); \
|
|
994
|
+
RB_GC_GUARD(buf); \
|
|
995
|
+
} while (0)
|
|
996
|
+
#define BOOLV(x) ((x) ? Qtrue : Qfalse)
|
|
997
|
+
#define UCHARV(x) UINT2NUM((unsigned char)(x))
|
|
998
|
+
switch (k) {
|
|
999
|
+
case RDDS_TK_BOOLEAN: READ_ARR(bool, rdds_in_boolean_array, BOOLV); break;
|
|
1000
|
+
case RDDS_TK_BYTE: READ_ARR(uint8_t, rdds_in_octet_array, UINT2NUM); break;
|
|
1001
|
+
case RDDS_TK_UINT8: READ_ARR(uint8_t, rdds_in_uint8_array, UINT2NUM); break;
|
|
1002
|
+
case RDDS_TK_INT8: READ_ARR(int8_t, rdds_in_int8_array, INT2NUM); break;
|
|
1003
|
+
case RDDS_TK_CHAR8: READ_ARR(char, rdds_in_char8_array, UCHARV); break;
|
|
1004
|
+
case RDDS_TK_INT16: READ_ARR(int16_t, rdds_in_int16_array, INT2NUM); break;
|
|
1005
|
+
case RDDS_TK_UINT16: READ_ARR(uint16_t, rdds_in_uint16_array, UINT2NUM); break;
|
|
1006
|
+
case RDDS_TK_CHAR16: READ_ARR(uint16_t, rdds_in_char16_array, UINT2NUM); break;
|
|
1007
|
+
case RDDS_TK_INT32: READ_ARR(int32_t, rdds_in_int32_array, INT2NUM); break;
|
|
1008
|
+
case RDDS_TK_UINT32: READ_ARR(uint32_t, rdds_in_uint32_array, UINT2NUM); break;
|
|
1009
|
+
case RDDS_TK_FLOAT32: READ_ARR(float, rdds_in_float32_array, DBL2NUM); break;
|
|
1010
|
+
case RDDS_TK_INT64: READ_ARR(int64_t, rdds_in_int64_array, LL2NUM); break;
|
|
1011
|
+
case RDDS_TK_UINT64: READ_ARR(uint64_t, rdds_in_uint64_array, ULL2NUM); break;
|
|
1012
|
+
case RDDS_TK_FLOAT64: READ_ARR(double, rdds_in_float64_array, DBL2NUM); break;
|
|
1013
|
+
default: rb_raise(rb_eArgError, "no arrays of the kind %d", k);
|
|
1014
|
+
}
|
|
1015
|
+
#undef READ_ARR
|
|
1016
|
+
#undef BOOLV
|
|
1017
|
+
#undef UCHARV
|
|
1018
|
+
return a;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/* DDS::Native.serialize(type, out, xcdr2): the payload, with its
|
|
1022
|
+
encapsulation header. */
|
|
1023
|
+
static VALUE native_serialize(VALUE self, VALUE type, VALUE out, VALUE xcdr2) {
|
|
1024
|
+
uint8_t* data = NULL;
|
|
1025
|
+
size_t len = 0;
|
|
1026
|
+
VALUE s;
|
|
1027
|
+
(void)self;
|
|
1028
|
+
CHECK(rdds_type_serialize(unwrap(type, K_TYPE), out_of(out), RTEST(xcdr2), &data, &len));
|
|
1029
|
+
s = rb_str_new((const char*)data, (long)len);
|
|
1030
|
+
rdds_bytes_free(data, len);
|
|
1031
|
+
return s;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
static VALUE native_deserialize(VALUE self, VALUE type, VALUE data) {
|
|
1035
|
+
rdds_in* in;
|
|
1036
|
+
(void)self;
|
|
1037
|
+
StringValue(data);
|
|
1038
|
+
CHECK(rdds_type_deserialize(unwrap(type, K_TYPE), (const uint8_t*)RSTRING_PTR(data), (size_t)RSTRING_LEN(data),
|
|
1039
|
+
&in));
|
|
1040
|
+
return wrap_in(in);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
/* --- QoS ------------------------------------------------------------------------ */
|
|
1044
|
+
|
|
1045
|
+
static VALUE qget(VALUE h, const char* key) {
|
|
1046
|
+
VALUE v = rb_hash_lookup2(h, ID2SYM(rb_intern(key)), Qundef);
|
|
1047
|
+
if (v == Qundef) rb_raise(rb_eArgError, "the QoS has no %s", key);
|
|
1048
|
+
return v;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
#define QI(q, h, f) (q)->f = (int32_t)int_in(qget(h, #f), INT32_MIN, INT32_MAX)
|
|
1052
|
+
#define QD(q, h, f) (q)->f = duration_in(qget(h, #f))
|
|
1053
|
+
#define QB(q, h, f) (q)->f = RTEST(qget(h, #f))
|
|
1054
|
+
|
|
1055
|
+
/* The arrays of a QoS, kept alive while it is used. */
|
|
1056
|
+
typedef struct qos_arrays {
|
|
1057
|
+
VALUE user_data;
|
|
1058
|
+
VALUE repr;
|
|
1059
|
+
} qos_arrays;
|
|
1060
|
+
|
|
1061
|
+
static void common_qos_in(VALUE h, rdds_writer_qos* q, qos_arrays* keep) {
|
|
1062
|
+
VALUE ud, dr;
|
|
1063
|
+
long i, n;
|
|
1064
|
+
int16_t* reps;
|
|
1065
|
+
QI(q, h, reliability_kind);
|
|
1066
|
+
QD(q, h, max_blocking_time);
|
|
1067
|
+
QI(q, h, history_kind);
|
|
1068
|
+
QI(q, h, history_depth);
|
|
1069
|
+
QI(q, h, max_samples);
|
|
1070
|
+
QI(q, h, max_instances);
|
|
1071
|
+
QI(q, h, max_samples_per_instance);
|
|
1072
|
+
QI(q, h, durability_kind);
|
|
1073
|
+
QD(q, h, deadline_period);
|
|
1074
|
+
QI(q, h, liveliness_kind);
|
|
1075
|
+
QD(q, h, lease_duration);
|
|
1076
|
+
ud = qget(h, "user_data");
|
|
1077
|
+
StringValue(ud);
|
|
1078
|
+
keep->user_data = ud;
|
|
1079
|
+
q->user_data = (const uint8_t*)RSTRING_PTR(ud);
|
|
1080
|
+
q->user_data_len = (size_t)RSTRING_LEN(ud);
|
|
1081
|
+
dr = qget(h, "data_representation");
|
|
1082
|
+
Check_Type(dr, T_ARRAY);
|
|
1083
|
+
n = RARRAY_LEN(dr);
|
|
1084
|
+
keep->repr = rb_str_buf_new((long)sizeof(int16_t) * (n > 0 ? n : 1));
|
|
1085
|
+
reps = (int16_t*)RSTRING_PTR(keep->repr);
|
|
1086
|
+
for (i = 0; i < n; i++) reps[i] = (int16_t)int_in(rb_ary_entry(dr, i), INT16_MIN, INT16_MAX);
|
|
1087
|
+
reps = (int16_t*)RSTRING_PTR(keep->repr);
|
|
1088
|
+
q->data_representation = reps;
|
|
1089
|
+
q->data_representation_len = (size_t)n;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
static void writer_qos_in(VALUE h, rdds_writer_qos* q, qos_arrays* keep) {
|
|
1093
|
+
Check_Type(h, T_HASH);
|
|
1094
|
+
memset(q, 0, sizeof *q);
|
|
1095
|
+
common_qos_in(h, q, keep);
|
|
1096
|
+
QB(q, h, autodispose_unregistered_instances);
|
|
1097
|
+
QD(q, h, service_cleanup_delay);
|
|
1098
|
+
QI(q, h, service_history_kind);
|
|
1099
|
+
QI(q, h, service_history_depth);
|
|
1100
|
+
QI(q, h, service_max_samples);
|
|
1101
|
+
QI(q, h, service_max_instances);
|
|
1102
|
+
QI(q, h, service_max_samples_per_instance);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
static void reader_qos_in(VALUE h, rdds_reader_qos* q, qos_arrays* keep) {
|
|
1106
|
+
rdds_writer_qos w;
|
|
1107
|
+
Check_Type(h, T_HASH);
|
|
1108
|
+
memset(q, 0, sizeof *q);
|
|
1109
|
+
memset(&w, 0, sizeof w);
|
|
1110
|
+
common_qos_in(h, &w, keep);
|
|
1111
|
+
q->reliability_kind = w.reliability_kind;
|
|
1112
|
+
q->max_blocking_time = w.max_blocking_time;
|
|
1113
|
+
q->history_kind = w.history_kind;
|
|
1114
|
+
q->history_depth = w.history_depth;
|
|
1115
|
+
q->max_samples = w.max_samples;
|
|
1116
|
+
q->max_instances = w.max_instances;
|
|
1117
|
+
q->max_samples_per_instance = w.max_samples_per_instance;
|
|
1118
|
+
q->durability_kind = w.durability_kind;
|
|
1119
|
+
q->deadline_period = w.deadline_period;
|
|
1120
|
+
q->liveliness_kind = w.liveliness_kind;
|
|
1121
|
+
q->lease_duration = w.lease_duration;
|
|
1122
|
+
q->user_data = w.user_data;
|
|
1123
|
+
q->user_data_len = w.user_data_len;
|
|
1124
|
+
q->data_representation = w.data_representation;
|
|
1125
|
+
q->data_representation_len = w.data_representation_len;
|
|
1126
|
+
QI(q, h, type_consistency_kind);
|
|
1127
|
+
QB(q, h, ignore_sequence_bounds);
|
|
1128
|
+
QB(q, h, ignore_string_bounds);
|
|
1129
|
+
QB(q, h, ignore_member_names);
|
|
1130
|
+
QB(q, h, prevent_type_widening);
|
|
1131
|
+
QB(q, h, force_type_validation);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
#define HSET(h, f, v) rb_hash_aset(h, ID2SYM(rb_intern(f)), v)
|
|
1135
|
+
|
|
1136
|
+
static VALUE common_qos_out(int32_t reliability_kind, rdds_duration max_blocking_time, int32_t history_kind,
|
|
1137
|
+
int32_t history_depth, int32_t max_samples, int32_t max_instances,
|
|
1138
|
+
int32_t max_samples_per_instance, int32_t durability_kind, rdds_duration deadline,
|
|
1139
|
+
int32_t liveliness_kind, rdds_duration lease, const uint8_t* ud, size_t ud_len,
|
|
1140
|
+
const int16_t* dr, size_t dr_len) {
|
|
1141
|
+
VALUE h = rb_hash_new(), reps = rb_ary_new();
|
|
1142
|
+
size_t i;
|
|
1143
|
+
HSET(h, "reliability_kind", INT2NUM(reliability_kind));
|
|
1144
|
+
HSET(h, "max_blocking_time", duration_out(max_blocking_time));
|
|
1145
|
+
HSET(h, "history_kind", INT2NUM(history_kind));
|
|
1146
|
+
HSET(h, "history_depth", INT2NUM(history_depth));
|
|
1147
|
+
HSET(h, "max_samples", INT2NUM(max_samples));
|
|
1148
|
+
HSET(h, "max_instances", INT2NUM(max_instances));
|
|
1149
|
+
HSET(h, "max_samples_per_instance", INT2NUM(max_samples_per_instance));
|
|
1150
|
+
HSET(h, "durability_kind", INT2NUM(durability_kind));
|
|
1151
|
+
HSET(h, "deadline_period", duration_out(deadline));
|
|
1152
|
+
HSET(h, "liveliness_kind", INT2NUM(liveliness_kind));
|
|
1153
|
+
HSET(h, "lease_duration", duration_out(lease));
|
|
1154
|
+
HSET(h, "user_data", rb_str_new((const char*)ud, (long)ud_len));
|
|
1155
|
+
for (i = 0; i < dr_len; i++) rb_ary_push(reps, INT2NUM(dr[i]));
|
|
1156
|
+
HSET(h, "data_representation", reps);
|
|
1157
|
+
return h;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
static VALUE native_writer_qos_default(VALUE self) {
|
|
1161
|
+
rdds_writer_qos q;
|
|
1162
|
+
VALUE h;
|
|
1163
|
+
(void)self;
|
|
1164
|
+
CHECK(rdds_writer_qos_default(&q));
|
|
1165
|
+
h = common_qos_out(q.reliability_kind, q.max_blocking_time, q.history_kind, q.history_depth, q.max_samples,
|
|
1166
|
+
q.max_instances, q.max_samples_per_instance, q.durability_kind, q.deadline_period,
|
|
1167
|
+
q.liveliness_kind, q.lease_duration, q.user_data, q.user_data_len, q.data_representation,
|
|
1168
|
+
q.data_representation_len);
|
|
1169
|
+
HSET(h, "autodispose_unregistered_instances", q.autodispose_unregistered_instances ? Qtrue : Qfalse);
|
|
1170
|
+
HSET(h, "service_cleanup_delay", duration_out(q.service_cleanup_delay));
|
|
1171
|
+
HSET(h, "service_history_kind", INT2NUM(q.service_history_kind));
|
|
1172
|
+
HSET(h, "service_history_depth", INT2NUM(q.service_history_depth));
|
|
1173
|
+
HSET(h, "service_max_samples", INT2NUM(q.service_max_samples));
|
|
1174
|
+
HSET(h, "service_max_instances", INT2NUM(q.service_max_instances));
|
|
1175
|
+
HSET(h, "service_max_samples_per_instance", INT2NUM(q.service_max_samples_per_instance));
|
|
1176
|
+
return h;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
static VALUE native_reader_qos_default(VALUE self) {
|
|
1180
|
+
rdds_reader_qos q;
|
|
1181
|
+
VALUE h;
|
|
1182
|
+
(void)self;
|
|
1183
|
+
CHECK(rdds_reader_qos_default(&q));
|
|
1184
|
+
h = common_qos_out(q.reliability_kind, q.max_blocking_time, q.history_kind, q.history_depth, q.max_samples,
|
|
1185
|
+
q.max_instances, q.max_samples_per_instance, q.durability_kind, q.deadline_period,
|
|
1186
|
+
q.liveliness_kind, q.lease_duration, q.user_data, q.user_data_len, q.data_representation,
|
|
1187
|
+
q.data_representation_len);
|
|
1188
|
+
HSET(h, "type_consistency_kind", INT2NUM(q.type_consistency_kind));
|
|
1189
|
+
HSET(h, "ignore_sequence_bounds", q.ignore_sequence_bounds ? Qtrue : Qfalse);
|
|
1190
|
+
HSET(h, "ignore_string_bounds", q.ignore_string_bounds ? Qtrue : Qfalse);
|
|
1191
|
+
HSET(h, "ignore_member_names", q.ignore_member_names ? Qtrue : Qfalse);
|
|
1192
|
+
HSET(h, "prevent_type_widening", q.prevent_type_widening ? Qtrue : Qfalse);
|
|
1193
|
+
HSET(h, "force_type_validation", q.force_type_validation ? Qtrue : Qfalse);
|
|
1194
|
+
return h;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/* An Array of Strings as NUL-terminated pointers, in a Ruby String (kept
|
|
1198
|
+
alive with the Strings by the caller's keep Array). */
|
|
1199
|
+
static const char* const* strings_in(VALUE ary, VALUE keep, size_t* n) {
|
|
1200
|
+
long i, len;
|
|
1201
|
+
VALUE buf;
|
|
1202
|
+
const char** p;
|
|
1203
|
+
Check_Type(ary, T_ARRAY);
|
|
1204
|
+
len = RARRAY_LEN(ary);
|
|
1205
|
+
buf = rb_str_buf_new((long)sizeof(char*) * (len > 0 ? len : 1));
|
|
1206
|
+
rb_ary_push(keep, buf);
|
|
1207
|
+
for (i = 0; i < len; i++) {
|
|
1208
|
+
VALUE s = rb_str_new_frozen(rb_ary_entry(ary, i));
|
|
1209
|
+
StringValueCStr(s);
|
|
1210
|
+
rb_ary_push(keep, s);
|
|
1211
|
+
}
|
|
1212
|
+
p = (const char**)RSTRING_PTR(buf);
|
|
1213
|
+
for (i = 0; i < len; i++) p[i] = RSTRING_PTR(rb_ary_entry(keep, RARRAY_LEN(keep) - len + i));
|
|
1214
|
+
*n = (size_t)len;
|
|
1215
|
+
return p;
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
/* --- listeners -------------------------------------------------------------------- */
|
|
1219
|
+
|
|
1220
|
+
/* A listener's self is its id in DDS::Native's registry of listeners; an
|
|
1221
|
+
event is delivered with DDS::Native.dispatch(id, event, endpoint, arg). */
|
|
1222
|
+
|
|
1223
|
+
enum ev_kind {
|
|
1224
|
+
EV_DEADLINE,
|
|
1225
|
+
EV_INCOMPATIBLE,
|
|
1226
|
+
EV_COUNT,
|
|
1227
|
+
EV_MATCHED,
|
|
1228
|
+
EV_LIVELINESS_CHANGED,
|
|
1229
|
+
EV_REJECTED,
|
|
1230
|
+
EV_NONE,
|
|
1231
|
+
EV_DATA_ON_READERS,
|
|
1232
|
+
EV_RELEASE
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
typedef struct event {
|
|
1236
|
+
uintptr_t id;
|
|
1237
|
+
const char* name;
|
|
1238
|
+
int kind;
|
|
1239
|
+
const rdds_endpoint_info* endpoint;
|
|
1240
|
+
const char* topic_name;
|
|
1241
|
+
const void* status;
|
|
1242
|
+
} event;
|
|
1243
|
+
|
|
1244
|
+
static VALUE status_value(const event* e) {
|
|
1245
|
+
switch (e->kind) {
|
|
1246
|
+
case EV_DEADLINE: {
|
|
1247
|
+
const rdds_deadline_missed_status* s = e->status;
|
|
1248
|
+
return rb_ary_new_from_args(3, INT2NUM(s->total_count), INT2NUM(s->total_count_change),
|
|
1249
|
+
bytes16(s->last_instance_handle.value));
|
|
1250
|
+
}
|
|
1251
|
+
case EV_INCOMPATIBLE: {
|
|
1252
|
+
const rdds_incompatible_qos_status* s = e->status;
|
|
1253
|
+
VALUE ps = rb_ary_new();
|
|
1254
|
+
uint32_t i;
|
|
1255
|
+
for (i = 0; i < s->policies_len && i < RDDS_MAX_POLICIES; i++)
|
|
1256
|
+
rb_ary_push(ps, rb_ary_new_from_args(2, INT2NUM(s->policies[i].policy_id), INT2NUM(s->policies[i].count)));
|
|
1257
|
+
return rb_ary_new_from_args(4, INT2NUM(s->total_count), INT2NUM(s->total_count_change),
|
|
1258
|
+
INT2NUM(s->last_policy_id), ps);
|
|
1259
|
+
}
|
|
1260
|
+
case EV_COUNT: {
|
|
1261
|
+
const rdds_count_status* s = e->status;
|
|
1262
|
+
return rb_ary_new_from_args(2, INT2NUM(s->total_count), INT2NUM(s->total_count_change));
|
|
1263
|
+
}
|
|
1264
|
+
case EV_MATCHED: {
|
|
1265
|
+
const rdds_matched_status* s = e->status;
|
|
1266
|
+
return rb_ary_new_from_args(5, INT2NUM(s->total_count), INT2NUM(s->total_count_change),
|
|
1267
|
+
INT2NUM(s->current_count), INT2NUM(s->current_count_change),
|
|
1268
|
+
bytes16(s->last_handle.value));
|
|
1269
|
+
}
|
|
1270
|
+
case EV_LIVELINESS_CHANGED: {
|
|
1271
|
+
const rdds_liveliness_changed_status* s = e->status;
|
|
1272
|
+
return rb_ary_new_from_args(5, INT2NUM(s->alive_count), INT2NUM(s->not_alive_count),
|
|
1273
|
+
INT2NUM(s->alive_count_change), INT2NUM(s->not_alive_count_change),
|
|
1274
|
+
bytes16(s->last_publication_handle.value));
|
|
1275
|
+
}
|
|
1276
|
+
case EV_REJECTED: {
|
|
1277
|
+
const rdds_sample_rejected_status* s = e->status;
|
|
1278
|
+
return rb_ary_new_from_args(4, INT2NUM(s->total_count), INT2NUM(s->total_count_change),
|
|
1279
|
+
INT2NUM(s->last_reason), bytes16(s->last_instance_handle.value));
|
|
1280
|
+
}
|
|
1281
|
+
case EV_DATA_ON_READERS: {
|
|
1282
|
+
rdds_subscriber* c = NULL;
|
|
1283
|
+
if (rdds_subscriber_clone(e->status, &c) != RDDS_RETCODE_OK) return Qnil;
|
|
1284
|
+
return wrap(K_SUBSCRIBER, c);
|
|
1285
|
+
}
|
|
1286
|
+
default:
|
|
1287
|
+
return Qnil;
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
static VALUE deliver_body(VALUE p) {
|
|
1292
|
+
const event* e = (const event*)p;
|
|
1293
|
+
VALUE endpoint = Qnil;
|
|
1294
|
+
if (e->endpoint) endpoint = bytes16(e->endpoint->guid.value);
|
|
1295
|
+
if (e->topic_name) endpoint = rb_utf8_str_new_cstr(e->topic_name);
|
|
1296
|
+
return rb_funcall(mNative, id_dispatch, 4, ULONG2NUM((unsigned long)e->id), ID2SYM(rb_intern(e->name)), endpoint,
|
|
1297
|
+
status_value(e));
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
static void* deliver(void* p) {
|
|
1301
|
+
int state = 0;
|
|
1302
|
+
rb_protect(deliver_body, (VALUE)p, &state);
|
|
1303
|
+
if (state) rb_set_errinfo(Qnil); /* DDS::Native.dispatch reports what it can */
|
|
1304
|
+
return NULL;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
static void fire(void* self, const char* name, int kind, const rdds_endpoint_info* endpoint, const void* status) {
|
|
1308
|
+
event e;
|
|
1309
|
+
e.id = (uintptr_t)self;
|
|
1310
|
+
e.name = name;
|
|
1311
|
+
e.kind = kind;
|
|
1312
|
+
e.endpoint = endpoint;
|
|
1313
|
+
e.topic_name = NULL;
|
|
1314
|
+
e.status = status;
|
|
1315
|
+
with_gvl(deliver, &e);
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
#define L_STATUS(fn, ev, stype) \
|
|
1319
|
+
static void l_##fn(void* self, const rdds_endpoint_info* who, const stype* s) { \
|
|
1320
|
+
fire(self, #fn, ev, who, s); \
|
|
1321
|
+
} \
|
|
1322
|
+
static void w_##fn(void* self, const stype* s) { fire(self, #fn, ev, NULL, s); }
|
|
1323
|
+
|
|
1324
|
+
L_STATUS(on_offered_deadline_missed, EV_DEADLINE, rdds_deadline_missed_status)
|
|
1325
|
+
L_STATUS(on_offered_incompatible_qos, EV_INCOMPATIBLE, rdds_incompatible_qos_status)
|
|
1326
|
+
L_STATUS(on_liveliness_lost, EV_COUNT, rdds_count_status)
|
|
1327
|
+
L_STATUS(on_publication_matched, EV_MATCHED, rdds_matched_status)
|
|
1328
|
+
L_STATUS(on_requested_deadline_missed, EV_DEADLINE, rdds_deadline_missed_status)
|
|
1329
|
+
L_STATUS(on_requested_incompatible_qos, EV_INCOMPATIBLE, rdds_incompatible_qos_status)
|
|
1330
|
+
L_STATUS(on_sample_rejected, EV_REJECTED, rdds_sample_rejected_status)
|
|
1331
|
+
L_STATUS(on_liveliness_changed, EV_LIVELINESS_CHANGED, rdds_liveliness_changed_status)
|
|
1332
|
+
L_STATUS(on_subscription_matched, EV_MATCHED, rdds_matched_status)
|
|
1333
|
+
L_STATUS(on_sample_lost, EV_COUNT, rdds_count_status)
|
|
1334
|
+
|
|
1335
|
+
static void l_on_data_available(void* self, const rdds_endpoint_info* who) {
|
|
1336
|
+
fire(self, "on_data_available", EV_NONE, who, NULL);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
static void w_on_data_available(void* self) { fire(self, "on_data_available", EV_NONE, NULL, NULL); }
|
|
1340
|
+
|
|
1341
|
+
static void l_on_data_on_readers(void* self, const rdds_subscriber* s) {
|
|
1342
|
+
fire(self, "on_data_on_readers", EV_DATA_ON_READERS, NULL, s);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
static void l_on_inconsistent_topic(void* self, const char* topic, const rdds_count_status* s) {
|
|
1346
|
+
event e;
|
|
1347
|
+
e.id = (uintptr_t)self;
|
|
1348
|
+
e.name = "on_inconsistent_topic";
|
|
1349
|
+
e.kind = EV_COUNT;
|
|
1350
|
+
e.endpoint = NULL;
|
|
1351
|
+
e.topic_name = topic;
|
|
1352
|
+
e.status = s;
|
|
1353
|
+
with_gvl(deliver, &e);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
static void l_release(void* self) { fire(self, "release", EV_RELEASE, NULL, NULL); }
|
|
1357
|
+
|
|
1358
|
+
static void group_listener(rdds_listener* l, VALUE id) {
|
|
1359
|
+
memset(l, 0, sizeof *l);
|
|
1360
|
+
l->self = (void*)(uintptr_t)NUM2ULONG(id);
|
|
1361
|
+
l->on_offered_deadline_missed = l_on_offered_deadline_missed;
|
|
1362
|
+
l->on_offered_incompatible_qos = l_on_offered_incompatible_qos;
|
|
1363
|
+
l->on_liveliness_lost = l_on_liveliness_lost;
|
|
1364
|
+
l->on_publication_matched = l_on_publication_matched;
|
|
1365
|
+
l->on_data_on_readers = l_on_data_on_readers;
|
|
1366
|
+
l->on_requested_deadline_missed = l_on_requested_deadline_missed;
|
|
1367
|
+
l->on_requested_incompatible_qos = l_on_requested_incompatible_qos;
|
|
1368
|
+
l->on_sample_rejected = l_on_sample_rejected;
|
|
1369
|
+
l->on_liveliness_changed = l_on_liveliness_changed;
|
|
1370
|
+
l->on_data_available = l_on_data_available;
|
|
1371
|
+
l->on_subscription_matched = l_on_subscription_matched;
|
|
1372
|
+
l->on_sample_lost = l_on_sample_lost;
|
|
1373
|
+
l->on_inconsistent_topic = l_on_inconsistent_topic;
|
|
1374
|
+
l->release = l_release;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
static void writer_listener(rdds_writer_listener* l, VALUE id) {
|
|
1378
|
+
memset(l, 0, sizeof *l);
|
|
1379
|
+
l->self = (void*)(uintptr_t)NUM2ULONG(id);
|
|
1380
|
+
l->on_offered_deadline_missed = w_on_offered_deadline_missed;
|
|
1381
|
+
l->on_offered_incompatible_qos = w_on_offered_incompatible_qos;
|
|
1382
|
+
l->on_liveliness_lost = w_on_liveliness_lost;
|
|
1383
|
+
l->on_publication_matched = w_on_publication_matched;
|
|
1384
|
+
l->release = l_release;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
static void reader_listener(rdds_reader_listener* l, VALUE id) {
|
|
1388
|
+
memset(l, 0, sizeof *l);
|
|
1389
|
+
l->self = (void*)(uintptr_t)NUM2ULONG(id);
|
|
1390
|
+
l->on_requested_deadline_missed = w_on_requested_deadline_missed;
|
|
1391
|
+
l->on_requested_incompatible_qos = w_on_requested_incompatible_qos;
|
|
1392
|
+
l->on_sample_rejected = w_on_sample_rejected;
|
|
1393
|
+
l->on_liveliness_changed = w_on_liveliness_changed;
|
|
1394
|
+
l->on_data_available = w_on_data_available;
|
|
1395
|
+
l->on_subscription_matched = w_on_subscription_matched;
|
|
1396
|
+
l->on_sample_lost = w_on_sample_lost;
|
|
1397
|
+
l->release = l_release;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/* --- entities ------------------------------------------------------------------- */
|
|
1401
|
+
|
|
1402
|
+
static rdds_status op_participant_new(call* c) {
|
|
1403
|
+
return rdds_participant_new(c->u, c->a, (uint32_t)c->i, c->out);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
/* participant_new(domain, user_data, [[name, value], ...], flags) */
|
|
1407
|
+
static VALUE native_participant_new(VALUE self, VALUE domain, VALUE user_data, VALUE props, VALUE flags) {
|
|
1408
|
+
rdds_participant_qos q;
|
|
1409
|
+
rdds_participant* p = NULL;
|
|
1410
|
+
VALUE keep = rb_ary_new(), buf;
|
|
1411
|
+
rdds_property* ps;
|
|
1412
|
+
long i, n;
|
|
1413
|
+
call c;
|
|
1414
|
+
(void)self;
|
|
1415
|
+
StringValue(user_data);
|
|
1416
|
+
Check_Type(props, T_ARRAY);
|
|
1417
|
+
n = RARRAY_LEN(props);
|
|
1418
|
+
buf = rb_str_buf_new((long)sizeof(rdds_property) * (n > 0 ? n : 1));
|
|
1419
|
+
for (i = 0; i < n; i++) {
|
|
1420
|
+
VALUE kv = rb_ary_entry(props, i);
|
|
1421
|
+
VALUE k, v;
|
|
1422
|
+
Check_Type(kv, T_ARRAY);
|
|
1423
|
+
k = rb_str_new_frozen(rb_ary_entry(kv, 0));
|
|
1424
|
+
v = rb_str_new_frozen(rb_ary_entry(kv, 1));
|
|
1425
|
+
StringValueCStr(k);
|
|
1426
|
+
StringValueCStr(v);
|
|
1427
|
+
rb_ary_push(keep, k);
|
|
1428
|
+
rb_ary_push(keep, v);
|
|
1429
|
+
}
|
|
1430
|
+
ps = (rdds_property*)RSTRING_PTR(buf);
|
|
1431
|
+
for (i = 0; i < n; i++) {
|
|
1432
|
+
ps[i].name = RSTRING_PTR(rb_ary_entry(keep, 2 * i));
|
|
1433
|
+
ps[i].value = RSTRING_PTR(rb_ary_entry(keep, 2 * i + 1));
|
|
1434
|
+
}
|
|
1435
|
+
q.user_data = (const uint8_t*)RSTRING_PTR(user_data);
|
|
1436
|
+
q.user_data_len = (size_t)RSTRING_LEN(user_data);
|
|
1437
|
+
q.property = ps;
|
|
1438
|
+
q.property_len = (size_t)n;
|
|
1439
|
+
memset(&c, 0, sizeof c);
|
|
1440
|
+
c.f = op_participant_new;
|
|
1441
|
+
c.u = NUM2UINT(domain);
|
|
1442
|
+
c.a = &q;
|
|
1443
|
+
c.i = (int32_t)NUM2UINT(flags);
|
|
1444
|
+
c.out = &p;
|
|
1445
|
+
nogvl(&c);
|
|
1446
|
+
RB_GC_GUARD(keep);
|
|
1447
|
+
RB_GC_GUARD(buf);
|
|
1448
|
+
RB_GC_GUARD(user_data);
|
|
1449
|
+
return wrap(K_PARTICIPANT, p);
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
static VALUE native_participant_info(VALUE self, VALUE p) {
|
|
1453
|
+
rdds_participant* pp = unwrap(p, K_PARTICIPANT);
|
|
1454
|
+
rdds_guid g;
|
|
1455
|
+
(void)self;
|
|
1456
|
+
CHECK(rdds_participant_guid(pp, &g));
|
|
1457
|
+
return rb_ary_new_from_args(3, UINT2NUM(rdds_participant_domain_id(pp)), bytes16(g.value),
|
|
1458
|
+
SIZET2NUM(rdds_participant_discovered_participants(pp)));
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
static VALUE native_participant_assert_liveliness(VALUE self, VALUE p) {
|
|
1462
|
+
(void)self;
|
|
1463
|
+
CHECK(rdds_participant_assert_liveliness(unwrap(p, K_PARTICIPANT)));
|
|
1464
|
+
return Qnil;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
static rdds_status op_create_topic(call* c) { return rdds_participant_create_topic(c->a, c->b, c->c, c->out); }
|
|
1468
|
+
|
|
1469
|
+
static VALUE native_create_topic(VALUE self, VALUE p, VALUE name, VALUE type) {
|
|
1470
|
+
rdds_topic* t = NULL;
|
|
1471
|
+
call c;
|
|
1472
|
+
(void)self;
|
|
1473
|
+
memset(&c, 0, sizeof c);
|
|
1474
|
+
c.f = op_create_topic;
|
|
1475
|
+
c.a = unwrap(p, K_PARTICIPANT);
|
|
1476
|
+
c.b = cstr(name);
|
|
1477
|
+
c.c = unwrap(type, K_TYPE);
|
|
1478
|
+
c.out = &t;
|
|
1479
|
+
nogvl(&c);
|
|
1480
|
+
RB_GC_GUARD(name);
|
|
1481
|
+
return wrap(K_TOPIC, t);
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
static VALUE native_topic_inconsistent_status(VALUE self, VALUE t) {
|
|
1485
|
+
rdds_count_status s;
|
|
1486
|
+
(void)self;
|
|
1487
|
+
CHECK(rdds_topic_inconsistent_topic_status(unwrap(t, K_TOPIC), &s));
|
|
1488
|
+
return rb_ary_new_from_args(2, INT2NUM(s.total_count), INT2NUM(s.total_count_change));
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
static rdds_status op_create_cftopic(call* c) {
|
|
1492
|
+
return rdds_participant_create_contentfilteredtopic(c->a, c->b, c->c, c->d, c->e, c->n, c->out);
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
static VALUE native_create_cftopic(VALUE self, VALUE p, VALUE name, VALUE topic, VALUE expr, VALUE params) {
|
|
1496
|
+
rdds_cftopic* t = NULL;
|
|
1497
|
+
VALUE keep = rb_ary_new();
|
|
1498
|
+
call c;
|
|
1499
|
+
(void)self;
|
|
1500
|
+
memset(&c, 0, sizeof c);
|
|
1501
|
+
c.f = op_create_cftopic;
|
|
1502
|
+
c.a = unwrap(p, K_PARTICIPANT);
|
|
1503
|
+
c.b = cstr(name);
|
|
1504
|
+
c.c = unwrap(topic, K_TOPIC);
|
|
1505
|
+
c.d = cstr(expr);
|
|
1506
|
+
c.e = strings_in(params, keep, &c.n);
|
|
1507
|
+
c.out = &t;
|
|
1508
|
+
nogvl(&c);
|
|
1509
|
+
RB_GC_GUARD(keep);
|
|
1510
|
+
RB_GC_GUARD(name);
|
|
1511
|
+
RB_GC_GUARD(expr);
|
|
1512
|
+
return wrap(K_CFTOPIC, t);
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
static VALUE native_cftopic_set_parameters(VALUE self, VALUE t, VALUE params) {
|
|
1516
|
+
VALUE keep = rb_ary_new();
|
|
1517
|
+
size_t n;
|
|
1518
|
+
const char* const* p;
|
|
1519
|
+
(void)self;
|
|
1520
|
+
p = strings_in(params, keep, &n);
|
|
1521
|
+
CHECK(rdds_cftopic_set_expression_parameters(unwrap(t, K_CFTOPIC), p, n));
|
|
1522
|
+
RB_GC_GUARD(keep);
|
|
1523
|
+
return Qnil;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
static rdds_status op_create_publisher(call* c) { return rdds_participant_create_publisher(c->a, c->b, c->out); }
|
|
1527
|
+
static rdds_status op_create_subscriber(call* c) { return rdds_participant_create_subscriber(c->a, c->b, c->out); }
|
|
1528
|
+
|
|
1529
|
+
static VALUE create_group(VALUE p, VALUE partitions, int subscriber) {
|
|
1530
|
+
rdds_group_qos q;
|
|
1531
|
+
VALUE keep = rb_ary_new();
|
|
1532
|
+
void* out = NULL;
|
|
1533
|
+
call c;
|
|
1534
|
+
q.partition = strings_in(partitions, keep, &q.partition_len);
|
|
1535
|
+
memset(&c, 0, sizeof c);
|
|
1536
|
+
c.f = subscriber ? op_create_subscriber : op_create_publisher;
|
|
1537
|
+
c.a = unwrap(p, K_PARTICIPANT);
|
|
1538
|
+
c.b = &q;
|
|
1539
|
+
c.out = &out;
|
|
1540
|
+
nogvl(&c);
|
|
1541
|
+
RB_GC_GUARD(keep);
|
|
1542
|
+
return wrap(subscriber ? K_SUBSCRIBER : K_PUBLISHER, out);
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
static VALUE native_create_publisher(VALUE self, VALUE p, VALUE partitions) {
|
|
1546
|
+
(void)self;
|
|
1547
|
+
return create_group(p, partitions, 0);
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
static VALUE native_create_subscriber(VALUE self, VALUE p, VALUE partitions) {
|
|
1551
|
+
(void)self;
|
|
1552
|
+
return create_group(p, partitions, 1);
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
static rdds_status op_set_group_listener(call* c) {
|
|
1556
|
+
switch (c->i) {
|
|
1557
|
+
case K_PARTICIPANT: return rdds_participant_set_listener(c->a, c->b, c->u);
|
|
1558
|
+
case K_PUBLISHER: return rdds_publisher_set_listener(c->a, c->b, c->u);
|
|
1559
|
+
case K_SUBSCRIBER: return rdds_subscriber_set_listener(c->a, c->b, c->u);
|
|
1560
|
+
case K_TOPIC: return rdds_topic_set_listener(c->a, c->b, c->u);
|
|
1561
|
+
case K_WRITER: return rdds_writer_set_listener(c->a, c->c, c->u);
|
|
1562
|
+
case K_READER: return rdds_reader_set_listener(c->a, c->d, c->u);
|
|
1563
|
+
}
|
|
1564
|
+
return RDDS_RETCODE_BAD_PARAMETER;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
/* set_listener(entity, listener id or nil, mask) */
|
|
1568
|
+
static VALUE native_set_listener(VALUE self, VALUE entity, VALUE id, VALUE mask) {
|
|
1569
|
+
rdds_listener gl;
|
|
1570
|
+
rdds_writer_listener wl;
|
|
1571
|
+
rdds_reader_listener rl;
|
|
1572
|
+
int k = handle_kind(entity);
|
|
1573
|
+
call c;
|
|
1574
|
+
(void)self;
|
|
1575
|
+
memset(&c, 0, sizeof c);
|
|
1576
|
+
c.f = op_set_group_listener;
|
|
1577
|
+
c.a = unwrap(entity, k);
|
|
1578
|
+
c.i = k;
|
|
1579
|
+
c.u = NUM2UINT(mask);
|
|
1580
|
+
if (k == K_WRITER) {
|
|
1581
|
+
if (!NIL_P(id)) {
|
|
1582
|
+
writer_listener(&wl, id);
|
|
1583
|
+
c.c = &wl;
|
|
1584
|
+
}
|
|
1585
|
+
} else if (k == K_READER) {
|
|
1586
|
+
if (!NIL_P(id)) {
|
|
1587
|
+
reader_listener(&rl, id);
|
|
1588
|
+
c.d = &rl;
|
|
1589
|
+
}
|
|
1590
|
+
} else if (k == K_PARTICIPANT || k == K_PUBLISHER || k == K_SUBSCRIBER || k == K_TOPIC) {
|
|
1591
|
+
if (!NIL_P(id)) {
|
|
1592
|
+
group_listener(&gl, id);
|
|
1593
|
+
c.b = ≷
|
|
1594
|
+
}
|
|
1595
|
+
} else {
|
|
1596
|
+
rb_raise(rb_eTypeError, "a %s has no listener", kind_names[k]);
|
|
1597
|
+
}
|
|
1598
|
+
nogvl(&c);
|
|
1599
|
+
return Qnil;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
static rdds_status op_notify_datareaders(call* c) { return rdds_subscriber_notify_datareaders(c->a); }
|
|
1603
|
+
|
|
1604
|
+
static VALUE native_notify_datareaders(VALUE self, VALUE s) {
|
|
1605
|
+
call c;
|
|
1606
|
+
(void)self;
|
|
1607
|
+
memset(&c, 0, sizeof c);
|
|
1608
|
+
c.f = op_notify_datareaders;
|
|
1609
|
+
c.a = unwrap(s, K_SUBSCRIBER);
|
|
1610
|
+
nogvl(&c);
|
|
1611
|
+
return Qnil;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
static VALUE native_subscriber_same(VALUE self, VALUE a, VALUE b) {
|
|
1615
|
+
(void)self;
|
|
1616
|
+
return rdds_subscriber_same(unwrap(a, K_SUBSCRIBER), unwrap(b, K_SUBSCRIBER)) ? Qtrue : Qfalse;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
/* writers */
|
|
1620
|
+
|
|
1621
|
+
static rdds_status op_create_writer(call* c) {
|
|
1622
|
+
return rdds_publisher_create_writer(c->a, c->b, c->c, c->d, c->u, c->out);
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
/* create_writer(publisher, topic, qos hash, listener id or nil, mask) */
|
|
1626
|
+
static VALUE native_create_writer(VALUE self, VALUE p, VALUE topic, VALUE qos, VALUE id, VALUE mask) {
|
|
1627
|
+
rdds_writer_qos q;
|
|
1628
|
+
rdds_writer_listener l;
|
|
1629
|
+
qos_arrays keep;
|
|
1630
|
+
rdds_writer* w = NULL;
|
|
1631
|
+
call c;
|
|
1632
|
+
(void)self;
|
|
1633
|
+
writer_qos_in(qos, &q, &keep);
|
|
1634
|
+
memset(&c, 0, sizeof c);
|
|
1635
|
+
c.f = op_create_writer;
|
|
1636
|
+
c.a = unwrap(p, K_PUBLISHER);
|
|
1637
|
+
c.b = unwrap(topic, K_TOPIC);
|
|
1638
|
+
c.c = &q;
|
|
1639
|
+
if (!NIL_P(id)) {
|
|
1640
|
+
writer_listener(&l, id);
|
|
1641
|
+
c.d = &l;
|
|
1642
|
+
}
|
|
1643
|
+
c.u = NUM2UINT(mask);
|
|
1644
|
+
c.out = &w;
|
|
1645
|
+
nogvl(&c);
|
|
1646
|
+
RB_GC_GUARD(keep.user_data);
|
|
1647
|
+
RB_GC_GUARD(keep.repr);
|
|
1648
|
+
return wrap(K_WRITER, w);
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
static VALUE native_writer_guid(VALUE self, VALUE w) {
|
|
1652
|
+
rdds_guid g;
|
|
1653
|
+
(void)self;
|
|
1654
|
+
CHECK(rdds_writer_guid(unwrap(w, K_WRITER), &g));
|
|
1655
|
+
return bytes16(g.value);
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
static rdds_status op_writer_sample(call* c) {
|
|
1659
|
+
rdds_time ts, *tp = NULL;
|
|
1660
|
+
if (c->d) {
|
|
1661
|
+
ts = *(const rdds_time*)c->d;
|
|
1662
|
+
tp = &ts;
|
|
1663
|
+
}
|
|
1664
|
+
switch (c->i) {
|
|
1665
|
+
case 0: return rdds_writer_write(c->a, c->b, tp);
|
|
1666
|
+
case 1: return rdds_writer_dispose(c->a, c->b, tp);
|
|
1667
|
+
case 2: return rdds_writer_unregister_instance(c->a, c->b, tp);
|
|
1668
|
+
case 3: return rdds_writer_register_instance(c->a, c->b, c->out);
|
|
1669
|
+
case 4: return rdds_writer_lookup_instance(c->a, c->b, c->out);
|
|
1670
|
+
}
|
|
1671
|
+
return RDDS_RETCODE_BAD_PARAMETER;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
/* writer_op(writer, op, out, timestamp [sec, nanosec] or nil): op 0 write,
|
|
1675
|
+
1 dispose, 2 unregister_instance, 3 register_instance, 4
|
|
1676
|
+
lookup_instance (the last two return the instance handle). */
|
|
1677
|
+
static VALUE native_writer_op(VALUE self, VALUE w, VALUE op, VALUE out, VALUE ts) {
|
|
1678
|
+
rdds_time t;
|
|
1679
|
+
rdds_instance_handle h;
|
|
1680
|
+
call c;
|
|
1681
|
+
(void)self;
|
|
1682
|
+
memset(&c, 0, sizeof c);
|
|
1683
|
+
memset(&h, 0, sizeof h);
|
|
1684
|
+
c.f = op_writer_sample;
|
|
1685
|
+
c.a = unwrap(w, K_WRITER);
|
|
1686
|
+
c.b = out_of(out);
|
|
1687
|
+
c.i = NUM2INT(op);
|
|
1688
|
+
if (!NIL_P(ts)) {
|
|
1689
|
+
rdds_duration d = duration_in(ts);
|
|
1690
|
+
t.sec = d.sec;
|
|
1691
|
+
t.nanosec = d.nanosec;
|
|
1692
|
+
c.d = &t;
|
|
1693
|
+
}
|
|
1694
|
+
c.out = &h;
|
|
1695
|
+
nogvl(&c);
|
|
1696
|
+
RB_GC_GUARD(out);
|
|
1697
|
+
return c.i >= 3 ? bytes16(h.value) : Qnil;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
static rdds_status op_writer_wait(call* c) {
|
|
1701
|
+
if (c->i == 0) return rdds_writer_wait_for_acknowledgments(c->a, c->dur);
|
|
1702
|
+
if (c->i == 1) return rdds_writer_wait_for_subscriptions(c->a, c->n, c->dur);
|
|
1703
|
+
if (c->i == 2) return rdds_reader_wait_for_data(c->a, c->dur);
|
|
1704
|
+
return rdds_reader_wait_for_publications(c->a, c->n, c->dur);
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
/* wait(entity, what, count, duration): what 0 acknowledgments, 1
|
|
1708
|
+
subscriptions (writers), 2 data, 3 publications (readers). */
|
|
1709
|
+
static VALUE native_wait(VALUE self, VALUE e, VALUE what, VALUE count, VALUE dur) {
|
|
1710
|
+
call c;
|
|
1711
|
+
(void)self;
|
|
1712
|
+
memset(&c, 0, sizeof c);
|
|
1713
|
+
c.f = op_writer_wait;
|
|
1714
|
+
c.i = NUM2INT(what);
|
|
1715
|
+
c.a = unwrap(e, c.i < 2 ? K_WRITER : K_READER);
|
|
1716
|
+
c.n = NUM2SIZET(count);
|
|
1717
|
+
c.dur = duration_in(dur);
|
|
1718
|
+
nogvl(&c);
|
|
1719
|
+
return Qnil;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
static VALUE guids_out(const rdds_guid* g, size_t n) {
|
|
1723
|
+
VALUE a = rb_ary_new_capa((long)n);
|
|
1724
|
+
size_t i;
|
|
1725
|
+
for (i = 0; i < n; i++) rb_ary_push(a, bytes16(g[i].value));
|
|
1726
|
+
return a;
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
static VALUE native_matched(VALUE self, VALUE e) {
|
|
1730
|
+
int k = handle_kind(e);
|
|
1731
|
+
void* p = unwrap(e, k);
|
|
1732
|
+
size_t n = 0, cap;
|
|
1733
|
+
rdds_guid* buf;
|
|
1734
|
+
VALUE r;
|
|
1735
|
+
(void)self;
|
|
1736
|
+
if (k == K_WRITER)
|
|
1737
|
+
CHECK(rdds_writer_matched_subscriptions(p, NULL, 0, &n));
|
|
1738
|
+
else
|
|
1739
|
+
CHECK(rdds_reader_matched_publications(unwrap(e, K_READER), NULL, 0, &n));
|
|
1740
|
+
cap = n + 8;
|
|
1741
|
+
buf = ALLOC_N(rdds_guid, cap);
|
|
1742
|
+
{
|
|
1743
|
+
rdds_status st = k == K_WRITER ? rdds_writer_matched_subscriptions(p, buf, cap, &n)
|
|
1744
|
+
: rdds_reader_matched_publications(p, buf, cap, &n);
|
|
1745
|
+
if (st != RDDS_RETCODE_OK) {
|
|
1746
|
+
xfree(buf);
|
|
1747
|
+
raise_status(st);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
r = guids_out(buf, n < cap ? n : cap);
|
|
1751
|
+
xfree(buf);
|
|
1752
|
+
return r;
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
static VALUE native_assert_liveliness(VALUE self, VALUE w) {
|
|
1756
|
+
(void)self;
|
|
1757
|
+
CHECK(rdds_writer_assert_liveliness(unwrap(w, K_WRITER)));
|
|
1758
|
+
return Qnil;
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
/* status(entity, name): a status as listeners get it. */
|
|
1762
|
+
static VALUE native_status(VALUE self, VALUE e, VALUE name) {
|
|
1763
|
+
ID n = SYM2ID(name);
|
|
1764
|
+
int k = handle_kind(e);
|
|
1765
|
+
event ev;
|
|
1766
|
+
union {
|
|
1767
|
+
rdds_matched_status m;
|
|
1768
|
+
rdds_incompatible_qos_status q;
|
|
1769
|
+
rdds_count_status c;
|
|
1770
|
+
rdds_deadline_missed_status d;
|
|
1771
|
+
rdds_liveliness_changed_status l;
|
|
1772
|
+
rdds_sample_rejected_status r;
|
|
1773
|
+
} s;
|
|
1774
|
+
(void)self;
|
|
1775
|
+
memset(&ev, 0, sizeof ev);
|
|
1776
|
+
memset(&s, 0, sizeof s);
|
|
1777
|
+
ev.status = &s;
|
|
1778
|
+
if (k == K_WRITER) {
|
|
1779
|
+
rdds_writer* w = unwrap(e, K_WRITER);
|
|
1780
|
+
if (n == rb_intern("publication_matched")) {
|
|
1781
|
+
CHECK(rdds_writer_publication_matched_status(w, &s.m));
|
|
1782
|
+
ev.kind = EV_MATCHED;
|
|
1783
|
+
} else if (n == rb_intern("offered_incompatible_qos")) {
|
|
1784
|
+
CHECK(rdds_writer_offered_incompatible_qos_status(w, &s.q));
|
|
1785
|
+
ev.kind = EV_INCOMPATIBLE;
|
|
1786
|
+
} else if (n == rb_intern("liveliness_lost")) {
|
|
1787
|
+
CHECK(rdds_writer_liveliness_lost_status(w, &s.c));
|
|
1788
|
+
ev.kind = EV_COUNT;
|
|
1789
|
+
} else if (n == rb_intern("offered_deadline_missed")) {
|
|
1790
|
+
CHECK(rdds_writer_offered_deadline_missed_status(w, &s.d));
|
|
1791
|
+
ev.kind = EV_DEADLINE;
|
|
1792
|
+
} else {
|
|
1793
|
+
rb_raise(rb_eArgError, "no status %" PRIsVALUE, name);
|
|
1794
|
+
}
|
|
1795
|
+
} else {
|
|
1796
|
+
rdds_reader* r = unwrap(e, K_READER);
|
|
1797
|
+
if (n == rb_intern("subscription_matched")) {
|
|
1798
|
+
CHECK(rdds_reader_subscription_matched_status(r, &s.m));
|
|
1799
|
+
ev.kind = EV_MATCHED;
|
|
1800
|
+
} else if (n == rb_intern("requested_incompatible_qos")) {
|
|
1801
|
+
CHECK(rdds_reader_requested_incompatible_qos_status(r, &s.q));
|
|
1802
|
+
ev.kind = EV_INCOMPATIBLE;
|
|
1803
|
+
} else if (n == rb_intern("liveliness_changed")) {
|
|
1804
|
+
CHECK(rdds_reader_liveliness_changed_status(r, &s.l));
|
|
1805
|
+
ev.kind = EV_LIVELINESS_CHANGED;
|
|
1806
|
+
} else if (n == rb_intern("requested_deadline_missed")) {
|
|
1807
|
+
CHECK(rdds_reader_requested_deadline_missed_status(r, &s.d));
|
|
1808
|
+
ev.kind = EV_DEADLINE;
|
|
1809
|
+
} else if (n == rb_intern("sample_lost")) {
|
|
1810
|
+
CHECK(rdds_reader_sample_lost_status(r, &s.c));
|
|
1811
|
+
ev.kind = EV_COUNT;
|
|
1812
|
+
} else if (n == rb_intern("sample_rejected")) {
|
|
1813
|
+
CHECK(rdds_reader_sample_rejected_status(r, &s.r));
|
|
1814
|
+
ev.kind = EV_REJECTED;
|
|
1815
|
+
} else {
|
|
1816
|
+
rb_raise(rb_eArgError, "no status %" PRIsVALUE, name);
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
return status_value(&ev);
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
static VALUE native_status_changes(VALUE self, VALUE e) {
|
|
1823
|
+
int k = handle_kind(e);
|
|
1824
|
+
(void)self;
|
|
1825
|
+
if (k == K_WRITER) return UINT2NUM(rdds_writer_status_changes(unwrap(e, K_WRITER)));
|
|
1826
|
+
return UINT2NUM(rdds_reader_status_changes(unwrap(e, K_READER)));
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
static VALUE native_status_condition(VALUE self, VALUE e) {
|
|
1830
|
+
int k = handle_kind(e);
|
|
1831
|
+
rdds_condition* c = NULL;
|
|
1832
|
+
(void)self;
|
|
1833
|
+
if (k == K_WRITER)
|
|
1834
|
+
CHECK(rdds_writer_status_condition(unwrap(e, K_WRITER), &c));
|
|
1835
|
+
else
|
|
1836
|
+
CHECK(rdds_reader_status_condition(unwrap(e, K_READER), &c));
|
|
1837
|
+
return wrap(K_CONDITION, c);
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
/* readers */
|
|
1841
|
+
|
|
1842
|
+
static rdds_status op_create_reader(call* c) {
|
|
1843
|
+
if (c->i) return rdds_subscriber_create_filtered_reader(c->a, c->b, c->c, c->d, c->u, c->out);
|
|
1844
|
+
return rdds_subscriber_create_reader(c->a, c->b, c->c, c->d, c->u, c->out);
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
/* create_reader(subscriber, topic or content filtered topic, qos hash,
|
|
1848
|
+
listener id or nil, mask) */
|
|
1849
|
+
static VALUE native_create_reader(VALUE self, VALUE s, VALUE topic, VALUE qos, VALUE id, VALUE mask) {
|
|
1850
|
+
rdds_reader_qos q;
|
|
1851
|
+
rdds_reader_listener l;
|
|
1852
|
+
qos_arrays keep;
|
|
1853
|
+
rdds_reader* r = NULL;
|
|
1854
|
+
call c;
|
|
1855
|
+
int k = handle_kind(topic);
|
|
1856
|
+
(void)self;
|
|
1857
|
+
reader_qos_in(qos, &q, &keep);
|
|
1858
|
+
memset(&c, 0, sizeof c);
|
|
1859
|
+
c.f = op_create_reader;
|
|
1860
|
+
c.a = unwrap(s, K_SUBSCRIBER);
|
|
1861
|
+
c.i = k == K_CFTOPIC;
|
|
1862
|
+
c.b = unwrap(topic, c.i ? K_CFTOPIC : K_TOPIC);
|
|
1863
|
+
c.c = &q;
|
|
1864
|
+
if (!NIL_P(id)) {
|
|
1865
|
+
reader_listener(&l, id);
|
|
1866
|
+
c.d = &l;
|
|
1867
|
+
}
|
|
1868
|
+
c.u = NUM2UINT(mask);
|
|
1869
|
+
c.out = &r;
|
|
1870
|
+
nogvl(&c);
|
|
1871
|
+
RB_GC_GUARD(keep.user_data);
|
|
1872
|
+
RB_GC_GUARD(keep.repr);
|
|
1873
|
+
return wrap(K_READER, r);
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
static VALUE native_reader_guid(VALUE self, VALUE r) {
|
|
1877
|
+
rdds_guid g;
|
|
1878
|
+
(void)self;
|
|
1879
|
+
CHECK(rdds_reader_guid(unwrap(r, K_READER), &g));
|
|
1880
|
+
return bytes16(g.value);
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
static VALUE samples_out(rdds_samples* s) {
|
|
1884
|
+
size_t n = rdds_samples_count(s), i;
|
|
1885
|
+
VALUE a = rb_ary_new_capa((long)n);
|
|
1886
|
+
for (i = 0; i < n; i++) {
|
|
1887
|
+
rdds_sample_info info;
|
|
1888
|
+
rdds_in* in = NULL;
|
|
1889
|
+
rdds_status st = rdds_samples_info(s, i, &info);
|
|
1890
|
+
VALUE iv, data = Qnil;
|
|
1891
|
+
if (st != RDDS_RETCODE_OK) {
|
|
1892
|
+
rdds_samples_release(s);
|
|
1893
|
+
raise_status(st);
|
|
1894
|
+
}
|
|
1895
|
+
if (info.valid_data) {
|
|
1896
|
+
st = rdds_samples_data(s, i, &in);
|
|
1897
|
+
if (st == RDDS_RETCODE_OK) data = wrap_in(in);
|
|
1898
|
+
}
|
|
1899
|
+
iv = rb_ary_new_from_args(13, UINT2NUM(info.sample_state), UINT2NUM(info.view_state),
|
|
1900
|
+
UINT2NUM(info.instance_state), INT2NUM(info.disposed_generation_count),
|
|
1901
|
+
INT2NUM(info.no_writers_generation_count), INT2NUM(info.sample_rank),
|
|
1902
|
+
INT2NUM(info.generation_rank), INT2NUM(info.absolute_generation_rank),
|
|
1903
|
+
rb_ary_new_from_args(2, INT2NUM(info.source_timestamp.sec),
|
|
1904
|
+
UINT2NUM(info.source_timestamp.nanosec)),
|
|
1905
|
+
bytes16(info.instance_handle.value), bytes16(info.publication_handle.value),
|
|
1906
|
+
LL2NUM(info.sequence_number), info.valid_data ? Qtrue : Qfalse);
|
|
1907
|
+
rb_ary_push(a, rb_ary_new_from_args(2, iv, data));
|
|
1908
|
+
}
|
|
1909
|
+
rdds_samples_release(s);
|
|
1910
|
+
return a;
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
/* select(reader, take, max, sample_states, view_states, instance_states,
|
|
1914
|
+
mode, instance or nil): [[info Array, In or nil], ...] */
|
|
1915
|
+
static VALUE native_select(int argc, VALUE* argv, VALUE self) {
|
|
1916
|
+
rdds_samples* s = NULL;
|
|
1917
|
+
rdds_instance_handle h;
|
|
1918
|
+
(void)self;
|
|
1919
|
+
if (argc != 8) rb_raise(rb_eArgError, "8 arguments expected");
|
|
1920
|
+
if (!NIL_P(argv[7])) bytes16_in(argv[7], h.value);
|
|
1921
|
+
CHECK(rdds_reader_select(unwrap(argv[0], K_READER), RTEST(argv[1]), NUM2INT(argv[2]), NUM2UINT(argv[3]),
|
|
1922
|
+
NUM2UINT(argv[4]), NUM2UINT(argv[5]), NUM2INT(argv[6]), NIL_P(argv[7]) ? NULL : &h,
|
|
1923
|
+
&s));
|
|
1924
|
+
return samples_out(s);
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
static VALUE native_select_w_condition(VALUE self, VALUE r, VALUE take, VALUE max, VALUE cond) {
|
|
1928
|
+
rdds_samples* s = NULL;
|
|
1929
|
+
(void)self;
|
|
1930
|
+
CHECK(rdds_reader_select_w_condition(unwrap(r, K_READER), RTEST(take), NUM2INT(max), unwrap(cond, K_CONDITION),
|
|
1931
|
+
&s));
|
|
1932
|
+
return samples_out(s);
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
static VALUE native_reader_lookup_instance(VALUE self, VALUE r, VALUE out) {
|
|
1936
|
+
rdds_instance_handle h;
|
|
1937
|
+
(void)self;
|
|
1938
|
+
CHECK(rdds_reader_lookup_instance(unwrap(r, K_READER), out_of(out), &h));
|
|
1939
|
+
return bytes16(h.value);
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
static VALUE native_key_value(VALUE self, VALUE r, VALUE handle) {
|
|
1943
|
+
rdds_instance_handle h;
|
|
1944
|
+
rdds_in* in = NULL;
|
|
1945
|
+
(void)self;
|
|
1946
|
+
bytes16_in(handle, h.value);
|
|
1947
|
+
CHECK(rdds_reader_get_key_value(unwrap(r, K_READER), h, &in));
|
|
1948
|
+
return wrap_in(in);
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
static VALUE native_create_readcondition(VALUE self, VALUE r, VALUE ss, VALUE vs, VALUE is) {
|
|
1952
|
+
rdds_condition* c = NULL;
|
|
1953
|
+
(void)self;
|
|
1954
|
+
CHECK(rdds_reader_create_readcondition(unwrap(r, K_READER), NUM2UINT(ss), NUM2UINT(vs), NUM2UINT(is), &c));
|
|
1955
|
+
return wrap(K_CONDITION, c);
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
/* --- conditions and waitsets ----------------------------------------------------- */
|
|
1959
|
+
|
|
1960
|
+
static VALUE native_guard_condition(VALUE self) {
|
|
1961
|
+
rdds_condition* c = NULL;
|
|
1962
|
+
(void)self;
|
|
1963
|
+
CHECK(rdds_guard_condition_new(&c));
|
|
1964
|
+
return wrap(K_CONDITION, c);
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
static VALUE native_trigger_value(VALUE self, VALUE c) {
|
|
1968
|
+
(void)self;
|
|
1969
|
+
return rdds_condition_trigger_value(unwrap(c, K_CONDITION)) ? Qtrue : Qfalse;
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
static VALUE native_set_trigger_value(VALUE self, VALUE c, VALUE v) {
|
|
1973
|
+
(void)self;
|
|
1974
|
+
CHECK(rdds_guard_condition_set_trigger_value(unwrap(c, K_CONDITION), RTEST(v)));
|
|
1975
|
+
return Qnil;
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
static VALUE native_condition_equals(VALUE self, VALUE a, VALUE b) {
|
|
1979
|
+
(void)self;
|
|
1980
|
+
return rdds_condition_equals(unwrap(a, K_CONDITION), unwrap(b, K_CONDITION)) ? Qtrue : Qfalse;
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
static VALUE native_enabled_statuses(VALUE self, VALUE c) {
|
|
1984
|
+
uint32_t m = 0;
|
|
1985
|
+
(void)self;
|
|
1986
|
+
CHECK(rdds_status_condition_get_enabled_statuses(unwrap(c, K_CONDITION), &m));
|
|
1987
|
+
return UINT2NUM(m);
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
static VALUE native_set_enabled_statuses(VALUE self, VALUE c, VALUE m) {
|
|
1991
|
+
(void)self;
|
|
1992
|
+
CHECK(rdds_status_condition_set_enabled_statuses(unwrap(c, K_CONDITION), NUM2UINT(m)));
|
|
1993
|
+
return Qnil;
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
static VALUE native_waitset_new(VALUE self) {
|
|
1997
|
+
rdds_waitset* w = NULL;
|
|
1998
|
+
(void)self;
|
|
1999
|
+
CHECK(rdds_waitset_new(&w));
|
|
2000
|
+
return wrap(K_WAITSET, w);
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
static VALUE native_waitset_attach(VALUE self, VALUE w, VALUE c, VALUE attach) {
|
|
2004
|
+
(void)self;
|
|
2005
|
+
if (RTEST(attach))
|
|
2006
|
+
CHECK(rdds_waitset_attach_condition(unwrap(w, K_WAITSET), unwrap(c, K_CONDITION)));
|
|
2007
|
+
else
|
|
2008
|
+
CHECK(rdds_waitset_detach_condition(unwrap(w, K_WAITSET), unwrap(c, K_CONDITION)));
|
|
2009
|
+
return Qnil;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
static rdds_status op_waitset_wait(call* c) { return rdds_waitset_wait(c->a, c->dur, c->out, c->cap, c->len); }
|
|
2013
|
+
|
|
2014
|
+
/* waitset_wait(waitset, duration, attached count): the indices of the
|
|
2015
|
+
conditions that are true. */
|
|
2016
|
+
static VALUE native_waitset_wait(VALUE self, VALUE w, VALUE dur, VALUE count) {
|
|
2017
|
+
size_t cap = NUM2SIZET(count) + 1, n = 0, i;
|
|
2018
|
+
VALUE buf = rb_str_buf_new((long)(sizeof(size_t) * cap)), r;
|
|
2019
|
+
size_t* active;
|
|
2020
|
+
call c;
|
|
2021
|
+
(void)self;
|
|
2022
|
+
memset(&c, 0, sizeof c);
|
|
2023
|
+
c.f = op_waitset_wait;
|
|
2024
|
+
c.a = unwrap(w, K_WAITSET);
|
|
2025
|
+
c.dur = duration_in(dur);
|
|
2026
|
+
c.out = RSTRING_PTR(buf);
|
|
2027
|
+
c.cap = cap;
|
|
2028
|
+
c.len = &n;
|
|
2029
|
+
nogvl(&c);
|
|
2030
|
+
active = (size_t*)RSTRING_PTR(buf);
|
|
2031
|
+
r = rb_ary_new();
|
|
2032
|
+
for (i = 0; i < n && i < cap; i++) rb_ary_push(r, SIZET2NUM(active[i]));
|
|
2033
|
+
RB_GC_GUARD(buf);
|
|
2034
|
+
return r;
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
/* --- setup ------------------------------------------------------------------------ */
|
|
2038
|
+
|
|
2039
|
+
/* DDS::Native.setup(errors): the exception classes, by return code. */
|
|
2040
|
+
static VALUE native_setup(VALUE self, VALUE errs) {
|
|
2041
|
+
(void)self;
|
|
2042
|
+
Check_Type(errs, T_ARRAY);
|
|
2043
|
+
errors = rb_ary_dup(errs);
|
|
2044
|
+
return Qnil;
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
static VALUE native_abi_version(VALUE self) {
|
|
2048
|
+
(void)self;
|
|
2049
|
+
return UINT2NUM(rdds_abi_version());
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
void Init_rustorb_dds_ext(void) {
|
|
2053
|
+
rb_ext_ractor_safe(false);
|
|
2054
|
+
mDDS = rb_define_module("DDS");
|
|
2055
|
+
mNative = rb_define_module_under(mDDS, "Native");
|
|
2056
|
+
errors = Qnil;
|
|
2057
|
+
rb_gc_register_address(&errors);
|
|
2058
|
+
id_dispatch = rb_intern("dispatch");
|
|
2059
|
+
id_spawn_dispatcher = rb_intern("spawn_dispatcher");
|
|
2060
|
+
id_negative_p = rb_intern("negative?");
|
|
2061
|
+
|
|
2062
|
+
cHandle = rb_define_class_under(mNative, "Handle", rb_cObject);
|
|
2063
|
+
rb_undef_alloc_func(cHandle);
|
|
2064
|
+
rb_define_method(cHandle, "closed?", handle_closed_p, 0);
|
|
2065
|
+
|
|
2066
|
+
rb_define_module_function(mNative, "setup", native_setup, 1);
|
|
2067
|
+
rb_define_module_function(mNative, "abi_version", native_abi_version, 0);
|
|
2068
|
+
rb_define_module_function(mNative, "dispatcher_loop", native_dispatcher_loop, 0);
|
|
2069
|
+
rb_define_module_function(mNative, "dispatchers", native_dispatchers, 0);
|
|
2070
|
+
rb_define_module_function(mNative, "release", native_release, 1);
|
|
2071
|
+
ruby_vm_at_exit(at_exit_dispatchers);
|
|
2072
|
+
|
|
2073
|
+
rb_define_module_function(mNative, "type_primitive", native_type_primitive, 1);
|
|
2074
|
+
rb_define_module_function(mNative, "type_string", native_type_string, 2);
|
|
2075
|
+
rb_define_module_function(mNative, "type_sequence", native_type_sequence, 2);
|
|
2076
|
+
rb_define_module_function(mNative, "type_array", native_type_array, 2);
|
|
2077
|
+
rb_define_module_function(mNative, "type_alias", native_type_alias, 2);
|
|
2078
|
+
rb_define_module_function(mNative, "type_enum", native_type_enum, 4);
|
|
2079
|
+
rb_define_module_function(mNative, "type_bitmask", native_type_bitmask, 4);
|
|
2080
|
+
rb_define_module_function(mNative, "type_struct", native_type_struct, 4);
|
|
2081
|
+
rb_define_module_function(mNative, "type_union", native_type_union, 5);
|
|
2082
|
+
rb_define_module_function(mNative, "type_hashes", native_type_hashes, 1);
|
|
2083
|
+
rb_define_module_function(mNative, "serialize", native_serialize, 3);
|
|
2084
|
+
rb_define_module_function(mNative, "deserialize", native_deserialize, 2);
|
|
2085
|
+
|
|
2086
|
+
cOut = rb_define_class_under(mNative, "Out", rb_cObject);
|
|
2087
|
+
rb_define_alloc_func(cOut, out_alloc);
|
|
2088
|
+
rb_define_method(cOut, "initialize", out_initialize, 0);
|
|
2089
|
+
rb_define_method(cOut, "clear", out_clear, 0);
|
|
2090
|
+
rb_define_method(cOut, "boolean", out_boolean, 1);
|
|
2091
|
+
rb_define_method(cOut, "octet", out_octet, 1);
|
|
2092
|
+
rb_define_method(cOut, "int8", out_int8, 1);
|
|
2093
|
+
rb_define_method(cOut, "uint8", out_uint8, 1);
|
|
2094
|
+
rb_define_method(cOut, "int16", out_int16, 1);
|
|
2095
|
+
rb_define_method(cOut, "uint16", out_uint16, 1);
|
|
2096
|
+
rb_define_method(cOut, "int32", out_int32, 1);
|
|
2097
|
+
rb_define_method(cOut, "uint32", out_uint32, 1);
|
|
2098
|
+
rb_define_method(cOut, "int64", out_int64, 1);
|
|
2099
|
+
rb_define_method(cOut, "uint64", out_uint64, 1);
|
|
2100
|
+
rb_define_method(cOut, "float32", out_float32, 1);
|
|
2101
|
+
rb_define_method(cOut, "float64", out_float64, 1);
|
|
2102
|
+
rb_define_method(cOut, "float128", out_float128, 2);
|
|
2103
|
+
rb_define_method(cOut, "char8", out_char8, 1);
|
|
2104
|
+
rb_define_method(cOut, "char16", out_char16, 1);
|
|
2105
|
+
rb_define_method(cOut, "string", out_string, 1);
|
|
2106
|
+
rb_define_method(cOut, "wstring", out_wstring, 1);
|
|
2107
|
+
rb_define_method(cOut, "length", out_length, 1);
|
|
2108
|
+
rb_define_method(cOut, "present", out_present, 1);
|
|
2109
|
+
rb_define_method(cOut, "discriminator", out_discriminator, 1);
|
|
2110
|
+
rb_define_method(cOut, "enum", out_enum, 1);
|
|
2111
|
+
rb_define_method(cOut, "bitmask", out_bitmask, 1);
|
|
2112
|
+
rb_define_method(cOut, "array", out_array, 2);
|
|
2113
|
+
|
|
2114
|
+
cIn = rb_define_class_under(mNative, "In", rb_cObject);
|
|
2115
|
+
rb_undef_alloc_func(cIn);
|
|
2116
|
+
rb_define_method(cIn, "check", in_check, 0);
|
|
2117
|
+
rb_define_method(cIn, "at_end?", in_at_end_p, 0);
|
|
2118
|
+
rb_define_method(cIn, "release", in_release, 0);
|
|
2119
|
+
rb_define_method(cIn, "boolean", in_boolean, 0);
|
|
2120
|
+
rb_define_method(cIn, "octet", in_octet, 0);
|
|
2121
|
+
rb_define_method(cIn, "int8", in_int8, 0);
|
|
2122
|
+
rb_define_method(cIn, "uint8", in_uint8, 0);
|
|
2123
|
+
rb_define_method(cIn, "int16", in_int16, 0);
|
|
2124
|
+
rb_define_method(cIn, "uint16", in_uint16, 0);
|
|
2125
|
+
rb_define_method(cIn, "int32", in_int32, 0);
|
|
2126
|
+
rb_define_method(cIn, "uint32", in_uint32, 0);
|
|
2127
|
+
rb_define_method(cIn, "int64", in_int64, 0);
|
|
2128
|
+
rb_define_method(cIn, "uint64", in_uint64, 0);
|
|
2129
|
+
rb_define_method(cIn, "float32", in_float32, 0);
|
|
2130
|
+
rb_define_method(cIn, "float64", in_float64, 0);
|
|
2131
|
+
rb_define_method(cIn, "float128", in_float128, 0);
|
|
2132
|
+
rb_define_method(cIn, "char8", in_char8, 0);
|
|
2133
|
+
rb_define_method(cIn, "char16", in_char16, 0);
|
|
2134
|
+
rb_define_method(cIn, "string", in_string, 0);
|
|
2135
|
+
rb_define_method(cIn, "wstring", in_wstring, 0);
|
|
2136
|
+
rb_define_method(cIn, "length", in_length, 0);
|
|
2137
|
+
rb_define_method(cIn, "present", in_present, 0);
|
|
2138
|
+
rb_define_method(cIn, "discriminator", in_discriminator, 0);
|
|
2139
|
+
rb_define_method(cIn, "enum", in_enum, 0);
|
|
2140
|
+
rb_define_method(cIn, "bitmask", in_bitmask, 0);
|
|
2141
|
+
rb_define_method(cIn, "array", in_array, 2);
|
|
2142
|
+
|
|
2143
|
+
rb_define_module_function(mNative, "writer_qos_default", native_writer_qos_default, 0);
|
|
2144
|
+
rb_define_module_function(mNative, "reader_qos_default", native_reader_qos_default, 0);
|
|
2145
|
+
|
|
2146
|
+
rb_define_module_function(mNative, "participant_new", native_participant_new, 4);
|
|
2147
|
+
rb_define_module_function(mNative, "participant_info", native_participant_info, 1);
|
|
2148
|
+
rb_define_module_function(mNative, "participant_assert_liveliness", native_participant_assert_liveliness, 1);
|
|
2149
|
+
rb_define_module_function(mNative, "create_topic", native_create_topic, 3);
|
|
2150
|
+
rb_define_module_function(mNative, "topic_inconsistent_status", native_topic_inconsistent_status, 1);
|
|
2151
|
+
rb_define_module_function(mNative, "create_cftopic", native_create_cftopic, 5);
|
|
2152
|
+
rb_define_module_function(mNative, "cftopic_set_parameters", native_cftopic_set_parameters, 2);
|
|
2153
|
+
rb_define_module_function(mNative, "create_publisher", native_create_publisher, 2);
|
|
2154
|
+
rb_define_module_function(mNative, "create_subscriber", native_create_subscriber, 2);
|
|
2155
|
+
rb_define_module_function(mNative, "set_listener", native_set_listener, 3);
|
|
2156
|
+
rb_define_module_function(mNative, "notify_datareaders", native_notify_datareaders, 1);
|
|
2157
|
+
rb_define_module_function(mNative, "subscriber_same", native_subscriber_same, 2);
|
|
2158
|
+
rb_define_module_function(mNative, "create_writer", native_create_writer, 5);
|
|
2159
|
+
rb_define_module_function(mNative, "writer_guid", native_writer_guid, 1);
|
|
2160
|
+
rb_define_module_function(mNative, "writer_op", native_writer_op, 4);
|
|
2161
|
+
rb_define_module_function(mNative, "wait", native_wait, 4);
|
|
2162
|
+
rb_define_module_function(mNative, "matched", native_matched, 1);
|
|
2163
|
+
rb_define_module_function(mNative, "assert_liveliness", native_assert_liveliness, 1);
|
|
2164
|
+
rb_define_module_function(mNative, "status", native_status, 2);
|
|
2165
|
+
rb_define_module_function(mNative, "status_changes", native_status_changes, 1);
|
|
2166
|
+
rb_define_module_function(mNative, "status_condition", native_status_condition, 1);
|
|
2167
|
+
rb_define_module_function(mNative, "create_reader", native_create_reader, 5);
|
|
2168
|
+
rb_define_module_function(mNative, "reader_guid", native_reader_guid, 1);
|
|
2169
|
+
rb_define_module_function(mNative, "select", native_select, -1);
|
|
2170
|
+
rb_define_module_function(mNative, "select_w_condition", native_select_w_condition, 4);
|
|
2171
|
+
rb_define_module_function(mNative, "reader_lookup_instance", native_reader_lookup_instance, 2);
|
|
2172
|
+
rb_define_module_function(mNative, "key_value", native_key_value, 2);
|
|
2173
|
+
rb_define_module_function(mNative, "create_readcondition", native_create_readcondition, 4);
|
|
2174
|
+
|
|
2175
|
+
rb_define_module_function(mNative, "guard_condition", native_guard_condition, 0);
|
|
2176
|
+
rb_define_module_function(mNative, "trigger_value", native_trigger_value, 1);
|
|
2177
|
+
rb_define_module_function(mNative, "set_trigger_value", native_set_trigger_value, 2);
|
|
2178
|
+
rb_define_module_function(mNative, "condition_equals", native_condition_equals, 2);
|
|
2179
|
+
rb_define_module_function(mNative, "enabled_statuses", native_enabled_statuses, 1);
|
|
2180
|
+
rb_define_module_function(mNative, "set_enabled_statuses", native_set_enabled_statuses, 2);
|
|
2181
|
+
rb_define_module_function(mNative, "waitset_new", native_waitset_new, 0);
|
|
2182
|
+
rb_define_module_function(mNative, "waitset_attach", native_waitset_attach, 3);
|
|
2183
|
+
rb_define_module_function(mNative, "waitset_wait", native_waitset_wait, 3);
|
|
2184
|
+
}
|