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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
// 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::{
    AsyncInitable, AsyncResult, BusType, Cancellable, DBusCallFlags, DBusConnection, DBusInterface,
    DBusInterfaceInfo, DBusProxyFlags, Initable,
};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::{boxed::Box as Box_, pin::Pin};

glib::wrapper! {
    /// `GDBusProxy` is a base class used for proxies to access a D-Bus
    /// interface on a remote object. A `GDBusProxy` can be constructed for
    /// both well-known and unique names.
    ///
    /// By default, `GDBusProxy` will cache all properties (and listen to
    /// changes) of the remote object, and proxy all signals that get
    /// emitted. This behaviour can be changed by passing suitable
    /// [`DBusProxyFlags`][crate::DBusProxyFlags] when the proxy is created. If the proxy is for a
    /// well-known name, the property cache is flushed when the name owner
    /// vanishes and reloaded when a name owner appears.
    ///
    /// The unique name owner of the proxy’s name is tracked and can be read from
    /// [`g-name-owner`][struct@crate::DBusProxy#g-name-owner]. Connect to the
    /// [`notify`][struct@crate::glib::Object#notify] signal to get notified of changes.
    /// Additionally, only signals and property changes emitted from the current name
    /// owner are considered and calls are always sent to the current name owner.
    /// This avoids a number of race conditions when the name is lost by one owner
    /// and claimed by another. However, if no name owner currently exists,
    /// then calls will be sent to the well-known name which may result in
    /// the message bus launching an owner (unless
    /// `G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START` is set).
    ///
    /// If the proxy is for a stateless D-Bus service, where the name owner may
    /// be started and stopped between calls, the
    /// [`g-name-owner`][struct@crate::DBusProxy#g-name-owner] tracking of `GDBusProxy` will cause the
    /// proxy to drop signal and property changes from the service after it has
    /// restarted for the first time. When interacting with a stateless D-Bus
    /// service, do not use `GDBusProxy` — use direct D-Bus method calls and signal
    /// connections.
    ///
    /// The generic [`g-properties-changed`][struct@crate::DBusProxy#g-properties-changed] and
    /// [`g-signal`][struct@crate::DBusProxy#g-signal] signals are not very convenient to work
    /// with. Therefore, the recommended way of working with proxies is to subclass
    /// `GDBusProxy`, and have more natural properties and signals in your derived
    /// class. This [example](migrating-gdbus.html#using-gdbus-codegen) shows how
    /// this can easily be done using the [`gdbus-codegen`](gdbus-codegen.html) tool.
    ///
    /// A `GDBusProxy` instance can be used from multiple threads but note
    /// that all signals (e.g. [`g-signal`][struct@crate::DBusProxy#g-signal],
    /// [`g-properties-changed`][struct@crate::DBusProxy#g-properties-changed] and
    /// [`notify`][struct@crate::glib::Object#notify]) are emitted in the thread-default main
    /// context (see [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()]) of the thread
    /// where the instance was constructed.
    ///
    /// An example using a proxy for a well-known name can be found in
    /// [`gdbus-example-watch-proxy.c`](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gdbus-example-watch-proxy.c).
    ///
    /// ## Properties
    ///
    ///
    /// #### `g-bus-type`
    ///  If this property is not [`BusType::None`][crate::BusType::None], then
    /// #GDBusProxy:g-connection must be [`None`] and will be set to the
    /// #GDBusConnection obtained by calling g_bus_get() with the value
    /// of this property.
    ///
    /// Writeable | Construct Only
    ///
    ///
    /// #### `g-connection`
    ///  The #GDBusConnection the proxy is for.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `g-default-timeout`
    ///  The timeout to use if -1 (specifying default timeout) is passed
    /// as @timeout_msec in the g_dbus_proxy_call() and
    /// g_dbus_proxy_call_sync() functions.
    ///
    /// This allows applications to set a proxy-wide timeout for all
    /// remote method invocations on the proxy. If this property is -1,
    /// the default timeout (typically 25 seconds) is used. If set to
    /// `G_MAXINT`, then no timeout is used.
    ///
    /// Readable | Writeable | Construct
    ///
    ///
    /// #### `g-flags`
    ///  Flags from the #GDBusProxyFlags enumeration.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `g-interface-info`
    ///  Ensure that interactions with this proxy conform to the given
    /// interface. This is mainly to ensure that malformed data received
    /// from the other peer is ignored. The given #GDBusInterfaceInfo is
    /// said to be the "expected interface".
    ///
    /// The checks performed are:
    /// - When completing a method call, if the type signature of
    ///   the reply message isn't what's expected, the reply is
    ///   discarded and the #GError is set to [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
    ///
    /// - Received signals that have a type signature mismatch are dropped and
    ///   a warning is logged via g_warning().
    ///
    /// - Properties received via the initial `GetAll()` call or via the
    ///   `::PropertiesChanged` signal (on the
    ///   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
    ///   interface) or set using g_dbus_proxy_set_cached_property()
    ///   with a type signature mismatch are ignored and a warning is
    ///   logged via g_warning().
    ///
    /// Note that these checks are never done on methods, signals and
    /// properties that are not referenced in the given
    /// #GDBusInterfaceInfo, since extending a D-Bus interface on the
    /// service-side is not considered an ABI break.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `g-interface-name`
    ///  The D-Bus interface name the proxy is for.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `g-name`
    ///  The well-known or unique name that the proxy is for.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `g-name-owner`
    ///  The unique name that owns #GDBusProxy:g-name or [`None`] if no-one
    /// currently owns that name. You may connect to #GObject::notify signal to
    /// track changes to this property.
    ///
    /// Readable
    ///
    ///
    /// #### `g-object-path`
    ///  The object path the proxy is for.
    ///
    /// Readable | Writeable | Construct Only
    ///
    /// ## Signals
    ///
    ///
    /// #### `g-properties-changed`
    ///  Emitted when one or more D-Bus properties on @proxy changes. The
    /// local cache has already been updated when this signal fires. Note
    /// that both @changed_properties and @invalidated_properties are
    /// guaranteed to never be [`None`] (either may be empty though).
    ///
    /// If the proxy has the flag
    /// [`DBusProxyFlags::GET_INVALIDATED_PROPERTIES`][crate::DBusProxyFlags::GET_INVALIDATED_PROPERTIES] set, then
    /// @invalidated_properties will always be empty.
    ///
    /// This signal corresponds to the
    /// `PropertiesChanged` D-Bus signal on the
    /// `org.freedesktop.DBus.Properties` interface.
    ///
    ///
    ///
    ///
    /// #### `g-signal`
    ///  Emitted when a signal from the remote object and interface that @proxy is for, has been received.
    ///
    /// Since 2.72 this signal supports detailed connections. You can connect to
    /// the detailed signal `g-signal::x` in order to receive callbacks only when
    /// signal `x` is received from the remote object.
    ///
    /// Detailed
    ///
    /// # Implements
    ///
    /// [`DBusProxyExt`][trait@crate::prelude::DBusProxyExt], [`trait@glib::ObjectExt`], [`AsyncInitableExt`][trait@crate::prelude::AsyncInitableExt], [`DBusInterfaceExt`][trait@crate::prelude::DBusInterfaceExt], [`InitableExt`][trait@crate::prelude::InitableExt], [`DBusProxyExtManual`][trait@crate::prelude::DBusProxyExtManual]
    #[doc(alias = "GDBusProxy")]
    pub struct DBusProxy(Object<ffi::GDBusProxy, ffi::GDBusProxyClass>) @implements AsyncInitable, DBusInterface, Initable;

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

impl DBusProxy {
    pub const NONE: Option<&'static DBusProxy> = None;

    /// Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.
    ///
    /// #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
    /// ## `bus_type`
    /// A #GBusType.
    /// ## `flags`
    /// Flags used when constructing the proxy.
    /// ## `info`
    /// A #GDBusInterfaceInfo specifying the minimal interface
    ///        that @proxy conforms to or [`None`].
    /// ## `name`
    /// A bus name (well-known or unique).
    /// ## `object_path`
    /// An object path.
    /// ## `interface_name`
    /// A D-Bus interface name.
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    ///
    /// # Returns
    ///
    /// A #GDBusProxy or [`None`] if error is set.
    ///    Free with g_object_unref().
    #[doc(alias = "g_dbus_proxy_new_for_bus_sync")]
    #[doc(alias = "new_for_bus_sync")]
    pub fn for_bus_sync(
        bus_type: BusType,
        flags: DBusProxyFlags,
        info: Option<&DBusInterfaceInfo>,
        name: &str,
        object_path: &str,
        interface_name: &str,
        cancellable: Option<&impl IsA<Cancellable>>,
    ) -> Result<DBusProxy, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_proxy_new_for_bus_sync(
                bus_type.into_glib(),
                flags.into_glib(),
                info.to_glib_none().0,
                name.to_glib_none().0,
                object_path.to_glib_none().0,
                interface_name.to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Creates a proxy for accessing @interface_name on the remote object
    /// at @object_path owned by @name at @connection and synchronously
    /// loads D-Bus properties unless the
    /// [`DBusProxyFlags::DO_NOT_LOAD_PROPERTIES`][crate::DBusProxyFlags::DO_NOT_LOAD_PROPERTIES] flag is used.
    ///
    /// If the [`DBusProxyFlags::DO_NOT_CONNECT_SIGNALS`][crate::DBusProxyFlags::DO_NOT_CONNECT_SIGNALS] flag is not set, also sets up
    /// match rules for signals. Connect to the #GDBusProxy::g-signal signal
    /// to handle signals from the remote object.
    ///
    /// If both [`DBusProxyFlags::DO_NOT_LOAD_PROPERTIES`][crate::DBusProxyFlags::DO_NOT_LOAD_PROPERTIES] and
    /// [`DBusProxyFlags::DO_NOT_CONNECT_SIGNALS`][crate::DBusProxyFlags::DO_NOT_CONNECT_SIGNALS] are set, this constructor is
    /// guaranteed to return immediately without blocking.
    ///
    /// If @name is a well-known name and the
    /// [`DBusProxyFlags::DO_NOT_AUTO_START`][crate::DBusProxyFlags::DO_NOT_AUTO_START] and [`DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION`][crate::DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION]
    /// flags aren't set and no name owner currently exists, the message bus
    /// will be requested to launch a name owner for the name.
    ///
    /// This is a synchronous failable constructor. See g_dbus_proxy_new()
    /// and g_dbus_proxy_new_finish() for the asynchronous version.
    ///
    /// #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
    /// ## `connection`
    /// A #GDBusConnection.
    /// ## `flags`
    /// Flags used when constructing the proxy.
    /// ## `info`
    /// A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or [`None`].
    /// ## `name`
    /// A bus name (well-known or unique) or [`None`] if @connection is not a message bus connection.
    /// ## `object_path`
    /// An object path.
    /// ## `interface_name`
    /// A D-Bus interface name.
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    ///
    /// # Returns
    ///
    /// A #GDBusProxy or [`None`] if error is set.
    ///    Free with g_object_unref().
    #[doc(alias = "g_dbus_proxy_new_sync")]
    pub fn new_sync(
        connection: &DBusConnection,
        flags: DBusProxyFlags,
        info: Option<&DBusInterfaceInfo>,
        name: Option<&str>,
        object_path: &str,
        interface_name: &str,
        cancellable: Option<&impl IsA<Cancellable>>,
    ) -> Result<DBusProxy, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_proxy_new_sync(
                connection.to_glib_none().0,
                flags.into_glib(),
                info.to_glib_none().0,
                name.to_glib_none().0,
                object_path.to_glib_none().0,
                interface_name.to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Creates a proxy for accessing @interface_name on the remote object
    /// at @object_path owned by @name at @connection and asynchronously
    /// loads D-Bus properties unless the
    /// [`DBusProxyFlags::DO_NOT_LOAD_PROPERTIES`][crate::DBusProxyFlags::DO_NOT_LOAD_PROPERTIES] flag is used. Connect to
    /// the #GDBusProxy::g-properties-changed signal to get notified about
    /// property changes.
    ///
    /// If the [`DBusProxyFlags::DO_NOT_CONNECT_SIGNALS`][crate::DBusProxyFlags::DO_NOT_CONNECT_SIGNALS] flag is not set, also sets up
    /// match rules for signals. Connect to the #GDBusProxy::g-signal signal
    /// to handle signals from the remote object.
    ///
    /// If both [`DBusProxyFlags::DO_NOT_LOAD_PROPERTIES`][crate::DBusProxyFlags::DO_NOT_LOAD_PROPERTIES] and
    /// [`DBusProxyFlags::DO_NOT_CONNECT_SIGNALS`][crate::DBusProxyFlags::DO_NOT_CONNECT_SIGNALS] are set, this constructor is
    /// guaranteed to complete immediately without blocking.
    ///
    /// If @name is a well-known name and the
    /// [`DBusProxyFlags::DO_NOT_AUTO_START`][crate::DBusProxyFlags::DO_NOT_AUTO_START] and [`DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION`][crate::DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION]
    /// flags aren't set and no name owner currently exists, the message bus
    /// will be requested to launch a name owner for the name.
    ///
    /// This is a failable asynchronous constructor - when the proxy is
    /// ready, @callback will be invoked and you can use
    /// g_dbus_proxy_new_finish() to get the result.
    ///
    /// See g_dbus_proxy_new_sync() and for a synchronous version of this constructor.
    ///
    /// #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
    /// ## `connection`
    /// A #GDBusConnection.
    /// ## `flags`
    /// Flags used when constructing the proxy.
    /// ## `info`
    /// A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or [`None`].
    /// ## `name`
    /// A bus name (well-known or unique) or [`None`] if @connection is not a message bus connection.
    /// ## `object_path`
    /// An object path.
    /// ## `interface_name`
    /// A D-Bus interface name.
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    /// ## `callback`
    /// Callback function to invoke when the proxy is ready.
    #[doc(alias = "g_dbus_proxy_new")]
    pub fn new<P: FnOnce(Result<DBusProxy, glib::Error>) + 'static>(
        connection: &DBusConnection,
        flags: DBusProxyFlags,
        info: Option<&DBusInterfaceInfo>,
        name: Option<&str>,
        object_path: &str,
        interface_name: &str,
        cancellable: Option<&impl IsA<Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn new_trampoline<P: FnOnce(Result<DBusProxy, glib::Error>) + 'static>(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut crate::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_proxy_new_finish(res, &mut error);
            let result = if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = new_trampoline::<P>;
        unsafe {
            ffi::g_dbus_proxy_new(
                connection.to_glib_none().0,
                flags.into_glib(),
                info.to_glib_none().0,
                name.to_glib_none().0,
                object_path.to_glib_none().0,
                interface_name.to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    pub fn new_future(
        connection: &DBusConnection,
        flags: DBusProxyFlags,
        info: Option<&DBusInterfaceInfo>,
        name: Option<&str>,
        object_path: &str,
        interface_name: &str,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<DBusProxy, glib::Error>> + 'static>> {
        let connection = connection.clone();
        let info = info.map(ToOwned::to_owned);
        let name = name.map(ToOwned::to_owned);
        let object_path = String::from(object_path);
        let interface_name = String::from(interface_name);
        Box_::pin(crate::GioFuture::new(
            &(),
            move |_obj, cancellable, send| {
                Self::new(
                    &connection,
                    flags,
                    info.as_ref().map(::std::borrow::Borrow::borrow),
                    name.as_ref().map(::std::borrow::Borrow::borrow),
                    &object_path,
                    &interface_name,
                    Some(cancellable),
                    move |res| {
                        send.resolve(res);
                    },
                );
            },
        ))
    }

    /// Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection.
    ///
    /// #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
    /// ## `bus_type`
    /// A #GBusType.
    /// ## `flags`
    /// Flags used when constructing the proxy.
    /// ## `info`
    /// A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or [`None`].
    /// ## `name`
    /// A bus name (well-known or unique).
    /// ## `object_path`
    /// An object path.
    /// ## `interface_name`
    /// A D-Bus interface name.
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    /// ## `callback`
    /// Callback function to invoke when the proxy is ready.
    #[doc(alias = "g_dbus_proxy_new_for_bus")]
    #[doc(alias = "new_for_bus")]
    pub fn for_bus<P: FnOnce(Result<DBusProxy, glib::Error>) + 'static>(
        bus_type: BusType,
        flags: DBusProxyFlags,
        info: Option<&DBusInterfaceInfo>,
        name: &str,
        object_path: &str,
        interface_name: &str,
        cancellable: Option<&impl IsA<Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn for_bus_trampoline<
            P: FnOnce(Result<DBusProxy, glib::Error>) + 'static,
        >(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut crate::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_proxy_new_for_bus_finish(res, &mut error);
            let result = if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = for_bus_trampoline::<P>;
        unsafe {
            ffi::g_dbus_proxy_new_for_bus(
                bus_type.into_glib(),
                flags.into_glib(),
                info.to_glib_none().0,
                name.to_glib_none().0,
                object_path.to_glib_none().0,
                interface_name.to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    pub fn for_bus_future(
        bus_type: BusType,
        flags: DBusProxyFlags,
        info: Option<&DBusInterfaceInfo>,
        name: &str,
        object_path: &str,
        interface_name: &str,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<DBusProxy, glib::Error>> + 'static>> {
        let info = info.map(ToOwned::to_owned);
        let name = String::from(name);
        let object_path = String::from(object_path);
        let interface_name = String::from(interface_name);
        Box_::pin(crate::GioFuture::new(
            &(),
            move |_obj, cancellable, send| {
                Self::for_bus(
                    bus_type,
                    flags,
                    info.as_ref().map(::std::borrow::Borrow::borrow),
                    &name,
                    &object_path,
                    &interface_name,
                    Some(cancellable),
                    move |res| {
                        send.resolve(res);
                    },
                );
            },
        ))
    }
}

unsafe impl Send for DBusProxy {}
unsafe impl Sync for DBusProxy {}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::DBusProxy>> Sealed for T {}
}

/// Trait containing all [`struct@DBusProxy`] methods.
///
/// # Implementors
///
/// [`DBusProxy`][struct@crate::DBusProxy]
pub trait DBusProxyExt: IsA<DBusProxy> + sealed::Sealed + 'static {
    /// Asynchronously invokes the @method_name method on @self.
    ///
    /// If @method_name contains any dots, then @name is split into interface and
    /// method name parts. This allows using @self for invoking methods on
    /// other interfaces.
    ///
    /// If the #GDBusConnection associated with @self is closed then
    /// the operation will fail with [`IOErrorEnum::Closed`][crate::IOErrorEnum::Closed]. If
    /// @cancellable is canceled, the operation will fail with
    /// [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled]. If @parameters contains a value not
    /// compatible with the D-Bus protocol, the operation fails with
    /// [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
    ///
    /// If the @parameters #GVariant is floating, it is consumed. This allows
    /// convenient 'inline' use of g_variant_new(), e.g.:
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    ///  g_dbus_proxy_call (proxy,
    ///                     "TwoStrings",
    ///                     g_variant_new ("(ss)",
    ///                                    "Thing One",
    ///                                    "Thing Two"),
    ///                     G_DBUS_CALL_FLAGS_NONE,
    ///                     -1,
    ///                     NULL,
    ///                     (GAsyncReadyCallback) two_strings_done,
    ///                     &data);
    /// ```
    ///
    /// If @self has an expected interface (see
    /// #GDBusProxy:g-interface-info) and @method_name is referenced by it,
    /// then the return value is checked against the return type.
    ///
    /// This is an asynchronous method. When the operation is finished,
    /// @callback will be invoked in the
    /// [thread-default main context][g-main-context-push-thread-default]
    /// of the thread you are calling this method from.
    /// You can then call g_dbus_proxy_call_finish() to get the result of
    /// the operation. See g_dbus_proxy_call_sync() for the synchronous
    /// version of this method.
    ///
    /// If @callback is [`None`] then the D-Bus method call message will be sent with
    /// the [`DBusMessageFlags::NO_REPLY_EXPECTED`][crate::DBusMessageFlags::NO_REPLY_EXPECTED] flag set.
    /// ## `method_name`
    /// Name of method to invoke.
    /// ## `parameters`
    /// A #GVariant tuple with parameters for the signal or [`None`] if not passing parameters.
    /// ## `flags`
    /// Flags from the #GDBusCallFlags enumeration.
    /// ## `timeout_msec`
    /// The timeout in milliseconds (with `G_MAXINT` meaning
    ///                "infinite") or -1 to use the proxy default timeout.
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    /// ## `callback`
    /// A #GAsyncReadyCallback to call when the request is satisfied or [`None`] if you don't
    /// care about the result of the method invocation.
    #[doc(alias = "g_dbus_proxy_call")]
    fn call<P: FnOnce(Result<glib::Variant, glib::Error>) + 'static>(
        &self,
        method_name: &str,
        parameters: Option<&glib::Variant>,
        flags: DBusCallFlags,
        timeout_msec: i32,
        cancellable: Option<&impl IsA<Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn call_trampoline<
            P: FnOnce(Result<glib::Variant, glib::Error>) + 'static,
        >(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut crate::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_proxy_call_finish(_source_object as *mut _, res, &mut error);
            let result = if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = call_trampoline::<P>;
        unsafe {
            ffi::g_dbus_proxy_call(
                self.as_ref().to_glib_none().0,
                method_name.to_glib_none().0,
                parameters.to_glib_none().0,
                flags.into_glib(),
                timeout_msec,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    fn call_future(
        &self,
        method_name: &str,
        parameters: Option<&glib::Variant>,
        flags: DBusCallFlags,
        timeout_msec: i32,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Variant, glib::Error>> + 'static>>
    {
        let method_name = String::from(method_name);
        let parameters = parameters.map(ToOwned::to_owned);
        Box_::pin(crate::GioFuture::new(
            self,
            move |obj, cancellable, send| {
                obj.call(
                    &method_name,
                    parameters.as_ref().map(::std::borrow::Borrow::borrow),
                    flags,
                    timeout_msec,
                    Some(cancellable),
                    move |res| {
                        send.resolve(res);
                    },
                );
            },
        ))
    }

    /// Synchronously invokes the @method_name method on @self.
    ///
    /// If @method_name contains any dots, then @name is split into interface and
    /// method name parts. This allows using @self for invoking methods on
    /// other interfaces.
    ///
    /// If the #GDBusConnection associated with @self is disconnected then
    /// the operation will fail with [`IOErrorEnum::Closed`][crate::IOErrorEnum::Closed]. If
    /// @cancellable is canceled, the operation will fail with
    /// [`IOErrorEnum::Cancelled`][crate::IOErrorEnum::Cancelled]. If @parameters contains a value not
    /// compatible with the D-Bus protocol, the operation fails with
    /// [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
    ///
    /// If the @parameters #GVariant is floating, it is consumed. This allows
    /// convenient 'inline' use of g_variant_new(), e.g.:
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    ///  g_dbus_proxy_call_sync (proxy,
    ///                          "TwoStrings",
    ///                          g_variant_new ("(ss)",
    ///                                         "Thing One",
    ///                                         "Thing Two"),
    ///                          G_DBUS_CALL_FLAGS_NONE,
    ///                          -1,
    ///                          NULL,
    ///                          &error);
    /// ```
    ///
    /// The calling thread is blocked until a reply is received. See
    /// g_dbus_proxy_call() for the asynchronous version of this
    /// method.
    ///
    /// If @self has an expected interface (see
    /// #GDBusProxy:g-interface-info) and @method_name is referenced by it,
    /// then the return value is checked against the return type.
    /// ## `method_name`
    /// Name of method to invoke.
    /// ## `parameters`
    /// A #GVariant tuple with parameters for the signal
    ///              or [`None`] if not passing parameters.
    /// ## `flags`
    /// Flags from the #GDBusCallFlags enumeration.
    /// ## `timeout_msec`
    /// The timeout in milliseconds (with `G_MAXINT` meaning
    ///                "infinite") or -1 to use the proxy default timeout.
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    ///
    /// # Returns
    ///
    /// [`None`] if @error is set. Otherwise a #GVariant tuple with
    /// return values. Free with g_variant_unref().
    #[doc(alias = "g_dbus_proxy_call_sync")]
    fn call_sync(
        &self,
        method_name: &str,
        parameters: Option<&glib::Variant>,
        flags: DBusCallFlags,
        timeout_msec: i32,
        cancellable: Option<&impl IsA<Cancellable>>,
    ) -> Result<glib::Variant, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_proxy_call_sync(
                self.as_ref().to_glib_none().0,
                method_name.to_glib_none().0,
                parameters.to_glib_none().0,
                flags.into_glib(),
                timeout_msec,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Like g_dbus_proxy_call() but also takes a #GUnixFDList object.
    ///
    /// This method is only available on UNIX.
    /// ## `method_name`
    /// Name of method to invoke.
    /// ## `parameters`
    /// A #GVariant tuple with parameters for the signal or [`None`] if not passing parameters.
    /// ## `flags`
    /// Flags from the #GDBusCallFlags enumeration.
    /// ## `timeout_msec`
    /// The timeout in milliseconds (with `G_MAXINT` meaning
    ///                "infinite") or -1 to use the proxy default timeout.
    /// ## `fd_list`
    /// A #GUnixFDList or [`None`].
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    /// ## `callback`
    /// A #GAsyncReadyCallback to call when the request is satisfied or [`None`] if you don't
    /// care about the result of the method invocation.
    #[cfg(unix)]
    #[cfg_attr(docsrs, doc(cfg(unix)))]
    #[doc(alias = "g_dbus_proxy_call_with_unix_fd_list")]
    fn call_with_unix_fd_list<
        P: FnOnce(Result<(glib::Variant, UnixFDList), glib::Error>) + 'static,
    >(
        &self,
        method_name: &str,
        parameters: Option<&glib::Variant>,
        flags: DBusCallFlags,
        timeout_msec: i32,
        fd_list: Option<&impl IsA<UnixFDList>>,
        cancellable: Option<&impl IsA<Cancellable>>,
        callback: P,
    ) {
        let main_context = glib::MainContext::ref_thread_default();
        let is_main_context_owner = main_context.is_owner();
        let has_acquired_main_context = (!is_main_context_owner)
            .then(|| main_context.acquire().ok())
            .flatten();
        assert!(
            is_main_context_owner || has_acquired_main_context.is_some(),
            "Async operations only allowed if the thread is owning the MainContext"
        );

        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn call_with_unix_fd_list_trampoline<
            P: FnOnce(Result<(glib::Variant, UnixFDList), glib::Error>) + 'static,
        >(
            _source_object: *mut glib::gobject_ffi::GObject,
            res: *mut crate::ffi::GAsyncResult,
            user_data: glib::ffi::gpointer,
        ) {
            let mut error = std::ptr::null_mut();
            let mut out_fd_list = std::ptr::null_mut();
            let ret = ffi::g_dbus_proxy_call_with_unix_fd_list_finish(
                _source_object as *mut _,
                &mut out_fd_list,
                res,
                &mut error,
            );
            let result = if error.is_null() {
                Ok((from_glib_full(ret), from_glib_full(out_fd_list)))
            } else {
                Err(from_glib_full(error))
            };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
                Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = call_with_unix_fd_list_trampoline::<P>;
        unsafe {
            ffi::g_dbus_proxy_call_with_unix_fd_list(
                self.as_ref().to_glib_none().0,
                method_name.to_glib_none().0,
                parameters.to_glib_none().0,
                flags.into_glib(),
                timeout_msec,
                fd_list.map(|p| p.as_ref()).to_glib_none().0,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                Some(callback),
                Box_::into_raw(user_data) as *mut _,
            );
        }
    }

    #[cfg(unix)]
    #[cfg_attr(docsrs, doc(cfg(unix)))]
    fn call_with_unix_fd_list_future(
        &self,
        method_name: &str,
        parameters: Option<&glib::Variant>,
        flags: DBusCallFlags,
        timeout_msec: i32,
        fd_list: Option<&(impl IsA<UnixFDList> + Clone + 'static)>,
    ) -> Pin<
        Box_<
            dyn std::future::Future<Output = Result<(glib::Variant, UnixFDList), glib::Error>>
                + 'static,
        >,
    > {
        let method_name = String::from(method_name);
        let parameters = parameters.map(ToOwned::to_owned);
        let fd_list = fd_list.map(ToOwned::to_owned);
        Box_::pin(crate::GioFuture::new(
            self,
            move |obj, cancellable, send| {
                obj.call_with_unix_fd_list(
                    &method_name,
                    parameters.as_ref().map(::std::borrow::Borrow::borrow),
                    flags,
                    timeout_msec,
                    fd_list.as_ref().map(::std::borrow::Borrow::borrow),
                    Some(cancellable),
                    move |res| {
                        send.resolve(res);
                    },
                );
            },
        ))
    }

    /// Like g_dbus_proxy_call_sync() but also takes and returns #GUnixFDList objects.
    ///
    /// This method is only available on UNIX.
    /// ## `method_name`
    /// Name of method to invoke.
    /// ## `parameters`
    /// A #GVariant tuple with parameters for the signal
    ///              or [`None`] if not passing parameters.
    /// ## `flags`
    /// Flags from the #GDBusCallFlags enumeration.
    /// ## `timeout_msec`
    /// The timeout in milliseconds (with `G_MAXINT` meaning
    ///                "infinite") or -1 to use the proxy default timeout.
    /// ## `fd_list`
    /// A #GUnixFDList or [`None`].
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    ///
    /// # Returns
    ///
    /// [`None`] if @error is set. Otherwise a #GVariant tuple with
    /// return values. Free with g_variant_unref().
    ///
    /// ## `out_fd_list`
    /// Return location for a #GUnixFDList or [`None`].
    #[cfg(unix)]
    #[cfg_attr(docsrs, doc(cfg(unix)))]
    #[doc(alias = "g_dbus_proxy_call_with_unix_fd_list_sync")]
    fn call_with_unix_fd_list_sync(
        &self,
        method_name: &str,
        parameters: Option<&glib::Variant>,
        flags: DBusCallFlags,
        timeout_msec: i32,
        fd_list: Option<&impl IsA<UnixFDList>>,
        cancellable: Option<&impl IsA<Cancellable>>,
    ) -> Result<(glib::Variant, UnixFDList), glib::Error> {
        unsafe {
            let mut out_fd_list = std::ptr::null_mut();
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_dbus_proxy_call_with_unix_fd_list_sync(
                self.as_ref().to_glib_none().0,
                method_name.to_glib_none().0,
                parameters.to_glib_none().0,
                flags.into_glib(),
                timeout_msec,
                fd_list.map(|p| p.as_ref()).to_glib_none().0,
                &mut out_fd_list,
                cancellable.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok((from_glib_full(ret), from_glib_full(out_fd_list)))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Looks up the value for a property from the cache. This call does no
    /// blocking IO.
    ///
    /// If @self has an expected interface (see
    /// #GDBusProxy:g-interface-info) and @property_name is referenced by
    /// it, then @value is checked against the type of the property.
    /// ## `property_name`
    /// Property name.
    ///
    /// # Returns
    ///
    /// A reference to the #GVariant instance
    ///    that holds the value for @property_name or [`None`] if the value is not in
    ///    the cache. The returned reference must be freed with g_variant_unref().
    #[doc(alias = "g_dbus_proxy_get_cached_property")]
    #[doc(alias = "get_cached_property")]
    fn cached_property(&self, property_name: &str) -> Option<glib::Variant> {
        unsafe {
            from_glib_full(ffi::g_dbus_proxy_get_cached_property(
                self.as_ref().to_glib_none().0,
                property_name.to_glib_none().0,
            ))
        }
    }

    /// Gets the names of all cached properties on @self.
    ///
    /// # Returns
    ///
    /// A
    ///          [`None`]-terminated array of strings or [`None`] if
    ///          @self has no cached properties. Free the returned array with
    ///          g_strfreev().
    #[doc(alias = "g_dbus_proxy_get_cached_property_names")]
    #[doc(alias = "get_cached_property_names")]
    fn cached_property_names(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::g_dbus_proxy_get_cached_property_names(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the connection @self is for.
    ///
    /// # Returns
    ///
    /// A #GDBusConnection owned by @self. Do not free.
    #[doc(alias = "g_dbus_proxy_get_connection")]
    #[doc(alias = "get_connection")]
    fn connection(&self) -> DBusConnection {
        unsafe {
            from_glib_none(ffi::g_dbus_proxy_get_connection(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the timeout to use if -1 (specifying default timeout) is
    /// passed as @timeout_msec in the g_dbus_proxy_call() and
    /// g_dbus_proxy_call_sync() functions.
    ///
    /// See the #GDBusProxy:g-default-timeout property for more details.
    ///
    /// # Returns
    ///
    /// Timeout to use for @self.
    #[doc(alias = "g_dbus_proxy_get_default_timeout")]
    #[doc(alias = "get_default_timeout")]
    fn default_timeout(&self) -> i32 {
        unsafe { ffi::g_dbus_proxy_get_default_timeout(self.as_ref().to_glib_none().0) }
    }

    /// Gets the flags that @self was constructed with.
    ///
    /// # Returns
    ///
    /// Flags from the #GDBusProxyFlags enumeration.
    #[doc(alias = "g_dbus_proxy_get_flags")]
    #[doc(alias = "get_flags")]
    fn flags(&self) -> DBusProxyFlags {
        unsafe { from_glib(ffi::g_dbus_proxy_get_flags(self.as_ref().to_glib_none().0)) }
    }

    /// Returns the #GDBusInterfaceInfo, if any, specifying the interface
    /// that @self conforms to. See the #GDBusProxy:g-interface-info
    /// property for more details.
    ///
    /// # Returns
    ///
    /// A #GDBusInterfaceInfo or [`None`].
    ///    Do not unref the returned object, it is owned by @self.
    #[doc(alias = "g_dbus_proxy_get_interface_info")]
    #[doc(alias = "get_interface_info")]
    fn interface_info(&self) -> Option<DBusInterfaceInfo> {
        unsafe {
            from_glib_none(ffi::g_dbus_proxy_get_interface_info(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the D-Bus interface name @self is for.
    ///
    /// # Returns
    ///
    /// A string owned by @self. Do not free.
    #[doc(alias = "g_dbus_proxy_get_interface_name")]
    #[doc(alias = "get_interface_name")]
    fn interface_name(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::g_dbus_proxy_get_interface_name(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the name that @self was constructed for.
    ///
    /// When connected to a message bus, this will usually be non-[`None`].
    /// However, it may be [`None`] for a proxy that communicates using a peer-to-peer
    /// pattern.
    ///
    /// # Returns
    ///
    /// A string owned by @self. Do not free.
    #[doc(alias = "g_dbus_proxy_get_name")]
    #[doc(alias = "get_name")]
    fn name(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::g_dbus_proxy_get_name(self.as_ref().to_glib_none().0)) }
    }

    /// The unique name that owns the name that @self is for or [`None`] if
    /// no-one currently owns that name. You may connect to the
    /// #GObject::notify signal to track changes to the
    /// #GDBusProxy:g-name-owner property.
    ///
    /// # Returns
    ///
    /// The name owner or [`None`] if no name
    ///    owner exists. Free with g_free().
    #[doc(alias = "g_dbus_proxy_get_name_owner")]
    #[doc(alias = "get_name_owner")]
    fn name_owner(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::g_dbus_proxy_get_name_owner(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the object path @self is for.
    ///
    /// # Returns
    ///
    /// A string owned by @self. Do not free.
    #[doc(alias = "g_dbus_proxy_get_object_path")]
    #[doc(alias = "get_object_path")]
    fn object_path(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::g_dbus_proxy_get_object_path(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// If @value is not [`None`], sets the cached value for the property with
    /// name @property_name to the value in @value.
    ///
    /// If @value is [`None`], then the cached value is removed from the
    /// property cache.
    ///
    /// If @self has an expected interface (see
    /// #GDBusProxy:g-interface-info) and @property_name is referenced by
    /// it, then @value is checked against the type of the property.
    ///
    /// If the @value #GVariant is floating, it is consumed. This allows
    /// convenient 'inline' use of g_variant_new(), e.g.
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    ///  g_dbus_proxy_set_cached_property (proxy,
    ///                                    "SomeProperty",
    ///                                    g_variant_new ("(si)",
    ///                                                  "A String",
    ///                                                  42));
    /// ```
    ///
    /// Normally you will not need to use this method since @self
    /// is tracking changes using the
    /// `org.freedesktop.DBus.Properties.PropertiesChanged`
    /// D-Bus signal. However, for performance reasons an object may
    /// decide to not use this signal for some properties and instead
    /// use a proprietary out-of-band mechanism to transmit changes.
    ///
    /// As a concrete example, consider an object with a property
    /// `ChatroomParticipants` which is an array of strings. Instead of
    /// transmitting the same (long) array every time the property changes,
    /// it is more efficient to only transmit the delta using e.g. signals
    /// `ChatroomParticipantJoined(String name)` and
    /// `ChatroomParticipantParted(String name)`.
    /// ## `property_name`
    /// Property name.
    /// ## `value`
    /// Value for the property or [`None`] to remove it from the cache.
    #[doc(alias = "g_dbus_proxy_set_cached_property")]
    fn set_cached_property(&self, property_name: &str, value: Option<&glib::Variant>) {
        unsafe {
            ffi::g_dbus_proxy_set_cached_property(
                self.as_ref().to_glib_none().0,
                property_name.to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    /// Sets the timeout to use if -1 (specifying default timeout) is
    /// passed as @timeout_msec in the g_dbus_proxy_call() and
    /// g_dbus_proxy_call_sync() functions.
    ///
    /// See the #GDBusProxy:g-default-timeout property for more details.
    /// ## `timeout_msec`
    /// Timeout in milliseconds.
    #[doc(alias = "g_dbus_proxy_set_default_timeout")]
    fn set_default_timeout(&self, timeout_msec: i32) {
        unsafe {
            ffi::g_dbus_proxy_set_default_timeout(self.as_ref().to_glib_none().0, timeout_msec);
        }
    }

    /// Ensure that interactions with @self conform to the given
    /// interface. See the #GDBusProxy:g-interface-info property for more
    /// details.
    /// ## `info`
    /// Minimum interface this proxy conforms to
    ///    or [`None`] to unset.
    #[doc(alias = "g_dbus_proxy_set_interface_info")]
    fn set_interface_info(&self, info: Option<&DBusInterfaceInfo>) {
        unsafe {
            ffi::g_dbus_proxy_set_interface_info(
                self.as_ref().to_glib_none().0,
                info.to_glib_none().0,
            );
        }
    }

    /// The #GDBusConnection the proxy is for.
    #[doc(alias = "g-connection")]
    fn g_connection(&self) -> Option<DBusConnection> {
        ObjectExt::property(self.as_ref(), "g-connection")
    }

    /// The timeout to use if -1 (specifying default timeout) is passed
    /// as @timeout_msec in the g_dbus_proxy_call() and
    /// g_dbus_proxy_call_sync() functions.
    ///
    /// This allows applications to set a proxy-wide timeout for all
    /// remote method invocations on the proxy. If this property is -1,
    /// the default timeout (typically 25 seconds) is used. If set to
    /// `G_MAXINT`, then no timeout is used.
    #[doc(alias = "g-default-timeout")]
    fn g_default_timeout(&self) -> i32 {
        ObjectExt::property(self.as_ref(), "g-default-timeout")
    }

    /// The timeout to use if -1 (specifying default timeout) is passed
    /// as @timeout_msec in the g_dbus_proxy_call() and
    /// g_dbus_proxy_call_sync() functions.
    ///
    /// This allows applications to set a proxy-wide timeout for all
    /// remote method invocations on the proxy. If this property is -1,
    /// the default timeout (typically 25 seconds) is used. If set to
    /// `G_MAXINT`, then no timeout is used.
    #[doc(alias = "g-default-timeout")]
    fn set_g_default_timeout(&self, g_default_timeout: i32) {
        ObjectExt::set_property(self.as_ref(), "g-default-timeout", g_default_timeout)
    }

    /// Flags from the #GDBusProxyFlags enumeration.
    #[doc(alias = "g-flags")]
    fn g_flags(&self) -> DBusProxyFlags {
        ObjectExt::property(self.as_ref(), "g-flags")
    }

    /// Ensure that interactions with this proxy conform to the given
    /// interface. This is mainly to ensure that malformed data received
    /// from the other peer is ignored. The given #GDBusInterfaceInfo is
    /// said to be the "expected interface".
    ///
    /// The checks performed are:
    /// - When completing a method call, if the type signature of
    ///   the reply message isn't what's expected, the reply is
    ///   discarded and the #GError is set to [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
    ///
    /// - Received signals that have a type signature mismatch are dropped and
    ///   a warning is logged via g_warning().
    ///
    /// - Properties received via the initial `GetAll()` call or via the
    ///   `::PropertiesChanged` signal (on the
    ///   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
    ///   interface) or set using g_dbus_proxy_set_cached_property()
    ///   with a type signature mismatch are ignored and a warning is
    ///   logged via g_warning().
    ///
    /// Note that these checks are never done on methods, signals and
    /// properties that are not referenced in the given
    /// #GDBusInterfaceInfo, since extending a D-Bus interface on the
    /// service-side is not considered an ABI break.
    #[doc(alias = "g-interface-info")]
    fn g_interface_info(&self) -> Option<DBusInterfaceInfo> {
        ObjectExt::property(self.as_ref(), "g-interface-info")
    }

    /// Ensure that interactions with this proxy conform to the given
    /// interface. This is mainly to ensure that malformed data received
    /// from the other peer is ignored. The given #GDBusInterfaceInfo is
    /// said to be the "expected interface".
    ///
    /// The checks performed are:
    /// - When completing a method call, if the type signature of
    ///   the reply message isn't what's expected, the reply is
    ///   discarded and the #GError is set to [`IOErrorEnum::InvalidArgument`][crate::IOErrorEnum::InvalidArgument].
    ///
    /// - Received signals that have a type signature mismatch are dropped and
    ///   a warning is logged via g_warning().
    ///
    /// - Properties received via the initial `GetAll()` call or via the
    ///   `::PropertiesChanged` signal (on the
    ///   [org.freedesktop.DBus.Properties](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties)
    ///   interface) or set using g_dbus_proxy_set_cached_property()
    ///   with a type signature mismatch are ignored and a warning is
    ///   logged via g_warning().
    ///
    /// Note that these checks are never done on methods, signals and
    /// properties that are not referenced in the given
    /// #GDBusInterfaceInfo, since extending a D-Bus interface on the
    /// service-side is not considered an ABI break.
    #[doc(alias = "g-interface-info")]
    fn set_g_interface_info(&self, g_interface_info: Option<&DBusInterfaceInfo>) {
        ObjectExt::set_property(self.as_ref(), "g-interface-info", g_interface_info)
    }

    /// The D-Bus interface name the proxy is for.
    #[doc(alias = "g-interface-name")]
    fn g_interface_name(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "g-interface-name")
    }

    /// The well-known or unique name that the proxy is for.
    #[doc(alias = "g-name")]
    fn g_name(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "g-name")
    }

    /// The unique name that owns #GDBusProxy:g-name or [`None`] if no-one
    /// currently owns that name. You may connect to #GObject::notify signal to
    /// track changes to this property.
    #[doc(alias = "g-name-owner")]
    fn g_name_owner(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "g-name-owner")
    }

    /// The object path the proxy is for.
    #[doc(alias = "g-object-path")]
    fn g_object_path(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "g-object-path")
    }

    #[doc(alias = "g-default-timeout")]
    fn connect_g_default_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_g_default_timeout_trampoline<
            P: IsA<DBusProxy>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GDBusProxy,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(DBusProxy::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::g-default-timeout\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_g_default_timeout_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "g-interface-info")]
    fn connect_g_interface_info_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_g_interface_info_trampoline<
            P: IsA<DBusProxy>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GDBusProxy,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(DBusProxy::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::g-interface-info\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_g_interface_info_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "g-name-owner")]
    fn connect_g_name_owner_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_g_name_owner_trampoline<
            P: IsA<DBusProxy>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GDBusProxy,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(DBusProxy::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::g-name-owner\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_g_name_owner_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<DBusProxy>> DBusProxyExt for O {}