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 crate::AsyncResult; 6 use crate::Cancellable; 7 use crate::IOStream; 8 use crate::Socket; 9 use crate::SocketAddress; 10 use crate::SocketFamily; 11 use crate::SocketType; 12 use glib::object::IsA; 13 use glib::translate::*; 14 use std::boxed::Box as Box_; 15 use std::fmt; 16 use std::pin::Pin; 17 use std::ptr; 18 19 glib::wrapper! { 20 #[doc(alias = "GSocketConnection")] 21 pub struct SocketConnection(Object<ffi::GSocketConnection, ffi::GSocketConnectionClass>) @extends IOStream; 22 23 match fn { 24 type_ => || ffi::g_socket_connection_get_type(), 25 } 26 } 27 28 impl SocketConnection { 29 #[doc(alias = "g_socket_connection_factory_lookup_type")] factory_lookup_type( family: SocketFamily, type_: SocketType, protocol_id: i32, ) -> glib::types::Type30 pub fn factory_lookup_type( 31 family: SocketFamily, 32 type_: SocketType, 33 protocol_id: i32, 34 ) -> glib::types::Type { 35 unsafe { 36 from_glib(ffi::g_socket_connection_factory_lookup_type( 37 family.into_glib(), 38 type_.into_glib(), 39 protocol_id, 40 )) 41 } 42 } 43 44 #[doc(alias = "g_socket_connection_factory_register_type")] factory_register_type( g_type: glib::types::Type, family: SocketFamily, type_: SocketType, protocol: i32, )45 pub fn factory_register_type( 46 g_type: glib::types::Type, 47 family: SocketFamily, 48 type_: SocketType, 49 protocol: i32, 50 ) { 51 unsafe { 52 ffi::g_socket_connection_factory_register_type( 53 g_type.into_glib(), 54 family.into_glib(), 55 type_.into_glib(), 56 protocol, 57 ); 58 } 59 } 60 } 61 62 pub const NONE_SOCKET_CONNECTION: Option<&SocketConnection> = None; 63 64 pub trait SocketConnectionExt: 'static { 65 #[doc(alias = "g_socket_connection_connect")] connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( &self, address: &P, cancellable: Option<&Q>, ) -> Result<(), glib::Error>66 fn connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( 67 &self, 68 address: &P, 69 cancellable: Option<&Q>, 70 ) -> Result<(), glib::Error>; 71 72 #[doc(alias = "g_socket_connection_connect_async")] connect_async< P: IsA<SocketAddress>, Q: IsA<Cancellable>, R: FnOnce(Result<(), glib::Error>) + Send + 'static, >( &self, address: &P, cancellable: Option<&Q>, callback: R, )73 fn connect_async< 74 P: IsA<SocketAddress>, 75 Q: IsA<Cancellable>, 76 R: FnOnce(Result<(), glib::Error>) + Send + 'static, 77 >( 78 &self, 79 address: &P, 80 cancellable: Option<&Q>, 81 callback: R, 82 ); 83 connect_async_future<P: IsA<SocketAddress> + Clone + 'static>( &self, address: &P, ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>84 fn connect_async_future<P: IsA<SocketAddress> + Clone + 'static>( 85 &self, 86 address: &P, 87 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>; 88 89 #[doc(alias = "g_socket_connection_get_local_address")] 90 #[doc(alias = "get_local_address")] local_address(&self) -> Result<SocketAddress, glib::Error>91 fn local_address(&self) -> Result<SocketAddress, glib::Error>; 92 93 #[doc(alias = "g_socket_connection_get_remote_address")] 94 #[doc(alias = "get_remote_address")] remote_address(&self) -> Result<SocketAddress, glib::Error>95 fn remote_address(&self) -> Result<SocketAddress, glib::Error>; 96 97 #[doc(alias = "g_socket_connection_get_socket")] 98 #[doc(alias = "get_socket")] socket(&self) -> Socket99 fn socket(&self) -> Socket; 100 101 #[doc(alias = "g_socket_connection_is_connected")] is_connected(&self) -> bool102 fn is_connected(&self) -> bool; 103 } 104 105 impl<O: IsA<SocketConnection>> SocketConnectionExt for O { connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( &self, address: &P, cancellable: Option<&Q>, ) -> Result<(), glib::Error>106 fn connect<P: IsA<SocketAddress>, Q: IsA<Cancellable>>( 107 &self, 108 address: &P, 109 cancellable: Option<&Q>, 110 ) -> Result<(), glib::Error> { 111 unsafe { 112 let mut error = ptr::null_mut(); 113 let _ = ffi::g_socket_connection_connect( 114 self.as_ref().to_glib_none().0, 115 address.as_ref().to_glib_none().0, 116 cancellable.map(|p| p.as_ref()).to_glib_none().0, 117 &mut error, 118 ); 119 if error.is_null() { 120 Ok(()) 121 } else { 122 Err(from_glib_full(error)) 123 } 124 } 125 } 126 connect_async< P: IsA<SocketAddress>, Q: IsA<Cancellable>, R: FnOnce(Result<(), glib::Error>) + Send + 'static, >( &self, address: &P, cancellable: Option<&Q>, callback: R, )127 fn connect_async< 128 P: IsA<SocketAddress>, 129 Q: IsA<Cancellable>, 130 R: FnOnce(Result<(), glib::Error>) + Send + 'static, 131 >( 132 &self, 133 address: &P, 134 cancellable: Option<&Q>, 135 callback: R, 136 ) { 137 let user_data: Box_<R> = Box_::new(callback); 138 unsafe extern "C" fn connect_async_trampoline< 139 R: FnOnce(Result<(), glib::Error>) + Send + 'static, 140 >( 141 _source_object: *mut glib::gobject_ffi::GObject, 142 res: *mut crate::ffi::GAsyncResult, 143 user_data: glib::ffi::gpointer, 144 ) { 145 let mut error = ptr::null_mut(); 146 let _ = 147 ffi::g_socket_connection_connect_finish(_source_object as *mut _, res, &mut error); 148 let result = if error.is_null() { 149 Ok(()) 150 } else { 151 Err(from_glib_full(error)) 152 }; 153 let callback: Box_<R> = Box_::from_raw(user_data as *mut _); 154 callback(result); 155 } 156 let callback = connect_async_trampoline::<R>; 157 unsafe { 158 ffi::g_socket_connection_connect_async( 159 self.as_ref().to_glib_none().0, 160 address.as_ref().to_glib_none().0, 161 cancellable.map(|p| p.as_ref()).to_glib_none().0, 162 Some(callback), 163 Box_::into_raw(user_data) as *mut _, 164 ); 165 } 166 } 167 connect_async_future<P: IsA<SocketAddress> + Clone + 'static>( &self, address: &P, ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>168 fn connect_async_future<P: IsA<SocketAddress> + Clone + 'static>( 169 &self, 170 address: &P, 171 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> { 172 let address = address.clone(); 173 Box_::pin(crate::GioFuture::new( 174 self, 175 move |obj, cancellable, send| { 176 obj.connect_async(&address, Some(cancellable), move |res| { 177 send.resolve(res); 178 }); 179 }, 180 )) 181 } 182 local_address(&self) -> Result<SocketAddress, glib::Error>183 fn local_address(&self) -> Result<SocketAddress, glib::Error> { 184 unsafe { 185 let mut error = ptr::null_mut(); 186 let ret = ffi::g_socket_connection_get_local_address( 187 self.as_ref().to_glib_none().0, 188 &mut error, 189 ); 190 if error.is_null() { 191 Ok(from_glib_full(ret)) 192 } else { 193 Err(from_glib_full(error)) 194 } 195 } 196 } 197 remote_address(&self) -> Result<SocketAddress, glib::Error>198 fn remote_address(&self) -> Result<SocketAddress, glib::Error> { 199 unsafe { 200 let mut error = ptr::null_mut(); 201 let ret = ffi::g_socket_connection_get_remote_address( 202 self.as_ref().to_glib_none().0, 203 &mut error, 204 ); 205 if error.is_null() { 206 Ok(from_glib_full(ret)) 207 } else { 208 Err(from_glib_full(error)) 209 } 210 } 211 } 212 socket(&self) -> Socket213 fn socket(&self) -> Socket { 214 unsafe { 215 from_glib_none(ffi::g_socket_connection_get_socket( 216 self.as_ref().to_glib_none().0, 217 )) 218 } 219 } 220 is_connected(&self) -> bool221 fn is_connected(&self) -> bool { 222 unsafe { 223 from_glib(ffi::g_socket_connection_is_connected( 224 self.as_ref().to_glib_none().0, 225 )) 226 } 227 } 228 } 229 230 impl fmt::Display for SocketConnection { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result231 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 232 f.write_str("SocketConnection") 233 } 234 } 235