forked from indilib/pyindi-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indiclientpython.i
227 lines (189 loc) · 5.85 KB
/
indiclientpython.i
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
%module(directors="1") PyIndi
%{
#include <indibase.h>
#include <indiapi.h>
#include <baseclient.h>
#include <basedevice.h>
#include <indiproperty.h>
#include <indiproperties.h>
#include <indipropertybasic.h>
#include <indipropertytext.h>
#include <indipropertynumber.h>
#include <indipropertyswitch.h>
#include <indipropertylight.h>
#include <indipropertyblob.h>
#include <stdexcept>
%}
%include "std_vector.i"
%include "std_except.i"
%include "std_string.i"
%include "stdint.i"
%implicitconv INDI::Property;
%feature("director") BaseMediator;
%feature("director") BaseClient;
%feature("director:except") {
if( $error != NULL ) {
PyObject *ptype, *pvalue, *ptraceback;
PyErr_Fetch( &ptype, &pvalue, &ptraceback );
PyErr_Restore( ptype, pvalue, ptraceback );
PyErr_Print();
Py_Exit(1);
}
}
%template(BaseDeviceVector) std::vector<INDI::BaseDevice *>;
%template(PropertyVector) std::vector<INDI::Property *>;
%include <indimacros.h>
%include <indibasetypes.h>
%include <indibase.h>
%include <indiapi.h>
%include <baseclient.h>
%include <basedevice.h>
%include <indiwidgettraits.h>
// INDI::PropertyView (low-level decorator for IXXXPropertyView)
// INDI::WidgetView (low-level decorator for IXXX)
%ignore INDI::PropertyView::apply;
%ignore INDI::PropertyView::define;
%ignore INDI::PropertyView::vapply;
%ignore INDI::PropertyView::vdefine;
%include <indipropertyview.h>
%exception {
try {
$action
} catch (std::out_of_range &e) {
SWIG_exception(SWIG_IndexError, "Index out of bounds");
}
}
%extend INDI::PropertyView {
const INDI::WidgetView<T> * __getitem__(int index) {
if (index >= $self->count()) {
throw std::out_of_range("Index out of bounds");
}
return $self->at(index);
}
int __len__() {
return $self->count();
}
}
%template(PropertyViewText) INDI::PropertyView<IText>;
%template(PropertyViewNumber) INDI::PropertyView<INumber>;
%template(PropertyViewSwitch) INDI::PropertyView<ISwitch>;
%template(PropertyViewLight) INDI::PropertyView<ILight>;
%template(PropertyViewBlob) INDI::PropertyView<IBLOB>;
%template(WidgetViewText) INDI::WidgetView<IText>;
%template(WidgetViewNumber) INDI::WidgetView<INumber>;
%template(WidgetViewSwitch) INDI::WidgetView<ISwitch>;
%template(WidgetViewLight) INDI::WidgetView<ILight>;
%template(WidgetViewBlob) INDI::WidgetView<IBLOB>;
// INDI::Property - generic container for INDI properties
%ignore INDI::Property::apply;
%ignore INDI::Property::define;
%ignore INDI::Property::vapply;
%ignore INDI::Property::vdefine;
%include <indiproperty.h>
// INDI::Property Typed -typed container for INDI properties
%ignore INDI::PropertyBasic::apply;
%ignore INDI::PropertyBasic::define;
%ignore INDI::PropertyBasic::vapply;
%ignore INDI::PropertyBasic::vdefine;
%ignore INDI::PropertyBasic::operator->;
%include <indipropertybasic.h>
%extend INDI::PropertyBasic {
const INDI::WidgetView<T> * __getitem__(int index) throw(std::out_of_range) {
if (index >= $self->size()) throw std::out_of_range("PropertyBasic index out of bounds");
return $self->at(index);
}
int __len__() {
return $self->size();
}
}
%template(PropertyBasicText) INDI::PropertyBasic<IText>;
%template(PropertyBasicNumber) INDI::PropertyBasic<INumber>;
%template(PropertyBasicSwitch) INDI::PropertyBasic<ISwitch>;
%template(PropertyBasicLight) INDI::PropertyBasic<ILight>;
%template(PropertyBasicBlob) INDI::PropertyBasic<IBLOB>;
%include <indipropertytext.h>
%include <indipropertynumber.h>
%include <indipropertyswitch.h>
%include <indipropertylight.h>
%include <indipropertyblob.h>
typedef enum {
B_NEVER=0,
B_ALSO,
B_ONLY
} BLOBHandling;
%extend _ITextVectorProperty {
IText *__getitem__(int index) throw(std::out_of_range) {
if (index >= $self->ntp) throw std::out_of_range("VectorProperty index out of bounds");
return $self->tp + index;
}
int __len__() {
return $self->ntp;
}
};
%extend _INumberVectorProperty {
INumber *__getitem__(int index) throw(std::out_of_range) {
if (index >= $self->nnp) throw std::out_of_range("VectorProperty index out of bounds");
return $self->np + index;
}
int __len__() {
return $self->nnp;
}
};
%extend _ISwitchVectorProperty {
ISwitch *__getitem__(int index) throw(std::out_of_range) {
if (index >= $self->nsp) throw std::out_of_range("VectorProperty index out of bounds");
return $self->sp + index;
}
int __len__() {
return $self->nsp;
}
};
%extend _ILightVectorProperty {
ILight *__getitem__(int index) throw(std::out_of_range) {
if (index >= $self->nlp) throw std::out_of_range("VectorProperty index out of bounds");
return $self->lp + index;
}
int __len__() {
return $self->nlp;
}
};
%extend _IBLOBVectorProperty {
IBLOB *__getitem__(int index) throw(std::out_of_range) {
if (index >= $self->nbp) throw std::out_of_range("VectorProperty index out of bounds");
return $self->bp + index;
}
int __len__() {
return $self->nbp;
}
};
%extend IBLOB {
PyObject *getblobdata() {
PyObject *result;
result = PyByteArray_FromStringAndSize((const char*) $self->blob, $self->size);
return result;
}
};
%ignore INDI::Properties::at;
%ignore INDI::Properties::front;
%ignore INDI::Properties::back;
%ignore INDI::Properties::empty;
%include <indiproperties.h>
%extend INDI::Properties {
INDI::Property * __getitem__(int index) throw(std::out_of_range) {
if ((unsigned int)index >= $self->size()) throw std::out_of_range("Properties index out of bounds");
return &($self->at(index));
}
int __len__() {
return $self->size();
}
}
%extend INDI::BaseClient {
%typemap(in) (char *data, long len) {
$1 = PyBytes_AsString($input);
$2 = PyBytes_Size($input);
}
public:
void sendOneBlobFromBuffer(const char *name, const char *type, char *data, long len) {
$self->sendOneBlob(name, len, type, (void*)(data));
}
}