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
27 struct bt_private_connection;
30 enum bt_connection_status {
31 BT_CONNECTION_STATUS_GRAPH_IS_CANCELED = 125,
32 BT_CONNECTION_STATUS_OK = 0,
33 BT_CONNECTION_STATUS_INVALID = -22,
34 BT_CONNECTION_STATUS_ERROR = -1,
35 BT_CONNECTION_STATUS_NOMEM = -12,
36 BT_CONNECTION_STATUS_IS_ENDED = 104,
39 /* Functions (public) */
40 struct bt_port *bt_connection_get_downstream_port(
41 struct bt_connection *connection);
42 struct bt_port *bt_connection_get_upstream_port(
43 struct bt_connection *connection);
44 int bt_connection_is_ended(struct bt_connection *connection);
46 /* Functions (private) */
47 struct bt_connection *bt_connection_from_private_connection(
48 struct bt_private_connection *private_connection);
50 /* Helper functions for Python */
51 %typemap(out) struct bt_py3_create_notif_iter_ret {
52 $result = PyTuple_New(2);
53 PyObject *py_notif_iter_ptr = SWIG_NewPointerObj(
54 SWIG_as_voidptr($1.notif_iter),
55 SWIGTYPE_p_bt_notification_iterator, 0);
56 PyObject *py_status = SWIG_From_long_SS_long($1.status);
57 PyTuple_SET_ITEM($result, 0, py_status);
58 PyTuple_SET_ITEM($result, 1, py_notif_iter_ptr);
62 struct bt_py3_create_notif_iter_ret {
63 enum bt_connection_status status;
64 struct bt_notification_iterator *notif_iter;
67 static struct bt_py3_create_notif_iter_ret bt_py3_create_notif_iter(
68 unsigned long long priv_conn_addr, PyObject *py_notif_types)
70 struct bt_private_connection *priv_conn;
71 enum bt_notification_type *notification_types = NULL;
72 struct bt_py3_create_notif_iter_ret ret;
74 priv_conn = (void *) priv_conn_addr;
75 assert(!PyErr_Occurred());
78 if (py_notif_types != Py_None) {
81 assert(PyList_Check(py_notif_types));
82 notification_types = g_new0(enum bt_notification_type,
83 PyList_Size(py_notif_types) + 1);
84 assert(notification_types);
85 notification_types[PyList_Size(py_notif_types)] =
86 BT_NOTIFICATION_TYPE_SENTINEL;
88 for (i = 0; i < PyList_Size(py_notif_types); i++) {
89 PyObject *item = PyList_GetItem(py_notif_types, i);
94 assert(PyLong_Check(item));
95 value = PyLong_AsLongAndOverflow(item, &overflow);
96 assert(overflow == 0);
97 notification_types[i] = value;
101 ret.status = bt_private_connection_create_notification_iterator(
102 priv_conn, notification_types, &ret.notif_iter);
104 if (notification_types) {
105 g_free(notification_types);
112 struct bt_py3_create_notif_iter_ret bt_py3_create_notif_iter(
113 unsigned long long priv_conn_addr, PyObject *notif_types);