babeltrace2 0.1.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.
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,123 @@
1
+ module Babeltrace2
2
+ BT_FIELD_PATH_SCOPE_PACKET_CONTEXT = 0
3
+ BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT = 1
4
+ BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT = 2
5
+ BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD = 3
6
+ BTFieldPathScope = enum :bt_field_path_scope,
7
+ [ :BT_FIELD_PATH_SCOPE_PACKET_CONTEXT,
8
+ BT_FIELD_PATH_SCOPE_PACKET_CONTEXT,
9
+ :BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT,
10
+ BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT,
11
+ :BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT,
12
+ BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT,
13
+ :BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD,
14
+ BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD ]
15
+
16
+ attach_function :bt_field_path_get_root_scope,
17
+ [ :bt_field_path_handle ],
18
+ :bt_field_path_scope
19
+
20
+ attach_function :bt_field_path_get_item_count,
21
+ [ :bt_field_path_handle ],
22
+ :uint64
23
+
24
+ attach_function :bt_field_path_borrow_item_by_index_const,
25
+ [ :bt_field_path_handle, :uint64 ],
26
+ :bt_field_path_item_handle
27
+
28
+ attach_function :bt_field_path_get_ref,
29
+ [ :bt_field_path_handle ],
30
+ :void
31
+
32
+ attach_function :bt_field_path_put_ref,
33
+ [ :bt_field_path_handle ],
34
+ :void
35
+
36
+ class BTFieldPath < BTSharedObject
37
+ Scope = BTFieldPathScope
38
+ @get_ref = :bt_field_path_get_ref
39
+ @put_ref = :bt_field_path_put_ref
40
+ def initialize(handle, retain: true, auto_release: true)
41
+ super(handle, retain: retain, auto_release: auto_release)
42
+ end
43
+
44
+ def get_root_scope
45
+ Babeltrace2.bt_field_path_get_root_scope(@handle)
46
+ end
47
+ alias root_scope get_root_scope
48
+
49
+ def get_item_count
50
+ @item_count ||= Babeltrace2.bt_field_path_get_item_count(@handle)
51
+ end
52
+ alias item_count get_item_count
53
+ alias size get_item_count
54
+
55
+ def get_item_by_index(index)
56
+ index = get_item_count + index if index < 0
57
+ return nil if index >= get_item_count || index < 0
58
+ BTFieldPathItem.new(
59
+ Babeltrace2.bt_field_path_borrow_item_by_index_const(@handle, index))
60
+ end
61
+ alias [] get_item_by_index
62
+
63
+ def each
64
+ if block_given?
65
+ get_item_count.times { |i|
66
+ yield get_item_by_index(i)
67
+ }
68
+ else
69
+ to_enum(:each)
70
+ end
71
+ end
72
+
73
+ def to_s
74
+ path = ""
75
+ path << root_scope.to_s.sub("BT_FIELD_PATH_SCOPE_","")
76
+ each { |e|
77
+ case e.type
78
+ when :BT_FIELD_PATH_ITEM_TYPE_INDEX
79
+ path << "[#{e.index}]"
80
+ when :BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
81
+ path << "->"
82
+ when :BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT
83
+ path << "=>"
84
+ end
85
+ }
86
+ path
87
+ end
88
+ end
89
+
90
+ BT_FIELD_PATH_ITEM_TYPE_INDEX = 1 << 0
91
+ BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT = 1 << 1
92
+ BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT = 1 << 2
93
+ BTFieldPathItemType = enum :bt_field_path_item_type,
94
+ [ :BT_FIELD_PATH_ITEM_TYPE_INDEX,
95
+ BT_FIELD_PATH_ITEM_TYPE_INDEX,
96
+ :BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT,
97
+ BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT,
98
+ :BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT,
99
+ BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT ]
100
+
101
+ attach_function :bt_field_path_item_get_type,
102
+ [ :bt_field_path_item_handle ],
103
+ :bt_field_path_item_type
104
+
105
+ attach_function :bt_field_path_item_index_get_index,
106
+ [ :bt_field_path_item_handle ],
107
+ :uint64
108
+
109
+ class BTFieldPath::Item < BTObject
110
+ Type = BTFieldPathItemType
111
+
112
+ def get_type
113
+ Babeltrace2.bt_field_path_item_get_type(@handle)
114
+ end
115
+ alias type get_type
116
+
117
+ def get_index
118
+ Babeltrace2.bt_field_path_item_index_get_index(@handle)
119
+ end
120
+ alias index get_index
121
+ end
122
+ BTFieldPathItem = BTFieldPath::Item
123
+ end
@@ -0,0 +1,871 @@
1
+ module Babeltrace2
2
+ attach_function :bt_field_get_class_type,
3
+ [ :bt_field_handle ],
4
+ :bt_field_class_type
5
+
6
+ attach_function :bt_field_borrow_class,
7
+ [ :bt_field_handle ],
8
+ :bt_field_class_handle
9
+
10
+ attach_function :bt_field_borrow_class_const,
11
+ [ :bt_field_handle ],
12
+ :bt_field_class_handle
13
+
14
+ class BTField < BTObject
15
+ TYPE_MAP = {}
16
+
17
+ def self.from_handle(handle)
18
+ clss = TYPE_MAP[Babeltrace2.bt_field_get_class_type(handle)]
19
+ raise "unsupported field class type" unless clss
20
+ handle = clss[0].new(handle)
21
+ clss[1].new(handle)
22
+ end
23
+
24
+ def get_class_type
25
+ Babeltrace2.bt_field_get_class_type(@handle)
26
+ end
27
+ alias class_type get_class_type
28
+
29
+ def get_class
30
+ @class ||= BTFieldClass.from_handle(Babeltrace2.bt_field_borrow_class(@handle))
31
+ end
32
+
33
+ def to_s
34
+ value.to_s
35
+ end
36
+ end
37
+
38
+ attach_function :bt_field_bool_set_value,
39
+ [ :bt_field_bool_handle, :bt_bool ],
40
+ :void
41
+
42
+ attach_function :bt_field_bool_get_value,
43
+ [ :bt_field_bool_handle ],
44
+ :bt_bool
45
+
46
+ class BTField::Bool < BTField
47
+ def set_value(value)
48
+ Babeltrace2.bt_field_bool_set_value(@handle, value ? BT_TRUE : BT_FALSE)
49
+ self
50
+ end
51
+
52
+ def value=(value)
53
+ set_value(value)
54
+ value
55
+ end
56
+
57
+ def get_value
58
+ Babeltrace2.bt_field_bool_get_value(@handle) != BT_FALSE
59
+ end
60
+ alias value get_value
61
+ end
62
+ BTFieldBool = BTField::Bool
63
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_BOOL] = [
64
+ BTFieldBoolHandle,
65
+ BTFieldBool ]
66
+
67
+ attach_function :bt_field_bit_array_set_value_as_integer,
68
+ [ :bt_field_bit_array_handle, :uint64 ],
69
+ :void
70
+
71
+ attach_function :bt_field_bit_array_get_value_as_integer,
72
+ [ :bt_field_bit_array_handle ],
73
+ :uint64
74
+
75
+ class BTField::BitArray < BTField
76
+ def set_value_as_integer(bits)
77
+ Babeltrace2.bt_field_bit_array_set_value_as_integer(@handle, bits)
78
+ self
79
+ end
80
+
81
+ def value_as_integer=(bits)
82
+ set_value_as_integer(bits)
83
+ bits
84
+ end
85
+
86
+ def get_value_as_integer
87
+ Babeltrace2.bt_field_bit_array_get_value_as_integer(@handle)
88
+ end
89
+ alias value_as_integer get_value_as_integer
90
+
91
+ def get_length
92
+ @length ||= get_class.get_length
93
+ end
94
+ alias length get_length
95
+
96
+ def [](position)
97
+ length = get_length
98
+ position += length if position < 0
99
+ raise "invalid position" if position >= length || position < 0
100
+ get_value_as_integer[position] != 0
101
+ end
102
+
103
+ def []=(position, bool)
104
+ length = get_length
105
+ position += length if position < 0
106
+ raise "invalid position" if position >= length || position < 0
107
+ v = get_value_as_integer
108
+ if bool then v |= (1 << position) else v &= ~(1 << position) end
109
+ set_value_as_integer(v)
110
+ bool
111
+ end
112
+
113
+ def each
114
+ if block_given?
115
+ length.times { |i|
116
+ yield self[i]
117
+ }
118
+ else
119
+ to_enum(:each)
120
+ end
121
+ end
122
+
123
+ def value
124
+ get_length.times.collect { |i| self[i] }
125
+ end
126
+
127
+ def to_s
128
+ s = "["
129
+ s << get_length.times.collect { |i| self[i] }.join(", ")
130
+ s << "]"
131
+ end
132
+ end
133
+ BTFieldBitArray = BTField::BitArray
134
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_BIT_ARRAY] = [
135
+ BTFieldBitArrayHandle,
136
+ BTFieldBitArray ]
137
+
138
+ class BTField::Integer < BTField
139
+ def get_field_value_range
140
+ @field_value_range ||= get_class.get_field_value_range
141
+ end
142
+ alias field_value_range get_field_value_range
143
+
144
+ def get_preferred_display_base
145
+ @preferred_display_base ||= get_class.get_preferred_display_base
146
+ end
147
+ alias preferred_display_base get_preferred_display_base
148
+ end
149
+ BTFieldInteger = BTField::Integer
150
+
151
+ attach_function :bt_field_integer_unsigned_set_value,
152
+ [ :bt_field_integer_unsigned_handle, :uint64 ],
153
+ :void
154
+
155
+ attach_function :bt_field_integer_unsigned_get_value,
156
+ [ :bt_field_integer_unsigned_handle ],
157
+ :uint64
158
+
159
+ class BTField::Integer::Unsigned < BTField::Integer
160
+ def set_value(value)
161
+ raise "invalid range" if (1 << get_field_value_range) - 1 < value || value < 0
162
+ Babeltrace2.bt_field_integer_unsigned_set_value(@handle, value)
163
+ self
164
+ end
165
+
166
+ def value=(value)
167
+ set_value(value)
168
+ value
169
+ end
170
+
171
+ def get_value
172
+ Babeltrace2.bt_field_integer_unsigned_get_value(@handle)
173
+ end
174
+ alias value get_value
175
+
176
+ def to_s
177
+ v = get_value
178
+ case preferred_display_base
179
+ when :BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
180
+ "0b#{v.to_s(2)}"
181
+ when :BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
182
+ "0#{v.to_s(8)}"
183
+ when :BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
184
+ v.to_s
185
+ when :BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
186
+ "0x#{v.to_s(16)}"
187
+ else
188
+ raise "invalid preffered display base"
189
+ end
190
+ end
191
+ end
192
+ BTFieldIntegerUnsigned = BTField::Integer::Unsigned
193
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER] = [
194
+ BTFieldIntegerUnsignedHandle,
195
+ BTFieldIntegerUnsigned ]
196
+
197
+ attach_function :bt_field_integer_signed_set_value,
198
+ [ :bt_field_integer_signed_handle, :int64 ],
199
+ :void
200
+
201
+ attach_function :bt_field_integer_signed_get_value,
202
+ [ :bt_field_integer_signed_handle ],
203
+ :int64
204
+
205
+ class BTField::Integer::Signed < BTField::Integer
206
+ def set_value(value)
207
+ range = get_field_value_range
208
+ raise "invalid range" if (1 << (range-1)) - 1 < value || value < -(1 << (range-1))
209
+ Babeltrace2.bt_field_integer_signed_set_value(@handle, value)
210
+ self
211
+ end
212
+
213
+ def value=(value)
214
+ set_value(value)
215
+ value
216
+ end
217
+
218
+ def get_value
219
+ Babeltrace2.bt_field_integer_signed_get_value(@handle)
220
+ end
221
+ alias value get_value
222
+
223
+ def get_twos_complement(v)
224
+ (((1 << get_field_value_range) -1) ^ -v) + 1
225
+ end
226
+ private :get_twos_complement
227
+
228
+ def to_s
229
+ v = get_value
230
+ case preferred_display_base
231
+ when :BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
232
+ "0b#{(v < 0 ? get_twos_complement(v) : v).to_s(2)}"
233
+ when :BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
234
+ "0#{(v < 0 ? get_twos_complement(v) : v).to_s(8)}"
235
+ when :BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
236
+ v.to_s
237
+ when :BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
238
+ "0x#{(v < 0 ? get_twos_complement(v) : v).to_s(16)}"
239
+ else
240
+ raise "invalid preffered display base"
241
+ end
242
+ end
243
+ end
244
+ BTFieldIntegerSigned = BTField::Integer::Signed
245
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_SIGNED_INTEGER] = [
246
+ BTFieldIntegerSignedHandle,
247
+ BTFieldIntegerSigned ]
248
+
249
+ BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_OK = BT_FUNC_STATUS_OK
250
+ BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
251
+ BTFieldEnumerationGetMappingLabelsStatus =
252
+ enum :bt_field_enumeration_get_mapping_labels_status,
253
+ [ :BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_OK,
254
+ BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_OK,
255
+ :BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR,
256
+ BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR ]
257
+
258
+ module BTField::Enumeration
259
+ GetMappingLabelsStatus = BTFieldEnumerationGetMappingLabelsStatus
260
+
261
+ def to_s
262
+ s = "(#{value}) ["
263
+ s << mapping_labels.collect { |l| l.kind_of?(Symbol) ? l.inspect : l } .join(", ")
264
+ s << "]"
265
+ end
266
+ end
267
+ BTFieldEnumeration = BTField::Enumeration
268
+
269
+ attach_function :bt_field_enumeration_unsigned_get_mapping_labels,
270
+ [ :bt_field_enumeration_unsigned_handle,
271
+ :pointer, :pointer ],
272
+ :bt_field_enumeration_get_mapping_labels_status
273
+
274
+ class BTField::Enumeration::Unsigned < BTField::Integer::Unsigned
275
+ include BTField::Enumeration
276
+ def get_mapping_labels
277
+ ptr1 = FFI::MemoryPointer.new(:pointer)
278
+ ptr2 = FFI::MemoryPointer.new(:uint64)
279
+ res = Babeltrace2.bt_field_enumeration_unsigned_get_mapping_labels(
280
+ @handle, ptr1, ptr2)
281
+ raise Babeltrace2.process_error(res) if res != :BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_OK
282
+ count = ptr2.read_uint64
283
+ return [] if count == 0
284
+ ptr1 = ptr1.read_pointer
285
+ ptr1.read_array_of_pointer(count).collect.collect { |v|
286
+ v = v.read_string
287
+ v[0] == ':' ? v[1..-1].to_sym : v
288
+ }
289
+ end
290
+ alias mapping_labels get_mapping_labels
291
+ end
292
+ BTFieldEnumerationUnsigned = BTField::Enumeration::Unsigned
293
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION] = [
294
+ BTFieldEnumerationUnsignedHandle,
295
+ BTFieldEnumerationUnsigned ]
296
+
297
+ attach_function :bt_field_enumeration_signed_get_mapping_labels,
298
+ [ :bt_field_enumeration_signed_handle,
299
+ :pointer, :pointer ],
300
+ :bt_field_enumeration_get_mapping_labels_status
301
+
302
+ class BTField::Enumeration::Signed < BTField::Integer::Signed
303
+ include BTField::Enumeration
304
+ def get_mapping_labels
305
+ ptr1 = FFI::MemoryPointer.new(:pointer)
306
+ ptr2 = FFI::MemoryPointer.new(:uint64)
307
+ res = Babeltrace2.bt_field_enumeration_signed_get_mapping_labels(
308
+ @handle, ptr1, ptr2)
309
+ raise Babeltrace2.process_error(res) if res != :BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_OK
310
+ count = ptr2.read_uint64
311
+ return [] if count == 0
312
+ ptr1 = ptr1.read_pointer
313
+ ptr1.read_array_of_pointer(count).collect.collect { |v|
314
+ v = v.read_string
315
+ v[0] == ':' ? v[1..-1].to_sym : v
316
+ }
317
+ end
318
+ alias mapping_labels get_mapping_labels
319
+ end
320
+ BTFieldEnumerationSigned = BTField::Enumeration::Signed
321
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION] = [
322
+ BTFieldEnumerationSignedHandle,
323
+ BTFieldEnumerationSigned ]
324
+
325
+ class BTField::Real < BTField
326
+ end
327
+ BTFieldReal = BTField::Real
328
+
329
+ attach_function :bt_field_real_single_precision_set_value,
330
+ [ :bt_field_real_single_precision_handle, :float ],
331
+ :void
332
+
333
+ attach_function :bt_field_real_single_precision_get_value,
334
+ [ :bt_field_real_single_precision_handle ],
335
+ :float
336
+
337
+ class BTField::Real::SinglePrecision < BTField::Real
338
+ def set_value(value)
339
+ Babeltrace2.bt_field_real_single_precision_set_value(@handle, value)
340
+ self
341
+ end
342
+
343
+ def value=(value)
344
+ set_value(value)
345
+ value
346
+ end
347
+
348
+ def get_value
349
+ Babeltrace2.bt_field_real_single_precision_get_value(@handle)
350
+ end
351
+ alias value get_value
352
+ end
353
+ BTFieldRealSinglePrecision = BTField::Real::SinglePrecision
354
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL] = [
355
+ BTFieldRealSinglePrecisionHandle,
356
+ BTFieldRealSinglePrecision ]
357
+
358
+ attach_function :bt_field_real_double_precision_set_value,
359
+ [ :bt_field_real_double_precision_handle, :double ],
360
+ :void
361
+
362
+ attach_function :bt_field_real_double_precision_get_value,
363
+ [ :bt_field_real_double_precision_handle ],
364
+ :double
365
+
366
+ class BTField::Real::DoublePrecision < BTField::Real
367
+ def set_value(value)
368
+ Babeltrace2.bt_field_real_double_precision_set_value(@handle, value)
369
+ self
370
+ end
371
+
372
+ def value=(value)
373
+ set_value(value)
374
+ value
375
+ end
376
+
377
+ def get_value
378
+ Babeltrace2.bt_field_real_double_precision_get_value(@handle)
379
+ end
380
+ alias value get_value
381
+ end
382
+ BTFieldRealDoublePrecision = BTField::Real::DoublePrecision
383
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL] = [
384
+ BTFieldRealDoublePrecisionHandle,
385
+ BTFieldRealDoublePrecision ]
386
+
387
+ BT_FIELD_STRING_SET_VALUE_STATUS_OK = BT_FUNC_STATUS_OK
388
+ BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
389
+ BTFieldStringSetValueStatus = enum :bt_field_string_set_value_status,
390
+ [ :BT_FIELD_STRING_SET_VALUE_STATUS_OK,
391
+ BT_FIELD_STRING_SET_VALUE_STATUS_OK,
392
+ :BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR,
393
+ BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR ]
394
+
395
+ attach_function :bt_field_string_set_value,
396
+ [ :bt_field_string_handle, :string ],
397
+ :bt_field_string_set_value_status
398
+
399
+ attach_function :bt_field_string_get_length,
400
+ [ :bt_field_string_handle ],
401
+ :uint64
402
+
403
+ attach_function :bt_field_string_get_value,
404
+ [ :bt_field_string_handle ],
405
+ :string
406
+
407
+ attach_function :bt_field_string_get_value_ptr, :bt_field_string_get_value,
408
+ [ :bt_field_string_handle ],
409
+ :pointer
410
+
411
+ BT_FIELD_STRING_APPEND_STATUS_OK = BT_FUNC_STATUS_OK
412
+ BT_FIELD_STRING_APPEND_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
413
+ BTFieldStringAppendStatus = enum :bt_field_string_append_status,
414
+ [ :BT_FIELD_STRING_APPEND_STATUS_OK,
415
+ BT_FIELD_STRING_APPEND_STATUS_OK,
416
+ :BT_FIELD_STRING_APPEND_STATUS_MEMORY_ERROR,
417
+ BT_FIELD_STRING_APPEND_STATUS_MEMORY_ERROR ]
418
+
419
+ attach_function :bt_field_string_append,
420
+ [ :bt_field_string_handle, :string ],
421
+ :bt_field_string_append_status
422
+
423
+ attach_function :bt_field_string_append_with_length,
424
+ [ :bt_field_string_handle, :string, :uint64 ],
425
+ :bt_field_string_append_status
426
+
427
+ attach_function :bt_field_string_clear,
428
+ [ :bt_field_string_handle ],
429
+ :void
430
+
431
+ class BTField::String < BTField
432
+ SetValueStatus = BTFieldStringSetValueStatus
433
+ AppendStatus = BTFieldStringAppendStatus
434
+ def set_value(value)
435
+ res = Babeltrace2.bt_field_string_set_value(@handle, value)
436
+ raise Babeltrace2.process_error(res) if res != :BT_FIELD_STRING_SET_VALUE_STATUS_OK
437
+ self
438
+ end
439
+
440
+ def value=(value)
441
+ set_value(value)
442
+ value
443
+ end
444
+
445
+ def get_length
446
+ Babeltrace2.bt_field_string_get_length(@handle)
447
+ end
448
+ alias length get_length
449
+
450
+ def get_value
451
+ Babeltrace2.bt_field_string_get_value_ptr(@handle).read_string(length)
452
+ end
453
+ alias value get_value
454
+ alias to_s get_value
455
+
456
+ def get_raw_value
457
+ Babeltrace2.bt_field_string_get_value_ptr(@handle).slice(0, get_length)
458
+ end
459
+ alias raw_value get_raw_value
460
+
461
+ def append(value, length: nil)
462
+ res = if length
463
+ Babeltrace2.bt_field_string_append_with_length(@handle, value, length)
464
+ else
465
+ Babeltrace2.bt_field_string_append(@handle, value)
466
+ end
467
+ raise Babeltrace2.process_error(res) if res != :BT_FIELD_STRING_APPEND_STATUS_OK
468
+ self
469
+ end
470
+
471
+ def <<(value)
472
+ append(value)
473
+ end
474
+
475
+ def clear
476
+ Babeltrace2.bt_field_string_clear(@handle)
477
+ self
478
+ end
479
+ alias clear! clear
480
+ end
481
+ BTFieldString = BTField::String
482
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_STRING] = [
483
+ BTFieldStringHandle,
484
+ BTFieldString ]
485
+
486
+ attach_function :bt_field_array_get_length,
487
+ [ :bt_field_array_handle ],
488
+ :uint64
489
+
490
+ attach_function :bt_field_array_borrow_element_field_by_index,
491
+ [ :bt_field_array_handle, :uint64 ],
492
+ :bt_field_handle
493
+
494
+ attach_function :bt_field_array_borrow_element_field_by_index_const,
495
+ [ :bt_field_array_handle, :uint64 ],
496
+ :bt_field_handle
497
+
498
+ class BTField::Array < BTField
499
+ def get_length
500
+ Babeltrace2.bt_field_array_get_length(@handle)
501
+ end
502
+ alias length get_length
503
+
504
+ def get_element_field_by_index(index)
505
+ length = get_length
506
+ index += length if index < 0
507
+ return nil if index >= length || index < 0
508
+ BTField.from_handle(
509
+ Babeltrace2.bt_field_array_borrow_element_field_by_index(@handle, index))
510
+ end
511
+ alias [] get_element_field_by_index
512
+
513
+ def each
514
+ if block_given?
515
+ get_length.times { |index|
516
+ yield get_element_field_by_index(index)
517
+ }
518
+ else
519
+ to_enum(:each)
520
+ end
521
+ end
522
+
523
+ def value
524
+ each.collect { |e| e.value }
525
+ end
526
+
527
+ def to_s
528
+ s = "["
529
+ s << each.collect { |e| e.to_s }.join(", ")
530
+ s << "]"
531
+ end
532
+ end
533
+ BTFieldArray = BTField::Array
534
+
535
+ class BTField::Array::Static < BTField::Array
536
+ def get_length
537
+ @length ||= super
538
+ end
539
+ end
540
+ BTFieldArrayStatic = BTField::Array::Static
541
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_STATIC_ARRAY] = [
542
+ BTFieldArrayStaticHandle,
543
+ BTFieldArrayStatic ]
544
+
545
+ BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_OK = BT_FUNC_STATUS_OK
546
+ BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
547
+ BTFieldArrayDynamicSetLengthStatus =
548
+ enum :bt_field_array_dynamic_set_length_status,
549
+ [ :BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_OK,
550
+ BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_OK,
551
+ :BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR,
552
+ BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR ]
553
+
554
+ attach_function :bt_field_array_dynamic_set_length,
555
+ [ :bt_field_array_dynamic_handle, :uint64 ],
556
+ :bt_field_array_dynamic_set_length_status
557
+
558
+ class BTField::Array::Dynamic < BTField::Array
559
+ module WithLengthField
560
+ end
561
+ SetLengthStatus = BTFieldArrayDynamicSetLengthStatus
562
+
563
+ def initialize(handle)
564
+ super
565
+ extend(BTFieldArrayDynamicWithLengthField) if class_type ==:BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
566
+ end
567
+
568
+ def set_length(length)
569
+ res = Babeltrace2.bt_field_array_dynamic_set_length(@handle, length)
570
+ raise Babeltrace2.process_error(res) if res != :BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_OK
571
+ self
572
+ end
573
+
574
+ def length=(length)
575
+ set_length(length)
576
+ length
577
+ end
578
+ end
579
+ BTFieldArrayDynamicWithLengthField = BTField::Array::Dynamic::WithLengthField
580
+ BTFieldArrayDynamic = BTField::Array::Dynamic
581
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD] = [
582
+ BTFieldArrayDynamicHandle,
583
+ BTFieldArrayDynamic ]
584
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD] = [
585
+ BTFieldArrayDynamicHandle,
586
+ BTFieldArrayDynamic ]
587
+
588
+ attach_function :bt_field_structure_borrow_member_field_by_index,
589
+ [ :bt_field_structure_handle, :uint64 ],
590
+ :bt_field_handle
591
+
592
+ attach_function :bt_field_structure_borrow_member_field_by_index_const,
593
+ [ :bt_field_structure_handle, :uint64 ],
594
+ :bt_field_handle
595
+
596
+ attach_function :bt_field_structure_borrow_member_field_by_name,
597
+ [ :bt_field_structure_handle, :string ],
598
+ :bt_field_handle
599
+
600
+ attach_function :bt_field_structure_borrow_member_field_by_name_const,
601
+ [ :bt_field_structure_handle, :string ],
602
+ :bt_field_handle
603
+
604
+ class BTField::Structure < BTField
605
+ def get_member_count
606
+ @member_count ||= get_class.get_member_count
607
+ end
608
+ alias member_count get_member_count
609
+
610
+ def get_member_field_by_index(index)
611
+ count = get_member_count
612
+ index += count if index < 0
613
+ return nil if index >= count || index < 0
614
+ BTField.from_handle(
615
+ Babeltrace2.bt_field_structure_borrow_member_field_by_index(@handle, index))
616
+ end
617
+
618
+ def get_member_field_by_name(name)
619
+ name = name.inspect if name.kind_of?(Symbol)
620
+ handle = Babeltrace2.bt_field_structure_borrow_member_field_by_name(@handle, name)
621
+ return nil if handle.null?
622
+ BTField.from_handle(handle)
623
+ end
624
+
625
+ def get_member_field(member_field)
626
+ case member_field
627
+ when ::String, Symbol
628
+ get_member_field_by_name(member_field)
629
+ when ::Integer
630
+ get_member_field_by_index(member_field)
631
+ else
632
+ raise TypeError, "wrong type for member field query"
633
+ end
634
+ end
635
+ alias [] get_member_field
636
+
637
+ def each
638
+ if block_given?
639
+ get_member_count.times { |i|
640
+ yield get_member_field_by_index(i)
641
+ }
642
+ else
643
+ to_enum(:each)
644
+ end
645
+ end
646
+
647
+ def value
648
+ v = {}
649
+ klass = get_class
650
+ get_member_count.times { |i|
651
+ v[klass.get_member_by_index(i).name] = get_member_field_by_index(i).value
652
+ }
653
+ v
654
+ end
655
+
656
+ def to_s
657
+ s = "{"
658
+ klass = get_class
659
+ s << get_member_count.times.collect { |i|
660
+ name = klass.get_member_by_index(i).name
661
+ name = name.inspect if name.kind_of?(Symbol)
662
+ "#{name}: #{get_member_field_by_index(i)}"
663
+ }.join(", ")
664
+ s << "}"
665
+ end
666
+ end
667
+ BTFieldStructure = BTField::Structure
668
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_STRUCTURE] = [
669
+ BTFieldStructureHandle,
670
+ BTFieldStructure ]
671
+
672
+ attach_function :bt_field_option_set_has_field,
673
+ [ :bt_field_option_handle, :bt_bool ],
674
+ :void
675
+
676
+ attach_function :bt_field_option_borrow_field,
677
+ [ :bt_field_option_handle ],
678
+ :bt_field_handle
679
+
680
+ attach_function :bt_field_option_borrow_field_const,
681
+ [ :bt_field_option_handle ],
682
+ :bt_field_handle
683
+
684
+ class BTField::Option < BTField
685
+ def set_has_field(has_field)
686
+ Babeltrace2.bt_field_option_set_has_field(@handle, has_field ? BT_TRUE : BT_FALSE)
687
+ self
688
+ end
689
+
690
+ def has_field=(has_field)
691
+ set_has_field(has_field)
692
+ has_field
693
+ end
694
+
695
+ def get_field
696
+ handle = Babeltrace2.bt_field_option_borrow_field(@handle)
697
+ return nil if handle.null?
698
+ BTField.from_handle(handle)
699
+ end
700
+ alias field get_field
701
+
702
+ def value
703
+ f = get_field
704
+ return nil unless f
705
+ f.value
706
+ end
707
+
708
+ def to_s
709
+ get_field.to_s
710
+ end
711
+ end
712
+ BTFieldOption = BTField::Option
713
+
714
+ class BTField::Option::WithoutSelectorField < BTField::Option
715
+ end
716
+ BTFieldOptionWithoutSelectorField = BTField::Option::WithoutSelectorField
717
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD] = [
718
+ BTFieldOptionWithoutSelectorFieldHandle,
719
+ BTFieldOptionWithoutSelectorField ]
720
+
721
+ class BTField::Option::WithSelectorField < BTField::Option
722
+ end
723
+ BTFieldOptionWithSelectorField = BTField::Option::WithSelectorField
724
+
725
+ class BTField::Option::WithSelectorField::Bool < BTField::Option::WithSelectorField
726
+ end
727
+ BTFieldOptionWithSelectorFieldBool = BTField::Option::WithSelectorField::Bool
728
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD] = [
729
+ BTFieldOptionWithSelectorFieldBoolHandle,
730
+ BTFieldOptionWithSelectorFieldBool ]
731
+
732
+ class BTField::Option::WithSelectorField::IntegerUnsigned < BTField::Option::WithSelectorField
733
+ end
734
+ BTFieldOptionWithSelectorFieldIntegerUnsigned = BTField::Option::WithSelectorField::IntegerUnsigned
735
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD] = [
736
+ BTFieldOptionWithSelectorFieldIntegerUnsignedHandle,
737
+ BTFieldOptionWithSelectorFieldIntegerUnsigned ]
738
+
739
+ class BTField::Option::WithSelectorField::IntegerSigned < BTField::Option::WithSelectorField
740
+ end
741
+ BTFieldOptionWithSelectorFieldIntegerSigned = BTField::Option::WithSelectorField::IntegerSigned
742
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD] = [
743
+ BTFieldOptionWithSelectorFieldIntegerSignedHandle,
744
+ BTFieldOptionWithSelectorFieldIntegerSigned ]
745
+
746
+ BT_FIELD_VARIANT_SELECT_OPTION_STATUS_OK = BT_FUNC_STATUS_OK
747
+ BTFieldVariantSelectOptionByIndexStatus =
748
+ enum :bt_field_variant_select_option_by_index_status,
749
+ [ :BT_FIELD_VARIANT_SELECT_OPTION_STATUS_OK,
750
+ BT_FIELD_VARIANT_SELECT_OPTION_STATUS_OK ]
751
+
752
+ attach_function :bt_field_variant_select_option_by_index,
753
+ [ :bt_field_variant_handle, :uint64 ],
754
+ :bt_field_variant_select_option_by_index_status
755
+
756
+ attach_function :bt_field_variant_borrow_selected_option_field,
757
+ [ :bt_field_variant_handle ],
758
+ :bt_field_handle
759
+
760
+ attach_function :bt_field_variant_borrow_selected_option_field_const,
761
+ [ :bt_field_variant_handle ],
762
+ :bt_field_handle
763
+
764
+ attach_function :bt_field_variant_get_selected_option_index,
765
+ [ :bt_field_variant_handle ],
766
+ :uint64
767
+
768
+ attach_function :bt_field_variant_borrow_selected_option_class_const,
769
+ [ :bt_field_variant_handle ],
770
+ :bt_field_class_variant_option_handle
771
+
772
+ class BTField::Variant < BTField
773
+ def get_option_count
774
+ @option_count ||= get_class.get_option_count
775
+ end
776
+ alias option_count get_option_count
777
+
778
+ def select_option_by_index(index)
779
+ count = get_option_count
780
+ index += count if index < 0
781
+ raise "invalid index" if index >= count || index < 0
782
+ res = Babeltrace2.bt_field_variant_select_option_by_index(@handle, index)
783
+ raise Babeltrace2.process_error(res) if res != :BT_FIELD_VARIANT_SELECT_OPTION_STATUS_OK
784
+ self
785
+ end
786
+
787
+ def get_selected_option_field
788
+ handle = Babeltrace2.bt_field_variant_borrow_selected_option_field(@handle)
789
+ return nil if handle.null?
790
+ BTField.from_handle(handle)
791
+ end
792
+ alias selected_option_field get_selected_option_field
793
+
794
+ def get_selected_option_index
795
+ Babeltrace2.bt_field_variant_get_selected_option_index(@handle)
796
+ end
797
+ alias selected_option_index get_selected_option_index
798
+
799
+ def get_selected_option_class
800
+ handle = Babeltrace2.bt_field_variant_borrow_selected_option_class_const(@handle)
801
+ return nil if handle.null?
802
+ BTFieldClassVariantOption.new(handle)
803
+ end
804
+ alias selected_option_class get_selected_option_class
805
+
806
+ def value
807
+ f = get_selected_option_field
808
+ return nil unless f
809
+ { selected_option_class.name => f.value }
810
+ end
811
+
812
+ def to_s
813
+ s = "{"
814
+ opt = get_selected_option_field
815
+ if opt
816
+ name = selected_option_class.name
817
+ name = name.inspect if name.kind_of?(Symbol)
818
+ s << "#{name}: #{opt.to_s}"
819
+ end
820
+ s << "}"
821
+ end
822
+ end
823
+ BTFieldVariant = BTField::Variant
824
+
825
+ class BTField::Variant::WithoutSelectorField < BTField::Variant
826
+ end
827
+ BTFieldVariantWithoutSelectorField = BTField::Variant::WithoutSelectorField
828
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD] = [
829
+ BTFieldVariantWithoutSelectorFieldHandle,
830
+ BTFieldVariantWithoutSelectorField ]
831
+
832
+ class BTField::Variant::WithSelectorField < BTField::Variant
833
+ end
834
+ BTFieldVariantWithSelectorField = BTField::Variant::WithSelectorField
835
+
836
+ attach_function :bt_field_variant_with_selector_field_integer_unsigned_borrow_selected_option_class_const,
837
+ [ :bt_field_variant_with_selector_field_integer_unsigned_handle ],
838
+ :bt_field_class_variant_with_selector_field_integer_unsigned_option_handle
839
+
840
+ class BTField::Variant::WithSelectorField::IntegerUnsigned <
841
+ BTField::Variant::WithSelectorField
842
+ def get_selected_option_class
843
+ handle = Babeltrace2.bt_field_variant_with_selector_field_integer_unsigned_borrow_selected_option_class_const(@handle)
844
+ return nil if handle.null?
845
+ BTFieldClassVariantWithSelectorFieldIntegerUnsignedOption.new(handle)
846
+ end
847
+ alias selected_option_class get_selected_option_class
848
+ end
849
+ BTFieldVariantWithSelectorFieldIntegerUnsigned = BTField::Variant::WithSelectorField::IntegerUnsigned
850
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD] = [
851
+ BTFieldVariantWithSelectorFieldIntegerUnsignedHandle,
852
+ BTFieldVariantWithSelectorFieldIntegerUnsigned ]
853
+
854
+ attach_function :bt_field_variant_with_selector_field_integer_signed_borrow_selected_option_class_const,
855
+ [ :bt_field_variant_with_selector_field_integer_signed_handle ],
856
+ :bt_field_class_variant_with_selector_field_integer_signed_option_handle
857
+
858
+ class BTField::Variant::WithSelectorField::IntegerSigned <
859
+ BTField::Variant::WithSelectorField
860
+ def get_selected_option_class
861
+ handle = Babeltrace2.bt_field_variant_with_selector_field_integer_signed_borrow_selected_option_class_const(@handle)
862
+ return nil if handle.null?
863
+ BTFieldClassVariantWithSelectorFieldIntegerSignedOption.new(handle)
864
+ end
865
+ alias selected_option_class get_selected_option_class
866
+ end
867
+ BTFieldVariantWithSelectorFieldIntegerSigned = BTField::Variant::WithSelectorField::IntegerSigned
868
+ BTField::TYPE_MAP[:BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD] = [
869
+ BTFieldVariantWithSelectorFieldIntegerSignedHandle,
870
+ BTFieldVariantWithSelectorFieldIntegerSigned ]
871
+ end