babeltrace2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/babeltrace2.gemspec +13 -0
  4. data/lib/babeltrace2.rb +49 -0
  5. data/lib/babeltrace2/error-reporting.rb +432 -0
  6. data/lib/babeltrace2/func-status.rb +26 -0
  7. data/lib/babeltrace2/graph/component-class-dev.rb +801 -0
  8. data/lib/babeltrace2/graph/component-class.rb +134 -0
  9. data/lib/babeltrace2/graph/component-descriptor-set.rb +78 -0
  10. data/lib/babeltrace2/graph/component.rb +362 -0
  11. data/lib/babeltrace2/graph/connection.rb +35 -0
  12. data/lib/babeltrace2/graph/graph.rb +523 -0
  13. data/lib/babeltrace2/graph/interrupter.rb +57 -0
  14. data/lib/babeltrace2/graph/message-iterator-class.rb +374 -0
  15. data/lib/babeltrace2/graph/message-iterator.rb +253 -0
  16. data/lib/babeltrace2/graph/message.rb +721 -0
  17. data/lib/babeltrace2/graph/port.rb +124 -0
  18. data/lib/babeltrace2/graph/private-query-executor.rb +4 -0
  19. data/lib/babeltrace2/graph/query-executor.rb +142 -0
  20. data/lib/babeltrace2/graph/self-component-class.rb +37 -0
  21. data/lib/babeltrace2/graph/self-component-port.rb +35 -0
  22. data/lib/babeltrace2/graph/self-component.rb +264 -0
  23. data/lib/babeltrace2/graph/self-message-iterator.rb +147 -0
  24. data/lib/babeltrace2/integer-range-set.rb +275 -0
  25. data/lib/babeltrace2/logging-defs.rb +19 -0
  26. data/lib/babeltrace2/logging.rb +77 -0
  27. data/lib/babeltrace2/plugin/plugin-dev.rb +335 -0
  28. data/lib/babeltrace2/plugin/plugin-loading.rb +459 -0
  29. data/lib/babeltrace2/trace-ir/clock-class.rb +258 -0
  30. data/lib/babeltrace2/trace-ir/clock-snapshot.rb +45 -0
  31. data/lib/babeltrace2/trace-ir/event-class.rb +292 -0
  32. data/lib/babeltrace2/trace-ir/event.rb +91 -0
  33. data/lib/babeltrace2/trace-ir/field-class.rb +1416 -0
  34. data/lib/babeltrace2/trace-ir/field-path.rb +123 -0
  35. data/lib/babeltrace2/trace-ir/field.rb +871 -0
  36. data/lib/babeltrace2/trace-ir/packet.rb +57 -0
  37. data/lib/babeltrace2/trace-ir/stream-class.rb +425 -0
  38. data/lib/babeltrace2/trace-ir/stream.rb +137 -0
  39. data/lib/babeltrace2/trace-ir/trace-class.rb +343 -0
  40. data/lib/babeltrace2/trace-ir/trace.rb +321 -0
  41. data/lib/babeltrace2/types.rb +667 -0
  42. data/lib/babeltrace2/util.rb +23 -0
  43. data/lib/babeltrace2/value.rb +869 -0
  44. data/lib/babeltrace2/version.rb +126 -0
  45. metadata +105 -0
@@ -0,0 +1,23 @@
1
+ module Babeltrace2
2
+ BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OK = BT_FUNC_STATUS_OK
3
+ BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR = BT_FUNC_STATUS_OVERFLOW_ERROR
4
+
5
+ BTUtilClockCyclesToNSFromOriginStatus = enum :bt_util_clock_cycles_to_ns_from_origin_status,
6
+ [ :BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OK, BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OK,
7
+ :BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR, BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR ]
8
+
9
+ attach_function :bt_util_clock_cycles_to_ns_from_origin,
10
+ [:uint64, :uint64, :int64, :uint64, :pointer],
11
+ :bt_util_clock_cycles_to_ns_from_origin_status
12
+
13
+ module BTUtil
14
+ ClockCyclesToNSFromOriginStatus = BTUtilClockCyclesToNSFromOriginStatus
15
+
16
+ def self.clock_cycles_to_ns_from_origin(cycles, frequency, offset_seconds, offset_cycles)
17
+ ptr = FFI::MemoryPointer.new(:int64)
18
+ res = Babeltrace2.bt_util_clock_cycles_to_ns_from_origin(cycles, frequency, offset_seconds, offset_cycles, ptr)
19
+ raise Babeltrace2.process_error(res) if res != :BT_UTIL_CLOCK_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OK
20
+ ptr.read_int64
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,869 @@
1
+ require 'singleton'
2
+ module Babeltrace2
3
+
4
+ BT_VALUE_TYPE_NULL = 1 << 0
5
+ BT_VALUE_TYPE_BOOL = 1 << 1
6
+ BT_VALUE_TYPE_INTEGER = 1 << 2
7
+ BT_VALUE_TYPE_UNSIGNED_INTEGER = (1 << 3) | BT_VALUE_TYPE_INTEGER
8
+ BT_VALUE_TYPE_SIGNED_INTEGER = (1 << 4) | BT_VALUE_TYPE_INTEGER
9
+ BT_VALUE_TYPE_REAL = 1 << 5
10
+ BT_VALUE_TYPE_STRING = 1 << 6
11
+ BT_VALUE_TYPE_ARRAY = 1 << 7
12
+ BT_VALUE_TYPE_MAP = 1 << 8
13
+
14
+ BTValueType = enum :bt_value_type,
15
+ [ :BT_VALUE_TYPE_NULL, BT_VALUE_TYPE_NULL,
16
+ :BT_VALUE_TYPE_BOOL, BT_VALUE_TYPE_BOOL,
17
+ :BT_VALUE_TYPE_INTEGER, BT_VALUE_TYPE_INTEGER,
18
+ :BT_VALUE_TYPE_UNSIGNED_INTEGER, BT_VALUE_TYPE_UNSIGNED_INTEGER,
19
+ :BT_VALUE_TYPE_SIGNED_INTEGER, BT_VALUE_TYPE_SIGNED_INTEGER,
20
+ :BT_VALUE_TYPE_REAL, BT_VALUE_TYPE_REAL,
21
+ :BT_VALUE_TYPE_STRING, BT_VALUE_TYPE_STRING,
22
+ :BT_VALUE_TYPE_ARRAY, BT_VALUE_TYPE_ARRAY,
23
+ :BT_VALUE_TYPE_MAP, BT_VALUE_TYPE_MAP ]
24
+
25
+ attach_function :bt_value_get_type,
26
+ [:bt_value_handle],
27
+ :bt_value_type
28
+
29
+ BT_VALUE_COPY_STATUS_OK = BT_FUNC_STATUS_OK
30
+ BT_VALUE_COPY_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
31
+ BTValueCopyStatus = enum :bt_value_copy_status,
32
+ [ :BT_VALUE_COPY_STATUS_OK, BT_VALUE_COPY_STATUS_OK,
33
+ :BT_VALUE_COPY_STATUS_MEMORY_ERROR, BT_VALUE_COPY_STATUS_MEMORY_ERROR ]
34
+
35
+ attach_function :bt_value_copy,
36
+ [:bt_value_handle, :pointer],
37
+ :bt_value_copy_status
38
+
39
+ attach_function :bt_value_is_equal,
40
+ [:bt_value_handle, :bt_value_handle],
41
+ :bt_bool
42
+
43
+ attach_function :bt_value_get_ref,
44
+ [:bt_value_handle],
45
+ :void
46
+
47
+ attach_function :bt_value_put_ref,
48
+ [:bt_value_handle],
49
+ :void
50
+
51
+ class BTValue < BTSharedObject
52
+ @get_ref = :bt_value_get_ref
53
+ @put_ref = :bt_value_put_ref
54
+
55
+ TYPE_MAP = {}
56
+
57
+ def get_type
58
+ Babeltrace2.bt_value_get_type(@handle)
59
+ end
60
+ alias type get_type
61
+
62
+ def self.from_handle(handle, retain: true, auto_release: true)
63
+ type = Babeltrace2.bt_value_get_type(handle)
64
+ if type == :BT_VALUE_TYPE_NULL
65
+ return BTValueNull.instance
66
+ else
67
+ clss = TYPE_MAP[type]
68
+ raise "unsupported value type" unless clss
69
+ handle = clss[0].new(handle)
70
+ clss[1].new(handle, retain: retain, auto_release: auto_release)
71
+ end
72
+ end
73
+
74
+ def self.from_value(value)
75
+ case value
76
+ when BTValue
77
+ value
78
+ when nil
79
+ return BTValueNull.instance
80
+ when false
81
+ Bool.new(value: false)
82
+ when true
83
+ Bool.new(value: true)
84
+ when ::Integer
85
+ if value > (1<<63) - 1
86
+ BTValueIntegerUnsigned.new(value: value)
87
+ else
88
+ BTValueIntegerSigned.new(value: value)
89
+ end
90
+ when ::Float
91
+ BTValueReal.new(value: value)
92
+ when ::String
93
+ BTValueString.new(value: value)
94
+ when ::Array
95
+ arr = BTValueArray.new
96
+ value.each { |v|
97
+ arr.push(v)
98
+ }
99
+ arr
100
+ when ::Hash
101
+ map = BTValueMap.new
102
+ value.each { |k, v|
103
+ map.insert_entry(k, v)
104
+ }
105
+ map
106
+ else
107
+ raise TypeError, "unsupported value type"
108
+ end
109
+ end
110
+
111
+ def to_s
112
+ value.to_s
113
+ end
114
+
115
+ def copy
116
+ ptr = FFI::MemoryPointer.new(:pointer)
117
+ res = Babeltrace2.bt_value_copy(@handle, ptr)
118
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_COPY_STATUS_OK
119
+ BTValue.from_handle(BTValueHandle.new(ptr.read_pointer), retain: false)
120
+ end
121
+
122
+ def is_equal(other)
123
+ other = BTValue.from_value(other)
124
+ Babeltrace2.bt_value_is_equal(@handle, other) != BT_FALSE
125
+ end
126
+ alias == is_equal
127
+ end
128
+
129
+ attach_variable :bt_value_null, :bt_value_null_handle
130
+
131
+ class BTValue
132
+ class Null < BTValue
133
+ include Singleton
134
+ def initialize
135
+ super(Babeltrace2.bt_value_null, retain: false, auto_release: false)
136
+ end
137
+
138
+ def value
139
+ nil
140
+ end
141
+ end
142
+ end
143
+ BTValueNull = BTValue::Null
144
+
145
+ attach_function :bt_value_bool_create,
146
+ [],
147
+ :bt_value_bool_handle
148
+
149
+ attach_function :bt_value_bool_create_init,
150
+ [:bt_bool],
151
+ :bt_value_bool_handle
152
+
153
+ attach_function :bt_value_bool_set,
154
+ [:bt_value_bool_handle, :bt_bool],
155
+ :void
156
+
157
+ attach_function :bt_value_bool_get,
158
+ [:bt_value_bool_handle],
159
+ :bt_bool
160
+
161
+ class BTValue
162
+ class Bool < BTValue
163
+ def initialize(handle = nil, retain: true, auto_release: true, value: nil)
164
+ if handle
165
+ super(handle, retain: retain, auto_release: auto_release)
166
+ else
167
+ handle = if value.nil?
168
+ Babeltrace2.bt_value_bool_create()
169
+ else
170
+ Babeltrace2.bt_value_bool_create_init(value ? BT_TRUE : BT_FALSE)
171
+ end
172
+ raise Babeltrace2.process_error if handle.null?
173
+ super(handle)
174
+ end
175
+ end
176
+
177
+ def set(value)
178
+ Babeltrace2.bt_value_bool_set(@handle, value ? BT_TRUE : BT_FALSE)
179
+ self
180
+ end
181
+
182
+ def value=(value)
183
+ set(value)
184
+ value
185
+ end
186
+
187
+ def get
188
+ Babeltrace2.bt_value_bool_get(@handle) != BT_FALSE
189
+ end
190
+ alias value get
191
+ end
192
+ end
193
+ BTValueBool = BTValue::Bool
194
+ BTValue::TYPE_MAP[:BT_VALUE_TYPE_BOOL] = [
195
+ BTValueBoolHandle,
196
+ BTValueBool ]
197
+
198
+ class BTValue::Integer < BTValue
199
+ end
200
+ BTValueInteger = BTValue::Integer
201
+
202
+ attach_function :bt_value_integer_unsigned_create,
203
+ [],
204
+ :bt_value_integer_unsigned_handle
205
+
206
+ attach_function :bt_value_integer_unsigned_create_init,
207
+ [:uint64],
208
+ :bt_value_integer_unsigned_handle
209
+
210
+ attach_function :bt_value_integer_unsigned_set,
211
+ [:bt_value_integer_unsigned_handle, :uint64],
212
+ :void
213
+
214
+ attach_function :bt_value_integer_unsigned_get,
215
+ [:bt_value_integer_unsigned_handle],
216
+ :uint64
217
+
218
+ class BTValue::Integer::Unsigned < BTValue::Integer
219
+ def initialize(handle = nil, retain: true, auto_release: true, value: nil)
220
+ if handle
221
+ super(handle, retain: retain, auto_release: auto_release)
222
+ else
223
+ handle = if value.nil?
224
+ Babeltrace2.bt_value_integer_unsigned_create()
225
+ else
226
+ Babeltrace2.bt_value_integer_unsigned_create_init(value)
227
+ end
228
+ raise Babeltrace2.process_error if handle.null?
229
+ super(handle)
230
+ end
231
+ end
232
+
233
+ def set(value)
234
+ Babeltrace2.bt_value_integer_unsigned_set(@handle, value)
235
+ self
236
+ end
237
+
238
+ def value=(value)
239
+ set(value)
240
+ value
241
+ end
242
+
243
+ def get
244
+ Babeltrace2.bt_value_integer_unsigned_get(@handle)
245
+ end
246
+ alias value get
247
+ alias to_i get
248
+ end
249
+ BTValue::IntegerUnsigned = BTValue::Integer::Unsigned
250
+ BTValueIntegerUnsigned = BTValue::Integer::Unsigned
251
+ BTValue::TYPE_MAP[:BT_VALUE_TYPE_UNSIGNED_INTEGER] = [
252
+ BTValueIntegerUnsignedHandle,
253
+ BTValueIntegerUnsigned ]
254
+
255
+ attach_function :bt_value_integer_signed_create,
256
+ [],
257
+ :bt_value_integer_signed_handle
258
+
259
+ attach_function :bt_value_integer_signed_create_init,
260
+ [:int64],
261
+ :bt_value_integer_signed_handle
262
+
263
+ attach_function :bt_value_integer_signed_set,
264
+ [:bt_value_integer_signed_handle, :int64],
265
+ :void
266
+
267
+ attach_function :bt_value_integer_signed_get,
268
+ [:bt_value_integer_signed_handle],
269
+ :int64
270
+
271
+ class BTValue::Integer::Signed < BTValue::Integer
272
+ def initialize(handle = nil, retain: true, auto_release: true, value: nil)
273
+ if handle
274
+ super(handle, retain: retain, auto_release: auto_release)
275
+ else
276
+ handle = if value.nil?
277
+ Babeltrace2.bt_value_integer_signed_create()
278
+ else
279
+ Babeltrace2.bt_value_integer_signed_create_init(value)
280
+ end
281
+ raise Babeltrace2.process_error if handle.null?
282
+ super(handle)
283
+ end
284
+ end
285
+
286
+ def set(value)
287
+ Babeltrace2.bt_value_integer_signed_set(@handle, value)
288
+ self
289
+ end
290
+
291
+ def value=(value)
292
+ set(value)
293
+ value
294
+ end
295
+
296
+ def get
297
+ Babeltrace2.bt_value_integer_signed_get(@handle)
298
+ end
299
+ alias value get
300
+ alias to_i get
301
+ end
302
+ BTValue::IntegerSigned = BTValue::Integer::Signed
303
+ BTValueIntegerSigned = BTValue::Integer::Signed
304
+ BTValue::TYPE_MAP[:BT_VALUE_TYPE_SIGNED_INTEGER] = [
305
+ BTValueIntegerSignedHandle,
306
+ BTValueIntegerSigned ]
307
+
308
+ attach_function :bt_value_real_create,
309
+ [],
310
+ :bt_value_real_handle
311
+
312
+ attach_function :bt_value_real_create_init,
313
+ [:double],
314
+ :bt_value_real_handle
315
+
316
+ attach_function :bt_value_real_set,
317
+ [:bt_value_real_handle, :double],
318
+ :void
319
+
320
+ attach_function :bt_value_real_get,
321
+ [:bt_value_real_handle],
322
+ :double
323
+
324
+ class BTValue::Real < BTValue
325
+ def initialize(handle = nil, retain: true, auto_release: true, value: nil)
326
+ if handle
327
+ super(handle, retain: retain, auto_release: auto_release)
328
+ else
329
+ handle = if value.nil?
330
+ Babeltrace2.bt_value_real_create()
331
+ else
332
+ Babeltrace2.bt_value_real_create_init(value)
333
+ end
334
+ raise Babeltrace2.process_error if handle.null?
335
+ super(handle)
336
+ end
337
+ end
338
+
339
+ def set(value)
340
+ Babeltrace2.bt_value_real_set(@handle, value)
341
+ self
342
+ end
343
+
344
+ def value=(value)
345
+ set(value)
346
+ value
347
+ end
348
+
349
+ def get
350
+ Babeltrace2.bt_value_real_get(@handle)
351
+ end
352
+ alias value get
353
+ alias to_f get
354
+ end
355
+ BTValueReal = BTValue::Real
356
+ BTValue::TYPE_MAP[:BT_VALUE_TYPE_REAL] = [
357
+ BTValueRealHandle,
358
+ BTValueReal ]
359
+
360
+ attach_function :bt_value_string_create,
361
+ [],
362
+ :bt_value_handle
363
+
364
+ attach_function :bt_value_string_create_init,
365
+ [:string],
366
+ :bt_value_handle
367
+
368
+ BT_VALUE_STRING_SET_STATUS_OK = BT_FUNC_STATUS_OK
369
+ BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
370
+ BTValueStringSetStatus = enum :bt_value_string_set_status,
371
+ [ :BT_VALUE_STRING_SET_STATUS_OK, BT_VALUE_STRING_SET_STATUS_OK,
372
+ :BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR, BT_FUNC_STATUS_MEMORY_ERROR ]
373
+
374
+ attach_function :bt_value_string_set,
375
+ [:bt_value_handle, :string],
376
+ :bt_value_string_set_status
377
+
378
+ attach_function :bt_value_string_get,
379
+ [:bt_value_handle],
380
+ :string
381
+ class BTValue
382
+ StringSetStatus = BTValueStringSetStatus
383
+ class String < BTValue
384
+ SetStatus = BTValueStringSetStatus
385
+ def initialize(handle = nil, retain: true, auto_release: true, value: nil)
386
+ if handle
387
+ super(handle, retain: retain, auto_release: auto_release)
388
+ else
389
+ handle = if value.nil?
390
+ Babeltrace2.bt_value_string_create()
391
+ else
392
+ Babeltrace2.bt_value_string_create_init(value)
393
+ end
394
+ raise Babeltrace2.process_error if handle.null?
395
+ super(handle)
396
+ end
397
+ end
398
+
399
+ def set(value)
400
+ raise TypeError, "value is 'nil'" if value.nil?
401
+ res = Babeltrace2.bt_value_string_set(@handle, value)
402
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_STRING_SET_STATUS_OK
403
+ self
404
+ end
405
+
406
+ def value=(value)
407
+ set(value)
408
+ value
409
+ end
410
+
411
+ def get
412
+ Babeltrace2.bt_value_string_get(@handle)
413
+ end
414
+ alias value get
415
+ alias to_s get
416
+ end
417
+ end
418
+ BTValueString = BTValue::String
419
+ BTValue::TYPE_MAP[:BT_VALUE_TYPE_STRING] = [
420
+ BTValueStringHandle,
421
+ BTValueString ]
422
+
423
+ attach_function :bt_value_array_create,
424
+ [],
425
+ :bt_value_handle
426
+
427
+ BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK = BT_FUNC_STATUS_OK
428
+ BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
429
+ BTValueArrayAppendElementStatus = enum :bt_value_array_append_element_status,
430
+ [ :BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK, BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK,
431
+ :BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR, BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR ]
432
+
433
+ attach_function :bt_value_array_append_element,
434
+ [:bt_value_handle, :bt_value_handle],
435
+ :bt_value_array_append_element_status
436
+
437
+ attach_function :bt_value_array_append_bool_element,
438
+ [:bt_value_handle, :bt_bool],
439
+ :bt_value_array_append_element_status
440
+
441
+ attach_function :bt_value_array_append_unsigned_integer_element,
442
+ [:bt_value_handle, :uint64],
443
+ :bt_value_array_append_element_status
444
+
445
+ attach_function :bt_value_array_append_signed_integer_element,
446
+ [:bt_value_handle, :int64],
447
+ :bt_value_array_append_element_status
448
+
449
+ attach_function :bt_value_array_append_real_element,
450
+ [:bt_value_handle, :double],
451
+ :bt_value_array_append_element_status
452
+
453
+ attach_function :bt_value_array_append_string_element,
454
+ [:bt_value_handle, :string],
455
+ :bt_value_array_append_element_status
456
+
457
+ attach_function :bt_value_array_append_empty_array_element,
458
+ [:bt_value_handle, :pointer],
459
+ :bt_value_array_append_element_status
460
+
461
+ attach_function :bt_value_array_append_empty_map_element,
462
+ [:bt_value_handle, :pointer],
463
+ :bt_value_array_append_element_status
464
+
465
+ BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_OK = BT_FUNC_STATUS_OK
466
+ BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
467
+ BTValueArraySetElementByIndexStatus = enum :bt_value_array_set_element_by_index_status,
468
+ [ :BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_OK, BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_OK,
469
+ :BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_MEMORY_ERROR, BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_MEMORY_ERROR ]
470
+
471
+ attach_function :bt_value_array_set_element_by_index,
472
+ [:bt_value_handle, :uint64, :bt_value_handle],
473
+ :bt_value_array_set_element_by_index_status
474
+
475
+ attach_function :bt_value_array_borrow_element_by_index,
476
+ [:bt_value_handle, :uint64],
477
+ :bt_value_handle
478
+
479
+ attach_function :bt_value_array_borrow_element_by_index_const,
480
+ [:bt_value_handle, :uint64],
481
+ :bt_value_handle
482
+
483
+ attach_function :bt_value_array_get_length,
484
+ [:bt_value_handle],
485
+ :uint64
486
+
487
+ class BTValue
488
+ ArrayAppendElementStatus = BTValueArrayAppendElementStatus
489
+ ArraySetElementByIndexStatus = BTValueArraySetElementByIndexStatus
490
+ class Array < BTValue
491
+ AppendElementStatus = BTValueArrayAppendElementStatus
492
+ SetElementByIndexStatus = BTValueArraySetElementByIndexStatus
493
+
494
+ def initialize(handle = nil, retain: true, auto_release: true)
495
+ if handle
496
+ super(handle, retain: retain, auto_release: auto_release)
497
+ else
498
+ handle = Babeltrace2.bt_value_array_create()
499
+ raise Babeltrace2.process_error if handle.null?
500
+ super(handle)
501
+ end
502
+ end
503
+
504
+ def append_element(value)
505
+ res = case value
506
+ when BTValue
507
+ Babeltrace2.bt_value_array_append_element(@handle, value)
508
+ when nil
509
+ Babeltrace2.bt_value_array_append_element(@handle, Babeltrace2.bt_value_null)
510
+ when true
511
+ Babeltrace2.bt_value_array_append_bool_element(@handle, BT_TRUE)
512
+ when false
513
+ Babeltrace2.bt_value_array_append_bool_element(@handle, BT_FALSE)
514
+ when ::Integer
515
+ if value > (1<<63) - 1
516
+ Babeltrace2.bt_value_array_append_unsigned_integer_element(@handle, value)
517
+ else
518
+ Babeltrace2.bt_value_array_append_signed_integer_element(@handle, value)
519
+ end
520
+ when ::Float
521
+ Babeltrace2.bt_value_array_append_real_element(@handle, value)
522
+ when ::String
523
+ Babeltrace2.bt_value_array_append_string_element(@handle, value)
524
+ when ::Array
525
+ ptr = FFI::MemoryPointer.new(:pointer)
526
+ res = Babeltrace2.bt_value_array_append_empty_array_element(@handle, ptr)
527
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
528
+ arr = BTValueArray.new(BTValueArrayHandle.new(ptr.read_pointer),
529
+ retain: false, auto_release: false)
530
+ value.each { |v| arr.append_element(v) }
531
+ :BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
532
+ when ::Hash
533
+ ptr = FFI::MemoryPointer.new(:pointer)
534
+ res = Babeltrace2.bt_value_array_append_empty_map_element(@handle, ptr)
535
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
536
+ map = BTValueMap.new(BTValueMapHandle.new(ptr.read_pointer),
537
+ retain: false, auto_release: false)
538
+ value.each { |k, v| map.insert_entry(k, v) }
539
+ :BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
540
+ else
541
+ raise TypeError, "unsupported value type"
542
+ end
543
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
544
+ self
545
+ end
546
+ alias push append_element
547
+
548
+ def set_element_by_index(index, value)
549
+ l = length
550
+ index += l if index < 0
551
+ raise IndexError, "invalid index" if index < 0 || index >= l
552
+ val = value
553
+ val = BTValue.from_value(val) unless val.kind_of?(BTValue)
554
+ res = Babeltrace2.bt_value_array_set_element_by_index(@handle, index, val)
555
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_ARRAY_SET_ELEMENT_BY_INDEX_STATUS_OK
556
+ self
557
+ end
558
+
559
+ def []=(index, value)
560
+ set_element_by_index(index, value)
561
+ value
562
+ end
563
+
564
+ def get_element_by_index(index)
565
+ l = length
566
+ index += l if index < 0
567
+ raise IndexError, "invalid index" if index < 0 || index >= l
568
+ handle = Babeltrace2.bt_value_array_borrow_element_by_index(@handle, index)
569
+ BTValue.from_handle(handle)
570
+ end
571
+ alias [] get_element_by_index
572
+
573
+ def get_length
574
+ Babeltrace2.bt_value_array_get_length(@handle)
575
+ end
576
+ alias length get_length
577
+ alias size length
578
+
579
+ def empty?
580
+ length == 0
581
+ end
582
+
583
+ def each
584
+ if block_given?
585
+ length.times { |i|
586
+ yield get_element_by_index(i)
587
+ }
588
+ else
589
+ to_enum(:each)
590
+ end
591
+ end
592
+
593
+ def value
594
+ each.collect(&:value)
595
+ end
596
+ alias to_a value
597
+ end
598
+ end
599
+ BTValueArray = BTValue::Array
600
+ BTValue::TYPE_MAP[:BT_VALUE_TYPE_ARRAY] = [
601
+ BTValueArrayHandle,
602
+ BTValueArray ]
603
+
604
+
605
+ attach_function :bt_value_map_create,
606
+ [],
607
+ :bt_value_map_handle
608
+
609
+ BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK = BT_FUNC_STATUS_OK
610
+ BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
611
+ BTValueMapInsertEntryStatus = enum :bt_value_map_insert_entry_status,
612
+ [ :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK, BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK,
613
+ :BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR, BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR ]
614
+
615
+ attach_function :bt_value_map_insert_entry,
616
+ [:bt_value_map_handle, :string, :bt_value_handle],
617
+ :bt_value_map_insert_entry_status
618
+
619
+ attach_function :bt_value_map_insert_bool_entry,
620
+ [:bt_value_map_handle, :string, :bt_bool],
621
+ :bt_value_map_insert_entry_status
622
+
623
+ attach_function :bt_value_map_insert_unsigned_integer_entry,
624
+ [:bt_value_map_handle, :string, :uint64],
625
+ :bt_value_map_insert_entry_status
626
+
627
+ attach_function :bt_value_map_insert_signed_integer_entry,
628
+ [:bt_value_map_handle, :string, :int64],
629
+ :bt_value_map_insert_entry_status
630
+
631
+ attach_function :bt_value_map_insert_real_entry,
632
+ [:bt_value_map_handle, :string, :double],
633
+ :bt_value_map_insert_entry_status
634
+
635
+ attach_function :bt_value_map_insert_string_entry,
636
+ [:bt_value_map_handle, :string, :string],
637
+ :bt_value_map_insert_entry_status
638
+
639
+ attach_function :bt_value_map_insert_empty_array_entry,
640
+ [:bt_value_map_handle, :string, :pointer],
641
+ :bt_value_map_insert_entry_status
642
+
643
+ attach_function :bt_value_map_insert_empty_map_entry,
644
+ [:bt_value_map_handle, :string, :pointer],
645
+ :bt_value_map_insert_entry_status
646
+
647
+ attach_function :bt_value_map_borrow_entry_value,
648
+ [:bt_value_map_handle, :string],
649
+ :bt_value_handle
650
+
651
+ attach_function :bt_value_map_borrow_entry_value_const,
652
+ [:bt_value_map_handle, :string],
653
+ :bt_value_handle
654
+
655
+ BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK = BT_FUNC_STATUS_OK
656
+ BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT = BT_FUNC_STATUS_INTERRUPTED
657
+ BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
658
+ BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR = BT_FUNC_STATUS_ERROR
659
+ BTValueMapForeachEntryFuncStatus = enum :bt_value_map_foreach_entry_func_status,
660
+ [ :BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK, BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK,
661
+ :BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT, BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT,
662
+ :BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR, BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR,
663
+ :BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR, BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR ]
664
+
665
+ callback :bt_value_map_foreach_entry_func,
666
+ [:string, :bt_value_handle, :pointer],
667
+ :bt_value_map_foreach_entry_func_status
668
+
669
+ BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK = BT_FUNC_STATUS_OK
670
+ BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPT = BT_FUNC_STATUS_INTERRUPTED
671
+ BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
672
+ BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR = BT_FUNC_STATUS_ERROR
673
+ BTValueMapForeachEntryStatus = enum :bt_value_map_foreach_entry_status,
674
+ [ :BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK, BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK,
675
+ :BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPT, BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPT,
676
+ :BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR, BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR,
677
+ :BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR, BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR ]
678
+
679
+ attach_function :bt_value_map_foreach_entry,
680
+ [:bt_value_map_handle, :bt_value_map_foreach_entry_func, :pointer],
681
+ :bt_value_map_foreach_entry_status
682
+
683
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_OK = BT_FUNC_STATUS_OK
684
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_INTERRUPT = BT_FUNC_STATUS_INTERRUPTED
685
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
686
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_ERROR = BT_FUNC_STATUS_ERROR
687
+ BTValueMapForeachEntryConstFuncStatus = enum :bt_value_map_foreach_entry_const_func_status,
688
+ [ :BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_OK, BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_OK,
689
+ :BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_INTERRUPT, BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_INTERRUPT,
690
+ :BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_MEMORY_ERROR, BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_MEMORY_ERROR,
691
+ :BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_ERROR, BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_ERROR ]
692
+
693
+ callback :bt_value_map_foreach_entry_const_func,
694
+ [:string, :bt_value_handle, :pointer],
695
+ :bt_value_map_foreach_entry_const_func_status
696
+
697
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_OK = BT_FUNC_STATUS_OK
698
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_INTERRUPT = BT_FUNC_STATUS_INTERRUPTED
699
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
700
+ BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_ERROR = BT_FUNC_STATUS_ERROR
701
+ BTValueMapForeachEntryConstStatus = enum :bt_value_map_foreach_entry_const_status,
702
+ [ :BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_OK, BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_OK,
703
+ :BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_INTERRUPT, BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_INTERRUPT,
704
+ :BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_MEMORY_ERROR, BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_MEMORY_ERROR,
705
+ :BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_ERROR, BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_ERROR ]
706
+
707
+ attach_function :bt_value_map_foreach_entry_const,
708
+ [:bt_value_map_handle, :bt_value_map_foreach_entry_const_func,
709
+ :pointer],
710
+ :bt_value_map_foreach_entry_const_status
711
+
712
+ attach_function :bt_value_map_get_size,
713
+ [:bt_value_map_handle],
714
+ :uint64
715
+
716
+ attach_function :bt_value_map_has_entry,
717
+ [:bt_value_map_handle],
718
+ :bt_bool
719
+
720
+ BT_VALUE_MAP_EXTEND_STATUS_OK = BT_FUNC_STATUS_OK
721
+ BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
722
+ BTValueMapExtendStatus = enum :bt_value_map_extend_status,
723
+ [ :BT_VALUE_MAP_EXTEND_STATUS_OK, BT_VALUE_MAP_EXTEND_STATUS_OK,
724
+ :BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR, BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR ]
725
+
726
+ attach_function :bt_value_map_extend,
727
+ [:bt_value_map_handle, :bt_value_map_handle],
728
+ :bt_value_map_extend_status
729
+
730
+ class BTValue
731
+ MapForeachEntryFuncStatus = BTValueMapForeachEntryFuncStatus
732
+ MapForeachEntryStatus = BTValueMapForeachEntryStatus
733
+ MapForeachEntryConstFuncStatus = BTValueMapForeachEntryConstFuncStatus
734
+ MapForeachEntryConstStatus = BTValueMapForeachEntryConstStatus
735
+ MapExtendStatus = BTValueMapExtendStatus
736
+ class Map < BTValue
737
+ ForeachEntryFuncStatus = BTValueMapForeachEntryFuncStatus
738
+ ForeachEntryStatus = BTValueMapForeachEntryStatus
739
+ ForeachEntryConstFuncStatus = BTValueMapForeachEntryConstFuncStatus
740
+ ForeachEntryConstStatus = BTValueMapForeachEntryConstStatus
741
+ ExtendStatus = BTValueMapExtendStatus
742
+
743
+ def initialize(handle = nil, retain: true, auto_release: true)
744
+ if handle
745
+ super(handle, retain: retain, auto_release: auto_release)
746
+ else
747
+ handle = Babeltrace2.bt_value_map_create()
748
+ raise Babeltrace2.process_error if handle.null?
749
+ super(handle)
750
+ end
751
+ end
752
+
753
+ def insert_entry(key, value)
754
+ key = key.inspect if key.kind_of?(Symbol)
755
+ res = case value
756
+ when BTValue
757
+ Babeltrace2.bt_value_map_insert_entry(@handle, key, value)
758
+ when nil
759
+ Babeltrace2.bt_value_map_insert_entry(@handle, key, Babeltrace2.bt_value_null)
760
+ when true
761
+ Babeltrace2.bt_value_map_insert_bool_entry(@handle, key, BT_TRUE)
762
+ when false
763
+ Babeltrace2.bt_value_map_insert_bool_entry(@handle, key, BT_FALSE)
764
+ when ::Integer
765
+ if value > (1<<63) - 1
766
+ Babeltrace2.bt_value_map_insert_unsigned_integer_entry(@handle, key, value)
767
+ else
768
+ Babeltrace2.bt_value_map_insert_signed_integer_entry(@handle, key, value)
769
+ end
770
+ when ::Float
771
+ Babeltrace2.bt_value_map_insert_real_entry(@handle, key, value)
772
+ when ::String
773
+ Babeltrace2.bt_value_map_insert_string_entry(@handle, key, value)
774
+ when ::Array
775
+ ptr = FFI::MemoryPointer.new(:pointer)
776
+ res = Babeltrace2.bt_value_map_insert_empty_array_entry(@handle, key, ptr)
777
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
778
+ arr = BTValueArray.new(BTValueArrayHandle.new(ptr.read_pointer),
779
+ retain: false, auto_release: false)
780
+ value.each { |v| arr.append_element(v) }
781
+ :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
782
+ when ::Hash
783
+ ptr = FFI::MemoryPointer.new(:pointer)
784
+ res = Babeltrace2.bt_value_map_insert_empty_map_entry(@handle, key, ptr)
785
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
786
+ map = BTValueMap.new(BTValueMapHandle.new(ptr.read_pointer),
787
+ retain: false, auto_release: false)
788
+ value.each { |k, v| map.insert_entry(k, v) }
789
+ :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
790
+ else
791
+ raise TypeError, "unsupported value type"
792
+ end
793
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
794
+ self
795
+ end
796
+
797
+ def []=(key, value)
798
+ insert_entry(key, value)
799
+ value
800
+ end
801
+
802
+ def get_size
803
+ Babeltrace2.bt_value_map_get_size(@handle)
804
+ end
805
+ alias size get_size
806
+
807
+ def empty?
808
+ size == 0
809
+ end
810
+
811
+ def has_entry(key)
812
+ key = key.inspect if key.kind_of?(Symbol)
813
+ Babeltrace2.bt_value_map_has_entry(@handle, key) != BT_FALSE
814
+ end
815
+ alias include? has_entry
816
+
817
+ def get_entry_value(key)
818
+ key = key.inspect if key.kind_of?(Symbol)
819
+ handle = Babeltrace2.bt_value_map_borrow_entry_value(@handle, key)
820
+ return nil if handle.null?
821
+ BTValue.from_handle(handle)
822
+ end
823
+ alias [] get_entry_value
824
+
825
+ def each(&block)
826
+ if block_given?
827
+ block_wrapper = lambda { |key, handle, ptr|
828
+ begin
829
+ val = BTValue.from_handle(handle)
830
+ key = key[1..-1].to_sym if key[0] == ':'
831
+ block.call(key, val)
832
+ :BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK
833
+ rescue Exception => e
834
+ Babeltrace2.stack_ruby_error(e, source: nil)
835
+ :BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR
836
+ end
837
+ }
838
+ Babeltrace2.bt_value_map_foreach_entry(@handle, block_wrapper, nil)
839
+ else
840
+ to_enum(:each)
841
+ end
842
+ end
843
+
844
+ def value
845
+ val = {}
846
+ each { |k, v| val[k] = v.value }
847
+ val
848
+ end
849
+ alias to_h value
850
+
851
+ def extend!(other)
852
+ res = Babeltrace2.bt_value_map_extend(@handle, other)
853
+ raise Babeltrace2.process_error(res) if res != :BT_VALUE_COPY_STATUS_OK
854
+ self
855
+ end
856
+
857
+ def extend(other)
858
+ hsh = self.class.new
859
+ hsh.extend!(self)
860
+ hsh.extend!(other)
861
+ end
862
+
863
+ end
864
+ end
865
+ BTValueMap = BTValue::Map
866
+ BTValue::TYPE_MAP[:BT_VALUE_TYPE_MAP] = [
867
+ BTValueMapHandle,
868
+ BTValueMap ]
869
+ end