| 1 |
// python-gphoto2 - Python interface to libgphoto2 |
| 2 |
// http://github.com/jim-easterbrook/python-gphoto2 |
| 3 |
// Copyright (C) 2017-25 Jim Easterbrook [email protected] |
| 4 |
// |
| 5 |
// This file is part of python-gphoto2. |
| 6 |
// |
| 7 |
// python-gphoto2 is free software: you can redistribute it and/or modify |
| 8 |
// it under the terms of the GNU Lesser General Public License as published |
| 9 |
// by the Free Software Foundation, either version 3 of the License, or |
| 10 |
// (at your option) any later version. |
| 11 |
// |
| 12 |
// python-gphoto2 is distributed in the hope that it will be useful, |
| 13 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
// GNU Lesser General Public License for more details. |
| 16 |
// |
| 17 |
// You should have received a copy of the GNU Lesser General Public License |
| 18 |
// along with python-gphoto2. If not, see <https://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// Stuff to go at the top of every gphoto2 .i file |
| 21 |
|
| 22 |
// C header file |
| 23 |
%{ |
| 24 |
#include "gphoto2/gphoto2.h" |
| 25 |
%} |
| 26 |
|
| 27 |
// Include our macros and swig's typemaps |
| 28 |
%include "common/macros.i" |
| 29 |
%include "typemaps.i" |
| 30 |
|
| 31 |
// Include doxygen documentation |
| 32 |
#if defined(DOC_FILE) |
| 33 |
%include DOC_FILE |
| 34 |
#endif |
| 35 |
%feature("autodoc", "2"); |
| 36 |
|
| 37 |
// Provide our own version of macros added in SWIG 4.3.0 |
| 38 |
#if SWIG_VERSION < 0x040300 |
| 39 |
%{ |
| 40 |
#define SWIG_Py_INCREF Py_INCREF |
| 41 |
#define SWIG_Py_XINCREF Py_XINCREF |
| 42 |
#define SWIG_Py_DECREF Py_DECREF |
| 43 |
#define SWIG_Py_XDECREF Py_XDECREF |
| 44 |
%} |
| 45 |
#endif |
| 46 |
|
| 47 |
// Improve documentation of some parameter types |
| 48 |
%typemap(doc) char const * "$1_name: str" |
| 49 |
%typemap(doc) uint64_t "$1_name: int" |
| 50 |
|
| 51 |
// Convert all char ** parameters to string return value |
| 52 |
%typemap(in, numinputs=0) char ** (char *temp) { |
| 53 |
temp = NULL; |
| 54 |
$1 = &temp; |
| 55 |
} |
| 56 |
%typemap(argout) char ** { |
| 57 |
$result = SWIG_AppendOutput($result, |
| 58 |
*$1 ? PyString_FromString(*$1) : SWIG_Py_Void()); |
| 59 |
} |
| 60 |
|
| 61 |
// Get PyExc_GPhoto2Error object |
| 62 |
%{ |
| 63 |
PyObject *PyExc_GPhoto2Error = NULL; |
| 64 |
%} |
| 65 |
%init %{ |
| 66 |
{ |
| 67 |
PyObject *module = PyImport_ImportModule("gphoto2"); |
| 68 |
if (module != NULL) { |
| 69 |
PyExc_GPhoto2Error = PyObject_GetAttrString(module, "GPhoto2Error"); |
| 70 |
SWIG_Py_DECREF(module); |
| 71 |
} |
| 72 |
if (PyExc_GPhoto2Error == NULL) |
| 73 |
#if PY_VERSION_HEX >= 0x03000000 |
| 74 |
return NULL; |
| 75 |
#else |
| 76 |
return; |
| 77 |
#endif |
| 78 |
} |
| 79 |
%} |