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