soup/auto/
websocket_connection.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi, WebsocketConnectionType, WebsocketExtension, WebsocketState};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "SoupWebsocketConnection")]
16    pub struct WebsocketConnection(Object<ffi::SoupWebsocketConnection, ffi::SoupWebsocketConnectionClass>);
17
18    match fn {
19        type_ => || ffi::soup_websocket_connection_get_type(),
20    }
21}
22
23impl WebsocketConnection {
24    // rustdoc-stripper-ignore-next
25    /// Creates a new builder-pattern struct instance to construct [`WebsocketConnection`] objects.
26    ///
27    /// This method returns an instance of [`WebsocketConnectionBuilder`](crate::builders::WebsocketConnectionBuilder) which can be used to create [`WebsocketConnection`] objects.
28    pub fn builder() -> WebsocketConnectionBuilder {
29        WebsocketConnectionBuilder::new()
30    }
31
32    #[doc(alias = "soup_websocket_connection_close")]
33    pub fn close(&self, code: libc::c_ushort, data: Option<&str>) {
34        unsafe {
35            ffi::soup_websocket_connection_close(
36                self.to_glib_none().0,
37                code,
38                data.to_glib_none().0,
39            );
40        }
41    }
42
43    #[doc(alias = "soup_websocket_connection_get_close_code")]
44    #[doc(alias = "get_close_code")]
45    pub fn close_code(&self) -> libc::c_ushort {
46        unsafe { ffi::soup_websocket_connection_get_close_code(self.to_glib_none().0) }
47    }
48
49    #[doc(alias = "soup_websocket_connection_get_close_data")]
50    #[doc(alias = "get_close_data")]
51    pub fn close_data(&self) -> Option<glib::GString> {
52        unsafe {
53            from_glib_none(ffi::soup_websocket_connection_get_close_data(
54                self.to_glib_none().0,
55            ))
56        }
57    }
58
59    #[doc(alias = "soup_websocket_connection_get_connection_type")]
60    #[doc(alias = "get_connection_type")]
61    #[doc(alias = "connection-type")]
62    pub fn connection_type(&self) -> WebsocketConnectionType {
63        unsafe {
64            from_glib(ffi::soup_websocket_connection_get_connection_type(
65                self.to_glib_none().0,
66            ))
67        }
68    }
69
70    #[doc(alias = "soup_websocket_connection_get_extensions")]
71    #[doc(alias = "get_extensions")]
72    pub fn extensions(&self) -> Vec<WebsocketExtension> {
73        unsafe {
74            FromGlibPtrContainer::from_glib_none(ffi::soup_websocket_connection_get_extensions(
75                self.to_glib_none().0,
76            ))
77        }
78    }
79
80    #[doc(alias = "soup_websocket_connection_get_io_stream")]
81    #[doc(alias = "get_io_stream")]
82    #[doc(alias = "io-stream")]
83    pub fn io_stream(&self) -> Option<gio::IOStream> {
84        unsafe {
85            from_glib_none(ffi::soup_websocket_connection_get_io_stream(
86                self.to_glib_none().0,
87            ))
88        }
89    }
90
91    #[doc(alias = "soup_websocket_connection_get_keepalive_interval")]
92    #[doc(alias = "get_keepalive_interval")]
93    #[doc(alias = "keepalive-interval")]
94    pub fn keepalive_interval(&self) -> u32 {
95        unsafe { ffi::soup_websocket_connection_get_keepalive_interval(self.to_glib_none().0) }
96    }
97
98    #[cfg(feature = "v3_6")]
99    #[cfg_attr(docsrs, doc(cfg(feature = "v3_6")))]
100    #[doc(alias = "soup_websocket_connection_get_keepalive_pong_timeout")]
101    #[doc(alias = "get_keepalive_pong_timeout")]
102    #[doc(alias = "keepalive-pong-timeout")]
103    pub fn keepalive_pong_timeout(&self) -> u32 {
104        unsafe { ffi::soup_websocket_connection_get_keepalive_pong_timeout(self.to_glib_none().0) }
105    }
106
107    #[doc(alias = "soup_websocket_connection_get_max_incoming_payload_size")]
108    #[doc(alias = "get_max_incoming_payload_size")]
109    #[doc(alias = "max-incoming-payload-size")]
110    pub fn max_incoming_payload_size(&self) -> u64 {
111        unsafe {
112            ffi::soup_websocket_connection_get_max_incoming_payload_size(self.to_glib_none().0)
113        }
114    }
115
116    #[doc(alias = "soup_websocket_connection_get_origin")]
117    #[doc(alias = "get_origin")]
118    pub fn origin(&self) -> Option<glib::GString> {
119        unsafe {
120            from_glib_none(ffi::soup_websocket_connection_get_origin(
121                self.to_glib_none().0,
122            ))
123        }
124    }
125
126    #[doc(alias = "soup_websocket_connection_get_protocol")]
127    #[doc(alias = "get_protocol")]
128    pub fn protocol(&self) -> Option<glib::GString> {
129        unsafe {
130            from_glib_none(ffi::soup_websocket_connection_get_protocol(
131                self.to_glib_none().0,
132            ))
133        }
134    }
135
136    #[doc(alias = "soup_websocket_connection_get_state")]
137    #[doc(alias = "get_state")]
138    pub fn state(&self) -> WebsocketState {
139        unsafe {
140            from_glib(ffi::soup_websocket_connection_get_state(
141                self.to_glib_none().0,
142            ))
143        }
144    }
145
146    #[doc(alias = "soup_websocket_connection_get_uri")]
147    #[doc(alias = "get_uri")]
148    pub fn uri(&self) -> Option<glib::Uri> {
149        unsafe {
150            from_glib_none(ffi::soup_websocket_connection_get_uri(
151                self.to_glib_none().0,
152            ))
153        }
154    }
155
156    #[doc(alias = "soup_websocket_connection_send_text")]
157    pub fn send_text(&self, text: &str) {
158        unsafe {
159            ffi::soup_websocket_connection_send_text(self.to_glib_none().0, text.to_glib_none().0);
160        }
161    }
162
163    #[doc(alias = "soup_websocket_connection_set_keepalive_interval")]
164    #[doc(alias = "keepalive-interval")]
165    pub fn set_keepalive_interval(&self, interval: u32) {
166        unsafe {
167            ffi::soup_websocket_connection_set_keepalive_interval(self.to_glib_none().0, interval);
168        }
169    }
170
171    #[cfg(feature = "v3_6")]
172    #[cfg_attr(docsrs, doc(cfg(feature = "v3_6")))]
173    #[doc(alias = "soup_websocket_connection_set_keepalive_pong_timeout")]
174    #[doc(alias = "keepalive-pong-timeout")]
175    pub fn set_keepalive_pong_timeout(&self, pong_timeout: u32) {
176        unsafe {
177            ffi::soup_websocket_connection_set_keepalive_pong_timeout(
178                self.to_glib_none().0,
179                pong_timeout,
180            );
181        }
182    }
183
184    #[doc(alias = "soup_websocket_connection_set_max_incoming_payload_size")]
185    #[doc(alias = "max-incoming-payload-size")]
186    pub fn set_max_incoming_payload_size(&self, max_incoming_payload_size: u64) {
187        unsafe {
188            ffi::soup_websocket_connection_set_max_incoming_payload_size(
189                self.to_glib_none().0,
190                max_incoming_payload_size,
191            );
192        }
193    }
194
195    #[doc(alias = "closed")]
196    pub fn connect_closed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
197        unsafe extern "C" fn closed_trampoline<F: Fn(&WebsocketConnection) + 'static>(
198            this: *mut ffi::SoupWebsocketConnection,
199            f: glib::ffi::gpointer,
200        ) {
201            let f: &F = &*(f as *const F);
202            f(&from_glib_borrow(this))
203        }
204        unsafe {
205            let f: Box_<F> = Box_::new(f);
206            connect_raw(
207                self.as_ptr() as *mut _,
208                b"closed\0".as_ptr() as *const _,
209                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
210                    closed_trampoline::<F> as *const (),
211                )),
212                Box_::into_raw(f),
213            )
214        }
215    }
216
217    #[doc(alias = "closing")]
218    pub fn connect_closing<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
219        unsafe extern "C" fn closing_trampoline<F: Fn(&WebsocketConnection) + 'static>(
220            this: *mut ffi::SoupWebsocketConnection,
221            f: glib::ffi::gpointer,
222        ) {
223            let f: &F = &*(f as *const F);
224            f(&from_glib_borrow(this))
225        }
226        unsafe {
227            let f: Box_<F> = Box_::new(f);
228            connect_raw(
229                self.as_ptr() as *mut _,
230                b"closing\0".as_ptr() as *const _,
231                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
232                    closing_trampoline::<F> as *const (),
233                )),
234                Box_::into_raw(f),
235            )
236        }
237    }
238
239    #[doc(alias = "error")]
240    pub fn connect_error<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
241        unsafe extern "C" fn error_trampoline<
242            F: Fn(&WebsocketConnection, &glib::Error) + 'static,
243        >(
244            this: *mut ffi::SoupWebsocketConnection,
245            error: *mut glib::ffi::GError,
246            f: glib::ffi::gpointer,
247        ) {
248            let f: &F = &*(f as *const F);
249            f(&from_glib_borrow(this), &from_glib_borrow(error))
250        }
251        unsafe {
252            let f: Box_<F> = Box_::new(f);
253            connect_raw(
254                self.as_ptr() as *mut _,
255                b"error\0".as_ptr() as *const _,
256                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
257                    error_trampoline::<F> as *const (),
258                )),
259                Box_::into_raw(f),
260            )
261        }
262    }
263
264    #[doc(alias = "message")]
265    pub fn connect_message<F: Fn(&Self, i32, &glib::Bytes) + 'static>(
266        &self,
267        f: F,
268    ) -> SignalHandlerId {
269        unsafe extern "C" fn message_trampoline<
270            F: Fn(&WebsocketConnection, i32, &glib::Bytes) + 'static,
271        >(
272            this: *mut ffi::SoupWebsocketConnection,
273            type_: libc::c_int,
274            message: *mut glib::ffi::GBytes,
275            f: glib::ffi::gpointer,
276        ) {
277            let f: &F = &*(f as *const F);
278            f(&from_glib_borrow(this), type_, &from_glib_borrow(message))
279        }
280        unsafe {
281            let f: Box_<F> = Box_::new(f);
282            connect_raw(
283                self.as_ptr() as *mut _,
284                b"message\0".as_ptr() as *const _,
285                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
286                    message_trampoline::<F> as *const (),
287                )),
288                Box_::into_raw(f),
289            )
290        }
291    }
292
293    #[doc(alias = "pong")]
294    pub fn connect_pong<F: Fn(&Self, &glib::Bytes) + 'static>(&self, f: F) -> SignalHandlerId {
295        unsafe extern "C" fn pong_trampoline<
296            F: Fn(&WebsocketConnection, &glib::Bytes) + 'static,
297        >(
298            this: *mut ffi::SoupWebsocketConnection,
299            message: *mut glib::ffi::GBytes,
300            f: glib::ffi::gpointer,
301        ) {
302            let f: &F = &*(f as *const F);
303            f(&from_glib_borrow(this), &from_glib_borrow(message))
304        }
305        unsafe {
306            let f: Box_<F> = Box_::new(f);
307            connect_raw(
308                self.as_ptr() as *mut _,
309                b"pong\0".as_ptr() as *const _,
310                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
311                    pong_trampoline::<F> as *const (),
312                )),
313                Box_::into_raw(f),
314            )
315        }
316    }
317
318    #[doc(alias = "keepalive-interval")]
319    pub fn connect_keepalive_interval_notify<F: Fn(&Self) + 'static>(
320        &self,
321        f: F,
322    ) -> SignalHandlerId {
323        unsafe extern "C" fn notify_keepalive_interval_trampoline<
324            F: Fn(&WebsocketConnection) + 'static,
325        >(
326            this: *mut ffi::SoupWebsocketConnection,
327            _param_spec: glib::ffi::gpointer,
328            f: glib::ffi::gpointer,
329        ) {
330            let f: &F = &*(f as *const F);
331            f(&from_glib_borrow(this))
332        }
333        unsafe {
334            let f: Box_<F> = Box_::new(f);
335            connect_raw(
336                self.as_ptr() as *mut _,
337                b"notify::keepalive-interval\0".as_ptr() as *const _,
338                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
339                    notify_keepalive_interval_trampoline::<F> as *const (),
340                )),
341                Box_::into_raw(f),
342            )
343        }
344    }
345
346    #[cfg(feature = "v3_6")]
347    #[cfg_attr(docsrs, doc(cfg(feature = "v3_6")))]
348    #[doc(alias = "keepalive-pong-timeout")]
349    pub fn connect_keepalive_pong_timeout_notify<F: Fn(&Self) + 'static>(
350        &self,
351        f: F,
352    ) -> SignalHandlerId {
353        unsafe extern "C" fn notify_keepalive_pong_timeout_trampoline<
354            F: Fn(&WebsocketConnection) + 'static,
355        >(
356            this: *mut ffi::SoupWebsocketConnection,
357            _param_spec: glib::ffi::gpointer,
358            f: glib::ffi::gpointer,
359        ) {
360            let f: &F = &*(f as *const F);
361            f(&from_glib_borrow(this))
362        }
363        unsafe {
364            let f: Box_<F> = Box_::new(f);
365            connect_raw(
366                self.as_ptr() as *mut _,
367                b"notify::keepalive-pong-timeout\0".as_ptr() as *const _,
368                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
369                    notify_keepalive_pong_timeout_trampoline::<F> as *const (),
370                )),
371                Box_::into_raw(f),
372            )
373        }
374    }
375
376    #[doc(alias = "max-incoming-payload-size")]
377    pub fn connect_max_incoming_payload_size_notify<F: Fn(&Self) + 'static>(
378        &self,
379        f: F,
380    ) -> SignalHandlerId {
381        unsafe extern "C" fn notify_max_incoming_payload_size_trampoline<
382            F: Fn(&WebsocketConnection) + 'static,
383        >(
384            this: *mut ffi::SoupWebsocketConnection,
385            _param_spec: glib::ffi::gpointer,
386            f: glib::ffi::gpointer,
387        ) {
388            let f: &F = &*(f as *const F);
389            f(&from_glib_borrow(this))
390        }
391        unsafe {
392            let f: Box_<F> = Box_::new(f);
393            connect_raw(
394                self.as_ptr() as *mut _,
395                b"notify::max-incoming-payload-size\0".as_ptr() as *const _,
396                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
397                    notify_max_incoming_payload_size_trampoline::<F> as *const (),
398                )),
399                Box_::into_raw(f),
400            )
401        }
402    }
403
404    #[doc(alias = "state")]
405    pub fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
406        unsafe extern "C" fn notify_state_trampoline<F: Fn(&WebsocketConnection) + 'static>(
407            this: *mut ffi::SoupWebsocketConnection,
408            _param_spec: glib::ffi::gpointer,
409            f: glib::ffi::gpointer,
410        ) {
411            let f: &F = &*(f as *const F);
412            f(&from_glib_borrow(this))
413        }
414        unsafe {
415            let f: Box_<F> = Box_::new(f);
416            connect_raw(
417                self.as_ptr() as *mut _,
418                b"notify::state\0".as_ptr() as *const _,
419                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
420                    notify_state_trampoline::<F> as *const (),
421                )),
422                Box_::into_raw(f),
423            )
424        }
425    }
426}
427
428// rustdoc-stripper-ignore-next
429/// A [builder-pattern] type to construct [`WebsocketConnection`] objects.
430///
431/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
432#[must_use = "The builder must be built to be used"]
433pub struct WebsocketConnectionBuilder {
434    builder: glib::object::ObjectBuilder<'static, WebsocketConnection>,
435}
436
437impl WebsocketConnectionBuilder {
438    fn new() -> Self {
439        Self {
440            builder: glib::object::Object::builder(),
441        }
442    }
443
444    pub fn connection_type(self, connection_type: WebsocketConnectionType) -> Self {
445        Self {
446            builder: self.builder.property("connection-type", connection_type),
447        }
448    }
449
450    //pub fn extensions(self, extensions: /*Unimplemented*/Basic: Pointer) -> Self {
451    //    Self { builder: self.builder.property("extensions", extensions), }
452    //}
453
454    pub fn io_stream(self, io_stream: &impl IsA<gio::IOStream>) -> Self {
455        Self {
456            builder: self
457                .builder
458                .property("io-stream", io_stream.clone().upcast()),
459        }
460    }
461
462    pub fn keepalive_interval(self, keepalive_interval: u32) -> Self {
463        Self {
464            builder: self
465                .builder
466                .property("keepalive-interval", keepalive_interval),
467        }
468    }
469
470    #[cfg(feature = "v3_6")]
471    #[cfg_attr(docsrs, doc(cfg(feature = "v3_6")))]
472    pub fn keepalive_pong_timeout(self, keepalive_pong_timeout: u32) -> Self {
473        Self {
474            builder: self
475                .builder
476                .property("keepalive-pong-timeout", keepalive_pong_timeout),
477        }
478    }
479
480    pub fn max_incoming_payload_size(self, max_incoming_payload_size: u64) -> Self {
481        Self {
482            builder: self
483                .builder
484                .property("max-incoming-payload-size", max_incoming_payload_size),
485        }
486    }
487
488    pub fn origin(self, origin: impl Into<glib::GString>) -> Self {
489        Self {
490            builder: self.builder.property("origin", origin.into()),
491        }
492    }
493
494    pub fn protocol(self, protocol: impl Into<glib::GString>) -> Self {
495        Self {
496            builder: self.builder.property("protocol", protocol.into()),
497        }
498    }
499
500    pub fn uri(self, uri: &glib::Uri) -> Self {
501        Self {
502            builder: self.builder.property("uri", uri.clone()),
503        }
504    }
505
506    // rustdoc-stripper-ignore-next
507    /// Build the [`WebsocketConnection`].
508    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
509    pub fn build(self) -> WebsocketConnection {
510        self.builder.build()
511    }
512}