gio/auto/
tls_file_database.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::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::GString;
12use glib::StaticType;
13use glib::Value;
14use glib_sys;
15use gobject_sys;
16use std;
17use std::boxed::Box as Box_;
18use std::fmt;
19use std::mem::transmute;
20use std::ptr;
21use Error;
22use TlsDatabase;
23
24glib_wrapper! {
25    pub struct TlsFileDatabase(Interface<gio_sys::GTlsFileDatabase>) @requires TlsDatabase;
26
27    match fn {
28        get_type => || gio_sys::g_tls_file_database_get_type(),
29    }
30}
31
32impl TlsFileDatabase {
33    pub fn new<P: AsRef<std::path::Path>>(anchors: P) -> Result<TlsFileDatabase, Error> {
34        unsafe {
35            let mut error = ptr::null_mut();
36            let ret =
37                gio_sys::g_tls_file_database_new(anchors.as_ref().to_glib_none().0, &mut error);
38            if error.is_null() {
39                Ok(from_glib_full(ret))
40            } else {
41                Err(from_glib_full(error))
42            }
43        }
44    }
45}
46
47pub const NONE_TLS_FILE_DATABASE: Option<&TlsFileDatabase> = None;
48
49pub trait TlsFileDatabaseExt: 'static {
50    fn get_property_anchors(&self) -> Option<GString>;
51
52    fn set_property_anchors(&self, anchors: Option<&str>);
53
54    fn connect_property_anchors_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
55}
56
57impl<O: IsA<TlsFileDatabase>> TlsFileDatabaseExt for O {
58    fn get_property_anchors(&self) -> Option<GString> {
59        unsafe {
60            let mut value = Value::from_type(<GString as StaticType>::static_type());
61            gobject_sys::g_object_get_property(
62                self.to_glib_none().0 as *mut gobject_sys::GObject,
63                b"anchors\0".as_ptr() as *const _,
64                value.to_glib_none_mut().0,
65            );
66            value.get()
67        }
68    }
69
70    fn set_property_anchors(&self, anchors: Option<&str>) {
71        unsafe {
72            gobject_sys::g_object_set_property(
73                self.to_glib_none().0 as *mut gobject_sys::GObject,
74                b"anchors\0".as_ptr() as *const _,
75                Value::from(anchors).to_glib_none().0,
76            );
77        }
78    }
79
80    fn connect_property_anchors_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
81        unsafe extern "C" fn notify_anchors_trampoline<P, F: Fn(&P) + 'static>(
82            this: *mut gio_sys::GTlsFileDatabase,
83            _param_spec: glib_sys::gpointer,
84            f: glib_sys::gpointer,
85        ) where
86            P: IsA<TlsFileDatabase>,
87        {
88            let f: &F = &*(f as *const F);
89            f(&TlsFileDatabase::from_glib_borrow(this).unsafe_cast())
90        }
91        unsafe {
92            let f: Box_<F> = Box_::new(f);
93            connect_raw(
94                self.as_ptr() as *mut _,
95                b"notify::anchors\0".as_ptr() as *const _,
96                Some(transmute(notify_anchors_trampoline::<Self, F> as usize)),
97                Box_::into_raw(f),
98            )
99        }
100    }
101}
102
103impl fmt::Display for TlsFileDatabase {
104    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
105        write!(f, "TlsFileDatabase")
106    }
107}