| 1 | # SPDX-License-Identifier: MIT |
| 2 | # |
| 3 | # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com> |
| 4 | |
| 5 | from bt2 import error as bt2_error |
| 6 | from bt2 import utils as bt2_utils |
| 7 | from bt2 import logging as bt2_logging |
| 8 | from bt2 import native_bt |
| 9 | from bt2 import component_descriptor as bt2_component_descriptor |
| 10 | |
| 11 | |
| 12 | def get_greatest_operative_mip_version( |
| 13 | component_descriptors, log_level=bt2_logging.LoggingLevel.NONE |
| 14 | ): |
| 15 | bt2_utils._check_log_level(log_level) |
| 16 | comp_descr_set_ptr = native_bt.component_descriptor_set_create() |
| 17 | |
| 18 | if comp_descr_set_ptr is None: |
| 19 | raise bt2_error._MemoryError("cannot create component descriptor set object") |
| 20 | |
| 21 | if len(component_descriptors) == 0: |
| 22 | raise ValueError("no component descriptors") |
| 23 | |
| 24 | try: |
| 25 | for descr in component_descriptors: |
| 26 | if type(descr) is not bt2_component_descriptor.ComponentDescriptor: |
| 27 | raise TypeError("'{}' is not a component descriptor".format(descr)) |
| 28 | |
| 29 | base_cc_ptr = descr.component_class._bt_component_class_ptr() |
| 30 | params_ptr = None |
| 31 | |
| 32 | if descr.params is not None: |
| 33 | params_ptr = descr.params._ptr |
| 34 | |
| 35 | status = native_bt.bt2_component_descriptor_set_add_descriptor_with_initialize_method_data( |
| 36 | comp_descr_set_ptr, base_cc_ptr, params_ptr, descr.obj |
| 37 | ) |
| 38 | bt2_utils._handle_func_status( |
| 39 | status, "cannot add descriptor to component descriptor set" |
| 40 | ) |
| 41 | |
| 42 | status, version = native_bt.get_greatest_operative_mip_version( |
| 43 | comp_descr_set_ptr, log_level |
| 44 | ) |
| 45 | |
| 46 | if status == native_bt.__BT_FUNC_STATUS_NO_MATCH: |
| 47 | return None |
| 48 | |
| 49 | bt2_utils._handle_func_status( |
| 50 | status, "cannot get greatest operative MIP version" |
| 51 | ) |
| 52 | return version |
| 53 | finally: |
| 54 | native_bt.component_descriptor_set_put_ref(comp_descr_set_ptr) |
| 55 | |
| 56 | |
| 57 | def get_maximal_mip_version(): |
| 58 | return native_bt.get_maximal_mip_version() |