nm-rs 0.1.3

Rust bindings for the libnm library.
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir
// from gtk-girs (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{Connection, VpnEditor, VpnEditorPluginCapability, ffi};
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
use crate::{VpnEditorPluginVT, VpnPluginInfo};
use glib::{
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    ///
    ///
    /// ## Properties
    ///
    ///
    /// #### `description`
    ///  Longer description of the VPN plugin.
    ///
    /// Readable
    ///
    ///
    /// #### `name`
    ///  Short display name of the VPN plugin.
    ///
    /// Readable
    ///
    ///
    /// #### `service`
    ///  D-Bus service name of the plugin's VPN service.
    ///
    /// Readable
    ///
    /// # Implements
    ///
    /// [`VpnEditorPluginExt`][trait@crate::prelude::VpnEditorPluginExt]
    #[doc(alias = "NMVpnEditorPlugin")]
    pub struct VpnEditorPlugin(Interface<ffi::NMVpnEditorPlugin, ffi::NMVpnEditorPluginInterface>);

    match fn {
        type_ => || ffi::nm_vpn_editor_plugin_get_type(),
    }
}

impl VpnEditorPlugin {
    pub const NONE: Option<&'static VpnEditorPlugin> = None;

    /// Load the shared library @plugin_name and create a new
    /// #NMVpnEditorPlugin instance via the #NMVpnEditorPluginFactory
    /// function.
    ///
    /// This is similar to nm_vpn_editor_plugin_load_from_file(), but
    /// it does no validation of the plugin name, instead passes it directly
    /// to dlopen(). If you have the full path to a plugin file,
    /// nm_vpn_editor_plugin_load_from_file() is preferred.
    /// ## `plugin_name`
    /// The name of the shared library to load.
    ///  This path will be directly passed to dlopen() without
    ///  further checks.
    /// ## `check_service`
    /// if not-null, check that the loaded plugin advertises
    ///  the given service.
    ///
    /// # Returns
    ///
    /// a new plugin instance or [`None`] on error.
    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "nm_vpn_editor_plugin_load")]
    pub fn load(plugin_name: &str, check_service: &str) -> Result<VpnEditorPlugin, glib::Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::nm_vpn_editor_plugin_load(
                plugin_name.to_glib_none().0,
                check_service.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    //#[cfg(feature = "v1_2")]
    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
    //#[doc(alias = "nm_vpn_editor_plugin_load_from_file")]
    //pub fn load_from_file(plugin_name: &str, check_service: &str, check_owner: i32, check_file: /*Unimplemented*/FnMut(&str, /*Unimplemented*/Option<Basic: Pointer>, Option<&glib::Error>) -> bool, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> Result<VpnEditorPlugin, glib::Error> {
    //    unsafe { TODO: call ffi:nm_vpn_editor_plugin_load_from_file() }
    //}
}

/// Trait containing all [`struct@VpnEditorPlugin`] methods.
///
/// # Implementors
///
/// [`VpnEditorPlugin`][struct@crate::VpnEditorPlugin]
pub trait VpnEditorPluginExt: IsA<VpnEditorPlugin> + 'static {
    #[doc(alias = "nm_vpn_editor_plugin_export")]
    fn export(&self, path: &str, connection: &impl IsA<Connection>) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::nm_vpn_editor_plugin_export(
                self.as_ref().to_glib_none().0,
                path.to_glib_none().0,
                connection.as_ref().to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "nm_vpn_editor_plugin_get_capabilities")]
    #[doc(alias = "get_capabilities")]
    fn capabilities(&self) -> VpnEditorPluginCapability {
        unsafe {
            from_glib(ffi::nm_vpn_editor_plugin_get_capabilities(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// ## `connection`
    /// the #NMConnection to be edited
    ///
    /// # Returns
    ///
    /// a new #NMVpnEditor or [`None`] on error
    #[doc(alias = "nm_vpn_editor_plugin_get_editor")]
    #[doc(alias = "get_editor")]
    fn editor(&self, connection: &impl IsA<Connection>) -> Result<VpnEditor, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::nm_vpn_editor_plugin_get_editor(
                self.as_ref().to_glib_none().0,
                connection.as_ref().to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    ///
    /// # Returns
    ///
    /// if set, return the #NMVpnPluginInfo instance.
    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "nm_vpn_editor_plugin_get_plugin_info")]
    #[doc(alias = "get_plugin_info")]
    fn plugin_info(&self) -> VpnPluginInfo {
        unsafe {
            from_glib_none(ffi::nm_vpn_editor_plugin_get_plugin_info(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "nm_vpn_editor_plugin_get_suggested_filename")]
    #[doc(alias = "get_suggested_filename")]
    fn suggested_filename(&self, connection: &impl IsA<Connection>) -> glib::GString {
        unsafe {
            from_glib_full(ffi::nm_vpn_editor_plugin_get_suggested_filename(
                self.as_ref().to_glib_none().0,
                connection.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Returns an opaque VT function table for the plugin to extend
    /// functionality. The actual meaning of NMVpnEditorPluginVT is not
    /// defined in public API of libnm, instead it must be agreed by
    /// both the plugin and the caller. See the header-only file
    /// 'nm-vpn-editor-plugin-call.h' which defines the meaning.
    /// ## `vt_size`
    /// the size of the buffer. Can be 0 to only query the
    ///   size of plugin's VT.
    ///
    /// # Returns
    ///
    /// the actual size of the @self's virtual function table.
    ///
    /// ## `vt`
    /// buffer to be filled with the VT table of the plugin
    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "nm_vpn_editor_plugin_get_vt")]
    #[doc(alias = "get_vt")]
    fn vt(&self, vt_size: usize) -> (usize, VpnEditorPluginVT) {
        unsafe {
            let mut vt = VpnEditorPluginVT::uninitialized();
            let ret = ffi::nm_vpn_editor_plugin_get_vt(
                self.as_ref().to_glib_none().0,
                &mut vt.to_glib_none_mut().0,
                vt_size,
            );
            (ret, vt)
        }
    }

    /// ## `path`
    /// full path to the file to attempt to read into a new #NMConnection
    ///
    /// # Returns
    ///
    /// a new #NMConnection imported from @path, or [`None`]
    /// on error or if the file at @path was not recognized by this plugin
    #[doc(alias = "nm_vpn_editor_plugin_import")]
    fn import(&self, path: &str) -> Result<Connection, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::nm_vpn_editor_plugin_import(
                self.as_ref().to_glib_none().0,
                path.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Set or clear the plugin-info instance.
    /// This takes a weak reference on @plugin_info, to avoid circular
    /// reference as the plugin-info might also reference the editor-plugin.
    /// ## `plugin_info`
    /// a #NMVpnPluginInfo instance or [`None`]
    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "nm_vpn_editor_plugin_set_plugin_info")]
    fn set_plugin_info(&self, plugin_info: Option<&VpnPluginInfo>) {
        unsafe {
            ffi::nm_vpn_editor_plugin_set_plugin_info(
                self.as_ref().to_glib_none().0,
                plugin_info.to_glib_none().0,
            );
        }
    }

    /// Longer description of the VPN plugin.
    fn description(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "description")
    }

    /// Short display name of the VPN plugin.
    fn name(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "name")
    }

    /// D-Bus service name of the plugin's VPN service.
    fn service(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "service")
    }

    #[doc(alias = "description")]
    fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_description_trampoline<
            P: IsA<VpnEditorPlugin>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::NMVpnEditorPlugin,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(VpnEditorPlugin::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::description".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_description_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "name")]
    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_name_trampoline<
            P: IsA<VpnEditorPlugin>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::NMVpnEditorPlugin,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(VpnEditorPlugin::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::name".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_name_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "service")]
    fn connect_service_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_service_trampoline<
            P: IsA<VpnEditorPlugin>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::NMVpnEditorPlugin,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(VpnEditorPlugin::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::service".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_service_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<VpnEditorPlugin>> VpnEditorPluginExt for O {}