Debian Codegraph @

Xpjproject/pjsip-apps/src/swig/pjsua2.i

raw
1 %module(directors="1") pjsua2
2
3 //
4 // Suppress few warnings
5 //
6 #pragma SWIG nowarn=312 // 312: nested struct (in types.h, sip_auth.h)
7
8 //
9 // Header section
10 //
11 %{
12 #include "pjsua2.hpp"
13 using namespace std;
14 using namespace pj;
15 %}
16
17 //
18 // STL stuff.
19 //
20 %include "std_string.i"
21 %include "std_vector.i"
22 %include "std_map.i"
23
24 // Android string handling
25 %include "and_string.i"
26
27 %template(StringVector) std::vector<std::string>;
28 %template(IntVector) std::vector<int>;
29 %template(ByteVector) std::vector<unsigned char>;
30 %template(StringToStringMap) std::map<string, string>;
31
32 #ifdef SWIGPYTHON
33 %feature("director:except") {
34 if( $error != NULL ) {
35 PyObject *ptype, *pvalue, *ptraceback;
36 PyErr_Fetch( &ptype, &pvalue, &ptraceback );
37 PyErr_Restore( ptype, pvalue, ptraceback );
38 PyErr_Print();
39 //Py_Exit(1);
40 }
41 }
42
43 %typemap(out) void* {
44 $result = PyLong_FromVoidPtr($1);
45 }
46
47 %apply void* { pj_oshandle_t };
48
49 %extend std::vector<unsigned char> {
50 void assign_from_bytes(PyObject* obj) {
51 Py_buffer view;
52 if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0) {
53 SWIG_Python_RaiseOrModifyTypeError("expected a bytes-like object (bytes, bytearray, memoryview)");
54 return;
55 }
56 $self->assign((unsigned char*)view.buf, (unsigned char*)view.buf + view.len);
57 PyBuffer_Release(&view);
58 }
59 void copy_to_bytearray(PyObject* obj) {
60 // Not using return value here, because in SWIG, using return value will cause one more copy
61 Py_buffer view;
62 if (PyObject_GetBuffer(obj, &view, PyBUF_WRITABLE) != 0) {
63 SWIG_Python_RaiseOrModifyTypeError("expected a writable bytes-like object (bytearray, memoryview)");
64 return;
65 }
66 if (view.len < (Py_ssize_t)$self->size()) {
67 PyBuffer_Release(&view);
68 SWIG_Python_RaiseOrModifyTypeError("bytearray too small");
69 return;
70 }
71 if ($self->size() > 0) {
72 memcpy(view.buf, $self->data(), $self->size());
73 }
74 PyBuffer_Release(&view);
75 }
76 }
77 #endif
78
79 #ifdef SWIGCSHARP
80 %typemap(throws, canthrow=1) pj::Error {
81 SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException,
82 (std::string("C++ pj::Error:\n") + $1.info(true).c_str()).c_str());
83
84 return $null;
85 }
86 %typemap(ctype) void* "void *"
87 %typemap(imtype) void* "System.IntPtr"
88 %typemap(cstype) void* "System.IntPtr"
89 %typemap(csin) void* "$csinput"
90 %typemap(in) void* %{ $1 = $input; %}
91 %typemap(out) void* %{ $result = $1; %}
92 %typemap(csout, excode=SWIGEXCODE) void* {
93 System.IntPtr cPtr = $imcall;$excode
94 return cPtr;
95 }
96 %typemap(csvarout, excode=SWIGEXCODE2) void* %{
97 get {
98 System.IntPtr cPtr = $imcall;$excode
99 return cPtr;
100 }
101 %}
102 #endif
103
104 #ifdef SWIGJAVA
105 // Allow C++ exceptions to be handled in Java
106 %typemap(throws, throws="java.lang.Exception") pj::Error {
107 jclass excep = jenv->FindClass("java/lang/Exception");
108 if (excep)
109 jenv->ThrowNew(excep, $1.info(true).c_str());
110 return $null;
111 }
112
113 // Force the Error Java class to extend java.lang.Exception
114 %typemap(javabase) pj::Error "java.lang.Exception";
115
116 %typemap(javacode) pj::Error %{
117 // Override getMessage()
118 public String getMessage() {
119 return getTitle();
120 }
121
122 // Disable serialization (check ticket #1868)
123 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
124 throw new java.io.NotSerializableException("Check ticket #1868!");
125 }
126 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException {
127 throw new java.io.NotSerializableException("Check ticket #1868!");
128 }
129 %}
130
131 // map "Token"/"void *" as "long"
132 %apply long long { void* };
133
134 // map "void **" as "long"
135 %apply long long { void** };
136
137 // map "pjmedia_aud_dev_index" as "int"
138 %apply int { pjmedia_aud_dev_index };
139
140 // map "unsigned char[20]" as "short array" for SslCertInfo.serialNo
141 %include "arrays_java.i"
142 %apply unsigned char[ANY] { unsigned char[20] };
143
144 // Constants from PJSIP libraries
145
146 %include "enumtypeunsafe.swg"
147 %javaconst(1);
148
149 %pragma(java) jniclasscode=%{
150 static {
151 try {
152 System.loadLibrary("openh264");
153 } catch (UnsatisfiedLinkError e) {
154 System.err.println("Failed to load native library openh264\n" + e);
155 System.out.println("This could be safely ignored if you " +
156 "don't use OpenH264 video codec.");
157 }
158 try {
159 System.loadLibrary("pjsua2");
160 } catch (UnsatisfiedLinkError e) {
161 System.err.println("Failed to load native library pjsua2\n" + e);
162 }
163 }
164 %}
165 #endif /* SWIGJAVA */
166
167
168 %include "symbols.i"
169
170
171 //
172 // Classes that can be extended in the target language
173 //
174 %feature("director") LogWriter;
175 %feature("director") Endpoint;
176 %feature("director") Account;
177 %feature("director") Call;
178 %feature("director") Buddy;
179 %feature("director") FindBuddyMatch;
180 %feature("director") AudioMediaPlayer;
181 %feature("director") AudioMediaPort;
182 %feature("director") AudioMediaAiPort;
183 %feature("director") VideoRecorder;
184
185 // PendingJob is only used on Python
186 #ifdef SWIGPYTHON
187 %feature("director") PendingJob;
188 #else
189 %ignore pj::PendingJob;
190 %ignore pj::Endpoint::utilAddPendingJob;
191 #endif
192
193 %newobject pj::AuthChallenge::defer;
194 %nocopyctor pj::AuthChallenge;
195
196 %copyctor pj::OnCallMediaEventParam;
197
198 // SWIG can't wrap 'operator=' — silence warning 503 for the copy-assign
199 // operator. (The move ctor/assignment are hidden via #ifndef SWIG in the
200 // header, since SWIG 4.x doesn't reliably match rvalue-ref signatures
201 // in %ignore.)
202 %ignore pj::DeferredResponse::operator=;
203
204 //
205 // Ignore stuffs in pjsua2
206 //
207 %ignore fromPj;
208 %ignore toPj;
209
210 %import "pj/config_site.h"
211 %import "pjsua2/config.hpp"
212
213 //
214 // Now include the API itself.
215 //
216 %include "pjsua2/types.hpp"
217
218 %ignore pj::ContainerNode::op;
219 %ignore pj::ContainerNode::data;
220 %ignore container_node_op;
221 %ignore container_node_internal_data;
222 %include "pjsua2/persistent.hpp"
223
224 %include "pjsua2/siptypes.hpp"
225
226 %template(SockOptVector) std::vector<pj::SockOpt>;
227 %template(SipHeaderVector) std::vector<pj::SipHeader>;
228 %template(AuthCredInfoVector) std::vector<pj::AuthCredInfo>;
229 %template(SrtpCryptoVector) std::vector<pj::SrtpCrypto>;
230 %template(SipMultipartPartVector) std::vector<pj::SipMultipartPart>;
231 %template(BuddyVector) std::vector<pj::Buddy*>;
232 %template(BuddyVector2) std::vector<pj::Buddy>;
233 %template(AudioMediaVector) std::vector<pj::AudioMedia*>;
234 %template(AudioMediaVector2) std::vector<pj::AudioMedia>;
235 %template(VideoMediaVector) std::vector<pj::VideoMedia>;
236 %template(ToneDescVector) std::vector<pj::ToneDesc>;
237 %template(ToneDigitVector) std::vector<pj::ToneDigit>;
238 %template(ToneDigitMapVector) std::vector<pj::ToneDigitMapDigit>;
239 %template(AudioDevInfoVector) std::vector<pj::AudioDevInfo*>;
240 %template(AudioDevInfoVector2) std::vector<pj::AudioDevInfo>;
241 %template(CodecInfoVector) std::vector<pj::CodecInfo*>;
242 %template(CodecInfoVector2) std::vector<pj::CodecInfo>;
243 %template(VideoDevInfoVector) std::vector<pj::VideoDevInfo*>;
244 %template(VideoDevInfoVector2) std::vector<pj::VideoDevInfo>;
245 %template(CodecFmtpVector) std::vector<pj::CodecFmtp>;
246 %template(MediaFormatAudioVector) std::vector<pj::MediaFormatAudio>;
247 %template(MediaFormatVideoVector) std::vector<pj::MediaFormatVideo>;
248 %template(CallMediaInfoVector) std::vector<pj::CallMediaInfo>;
249 %template(RtcpFbCapVector) std::vector<pj::RtcpFbCap>;
250 %template(SslCertNameVector) std::vector<pj::SslCertName>;
251
252 #if defined(__ANDROID__)
253 %ignore pj::WindowHandle::display;
254 %ignore pj::WindowHandle::window;
255 #endif
256
257 /* pj::WindowHandle::setWindow() receives Surface object */
258 #if defined(SWIGJAVA) && defined(__ANDROID__)
259 %{
260 #if defined(PJMEDIA_HAS_VIDEO) && PJMEDIA_HAS_VIDEO!=0
261 # include <android/native_window_jni.h>
262 #else
263 # define ANativeWindow_fromSurface(a,b) NULL
264 #endif
265 %}
266 %typemap(in) jobject surface {
267 $1 = ($input? (jobject)ANativeWindow_fromSurface(jenv, $input): NULL);
268 }
269 %extend pj::WindowHandle {
270 void setWindow(jobject surface) { $self->window = surface; }
271 }
272 #else
273 //%extend pj::WindowHandle {
274 // void setWindow(long long hwnd) { $self->window = (void*)hwnd; }
275 //}
276 #endif
277
278 %include "pjsua2/media.hpp"
279 %include "pjsua2/presence.hpp"
280 %include "pjsua2/account.hpp"
281 %include "pjsua2/call.hpp"
282
283 %ignore pj::JsonDocument::allocElement;
284 %ignore pj::JsonDocument::getPool;
285 %include "pjsua2/json.hpp"
286
287 // Try force Java GC before destroying the lib:
288 // - to avoid late destroy of PJ objects by GC
289 // - to avoid destruction of PJ objects from a non-registered GC thread
290 #ifdef SWIGJAVA
291 %rename(libDestroy_) pj::Endpoint::libDestroy;
292 %typemap(javacode) pj::Endpoint %{
293 public void libDestroy(long prmFlags) throws java.lang.Exception {
294 Runtime.getRuntime().gc();
295 libDestroy_(prmFlags);
296 }
297
298 public void libDestroy() throws java.lang.Exception {
299 Runtime.getRuntime().gc();
300 libDestroy_();
301 }
302 %}
303 #endif
304
305 #ifdef SWIGPYTHON
306 %pythonprepend pj::Endpoint::utilAddPendingJob(PendingJob *job) %{
307 # print('disowning job')
308 job.__disown__()
309 %}
310 #endif
311
312 %include "pjsua2/endpoint.hpp"