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
37/// Trait containing all [`struct@URIHandler`] methods.
38///
39/// # Implementors
40///
41/// [`URIHandler`][struct@crate::URIHandler]
42pub trait URIHandlerExt: IsA<URIHandler> + 'static {
43 /// Gets the list of protocols supported by `self`. This list may not be
44 /// modified.
45 ///
46 /// # Returns
47 ///
48 /// the
49 /// supported protocols. Returns [`None`] if the `self` isn't
50 /// implemented properly, or the `self` doesn't support any
51 /// protocols.
52 #[doc(alias = "gst_uri_handler_get_protocols")]
53 #[doc(alias = "get_protocols")]
54 fn protocols(&self) -> Vec<glib::GString> {
55 unsafe {
56 FromGlibPtrContainer::from_glib_none(ffi::gst_uri_handler_get_protocols(
57 self.as_ref().to_glib_none().0,
58 ))
59 }
60 }
61
62 /// Gets the currently handled URI.
63 ///
64 /// # Returns
65 ///
66 /// the URI currently handled by
67 /// the `self`. Returns [`None`] if there are no URI currently
68 /// handled. The returned string must be freed with `g_free()` when no
69 /// longer needed.
70 #[doc(alias = "gst_uri_handler_get_uri")]
71 #[doc(alias = "get_uri")]
72 fn uri(&self) -> Option<glib::GString> {
73 unsafe { from_glib_full(ffi::gst_uri_handler_get_uri(self.as_ref().to_glib_none().0)) }
74 }
75
76 /// Gets the type of the given URI handler
77 ///
78 /// # Returns
79 ///
80 /// the [`URIType`][crate::URIType] of the URI handler.
81 /// Returns [`URIType::Unknown`][crate::URIType::Unknown] if the `self` isn't implemented correctly.
82 #[doc(alias = "gst_uri_handler_get_uri_type")]
83 #[doc(alias = "get_uri_type")]
84 fn uri_type(&self) -> URIType {
85 unsafe {
86 from_glib(ffi::gst_uri_handler_get_uri_type(
87 self.as_ref().to_glib_none().0,
88 ))
89 }
90 }
91
92 /// Tries to set the URI of the given handler.
93 /// ## `uri`
94 /// URI to set
95 ///
96 /// # Returns
97 ///
98 /// [`true`] if the URI was set successfully, else [`false`].
99 #[doc(alias = "gst_uri_handler_set_uri")]
100 fn set_uri(&self, uri: &str) -> Result<(), glib::Error> {
101 unsafe {
102 let mut error = std::ptr::null_mut();
103 let is_ok = ffi::gst_uri_handler_set_uri(
104 self.as_ref().to_glib_none().0,
105 uri.to_glib_none().0,
106 &mut error,
107 );
108 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
109 if error.is_null() {
110 Ok(())
111 } else {
112 Err(from_glib_full(error))
113 }
114 }
115 }
116}
117
118impl<O: IsA<URIHandler>> URIHandlerExt for O {}