1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::ffi;
use glib::{prelude::*, translate::*};

glib::wrapper! {
    ///
    ///
    /// # Implements
    ///
    /// [`InstanceExt`][trait@crate::prelude::InstanceExt]
    #[doc(alias = "FlatpakInstance")]
    pub struct Instance(Object<ffi::FlatpakInstance, ffi::FlatpakInstanceClass>);

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

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

    /// Gets FlatpakInstance objects for all running sandboxes in the current session.
    ///
    /// # Returns
    ///
    /// a [`glib::PtrArray`][crate::glib::PtrArray] of
    ///  [`Instance`][crate::Instance] objects
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_all")]
    #[doc(alias = "get_all")]
    pub fn all() -> Vec<Instance> {
        assert_initialized_main_thread!();
        unsafe { FromGlibPtrContainer::from_glib_full(ffi::flatpak_instance_get_all()) }
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Instance>> Sealed for T {}
}

/// Trait containing all [`struct@Instance`] methods.
///
/// # Implementors
///
/// [`Instance`][struct@crate::Instance]
pub trait InstanceExt: IsA<Instance> + sealed::Sealed + 'static {
    /// Gets the application ID of the application running in the instance.
    ///
    /// Note that this may return [`None`] for sandboxes that don't have an application.
    ///
    /// # Returns
    ///
    /// the application ID or [`None`]
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_app")]
    #[doc(alias = "get_app")]
    fn app(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::flatpak_instance_get_app(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the architecture of the application running in the instance.
    ///
    /// # Returns
    ///
    /// the architecture
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_arch")]
    #[doc(alias = "get_arch")]
    fn arch(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::flatpak_instance_get_arch(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the branch of the application running in the instance.
    ///
    /// # Returns
    ///
    /// the architecture
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_branch")]
    #[doc(alias = "get_branch")]
    fn branch(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::flatpak_instance_get_branch(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the PID of the application process in the sandbox.
    ///
    /// See [`pid()`][Self::pid()].
    ///
    /// Note that this function may return 0 immediately after launching
    /// a sandbox, for a short amount of time.
    ///
    /// # Returns
    ///
    /// the application process PID
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_child_pid")]
    #[doc(alias = "get_child_pid")]
    fn child_pid(&self) -> i32 {
        unsafe { ffi::flatpak_instance_get_child_pid(self.as_ref().to_glib_none().0) }
    }

    /// Gets the commit of the application running in the instance.
    ///
    /// # Returns
    ///
    /// the commit
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_commit")]
    #[doc(alias = "get_commit")]
    fn commit(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::flatpak_instance_get_commit(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the instance ID. The ID is used by Flatpak for bookkeeping
    /// purposes and has no further relevance.
    ///
    /// # Returns
    ///
    /// the instance ID
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_id")]
    #[doc(alias = "get_id")]
    fn id(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::flatpak_instance_get_id(self.as_ref().to_glib_none().0)) }
    }

    /// Gets a keyfile that holds information about the running sandbox.
    ///
    /// This file is available as /.flatpak-info inside the sandbox as well.
    ///
    /// The most important data in the keyfile is available with separate getters,
    /// but there may be more information in the keyfile.
    ///
    /// # Returns
    ///
    /// the flatpak-info keyfile
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_info")]
    #[doc(alias = "get_info")]
    fn info(&self) -> Option<glib::KeyFile> {
        unsafe {
            from_glib_full(ffi::flatpak_instance_get_info(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the PID of the outermost process in the sandbox. This is not the
    /// application process itself, but a bubblewrap 'babysitter' process.
    ///
    /// See [`child_pid()`][Self::child_pid()].
    ///
    /// # Returns
    ///
    /// the outermost process PID
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_pid")]
    #[doc(alias = "get_pid")]
    fn pid(&self) -> i32 {
        unsafe { ffi::flatpak_instance_get_pid(self.as_ref().to_glib_none().0) }
    }

    /// Gets the ref of the runtime used in the instance.
    ///
    /// # Returns
    ///
    /// the runtime ref
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_runtime")]
    #[doc(alias = "get_runtime")]
    fn runtime(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::flatpak_instance_get_runtime(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the commit of the runtime used in the instance.
    ///
    /// # Returns
    ///
    /// the runtime commit
    #[cfg(feature = "v1_1")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
    #[doc(alias = "flatpak_instance_get_runtime_commit")]
    #[doc(alias = "get_runtime_commit")]
    fn runtime_commit(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::flatpak_instance_get_runtime_commit(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Finds out if the sandbox represented by `self` is still running.
    ///
    /// # Returns
    ///
    /// [`true`] if the sandbox is still running
    #[doc(alias = "flatpak_instance_is_running")]
    fn is_running(&self) -> bool {
        unsafe {
            from_glib(ffi::flatpak_instance_is_running(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<Instance>> InstanceExt for O {}