1 // This file was generated by gir (https://github.com/gtk-rs/gir)
2 // from gir-files (https://github.com/gtk-rs/gir-files)
3 // DO NOT EDIT
4 
5 use gio_sys;
6 use glib;
7 use glib::object::Cast;
8 use glib::object::IsA;
9 use glib::signal::connect_raw;
10 use glib::signal::SignalHandlerId;
11 use glib::translate::*;
12 use glib::GString;
13 use glib_sys;
14 use gobject_sys;
15 use std::boxed::Box as Box_;
16 use std::fmt;
17 use std::mem::transmute;
18 use std::pin::Pin;
19 use std::ptr;
20 use Cancellable;
21 use InetAddress;
22 #[cfg(any(feature = "v2_60", feature = "dox"))]
23 use ResolverNameLookupFlags;
24 use ResolverRecordType;
25 use SrvTarget;
26 
27 glib_wrapper! {
28     pub struct Resolver(Object<gio_sys::GResolver, gio_sys::GResolverClass, ResolverClass>);
29 
30     match fn {
31         get_type => || gio_sys::g_resolver_get_type(),
32     }
33 }
34 
35 impl Resolver {
36     //pub fn free_addresses(addresses: /*Unimplemented*/&[&Fundamental: Pointer]) {
37     //    unsafe { TODO: call gio_sys:g_resolver_free_addresses() }
38     //}
39 
40     //pub fn free_targets(targets: /*Unimplemented*/&[&Fundamental: Pointer]) {
41     //    unsafe { TODO: call gio_sys:g_resolver_free_targets() }
42     //}
43 
get_default() -> Option<Resolver>44     pub fn get_default() -> Option<Resolver> {
45         unsafe { from_glib_full(gio_sys::g_resolver_get_default()) }
46     }
47 }
48 
49 pub const NONE_RESOLVER: Option<&Resolver> = None;
50 
51 pub trait ResolverExt: 'static {
lookup_by_address<P: IsA<InetAddress>, Q: IsA<Cancellable>>( &self, address: &P, cancellable: Option<&Q>, ) -> Result<GString, glib::Error>52     fn lookup_by_address<P: IsA<InetAddress>, Q: IsA<Cancellable>>(
53         &self,
54         address: &P,
55         cancellable: Option<&Q>,
56     ) -> Result<GString, glib::Error>;
57 
lookup_by_address_async< P: IsA<InetAddress>, Q: IsA<Cancellable>, R: FnOnce(Result<GString, glib::Error>) + Send + 'static, >( &self, address: &P, cancellable: Option<&Q>, callback: R, )58     fn lookup_by_address_async<
59         P: IsA<InetAddress>,
60         Q: IsA<Cancellable>,
61         R: FnOnce(Result<GString, glib::Error>) + Send + 'static,
62     >(
63         &self,
64         address: &P,
65         cancellable: Option<&Q>,
66         callback: R,
67     );
68 
lookup_by_address_async_future<P: IsA<InetAddress> + Clone + 'static>( &self, address: &P, ) -> Pin<Box_<dyn std::future::Future<Output = Result<GString, glib::Error>> + 'static>>69     fn lookup_by_address_async_future<P: IsA<InetAddress> + Clone + 'static>(
70         &self,
71         address: &P,
72     ) -> Pin<Box_<dyn std::future::Future<Output = Result<GString, glib::Error>> + 'static>>;
73 
lookup_by_name<P: IsA<Cancellable>>( &self, hostname: &str, cancellable: Option<&P>, ) -> Result<Vec<InetAddress>, glib::Error>74     fn lookup_by_name<P: IsA<Cancellable>>(
75         &self,
76         hostname: &str,
77         cancellable: Option<&P>,
78     ) -> Result<Vec<InetAddress>, glib::Error>;
79 
lookup_by_name_async< P: IsA<Cancellable>, Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static, >( &self, hostname: &str, cancellable: Option<&P>, callback: Q, )80     fn lookup_by_name_async<
81         P: IsA<Cancellable>,
82         Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static,
83     >(
84         &self,
85         hostname: &str,
86         cancellable: Option<&P>,
87         callback: Q,
88     );
89 
lookup_by_name_async_future( &self, hostname: &str, ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<InetAddress>, glib::Error>> + 'static>>90     fn lookup_by_name_async_future(
91         &self,
92         hostname: &str,
93     ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<InetAddress>, glib::Error>> + 'static>>;
94 
95     #[cfg(any(feature = "v2_60", feature = "dox"))]
lookup_by_name_with_flags<P: IsA<Cancellable>>( &self, hostname: &str, flags: ResolverNameLookupFlags, cancellable: Option<&P>, ) -> Result<Vec<InetAddress>, glib::Error>96     fn lookup_by_name_with_flags<P: IsA<Cancellable>>(
97         &self,
98         hostname: &str,
99         flags: ResolverNameLookupFlags,
100         cancellable: Option<&P>,
101     ) -> Result<Vec<InetAddress>, glib::Error>;
102 
103     #[cfg(any(feature = "v2_60", feature = "dox"))]
lookup_by_name_with_flags_async< P: IsA<Cancellable>, Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static, >( &self, hostname: &str, flags: ResolverNameLookupFlags, cancellable: Option<&P>, callback: Q, )104     fn lookup_by_name_with_flags_async<
105         P: IsA<Cancellable>,
106         Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static,
107     >(
108         &self,
109         hostname: &str,
110         flags: ResolverNameLookupFlags,
111         cancellable: Option<&P>,
112         callback: Q,
113     );
114 
115     #[cfg(any(feature = "v2_60", feature = "dox"))]
lookup_by_name_with_flags_async_future( &self, hostname: &str, flags: ResolverNameLookupFlags, ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<InetAddress>, glib::Error>> + 'static>>116     fn lookup_by_name_with_flags_async_future(
117         &self,
118         hostname: &str,
119         flags: ResolverNameLookupFlags,
120     ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<InetAddress>, glib::Error>> + 'static>>;
121 
lookup_records<P: IsA<Cancellable>>( &self, rrname: &str, record_type: ResolverRecordType, cancellable: Option<&P>, ) -> Result<Vec<glib::Variant>, glib::Error>122     fn lookup_records<P: IsA<Cancellable>>(
123         &self,
124         rrname: &str,
125         record_type: ResolverRecordType,
126         cancellable: Option<&P>,
127     ) -> Result<Vec<glib::Variant>, glib::Error>;
128 
lookup_records_async< P: IsA<Cancellable>, Q: FnOnce(Result<Vec<glib::Variant>, glib::Error>) + Send + 'static, >( &self, rrname: &str, record_type: ResolverRecordType, cancellable: Option<&P>, callback: Q, )129     fn lookup_records_async<
130         P: IsA<Cancellable>,
131         Q: FnOnce(Result<Vec<glib::Variant>, glib::Error>) + Send + 'static,
132     >(
133         &self,
134         rrname: &str,
135         record_type: ResolverRecordType,
136         cancellable: Option<&P>,
137         callback: Q,
138     );
139 
lookup_records_async_future( &self, rrname: &str, record_type: ResolverRecordType, ) -> Pin< Box_<dyn std::future::Future<Output = Result<Vec<glib::Variant>, glib::Error>> + 'static>, >140     fn lookup_records_async_future(
141         &self,
142         rrname: &str,
143         record_type: ResolverRecordType,
144     ) -> Pin<
145         Box_<dyn std::future::Future<Output = Result<Vec<glib::Variant>, glib::Error>> + 'static>,
146     >;
147 
lookup_service<P: IsA<Cancellable>>( &self, service: &str, protocol: &str, domain: &str, cancellable: Option<&P>, ) -> Result<Vec<SrvTarget>, glib::Error>148     fn lookup_service<P: IsA<Cancellable>>(
149         &self,
150         service: &str,
151         protocol: &str,
152         domain: &str,
153         cancellable: Option<&P>,
154     ) -> Result<Vec<SrvTarget>, glib::Error>;
155 
lookup_service_async< P: IsA<Cancellable>, Q: FnOnce(Result<Vec<SrvTarget>, glib::Error>) + Send + 'static, >( &self, service: &str, protocol: &str, domain: &str, cancellable: Option<&P>, callback: Q, )156     fn lookup_service_async<
157         P: IsA<Cancellable>,
158         Q: FnOnce(Result<Vec<SrvTarget>, glib::Error>) + Send + 'static,
159     >(
160         &self,
161         service: &str,
162         protocol: &str,
163         domain: &str,
164         cancellable: Option<&P>,
165         callback: Q,
166     );
167 
lookup_service_async_future( &self, service: &str, protocol: &str, domain: &str, ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<SrvTarget>, glib::Error>> + 'static>>168     fn lookup_service_async_future(
169         &self,
170         service: &str,
171         protocol: &str,
172         domain: &str,
173     ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<SrvTarget>, glib::Error>> + 'static>>;
174 
set_default(&self)175     fn set_default(&self);
176 
connect_reload<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId177     fn connect_reload<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
178 }
179 
180 impl<O: IsA<Resolver>> ResolverExt for O {
lookup_by_address<P: IsA<InetAddress>, Q: IsA<Cancellable>>( &self, address: &P, cancellable: Option<&Q>, ) -> Result<GString, glib::Error>181     fn lookup_by_address<P: IsA<InetAddress>, Q: IsA<Cancellable>>(
182         &self,
183         address: &P,
184         cancellable: Option<&Q>,
185     ) -> Result<GString, glib::Error> {
186         unsafe {
187             let mut error = ptr::null_mut();
188             let ret = gio_sys::g_resolver_lookup_by_address(
189                 self.as_ref().to_glib_none().0,
190                 address.as_ref().to_glib_none().0,
191                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
192                 &mut error,
193             );
194             if error.is_null() {
195                 Ok(from_glib_full(ret))
196             } else {
197                 Err(from_glib_full(error))
198             }
199         }
200     }
201 
lookup_by_address_async< P: IsA<InetAddress>, Q: IsA<Cancellable>, R: FnOnce(Result<GString, glib::Error>) + Send + 'static, >( &self, address: &P, cancellable: Option<&Q>, callback: R, )202     fn lookup_by_address_async<
203         P: IsA<InetAddress>,
204         Q: IsA<Cancellable>,
205         R: FnOnce(Result<GString, glib::Error>) + Send + 'static,
206     >(
207         &self,
208         address: &P,
209         cancellable: Option<&Q>,
210         callback: R,
211     ) {
212         let user_data: Box_<R> = Box_::new(callback);
213         unsafe extern "C" fn lookup_by_address_async_trampoline<
214             R: FnOnce(Result<GString, glib::Error>) + Send + 'static,
215         >(
216             _source_object: *mut gobject_sys::GObject,
217             res: *mut gio_sys::GAsyncResult,
218             user_data: glib_sys::gpointer,
219         ) {
220             let mut error = ptr::null_mut();
221             let ret = gio_sys::g_resolver_lookup_by_address_finish(
222                 _source_object as *mut _,
223                 res,
224                 &mut error,
225             );
226             let result = if error.is_null() {
227                 Ok(from_glib_full(ret))
228             } else {
229                 Err(from_glib_full(error))
230             };
231             let callback: Box_<R> = Box_::from_raw(user_data as *mut _);
232             callback(result);
233         }
234         let callback = lookup_by_address_async_trampoline::<R>;
235         unsafe {
236             gio_sys::g_resolver_lookup_by_address_async(
237                 self.as_ref().to_glib_none().0,
238                 address.as_ref().to_glib_none().0,
239                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
240                 Some(callback),
241                 Box_::into_raw(user_data) as *mut _,
242             );
243         }
244     }
245 
lookup_by_address_async_future<P: IsA<InetAddress> + Clone + 'static>( &self, address: &P, ) -> Pin<Box_<dyn std::future::Future<Output = Result<GString, glib::Error>> + 'static>>246     fn lookup_by_address_async_future<P: IsA<InetAddress> + Clone + 'static>(
247         &self,
248         address: &P,
249     ) -> Pin<Box_<dyn std::future::Future<Output = Result<GString, glib::Error>> + 'static>> {
250         let address = address.clone();
251         Box_::pin(crate::GioFuture::new(self, move |obj, send| {
252             let cancellable = Cancellable::new();
253             obj.lookup_by_address_async(&address, Some(&cancellable), move |res| {
254                 send.resolve(res);
255             });
256 
257             cancellable
258         }))
259     }
260 
lookup_by_name<P: IsA<Cancellable>>( &self, hostname: &str, cancellable: Option<&P>, ) -> Result<Vec<InetAddress>, glib::Error>261     fn lookup_by_name<P: IsA<Cancellable>>(
262         &self,
263         hostname: &str,
264         cancellable: Option<&P>,
265     ) -> Result<Vec<InetAddress>, glib::Error> {
266         unsafe {
267             let mut error = ptr::null_mut();
268             let ret = gio_sys::g_resolver_lookup_by_name(
269                 self.as_ref().to_glib_none().0,
270                 hostname.to_glib_none().0,
271                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
272                 &mut error,
273             );
274             if error.is_null() {
275                 Ok(FromGlibPtrContainer::from_glib_full(ret))
276             } else {
277                 Err(from_glib_full(error))
278             }
279         }
280     }
281 
lookup_by_name_async< P: IsA<Cancellable>, Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static, >( &self, hostname: &str, cancellable: Option<&P>, callback: Q, )282     fn lookup_by_name_async<
283         P: IsA<Cancellable>,
284         Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static,
285     >(
286         &self,
287         hostname: &str,
288         cancellable: Option<&P>,
289         callback: Q,
290     ) {
291         let user_data: Box_<Q> = Box_::new(callback);
292         unsafe extern "C" fn lookup_by_name_async_trampoline<
293             Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static,
294         >(
295             _source_object: *mut gobject_sys::GObject,
296             res: *mut gio_sys::GAsyncResult,
297             user_data: glib_sys::gpointer,
298         ) {
299             let mut error = ptr::null_mut();
300             let ret = gio_sys::g_resolver_lookup_by_name_finish(
301                 _source_object as *mut _,
302                 res,
303                 &mut error,
304             );
305             let result = if error.is_null() {
306                 Ok(FromGlibPtrContainer::from_glib_full(ret))
307             } else {
308                 Err(from_glib_full(error))
309             };
310             let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
311             callback(result);
312         }
313         let callback = lookup_by_name_async_trampoline::<Q>;
314         unsafe {
315             gio_sys::g_resolver_lookup_by_name_async(
316                 self.as_ref().to_glib_none().0,
317                 hostname.to_glib_none().0,
318                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
319                 Some(callback),
320                 Box_::into_raw(user_data) as *mut _,
321             );
322         }
323     }
324 
lookup_by_name_async_future( &self, hostname: &str, ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<InetAddress>, glib::Error>> + 'static>>325     fn lookup_by_name_async_future(
326         &self,
327         hostname: &str,
328     ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<InetAddress>, glib::Error>> + 'static>>
329     {
330         let hostname = String::from(hostname);
331         Box_::pin(crate::GioFuture::new(self, move |obj, send| {
332             let cancellable = Cancellable::new();
333             obj.lookup_by_name_async(&hostname, Some(&cancellable), move |res| {
334                 send.resolve(res);
335             });
336 
337             cancellable
338         }))
339     }
340 
341     #[cfg(any(feature = "v2_60", feature = "dox"))]
lookup_by_name_with_flags<P: IsA<Cancellable>>( &self, hostname: &str, flags: ResolverNameLookupFlags, cancellable: Option<&P>, ) -> Result<Vec<InetAddress>, glib::Error>342     fn lookup_by_name_with_flags<P: IsA<Cancellable>>(
343         &self,
344         hostname: &str,
345         flags: ResolverNameLookupFlags,
346         cancellable: Option<&P>,
347     ) -> Result<Vec<InetAddress>, glib::Error> {
348         unsafe {
349             let mut error = ptr::null_mut();
350             let ret = gio_sys::g_resolver_lookup_by_name_with_flags(
351                 self.as_ref().to_glib_none().0,
352                 hostname.to_glib_none().0,
353                 flags.to_glib(),
354                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
355                 &mut error,
356             );
357             if error.is_null() {
358                 Ok(FromGlibPtrContainer::from_glib_full(ret))
359             } else {
360                 Err(from_glib_full(error))
361             }
362         }
363     }
364 
365     #[cfg(any(feature = "v2_60", feature = "dox"))]
lookup_by_name_with_flags_async< P: IsA<Cancellable>, Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static, >( &self, hostname: &str, flags: ResolverNameLookupFlags, cancellable: Option<&P>, callback: Q, )366     fn lookup_by_name_with_flags_async<
367         P: IsA<Cancellable>,
368         Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static,
369     >(
370         &self,
371         hostname: &str,
372         flags: ResolverNameLookupFlags,
373         cancellable: Option<&P>,
374         callback: Q,
375     ) {
376         let user_data: Box_<Q> = Box_::new(callback);
377         unsafe extern "C" fn lookup_by_name_with_flags_async_trampoline<
378             Q: FnOnce(Result<Vec<InetAddress>, glib::Error>) + Send + 'static,
379         >(
380             _source_object: *mut gobject_sys::GObject,
381             res: *mut gio_sys::GAsyncResult,
382             user_data: glib_sys::gpointer,
383         ) {
384             let mut error = ptr::null_mut();
385             let ret = gio_sys::g_resolver_lookup_by_name_with_flags_finish(
386                 _source_object as *mut _,
387                 res,
388                 &mut error,
389             );
390             let result = if error.is_null() {
391                 Ok(FromGlibPtrContainer::from_glib_full(ret))
392             } else {
393                 Err(from_glib_full(error))
394             };
395             let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
396             callback(result);
397         }
398         let callback = lookup_by_name_with_flags_async_trampoline::<Q>;
399         unsafe {
400             gio_sys::g_resolver_lookup_by_name_with_flags_async(
401                 self.as_ref().to_glib_none().0,
402                 hostname.to_glib_none().0,
403                 flags.to_glib(),
404                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
405                 Some(callback),
406                 Box_::into_raw(user_data) as *mut _,
407             );
408         }
409     }
410 
411     #[cfg(any(feature = "v2_60", feature = "dox"))]
lookup_by_name_with_flags_async_future( &self, hostname: &str, flags: ResolverNameLookupFlags, ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<InetAddress>, glib::Error>> + 'static>>412     fn lookup_by_name_with_flags_async_future(
413         &self,
414         hostname: &str,
415         flags: ResolverNameLookupFlags,
416     ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<InetAddress>, glib::Error>> + 'static>>
417     {
418         let hostname = String::from(hostname);
419         Box_::pin(crate::GioFuture::new(self, move |obj, send| {
420             let cancellable = Cancellable::new();
421             obj.lookup_by_name_with_flags_async(&hostname, flags, Some(&cancellable), move |res| {
422                 send.resolve(res);
423             });
424 
425             cancellable
426         }))
427     }
428 
lookup_records<P: IsA<Cancellable>>( &self, rrname: &str, record_type: ResolverRecordType, cancellable: Option<&P>, ) -> Result<Vec<glib::Variant>, glib::Error>429     fn lookup_records<P: IsA<Cancellable>>(
430         &self,
431         rrname: &str,
432         record_type: ResolverRecordType,
433         cancellable: Option<&P>,
434     ) -> Result<Vec<glib::Variant>, glib::Error> {
435         unsafe {
436             let mut error = ptr::null_mut();
437             let ret = gio_sys::g_resolver_lookup_records(
438                 self.as_ref().to_glib_none().0,
439                 rrname.to_glib_none().0,
440                 record_type.to_glib(),
441                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
442                 &mut error,
443             );
444             if error.is_null() {
445                 Ok(FromGlibPtrContainer::from_glib_full(ret))
446             } else {
447                 Err(from_glib_full(error))
448             }
449         }
450     }
451 
lookup_records_async< P: IsA<Cancellable>, Q: FnOnce(Result<Vec<glib::Variant>, glib::Error>) + Send + 'static, >( &self, rrname: &str, record_type: ResolverRecordType, cancellable: Option<&P>, callback: Q, )452     fn lookup_records_async<
453         P: IsA<Cancellable>,
454         Q: FnOnce(Result<Vec<glib::Variant>, glib::Error>) + Send + 'static,
455     >(
456         &self,
457         rrname: &str,
458         record_type: ResolverRecordType,
459         cancellable: Option<&P>,
460         callback: Q,
461     ) {
462         let user_data: Box_<Q> = Box_::new(callback);
463         unsafe extern "C" fn lookup_records_async_trampoline<
464             Q: FnOnce(Result<Vec<glib::Variant>, glib::Error>) + Send + 'static,
465         >(
466             _source_object: *mut gobject_sys::GObject,
467             res: *mut gio_sys::GAsyncResult,
468             user_data: glib_sys::gpointer,
469         ) {
470             let mut error = ptr::null_mut();
471             let ret = gio_sys::g_resolver_lookup_records_finish(
472                 _source_object as *mut _,
473                 res,
474                 &mut error,
475             );
476             let result = if error.is_null() {
477                 Ok(FromGlibPtrContainer::from_glib_full(ret))
478             } else {
479                 Err(from_glib_full(error))
480             };
481             let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
482             callback(result);
483         }
484         let callback = lookup_records_async_trampoline::<Q>;
485         unsafe {
486             gio_sys::g_resolver_lookup_records_async(
487                 self.as_ref().to_glib_none().0,
488                 rrname.to_glib_none().0,
489                 record_type.to_glib(),
490                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
491                 Some(callback),
492                 Box_::into_raw(user_data) as *mut _,
493             );
494         }
495     }
496 
lookup_records_async_future( &self, rrname: &str, record_type: ResolverRecordType, ) -> Pin< Box_<dyn std::future::Future<Output = Result<Vec<glib::Variant>, glib::Error>> + 'static>, >497     fn lookup_records_async_future(
498         &self,
499         rrname: &str,
500         record_type: ResolverRecordType,
501     ) -> Pin<
502         Box_<dyn std::future::Future<Output = Result<Vec<glib::Variant>, glib::Error>> + 'static>,
503     > {
504         let rrname = String::from(rrname);
505         Box_::pin(crate::GioFuture::new(self, move |obj, send| {
506             let cancellable = Cancellable::new();
507             obj.lookup_records_async(&rrname, record_type, Some(&cancellable), move |res| {
508                 send.resolve(res);
509             });
510 
511             cancellable
512         }))
513     }
514 
lookup_service<P: IsA<Cancellable>>( &self, service: &str, protocol: &str, domain: &str, cancellable: Option<&P>, ) -> Result<Vec<SrvTarget>, glib::Error>515     fn lookup_service<P: IsA<Cancellable>>(
516         &self,
517         service: &str,
518         protocol: &str,
519         domain: &str,
520         cancellable: Option<&P>,
521     ) -> Result<Vec<SrvTarget>, glib::Error> {
522         unsafe {
523             let mut error = ptr::null_mut();
524             let ret = gio_sys::g_resolver_lookup_service(
525                 self.as_ref().to_glib_none().0,
526                 service.to_glib_none().0,
527                 protocol.to_glib_none().0,
528                 domain.to_glib_none().0,
529                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
530                 &mut error,
531             );
532             if error.is_null() {
533                 Ok(FromGlibPtrContainer::from_glib_full(ret))
534             } else {
535                 Err(from_glib_full(error))
536             }
537         }
538     }
539 
lookup_service_async< P: IsA<Cancellable>, Q: FnOnce(Result<Vec<SrvTarget>, glib::Error>) + Send + 'static, >( &self, service: &str, protocol: &str, domain: &str, cancellable: Option<&P>, callback: Q, )540     fn lookup_service_async<
541         P: IsA<Cancellable>,
542         Q: FnOnce(Result<Vec<SrvTarget>, glib::Error>) + Send + 'static,
543     >(
544         &self,
545         service: &str,
546         protocol: &str,
547         domain: &str,
548         cancellable: Option<&P>,
549         callback: Q,
550     ) {
551         let user_data: Box_<Q> = Box_::new(callback);
552         unsafe extern "C" fn lookup_service_async_trampoline<
553             Q: FnOnce(Result<Vec<SrvTarget>, glib::Error>) + Send + 'static,
554         >(
555             _source_object: *mut gobject_sys::GObject,
556             res: *mut gio_sys::GAsyncResult,
557             user_data: glib_sys::gpointer,
558         ) {
559             let mut error = ptr::null_mut();
560             let ret = gio_sys::g_resolver_lookup_service_finish(
561                 _source_object as *mut _,
562                 res,
563                 &mut error,
564             );
565             let result = if error.is_null() {
566                 Ok(FromGlibPtrContainer::from_glib_full(ret))
567             } else {
568                 Err(from_glib_full(error))
569             };
570             let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
571             callback(result);
572         }
573         let callback = lookup_service_async_trampoline::<Q>;
574         unsafe {
575             gio_sys::g_resolver_lookup_service_async(
576                 self.as_ref().to_glib_none().0,
577                 service.to_glib_none().0,
578                 protocol.to_glib_none().0,
579                 domain.to_glib_none().0,
580                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
581                 Some(callback),
582                 Box_::into_raw(user_data) as *mut _,
583             );
584         }
585     }
586 
lookup_service_async_future( &self, service: &str, protocol: &str, domain: &str, ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<SrvTarget>, glib::Error>> + 'static>>587     fn lookup_service_async_future(
588         &self,
589         service: &str,
590         protocol: &str,
591         domain: &str,
592     ) -> Pin<Box_<dyn std::future::Future<Output = Result<Vec<SrvTarget>, glib::Error>> + 'static>>
593     {
594         let service = String::from(service);
595         let protocol = String::from(protocol);
596         let domain = String::from(domain);
597         Box_::pin(crate::GioFuture::new(self, move |obj, send| {
598             let cancellable = Cancellable::new();
599             obj.lookup_service_async(
600                 &service,
601                 &protocol,
602                 &domain,
603                 Some(&cancellable),
604                 move |res| {
605                     send.resolve(res);
606                 },
607             );
608 
609             cancellable
610         }))
611     }
612 
set_default(&self)613     fn set_default(&self) {
614         unsafe {
615             gio_sys::g_resolver_set_default(self.as_ref().to_glib_none().0);
616         }
617     }
618 
connect_reload<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId619     fn connect_reload<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
620         unsafe extern "C" fn reload_trampoline<P, F: Fn(&P) + 'static>(
621             this: *mut gio_sys::GResolver,
622             f: glib_sys::gpointer,
623         ) where
624             P: IsA<Resolver>,
625         {
626             let f: &F = &*(f as *const F);
627             f(&Resolver::from_glib_borrow(this).unsafe_cast())
628         }
629         unsafe {
630             let f: Box_<F> = Box_::new(f);
631             connect_raw(
632                 self.as_ptr() as *mut _,
633                 b"reload\0".as_ptr() as *const _,
634                 Some(transmute(reload_trampoline::<Self, F> as usize)),
635                 Box_::into_raw(f),
636             )
637         }
638     }
639 }
640 
641 impl fmt::Display for Resolver {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result642     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
643         write!(f, "Resolver")
644     }
645 }
646