gio/auto/
network_service.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, SocketConnectable};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// Like [`NetworkAddress`][crate::NetworkAddress] does with hostnames, `GNetworkService`
15    /// provides an easy way to resolve a SRV record, and then attempt to
16    /// connect to one of the hosts that implements that service, handling
17    /// service priority/weighting, multiple IP addresses, and multiple
18    /// address families.
19    ///
20    /// See [`SrvTarget`][crate::SrvTarget] for more information about SRV records, and see
21    /// [`SocketConnectable`][crate::SocketConnectable] for an example of using the connectable
22    /// interface.
23    ///
24    /// ## Properties
25    ///
26    ///
27    /// #### `domain`
28    ///  Network domain, for example `example.com`.
29    ///
30    /// Readable | Writeable | Construct Only
31    ///
32    ///
33    /// #### `protocol`
34    ///  Network protocol, for example `tcp`.
35    ///
36    /// Readable | Writeable | Construct Only
37    ///
38    ///
39    /// #### `scheme`
40    ///  Network scheme (default is to use service).
41    ///
42    /// Readable | Writeable
43    ///
44    ///
45    /// #### `service`
46    ///  Service name, for example `ldap`.
47    ///
48    /// Readable | Writeable | Construct Only
49    ///
50    /// # Implements
51    ///
52    /// [`NetworkServiceExt`][trait@crate::prelude::NetworkServiceExt], [`trait@glib::ObjectExt`], [`SocketConnectableExt`][trait@crate::prelude::SocketConnectableExt]
53    #[doc(alias = "GNetworkService")]
54    pub struct NetworkService(Object<ffi::GNetworkService, ffi::GNetworkServiceClass>) @implements SocketConnectable;
55
56    match fn {
57        type_ => || ffi::g_network_service_get_type(),
58    }
59}
60
61impl NetworkService {
62    pub const NONE: Option<&'static NetworkService> = None;
63
64    /// Creates a new #GNetworkService representing the given @service,
65    /// @protocol, and @domain. This will initially be unresolved; use the
66    /// #GSocketConnectable interface to resolve it.
67    /// ## `service`
68    /// the service type to look up (eg, "ldap")
69    /// ## `protocol`
70    /// the networking protocol to use for @service (eg, "tcp")
71    /// ## `domain`
72    /// the DNS domain to look up the service in
73    ///
74    /// # Returns
75    ///
76    /// a new #GNetworkService
77    #[doc(alias = "g_network_service_new")]
78    pub fn new(service: &str, protocol: &str, domain: &str) -> NetworkService {
79        unsafe {
80            from_glib_full(ffi::g_network_service_new(
81                service.to_glib_none().0,
82                protocol.to_glib_none().0,
83                domain.to_glib_none().0,
84            ))
85        }
86    }
87}
88
89mod sealed {
90    pub trait Sealed {}
91    impl<T: super::IsA<super::NetworkService>> Sealed for T {}
92}
93
94/// Trait containing all [`struct@NetworkService`] methods.
95///
96/// # Implementors
97///
98/// [`NetworkService`][struct@crate::NetworkService]
99pub trait NetworkServiceExt: IsA<NetworkService> + sealed::Sealed + 'static {
100    /// Gets the domain that @self serves. This might be either UTF-8 or
101    /// ASCII-encoded, depending on what @self was created with.
102    ///
103    /// # Returns
104    ///
105    /// @self's domain name
106    #[doc(alias = "g_network_service_get_domain")]
107    #[doc(alias = "get_domain")]
108    fn domain(&self) -> glib::GString {
109        unsafe {
110            from_glib_none(ffi::g_network_service_get_domain(
111                self.as_ref().to_glib_none().0,
112            ))
113        }
114    }
115
116    /// Gets @self's protocol name (eg, "tcp").
117    ///
118    /// # Returns
119    ///
120    /// @self's protocol name
121    #[doc(alias = "g_network_service_get_protocol")]
122    #[doc(alias = "get_protocol")]
123    fn protocol(&self) -> glib::GString {
124        unsafe {
125            from_glib_none(ffi::g_network_service_get_protocol(
126                self.as_ref().to_glib_none().0,
127            ))
128        }
129    }
130
131    /// Gets the URI scheme used to resolve proxies. By default, the service name
132    /// is used as scheme.
133    ///
134    /// # Returns
135    ///
136    /// @self's scheme name
137    #[doc(alias = "g_network_service_get_scheme")]
138    #[doc(alias = "get_scheme")]
139    fn scheme(&self) -> glib::GString {
140        unsafe {
141            from_glib_none(ffi::g_network_service_get_scheme(
142                self.as_ref().to_glib_none().0,
143            ))
144        }
145    }
146
147    /// Gets @self's service name (eg, "ldap").
148    ///
149    /// # Returns
150    ///
151    /// @self's service name
152    #[doc(alias = "g_network_service_get_service")]
153    #[doc(alias = "get_service")]
154    fn service(&self) -> glib::GString {
155        unsafe {
156            from_glib_none(ffi::g_network_service_get_service(
157                self.as_ref().to_glib_none().0,
158            ))
159        }
160    }
161
162    /// Set's the URI scheme used to resolve proxies. By default, the service name
163    /// is used as scheme.
164    /// ## `scheme`
165    /// a URI scheme
166    #[doc(alias = "g_network_service_set_scheme")]
167    #[doc(alias = "scheme")]
168    fn set_scheme(&self, scheme: &str) {
169        unsafe {
170            ffi::g_network_service_set_scheme(
171                self.as_ref().to_glib_none().0,
172                scheme.to_glib_none().0,
173            );
174        }
175    }
176
177    #[doc(alias = "scheme")]
178    fn connect_scheme_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
179        unsafe extern "C" fn notify_scheme_trampoline<
180            P: IsA<NetworkService>,
181            F: Fn(&P) + 'static,
182        >(
183            this: *mut ffi::GNetworkService,
184            _param_spec: glib::ffi::gpointer,
185            f: glib::ffi::gpointer,
186        ) {
187            let f: &F = &*(f as *const F);
188            f(NetworkService::from_glib_borrow(this).unsafe_cast_ref())
189        }
190        unsafe {
191            let f: Box_<F> = Box_::new(f);
192            connect_raw(
193                self.as_ptr() as *mut _,
194                b"notify::scheme\0".as_ptr() as *const _,
195                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
196                    notify_scheme_trampoline::<Self, F> as *const (),
197                )),
198                Box_::into_raw(f),
199            )
200        }
201    }
202}
203
204impl<O: IsA<NetworkService>> NetworkServiceExt for O {}