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 /// Produces a human-readable multi-line description of @self.
477 ///
478 /// The contents and formatting are subject to change at any time and no ABI
479 /// guarantees are given. Typical output looks something like this:
480 /// ```text
481 /// Flags: none
482 /// Version: 0
483 /// Serial: 4
484 /// Headers:
485 /// path -> objectpath '/org/gtk/GDBus/TestObject'
486 /// interface -> 'org.gtk.GDBus.TestInterface'
487 /// member -> 'GimmeStdout'
488 /// destination -> ':1.146'
489 /// Body: ()
490 /// UNIX File Descriptors:
491 /// (none)
492 /// ```
493 /// or
494 /// ```text
495 /// Flags: no-reply-expected
496 /// Version: 0
497 /// Serial: 477
498 /// Headers:
499 /// reply-serial -> uint32 4
500 /// destination -> ':1.159'
501 /// sender -> ':1.146'
502 /// num-unix-fds -> uint32 1
503 /// Body: ()
504 /// UNIX File Descriptors:
505 /// fd 12: dev=0:10,mode=020620,ino=5,uid=500,gid=5,rdev=136:2,size=0,atime=1273085037,mtime=1273085851,ctime=1272982635
506 /// ```
507 /// ## `indent`
508 /// indentation level
509 ///
510 /// # Returns
511 ///
512 /// Human readable description
513 /// of @self
514 #[doc(alias = "g_dbus_message_print")]
515 pub fn print(&self, indent: u32) -> glib::GString {
516 unsafe { from_glib_full(ffi::g_dbus_message_print(self.to_glib_none().0, indent)) }
517 }
518
519 /// Sets the body of @self.
520 ///
521 /// As a side-effect the [enum@Gio.DBusMessageHeaderField.SIGNATURE] header field
522 /// is set to the type string of @body (or cleared if @body is `NULL`).
523 ///
524 /// If @body is floating, @self assumes ownership of @body.
525 /// ## `body`
526 /// a [type@GLib.Variant] containing a tuple, or `NULL` if no body is
527 /// needed
528 #[doc(alias = "g_dbus_message_set_body")]
529 pub fn set_body(&self, body: &glib::Variant) {
530 unsafe {
531 ffi::g_dbus_message_set_body(self.to_glib_none().0, body.to_glib_none().0);
532 }
533 }
534
535 /// Sets the byte order of @self.
536 /// ## `byte_order`
537 /// the byte order
538 #[doc(alias = "g_dbus_message_set_byte_order")]
539 pub fn set_byte_order(&self, byte_order: DBusMessageByteOrder) {
540 unsafe {
541 ffi::g_dbus_message_set_byte_order(self.to_glib_none().0, byte_order.into_glib());
542 }
543 }
544
545 /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.DESTINATION]
546 /// header field.
547 /// ## `value`
548 /// the value to set
549 #[doc(alias = "g_dbus_message_set_destination")]
550 pub fn set_destination(&self, value: Option<&str>) {
551 unsafe {
552 ffi::g_dbus_message_set_destination(self.to_glib_none().0, value.to_glib_none().0);
553 }
554 }
555
556 /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.ERROR_NAME]
557 /// header field.
558 /// ## `value`
559 /// the value to set
560 #[doc(alias = "g_dbus_message_set_error_name")]
561 pub fn set_error_name(&self, value: Option<&str>) {
562 unsafe {
563 ffi::g_dbus_message_set_error_name(self.to_glib_none().0, value.to_glib_none().0);
564 }
565 }
566
567 /// Sets the flags to set on @self.
568 /// ## `flags`
569 /// flags for @self that are set (typically values from the
570 /// [`DBusMessageFlags`][crate::DBusMessageFlags] enumeration bitwise ORed together)
571 #[doc(alias = "g_dbus_message_set_flags")]
572 pub fn set_flags(&self, flags: DBusMessageFlags) {
573 unsafe {
574 ffi::g_dbus_message_set_flags(self.to_glib_none().0, flags.into_glib());
575 }
576 }
577
578 /// Sets a header field on @self.
579 ///
580 /// If @value is floating, @self assumes ownership of @value.
581 /// ## `header_field`
582 /// a 8-bit unsigned integer (typically a value from the
583 /// [`DBusMessageHeaderField`][crate::DBusMessageHeaderField] enumeration)
584 /// ## `value`
585 /// a [type@GLib.Variant] to set the header field, or `NULL`
586 /// to clear the header field.
587 #[doc(alias = "g_dbus_message_set_header")]
588 pub fn set_header(&self, header_field: DBusMessageHeaderField, value: Option<&glib::Variant>) {
589 unsafe {
590 ffi::g_dbus_message_set_header(
591 self.to_glib_none().0,
592 header_field.into_glib(),
593 value.to_glib_none().0,
594 );
595 }
596 }
597
598 /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.INTERFACE] header
599 /// field.
600 /// ## `value`
601 /// the value to set
602 #[doc(alias = "g_dbus_message_set_interface")]
603 pub fn set_interface(&self, value: Option<&str>) {
604 unsafe {
605 ffi::g_dbus_message_set_interface(self.to_glib_none().0, value.to_glib_none().0);
606 }
607 }
608
609 /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.MEMBER] header
610 /// field.
611 /// ## `value`
612 /// the value to set
613 #[doc(alias = "g_dbus_message_set_member")]
614 pub fn set_member(&self, value: Option<&str>) {
615 unsafe {
616 ffi::g_dbus_message_set_member(self.to_glib_none().0, value.to_glib_none().0);
617 }
618 }
619
620 /// Sets @self to be of @type_.
621 /// ## `type_`
622 /// a 8-bit unsigned integer (typically a value from the
623 /// [`DBusMessageType`][crate::DBusMessageType] enumeration)
624 #[doc(alias = "g_dbus_message_set_message_type")]
625 pub fn set_message_type(&self, type_: DBusMessageType) {
626 unsafe {
627 ffi::g_dbus_message_set_message_type(self.to_glib_none().0, type_.into_glib());
628 }
629 }
630
631 /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.NUM_UNIX_FDS]
632 /// header field.
633 /// ## `value`
634 /// the value to set
635 #[cfg(unix)]
636 #[cfg_attr(docsrs, doc(cfg(unix)))]
637 #[doc(alias = "g_dbus_message_set_num_unix_fds")]
638 pub fn set_num_unix_fds(&self, value: u32) {
639 unsafe {
640 ffi::g_dbus_message_set_num_unix_fds(self.to_glib_none().0, value);
641 }
642 }
643
644 /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.PATH] header
645 /// field.
646 /// ## `value`
647 /// the value to set
648 #[doc(alias = "g_dbus_message_set_path")]
649 pub fn set_path(&self, value: Option<&str>) {
650 unsafe {
651 ffi::g_dbus_message_set_path(self.to_glib_none().0, value.to_glib_none().0);
652 }
653 }
654
655 /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.REPLY_SERIAL]
656 /// header field.
657 /// ## `value`
658 /// the value to set
659 #[doc(alias = "g_dbus_message_set_reply_serial")]
660 pub fn set_reply_serial(&self, value: u32) {
661 unsafe {
662 ffi::g_dbus_message_set_reply_serial(self.to_glib_none().0, value);
663 }
664 }
665
666 /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.SENDER] header
667 /// field.
668 /// ## `value`
669 /// the value to set
670 #[doc(alias = "g_dbus_message_set_sender")]
671 pub fn set_sender(&self, value: Option<&str>) {
672 unsafe {
673 ffi::g_dbus_message_set_sender(self.to_glib_none().0, value.to_glib_none().0);
674 }
675 }
676
677 /// Sets the serial for @self.
678 ///
679 /// The [D-Bus specification](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages)
680 /// does not allow the @serial to be zero.
681 /// ## `serial`
682 /// a serial number, which must not be zero
683 #[doc(alias = "g_dbus_message_set_serial")]
684 pub fn set_serial(&self, serial: u32) {
685 unsafe {
686 ffi::g_dbus_message_set_serial(self.to_glib_none().0, serial);
687 }
688 }
689
690 /// Convenience setter for the [enum@Gio.DBusMessageHeaderField.SIGNATURE] header
691 /// field.
692 /// ## `value`
693 /// the value to set
694 #[doc(alias = "g_dbus_message_set_signature")]
695 pub fn set_signature(&self, value: Option<&str>) {
696 unsafe {
697 ffi::g_dbus_message_set_signature(self.to_glib_none().0, value.to_glib_none().0);
698 }
699 }
700
701 /// Sets the UNIX file descriptors associated with @self.
702 ///
703 /// As a side-effect the [enum@Gio.DBusMessageHeaderField.NUM_UNIX_FDS] header
704 /// field is set to the number of fds in @fd_list (or cleared if
705 /// @fd_list is `NULL`).
706 ///
707 /// This method is only available on UNIX.
708 ///
709 /// When designing D-Bus APIs that are intended to be interoperable,
710 /// please note that non-GDBus implementations of D-Bus can usually only
711 /// access file descriptors if they are referenced by a value of type
712 /// `G_VARIANT_TYPE_HANDLE` in the body of the message.
713 /// ## `fd_list`
714 /// A [`UnixFDList`][crate::UnixFDList], or `NULL` to clear
715 #[cfg(unix)]
716 #[cfg_attr(docsrs, doc(cfg(unix)))]
717 #[doc(alias = "g_dbus_message_set_unix_fd_list")]
718 pub fn set_unix_fd_list(&self, fd_list: Option<&impl IsA<UnixFDList>>) {
719 unsafe {
720 ffi::g_dbus_message_set_unix_fd_list(
721 self.to_glib_none().0,
722 fd_list.map(|p| p.as_ref()).to_glib_none().0,
723 );
724 }
725 }
726
727 /// Serializes @self to a blob.
728 ///
729 /// The byte order returned by [`byte_order()`][Self::byte_order()] will be
730 /// used.
731 /// ## `capabilities`
732 /// flags describing what protocol features are supported
733 ///
734 /// # Returns
735 ///
736 /// A pointer to a
737 /// valid binary D-Bus message of @out_size bytes generated by @self
738 #[doc(alias = "g_dbus_message_to_blob")]
739 pub fn to_blob(&self, capabilities: DBusCapabilityFlags) -> Result<Vec<u8>, glib::Error> {
740 unsafe {
741 let mut out_size = std::mem::MaybeUninit::uninit();
742 let mut error = std::ptr::null_mut();
743 let ret = ffi::g_dbus_message_to_blob(
744 self.to_glib_none().0,
745 out_size.as_mut_ptr(),
746 capabilities.into_glib(),
747 &mut error,
748 );
749 if error.is_null() {
750 Ok(FromGlibContainer::from_glib_full_num(
751 ret,
752 out_size.assume_init() as _,
753 ))
754 } else {
755 Err(from_glib_full(error))
756 }
757 }
758 }
759
760 /// Encodes the error in @self as a [type@GLib.Error].
761 ///
762 /// If @self is of type [enum@Gio.DBusMessageType.ERROR], this function
763 /// calls `Gio::DBusError::set_dbus_error()` using the information in the
764 /// [enum@Gio.DBusMessageHeaderField.ERROR_NAME] header field of @self as
765 /// well as the first string item in @self’s body.
766 ///
767 /// If @self is not of type [enum@Gio.DBusMessageType.ERROR], this function
768 /// does nothing and returns false.
769 ///
770 /// # Returns
771 ///
772 /// true if @error was set, false otherwise
773 #[doc(alias = "g_dbus_message_to_gerror")]
774 pub fn to_gerror(&self) -> Result<(), glib::Error> {
775 unsafe {
776 let mut error = std::ptr::null_mut();
777 let is_ok = ffi::g_dbus_message_to_gerror(self.to_glib_none().0, &mut error);
778 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
779 if error.is_null() {
780 Ok(())
781 } else {
782 Err(from_glib_full(error))
783 }
784 }
785 }
786
787 /// Utility function to calculate how many bytes are needed to
788 /// completely deserialize the D-Bus message stored at @blob.
789 ///
790 /// An error will be returned if @blob contains invalid data, or if not enough
791 /// data is available to determine the size.
792 /// ## `blob`
793 /// a blob representing a
794 /// binary D-Bus message.
795 ///
796 /// # Returns
797 ///
798 /// Number of bytes needed or `-1` if @error is set
799 #[doc(alias = "g_dbus_message_bytes_needed")]
800 pub fn bytes_needed(blob: &[u8]) -> Result<isize, glib::Error> {
801 let blob_len = blob.len() as _;
802 unsafe {
803 let mut error = std::ptr::null_mut();
804 let ret = ffi::g_dbus_message_bytes_needed(blob.to_glib_none().0, blob_len, &mut error);
805 if error.is_null() {
806 Ok(ret)
807 } else {
808 Err(from_glib_full(error))
809 }
810 }
811 }
812
813 #[doc(alias = "locked")]
814 pub fn connect_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
815 unsafe extern "C" fn notify_locked_trampoline<F: Fn(&DBusMessage) + 'static>(
816 this: *mut ffi::GDBusMessage,
817 _param_spec: glib::ffi::gpointer,
818 f: glib::ffi::gpointer,
819 ) {
820 unsafe {
821 let f: &F = &*(f as *const F);
822 f(&from_glib_borrow(this))
823 }
824 }
825 unsafe {
826 let f: Box_<F> = Box_::new(f);
827 connect_raw(
828 self.as_ptr() as *mut _,
829 c"notify::locked".as_ptr(),
830 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
831 notify_locked_trampoline::<F> as *const (),
832 )),
833 Box_::into_raw(f),
834 )
835 }
836 }
837}
838
839impl Default for DBusMessage {
840 fn default() -> Self {
841 Self::new()
842 }
843}