1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
* pi-file-maps.i
*
* Provide our own wrappers for pi_file_install and pi_file_retrieve
*
* Copyright (c) 2005, Florent Pillet.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
* General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $Id: pi-file-maps.i,v 1.7 2006/05/31 17:59:55 desrod Exp $
*/
// TODO: handle callback functions (ignored for now)
%native(pi_file_install) PyObject *_wrap_pi_file_install(PyObject *, PyObject *);
%native(pi_file_retrieve) PyObject *_wrap_pi_file_retrieve(PyObject *, PyObject *);
%wrapper %{
/*
* Python syntax: pi_file_install(sd, cardno, filename, callback)
*/
static PyObject *_wrap_pi_file_install (PyObject *self, PyObject *args)
{
PyObject *obj1 = NULL;
PyObject *obj2 = NULL;
PyObject *obj3 = NULL;
PyObject *cback = NULL;
int sd, cardno, result;
char *path = NULL;
pi_file_t *pf = NULL;
if (!PyArg_ParseTuple(args,(char *)"OOOO:pi_file_install",&obj1, &obj2, &obj3, &cback))
return NULL;
sd = (int)SWIG_As_int(obj1);
cardno = (int)SWIG_As_int(obj2);
if (!SWIG_AsCharPtr(obj3, (char**)&path)) {
SWIG_arg_fail(3);
return NULL;
}
pf = pi_file_open(path);
if (pf == NULL) {
PyErr_SetObject(PIError, Py_BuildValue("(is)", PI_ERR_FILE_INVALID, "invalid file"));
return NULL;
}
{
PyThreadState *save = PyEval_SaveThread();
result = pi_file_install(pf, sd, cardno, NULL);
PyEval_RestoreThread(save);
}
pi_file_close(pf);
if (result < 0) {
pythonWrapper_handlePiErr(sd, result);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
/*
* Python syntax: pi_file_retrieve(sd, cardno, dbname, storagepath, callback)
*/
static PyObject *_wrap_pi_file_retrieve (PyObject *self, PyObject *args)
{
PyObject *obj1 = NULL;
PyObject *obj2 = NULL;
PyObject *obj3 = NULL;
PyObject *obj4 = NULL;
PyObject *cback = NULL;
int sd, cardno, result;
char *dbname = NULL;
char *path = NULL;
struct DBInfo dbi;
pi_file_t *pf = NULL;
PyThreadState *save;
if (!PyArg_ParseTuple(args, (char *)"OOOOO:pi_file_retrieve",&obj1,&obj2,&obj3,&obj4,&cback))
return NULL;
sd = SWIG_As_int(obj1);
cardno = SWIG_As_int(obj2);
if (!SWIG_AsCharPtr(obj3, (char**)&dbname)) {
SWIG_arg_fail(3);
return NULL;
}
if (!SWIG_AsCharPtr(obj4, (char **)&path)) {
SWIG_arg_fail(4);
return NULL;
}
/* let other threads run */
save = PyEval_SaveThread();
memset(&dbi, 0, sizeof(dbi));
result = dlp_FindDBByName(sd, cardno, dbname, NULL, NULL, &dbi, NULL);
if (result < 0) {
PyEval_RestoreThread(save);
pythonWrapper_handlePiErr(sd, result);
return NULL;
}
pf = pi_file_create(path, &dbi);
if (pf == NULL) {
PyEval_RestoreThread(save);
PyErr_SetObject(PIError, Py_BuildValue("(is)", PI_ERR_FILE_INVALID, "invalid file"));
return NULL;
}
result = pi_file_retrieve(pf, sd, cardno, NULL);
if (result < 0) {
PyEval_RestoreThread(save);
pythonWrapper_handlePiErr(sd, result);
return NULL;
}
result = pi_file_close(pf);
PyEval_RestoreThread(save);
if (result < 0) {
pythonWrapper_handlePiErr(sd, result);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
%}
|