Skip to main content

gio/auto/
dbus_message.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// DO NOT EDIT
4
5#[cfg(unix)]
6#[cfg_attr(docsrs, doc(cfg(unix)))]
7use crate::UnixFDList;
8use crate::{
9    DBusCapabilityFlags, DBusMessageByteOrder, DBusMessageFlags, DBusMessageHeaderField,
10    DBusMessageType, ffi,
11};
12use glib::{
13    prelude::*,
14    signal::{SignalHandlerId, connect_raw},
15    translate::*,
16};
17use std::boxed::Box as Box_;
18
19glib::wrapper! {
20    /// A type for representing D-Bus messages that can be sent or received
21    /// on a [`DBusConnection`][crate::DBusConnection].
22    ///
23    /// ## Properties
24    ///
25    ///
26    /// #### `locked`
27    ///  Readable
28    ///
29    /// # Implements
30    ///
31    /// [`trait@glib::ObjectExt`]
32    #[doc(alias = "GDBusMessage")]
33    pub struct DBusMessage(Object<ffi::GDBusMessage>);
34
35    match fn {
36        type_ => || ffi::g_dbus_message_get_type(),
37    }
38}
39
40impl DBusMessage {
41    /// Creates a new empty D-Bus message.
42    ///
43    /// # Returns
44    ///
45    /// The D-Bus message
46    #[doc(alias = "g_dbus_message_new")]
47    pub fn new() -> DBusMessage {
48        unsafe { from_glib_full(ffi::g_dbus_message_new()) }
49    }
50
51    /// Creates a new D-Bus message from the data stored at @blob.
52    ///
53    /// You must have previously called [`bytes_needed()`][Self::bytes_needed()] on @blob,
54    /// and ensure that @blob is at least as long as the return value from that
55    /// function indicates. In particular, that means that @blob must be at least 16
56    /// bytes long (but will typically be much longer).
57    ///
58    /// The byte order that the message was in can be retrieved using
59    /// [`byte_order()`][Self::byte_order()].
60    ///
61    /// If the @blob cannot be parsed, contains invalid fields, or contains invalid
62    /// headers, [error@Gio.IOErrorEnum.INVALID_ARGUMENT] will be returned.
63    /// ## `blob`
64    /// a blob representing a
65    ///   binary D-Bus message
66    /// ## `capabilities`
67    /// flags describing what protocol features are supported
68    ///
69    /// # Returns
70    ///
71    /// The D-Bus message
72    #[doc(alias = "g_dbus_message_new_from_blob")]
73    #[doc(alias = "new_from_blob")]
74    pub fn from_blob(
75        blob: &[u8],
76        capabilities: DBusCapabilityFlags,
77    ) -> Result<DBusMessage, glib::Error> {
78        let blob_len = blob.len() as _;
79        unsafe {
80            let mut error = std::ptr::null_mut();
81            let ret = ffi::g_dbus_message_new_from_blob(
82                blob.to_glib_none().0,
83                blob_len,
84                capabilities.into_glib(),
85                &mut error,
86            );
87            if error.is_null() {
88                Ok(from_glib_full(ret))
89            } else {
90                Err(from_glib_full(error))
91            }
92        }
93    }
94
95    /// Creates a new D-Bus message for a method call.
96    /// ## `name`
97    /// a valid D-Bus name, or `NULL` if no destination is needed
98    /// ## `path`
99    /// a valid object path
100    /// ## `interface_`
101    /// a valid D-Bus interface name, or `NULL` if none is
102    ///   needed
103    /// ## `method`
104    /// a valid method name
105    ///
106    /// # Returns
107    ///
108    /// The D-Bus message
109    #[doc(alias = "g_dbus_message_new_method_call")]
110    pub fn new_method_call(
111        name: Option<&str>,
112        path: &str,
113        interface_: Option<&str>,
114        method: &str,
115    ) -> DBusMessage {
116        unsafe {
117            from_glib_full(ffi::g_dbus_message_new_method_call(
118                name.to_glib_none().0,
119                path.to_glib_none().0,
120                interface_.to_glib_none().0,
121                method.to_glib_none().0,
122            ))
123        }
124    }
125
126    //#[doc(alias = "g_dbus_message_new_method_error")]
127    //pub fn new_method_error(method_call_message: &DBusMessage, error_name: &str, error_message_format: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> DBusMessage {
128    //    unsafe { TODO: call ffi:g_dbus_message_new_method_error() }
129    //}
130
131    /// Creates a new D-Bus message for a signal emission.
132    /// ## `path`
133    /// a valid object path
134    /// ## `interface_`
135    /// a valid D-Bus interface name
136    /// ## `signal`
137    /// a valid signal name
138    ///
139    /// # Returns
140    ///
141    /// The D-Bus message
142    #[doc(alias = "g_dbus_message_new_signal")]
143    pub fn new_signal(path: &str, interface_: &str, signal: &str) -> DBusMessage {
144        unsafe {
145            from_glib_full(ffi::g_dbus_message_new_signal(
146                path.to_glib_none().0,
147                interface_.to_glib_none().0,
148                signal.to_glib_none().0,
149            ))
150        }
151    }
152
153    #[doc(alias = "g_dbus_message_copy")]
154    pub fn copy(&self) -> Result<DBusMessage, glib::Error> {
155        unsafe {
156            let mut error = std::ptr::null_mut();
157            let ret = ffi::g_dbus_message_copy(self.to_glib_none().0, &mut error);
158            if error.is_null() {
159                Ok(from_glib_full(ret))
160            } else {
161                Err(from_glib_full(error))
162            }
163        }
164    }
165
166    /// Convenience to get the first item in the body of @self.
167    ///
168    /// See [`arg0_path()`][Self::arg0_path()] for returning object-path-typed
169    /// arg0 values.
170    ///
171    /// # Returns
172    ///
173    /// The string item, or `NULL` if the first item in the body
174    ///   of @self is not a string
175    #[doc(alias = "g_dbus_message_get_arg0")]
176    #[doc(alias = "get_arg0")]
177    pub fn arg0(&self) -> Option<glib::GString> {
178        unsafe { from_glib_none(ffi::g_dbus_message_get_arg0(self.to_glib_none().0)) }
179    }
180
181    /// Convenience to get the first item in the body of @self.
182    ///
183    /// See [`arg0()`][Self::arg0()] for returning string-typed arg0 values.
184    ///
185    /// # Returns
186    ///
187    /// The object path item, or `NULL` if the first item in the
188    ///   body of @self is not an object path
189    #[cfg(feature = "v2_80")]
190    #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
191    #[doc(alias = "g_dbus_message_get_arg0_path")]
192    #[doc(alias = "get_arg0_path")]
193    pub fn arg0_path(&self) -> Option<glib::GString> {
194        unsafe { from_glib_none(ffi::g_dbus_message_get_arg0_path(self.to_glib_none().0)) }
195    }
196
197    /// Gets the body of a message.
198    ///
199    /// # Returns
200    ///
201    /// A [type@GLib.Variant], or `NULL` if the
202    ///   body is empty
203    #[doc(alias = "g_dbus_message_get_body")]
204    #[doc(alias = "get_body")]
205    pub fn body(&self) -> Option<glib::Variant> {
206        unsafe { from_glib_none(ffi::g_dbus_message_get_body(self.to_glib_none().0)) }
207    }
208
209    /// Gets the byte order of @self.
210    ///
211    /// # Returns
212    ///
213    /// The byte order
214    #[doc(alias = "g_dbus_message_get_byte_order")]
215    #[doc(alias = "get_byte_order")]
216    pub fn byte_order(&self) -> DBusMessageByteOrder {
217        unsafe { from_glib(ffi::g_dbus_message_get_byte_order(self.to_glib_none().0)) }
218    }
219
220    /// Convenience getter for the [enum@Gio.DBusMessageHeaderField.DESTINATION]
221    /// header field.
222    ///
223    /// # Returns
224    ///
225    /// The value
226    #[doc(alias = "g_dbus_message_get_destination")]
227    #[doc(alias = "get_destination")]
228    pub fn destination(&self) -> Option<glib::GString> {
229        unsafe { from_glib_none(ffi::g_dbus_message_get_destination(self.to_glib_none().0)) }
230    }
231
232    /// Convenience getter for the [enum@Gio.DBusMessageHeaderField.ERROR_NAME]
233    /// header field.
234    ///
235    /// # Returns
236    ///
237    /// The value
238    #[doc(alias = "g_dbus_message_get_error_name")]
239    #[doc(alias = "get_error_name")]
240    pub fn error_name(&self) -> Option<glib::GString> {
241        unsafe { from_glib_none(ffi::g_dbus_message_get_error_name(self.to_glib_none().0)) }
242    }
243
244    /// Gets the flags for @self.
245    ///
246    /// # Returns
247    ///
248    /// Flags that are set (typically values from the
249    ///   [`DBusMessageFlags`][crate::DBusMessageFlags] enumeration bitwise ORed together)
250    #[doc(alias = "g_dbus_message_get_flags")]
251    #[doc(alias = "get_flags")]
252    pub fn flags(&self) -> DBusMessageFlags {
253        unsafe { from_glib(ffi::g_dbus_message_get_flags(self.to_glib_none().0)) }
254    }
255
256    /// Gets a header field on @self.
257    ///
258    /// The caller is responsible for checking the type of the returned
259    /// [type@GLib.Variant] matches what is expected.
260    /// ## `header_field`
261    /// a 8-bit unsigned integer (typically a value from the
262    ///   [`DBusMessageHeaderField`][crate::DBusMessageHeaderField] enumeration)
263    ///
264    /// # Returns
265    ///
266    /// A [type@GLib.Variant] with the value, or
267    ///   `NULL` if the header was not found
268    #[doc(alias = "g_dbus_message_get_header")]
269    #[doc(alias = "get_header")]
270    pub fn header(&self, header_field: DBusMessageHeaderField) -> Option<glib::Variant> {
271        unsafe {
272            from_glib_none(ffi::g_dbus_message_get_header(
273                self.to_glib_none().0,
274                header_field.into_glib(),
275            ))
276        }
277    }
278
279    /// Convenience getter for the [enum@Gio.DBusMessageHeaderField.INTERFACE] header
280    /// field.
281    ///
282    /// # Returns
283    ///
284    /// The value
285    #[doc(alias = "g_dbus_message_get_interface")]
286    #[doc(alias = "get_interface")]
287    pub fn interface(&self) -> Option<glib::GString> {
288        unsafe { from_glib_none(ffi::g_dbus_message_get_interface(self.to_glib_none().0)) }
289    }
290
291    /// Checks whether @self is locked.
292    ///
293    /// To monitor changes to this value, connect to the
294    /// [`notify`][struct@crate::glib::Object#notify] signal to listen for changes on the
295    /// [`locked`][struct@crate::DBusMessage#locked] property.
296    ///
297    /// # Returns
298    ///
299    /// true if @self is locked, false otherwise
300    #[doc(alias = "g_dbus_message_get_locked")]
301    #[doc(alias = "get_locked")]
302    #[doc(alias = "locked")]
303    pub fn is_locked(&self) -> bool {
304        unsafe { from_glib(ffi::g_dbus_message_get_locked(self.to_glib_none().0)) }
305    }
306
307    /// Convenience getter for the [enum@Gio.DBusMessageHeaderField.MEMBER] header
308    /// field.
309    ///
310    /// # Returns
311    ///
312    /// The value
313    #[doc(alias = "g_dbus_message_get_member")]
314    #[doc(alias = "get_member")]
315    pub fn member(&self) -> Option<glib::GString> {
316        unsafe { from_glib_none(ffi::g_dbus_message_get_member(self.to_glib_none().0)) }
317    }
318
319    /// Gets the type of @self.
320    ///
321    /// # Returns
322    ///
323    /// A 8-bit unsigned integer (typically a value from the
324    ///   [`DBusMessageType`][crate::DBusMessageType] enumeration)
325    #[doc(alias = "g_dbus_message_get_message_type")]
326    #[doc(alias = "get_message_type")]
327    pub fn message_type(&self) -> DBusMessageType {
328        unsafe { from_glib(ffi::g_dbus_message_get_message_type(self.to_glib_none().0)) }
329    }
330
331    /// Convenience getter for the [enum@Gio.DBusMessageHeaderField.NUM_UNIX_FDS]
332    /// header field.
333    ///
334    /// # Returns
335    ///
336    /// The value
337    #[cfg(unix)]
338    #[cfg_attr(docsrs, doc(cfg(unix)))]
339    #[doc(alias = "g_dbus_message_get_num_unix_fds")]
340    #[doc(alias = "get_num_unix_fds")]
341    pub fn num_unix_fds(&self) -> u32 {
342        unsafe { ffi::g_dbus_message_get_num_unix_fds(self.to_glib_none().0) }
343    }
344
345    /// Convenience getter for the [enum@Gio.DBusMessageHeaderField.PATH] header
346    /// field.
347    ///
348    /// # Returns
349    ///
350    /// The value
351    #[doc(alias = "g_dbus_message_get_path")]
352    #[doc(alias = "get_path")]
353    pub fn path(&self) -> Option<glib::GString> {
354        unsafe { from_glib_none(ffi::g_dbus_message_get_path(self.to_glib_none().0)) }
355    }
356
357    /// Convenience getter for the [enum@Gio.DBusMessageHeaderField.REPLY_SERIAL]
358    /// header field.
359    ///
360    /// # Returns
361    ///
362    /// The value
363    #[doc(alias = "g_dbus_message_get_reply_serial")]
364    #[doc(alias = "get_reply_serial")]
365    pub fn reply_serial(&self) -> u32 {
366        unsafe { ffi::g_dbus_message_get_reply_serial(self.to_glib_none().0) }
367    }
368
369    /// Convenience getter for the [enum@Gio.DBusMessageHeaderField.SENDER] header
370    /// field.
371    ///
372    /// # Returns
373    ///
374    /// The value
375    #[doc(alias = "g_dbus_message_get_sender")]
376    #[doc(alias = "get_sender")]
377    pub fn sender(&self) -> Option<glib::GString> {
378        unsafe { from_glib_none(ffi::g_dbus_message_get_sender(self.to_glib_none().0)) }
379    }
380
381    /// Gets the serial for @self.
382    ///
383    /// # Returns
384    ///
385    /// The serial number, which should not be zero
386    #[doc(alias = "g_dbus_message_get_serial")]
387    #[doc(alias = "get_serial")]
388    pub fn serial(&self) -> u32 {
389        unsafe { ffi::g_dbus_message_get_serial(self.to_glib_none().0) }
390    }
391
392    /// Convenience getter for the [enum@Gio.DBusMessageHeaderField.SIGNATURE header
393    /// field.
394    ///
395    /// This will always be non-`NULL`, but may be an empty string.
396    ///
397    /// # Returns
398    ///
399    /// The value
400    #[doc(alias = "g_dbus_message_get_signature")]
401    #[doc(alias = "get_signature")]
402    pub fn signature(&self) -> glib::GString {
403        unsafe { from_glib_none(ffi::g_dbus_message_get_signature(self.to_glib_none().0)) }
404    }
405
406    /// Gets the UNIX file descriptors associated with @self, if any.
407    ///
408    /// This method is only available on UNIX.
409    ///
410    /// The file descriptors normally correspond to `G_VARIANT_TYPE_HANDLE`
411    /// values in the body of the message. For example, if
412    /// [`glib::Variant::handle()`][crate::glib::Variant::handle()] returns 5, that is intended to be a
413    /// reference to the file descriptor that can be accessed by
414    /// `g_unix_fd_list_get (list, 5, ...)`.
415    ///
416    /// # Returns
417    ///
418    /// A [`UnixFDList`][crate::UnixFDList] or `NULL` if no
419    ///   file descriptors are associated
420    #[cfg(unix)]
421    #[cfg_attr(docsrs, doc(cfg(unix)))]
422    #[doc(alias = "g_dbus_message_get_unix_fd_list")]
423    #[doc(alias = "get_unix_fd_list")]
424    pub fn unix_fd_list(&self) -> Option<UnixFDList> {
425        unsafe { from_glib_none(ffi::g_dbus_message_get_unix_fd_list(self.to_glib_none().0)) }
426    }
427
428    /// Locks the message.
429    ///
430    /// If @self is locked already, this does nothing.
431    #[doc(alias = "g_dbus_message_lock")]
432    pub fn lock(&self) {
433        unsafe {
434            ffi::g_dbus_message_lock(self.to_glib_none().0);
435        }
436    }
437
438    /// Creates a new D-Bus message that is an error reply to @self.
439    /// ## `error_name`
440    /// a valid D-Bus error name
441    /// ## `error_message`
442    /// the D-Bus error message
443    ///
444    /// # Returns
445    ///
446    /// The D-Bus message
447    #[doc(alias = "g_dbus_message_new_method_error_literal")]
448    #[must_use]
449    pub fn new_method_error_literal(&self, error_name: &str, error_message: &str) -> DBusMessage {
450        unsafe {
451            from_glib_full(ffi::g_dbus_message_new_method_error_literal(
452                self.to_glib_none().0,
453                error_name.to_glib_none().0,
454                error_message.to_glib_none().0,
455            ))
456        }
457    }
458
459    //#[doc(alias = "g_dbus_message_new_method_error_valist")]
460    //#[must_use]
461    //pub fn new_method_error_valist(&self, error_name: &str, error_message_format: &str, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) -> DBusMessage {
462    //    unsafe { TODO: call ffi:g_dbus_message_new_method_error_valist() }
463    //}
464
465    /// Creates a new D-Bus message that is a reply to @self.
466    ///
467    /// # Returns
468    ///
469    /// The D-Bus message
470    #[doc(alias = "g_dbus_message_new_method_reply")]
471    #[must_use]
472    pub fn new_method_reply(&self) -> DBusMessage {
473        unsafe { from_glib_full(ffi::g_dbus_message_new_method_reply(self.to_glib_none().0)) }
474    }
475
476    ///  uint32 1
477    /// Body: ()
478    /// UNIX File Descriptors:
479    ///   fd 12: dev=0:10,mode=020620,ino=5,uid=500,gid=5,rdev=136:2,size=0,atime=1273085037,mtime=1273085851,ctime=1272982635
480    /// ```text
481    ///
482    /// ## `indent`
483    /// indentation level
484    ///
485    /// # Returns
486    ///
487    /// Human readable description
488    ///   of @self
489    #[doc(alias = "g_dbus_message_print")]
490    pub fn print(&self, indent: u32) -> glib::GString {
491        unsafe { from_glib_full(ffi::g_dbus_message_print(self.to_glib_none().0, indent)) }
492    }
493
494    /// Sets the body of @self.
495    ///
496    /// As a side-effect the [enum@Gio.DBusMessageHeaderField.SIGNATURE] header field
497    ///   is set to the type string of @body (or cleared if @body is `NULL`).
498    ///
499    /// If @body is floating, @self assumes ownership of @body.
500    /// ## `body`
501    /// a [type@GLib.Variant] containing a tuple, or `NULL` if no body is
502    ///   needed
503    #[doc(alias = "g_dbus_message_set_body")]
504    pub fn set_body(&self, body: &glib::Variant) {
505        unsafe {
506            ffi::g_dbus_message_set_body(self.to_glib_none().0, body.to_glib_none().0);
507        }
508    }
509
510    /// Sets the byte order of @self.
511    /// ## `byte_order`
512    /// the byte order
513    #[doc(alias = "g_dbus_message_set_byte_order")]
514    pub fn set_byte_order(&self, byte_order: DBusMessageByteOrder) {
515        unsafe {
516            ffi::g_dbus_message_set_byte_order(self.to_glib_none().0, byte_order.into_glib());
517        }
518    }
519
520    /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.DESTINATION]
521    /// header field.
522    /// ## `value`
523    /// the value to set
524    #[doc(alias = "g_dbus_message_set_destination")]
525    pub fn set_destination(&self, value: Option<&str>) {
526        unsafe {
527            ffi::g_dbus_message_set_destination(self.to_glib_none().0, value.to_glib_none().0);
528        }
529    }
530
531    /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.ERROR_NAME]
532    /// header field.
533    /// ## `value`
534    /// the value to set
535    #[doc(alias = "g_dbus_message_set_error_name")]
536    pub fn set_error_name(&self, value: Option<&str>) {
537        unsafe {
538            ffi::g_dbus_message_set_error_name(self.to_glib_none().0, value.to_glib_none().0);
539        }
540    }
541
542    /// Sets the flags to set on @self.
543    /// ## `flags`
544    /// flags for @self that are set (typically values from the
545    ///   [`DBusMessageFlags`][crate::DBusMessageFlags] enumeration bitwise ORed together)
546    #[doc(alias = "g_dbus_message_set_flags")]
547    pub fn set_flags(&self, flags: DBusMessageFlags) {
548        unsafe {
549            ffi::g_dbus_message_set_flags(self.to_glib_none().0, flags.into_glib());
550        }
551    }
552
553    /// Sets a header field on @self.
554    ///
555    /// If @value is floating, @self assumes ownership of @value.
556    /// ## `header_field`
557    /// a 8-bit unsigned integer (typically a value from the
558    ///   [`DBusMessageHeaderField`][crate::DBusMessageHeaderField] enumeration)
559    /// ## `value`
560    /// a [type@GLib.Variant] to set the header field, or `NULL`
561    ///   to clear the header field.
562    #[doc(alias = "g_dbus_message_set_header")]
563    pub fn set_header(&self, header_field: DBusMessageHeaderField, value: Option<&glib::Variant>) {
564        unsafe {
565            ffi::g_dbus_message_set_header(
566                self.to_glib_none().0,
567                header_field.into_glib(),
568                value.to_glib_none().0,
569            );
570        }
571    }
572
573    /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.INTERFACE] header
574    /// field.
575    /// ## `value`
576    /// the value to set
577    #[doc(alias = "g_dbus_message_set_interface")]
578    pub fn set_interface(&self, value: Option<&str>) {
579        unsafe {
580            ffi::g_dbus_message_set_interface(self.to_glib_none().0, value.to_glib_none().0);
581        }
582    }
583
584    /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.MEMBER] header
585    /// field.
586    /// ## `value`
587    /// the value to set
588    #[doc(alias = "g_dbus_message_set_member")]
589    pub fn set_member(&self, value: Option<&str>) {
590        unsafe {
591            ffi::g_dbus_message_set_member(self.to_glib_none().0, value.to_glib_none().0);
592        }
593    }
594
595    /// Sets @self to be of @type_.
596    /// ## `type_`
597    /// a 8-bit unsigned integer (typically a value from the
598    ///   [`DBusMessageType`][crate::DBusMessageType] enumeration)
599    #[doc(alias = "g_dbus_message_set_message_type")]
600    pub fn set_message_type(&self, type_: DBusMessageType) {
601        unsafe {
602            ffi::g_dbus_message_set_message_type(self.to_glib_none().0, type_.into_glib());
603        }
604    }
605
606    /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.NUM_UNIX_FDS]
607    /// header field.
608    /// ## `value`
609    /// the value to set
610    #[cfg(unix)]
611    #[cfg_attr(docsrs, doc(cfg(unix)))]
612    #[doc(alias = "g_dbus_message_set_num_unix_fds")]
613    pub fn set_num_unix_fds(&self, value: u32) {
614        unsafe {
615            ffi::g_dbus_message_set_num_unix_fds(self.to_glib_none().0, value);
616        }
617    }
618
619    /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.PATH] header
620    /// field.
621    /// ## `value`
622    /// the value to set
623    #[doc(alias = "g_dbus_message_set_path")]
624    pub fn set_path(&self, value: Option<&str>) {
625        unsafe {
626            ffi::g_dbus_message_set_path(self.to_glib_none().0, value.to_glib_none().0);
627        }
628    }
629
630    /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.REPLY_SERIAL]
631    /// header field.
632    /// ## `value`
633    /// the value to set
634    #[doc(alias = "g_dbus_message_set_reply_serial")]
635    pub fn set_reply_serial(&self, value: u32) {
636        unsafe {
637            ffi::g_dbus_message_set_reply_serial(self.to_glib_none().0, value);
638        }
639    }
640
641    /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.SENDER] header
642    /// field.
643    /// ## `value`
644    /// the value to set
645    #[doc(alias = "g_dbus_message_set_sender")]
646    pub fn set_sender(&self, value: Option<&str>) {
647        unsafe {
648            ffi::g_dbus_message_set_sender(self.to_glib_none().0, value.to_glib_none().0);
649        }
650    }
651
652    /// Sets the serial for @self.
653    ///
654    /// The [D-Bus specification](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages)
655    /// does not allow the @serial to be zero.
656    /// ## `serial`
657    /// a serial number, which must not be zero
658    #[doc(alias = "g_dbus_message_set_serial")]
659    pub fn set_serial(&self, serial: u32) {
660        unsafe {
661            ffi::g_dbus_message_set_serial(self.to_glib_none().0, serial);
662        }
663    }
664
665    /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.SIGNATURE] header
666    /// field.
667    /// ## `value`
668    /// the value to set
669    #[doc(alias = "g_dbus_message_set_signature")]
670    pub fn set_signature(&self, value: Option<&str>) {
671        unsafe {
672            ffi::g_dbus_message_set_signature(self.to_glib_none().0, value.to_glib_none().0);
673        }
674    }
675
676    /// Sets the UNIX file descriptors associated with @self.
677    ///
678    /// As a side-effect the [enum@Gio.DBusMessageHeaderField.NUM_UNIX_FDS] header
679    /// field is set to the number of fds in @fd_list (or cleared if
680    /// @fd_list is `NULL`).
681    ///
682    /// This method is only available on UNIX.
683    ///
684    /// When designing D-Bus APIs that are intended to be interoperable,
685    /// please note that non-GDBus implementations of D-Bus can usually only
686    /// access file descriptors if they are referenced by a value of type
687    /// `G_VARIANT_TYPE_HANDLE` in the body of the message.
688    /// ## `fd_list`
689    /// A [`UnixFDList`][crate::UnixFDList], or `NULL` to clear
690    #[cfg(unix)]
691    #[cfg_attr(docsrs, doc(cfg(unix)))]
692    #[doc(alias = "g_dbus_message_set_unix_fd_list")]
693    pub fn set_unix_fd_list(&self, fd_list: Option<&impl IsA<UnixFDList>>) {
694        unsafe {
695            ffi::g_dbus_message_set_unix_fd_list(
696                self.to_glib_none().0,
697                fd_list.map(|p| p.as_ref()).to_glib_none().0,
698            );
699        }
700    }
701
702    /// Serializes @self to a blob.
703    ///
704    /// The byte order returned by [`byte_order()`][Self::byte_order()] will be
705    /// used.
706    /// ## `capabilities`
707    /// flags describing what protocol features are supported
708    ///
709    /// # Returns
710    ///
711    /// A pointer to a
712    ///   valid binary D-Bus message of @out_size bytes generated by @self
713    #[doc(alias = "g_dbus_message_to_blob")]
714    pub fn to_blob(&self, capabilities: DBusCapabilityFlags) -> Result<Vec<u8>, glib::Error> {
715        unsafe {
716            let mut out_size = std::mem::MaybeUninit::uninit();
717            let mut error = std::ptr::null_mut();
718            let ret = ffi::g_dbus_message_to_blob(
719                self.to_glib_none().0,
720                out_size.as_mut_ptr(),
721                capabilities.into_glib(),
722                &mut error,
723            );
724            if error.is_null() {
725                Ok(FromGlibContainer::from_glib_full_num(
726                    ret,
727                    out_size.assume_init() as _,
728                ))
729            } else {
730                Err(from_glib_full(error))
731            }
732        }
733    }
734
735    /// s body.
736    ///
737    /// If @self is not of type [enum@Gio.DBusMessageType.ERROR], this function
738    /// does nothing and returns false.
739    ///
740    /// # Returns
741    ///
742    /// true if @error was set, false otherwise
743    #[doc(alias = "g_dbus_message_to_gerror")]
744    pub fn to_gerror(&self) -> Result<(), glib::Error> {
745        unsafe {
746            let mut error = std::ptr::null_mut();
747            let is_ok = ffi::g_dbus_message_to_gerror(self.to_glib_none().0, &mut error);
748            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
749            if error.is_null() {
750                Ok(())
751            } else {
752                Err(from_glib_full(error))
753            }
754        }
755    }
756
757    /// Utility function to calculate how many bytes are needed to
758    /// completely deserialize the D-Bus message stored at @blob.
759    ///
760    /// An error will be returned if @blob contains invalid data, or if not enough
761    /// data is available to determine the size.
762    /// ## `blob`
763    /// a blob representing a
764    ///   binary D-Bus message.
765    ///
766    /// # Returns
767    ///
768    /// Number of bytes needed or `-1` if @error is set
769    #[doc(alias = "g_dbus_message_bytes_needed")]
770    pub fn bytes_needed(blob: &[u8]) -> Result<isize, glib::Error> {
771        let blob_len = blob.len() as _;
772        unsafe {
773            let mut error = std::ptr::null_mut();
774            let ret = ffi::g_dbus_message_bytes_needed(blob.to_glib_none().0, blob_len, &mut error);
775            if error.is_null() {
776                Ok(ret)
777            } else {
778                Err(from_glib_full(error))
779            }
780        }
781    }
782
783    #[doc(alias = "locked")]
784    pub fn connect_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
785        unsafe extern "C" fn notify_locked_trampoline<F: Fn(&DBusMessage) + 'static>(
786            this: *mut ffi::GDBusMessage,
787            _param_spec: glib::ffi::gpointer,
788            f: glib::ffi::gpointer,
789        ) {
790            unsafe {
791                let f: &F = &*(f as *const F);
792                f(&from_glib_borrow(this))
793            }
794        }
795        unsafe {
796            let f: Box_<F> = Box_::new(f);
797            connect_raw(
798                self.as_ptr() as *mut _,
799                c"notify::locked".as_ptr(),
800                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
801                    notify_locked_trampoline::<F> as *const (),
802                )),
803                Box_::into_raw(f),
804            )
805        }
806    }
807}
808
809impl Default for DBusMessage {
810    fn default() -> Self {
811        Self::new()
812    }
813}