-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlsf.i
More file actions
232 lines (189 loc) · 5.41 KB
/
Copy pathlsf.i
File metadata and controls
232 lines (189 loc) · 5.41 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
* Copyright (C) 2010-2012 Platform Computing
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* File: lsf.i */
%module lsf
%include "cpointer.i"
%include "carrays.i"
%{
#define SWIG_FILE_WITH_INIT
#include "/usr/share/lsf/8.0/include/lsf/lsf.h"
#include "/usr/share/lsf/8.0/include/lsf/lsbatch.h"
%}
%pointer_functions(int, intp)
%pointer_functions(float, floatp)
%array_class(struct queueInfoEnt, queueInfoEntArray);
%array_class(struct hostInfoEnt, hostInfoEntArray);
// howto handle char **
%typemap(in) char ** {
if ($input == Py_None) {
$1 = NULL;
} else if (PyList_Check($input)) {
int size = PyList_Size($input);
int i = 0;
$1 = (char **) malloc((size+1)*sizeof(char *));
for (i = 0; i < size; i++) {
PyObject *o = PyList_GetItem($input,i);
if (PyString_Check(o))
$1[i] = PyString_AsString(PyList_GetItem($input,i));
else {
PyErr_SetString(PyExc_TypeError,"list must contain strings");
free($1);
return NULL;
}
}
$1[i] = 0;
} else {
PyErr_SetString(PyExc_TypeError,"not a list");
return NULL;
}
}
%typemap(freearg) char ** {
free((char *) $1);
}
%typemap(out) char ** {
int len,i;
len = 0;
while ($1[len]) len++;
$result = PyList_New(len);
for (i = 0; i < len; i++) {
PyList_SetItem($result,i,PyString_FromString($1[i]));
}
}
// handle int arrays
%typemap(in) int [ANY] (int temp[$1_dim0]) {
int i;
for (i = 0; i < $1_dim0; i++) {
PyObject *o = PySequence_GetItem($input,i);
temp[i] = (int) PyInt_AsLong(o);
}
$1 = temp;
}
// See github issue 1
//%typemap(freearg) int [ANY] {
// free((int *) $1);
//}
%typemap(out) int [ANY] {
int i;
$result = PyList_New($1_dim0);
for (i = 0; i < $1_dim0; i++) {
PyObject *o = PyLong_FromDouble((int) $1[i]);
PyList_SetItem($result,i,o);
}
}
// typemap for time_t
%typemap(in) time_t {
$1 = (time_t) PyLong_AsLong($input);
}
%typemap(freearg) time_t {
free((time_t *) $1);
}
%typemap(out) time_t {
$result = PyLong_FromLong((long)$1);
}
/*
The following routines are not wrapped because SWIG has issues generating
proper code for them
*/
// Following are ignored from lsf.h
%ignore getBEtime;
%ignore ls_gethostrespriority;
%ignore ls_loadoftype;
%ignore ls_lostconnection;
%ignore ls_nioclose;
%ignore ls_nioctl;
%ignore ls_niodump;
%ignore ls_nioinit;
%ignore ls_niokill;
%ignore ls_nionewtask;
%ignore ls_nioread;
%ignore ls_nioremovetask;
%ignore ls_nioselect;
%ignore ls_niosetdebug;
%ignore ls_niostatus;
%ignore ls_niotasks;
%ignore ls_niowrite;
%ignore ls_placeoftype;
%ignore ls_readrexlog;
%ignore ls_verrlog;
// Following are ignored from lsbatch.h
%ignore lsb_readstatusline;
// Now include the rest...
%include "/usr/share/lsf/8.0/include/lsf/lsf.h"
%include "/usr/share/lsf/8.0/include/lsf/lsbatch.h"
%inline %{
PyObject * get_host_names() {
struct hostInfo *hostinfo;
char *resreq;
int numhosts = 0;
int options = 0;
resreq="";
hostinfo = ls_gethostinfo(resreq, &numhosts, NULL, 0, options);
PyObject *result = PyList_New(numhosts);
int i;
for (i = 0; i < numhosts; i++) {
PyObject *o = PyString_FromString(hostinfo[i].hostName);
PyList_SetItem(result,i,o);
}
return result;
}
PyObject * get_host_info() {
struct hostInfo *hostinfo;
char *resreq;
int numhosts = 0;
int options = 0;
resreq = "";
hostinfo = ls_gethostinfo(resreq, &numhosts, NULL, 0, options);
PyObject *result = PyList_New(numhosts);
int i;
for (i = 0; i < numhosts; i++) {
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&hostinfo[i]),
SWIGTYPE_p_hostInfo, 0 | 0 );
PyList_SetItem(result,i,o);
}
return result;
}
PyObject * get_load_of_hosts() {
struct hostLoad *hostload;
char *resreq;
int numhosts = 0;
int options = 0;
resreq = "";
hostload = ls_loadofhosts(resreq, &numhosts, 0, NULL, NULL, 0);
PyObject *result = PyList_New(numhosts);
int i;
for (i = 0; i < numhosts; i++) {
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&hostload[i]),
SWIGTYPE_p_hostLoad, 0 | 0 );
PyList_SetItem(result,i,o);
}
return result;
}
PyObject * get_host_load(char *resreq, int index) {
struct hostLoad *hosts;
int numhosts = 0;
int options = 0;
char *fromhost = NULL;
hosts = ls_load(resreq, &numhosts, options, fromhost);
if (hosts == NULL || numhosts > 1) {
ls_perror("ls_load");
exit(-1);
}
PyObject *result = PyFloat_FromDouble(hosts[0].li[index]);
return result;
}
%}