@@ -22,89 +22,149 @@ pub struct FilterId(NonZeroU32);
22
22
#[ derive( Debug , Eq , PartialEq ) ]
23
23
pub struct SignalSubscriptionId ( NonZeroU32 ) ;
24
24
25
- impl DBusConnection {
26
- #[ doc( alias = "g_dbus_connection_register_object_with_closures" ) ]
27
- pub fn register_object < MethodCall , SetProperty , GetProperty > (
28
- & self ,
29
- object_path : & str ,
30
- interface_info : & DBusInterfaceInfo ,
31
- method_call : MethodCall ,
32
- get_property : GetProperty ,
33
- set_property : SetProperty ,
34
- ) -> Result < RegistrationId , glib:: Error >
35
- where
36
- MethodCall : Fn ( DBusConnection , & str , & str , & str , & str , glib:: Variant , DBusMethodInvocation )
37
- + ' static ,
38
- GetProperty : Fn ( DBusConnection , & str , & str , & str , & str ) -> glib:: Variant + ' static ,
39
- SetProperty : Fn ( DBusConnection , & str , & str , & str , & str , glib:: Variant ) -> bool + ' static ,
40
- {
25
+ #[ must_use = "The builder must be built to be used" ]
26
+ pub struct RegistrationBuilder < ' a > {
27
+ connection : & ' a DBusConnection ,
28
+ object_path : & ' a str ,
29
+ interface_info : & ' a DBusInterfaceInfo ,
30
+ #[ allow( clippy:: type_complexity) ]
31
+ method_call : Option <
32
+ Box_ < dyn Fn ( DBusConnection , & str , & str , & str , & str , glib:: Variant , DBusMethodInvocation ) > ,
33
+ > ,
34
+ #[ allow( clippy:: type_complexity) ]
35
+ get_property : Option < Box_ < dyn Fn ( DBusConnection , & str , & str , & str , & str ) -> glib:: Variant > > ,
36
+ #[ allow( clippy:: type_complexity) ]
37
+ set_property :
38
+ Option < Box_ < dyn Fn ( DBusConnection , & str , & str , & str , & str , glib:: Variant ) -> bool > > ,
39
+ }
40
+
41
+ impl < ' a > RegistrationBuilder < ' a > {
42
+ pub fn method_call <
43
+ F : Fn ( DBusConnection , & str , & str , & str , & str , glib:: Variant , DBusMethodInvocation ) + ' static ,
44
+ > (
45
+ mut self ,
46
+ f : F ,
47
+ ) -> Self {
48
+ self . method_call = Some ( Box_ :: new ( f) ) ;
49
+ self
50
+ }
51
+
52
+ #[ doc( alias = "get_property" ) ]
53
+ pub fn property < F : Fn ( DBusConnection , & str , & str , & str , & str ) -> glib:: Variant + ' static > (
54
+ mut self ,
55
+ f : F ,
56
+ ) -> Self {
57
+ self . get_property = Some ( Box_ :: new ( f) ) ;
58
+ self
59
+ }
60
+
61
+ pub fn set_property <
62
+ F : Fn ( DBusConnection , & str , & str , & str , & str , glib:: Variant ) -> bool + ' static ,
63
+ > (
64
+ mut self ,
65
+ f : F ,
66
+ ) -> Self {
67
+ self . set_property = Some ( Box_ :: new ( f) ) ;
68
+ self
69
+ }
70
+
71
+ pub fn build ( self ) -> Result < RegistrationId , glib:: Error > {
41
72
unsafe {
42
73
let mut error = std:: ptr:: null_mut ( ) ;
43
74
let id = ffi:: g_dbus_connection_register_object_with_closures (
44
- self . to_glib_none ( ) . 0 ,
45
- object_path. to_glib_none ( ) . 0 ,
46
- interface_info. to_glib_none ( ) . 0 ,
47
- glib:: Closure :: new_local ( move |args| {
48
- let conn = args[ 0 ] . get :: < DBusConnection > ( ) . unwrap ( ) ;
49
- let sender = args[ 1 ] . get :: < & str > ( ) . unwrap ( ) ;
50
- let object_path = args[ 2 ] . get :: < & str > ( ) . unwrap ( ) ;
51
- let interface_name = args[ 3 ] . get :: < & str > ( ) . unwrap ( ) ;
52
- let method_name = args[ 4 ] . get :: < & str > ( ) . unwrap ( ) ;
53
- let parameters = args[ 5 ] . get :: < glib:: Variant > ( ) . unwrap ( ) ;
54
- let invocation = args[ 6 ] . get :: < DBusMethodInvocation > ( ) . unwrap ( ) ;
55
- method_call (
56
- conn,
57
- sender,
58
- object_path,
59
- interface_name,
60
- method_name,
61
- parameters,
62
- invocation,
63
- ) ;
64
- None
65
- } )
66
- . to_glib_none ( )
67
- . 0 ,
68
- glib:: Closure :: new_local ( move |args| {
69
- let conn = args[ 0 ] . get :: < DBusConnection > ( ) . unwrap ( ) ;
70
- let sender = args[ 1 ] . get :: < & str > ( ) . unwrap ( ) ;
71
- let object_path = args[ 2 ] . get :: < & str > ( ) . unwrap ( ) ;
72
- let interface_name = args[ 3 ] . get :: < & str > ( ) . unwrap ( ) ;
73
- let property_name = args[ 4 ] . get :: < & str > ( ) . unwrap ( ) ;
74
- let result =
75
- get_property ( conn, sender, object_path, interface_name, property_name) ;
76
- Some ( result. to_value ( ) )
77
- } )
78
- . to_glib_none ( )
79
- . 0 ,
80
- glib:: Closure :: new_local ( move |args| {
81
- let conn = args[ 0 ] . get :: < DBusConnection > ( ) . unwrap ( ) ;
82
- let sender = args[ 1 ] . get :: < & str > ( ) . unwrap ( ) ;
83
- let object_path = args[ 2 ] . get :: < & str > ( ) . unwrap ( ) ;
84
- let interface_name = args[ 3 ] . get :: < & str > ( ) . unwrap ( ) ;
85
- let property_name = args[ 4 ] . get :: < & str > ( ) . unwrap ( ) ;
86
- let value = args[ 5 ] . get :: < glib:: Variant > ( ) . unwrap ( ) ;
87
- let result = set_property (
88
- conn,
89
- sender,
90
- object_path,
91
- interface_name,
92
- property_name,
93
- value,
94
- ) ;
95
- Some ( result. to_value ( ) )
96
- } )
97
- . to_glib_none ( )
98
- . 0 ,
75
+ self . connection . to_glib_none ( ) . 0 ,
76
+ self . object_path . to_glib_none ( ) . 0 ,
77
+ self . interface_info . to_glib_none ( ) . 0 ,
78
+ self . method_call
79
+ . map ( |f| {
80
+ glib:: Closure :: new_local ( move |args| {
81
+ let conn = args[ 0 ] . get :: < DBusConnection > ( ) . unwrap ( ) ;
82
+ let sender = args[ 1 ] . get :: < & str > ( ) . unwrap ( ) ;
83
+ let object_path = args[ 2 ] . get :: < & str > ( ) . unwrap ( ) ;
84
+ let interface_name = args[ 3 ] . get :: < & str > ( ) . unwrap ( ) ;
85
+ let method_name = args[ 4 ] . get :: < & str > ( ) . unwrap ( ) ;
86
+ let parameters = args[ 5 ] . get :: < glib:: Variant > ( ) . unwrap ( ) ;
87
+ let invocation = args[ 6 ] . get :: < DBusMethodInvocation > ( ) . unwrap ( ) ;
88
+ f (
89
+ conn,
90
+ sender,
91
+ object_path,
92
+ interface_name,
93
+ method_name,
94
+ parameters,
95
+ invocation,
96
+ ) ;
97
+ None
98
+ } )
99
+ } )
100
+ . to_glib_none ( )
101
+ . 0 ,
102
+ self . set_property
103
+ . map ( |f| {
104
+ glib:: Closure :: new_local ( move |args| {
105
+ let conn = args[ 0 ] . get :: < DBusConnection > ( ) . unwrap ( ) ;
106
+ let sender = args[ 1 ] . get :: < & str > ( ) . unwrap ( ) ;
107
+ let object_path = args[ 2 ] . get :: < & str > ( ) . unwrap ( ) ;
108
+ let interface_name = args[ 3 ] . get :: < & str > ( ) . unwrap ( ) ;
109
+ let property_name = args[ 4 ] . get :: < & str > ( ) . unwrap ( ) ;
110
+ let value = args[ 5 ] . get :: < glib:: Variant > ( ) . unwrap ( ) ;
111
+ let result = f (
112
+ conn,
113
+ sender,
114
+ object_path,
115
+ interface_name,
116
+ property_name,
117
+ value,
118
+ ) ;
119
+ Some ( result. to_value ( ) )
120
+ } )
121
+ } )
122
+ . to_glib_none ( )
123
+ . 0 ,
124
+ self . get_property
125
+ . map ( |f| {
126
+ glib:: Closure :: new_local ( move |args| {
127
+ let conn = args[ 0 ] . get :: < DBusConnection > ( ) . unwrap ( ) ;
128
+ let sender = args[ 1 ] . get :: < & str > ( ) . unwrap ( ) ;
129
+ let object_path = args[ 2 ] . get :: < & str > ( ) . unwrap ( ) ;
130
+ let interface_name = args[ 3 ] . get :: < & str > ( ) . unwrap ( ) ;
131
+ let property_name = args[ 4 ] . get :: < & str > ( ) . unwrap ( ) ;
132
+ let result =
133
+ f ( conn, sender, object_path, interface_name, property_name) ;
134
+ Some ( result. to_value ( ) )
135
+ } )
136
+ } )
137
+ . to_glib_none ( )
138
+ . 0 ,
99
139
& mut error,
100
140
) ;
141
+
101
142
if error. is_null ( ) {
102
143
Ok ( RegistrationId ( NonZeroU32 :: new_unchecked ( id) ) )
103
144
} else {
104
145
Err ( from_glib_full ( error) )
105
146
}
106
147
}
107
148
}
149
+ }
150
+
151
+ impl DBusConnection {
152
+ #[ doc( alias = "g_dbus_connection_register_object" ) ]
153
+ #[ doc( alias = "g_dbus_connection_register_object_with_closures" ) ]
154
+ pub fn register_object < ' a > (
155
+ & ' a self ,
156
+ object_path : & ' a str ,
157
+ interface_info : & ' a DBusInterfaceInfo ,
158
+ ) -> RegistrationBuilder < ' a > {
159
+ RegistrationBuilder {
160
+ connection : self ,
161
+ object_path,
162
+ interface_info,
163
+ method_call : None ,
164
+ get_property : None ,
165
+ set_property : None ,
166
+ }
167
+ }
108
168
109
169
#[ doc( alias = "g_dbus_connection_unregister_object" ) ]
110
170
pub fn unregister_object (
0 commit comments