gio/auto/
threaded_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 gio_sys;
6use glib;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib::StaticType;
13use glib::Value;
14use glib_sys;
15use gobject_sys;
16use std::boxed::Box as Box_;
17use std::fmt;
18use std::mem::transmute;
19use SocketConnection;
20use SocketListener;
21use SocketService;
22
23glib_wrapper! {
24    pub struct ThreadedSocketService(Object<gio_sys::GThreadedSocketService, gio_sys::GThreadedSocketServiceClass, ThreadedSocketServiceClass>) @extends SocketService, SocketListener;
25
26    match fn {
27        get_type => || gio_sys::g_threaded_socket_service_get_type(),
28    }
29}
30
31impl ThreadedSocketService {
32    pub fn new(max_threads: i32) -> ThreadedSocketService {
33        unsafe {
34            SocketService::from_glib_full(gio_sys::g_threaded_socket_service_new(max_threads))
35                .unsafe_cast()
36        }
37    }
38}
39
40pub const NONE_THREADED_SOCKET_SERVICE: Option<&ThreadedSocketService> = None;
41
42pub trait ThreadedSocketServiceExt: 'static {
43    fn get_property_max_threads(&self) -> i32;
44
45    fn connect_run<F: Fn(&Self, &SocketConnection, &glib::Object) -> bool + 'static>(
46        &self,
47        f: F,
48    ) -> SignalHandlerId;
49}
50
51impl<O: IsA<ThreadedSocketService>> ThreadedSocketServiceExt for O {
52    fn get_property_max_threads(&self) -> i32 {
53        unsafe {
54            let mut value = Value::from_type(<i32 as StaticType>::static_type());
55            gobject_sys::g_object_get_property(
56                self.to_glib_none().0 as *mut gobject_sys::GObject,
57                b"max-threads\0".as_ptr() as *const _,
58                value.to_glib_none_mut().0,
59            );
60            value.get().unwrap()
61        }
62    }
63
64    fn connect_run<F: Fn(&Self, &SocketConnection, &glib::Object) -> bool + 'static>(
65        &self,
66        f: F,
67    ) -> SignalHandlerId {
68        unsafe extern "C" fn run_trampoline<
69            P,
70            F: Fn(&P, &SocketConnection, &glib::Object) -> bool + 'static,
71        >(
72            this: *mut gio_sys::GThreadedSocketService,
73            connection: *mut gio_sys::GSocketConnection,
74            source_object: *mut gobject_sys::GObject,
75            f: glib_sys::gpointer,
76        ) -> glib_sys::gboolean
77        where
78            P: IsA<ThreadedSocketService>,
79        {
80            let f: &F = &*(f as *const F);
81            f(
82                &ThreadedSocketService::from_glib_borrow(this).unsafe_cast(),
83                &from_glib_borrow(connection),
84                &from_glib_borrow(source_object),
85            )
86            .to_glib()
87        }
88        unsafe {
89            let f: Box_<F> = Box_::new(f);
90            connect_raw(
91                self.as_ptr() as *mut _,
92                b"run\0".as_ptr() as *const _,
93                Some(transmute(run_trampoline::<Self, F> as usize)),
94                Box_::into_raw(f),
95            )
96        }
97    }
98}
99
100impl fmt::Display for ThreadedSocketService {
101    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
102        write!(f, "ThreadedSocketService")
103    }
104}