Skip to main content

gstreamer_webrtc/auto/
web_rtc_data_channel.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5#![allow(deprecated)]
6
7use crate::{WebRTCDataChannelState, WebRTCPriorityType, ffi};
8use glib::{
9    object::ObjectType as _,
10    prelude::*,
11    signal::{SignalHandlerId, connect_raw},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17    ///
18    ///
19    /// This is an Abstract Base Class, you cannot instantiate it.
20    ///
21    /// ## Properties
22    ///
23    ///
24    /// #### `buffered-amount`
25    ///  Readable
26    ///
27    ///
28    /// #### `buffered-amount-low-threshold`
29    ///  Readable | Writeable
30    ///
31    ///
32    /// #### `id`
33    ///  Readable | Writeable | Construct Only
34    ///
35    ///
36    /// #### `label`
37    ///  Readable | Writeable | Construct Only
38    ///
39    ///
40    /// #### `max-packet-lifetime`
41    ///  Readable | Writeable | Construct Only
42    ///
43    ///
44    /// #### `max-retransmits`
45    ///  Readable | Writeable | Construct Only
46    ///
47    ///
48    /// #### `negotiated`
49    ///  Readable | Writeable | Construct Only
50    ///
51    ///
52    /// #### `ordered`
53    ///  Readable | Writeable | Construct Only
54    ///
55    ///
56    /// #### `priority`
57    ///  Readable | Writeable | Construct Only
58    ///
59    ///
60    /// #### `protocol`
61    ///  Readable | Writeable | Construct Only
62    ///
63    ///
64    /// #### `ready-state`
65    ///  Readable
66    ///
67    /// ## Signals
68    ///
69    ///
70    /// #### `close`
71    ///  Close the data channel
72    ///
73    /// Action
74    ///
75    ///
76    /// #### `on-buffered-amount-low`
77    ///
78    ///
79    ///
80    /// #### `on-close`
81    ///
82    ///
83    ///
84    /// #### `on-error`
85    ///
86    ///
87    ///
88    /// #### `on-message-data`
89    ///
90    ///
91    ///
92    /// #### `on-message-string`
93    ///
94    ///
95    ///
96    /// #### `on-open`
97    ///
98    ///
99    ///
100    /// #### `send-data`
101    ///  Action
102    ///
103    ///
104    /// #### `send-string`
105    ///  Action
106    ///
107    /// # Implements
108    ///
109    /// [`trait@glib::ObjectExt`]
110    #[doc(alias = "GstWebRTCDataChannel")]
111    pub struct WebRTCDataChannel(Object<ffi::GstWebRTCDataChannel, ffi::GstWebRTCDataChannelClass>);
112
113    match fn {
114        type_ => || ffi::gst_webrtc_data_channel_get_type(),
115    }
116}
117
118impl WebRTCDataChannel {
119    /// Close the `self`.
120    #[doc(alias = "gst_webrtc_data_channel_close")]
121    pub fn close(&self) {
122        unsafe {
123            ffi::gst_webrtc_data_channel_close(self.to_glib_none().0);
124        }
125    }
126
127    /// Send `data` as a data message over `self`.
128    ///
129    /// # Deprecated since 1.22
130    ///
131    /// Use [`send_data_full()`][Self::send_data_full()] instead
132    /// ## `data`
133    /// a [`glib::Bytes`][crate::glib::Bytes] or [`None`]
134    #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
135    #[allow(deprecated)]
136    #[doc(alias = "gst_webrtc_data_channel_send_data")]
137    pub fn send_data(&self, data: Option<&glib::Bytes>) {
138        unsafe {
139            ffi::gst_webrtc_data_channel_send_data(self.to_glib_none().0, data.to_glib_none().0);
140        }
141    }
142
143    /// Send `data` as a data message over `self`.
144    /// ## `data`
145    /// a [`glib::Bytes`][crate::glib::Bytes] or [`None`]
146    ///
147    /// # Returns
148    ///
149    /// TRUE if `self` is open and data could be queued
150    #[cfg(feature = "v1_22")]
151    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
152    #[doc(alias = "gst_webrtc_data_channel_send_data_full")]
153    pub fn send_data_full(&self, data: Option<&glib::Bytes>) -> Result<(), glib::Error> {
154        unsafe {
155            let mut error = std::ptr::null_mut();
156            let is_ok = ffi::gst_webrtc_data_channel_send_data_full(
157                self.to_glib_none().0,
158                data.to_glib_none().0,
159                &mut error,
160            );
161            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
162            if error.is_null() {
163                Ok(())
164            } else {
165                Err(from_glib_full(error))
166            }
167        }
168    }
169
170    /// Send `str` as a string message over `self`.
171    ///
172    /// # Deprecated since 1.22
173    ///
174    /// Use [`send_string_full()`][Self::send_string_full()] instead
175    /// ## `str`
176    /// a string or [`None`]
177    #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
178    #[allow(deprecated)]
179    #[doc(alias = "gst_webrtc_data_channel_send_string")]
180    pub fn send_string(&self, str: Option<&str>) {
181        unsafe {
182            ffi::gst_webrtc_data_channel_send_string(self.to_glib_none().0, str.to_glib_none().0);
183        }
184    }
185
186    /// Send `str` as a string message over `self`.
187    /// ## `str`
188    /// a string or [`None`]
189    ///
190    /// # Returns
191    ///
192    /// TRUE if `self` is open and data could be queued
193    #[cfg(feature = "v1_22")]
194    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
195    #[doc(alias = "gst_webrtc_data_channel_send_string_full")]
196    pub fn send_string_full(&self, str: Option<&str>) -> Result<(), glib::Error> {
197        unsafe {
198            let mut error = std::ptr::null_mut();
199            let is_ok = ffi::gst_webrtc_data_channel_send_string_full(
200                self.to_glib_none().0,
201                str.to_glib_none().0,
202                &mut error,
203            );
204            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
205            if error.is_null() {
206                Ok(())
207            } else {
208                Err(from_glib_full(error))
209            }
210        }
211    }
212
213    #[doc(alias = "buffered-amount")]
214    pub fn buffered_amount(&self) -> u64 {
215        ObjectExt::property(self, "buffered-amount")
216    }
217
218    #[doc(alias = "buffered-amount-low-threshold")]
219    pub fn buffered_amount_low_threshold(&self) -> u64 {
220        ObjectExt::property(self, "buffered-amount-low-threshold")
221    }
222
223    #[doc(alias = "buffered-amount-low-threshold")]
224    pub fn set_buffered_amount_low_threshold(&self, buffered_amount_low_threshold: u64) {
225        ObjectExt::set_property(
226            self,
227            "buffered-amount-low-threshold",
228            buffered_amount_low_threshold,
229        )
230    }
231
232    pub fn id(&self) -> i32 {
233        ObjectExt::property(self, "id")
234    }
235
236    pub fn label(&self) -> Option<glib::GString> {
237        ObjectExt::property(self, "label")
238    }
239
240    #[doc(alias = "max-packet-lifetime")]
241    pub fn max_packet_lifetime(&self) -> i32 {
242        ObjectExt::property(self, "max-packet-lifetime")
243    }
244
245    #[doc(alias = "max-retransmits")]
246    pub fn max_retransmits(&self) -> i32 {
247        ObjectExt::property(self, "max-retransmits")
248    }
249
250    pub fn is_negotiated(&self) -> bool {
251        ObjectExt::property(self, "negotiated")
252    }
253
254    pub fn is_ordered(&self) -> bool {
255        ObjectExt::property(self, "ordered")
256    }
257
258    pub fn priority(&self) -> WebRTCPriorityType {
259        ObjectExt::property(self, "priority")
260    }
261
262    pub fn protocol(&self) -> Option<glib::GString> {
263        ObjectExt::property(self, "protocol")
264    }
265
266    #[doc(alias = "ready-state")]
267    pub fn ready_state(&self) -> WebRTCDataChannelState {
268        ObjectExt::property(self, "ready-state")
269    }
270
271    #[doc(alias = "on-buffered-amount-low")]
272    pub fn connect_on_buffered_amount_low<F: Fn(&Self) + Send + Sync + 'static>(
273        &self,
274        f: F,
275    ) -> SignalHandlerId {
276        unsafe extern "C" fn on_buffered_amount_low_trampoline<
277            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
278        >(
279            this: *mut ffi::GstWebRTCDataChannel,
280            f: glib::ffi::gpointer,
281        ) {
282            unsafe {
283                let f: &F = &*(f as *const F);
284                f(&from_glib_borrow(this))
285            }
286        }
287        unsafe {
288            let f: Box_<F> = Box_::new(f);
289            connect_raw(
290                self.as_ptr() as *mut _,
291                c"on-buffered-amount-low".as_ptr(),
292                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
293                    on_buffered_amount_low_trampoline::<F> as *const (),
294                )),
295                Box_::into_raw(f),
296            )
297        }
298    }
299
300    #[doc(alias = "on-close")]
301    pub fn connect_on_close<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
302        unsafe extern "C" fn on_close_trampoline<
303            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
304        >(
305            this: *mut ffi::GstWebRTCDataChannel,
306            f: glib::ffi::gpointer,
307        ) {
308            unsafe {
309                let f: &F = &*(f as *const F);
310                f(&from_glib_borrow(this))
311            }
312        }
313        unsafe {
314            let f: Box_<F> = Box_::new(f);
315            connect_raw(
316                self.as_ptr() as *mut _,
317                c"on-close".as_ptr(),
318                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319                    on_close_trampoline::<F> as *const (),
320                )),
321                Box_::into_raw(f),
322            )
323        }
324    }
325
326    /// ## `error`
327    /// the [`glib::Error`][crate::glib::Error] thrown
328    #[doc(alias = "on-error")]
329    pub fn connect_on_error<F: Fn(&Self, &glib::Error) + Send + Sync + 'static>(
330        &self,
331        f: F,
332    ) -> SignalHandlerId {
333        unsafe extern "C" fn on_error_trampoline<
334            F: Fn(&WebRTCDataChannel, &glib::Error) + Send + Sync + 'static,
335        >(
336            this: *mut ffi::GstWebRTCDataChannel,
337            error: *mut glib::ffi::GError,
338            f: glib::ffi::gpointer,
339        ) {
340            unsafe {
341                let f: &F = &*(f as *const F);
342                f(&from_glib_borrow(this), &from_glib_borrow(error))
343            }
344        }
345        unsafe {
346            let f: Box_<F> = Box_::new(f);
347            connect_raw(
348                self.as_ptr() as *mut _,
349                c"on-error".as_ptr(),
350                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
351                    on_error_trampoline::<F> as *const (),
352                )),
353                Box_::into_raw(f),
354            )
355        }
356    }
357
358    /// ## `data`
359    /// a [`glib::Bytes`][crate::glib::Bytes] of the data received
360    #[doc(alias = "on-message-data")]
361    pub fn connect_on_message_data<F: Fn(&Self, Option<&glib::Bytes>) + Send + Sync + 'static>(
362        &self,
363        f: F,
364    ) -> SignalHandlerId {
365        unsafe extern "C" fn on_message_data_trampoline<
366            F: Fn(&WebRTCDataChannel, Option<&glib::Bytes>) + Send + Sync + 'static,
367        >(
368            this: *mut ffi::GstWebRTCDataChannel,
369            data: *mut glib::ffi::GBytes,
370            f: glib::ffi::gpointer,
371        ) {
372            unsafe {
373                let f: &F = &*(f as *const F);
374                f(
375                    &from_glib_borrow(this),
376                    Option::<glib::Bytes>::from_glib_borrow(data)
377                        .as_ref()
378                        .as_ref(),
379                )
380            }
381        }
382        unsafe {
383            let f: Box_<F> = Box_::new(f);
384            connect_raw(
385                self.as_ptr() as *mut _,
386                c"on-message-data".as_ptr(),
387                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
388                    on_message_data_trampoline::<F> as *const (),
389                )),
390                Box_::into_raw(f),
391            )
392        }
393    }
394
395    /// ## `data`
396    /// the data received as a string
397    #[doc(alias = "on-message-string")]
398    pub fn connect_on_message_string<F: Fn(&Self, Option<&str>) + Send + Sync + 'static>(
399        &self,
400        f: F,
401    ) -> SignalHandlerId {
402        unsafe extern "C" fn on_message_string_trampoline<
403            F: Fn(&WebRTCDataChannel, Option<&str>) + Send + Sync + 'static,
404        >(
405            this: *mut ffi::GstWebRTCDataChannel,
406            data: *mut std::ffi::c_char,
407            f: glib::ffi::gpointer,
408        ) {
409            unsafe {
410                let f: &F = &*(f as *const F);
411                f(
412                    &from_glib_borrow(this),
413                    Option::<glib::GString>::from_glib_borrow(data)
414                        .as_ref()
415                        .as_ref()
416                        .map(|s| s.as_str()),
417                )
418            }
419        }
420        unsafe {
421            let f: Box_<F> = Box_::new(f);
422            connect_raw(
423                self.as_ptr() as *mut _,
424                c"on-message-string".as_ptr(),
425                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
426                    on_message_string_trampoline::<F> as *const (),
427                )),
428                Box_::into_raw(f),
429            )
430        }
431    }
432
433    #[doc(alias = "on-open")]
434    pub fn connect_on_open<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
435        unsafe extern "C" fn on_open_trampoline<
436            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
437        >(
438            this: *mut ffi::GstWebRTCDataChannel,
439            f: glib::ffi::gpointer,
440        ) {
441            unsafe {
442                let f: &F = &*(f as *const F);
443                f(&from_glib_borrow(this))
444            }
445        }
446        unsafe {
447            let f: Box_<F> = Box_::new(f);
448            connect_raw(
449                self.as_ptr() as *mut _,
450                c"on-open".as_ptr(),
451                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
452                    on_open_trampoline::<F> as *const (),
453                )),
454                Box_::into_raw(f),
455            )
456        }
457    }
458
459    #[doc(alias = "buffered-amount")]
460    pub fn connect_buffered_amount_notify<F: Fn(&Self) + Send + Sync + 'static>(
461        &self,
462        f: F,
463    ) -> SignalHandlerId {
464        unsafe extern "C" fn notify_buffered_amount_trampoline<
465            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
466        >(
467            this: *mut ffi::GstWebRTCDataChannel,
468            _param_spec: glib::ffi::gpointer,
469            f: glib::ffi::gpointer,
470        ) {
471            unsafe {
472                let f: &F = &*(f as *const F);
473                f(&from_glib_borrow(this))
474            }
475        }
476        unsafe {
477            let f: Box_<F> = Box_::new(f);
478            connect_raw(
479                self.as_ptr() as *mut _,
480                c"notify::buffered-amount".as_ptr(),
481                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
482                    notify_buffered_amount_trampoline::<F> as *const (),
483                )),
484                Box_::into_raw(f),
485            )
486        }
487    }
488
489    #[doc(alias = "buffered-amount-low-threshold")]
490    pub fn connect_buffered_amount_low_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(
491        &self,
492        f: F,
493    ) -> SignalHandlerId {
494        unsafe extern "C" fn notify_buffered_amount_low_threshold_trampoline<
495            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
496        >(
497            this: *mut ffi::GstWebRTCDataChannel,
498            _param_spec: glib::ffi::gpointer,
499            f: glib::ffi::gpointer,
500        ) {
501            unsafe {
502                let f: &F = &*(f as *const F);
503                f(&from_glib_borrow(this))
504            }
505        }
506        unsafe {
507            let f: Box_<F> = Box_::new(f);
508            connect_raw(
509                self.as_ptr() as *mut _,
510                c"notify::buffered-amount-low-threshold".as_ptr(),
511                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
512                    notify_buffered_amount_low_threshold_trampoline::<F> as *const (),
513                )),
514                Box_::into_raw(f),
515            )
516        }
517    }
518
519    #[doc(alias = "ready-state")]
520    pub fn connect_ready_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
521        &self,
522        f: F,
523    ) -> SignalHandlerId {
524        unsafe extern "C" fn notify_ready_state_trampoline<
525            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
526        >(
527            this: *mut ffi::GstWebRTCDataChannel,
528            _param_spec: glib::ffi::gpointer,
529            f: glib::ffi::gpointer,
530        ) {
531            unsafe {
532                let f: &F = &*(f as *const F);
533                f(&from_glib_borrow(this))
534            }
535        }
536        unsafe {
537            let f: Box_<F> = Box_::new(f);
538            connect_raw(
539                self.as_ptr() as *mut _,
540                c"notify::ready-state".as_ptr(),
541                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
542                    notify_ready_state_trampoline::<F> as *const (),
543                )),
544                Box_::into_raw(f),
545            )
546        }
547    }
548}
549
550unsafe impl Send for WebRTCDataChannel {}
551unsafe impl Sync for WebRTCDataChannel {}