1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

#[cfg(unix)]
#[cfg_attr(docsrs, doc(cfg(unix)))]
use crate::UnixFDList;
use crate::{
    DBusCapabilityFlags, DBusMessageByteOrder, DBusMessageFlags, DBusMessageHeaderField,
    DBusMessageType,
};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// A type for representing D-Bus messages that can be sent or received
    /// on a [`DBusConnection`][crate::DBusConnection].
    ///
    /// ## Properties
    ///
    ///
    /// #### `locked`
    ///  Readable
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`]
    #[doc(alias = "GDBusMessage")]
    pub struct DBusMessage(Object<ffi::GDBusMessage>);

    match fn {
        type_ => || ffi::g_dbus_message_get_type(),
    }
}

impl DBusMessage {
    /// Creates a new empty #GDBusMessage.
    ///
    /// # Returns
    ///
    /// A #GDBusMessage. Free with g_object_unref().
    #[doc(alias = "g_dbus_message_new")]
    pub fn new() -> DBusMessage {
        unsafe { from_glib_full(ffi::g_dbus_message_new()) }
    }

    /// Creates a new #GDBusMessage from the data stored at @blob. The byte
    /// order that the message was in can be retrieved using
    /// g_dbus_message_get_byte_order().
    ///
    /// If the @blob cannot be parsed, contains invalid fields, or contains invalid
    /// headers, [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument] will be returned.
    /// ## `blob`
    /// A blob representing a binary D-Bus message.
    /// ## `capabilities`
    /// A #GDBusCapabilityFlags describing what protocol features are supported.
    ///
    /// # Returns
    ///
    /// A new #GDBusMessage or [`None`] if @error is set. Free with
    /// g_object_unref().
    #[doc(alias = "g_dbus_message_new_from_blob")]
    #[doc(alias = "new_from_blob")]
    pub fn from_blob(
        blob: &[u8],
        capabilities: DBusCapabilityFlags,
    ) -> Result<DBusMessage, glib::Error> {
        let blob_len = blob.len() as _;
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_message_new_from_blob(
                blob.to_glib_none().0,
                blob_len,
                capabilities.into_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Creates a new #GDBusMessage for a method call.
    /// ## `name`
    /// A valid D-Bus name or [`None`].
    /// ## `path`
    /// A valid object path.
    /// ## `interface_`
    /// A valid D-Bus interface name or [`None`].
    /// ## `method`
    /// A valid method name.
    ///
    /// # Returns
    ///
    /// A #GDBusMessage. Free with g_object_unref().
    #[doc(alias = "g_dbus_message_new_method_call")]
    pub fn new_method_call(
        name: Option<&str>,
        path: &str,
        interface_: Option<&str>,
        method: &str,
    ) -> DBusMessage {
        unsafe {
            from_glib_full(ffi::g_dbus_message_new_method_call(
                name.to_glib_none().0,
                path.to_glib_none().0,
                interface_.to_glib_none().0,
                method.to_glib_none().0,
            ))
        }
    }

    /// Creates a new #GDBusMessage for a signal emission.
    /// ## `path`
    /// A valid object path.
    /// ## `interface_`
    /// A valid D-Bus interface name.
    /// ## `signal`
    /// A valid signal name.
    ///
    /// # Returns
    ///
    /// A #GDBusMessage. Free with g_object_unref().
    #[doc(alias = "g_dbus_message_new_signal")]
    pub fn new_signal(path: &str, interface_: &str, signal: &str) -> DBusMessage {
        unsafe {
            from_glib_full(ffi::g_dbus_message_new_signal(
                path.to_glib_none().0,
                interface_.to_glib_none().0,
                signal.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_dbus_message_copy")]
    pub fn copy(&self) -> Result<DBusMessage, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_message_copy(self.to_glib_none().0, &mut error);
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Convenience to get the first item in the body of @self.
    ///
    /// See [`arg0_path()`][Self::arg0_path()] for returning object-path-typed
    /// arg0 values.
    ///
    /// # Returns
    ///
    /// The string item or [`None`] if the first item in the body of
    /// @self is not a string.
    #[doc(alias = "g_dbus_message_get_arg0")]
    #[doc(alias = "get_arg0")]
    pub fn arg0(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_arg0(self.to_glib_none().0)) }
    }

    /// Convenience to get the first item in the body of @self.
    ///
    /// See [`arg0()`][Self::arg0()] for returning string-typed arg0 values.
    ///
    /// # Returns
    ///
    /// The object path item or `NULL` if the first item in the
    ///   body of @self is not an object path.
    #[cfg(feature = "v2_80")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
    #[doc(alias = "g_dbus_message_get_arg0_path")]
    #[doc(alias = "get_arg0_path")]
    pub fn arg0_path(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_arg0_path(self.to_glib_none().0)) }
    }

    /// Gets the body of a message.
    ///
    /// # Returns
    ///
    /// A #GVariant or [`None`] if the body is
    /// empty. Do not free, it is owned by @self.
    #[doc(alias = "g_dbus_message_get_body")]
    #[doc(alias = "get_body")]
    pub fn body(&self) -> Option<glib::Variant> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_body(self.to_glib_none().0)) }
    }

    /// Gets the byte order of @self.
    ///
    /// # Returns
    ///
    /// The byte order.
    #[doc(alias = "g_dbus_message_get_byte_order")]
    #[doc(alias = "get_byte_order")]
    pub fn byte_order(&self) -> DBusMessageByteOrder {
        unsafe { from_glib(ffi::g_dbus_message_get_byte_order(self.to_glib_none().0)) }
    }

    /// Convenience getter for the [`DBusMessageHeaderField::Destination`][crate::DBusMessageHeaderField::Destination] header field.
    ///
    /// # Returns
    ///
    /// The value.
    #[doc(alias = "g_dbus_message_get_destination")]
    #[doc(alias = "get_destination")]
    pub fn destination(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_destination(self.to_glib_none().0)) }
    }

    /// Convenience getter for the [`DBusMessageHeaderField::ErrorName`][crate::DBusMessageHeaderField::ErrorName] header field.
    ///
    /// # Returns
    ///
    /// The value.
    #[doc(alias = "g_dbus_message_get_error_name")]
    #[doc(alias = "get_error_name")]
    pub fn error_name(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_error_name(self.to_glib_none().0)) }
    }

    /// Gets the flags for @self.
    ///
    /// # Returns
    ///
    /// Flags that are set (typically values from the #GDBusMessageFlags enumeration bitwise ORed together).
    #[doc(alias = "g_dbus_message_get_flags")]
    #[doc(alias = "get_flags")]
    pub fn flags(&self) -> DBusMessageFlags {
        unsafe { from_glib(ffi::g_dbus_message_get_flags(self.to_glib_none().0)) }
    }

    /// Gets a header field on @self.
    ///
    /// The caller is responsible for checking the type of the returned #GVariant
    /// matches what is expected.
    /// ## `header_field`
    /// A 8-bit unsigned integer (typically a value from the #GDBusMessageHeaderField enumeration)
    ///
    /// # Returns
    ///
    /// A #GVariant with the value if the header was found, [`None`]
    /// otherwise. Do not free, it is owned by @self.
    #[doc(alias = "g_dbus_message_get_header")]
    #[doc(alias = "get_header")]
    pub fn header(&self, header_field: DBusMessageHeaderField) -> Option<glib::Variant> {
        unsafe {
            from_glib_none(ffi::g_dbus_message_get_header(
                self.to_glib_none().0,
                header_field.into_glib(),
            ))
        }
    }

    /// Convenience getter for the [`DBusMessageHeaderField::Interface`][crate::DBusMessageHeaderField::Interface] header field.
    ///
    /// # Returns
    ///
    /// The value.
    #[doc(alias = "g_dbus_message_get_interface")]
    #[doc(alias = "get_interface")]
    pub fn interface(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_interface(self.to_glib_none().0)) }
    }

    /// Checks whether @self is locked. To monitor changes to this
    /// value, conncet to the #GObject::notify signal to listen for changes
    /// on the #GDBusMessage:locked property.
    ///
    /// # Returns
    ///
    /// [`true`] if @self is locked, [`false`] otherwise.
    #[doc(alias = "g_dbus_message_get_locked")]
    #[doc(alias = "get_locked")]
    pub fn is_locked(&self) -> bool {
        unsafe { from_glib(ffi::g_dbus_message_get_locked(self.to_glib_none().0)) }
    }

    /// Convenience getter for the [`DBusMessageHeaderField::Member`][crate::DBusMessageHeaderField::Member] header field.
    ///
    /// # Returns
    ///
    /// The value.
    #[doc(alias = "g_dbus_message_get_member")]
    #[doc(alias = "get_member")]
    pub fn member(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_member(self.to_glib_none().0)) }
    }

    /// Gets the type of @self.
    ///
    /// # Returns
    ///
    /// A 8-bit unsigned integer (typically a value from the #GDBusMessageType enumeration).
    #[doc(alias = "g_dbus_message_get_message_type")]
    #[doc(alias = "get_message_type")]
    pub fn message_type(&self) -> DBusMessageType {
        unsafe { from_glib(ffi::g_dbus_message_get_message_type(self.to_glib_none().0)) }
    }

    /// Convenience getter for the [`DBusMessageHeaderField::NumUnixFds`][crate::DBusMessageHeaderField::NumUnixFds] header field.
    ///
    /// # Returns
    ///
    /// The value.
    #[cfg(unix)]
    #[cfg_attr(docsrs, doc(cfg(unix)))]
    #[doc(alias = "g_dbus_message_get_num_unix_fds")]
    #[doc(alias = "get_num_unix_fds")]
    pub fn num_unix_fds(&self) -> u32 {
        unsafe { ffi::g_dbus_message_get_num_unix_fds(self.to_glib_none().0) }
    }

    /// Convenience getter for the [`DBusMessageHeaderField::Path`][crate::DBusMessageHeaderField::Path] header field.
    ///
    /// # Returns
    ///
    /// The value.
    #[doc(alias = "g_dbus_message_get_path")]
    #[doc(alias = "get_path")]
    pub fn path(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_path(self.to_glib_none().0)) }
    }

    /// Convenience getter for the [`DBusMessageHeaderField::ReplySerial`][crate::DBusMessageHeaderField::ReplySerial] header field.
    ///
    /// # Returns
    ///
    /// The value.
    #[doc(alias = "g_dbus_message_get_reply_serial")]
    #[doc(alias = "get_reply_serial")]
    pub fn reply_serial(&self) -> u32 {
        unsafe { ffi::g_dbus_message_get_reply_serial(self.to_glib_none().0) }
    }

    /// Convenience getter for the [`DBusMessageHeaderField::Sender`][crate::DBusMessageHeaderField::Sender] header field.
    ///
    /// # Returns
    ///
    /// The value.
    #[doc(alias = "g_dbus_message_get_sender")]
    #[doc(alias = "get_sender")]
    pub fn sender(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_sender(self.to_glib_none().0)) }
    }

    /// Gets the serial for @self.
    ///
    /// # Returns
    ///
    /// A #guint32.
    #[doc(alias = "g_dbus_message_get_serial")]
    #[doc(alias = "get_serial")]
    pub fn serial(&self) -> u32 {
        unsafe { ffi::g_dbus_message_get_serial(self.to_glib_none().0) }
    }

    /// Convenience getter for the [`DBusMessageHeaderField::Signature`][crate::DBusMessageHeaderField::Signature] header field.
    ///
    /// This will always be non-[`None`], but may be an empty string.
    ///
    /// # Returns
    ///
    /// The value.
    #[doc(alias = "g_dbus_message_get_signature")]
    #[doc(alias = "get_signature")]
    pub fn signature(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::g_dbus_message_get_signature(self.to_glib_none().0)) }
    }

    /// Gets the UNIX file descriptors associated with @self, if any.
    ///
    /// This method is only available on UNIX.
    ///
    /// The file descriptors normally correspond to `G_VARIANT_TYPE_HANDLE`
    /// values in the body of the message. For example,
    /// if g_variant_get_handle() returns 5, that is intended to be a reference
    /// to the file descriptor that can be accessed by
    /// `g_unix_fd_list_get (list, 5, ...)`.
    ///
    /// # Returns
    ///
    /// A #GUnixFDList or [`None`] if no file descriptors are
    /// associated. Do not free, this object is owned by @self.
    #[cfg(unix)]
    #[cfg_attr(docsrs, doc(cfg(unix)))]
    #[doc(alias = "g_dbus_message_get_unix_fd_list")]
    #[doc(alias = "get_unix_fd_list")]
    pub fn unix_fd_list(&self) -> Option<UnixFDList> {
        unsafe { from_glib_none(ffi::g_dbus_message_get_unix_fd_list(self.to_glib_none().0)) }
    }

    /// If @self is locked, does nothing. Otherwise locks the message.
    #[doc(alias = "g_dbus_message_lock")]
    pub fn lock(&self) {
        unsafe {
            ffi::g_dbus_message_lock(self.to_glib_none().0);
        }
    }

    //#[doc(alias = "g_dbus_message_new_method_error")]
    //#[must_use]
    //pub fn new_method_error(&self, error_name: &str, error_message_format: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> DBusMessage {
    //    unsafe { TODO: call ffi:g_dbus_message_new_method_error() }
    //}

    /// Creates a new #GDBusMessage that is an error reply to @self.
    /// ## `error_name`
    /// A valid D-Bus error name.
    /// ## `error_message`
    /// The D-Bus error message.
    ///
    /// # Returns
    ///
    /// A #GDBusMessage. Free with g_object_unref().
    #[doc(alias = "g_dbus_message_new_method_error_literal")]
    #[must_use]
    pub fn new_method_error_literal(&self, error_name: &str, error_message: &str) -> DBusMessage {
        unsafe {
            from_glib_full(ffi::g_dbus_message_new_method_error_literal(
                self.to_glib_none().0,
                error_name.to_glib_none().0,
                error_message.to_glib_none().0,
            ))
        }
    }

    //#[doc(alias = "g_dbus_message_new_method_error_valist")]
    //#[must_use]
    //pub fn new_method_error_valist(&self, error_name: &str, error_message_format: &str, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) -> DBusMessage {
    //    unsafe { TODO: call ffi:g_dbus_message_new_method_error_valist() }
    //}

    /// Creates a new #GDBusMessage that is a reply to @self.
    ///
    /// # Returns
    ///
    /// #GDBusMessage. Free with g_object_unref().
    #[doc(alias = "g_dbus_message_new_method_reply")]
    #[must_use]
    pub fn new_method_reply(&self) -> DBusMessage {
        unsafe { from_glib_full(ffi::g_dbus_message_new_method_reply(self.to_glib_none().0)) }
    }

    /// Produces a human-readable multi-line description of @self.
    ///
    /// The contents of the description has no ABI guarantees, the contents
    /// and formatting is subject to change at any time. Typical output
    /// looks something like this:
    /// ```text
    /// Flags:   none
    /// Version: 0
    /// Serial:  4
    /// Headers:
    ///   path -> objectpath '/org/gtk/GDBus/TestObject'
    ///   interface -> 'org.gtk.GDBus.TestInterface'
    ///   member -> 'GimmeStdout'
    ///   destination -> ':1.146'
    /// Body: ()
    /// UNIX File Descriptors:
    ///   (none)
    /// ```
    /// or
    /// ```text
    /// Flags:   no-reply-expected
    /// Version: 0
    /// Serial:  477
    /// Headers:
    ///   reply-serial -> uint32 4
    ///   destination -> ':1.159'
    ///   sender -> ':1.146'
    ///   num-unix-fds -> uint32 1
    /// Body: ()
    /// UNIX File Descriptors:
    ///   fd 12: dev=0:10,mode=020620,ino=5,uid=500,gid=5,rdev=136:2,size=0,atime=1273085037,mtime=1273085851,ctime=1272982635
    /// ```
    /// ## `indent`
    /// Indentation level.
    ///
    /// # Returns
    ///
    /// A string that should be freed with `free()`.
    #[doc(alias = "g_dbus_message_print")]
    pub fn print(&self, indent: u32) -> glib::GString {
        unsafe { from_glib_full(ffi::g_dbus_message_print(self.to_glib_none().0, indent)) }
    }

    /// Sets the body @self. As a side-effect the
    /// [`DBusMessageHeaderField::Signature`][crate::DBusMessageHeaderField::Signature] header field is set to the
    /// type string of @body (or cleared if @body is [`None`]).
    ///
    /// If @body is floating, @self assumes ownership of @body.
    /// ## `body`
    /// Either [`None`] or a #GVariant that is a tuple.
    #[doc(alias = "g_dbus_message_set_body")]
    pub fn set_body(&self, body: &glib::Variant) {
        unsafe {
            ffi::g_dbus_message_set_body(self.to_glib_none().0, body.to_glib_none().0);
        }
    }

    /// Sets the byte order of @self.
    /// ## `byte_order`
    /// The byte order.
    #[doc(alias = "g_dbus_message_set_byte_order")]
    pub fn set_byte_order(&self, byte_order: DBusMessageByteOrder) {
        unsafe {
            ffi::g_dbus_message_set_byte_order(self.to_glib_none().0, byte_order.into_glib());
        }
    }

    /// Convenience setter for the [`DBusMessageHeaderField::Destination`][crate::DBusMessageHeaderField::Destination] header field.
    /// ## `value`
    /// The value to set.
    #[doc(alias = "g_dbus_message_set_destination")]
    pub fn set_destination(&self, value: Option<&str>) {
        unsafe {
            ffi::g_dbus_message_set_destination(self.to_glib_none().0, value.to_glib_none().0);
        }
    }

    /// Convenience setter for the [`DBusMessageHeaderField::ErrorName`][crate::DBusMessageHeaderField::ErrorName] header field.
    /// ## `value`
    /// The value to set.
    #[doc(alias = "g_dbus_message_set_error_name")]
    pub fn set_error_name(&self, value: &str) {
        unsafe {
            ffi::g_dbus_message_set_error_name(self.to_glib_none().0, value.to_glib_none().0);
        }
    }

    /// Sets the flags to set on @self.
    /// ## `flags`
    /// Flags for @self that are set (typically values from the #GDBusMessageFlags
    /// enumeration bitwise ORed together).
    #[doc(alias = "g_dbus_message_set_flags")]
    pub fn set_flags(&self, flags: DBusMessageFlags) {
        unsafe {
            ffi::g_dbus_message_set_flags(self.to_glib_none().0, flags.into_glib());
        }
    }

    /// Sets a header field on @self.
    ///
    /// If @value is floating, @self assumes ownership of @value.
    /// ## `header_field`
    /// A 8-bit unsigned integer (typically a value from the #GDBusMessageHeaderField enumeration)
    /// ## `value`
    /// A #GVariant to set the header field or [`None`] to clear the header field.
    #[doc(alias = "g_dbus_message_set_header")]
    pub fn set_header(&self, header_field: DBusMessageHeaderField, value: Option<&glib::Variant>) {
        unsafe {
            ffi::g_dbus_message_set_header(
                self.to_glib_none().0,
                header_field.into_glib(),
                value.to_glib_none().0,
            );
        }
    }

    /// Convenience setter for the [`DBusMessageHeaderField::Interface`][crate::DBusMessageHeaderField::Interface] header field.
    /// ## `value`
    /// The value to set.
    #[doc(alias = "g_dbus_message_set_interface")]
    pub fn set_interface(&self, value: Option<&str>) {
        unsafe {
            ffi::g_dbus_message_set_interface(self.to_glib_none().0, value.to_glib_none().0);
        }
    }

    /// Convenience setter for the [`DBusMessageHeaderField::Member`][crate::DBusMessageHeaderField::Member] header field.
    /// ## `value`
    /// The value to set.
    #[doc(alias = "g_dbus_message_set_member")]
    pub fn set_member(&self, value: Option<&str>) {
        unsafe {
            ffi::g_dbus_message_set_member(self.to_glib_none().0, value.to_glib_none().0);
        }
    }

    /// Sets @self to be of @type_.
    /// ## `type_`
    /// A 8-bit unsigned integer (typically a value from the #GDBusMessageType enumeration).
    #[doc(alias = "g_dbus_message_set_message_type")]
    pub fn set_message_type(&self, type_: DBusMessageType) {
        unsafe {
            ffi::g_dbus_message_set_message_type(self.to_glib_none().0, type_.into_glib());
        }
    }

    /// Convenience setter for the [`DBusMessageHeaderField::NumUnixFds`][crate::DBusMessageHeaderField::NumUnixFds] header field.
    /// ## `value`
    /// The value to set.
    #[cfg(unix)]
    #[cfg_attr(docsrs, doc(cfg(unix)))]
    #[doc(alias = "g_dbus_message_set_num_unix_fds")]
    pub fn set_num_unix_fds(&self, value: u32) {
        unsafe {
            ffi::g_dbus_message_set_num_unix_fds(self.to_glib_none().0, value);
        }
    }

    /// Convenience setter for the [`DBusMessageHeaderField::Path`][crate::DBusMessageHeaderField::Path] header field.
    /// ## `value`
    /// The value to set.
    #[doc(alias = "g_dbus_message_set_path")]
    pub fn set_path(&self, value: Option<&str>) {
        unsafe {
            ffi::g_dbus_message_set_path(self.to_glib_none().0, value.to_glib_none().0);
        }
    }

    /// Convenience setter for the [`DBusMessageHeaderField::ReplySerial`][crate::DBusMessageHeaderField::ReplySerial] header field.
    /// ## `value`
    /// The value to set.
    #[doc(alias = "g_dbus_message_set_reply_serial")]
    pub fn set_reply_serial(&self, value: u32) {
        unsafe {
            ffi::g_dbus_message_set_reply_serial(self.to_glib_none().0, value);
        }
    }

    /// Convenience setter for the [`DBusMessageHeaderField::Sender`][crate::DBusMessageHeaderField::Sender] header field.
    /// ## `value`
    /// The value to set.
    #[doc(alias = "g_dbus_message_set_sender")]
    pub fn set_sender(&self, value: Option<&str>) {
        unsafe {
            ffi::g_dbus_message_set_sender(self.to_glib_none().0, value.to_glib_none().0);
        }
    }

    /// Sets the serial for @self.
    /// ## `serial`
    /// A #guint32.
    #[doc(alias = "g_dbus_message_set_serial")]
    pub fn set_serial(&self, serial: u32) {
        unsafe {
            ffi::g_dbus_message_set_serial(self.to_glib_none().0, serial);
        }
    }

    /// Convenience setter for the [`DBusMessageHeaderField::Signature`][crate::DBusMessageHeaderField::Signature] header field.
    /// ## `value`
    /// The value to set.
    #[doc(alias = "g_dbus_message_set_signature")]
    pub fn set_signature(&self, value: Option<&str>) {
        unsafe {
            ffi::g_dbus_message_set_signature(self.to_glib_none().0, value.to_glib_none().0);
        }
    }

    /// Sets the UNIX file descriptors associated with @self. As a
    /// side-effect the [`DBusMessageHeaderField::NumUnixFds`][crate::DBusMessageHeaderField::NumUnixFds] header
    /// field is set to the number of fds in @fd_list (or cleared if
    /// @fd_list is [`None`]).
    ///
    /// This method is only available on UNIX.
    ///
    /// When designing D-Bus APIs that are intended to be interoperable,
    /// please note that non-GDBus implementations of D-Bus can usually only
    /// access file descriptors if they are referenced by a value of type
    /// `G_VARIANT_TYPE_HANDLE` in the body of the message.
    /// ## `fd_list`
    /// A #GUnixFDList or [`None`].
    #[cfg(unix)]
    #[cfg_attr(docsrs, doc(cfg(unix)))]
    #[doc(alias = "g_dbus_message_set_unix_fd_list")]
    pub fn set_unix_fd_list(&self, fd_list: Option<&impl IsA<UnixFDList>>) {
        unsafe {
            ffi::g_dbus_message_set_unix_fd_list(
                self.to_glib_none().0,
                fd_list.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    /// Serializes @self to a blob. The byte order returned by
    /// g_dbus_message_get_byte_order() will be used.
    /// ## `capabilities`
    /// A #GDBusCapabilityFlags describing what protocol features are supported.
    ///
    /// # Returns
    ///
    /// A pointer to a
    /// valid binary D-Bus message of @out_size bytes generated by @self
    /// or [`None`] if @error is set. Free with g_free().
    #[doc(alias = "g_dbus_message_to_blob")]
    pub fn to_blob(&self, capabilities: DBusCapabilityFlags) -> Result<Vec<u8>, glib::Error> {
        unsafe {
            let mut out_size = std::mem::MaybeUninit::uninit();
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_message_to_blob(
                self.to_glib_none().0,
                out_size.as_mut_ptr(),
                capabilities.into_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(FromGlibContainer::from_glib_full_num(
                    ret,
                    out_size.assume_init() as _,
                ))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// If @self is not of type [`DBusMessageType::Error`][crate::DBusMessageType::Error] does
    /// nothing and returns [`false`].
    ///
    /// Otherwise this method encodes the error in @self as a #GError
    /// using g_dbus_error_set_dbus_error() using the information in the
    /// [`DBusMessageHeaderField::ErrorName`][crate::DBusMessageHeaderField::ErrorName] header field of @self as
    /// well as the first string item in @self's body.
    ///
    /// # Returns
    ///
    /// [`true`] if @error was set, [`false`] otherwise.
    #[doc(alias = "g_dbus_message_to_gerror")]
    pub fn to_gerror(&self) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::g_dbus_message_to_gerror(self.to_glib_none().0, &mut error);
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Utility function to calculate how many bytes are needed to
    /// completely deserialize the D-Bus message stored at @blob.
    /// ## `blob`
    /// A blob representing a binary D-Bus message.
    ///
    /// # Returns
    ///
    /// Number of bytes needed or -1 if @error is set (e.g. if
    /// @blob contains invalid data or not enough data is available to
    /// determine the size).
    #[doc(alias = "g_dbus_message_bytes_needed")]
    pub fn bytes_needed(blob: &[u8]) -> Result<isize, glib::Error> {
        let blob_len = blob.len() as _;
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_message_bytes_needed(blob.to_glib_none().0, blob_len, &mut error);
            if error.is_null() {
                Ok(ret)
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "locked")]
    pub fn connect_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_locked_trampoline<F: Fn(&DBusMessage) + 'static>(
            this: *mut ffi::GDBusMessage,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::locked\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_locked_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for DBusMessage {
    fn default() -> Self {
        Self::new()
    }
}