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,335 @@
1
+ require 'digest'
2
+
3
+ module Babeltrace2
4
+ class UserPlugin
5
+ attr_reader :name
6
+ attr_reader :author
7
+ attr_reader :description
8
+ attr_reader :license
9
+ attr_accessor :path
10
+ attr_reader :major
11
+ attr_reader :minor
12
+ attr_reader :patch
13
+ attr_reader :version_extra
14
+
15
+ def initialize(name:, author: nil, description: nil, license: nil, path: nil,
16
+ major: 0, minor: 0, patch: 0, version_extra: nil)
17
+ @name = name
18
+ @author = author
19
+ @description = description
20
+ @license = license
21
+ @path = path
22
+ @major = major.to_i
23
+ @minor = minor.to_i
24
+ @patch = patch.to_i
25
+ @version_extra = version_extra
26
+ @component_classes = []
27
+ @user_component_classes = []
28
+ end
29
+
30
+ def user_component_classes
31
+ @user_component_classes
32
+ end
33
+
34
+ alias get_name name
35
+ alias get_description description
36
+ alias get_author author
37
+ alias get_license license
38
+ alias get_path path
39
+
40
+ def get_version
41
+ BTVersion::Number.new(major, minor, patch, extra)
42
+ end
43
+ alias version get_version
44
+
45
+ def get_component_classes
46
+ @component_classes
47
+ end
48
+ alias component_classes get_component_classes
49
+
50
+ def get_component_class_addresses
51
+ get_component_classes.collect { |c|
52
+ c.handle.to_ptr.to_i
53
+ }
54
+ end
55
+ alias component_class_addresses get_component_class_addresses
56
+
57
+ def get_source_component_classes
58
+ @component_classes.select { |c| c.source? }
59
+ end
60
+ alias source_component_classes get_source_component_classes
61
+
62
+ def get_source_component_class_count
63
+ get_source_component_classes.count
64
+ end
65
+ alias source_component_class_count get_source_component_class_count
66
+
67
+ def get_filter_component_classes
68
+ @component_classes.select { |c| c.filter? }
69
+ end
70
+ alias filter_component_classes get_filter_component_classes
71
+
72
+ def get_filter_component_class_count
73
+ get_filter_component_classes.count
74
+ end
75
+ alias filter_component_class_count get_filter_component_class_count
76
+
77
+ def get_sink_component_classes
78
+ @component_classes.select { |c| c.sink? }
79
+ end
80
+ alias sink_component_classes get_sink_component_classes
81
+
82
+ def get_sink_component_class_count
83
+ get_sink_component_classes.count
84
+ end
85
+ alias sink_component_class_count get_sink_component_class_count
86
+
87
+ def get_source_component_class_by_index(index)
88
+ get_source_component_classes[index]
89
+ end
90
+
91
+ def get_filter_component_class_by_index(index)
92
+ get_filter_component_classes[index]
93
+ end
94
+
95
+ def get_sink_component_class_by_index(index)
96
+ get_sink_component_classes[index]
97
+ end
98
+
99
+ def get_source_component_class_by_name(name)
100
+ get_source_component_classes.find { |c| c.name == name }
101
+ end
102
+
103
+ def get_filter_component_class_by_name(name)
104
+ get_filter_component_classes.find { |c| c.name == name }
105
+ end
106
+
107
+ def get_sink_component_class_by_name(name)
108
+ get_sink_component_classes.find { |c| c.name == name }
109
+ end
110
+
111
+ def get_source_component_class(source_component_class)
112
+ case source_component_class
113
+ when String
114
+ get_source_component_class_by_name(source_component_class)
115
+ when Integer
116
+ get_source_component_class_by_index(source_component_class)
117
+ else
118
+ raise TypeError, "wrong type for source component class query"
119
+ end
120
+ end
121
+
122
+ def get_filter_component_class(filter_component_class)
123
+ case filter_component_class
124
+ when String
125
+ get_filter_component_class_by_name(filter_component_class)
126
+ when Integer
127
+ get_filter_component_class_by_index(filter_component_class)
128
+ else
129
+ raise TypeError, "wrong type for filter component class query"
130
+ end
131
+ end
132
+
133
+ def get_sink_component_class(sink_component_class)
134
+ case sink_component_class
135
+ when String
136
+ get_sink_component_class_by_name(sink_component_class)
137
+ when Integer
138
+ get_sink_component_class_by_index(sink_component_class)
139
+ else
140
+ raise TypeError, "wrong type for sink component class query"
141
+ end
142
+ end
143
+
144
+ def register_component_class(component)
145
+ raise "component with same name and type already exist" if @component_classes.find { |c| c.type == component.type && c.name == component.name}
146
+ if component.kind_of?(Class) && component < UserComponentClass
147
+ component = component.new
148
+ @user_component_classes.push component
149
+ component = component.bt_component_class
150
+ end
151
+ @component_classes.push component
152
+ self
153
+ end
154
+ alias register_component register_component_class
155
+ alias register register_component_class
156
+ alias push register_component_class
157
+ end
158
+
159
+ module GetMethod
160
+ private
161
+ def get_method(name, arity)
162
+ return nil unless self.class.method_defined?(name)
163
+ method = self.method(name)
164
+ raise "'#{name}' method must take #{arity} argument#{arity > 1 ? "s" : ""}" unless method.arity == arity
165
+ method
166
+ end
167
+ end
168
+
169
+ class UserMessageIterator
170
+ include GetMethod
171
+ attr_reader :bt_message_iterator
172
+
173
+ def initialize
174
+ next_method = get_method(:next, 2)
175
+ raise "'next' method must be defined" unless next_method
176
+ finalize_method = get_method(:finalize, 1)
177
+ initialize_method = get_method(:init, 3)
178
+ seek_beginning_method = get_method(:seek_beginning, 1)
179
+ can_seek_beginning_method = get_method(:can_seek_beginning, 1)
180
+ seek_ns_from_origin_method = get_method(:seek_ns_from_origin, 2)
181
+ can_seek_ns_from_origin_method = get_method(:can_seek_ns_from_origin, 2)
182
+ @bt_message_iterator = BTMessageIteratorClass.new(next_method: next_method)
183
+ @bt_message_iterator.finalize_method = finalize_method if finalize_method
184
+ @bt_message_iterator.initialize_method = initialize_method if initialize_method
185
+ if seek_beginning_method
186
+ @bt_message_iterator.set_seek_beginning_methods(seek_beginning_method, can_seek_method: can_seek_beginning_method)
187
+ end
188
+ if seek_ns_from_origin_method
189
+ @bt_message_iterator.set_seek_ns_from_origin_methods(seek_ns_from_origin_method, can_seek_method: can_seek_ns_from_origin_method)
190
+ end
191
+ end
192
+ end
193
+
194
+ class UserComponentClass
195
+ include GetMethod
196
+ attr_reader :bt_component_class
197
+ class << self
198
+ def get_name
199
+ @name ||= name.split("::").last
200
+ end
201
+ attr_accessor :description
202
+ attr_accessor :help
203
+ end
204
+ end
205
+
206
+ class UserSource < UserComponentClass
207
+ class << self
208
+ attr_accessor :message_iterator_class
209
+ def type
210
+ :BT_COMPONENT_CLASS_TYPE_SOURCE
211
+ end
212
+ end
213
+ attr_reader :user_message_iterator_class
214
+ def initialize
215
+ message_iterator_class = self.class.message_iterator_class
216
+ raise "'message_iterator_class' sould be defined" unless message_iterator_class
217
+ if message_iterator_class.kind_of?(Class) && message_iterator_class < UserMessageIterator
218
+ message_iterator_class = message_iterator_class.new
219
+ @user_message_iterator_class = message_iterator_class
220
+ message_iterator_class = message_iterator_class.bt_message_iterator
221
+ end
222
+ raise "'message_iterator_class' sould be an instance of UserMessageIterator or BTMessageIteratorClass" unless message_iterator_class.kind_of?(BTMessageIteratorClass)
223
+ finalize_method = get_method(:finalize, 1)
224
+ get_supported_mip_versions_method = get_method(:get_supported_mip_versions, 5)
225
+ initialize_method = get_method(:init, 4)
226
+ query_method = get_method(:query, 5)
227
+ output_port_connected_method = get_method(:output_port_connected, 3)
228
+ name = self.class.get_name
229
+ description = self.class.description
230
+ help = self.class.help
231
+ @bt_component_class = BTComponentClassSource.new(
232
+ name: name,
233
+ message_iterator_class: message_iterator_class)
234
+ @bt_component_class.description = description if description
235
+ @bt_component_class.help = help if help
236
+ @bt_component_class.finalize_method = finalize_method if finalize_method
237
+ @bt_component_class.initialize_method = initialize_method if initialize_method
238
+ @bt_component_class.get_supported_mip_versions_method = get_supported_mip_versions_method if get_supported_mip_versions_method
239
+ @bt_component_class.query_method = query_method if query_method
240
+ @bt_component_class.output_port_connected_method = output_port_connected_method if output_port_connected_method
241
+ end
242
+ end
243
+
244
+ class UserFilter < UserComponentClass
245
+ class << self
246
+ attr_accessor :message_iterator_class
247
+ def type
248
+ :BT_COMPONENT_CLASS_TYPE_FILTER
249
+ end
250
+ end
251
+ attr_reader :user_message_iterator_class
252
+ def initialize
253
+ message_iterator_class = self.class.message_iterator_class
254
+ raise "'message_iterator_class' sould be defined" unless message_iterator_class
255
+ if message_iterator_class.kind_of?(Class) && message_iterator_class < UserMessageIterator
256
+ message_iterator_class = message_iterator_class.new
257
+ @user_message_iterator_class = message_iterator_class
258
+ message_iterator_class = message_iterator_class.bt_message_iterator
259
+ end
260
+ finalize_method = get_method(:finalize, 1)
261
+ get_supported_mip_versions_method = get_method(:get_supported_mip_versions, 5)
262
+ initialize_method = get_method(:init, 4)
263
+ query_method = get_method(:query, 5)
264
+ input_port_connected_method = get_method(:input_port_connected, 3)
265
+ output_port_connected_method = get_method(:output_port_connected, 3)
266
+ name = self.class.get_name
267
+ description = self.class.description
268
+ help = self.class.help
269
+ @bt_component_class = BTComponentClassFilter.new(
270
+ name: name,
271
+ message_iterator_class: message_iterator_class)
272
+ @bt_component_class.description = description if description
273
+ @bt_component_class.help = help if help
274
+ @bt_component_class.finalize_method = finalize_method if finalize_method
275
+ @bt_component_class.initialize_method = initialize_method if initialize_method
276
+ @bt_component_class.get_supported_mip_versions_method = get_supported_mip_versions_method if get_supported_mip_versions_method
277
+ @bt_component_class.query_method = query_method if query_method
278
+ @bt_component_class.input_port_connected_method = input_port_connected_method if input_port_connected_method
279
+ @bt_component_class.output_port_connected_method = output_port_connected_method if output_port_connected_method
280
+ end
281
+ end
282
+
283
+ class UserSink < UserComponentClass
284
+ class << self
285
+ def type
286
+ :BT_COMPONENT_CLASS_TYPE_SINK
287
+ end
288
+ end
289
+ def initialize
290
+ consume_method = get_method(:consume, 1)
291
+ raise "'consum' method must be defined" unless consume_method
292
+ finalize_method = get_method(:finalize, 1)
293
+ get_supported_mip_versions_method = get_method(:get_supported_mip_versions, 5)
294
+ initialize_method = get_method(:init, 4)
295
+ query_method = get_method(:query, 5)
296
+ graph_is_configured_method = get_method(:graph_is_configured, 1)
297
+ input_port_connected_method = get_method(:input_port_connected, 3)
298
+ name = self.class.get_name
299
+ description = self.class.description
300
+ help = self.class.help
301
+ @bt_component_class = BTComponentClassSink.new(name: name, consume_method: consume_method)
302
+ @bt_component_class.description = description if description
303
+ @bt_component_class.help = help if help
304
+ @bt_component_class.finalize_method = finalize_method if finalize_method
305
+ @bt_component_class.initialize_method = initialize_method if initialize_method
306
+ @bt_component_class.get_supported_mip_versions_method = get_supported_mip_versions_method if get_supported_mip_versions_method
307
+ @bt_component_class.query_method = query_method if query_method
308
+ @bt_component_class.graph_is_configured_method = graph_is_configured_method if graph_is_configured_method
309
+ @bt_component_class.input_port_connected_method = input_port_connected_method if input_port_connected_method
310
+ end
311
+ end
312
+
313
+ @@native_plugins = {}
314
+
315
+ @@user_plugins = []
316
+
317
+ def self.register_user_plugin(plugin)
318
+ @@user_plugins.push(plugin)
319
+ end
320
+
321
+ def self.load_plugin_file(path)
322
+ return [] unless File.exist?(path)
323
+ hash = Digest::SHA256.file(path).to_s
324
+ return @@native_plugins[hash] if @@native_plugins.include?(hash)
325
+ @@user_plugins = []
326
+ str = ""
327
+ str << "module Mod#{hash}; class << self; def register_user_plugin(plugin); Babeltrace2.register_user_plugin(plugin); end; alias register_plugin register_user_plugin; alias register register_user_plugin; end; "
328
+ str << File.read(path) << "; end"
329
+ eval(str, nil, path)
330
+ @@user_plugins.each { |p|
331
+ p.path = path unless p.path
332
+ }
333
+ @@native_plugins[hash] = @@user_plugins
334
+ end
335
+ end
@@ -0,0 +1,459 @@
1
+ module Babeltrace2
2
+
3
+ BT_PLUGIN_FIND_STATUS_OK = BT_FUNC_STATUS_OK
4
+ BT_PLUGIN_FIND_STATUS_NOT_FOUND = BT_FUNC_STATUS_NOT_FOUND
5
+ BT_PLUGIN_FIND_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
6
+ BT_PLUGIN_FIND_STATUS_ERROR = BT_FUNC_STATUS_ERROR
7
+ BTPluginFindStatus = enum :bt_plugin_find_status,
8
+ [ :BT_PLUGIN_FIND_STATUS_OK,
9
+ BT_PLUGIN_FIND_STATUS_OK,
10
+ :BT_PLUGIN_FIND_STATUS_NOT_FOUND,
11
+ BT_PLUGIN_FIND_STATUS_NOT_FOUND,
12
+ :BT_PLUGIN_FIND_STATUS_MEMORY_ERROR,
13
+ BT_PLUGIN_FIND_STATUS_MEMORY_ERROR,
14
+ :BT_PLUGIN_FIND_STATUS_ERROR,
15
+ BT_PLUGIN_FIND_STATUS_ERROR ]
16
+
17
+ attach_function :bt_plugin_find,
18
+ [ :string, :bt_bool, :bt_bool, :bt_bool, :bt_bool, :bt_bool, :pointer ],
19
+ :bt_plugin_find_status
20
+
21
+ BT_PLUGIN_FIND_ALL_STATUS_OK = BT_FUNC_STATUS_OK
22
+ BT_PLUGIN_FIND_ALL_STATUS_NOT_FOUND = BT_FUNC_STATUS_NOT_FOUND
23
+ BT_PLUGIN_FIND_ALL_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
24
+ BT_PLUGIN_FIND_ALL_STATUS_ERROR = BT_FUNC_STATUS_ERROR
25
+ BTPluginFindAllStatus = enum :bt_plugin_find_all_status,
26
+ [ :BT_PLUGIN_FIND_ALL_STATUS_OK,
27
+ BT_PLUGIN_FIND_ALL_STATUS_OK,
28
+ :BT_PLUGIN_FIND_ALL_STATUS_NOT_FOUND,
29
+ BT_PLUGIN_FIND_ALL_STATUS_NOT_FOUND,
30
+ :BT_PLUGIN_FIND_ALL_STATUS_MEMORY_ERROR,
31
+ BT_PLUGIN_FIND_ALL_STATUS_MEMORY_ERROR,
32
+ :BT_PLUGIN_FIND_ALL_STATUS_ERROR,
33
+ BT_PLUGIN_FIND_ALL_STATUS_ERROR ]
34
+
35
+ attach_function :bt_plugin_find_all,
36
+ [ :bt_bool, :bt_bool, :bt_bool, :bt_bool, :bt_bool, :pointer ],
37
+ :bt_plugin_find_all_status
38
+
39
+ BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_OK = BT_FUNC_STATUS_OK
40
+ BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_NOT_FOUND = BT_FUNC_STATUS_NOT_FOUND
41
+ BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
42
+ BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_ERROR = BT_FUNC_STATUS_ERROR
43
+ BTPluginFindAllFromFileStatus = enum :bt_plugin_find_all_from_file_status,
44
+ [ :BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_OK,
45
+ BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_OK,
46
+ :BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_NOT_FOUND,
47
+ BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_NOT_FOUND,
48
+ :BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_MEMORY_ERROR,
49
+ BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_MEMORY_ERROR,
50
+ :BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_ERROR,
51
+ BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_ERROR ]
52
+
53
+ attach_function :bt_plugin_find_all_from_file,
54
+ [ :string, :bt_bool, :pointer ],
55
+ :bt_plugin_find_all_from_file_status
56
+
57
+ BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_OK = BT_FUNC_STATUS_OK
58
+ BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_NOT_FOUND = BT_FUNC_STATUS_NOT_FOUND
59
+ BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
60
+ BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_ERROR = BT_FUNC_STATUS_ERROR
61
+ BTPluginFindAllFromDirStatus = enum :bt_plugin_find_all_from_dir_status,
62
+ [ :BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_OK,
63
+ BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_OK,
64
+ :BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_NOT_FOUND,
65
+ BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_NOT_FOUND,
66
+ :BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_MEMORY_ERROR,
67
+ BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_MEMORY_ERROR,
68
+ :BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_ERROR,
69
+ BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_ERROR ]
70
+
71
+ attach_function :bt_plugin_find_all_from_dir,
72
+ [ :string, :bt_bool, :bt_bool, :pointer ],
73
+ :bt_plugin_find_all_from_dir_status
74
+
75
+ BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_OK = BT_FUNC_STATUS_OK
76
+ BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_NOT_FOUND = BT_FUNC_STATUS_NOT_FOUND
77
+ BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_MEMORY_ERROR = BT_FUNC_STATUS_MEMORY_ERROR
78
+ BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_ERROR = BT_FUNC_STATUS_ERROR
79
+ BTPluginFindAllFromStaticStatus = enum :bt_plugin_find_all_from_static_status,
80
+ [ :BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_OK,
81
+ BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_OK,
82
+ :BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_NOT_FOUND,
83
+ BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_NOT_FOUND,
84
+ :BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_MEMORY_ERROR,
85
+ BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_MEMORY_ERROR,
86
+ :BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_ERROR,
87
+ BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_ERROR ]
88
+
89
+ attach_function :bt_plugin_find_all_from_static,
90
+ [ :bt_bool, :pointer ],
91
+ :bt_plugin_find_all_from_static_status
92
+
93
+ attach_function :bt_plugin_get_name,
94
+ [ :bt_plugin_handle ],
95
+ :string
96
+
97
+ attach_function :bt_plugin_get_description,
98
+ [ :bt_plugin_handle ],
99
+ :string
100
+
101
+ attach_function :bt_plugin_get_author,
102
+ [ :bt_plugin_handle ],
103
+ :string
104
+
105
+ attach_function :bt_plugin_get_license,
106
+ [ :bt_plugin_handle ],
107
+ :string
108
+
109
+ attach_function :bt_plugin_get_path,
110
+ [ :bt_plugin_handle ],
111
+ :string
112
+
113
+ attach_function :bt_plugin_get_version,
114
+ [ :bt_plugin_handle, :pointer, :pointer, :pointer, :pointer ],
115
+ :bt_property_availability
116
+
117
+ attach_function :bt_plugin_get_source_component_class_count,
118
+ [ :bt_plugin_handle ],
119
+ :uint64
120
+
121
+ attach_function :bt_plugin_get_filter_component_class_count,
122
+ [ :bt_plugin_handle ],
123
+ :uint64
124
+
125
+ attach_function :bt_plugin_get_sink_component_class_count,
126
+ [ :bt_plugin_handle ],
127
+ :uint64
128
+
129
+ attach_function :bt_plugin_borrow_source_component_class_by_index_const,
130
+ [ :bt_plugin_handle, :uint64 ],
131
+ :bt_component_class_source_handle
132
+
133
+ attach_function :bt_plugin_borrow_filter_component_class_by_index_const,
134
+ [ :bt_plugin_handle, :uint64 ],
135
+ :bt_component_class_filter_handle
136
+
137
+ attach_function :bt_plugin_borrow_sink_component_class_by_index_const,
138
+ [ :bt_plugin_handle, :uint64 ],
139
+ :bt_component_class_sink_handle
140
+
141
+ attach_function :bt_plugin_borrow_source_component_class_by_name_const,
142
+ [ :bt_plugin_handle, :string ],
143
+ :bt_component_class_source_handle
144
+
145
+ attach_function :bt_plugin_borrow_filter_component_class_by_name_const,
146
+ [ :bt_plugin_handle, :string ],
147
+ :bt_component_class_filter_handle
148
+
149
+ attach_function :bt_plugin_borrow_sink_component_class_by_name_const,
150
+ [ :bt_plugin_handle, :string ],
151
+ :bt_component_class_sink_handle
152
+
153
+ attach_function :bt_plugin_get_ref,
154
+ [ :bt_plugin_handle ],
155
+ :void
156
+
157
+ attach_function :bt_plugin_put_ref,
158
+ [ :bt_plugin_handle ],
159
+ :void
160
+
161
+ class BTPlugin < BTSharedObject
162
+ FindStatus = BTPluginFindStatus
163
+ FindAllStatus = BTPluginFindAllStatus
164
+ FindAllFromFileStatus = BTPluginFindAllFromFileStatus
165
+ FindAllFromDirStatus = BTPluginFindAllFromDirStatus
166
+ FindAllFromStaticStatus = BTPluginFindAllFromStaticStatus
167
+ @get_ref = :bt_plugin_get_ref
168
+ @put_ref = :bt_plugin_put_ref
169
+
170
+ def self.find(name,
171
+ find_in_std_env_var: true,
172
+ find_in_user_dir: true,
173
+ find_in_sys_dir: true,
174
+ find_in_static: false,
175
+ fail_on_load_error: true)
176
+ ptr = FFI::MemoryPointer.new(:pointer)
177
+ res = Babeltrace2.bt_plugin_find(
178
+ name,
179
+ find_in_std_env_var ? BT_TRUE : BT_FALSE,
180
+ find_in_user_dir ? BT_TRUE : BT_FALSE,
181
+ find_in_sys_dir ? BT_TRUE : BT_FALSE,
182
+ find_in_static ? BT_TRUE : BT_FALSE,
183
+ fail_on_load_error ? BT_TRUE : BT_FALSE,
184
+ ptr)
185
+ return nil if res == :BT_PLUGIN_FIND_STATUS_NOT_FOUND
186
+ raise Babeltrace2.process_error(res) if res != :BT_PLUGIN_FIND_STATUS_OK
187
+ handle = BTPluginHandle.new(ptr.read_pointer)
188
+ BTPlugin.new(handle, retain: false)
189
+ end
190
+
191
+ def self.find_all(find_in_std_env_var: true,
192
+ find_in_user_dir: true,
193
+ find_in_sys_dir: true,
194
+ find_in_static: false,
195
+ fail_on_load_error: true)
196
+ ptr = FFI::MemoryPointer.new(:pointer)
197
+ res = Babeltrace2.bt_plugin_find_all(
198
+ find_in_std_env_var ? BT_TRUE : BT_FALSE,
199
+ find_in_user_dir ? BT_TRUE : BT_FALSE,
200
+ find_in_sys_dir ? BT_TRUE : BT_FALSE,
201
+ find_in_static ? BT_TRUE : BT_FALSE,
202
+ fail_on_load_error ? BT_TRUE : BT_FALSE,
203
+ ptr)
204
+ return [] if res == :BT_PLUGIN_FIND_ALL_STATUS_NOT_FOUND
205
+ raise Babeltrace2.process_error(res) if res != :BT_PLUGIN_FIND_ALL_STATUS_OK
206
+ handle = BTPluginSetHandle.new(ptr.read_pointer)
207
+ BTPluginSet.new(handle, retain: false).plugins
208
+ end
209
+
210
+ def self.find_all_from_file(path, fail_on_load_error: true)
211
+ ptr = FFI::MemoryPointer.new(:pointer)
212
+ res = Babeltrace2.bt_plugin_find_all_from_file(
213
+ path,
214
+ fail_on_load_error ? BT_TRUE : BT_FALSE,
215
+ ptr)
216
+ return [] if res == :BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_NOT_FOUND
217
+ raise Babeltrace2.process_error(res) if res != :BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_OK
218
+ handle = BTPluginSetHandle.new(ptr.read_pointer)
219
+ BTPluginSet.new(handle, retain: false).plugins
220
+ end
221
+
222
+ def self.find_all_from_dir(path, recurse: false, fail_on_load_error: true)
223
+ ptr = FFI::MemoryPointer.new(:pointer)
224
+ res = Babeltrace2.bt_plugin_find_all_from_dir(
225
+ path,
226
+ recurse ? BT_TRUE : BT_FALSE,
227
+ fail_on_load_error ? BT_TRUE : BT_FALSE,
228
+ ptr)
229
+ return [] if res == :BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_NOT_FOUND
230
+ raise Babeltrace2.process_error(res) if res != :BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_OK
231
+ handle = BTPluginSetHandle.new(ptr.read_pointer)
232
+ BTPluginSet.new(handle, retain: false).plugins
233
+ end
234
+
235
+ def self.find_all_from_static(recurse: false, fail_on_load_error: true)
236
+ ptr = FFI::MemoryPointer.new(:pointer)
237
+ res = Babeltrace2.bt_plugin_find_all_from_static(
238
+ path,
239
+ recurse ? BT_TRUE : BT_FALSE,
240
+ fail_on_load_error ? BT_TRUE : BT_FALSE,
241
+ ptr)
242
+ return [] if res == :BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_NOT_FOUND
243
+ raise Babeltrace2.process_error(res) if res != :BT_PLUGIN_FIND_ALL_FROM_STATIC_STATUS_OK
244
+ handle = BTPluginSetHandle.new(ptr.read_pointer)
245
+ BTPluginSet.new(handle, retain: false).plugins
246
+ end
247
+
248
+ def get_name
249
+ Babeltrace2.bt_plugin_get_name(@handle)
250
+ end
251
+ alias name get_name
252
+
253
+ def get_description
254
+ Babeltrace2.bt_plugin_get_description(@handle)
255
+ end
256
+ alias description get_description
257
+
258
+ def get_author
259
+ Babeltrace2.bt_plugin_get_author(@handle)
260
+ end
261
+ alias author get_author
262
+
263
+ def get_license
264
+ Babeltrace2.bt_plugin_get_license(@handle)
265
+ end
266
+ alias license get_license
267
+
268
+ def get_path
269
+ Babeltrace2.bt_plugin_get_path(@handle)
270
+ end
271
+ alias path get_path
272
+
273
+ def get_version
274
+ major = FFI::MemoryPointer.new(:uint)
275
+ minor = FFI::MemoryPointer.new(:uint)
276
+ patch = FFI::MemoryPointer.new(:uint)
277
+ extra = FFI::MemoryPointer.new(:pointer)
278
+ res = Babeltrace2.bt_plugin_get_version(@handle, major, minor, patch, extra)
279
+ if res == :BT_PROPERTY_AVAILABILITY_AVAILABLE
280
+ extra = extra.read_pointer
281
+ BTVersion::Number.new(major.read_uint, minor.read_uint, patch.read_uint,
282
+ extra.null? ? nil : extra.read_string)
283
+ else
284
+ nil
285
+ end
286
+ end
287
+ alias version get_version
288
+
289
+ def get_source_component_class_count
290
+ Babeltrace2.bt_plugin_get_source_component_class_count(@handle)
291
+ end
292
+ alias source_component_class_count get_source_component_class_count
293
+
294
+ def get_filter_component_class_count
295
+ Babeltrace2.bt_plugin_get_filter_component_class_count(@handle)
296
+ end
297
+ alias filter_component_class_count get_filter_component_class_count
298
+
299
+ def get_sink_component_class_count
300
+ Babeltrace2.bt_plugin_get_sink_component_class_count(@handle)
301
+ end
302
+ alias sink_component_class_count get_sink_component_class_count
303
+
304
+ def get_source_component_class_by_index(index)
305
+ count = get_source_component_class_count
306
+ index += count if index < 0
307
+ return nil if index >= count || index < 0
308
+ handle = Babeltrace2.bt_plugin_borrow_source_component_class_by_index_const(
309
+ @handle, index)
310
+ BTComponentClassSource.new(handle, retain: true)
311
+ end
312
+
313
+ def get_source_component_class_by_name(name)
314
+ handle = Babeltrace2.bt_plugin_borrow_source_component_class_by_name_const(
315
+ @handle, name)
316
+ return nil if handle.null?
317
+ BTComponentClassSource.new(handle, retain: true)
318
+ end
319
+
320
+ def get_source_component_class(source_component_class)
321
+ case source_component_class
322
+ when String
323
+ get_source_component_class_by_name(source_component_class)
324
+ when Integer
325
+ get_source_component_class_by_index(source_component_class)
326
+ else
327
+ raise TypeError, "wrong type for source component class query"
328
+ end
329
+ end
330
+
331
+ def get_source_component_classes
332
+ source_component_class_count.times.collect { |index|
333
+ handle = Babeltrace2.bt_plugin_borrow_source_component_class_by_index_const(
334
+ @handle, index)
335
+ BTComponentClassSource.new(handle, retain: true)
336
+ }
337
+ end
338
+ alias source_component_classes get_source_component_classes
339
+
340
+ def get_filter_component_class_by_index(index)
341
+ count = get_filter_component_class_count
342
+ index += count if index < 0
343
+ return nil if index >= count || index < 0
344
+ handle = Babeltrace2.bt_plugin_borrow_filter_component_class_by_index_const(
345
+ @handle, index)
346
+ BTComponentClassFilter.new(handle, retain: true)
347
+ end
348
+
349
+ def get_filter_component_class_by_name(name)
350
+ handle = Babeltrace2.bt_plugin_borrow_filter_component_class_by_name_const(
351
+ @handle, name)
352
+ return nil if handle.null?
353
+ BTComponentClassFilter.new(handle, retain: true)
354
+ end
355
+
356
+ def get_filter_component_class(filter_component_class)
357
+ case filter_component_class
358
+ when String
359
+ get_filter_component_class_by_name(filter_component_class)
360
+ when Integer
361
+ get_filter_component_class_by_index(filter_component_class)
362
+ else
363
+ raise TypeError, "wrong type for filter component class query"
364
+ end
365
+ end
366
+
367
+ def get_filter_component_classes
368
+ filter_component_class_count.times.collect { |index|
369
+ handle = Babeltrace2.bt_plugin_borrow_filter_component_class_by_index_const(
370
+ @handle, index)
371
+ BTComponentClassFilter.new(handle, retain: true)
372
+ }
373
+ end
374
+ alias filter_component_classes get_filter_component_classes
375
+
376
+ def get_sink_component_class_by_index(index)
377
+ count = get_sink_component_class_count
378
+ index += count if index < 0
379
+ return nil if index >= count || index < 0
380
+ handle = Babeltrace2.bt_plugin_borrow_sink_component_class_by_index_const(
381
+ @handle, index)
382
+ BTComponentClassSink.new(handle, retain: true)
383
+ end
384
+
385
+ def get_sink_component_class_by_name(name)
386
+ handle = Babeltrace2.bt_plugin_borrow_sink_component_class_by_name_const(
387
+ @handle, name)
388
+ return nil if handle.null?
389
+ BTComponentClassSink.new(handle, retain: true)
390
+ end
391
+
392
+ def get_sink_component_class(sink_component_class)
393
+ case sink_component_class
394
+ when String
395
+ get_sink_component_class_by_name(sink_component_class)
396
+ when Integer
397
+ get_sink_component_class_by_index(sink_component_class)
398
+ else
399
+ raise TypeError, "wrong type for sink component class query"
400
+ end
401
+ end
402
+
403
+ def get_sink_component_classes
404
+ sink_component_class_count.times.collect { |index|
405
+ handle = Babeltrace2.bt_plugin_borrow_sink_component_class_by_index_const(
406
+ @handle, index)
407
+ BTComponentClassSink.new(handle, retain: true)
408
+ }
409
+ end
410
+ alias sink_component_classes get_sink_component_classes
411
+ end
412
+
413
+ attach_function :bt_plugin_set_get_plugin_count,
414
+ [ :bt_plugin_set_handle ],
415
+ :uint64
416
+
417
+ attach_function :bt_plugin_set_borrow_plugin_by_index_const,
418
+ [ :bt_plugin_set_handle, :uint64 ],
419
+ :bt_plugin_handle
420
+
421
+ attach_function :bt_plugin_set_get_ref,
422
+ [ :bt_plugin_set_handle ],
423
+ :void
424
+
425
+ attach_function :bt_plugin_set_put_ref,
426
+ [ :bt_plugin_set_handle ],
427
+ :void
428
+
429
+ class BTPlugin
430
+ class Set < BTSharedObject
431
+ @get_ref = :bt_plugin_set_get_ref
432
+ @put_ref = :bt_plugin_set_put_ref
433
+
434
+ def get_plugin_count
435
+ Babeltrace2.bt_plugin_set_get_plugin_count(@handle)
436
+ end
437
+ alias plugin_count get_plugin_count
438
+ alias size get_plugin_count
439
+
440
+ def get_plugin_by_index(index)
441
+ count = get_plugin_count
442
+ index += count if index < 0
443
+ return nil if index >= count || index < 0
444
+ handle = Babeltrace2.bt_plugin_set_borrow_plugin_by_index_const(@handle, index)
445
+ BTPlugin.new(handle, retain: true)
446
+ end
447
+ alias [] get_plugin_by_index
448
+
449
+ def get_plugins
450
+ get_plugin_count.times.collect { |index|
451
+ handle = Babeltrace2.bt_plugin_set_borrow_plugin_by_index_const(@handle, index)
452
+ BTPlugin.new(handle, retain: true)
453
+ }
454
+ end
455
+ alias plugins get_plugins
456
+ end
457
+ end
458
+ BTPluginSet = BTPlugin::Set
459
+ end