gio/auto/
socket_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, SocketConnection, SocketListener};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GSocketService")]
16    pub struct SocketService(Object<ffi::GSocketService, ffi::GSocketServiceClass>) @extends SocketListener;
17
18    match fn {
19        type_ => || ffi::g_socket_service_get_type(),
20    }
21}
22
23impl SocketService {
24    pub const NONE: Option<&'static SocketService> = None;
25
26    #[doc(alias = "g_socket_service_new")]
27    pub fn new() -> SocketService {
28        unsafe { from_glib_full(ffi::g_socket_service_new()) }
29    }
30}
31
32impl Default for SocketService {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37
38pub trait SocketServiceExt: IsA<SocketService> + 'static {
39    #[doc(alias = "g_socket_service_is_active")]
40    #[doc(alias = "active")]
41    fn is_active(&self) -> bool {
42        unsafe {
43            from_glib(ffi::g_socket_service_is_active(
44                self.as_ref().to_glib_none().0,
45            ))
46        }
47    }
48
49    #[doc(alias = "g_socket_service_start")]
50    fn start(&self) {
51        unsafe {
52            ffi::g_socket_service_start(self.as_ref().to_glib_none().0);
53        }
54    }
55
56    #[doc(alias = "g_socket_service_stop")]
57    fn stop(&self) {
58        unsafe {
59            ffi::g_socket_service_stop(self.as_ref().to_glib_none().0);
60        }
61    }
62
63    fn set_active(&self, active: bool) {
64        ObjectExt::set_property(self.as_ref(), "active", active)
65    }
66
67    #[doc(alias = "incoming")]
68    fn connect_incoming<
69        F: Fn(&Self, &SocketConnection, Option<&glib::Object>) -> bool + 'static,
70    >(
71        &self,
72        f: F,
73    ) -> SignalHandlerId {
74        unsafe extern "C" fn incoming_trampoline<
75            P: IsA<SocketService>,
76            F: Fn(&P, &SocketConnection, Option<&glib::Object>) -> bool + 'static,
77        >(
78            this: *mut ffi::GSocketService,
79            connection: *mut ffi::GSocketConnection,
80            source_object: *mut glib::gobject_ffi::GObject,
81            f: glib::ffi::gpointer,
82        ) -> glib::ffi::gboolean {
83            let f: &F = &*(f as *const F);
84            f(
85                SocketService::from_glib_borrow(this).unsafe_cast_ref(),
86                &from_glib_borrow(connection),
87                Option::<glib::Object>::from_glib_borrow(source_object)
88                    .as_ref()
89                    .as_ref(),
90            )
91            .into_glib()
92        }
93        unsafe {
94            let f: Box_<F> = Box_::new(f);
95            connect_raw(
96                self.as_ptr() as *mut _,
97                c"incoming".as_ptr() as *const _,
98                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
99                    incoming_trampoline::<Self, F> as *const (),
100                )),
101                Box_::into_raw(f),
102            )
103        }
104    }
105
106    #[doc(alias = "active")]
107    fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
108        unsafe extern "C" fn notify_active_trampoline<
109            P: IsA<SocketService>,
110            F: Fn(&P) + 'static,
111        >(
112            this: *mut ffi::GSocketService,
113            _param_spec: glib::ffi::gpointer,
114            f: glib::ffi::gpointer,
115        ) {
116            let f: &F = &*(f as *const F);
117            f(SocketService::from_glib_borrow(this).unsafe_cast_ref())
118        }
119        unsafe {
120            let f: Box_<F> = Box_::new(f);
121            connect_raw(
122                self.as_ptr() as *mut _,
123                c"notify::active".as_ptr() as *const _,
124                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
125                    notify_active_trampoline::<Self, F> as *const (),
126                )),
127                Box_::into_raw(f),
128            )
129        }
130    }
131}
132
133impl<O: IsA<SocketService>> SocketServiceExt for O {}