1
//! Tracks metadata for a loading/rendering session.
2

            
3
use std::sync::Arc;
4

            
5
/// Metadata for a loading/rendering session.
6
///
7
/// When the calling program first uses one of the API entry points (e.g. `Loader::new()`
8
/// in the Rust API, or `rsvg_handle_new()` in the C API), there is no context yet where
9
/// librsvg's code may start to track things.  This struct provides that context.
10
2011642
#[derive(Clone)]
11
pub struct Session {
12
1005821
    inner: Arc<SessionInner>,
13
}
14

            
15
struct SessionInner {
16
    log_enabled: bool,
17
}
18

            
19
1242
fn log_enabled_via_env_var() -> bool {
20
1242
    ::std::env::var_os("RSVG_LOG").is_some()
21
1242
}
22

            
23
impl Default for Session {
24
1225
    fn default() -> Self {
25
        Self {
26
1225
            inner: Arc::new(SessionInner {
27
1225
                log_enabled: log_enabled_via_env_var(),
28
            }),
29
        }
30
1225
    }
31
}
32

            
33
impl Session {
34
    #[cfg(test)]
35
6
    pub fn new_for_test_suite() -> Self {
36
        Self {
37
6
            inner: Arc::new(SessionInner { log_enabled: false }),
38
        }
39
6
    }
40

            
41
3921563
    pub fn log_enabled(&self) -> bool {
42
3921563
        self.inner.log_enabled
43
3921563
    }
44
}