| 1 |
// python-gphoto2 - Python interface to libgphoto2 |
| 2 |
// http://github.com/jim-easterbrook/python-gphoto2 |
| 3 |
// Copyright (C) 2014-24 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 |
%module(package="gphoto2") port_info_list |
| 21 |
|
| 22 |
%include "common/preamble.i" |
| 23 |
|
| 24 |
%rename(GPPortInfoList) _GPPortInfoList; |
| 25 |
%rename(GPPortInfo) _GPPortInfo; |
| 26 |
%pythoncode %{ |
| 27 |
PortInfoList = GPPortInfoList |
| 28 |
PortInfo = GPPortInfo |
| 29 |
%} |
| 30 |
|
| 31 |
// Deprecate some functions intended for camera drivers (2023-08-01) |
| 32 |
DEPRECATED(gp_port_info_list_append,) |
| 33 |
DEPRECATED(_GPPortInfoList::append, 1) |
| 34 |
|
| 35 |
%typemap(in, numinputs=0) GPPortInfo * (GPPortInfo temp) { |
| 36 |
temp = NULL; |
| 37 |
$1 = &temp; |
| 38 |
} |
| 39 |
%typemap(argout) GPPortInfo * { |
| 40 |
$result = SWIG_AppendOutput( |
| 41 |
$result, SWIG_NewPointerObj(*$1, $descriptor(_GPPortInfo*), 0)); |
| 42 |
} |
| 43 |
|
| 44 |
// Make docstring parameter types more Pythonic |
| 45 |
%typemap(doc) GPPortInfo "$1_name: gphoto2.$1_type"; |
| 46 |
%typemap(doc) GPPortInfoList * "$1_name: gphoto2.$*1_type"; |
| 47 |
|
| 48 |
// Turn on default exception handling |
| 49 |
DEFAULT_EXCEPTION |
| 50 |
|
| 51 |
// gp_port_info_list_new() returns a pointer in an output parameter |
| 52 |
PLAIN_ARGOUT(GPPortInfoList **) |
| 53 |
|
| 54 |
// gp_port_info_get_type returns a pointer to an enum |
| 55 |
%apply int *OUTPUT { GPPortType * }; |
| 56 |
|
| 57 |
// Make GPPortInfoList more like a Python list |
| 58 |
LEN_MEMBER_FUNCTION(_GPPortInfoList, gp_port_info_list_count) |
| 59 |
%feature("python:slot", "sq_item", functype="ssizeargfunc") _GPPortInfoList::__getitem__; |
| 60 |
%exception __getitem__ { |
| 61 |
$action |
| 62 |
if (PyErr_Occurred() != NULL) { |
| 63 |
goto fail; |
| 64 |
} |
| 65 |
} |
| 66 |
%extend _GPPortInfoList { |
| 67 |
void __getitem__(int idx, GPPortInfo *info) { |
| 68 |
if (idx < 0 || idx >= gp_port_info_list_count($self)) { |
| 69 |
PyErr_SetString(PyExc_IndexError, "GPPortInfoList index out of range"); |
| 70 |
return; |
| 71 |
} |
| 72 |
{ |
| 73 |
int error = gp_port_info_list_get_info($self, idx, info); |
| 74 |
if (error < GP_OK) { |
| 75 |
GPHOTO2_ERROR(error) |
| 76 |
return; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
}; |
| 81 |
|
| 82 |
// Add member methods to _GPPortInfo |
| 83 |
struct _GPPortInfo {}; |
| 84 |
MEMBER_FUNCTION(_GPPortInfo, |
| 85 |
void, get_name, (char **name), |
| 86 |
gp_port_info_get_name, ($self, name), ) |
| 87 |
MEMBER_FUNCTION(_GPPortInfo, |
| 88 |
void, get_path, (char **path), |
| 89 |
gp_port_info_get_path, ($self, path), ) |
| 90 |
MEMBER_FUNCTION(_GPPortInfo, |
| 91 |
void, get_type, (GPPortType *type), |
| 92 |
gp_port_info_get_type, ($self, type), ) |
| 93 |
|
| 94 |
// Add default constructor and destructor to _GPPortInfoList |
| 95 |
struct _GPPortInfoList {}; |
| 96 |
DEFAULT_CTOR(_GPPortInfoList, gp_port_info_list_new) |
| 97 |
DEFAULT_DTOR(_GPPortInfoList, gp_port_info_list_free) |
| 98 |
|
| 99 |
// Add member methods to _GPPortInfoList |
| 100 |
MEMBER_FUNCTION(_GPPortInfoList, |
| 101 |
void, append, (GPPortInfo info), |
| 102 |
gp_port_info_list_append, ($self, info), ) |
| 103 |
MEMBER_FUNCTION(_GPPortInfoList, |
| 104 |
void, load, (), |
| 105 |
gp_port_info_list_load, ($self), ) |
| 106 |
MEMBER_FUNCTION(_GPPortInfoList, |
| 107 |
int, count, (), |
| 108 |
gp_port_info_list_count, ($self), ) |
| 109 |
MEMBER_FUNCTION(_GPPortInfoList, |
| 110 |
int, lookup_path, (const char *path), |
| 111 |
gp_port_info_list_lookup_path, ($self, path), ) |
| 112 |
MEMBER_FUNCTION(_GPPortInfoList, |
| 113 |
int, lookup_name, (const char *name), |
| 114 |
gp_port_info_list_lookup_name, ($self, name), ) |
| 115 |
MEMBER_FUNCTION(_GPPortInfoList, |
| 116 |
void, get_info, (const int n, GPPortInfo *info), |
| 117 |
gp_port_info_list_get_info, ($self, n, info), ) |
| 118 |
|
| 119 |
// Substitute definitions of things added during libgphoto2 development |
| 120 |
%{ |
| 121 |
#if GPHOTO2_VERSION < 0x02051e00 |
| 122 |
static int gp_port_init_localedir(const char *localedir) { |
| 123 |
return GP_ERROR_NOT_SUPPORTED; |
| 124 |
} |
| 125 |
#endif |
| 126 |
#if GPHOTO2_VERSION < 0x02051800 |
| 127 |
int GP_PORT_IP = GP_PORT_USB_SCSI + 1; |
| 128 |
#endif |
| 129 |
%} |
| 130 |
|
| 131 |
// Don't wrap internal functions |
| 132 |
%ignore gp_port_info_new; |
| 133 |
%ignore gp_port_info_set_name; |
| 134 |
%ignore gp_port_info_set_path; |
| 135 |
%ignore gp_port_info_set_type; |
| 136 |
%ignore gp_port_info_get_library_filename; |
| 137 |
%ignore gp_port_info_set_library_filename; |
| 138 |
%ignore gp_port_info_list_free; |
| 139 |
|
| 140 |
// Turn off default exception handling |
| 141 |
%noexception; |
| 142 |
|
| 143 |
%include "gphoto2/gphoto2-port-info-list.h" |