Commit | Line | Data |
---|---|---|
4212232c | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
4212232c PP |
3 | * |
4 | * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com> | |
4212232c PP |
5 | */ |
6 | ||
7c7301d5 | 7 | static |
9a2c8b8e PP |
8 | bt_message_iterator_create_from_message_iterator_status |
9 | bt_bt2_message_iterator_create_from_message_iterator( | |
e803df70 SM |
10 | bt_self_message_iterator *self_msg_iter, |
11 | bt_self_component_port_input *input_port, | |
9a2c8b8e | 12 | bt_message_iterator **message_iterator) |
e803df70 | 13 | { |
9a2c8b8e | 14 | bt_message_iterator_create_from_message_iterator_status |
e803df70 SM |
15 | status; |
16 | ||
9a2c8b8e | 17 | status = bt_message_iterator_create_from_message_iterator( |
e803df70 SM |
18 | self_msg_iter, input_port, message_iterator); |
19 | ||
9a2c8b8e | 20 | if (status != BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK) { |
e803df70 SM |
21 | *message_iterator = NULL; |
22 | } | |
23 | ||
24 | return status; | |
25 | } | |
26 | ||
7c7301d5 | 27 | static |
9a2c8b8e PP |
28 | bt_message_iterator_create_from_sink_component_status |
29 | bt_bt2_message_iterator_create_from_sink_component( | |
e803df70 SM |
30 | bt_self_component_sink *self_comp, |
31 | bt_self_component_port_input *input_port, | |
9a2c8b8e | 32 | bt_message_iterator **message_iterator) |
e803df70 | 33 | { |
9a2c8b8e | 34 | bt_message_iterator_create_from_sink_component_status |
e803df70 SM |
35 | status; |
36 | ||
9a2c8b8e | 37 | status = bt_message_iterator_create_from_sink_component( |
e803df70 SM |
38 | self_comp, input_port, message_iterator); |
39 | ||
9a2c8b8e | 40 | if (status != BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) { |
e803df70 SM |
41 | *message_iterator = NULL; |
42 | } | |
43 | ||
44 | return status; | |
45 | } | |
46 | ||
4212232c PP |
47 | static PyObject *bt_bt2_get_user_component_from_user_msg_iter( |
48 | bt_self_message_iterator *self_message_iterator) | |
49 | { | |
50 | bt_self_component *self_component = bt_self_message_iterator_borrow_component(self_message_iterator); | |
51 | PyObject *py_comp; | |
52 | ||
98b15851 | 53 | BT_ASSERT_DBG(self_component); |
4212232c | 54 | py_comp = bt_self_component_get_data(self_component); |
98b15851 | 55 | BT_ASSERT_DBG(py_comp); |
4212232c PP |
56 | |
57 | /* Return new reference */ | |
58 | Py_INCREF(py_comp); | |
59 | return py_comp; | |
60 | } | |
61 | ||
62 | static inline | |
63 | PyObject *create_pylist_from_messages(bt_message_array_const messages, | |
64 | uint64_t message_count) | |
65 | { | |
66 | uint64_t i; | |
67 | PyObject *py_msg_list = PyList_New(message_count); | |
68 | ||
69 | BT_ASSERT(py_msg_list); | |
70 | ||
71 | for (i = 0; i < message_count; i++) { | |
72 | PyList_SET_ITEM(py_msg_list, i, | |
73 | SWIG_NewPointerObj(SWIG_as_voidptr(messages[i]), | |
74 | SWIGTYPE_p_bt_message, 0)); | |
75 | } | |
76 | ||
77 | return py_msg_list; | |
78 | } | |
79 | ||
80 | static | |
81 | PyObject *get_msg_range_common(bt_message_iterator_next_status status, | |
82 | bt_message_array_const messages, uint64_t message_count) | |
83 | { | |
84 | PyObject *py_status; | |
85 | PyObject *py_return_tuple; | |
86 | PyObject *py_msg_list; | |
87 | ||
88 | py_return_tuple = PyTuple_New(2); | |
89 | BT_ASSERT(py_return_tuple); | |
90 | ||
91 | /* Set tuple[0], status. */ | |
92 | py_status = SWIG_From_long_SS_long(status); | |
93 | PyTuple_SET_ITEM(py_return_tuple, 0, py_status); | |
94 | ||
95 | /* Set tuple[1], message list on success, None otherwise. */ | |
96 | if (status == __BT_FUNC_STATUS_OK) { | |
97 | py_msg_list = create_pylist_from_messages(messages, message_count); | |
98 | } else { | |
99 | py_msg_list = Py_None; | |
100 | Py_INCREF(py_msg_list); | |
101 | } | |
102 | ||
103 | PyTuple_SET_ITEM(py_return_tuple, 1, py_msg_list); | |
104 | ||
105 | return py_return_tuple; | |
106 | } | |
107 | ||
108 | static PyObject *bt_bt2_self_component_port_input_get_msg_range( | |
9a2c8b8e | 109 | bt_message_iterator *iter) |
4212232c PP |
110 | { |
111 | bt_message_array_const messages; | |
112 | uint64_t message_count = 0; | |
113 | bt_message_iterator_next_status status; | |
114 | ||
9a2c8b8e | 115 | status = bt_message_iterator_next(iter, |
4212232c PP |
116 | &messages, &message_count); |
117 | return get_msg_range_common(status, messages, message_count); | |
118 | } |