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