summaryrefslogtreecommitdiff
path: root/rsvg/src/session.rs
diff options
context:
space:
mode:
authorMarge Bot <marge-bot@gnome.org>2023-04-25 23:30:10 +0000
committerMarge Bot <marge-bot@gnome.org>2023-04-25 23:30:10 +0000
commit30567b3eac0148e3e95f5dd011ff76bda5000a99 (patch)
tree7d5c56dc2b20f91ccc77aee4dad07830e7eb429a /rsvg/src/session.rs
parentd597831ff93b09cc41ce4768a833bc6407c95184 (diff)
parent7608c94036d7a44296a7e135f42e84aed20afeb7 (diff)
downloadlibrsvg-30567b3eac0148e3e95f5dd011ff76bda5000a99.tar.gz
Merge branch 'wip/sophie-h/workspace' into 'main'
meta: Move lib and bins into separate crates Closes #950 See merge request GNOME/librsvg!822
Diffstat (limited to 'rsvg/src/session.rs')
-rw-r--r--rsvg/src/session.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/rsvg/src/session.rs b/rsvg/src/session.rs
new file mode 100644
index 00000000..fe556cef
--- /dev/null
+++ b/rsvg/src/session.rs
@@ -0,0 +1,44 @@
+//! Tracks metadata for a loading/rendering session.
+
+use std::sync::Arc;
+
+/// Metadata for a loading/rendering session.
+///
+/// When the calling program first uses one of the API entry points (e.g. `Loader::new()`
+/// in the Rust API, or `rsvg_handle_new()` in the C API), there is no context yet where
+/// librsvg's code may start to track things. This struct provides that context.
+#[derive(Clone)]
+pub struct Session {
+ inner: Arc<SessionInner>,
+}
+
+struct SessionInner {
+ log_enabled: bool,
+}
+
+fn log_enabled_via_env_var() -> bool {
+ ::std::env::var_os("RSVG_LOG").is_some()
+}
+
+impl Default for Session {
+ fn default() -> Self {
+ Self {
+ inner: Arc::new(SessionInner {
+ log_enabled: log_enabled_via_env_var(),
+ }),
+ }
+ }
+}
+
+impl Session {
+ #[cfg(test)]
+ pub fn new_for_test_suite() -> Self {
+ Self {
+ inner: Arc::new(SessionInner { log_enabled: false }),
+ }
+ }
+
+ pub fn log_enabled(&self) -> bool {
+ self.inner.log_enabled
+ }
+}