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
2011812
#[derive(Clone)]
11
pub struct Session {
12
1005906
    inner: Arc<SessionInner>,
13
}
14

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

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

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

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

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