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
89/// Trait containing all [`struct@NetworkService`] methods.
90///
91/// # Implementors
92///
93/// [`NetworkService`][struct@crate::NetworkService]
94pub trait NetworkServiceExt: IsA<NetworkService> + 'static {
95    /// Gets the domain that @self serves. This might be either UTF-8 or
96    /// ASCII-encoded, depending on what @self was created with.
97    ///
98    /// # Returns
99    ///
100    /// @self's domain name
101    #[doc(alias = "g_network_service_get_domain")]
102    #[doc(alias = "get_domain")]
103    fn domain(&self) -> glib::GString {
104        unsafe {
105            from_glib_none(ffi::g_network_service_get_domain(
106                self.as_ref().to_glib_none().0,
107            ))
108        }
109    }
110
111    /// Gets @self's protocol name (eg, "tcp").
112    ///
113    /// # Returns
114    ///
115    /// @self's protocol name
116    #[doc(alias = "g_network_service_get_protocol")]
117    #[doc(alias = "get_protocol")]
118    fn protocol(&self) -> glib::GString {
119        unsafe {
120            from_glib_none(ffi::g_network_service_get_protocol(
121                self.as_ref().to_glib_none().0,
122            ))
123        }
124    }
125
126    /// Gets the URI scheme used to resolve proxies. By default, the service name
127    /// is used as scheme.
128    ///
129    /// # Returns
130    ///
131    /// @self's scheme name
132    #[doc(alias = "g_network_service_get_scheme")]
133    #[doc(alias = "get_scheme")]
134    fn scheme(&self) -> glib::GString {
135        unsafe {
136            from_glib_none(ffi::g_network_service_get_scheme(
137                self.as_ref().to_glib_none().0,
138            ))
139        }
140    }
141
142    /// Gets @self's service name (eg, "ldap").
143    ///
144    /// # Returns
145    ///
146    /// @self's service name
147    #[doc(alias = "g_network_service_get_service")]
148    #[doc(alias = "get_service")]
149    fn service(&self) -> glib::GString {
150        unsafe {
151            from_glib_none(ffi::g_network_service_get_service(
152                self.as_ref().to_glib_none().0,
153            ))
154        }
155    }
156
157    /// Set's the URI scheme used to resolve proxies. By default, the service name
158    /// is used as scheme.
159    /// ## `scheme`
160    /// a URI scheme
161    #[doc(alias = "g_network_service_set_scheme")]
162    #[doc(alias = "scheme")]
163    fn set_scheme(&self, scheme: &str) {
164        unsafe {
165            ffi::g_network_service_set_scheme(
166                self.as_ref().to_glib_none().0,
167                scheme.to_glib_none().0,
168            );
169        }
170    }
171
172    #[doc(alias = "scheme")]
173    fn connect_scheme_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
174        unsafe extern "C" fn notify_scheme_trampoline<
175            P: IsA<NetworkService>,
176            F: Fn(&P) + 'static,
177        >(
178            this: *mut ffi::GNetworkService,
179            _param_spec: glib::ffi::gpointer,
180            f: glib::ffi::gpointer,
181        ) {
182            let f: &F = &*(f as *const F);
183            f(NetworkService::from_glib_borrow(this).unsafe_cast_ref())
184        }
185        unsafe {
186            let f: Box_<F> = Box_::new(f);
187            connect_raw(
188                self.as_ptr() as *mut _,
189                c"notify::scheme".as_ptr() as *const _,
190                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
191                    notify_scheme_trampoline::<Self, F> as *const (),
192                )),
193                Box_::into_raw(f),
194            )
195        }
196    }
197}
198
199impl<O: IsA<NetworkService>> NetworkServiceExt for O {}