use browser_window_ffi::*;
use std::ops::Deref;
use std::sync::Arc;
use super::common::*;
#[derive(Clone)]
pub struct Application {
pub inner: Arc<ApplicationInner>
}
#[cfg(feature = "nightly")]
impl !Send for Application {}
#[derive(Clone)]
pub struct ApplicationAsync {
pub inner: Arc<ApplicationInner>
}
#[derive(Clone)]
pub struct ApplicationHandle {
pub _ffi_handle: *mut bw_Application
}
unsafe impl Send for ApplicationHandle {}
unsafe impl Sync for ApplicationHandle {}
pub type ApplicationDispatchFuture<'a,R> = DispatchFuture<'a, ApplicationHandle, R>;
pub struct ApplicationInner {
pub inner: ApplicationHandle
}
impl Application {
pub fn async_clone( &self ) -> ApplicationAsync {
ApplicationAsync {
inner: self.inner.clone()
}
}
pub fn new() -> Self {
let ffi_handle = unsafe { bw_Application_new() };
Self {
inner: Arc::new( ApplicationInner{
inner: ApplicationHandle {
_ffi_handle: ffi_handle
}
} )
}
}
pub fn run( &self ) -> i32 {
unsafe { bw_Application_run( self.inner._ffi_handle ) }
}
}
impl Deref for Application {
type Target = ApplicationHandle;
fn deref( &self ) -> &Self::Target {
&**self.inner
}
}
impl AppHandle for ApplicationHandle {
fn app_handle( &self ) -> ApplicationHandle {
ApplicationHandle {
_ffi_handle: self._ffi_handle
}
}
}
impl ApplicationAsync {
unsafe fn clone_threadunsafe_handle( &self ) -> ApplicationHandle {
ApplicationHandle {
_ffi_handle: (**self.inner)._ffi_handle.clone()
}
}
pub fn dispatch<'a,F,R>( &self, func: F ) -> ApplicationDispatchFuture<'a,R> where
F: FnOnce( ApplicationHandle ) -> R + Send + 'a,
R: Send
{
ApplicationDispatchFuture::<'a,R>::new( unsafe { self.clone_threadunsafe_handle() }, func )
}
pub fn exit( &self, exit_code: u32 ) {
unsafe { bw_Application_exitAsync( self.inner._ffi_handle, exit_code as _ ); }
}
}
impl From<Application> for ApplicationAsync {
fn from( app: Application ) -> Self {
ApplicationAsync {
inner: app.inner
}
}
}
impl ApplicationHandle {
pub fn exit( &self, exit_code: u32 ) {
unsafe { bw_Application_exit( self._ffi_handle, exit_code as _ ); }
}
pub fn from_ptr( ptr: &mut bw_Application ) -> ApplicationHandle {
ApplicationHandle {
_ffi_handle: ptr
}
}
}
impl Deref for ApplicationInner {
type Target = ApplicationHandle;
fn deref( &self ) -> &Self::Target {
&self.inner
}
}
impl Drop for ApplicationInner {
fn drop( &mut self ) {
unsafe { bw_Application_free( self._ffi_handle ) }
}
}