2 * The MIT License (MIT)
4 * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 /* From message-iterator-const.h */
27 typedef enum bt_message_iterator_status {
28 BT_MESSAGE_ITERATOR_STATUS_OK = 0,
29 BT_MESSAGE_ITERATOR_STATUS_END = 1,
30 BT_MESSAGE_ITERATOR_STATUS_AGAIN = 11,
31 BT_MESSAGE_ITERATOR_STATUS_ERROR = -1,
32 BT_MESSAGE_ITERATOR_STATUS_NOMEM = -12,
33 } bt_message_iterator_status;
35 /* From self-message-iterator.h */
37 typedef enum bt_self_message_iterator_status {
38 BT_SELF_MESSAGE_ITERATOR_STATUS_OK = BT_MESSAGE_ITERATOR_STATUS_OK,
39 BT_SELF_MESSAGE_ITERATOR_STATUS_END = BT_MESSAGE_ITERATOR_STATUS_END,
40 BT_SELF_MESSAGE_ITERATOR_STATUS_AGAIN = BT_MESSAGE_ITERATOR_STATUS_AGAIN,
41 BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR = BT_MESSAGE_ITERATOR_STATUS_ERROR,
42 BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM = BT_MESSAGE_ITERATOR_STATUS_NOMEM,
43 } bt_self_message_iterator_status;
45 extern bt_self_component *
46 bt_self_message_iterator_borrow_component(
47 bt_self_message_iterator *message_iterator);
49 extern bt_self_port_output *
50 bt_self_message_iterator_borrow_port(
51 bt_self_message_iterator *message_iterator);
53 extern void bt_self_message_iterator_set_data(
54 bt_self_message_iterator *message_iterator,
57 extern void *bt_self_message_iterator_get_data(
58 const bt_self_message_iterator *message_iterator);
60 /* From self-component-port-input-message-iterator.h */
63 bt_self_component_port_input_message_iterator_as_message_iterator(
64 bt_self_component_port_input_message_iterator *iterator);
66 extern bt_self_component_port_input_message_iterator *
67 bt_self_component_port_input_message_iterator_create(
68 bt_self_component_port_input *input_port);
71 bt_self_component_port_input_message_iterator_borrow_component(
72 bt_self_component_port_input_message_iterator *iterator);
74 extern bt_message_iterator_status
75 bt_self_component_port_input_message_iterator_next(
76 bt_self_component_port_input_message_iterator *iterator,
77 bt_message_array_const *msgs, uint64_t *count);
80 bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
81 bt_self_component_port_input_message_iterator *iterator,
82 int64_t ns_from_origin);
84 extern bt_bool bt_self_component_port_input_message_iterator_can_seek_beginning(
85 bt_self_component_port_input_message_iterator *iterator);
87 extern bt_message_iterator_status
88 bt_self_component_port_input_message_iterator_seek_ns_from_origin(
89 bt_self_component_port_input_message_iterator *iterator,
90 int64_t ns_from_origin);
92 extern bt_message_iterator_status
93 bt_self_component_port_input_message_iterator_seek_beginning(
94 bt_self_component_port_input_message_iterator *iterator);
96 extern void bt_self_component_port_input_message_iterator_get_ref(
97 const bt_self_component_port_input_message_iterator *self_component_port_input_message_iterator);
99 extern void bt_self_component_port_input_message_iterator_put_ref(
100 const bt_self_component_port_input_message_iterator *self_component_port_input_message_iterator);
102 /* From port-output-message-iterator.h */
104 bt_message_iterator *
105 bt_port_output_message_iterator_as_message_iterator(
106 bt_port_output_message_iterator *iterator);
108 extern bt_port_output_message_iterator *
109 bt_port_output_message_iterator_create(
111 const bt_port_output *output_port);
113 extern bt_message_iterator_status
114 bt_port_output_message_iterator_next(
115 bt_port_output_message_iterator *iterator,
116 bt_message_array_const *msgs, uint64_t *count);
118 extern bt_bool bt_port_output_message_iterator_can_seek_ns_from_origin(
119 bt_port_output_message_iterator *iterator,
120 int64_t ns_from_origin);
122 extern bt_bool bt_port_output_message_iterator_can_seek_beginning(
123 bt_port_output_message_iterator *iterator);
125 extern bt_message_iterator_status
126 bt_port_output_message_iterator_seek_ns_from_origin(
127 bt_port_output_message_iterator *iterator,
128 int64_t ns_from_origin);
130 extern bt_message_iterator_status
131 bt_port_output_message_iterator_seek_beginning(
132 bt_port_output_message_iterator *iterator);
134 extern void bt_port_output_message_iterator_get_ref(
135 const bt_port_output_message_iterator *port_output_message_iterator);
137 extern void bt_port_output_message_iterator_put_ref(
138 const bt_port_output_message_iterator *port_output_message_iterator);
140 /* Helper functions for Python */
142 static PyObject *bt_py3_get_user_component_from_user_msg_iter(
143 bt_self_message_iterator *self_message_iterator)
145 bt_self_component *self_component = bt_self_message_iterator_borrow_component(self_message_iterator);
148 BT_ASSERT(self_component);
149 py_comp = bt_self_component_get_data(self_component);
152 /* Return new reference */
158 PyObject *create_pylist_from_messages(bt_message_array_const messages,
159 uint64_t message_count)
162 PyObject *py_msg_list = PyList_New(message_count);
163 BT_ASSERT(py_msg_list);
164 for (i = 0; i < message_count; i++) {
165 PyList_SET_ITEM(py_msg_list, i,
166 SWIG_NewPointerObj(SWIG_as_voidptr(messages[i]),
167 SWIGTYPE_p_bt_message, 0));
174 PyObject *bt_py3_get_msg_range_common(bt_message_iterator_status status,
175 bt_message_array_const messages, uint64_t message_count)
178 PyObject *py_return_tuple;
179 PyObject *py_msg_list = Py_None;
181 py_status = SWIG_From_long_SS_long(status);
182 if (status != BT_MESSAGE_ITERATOR_STATUS_OK) {
186 py_msg_list = create_pylist_from_messages(messages, message_count);
189 py_return_tuple = PyTuple_New(2);
190 BT_ASSERT(py_return_tuple);
191 PyTuple_SET_ITEM(py_return_tuple, 0, py_status);
192 PyTuple_SET_ITEM(py_return_tuple, 1, py_msg_list);
194 return py_return_tuple;
198 *bt_py3_self_component_port_input_get_msg_range(
199 bt_self_component_port_input_message_iterator *iter)
201 bt_message_array_const messages;
202 uint64_t message_count = 0;
203 bt_message_iterator_status status;
205 status = bt_self_component_port_input_message_iterator_next(iter, &messages,
208 return bt_py3_get_msg_range_common(status, messages, message_count);
212 *bt_py3_port_output_get_msg_range(
213 bt_port_output_message_iterator *iter)
215 bt_message_array_const messages;
216 uint64_t message_count = 0;
217 bt_message_iterator_status status;
220 bt_port_output_message_iterator_next(iter, &messages,
223 return bt_py3_get_msg_range_common(status, messages, message_count);
227 PyObject *bt_py3_get_user_component_from_user_msg_iter(
228 bt_self_message_iterator *self_message_iterator);
229 PyObject *bt_py3_self_component_port_input_get_msg_range(
230 bt_self_component_port_input_message_iterator *iter);
231 PyObject *bt_py3_port_output_get_msg_range(
232 bt_port_output_message_iterator *iter);