| 1 | /* |
| 2 | * The MIT License (MIT) |
| 3 | * |
| 4 | * Copyright (c) 2016 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 | #ifndef SWIGPYTHON |
| 26 | # error Unsupported output language |
| 27 | #endif |
| 28 | |
| 29 | %module native_bt |
| 30 | |
| 31 | %{ |
| 32 | #define BT_LOG_TAG "PY-NATIVE" |
| 33 | #include "logging.h" |
| 34 | |
| 35 | #include <babeltrace/babeltrace.h> |
| 36 | #include <babeltrace/assert-internal.h> |
| 37 | |
| 38 | typedef const unsigned char *BTUUID; |
| 39 | %} |
| 40 | |
| 41 | typedef int bt_bool; |
| 42 | |
| 43 | /* For uint*_t/int*_t */ |
| 44 | %include "stdint.i" |
| 45 | |
| 46 | /* Remove `bt_` and `BT_` prefixes from function names and enumeration items */ |
| 47 | %rename("%(strip:[bt_])s", %$isfunction) ""; |
| 48 | %rename("%(strip:[BT_])s", %$isenumitem) ""; |
| 49 | |
| 50 | /* Output argument typemap for string output (always appends) */ |
| 51 | %typemap(in, numinputs=0) const char **BTOUTSTR (char *temp_value = NULL) { |
| 52 | $1 = &temp_value; |
| 53 | } |
| 54 | |
| 55 | %typemap(argout) const char **BTOUTSTR { |
| 56 | if (*$1) { |
| 57 | /* SWIG_Python_AppendOutput() steals the created object */ |
| 58 | $result = SWIG_Python_AppendOutput($result, SWIG_Python_str_FromChar(*$1)); |
| 59 | } else { |
| 60 | /* SWIG_Python_AppendOutput() steals Py_None */ |
| 61 | Py_INCREF(Py_None); |
| 62 | $result = SWIG_Python_AppendOutput($result, Py_None); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /* Output argument typemap for field type output (always appends) */ |
| 67 | %typemap(in, numinputs=0) struct bt_field_type **BTOUTFT (struct bt_field_type *temp_ft = NULL) { |
| 68 | $1 = &temp_ft; |
| 69 | } |
| 70 | |
| 71 | %typemap(argout) struct bt_field_type **BTOUTFT { |
| 72 | if (*$1) { |
| 73 | /* SWIG_Python_AppendOutput() steals the created object */ |
| 74 | $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_field_type, 0)); |
| 75 | } else { |
| 76 | /* SWIG_Python_AppendOutput() steals Py_None */ |
| 77 | Py_INCREF(Py_None); |
| 78 | $result = SWIG_Python_AppendOutput($result, Py_None); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /* Output argument typemap for component output (always appends) */ |
| 83 | %typemap(in, numinputs=0) struct bt_component **BTOUTCOMP (struct bt_component *temp_comp = NULL) { |
| 84 | $1 = &temp_comp; |
| 85 | } |
| 86 | |
| 87 | %typemap(argout) struct bt_component **BTOUTCOMP { |
| 88 | if (*$1) { |
| 89 | /* SWIG_Python_AppendOutput() steals the created object */ |
| 90 | $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_component, 0)); |
| 91 | } else { |
| 92 | /* SWIG_Python_AppendOutput() steals Py_None */ |
| 93 | Py_INCREF(Py_None); |
| 94 | $result = SWIG_Python_AppendOutput($result, Py_None); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /* Output argument typemap for connection output (always appends) */ |
| 99 | %typemap(in, numinputs=0) struct bt_connection **BTOUTCONN (struct bt_connection *temp_conn = NULL) { |
| 100 | $1 = &temp_conn; |
| 101 | } |
| 102 | |
| 103 | %typemap(argout) struct bt_connection **BTOUTCONN { |
| 104 | if (*$1) { |
| 105 | /* SWIG_Python_AppendOutput() steals the created object */ |
| 106 | $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_connection, 0)); |
| 107 | } else { |
| 108 | /* SWIG_Python_AppendOutput() steals Py_None */ |
| 109 | Py_INCREF(Py_None); |
| 110 | $result = SWIG_Python_AppendOutput($result, Py_None); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /* Output argument typemap for private port output (always appends) */ |
| 115 | %typemap(in, numinputs=0) struct bt_private_port **BTOUTPRIVPORT (struct bt_private_port *temp_priv_port = NULL) { |
| 116 | $1 = &temp_priv_port; |
| 117 | } |
| 118 | |
| 119 | %typemap(argout) struct bt_private_port **BTOUTPRIVPORT { |
| 120 | if (*$1) { |
| 121 | /* SWIG_Python_AppendOutput() steals the created object */ |
| 122 | $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_private_port, 0)); |
| 123 | } else { |
| 124 | /* SWIG_Python_AppendOutput() steals Py_None */ |
| 125 | Py_INCREF(Py_None); |
| 126 | $result = SWIG_Python_AppendOutput($result, Py_None); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /* Output argument typemap for value output (always appends) */ |
| 131 | %typemap(in, numinputs=0) struct bt_value **BTOUTVALUE (struct bt_value *temp_value = NULL) { |
| 132 | $1 = &temp_value; |
| 133 | } |
| 134 | |
| 135 | %typemap(argout) struct bt_value **BTOUTVALUE { |
| 136 | if (*$1) { |
| 137 | /* SWIG_Python_AppendOutput() steals the created object */ |
| 138 | $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr(*$1), SWIGTYPE_p_bt_value, 0)); |
| 139 | } else { |
| 140 | /* SWIG_Python_AppendOutput() steals Py_None */ |
| 141 | Py_INCREF(Py_None); |
| 142 | $result = SWIG_Python_AppendOutput($result, Py_None); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /* Output argument typemap for initialized uint64_t output parameter (always appends) */ |
| 147 | %typemap(in, numinputs=0) uint64_t *OUTPUTINIT (uint64_t temp = -1ULL) { |
| 148 | $1 = &temp; |
| 149 | } |
| 150 | |
| 151 | %typemap(argout) uint64_t *OUTPUTINIT { |
| 152 | $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_unsigned_SS_long_SS_long((*$1))); |
| 153 | } |
| 154 | |
| 155 | /* Output argument typemap for initialized unsigned int output parameter (always appends) */ |
| 156 | %typemap(in, numinputs=0) unsigned int *OUTPUTINIT (unsigned int temp = -1) { |
| 157 | $1 = &temp; |
| 158 | } |
| 159 | |
| 160 | %typemap(argout) unsigned int *OUTPUTINIT { |
| 161 | $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_unsigned_SS_long_SS_long((uint64_t) (*$1))); |
| 162 | } |
| 163 | |
| 164 | /* Input argument typemap for UUID bytes */ |
| 165 | %typemap(in) BTUUID { |
| 166 | $1 = (unsigned char *) PyBytes_AsString($input); |
| 167 | } |
| 168 | |
| 169 | /* Output argument typemap for UUID bytes */ |
| 170 | %typemap(out) BTUUID { |
| 171 | if (!$1) { |
| 172 | Py_INCREF(Py_None); |
| 173 | $result = Py_None; |
| 174 | } else { |
| 175 | $result = PyBytes_FromStringAndSize((const char *) $1, 16); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Input and output argument typemaps for raw Python objects (direct). |
| 181 | * |
| 182 | * Those typemaps honor the convention of Python C function calls with |
| 183 | * respect to reference counting: parameters are passed as borrowed |
| 184 | * references, and objects are returned as new references. The wrapped |
| 185 | * C function must ensure that the return value is always a new |
| 186 | * reference, and never steal parameter references. |
| 187 | */ |
| 188 | %typemap(in) PyObject * { |
| 189 | $1 = $input; |
| 190 | } |
| 191 | |
| 192 | %typemap(out) PyObject * { |
| 193 | $result = $1; |
| 194 | } |
| 195 | |
| 196 | %{ |
| 197 | static enum bt_notification_type *bt_py3_notif_types_from_py_list( |
| 198 | PyObject *py_notif_types) |
| 199 | { |
| 200 | enum bt_notification_type *notification_types = NULL; |
| 201 | size_t i; |
| 202 | |
| 203 | BT_ASSERT(!PyErr_Occurred()); |
| 204 | |
| 205 | if (py_notif_types == Py_None) { |
| 206 | goto end; |
| 207 | } |
| 208 | |
| 209 | BT_ASSERT(PyList_Check(py_notif_types)); |
| 210 | notification_types = g_new0(enum bt_notification_type, |
| 211 | PyList_Size(py_notif_types) + 1); |
| 212 | BT_ASSERT(notification_types); |
| 213 | notification_types[PyList_Size(py_notif_types)] = |
| 214 | BT_NOTIFICATION_TYPE_SENTINEL; |
| 215 | |
| 216 | for (i = 0; i < PyList_Size(py_notif_types); i++) { |
| 217 | PyObject *item = PyList_GetItem(py_notif_types, i); |
| 218 | long value; |
| 219 | int overflow; |
| 220 | |
| 221 | BT_ASSERT(item); |
| 222 | BT_ASSERT(PyLong_Check(item)); |
| 223 | value = PyLong_AsLongAndOverflow(item, &overflow); |
| 224 | BT_ASSERT(overflow == 0); |
| 225 | notification_types[i] = value; |
| 226 | } |
| 227 | |
| 228 | end: |
| 229 | return notification_types; |
| 230 | } |
| 231 | %} |
| 232 | |
| 233 | /* Per-module interface files */ |
| 234 | %include "native_btccpriomap.i" |
| 235 | %include "native_btclockclass.i" |
| 236 | %include "native_btcomponent.i" |
| 237 | %include "native_btcomponentclass.i" |
| 238 | %include "native_btconnection.i" |
| 239 | %include "native_btctfwriter.i" |
| 240 | %include "native_btevent.i" |
| 241 | %include "native_bteventclass.i" |
| 242 | %include "native_btfields.i" |
| 243 | %include "native_btft.i" |
| 244 | %include "native_btgraph.i" |
| 245 | %include "native_btlogging.i" |
| 246 | %include "native_btnotification.i" |
| 247 | %include "native_btnotifiter.i" |
| 248 | %include "native_btpacket.i" |
| 249 | %include "native_btplugin.i" |
| 250 | %include "native_btport.i" |
| 251 | %include "native_btqueryexec.i" |
| 252 | %include "native_btref.i" |
| 253 | %include "native_btstream.i" |
| 254 | %include "native_btstreamclass.i" |
| 255 | %include "native_bttrace.i" |
| 256 | %include "native_btvalues.i" |
| 257 | %include "native_btversion.i" |