gio/auto/memory_monitor.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 crate::{Initable, MemoryMonitorWarningLevel, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// t forget to disconnect the [`low-memory-warning`][struct@crate::MemoryMonitor#low-memory-warning]
16 /// signal, and unref the `GMemoryMonitor` itself when exiting.
17 ///
18 /// ## Signals
19 ///
20 ///
21 /// #### `low-memory-warning`
22 /// Emitted when the system is running low on free memory.
23 ///
24 /// The signal
25 /// handler should then take the appropriate action depending on the
26 /// warning level. See the #GMemoryMonitorWarningLevel documentation for
27 /// details.
28 ///
29 /// Since the [`MemoryMonitor`][crate::MemoryMonitor] is a singleton, this signal will be
30 /// emitted in the [`glib::MainContext::default()`][crate::glib::MainContext::default()][global-default main
31 /// context].
32 ///
33 ///
34 ///
35 /// # Implements
36 ///
37 /// [`MemoryMonitorExt`][trait@crate::prelude::MemoryMonitorExt], [`InitableExt`][trait@crate::prelude::InitableExt]
38 #[doc(alias = "GMemoryMonitor")]
39 pub struct MemoryMonitor(Interface<ffi::GMemoryMonitor, ffi::GMemoryMonitorInterface>) @requires Initable;
40
41 match fn {
42 type_ => || ffi::g_memory_monitor_get_type(),
43 }
44}
45
46impl MemoryMonitor {
47 pub const NONE: Option<&'static MemoryMonitor> = None;
48
49 /// Gets a reference to the default #GMemoryMonitor for the system.
50 ///
51 /// # Returns
52 ///
53 /// a new reference to the default #GMemoryMonitor
54 #[doc(alias = "g_memory_monitor_dup_default")]
55 pub fn dup_default() -> MemoryMonitor {
56 unsafe { from_glib_full(ffi::g_memory_monitor_dup_default()) }
57 }
58}
59
60/// Trait containing all [`struct@MemoryMonitor`] methods.
61///
62/// # Implementors
63///
64/// [`MemoryMonitor`][struct@crate::MemoryMonitor]
65pub trait MemoryMonitorExt: IsA<MemoryMonitor> + 'static {
66 /// Emitted when the system is running low on free memory.
67 ///
68 /// The signal
69 /// handler should then take the appropriate action depending on the
70 /// warning level. See the #GMemoryMonitorWarningLevel documentation for
71 /// details.
72 ///
73 /// Since the [`MemoryMonitor`][crate::MemoryMonitor] is a singleton, this signal will be
74 /// emitted in the [`glib::MainContext::default()`][crate::glib::MainContext::default()][global-default main
75 /// context].
76 /// ## `level`
77 /// the #GMemoryMonitorWarningLevel warning level
78 #[cfg(feature = "v2_64")]
79 #[cfg_attr(docsrs, doc(cfg(feature = "v2_64")))]
80 #[doc(alias = "low-memory-warning")]
81 fn connect_low_memory_warning<F: Fn(&Self, MemoryMonitorWarningLevel) + 'static>(
82 &self,
83 f: F,
84 ) -> SignalHandlerId {
85 unsafe extern "C" fn low_memory_warning_trampoline<
86 P: IsA<MemoryMonitor>,
87 F: Fn(&P, MemoryMonitorWarningLevel) + 'static,
88 >(
89 this: *mut ffi::GMemoryMonitor,
90 level: ffi::GMemoryMonitorWarningLevel,
91 f: glib::ffi::gpointer,
92 ) {
93 unsafe {
94 let f: &F = &*(f as *const F);
95 f(
96 MemoryMonitor::from_glib_borrow(this).unsafe_cast_ref(),
97 from_glib(level),
98 )
99 }
100 }
101 unsafe {
102 let f: Box_<F> = Box_::new(f);
103 connect_raw(
104 self.as_ptr() as *mut _,
105 c"low-memory-warning".as_ptr(),
106 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
107 low_memory_warning_trampoline::<Self, F> as *const (),
108 )),
109 Box_::into_raw(f),
110 )
111 }
112 }
113}
114
115impl<O: IsA<MemoryMonitor>> MemoryMonitorExt for O {}