lib: remove output port message iterator
[babeltrace.git] / src / bindings / python / bt2 / bt2 / native_bt_message_iterator.i.h
1 /*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 static PyObject *bt_bt2_get_user_component_from_user_msg_iter(
26 bt_self_message_iterator *self_message_iterator)
27 {
28 bt_self_component *self_component = bt_self_message_iterator_borrow_component(self_message_iterator);
29 PyObject *py_comp;
30
31 BT_ASSERT(self_component);
32 py_comp = bt_self_component_get_data(self_component);
33 BT_ASSERT(py_comp);
34
35 /* Return new reference */
36 Py_INCREF(py_comp);
37 return py_comp;
38 }
39
40 static inline
41 PyObject *create_pylist_from_messages(bt_message_array_const messages,
42 uint64_t message_count)
43 {
44 uint64_t i;
45 PyObject *py_msg_list = PyList_New(message_count);
46
47 BT_ASSERT(py_msg_list);
48
49 for (i = 0; i < message_count; i++) {
50 PyList_SET_ITEM(py_msg_list, i,
51 SWIG_NewPointerObj(SWIG_as_voidptr(messages[i]),
52 SWIGTYPE_p_bt_message, 0));
53 }
54
55 return py_msg_list;
56 }
57
58 static
59 PyObject *get_msg_range_common(bt_message_iterator_next_status status,
60 bt_message_array_const messages, uint64_t message_count)
61 {
62 PyObject *py_status;
63 PyObject *py_return_tuple;
64 PyObject *py_msg_list;
65
66 py_return_tuple = PyTuple_New(2);
67 BT_ASSERT(py_return_tuple);
68
69 /* Set tuple[0], status. */
70 py_status = SWIG_From_long_SS_long(status);
71 PyTuple_SET_ITEM(py_return_tuple, 0, py_status);
72
73 /* Set tuple[1], message list on success, None otherwise. */
74 if (status == __BT_FUNC_STATUS_OK) {
75 py_msg_list = create_pylist_from_messages(messages, message_count);
76 } else {
77 py_msg_list = Py_None;
78 Py_INCREF(py_msg_list);
79 }
80
81 PyTuple_SET_ITEM(py_return_tuple, 1, py_msg_list);
82
83 return py_return_tuple;
84 }
85
86 static PyObject *bt_bt2_self_component_port_input_get_msg_range(
87 bt_self_component_port_input_message_iterator *iter)
88 {
89 bt_message_array_const messages;
90 uint64_t message_count = 0;
91 bt_message_iterator_next_status status;
92
93 status = bt_self_component_port_input_message_iterator_next(iter,
94 &messages, &message_count);
95 return get_msg_range_common(status, messages, message_count);
96 }
This page took 0.03097 seconds and 4 git commands to generate.