Debian Codegraph @

src/gphoto2/abilities_list.i

raw
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") abilities_list
21
22 %include "common/preamble.i"
23
24 %import "context.i"
25 %import "list.i"
26 %import "port_info_list.i"
27
28 %rename(CameraAbilitiesList) _CameraAbilitiesList;
29
30 // Deprecate some functions intended for camera drivers (2023-07-25)
31 DEPRECATED(gp_abilities_list_append,)
32 DEPRECATED(_CameraAbilitiesList::append, 1)
33
34 // Make docstring parameter types more Pythonic
35 %typemap(doc) CameraAbilities "$1_name: gphoto2.$1_type"
36 %typemap(doc) CameraAbilitiesList * "$1_name: gphoto2.$*1_type"
37
38 // Turn on default exception handling
39 DEFAULT_EXCEPTION
40
41 // Many functions accept NULL context value
42 DEFAULT_CONTEXT
43
44 // gp_abilities_list_get_abilities() returns a pointer in an output parameter
45 CALLOC_ARGOUT(CameraAbilities *abilities)
46
47 // gp_abilities_list_detect() returns a pointer in an output parameter
48 NEW_ARGOUT(CameraList *, gp_list_new, gp_list_unref)
49
50 // gp_abilities_list_new() returns a pointer in an output parameter
51 PLAIN_ARGOUT(CameraAbilitiesList **)
52
53 // Add default constructor and destructor to _CameraAbilitiesList
54 struct _CameraAbilitiesList {};
55 DEFAULT_CTOR(_CameraAbilitiesList, gp_abilities_list_new)
56 DEFAULT_DTOR(_CameraAbilitiesList, gp_abilities_list_free)
57 %ignore gp_abilities_list_free;
58
59 // Make CameraAbilitiesList more like a Python list
60 LEN_MEMBER_FUNCTION(_CameraAbilitiesList, gp_abilities_list_count)
61 %feature("python:slot", "sq_item", functype="ssizeargfunc")
62 _CameraAbilitiesList::__getitem__;
63 %exception __getitem__ {
64 $action
65 if (PyErr_Occurred() != NULL) goto fail;
66 }
67 %extend _CameraAbilitiesList {
68 void __getitem__(int idx, CameraAbilities *abilities) {
69 if (idx < 0 || idx >= gp_abilities_list_count($self)) {
70 PyErr_SetString(PyExc_IndexError, "CameraAbilitiesList index out of range");
71 return;
72 }
73 {
74 int error = gp_abilities_list_get_abilities($self, idx, abilities);
75 if (error < GP_OK) {
76 GPHOTO2_ERROR(error)
77 return;
78 }
79 }
80 }
81 };
82
83 // Convert array of serial port speeds to Python list
84 %typemap(out) int speed [64] {
85 int *value = $1;
86 $result = PyList_New(0);
87 while (*value) {
88 PyObject* temp = PyInt_FromLong(*value);
89 PyList_Append($result, temp);
90 SWIG_Py_DECREF(temp);
91 value++;
92 }
93 }
94
95 // Substitute definitions of things added during libgphoto2 development
96 %{
97 #if GPHOTO2_VERSION < 0x02051e00
98 static int gp_init_localedir(const char *localedir) {
99 return GP_ERROR_NOT_SUPPORTED;
100 }
101 #endif
102 %}
103
104 // Add member methods to _CameraAbilitiesList
105 MEMBER_FUNCTION(_CameraAbilitiesList,
106 void, load, (GPContext *context),
107 gp_abilities_list_load, ($self, context), )
108 MEMBER_FUNCTION(_CameraAbilitiesList,
109 void, load_dir, (const char *dir, GPContext *context),
110 gp_abilities_list_load_dir, ($self, dir, context), )
111 MEMBER_FUNCTION(_CameraAbilitiesList,
112 void, reset, (),
113 gp_abilities_list_reset, ($self), )
114 MEMBER_FUNCTION(_CameraAbilitiesList,
115 void, detect, (GPPortInfoList *info_list, CameraList *l, GPContext *context),
116 gp_abilities_list_detect, ($self, info_list, l, context), )
117 MEMBER_FUNCTION(_CameraAbilitiesList,
118 void, append, (CameraAbilities abilities),
119 gp_abilities_list_append, ($self, abilities), )
120 MEMBER_FUNCTION(_CameraAbilitiesList,
121 int, count, (),
122 gp_abilities_list_count, ($self), )
123 MEMBER_FUNCTION(_CameraAbilitiesList,
124 int, lookup_model, (const char *model),
125 gp_abilities_list_lookup_model, ($self, model), )
126 MEMBER_FUNCTION(_CameraAbilitiesList,
127 void, get_abilities, (int index, CameraAbilities *abilities),
128 gp_abilities_list_get_abilities, ($self, index, abilities), )
129
130 // Structures are read only
131 %immutable;
132
133 // Turn off default exception handling
134 %noexception;
135
136 %include "gphoto2/gphoto2-abilities-list.h"