gstreamer_rtsp_server/
rtsp_token.rs
1use std::fmt;
4
5use crate::ffi;
6use glib::{translate::*, SendValue};
7use gst::IdStr;
8
9gst::mini_object_wrapper!(RTSPToken, RTSPTokenRef, ffi::GstRTSPToken, || {
10 ffi::gst_rtsp_token_get_type()
11});
12
13impl RTSPToken {
14 #[doc(alias = "gst_rtsp_token_new_empty")]
20 pub fn new_empty() -> Self {
21 assert_initialized_main_thread!();
22 unsafe { from_glib_full(ffi::gst_rtsp_token_new_empty()) }
23 }
24
25 #[doc(alias = "gst_rtsp_token_new")]
26 pub fn builder() -> Builder {
27 skip_assert_initialized!();
28 Builder::new()
29 }
30
31 #[allow(clippy::should_implement_trait)]
32 pub fn from_iter<S: IntoGStr>(iter: impl IntoIterator<Item = (S, SendValue)>) -> RTSPToken {
33 skip_assert_initialized!();
34 let mut token = RTSPToken::new_empty();
35
36 let s = token.get_mut().unwrap().structure_mut();
37 iter.into_iter().for_each(|(f, v)| s.set_value(f, v));
38
39 token
40 }
41}
42
43impl RTSPTokenRef {
44 #[doc(alias = "get_string")]
45 #[doc(alias = "gst_rtsp_token_get_string")]
46 pub fn string(&self, field: &str) -> Option<String> {
47 unsafe {
48 from_glib_none(ffi::gst_rtsp_token_get_string(
49 self.as_mut_ptr(),
50 field.to_glib_none().0,
51 ))
52 }
53 }
54
55 #[doc(alias = "get_structure")]
56 #[doc(alias = "gst_rtsp_token_get_structure")]
57 pub fn structure(&self) -> Option<gst::Structure> {
58 unsafe { from_glib_none(ffi::gst_rtsp_token_get_structure(self.as_mut_ptr())) }
59 }
60
61 #[doc(alias = "gst_rtsp_token_is_allowed")]
62 pub fn is_allowed(&self, field: &str) -> bool {
63 unsafe {
64 from_glib(ffi::gst_rtsp_token_is_allowed(
65 self.as_mut_ptr(),
66 field.to_glib_none().0,
67 ))
68 }
69 }
70
71 #[doc(alias = "get_mut_structure")]
72 pub fn structure_mut(&mut self) -> &mut gst::StructureRef {
73 unsafe {
74 let structure = ffi::gst_rtsp_token_writable_structure(self.as_mut_ptr());
75 gst::StructureRef::from_glib_borrow_mut(structure)
76 }
77 }
78}
79
80impl fmt::Debug for RTSPToken {
81 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
82 RTSPTokenRef::fmt(self, f)
83 }
84}
85
86impl fmt::Debug for RTSPTokenRef {
87 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
88 f.debug_struct("RTSPToken")
89 .field("structure", &self.structure())
90 .finish()
91 }
92}
93
94#[derive(Debug)]
95#[must_use = "The builder must be built to be used"]
96pub struct Builder {
97 token: RTSPToken,
98}
99
100impl Builder {
101 fn new() -> Self {
102 skip_assert_initialized!();
103 Builder {
104 token: RTSPToken::new_empty(),
105 }
106 }
107
108 pub fn field(mut self, name: impl IntoGStr, value: impl Into<glib::Value> + Send) -> Self {
109 self.token
110 .get_mut()
111 .unwrap()
112 .structure_mut()
113 .set(name, value);
114 self
115 }
116
117 pub fn field_with_static(
118 mut self,
119 name: impl AsRef<glib::GStr> + 'static,
120 value: impl Into<glib::Value> + Send,
121 ) -> Self {
122 self.token
123 .get_mut()
124 .unwrap()
125 .structure_mut()
126 .set_with_static(name, value);
127 self
128 }
129
130 pub fn field_with_id(
131 mut self,
132 name: impl AsRef<IdStr>,
133 value: impl Into<glib::Value> + Send,
134 ) -> Self {
135 self.token
136 .get_mut()
137 .unwrap()
138 .structure_mut()
139 .set_with_id(name, value);
140 self
141 }
142
143 gst::impl_builder_gvalue_extra_setters!(field);
144
145 #[must_use = "Building the structure without using it has no effect"]
146 pub fn build(self) -> RTSPToken {
147 self.token
148 }
149}