gstreamer/auto/uri_handler.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
6use crate::{ffi, URIType};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10 /// The [`URIHandler`][crate::URIHandler] is an interface that is implemented by Source and Sink
11 /// [`Element`][crate::Element] to unify handling of URI.
12 ///
13 /// An application can use the following functions to quickly get an element
14 /// that handles the given URI for reading or writing
15 /// ([`Element::make_from_uri()`][crate::Element::make_from_uri()]).
16 ///
17 /// Source and Sink plugins should implement this interface when possible.
18 ///
19 /// # Implements
20 ///
21 /// [`URIHandlerExt`][trait@crate::prelude::URIHandlerExt]
22 #[doc(alias = "GstURIHandler")]
23 pub struct URIHandler(Interface<ffi::GstURIHandler, ffi::GstURIHandlerInterface>);
24
25 match fn {
26 type_ => || ffi::gst_uri_handler_get_type(),
27 }
28}
29
30impl URIHandler {
31 pub const NONE: Option<&'static URIHandler> = None;
32}
33
34unsafe impl Send for URIHandler {}
35unsafe impl Sync for URIHandler {}
36
37mod sealed {
38 pub trait Sealed {}
39 impl<T: super::IsA<super::URIHandler>> Sealed for T {}
40}
41
42/// Trait containing all [`struct@URIHandler`] methods.
43///
44/// # Implementors
45///
46/// [`URIHandler`][struct@crate::URIHandler]
47pub trait URIHandlerExt: IsA<URIHandler> + sealed::Sealed + 'static {
48 /// Gets the list of protocols supported by `self`. This list may not be
49 /// modified.
50 ///
51 /// # Returns
52 ///
53 /// the
54 /// supported protocols. Returns [`None`] if the `self` isn't
55 /// implemented properly, or the `self` doesn't support any
56 /// protocols.
57 #[doc(alias = "gst_uri_handler_get_protocols")]
58 #[doc(alias = "get_protocols")]
59 fn protocols(&self) -> Vec<glib::GString> {
60 unsafe {
61 FromGlibPtrContainer::from_glib_none(ffi::gst_uri_handler_get_protocols(
62 self.as_ref().to_glib_none().0,
63 ))
64 }
65 }
66
67 /// Gets the currently handled URI.
68 ///
69 /// # Returns
70 ///
71 /// the URI currently handled by
72 /// the `self`. Returns [`None`] if there are no URI currently
73 /// handled. The returned string must be freed with `g_free()` when no
74 /// longer needed.
75 #[doc(alias = "gst_uri_handler_get_uri")]
76 #[doc(alias = "get_uri")]
77 fn uri(&self) -> Option<glib::GString> {
78 unsafe { from_glib_full(ffi::gst_uri_handler_get_uri(self.as_ref().to_glib_none().0)) }
79 }
80
81 /// Gets the type of the given URI handler
82 ///
83 /// # Returns
84 ///
85 /// the [`URIType`][crate::URIType] of the URI handler.
86 /// Returns [`URIType::Unknown`][crate::URIType::Unknown] if the `self` isn't implemented correctly.
87 #[doc(alias = "gst_uri_handler_get_uri_type")]
88 #[doc(alias = "get_uri_type")]
89 fn uri_type(&self) -> URIType {
90 unsafe {
91 from_glib(ffi::gst_uri_handler_get_uri_type(
92 self.as_ref().to_glib_none().0,
93 ))
94 }
95 }
96
97 /// Tries to set the URI of the given handler.
98 /// ## `uri`
99 /// URI to set
100 ///
101 /// # Returns
102 ///
103 /// [`true`] if the URI was set successfully, else [`false`].
104 #[doc(alias = "gst_uri_handler_set_uri")]
105 fn set_uri(&self, uri: &str) -> Result<(), glib::Error> {
106 unsafe {
107 let mut error = std::ptr::null_mut();
108 let is_ok = ffi::gst_uri_handler_set_uri(
109 self.as_ref().to_glib_none().0,
110 uri.to_glib_none().0,
111 &mut error,
112 );
113 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
114 if error.is_null() {
115 Ok(())
116 } else {
117 Err(from_glib_full(error))
118 }
119 }
120 }
121}
122
123impl<O: IsA<URIHandler>> URIHandlerExt for O {}