Skip to main content

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