dmsc/java/classes/
log.rs

1//! Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
2//!
3//! This file is part of DMSC.
4//! The DMSC project belongs to the Dunimd Team.
5//!
6//! Licensed under the Apache License, Version 2.0 (the "License");
7//! You may not use this file except in compliance with the License.
8//! You may obtain a copy of the License at
9//!
10//!     http://www.apache.org/licenses/LICENSE-2.0
11//!
12//! Unless required by applicable law or agreed to in writing, software
13//! distributed under the License is distributed on an "AS IS" BASIS,
14//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15//! See the License for the specific language governing permissions and
16//! limitations under the License.
17
18//! # Log Module JNI Bindings
19//!
20//! JNI bindings for DMSC log classes.
21
22use jni::JNIEnv;
23use jni::objects::JClass;
24use jni::sys::jlong;
25use crate::log::{DMSCLogger, DMSCLogConfig};
26use crate::fs::DMSCFileSystem;
27
28#[no_mangle]
29pub extern "system" fn Java_com_dunimd_dmsc_log_DMSCLogger_new0(
30    _env: JNIEnv,
31    _class: JClass,
32) -> jlong {
33    let config = DMSCLogConfig::default();
34    let fs = DMSCFileSystem::new_auto_root().unwrap_or_else(|_| DMSCFileSystem::new_with_root(std::env::current_dir().unwrap_or_default()));
35    let logger = Box::new(DMSCLogger::new(&config, fs));
36    Box::into_raw(logger) as jlong
37}
38
39#[no_mangle]
40pub extern "system" fn Java_com_dunimd_dmsc_log_DMSCLogger_free0(
41    _env: JNIEnv,
42    _class: JClass,
43    ptr: jlong,
44) {
45    if ptr != 0 {
46        unsafe {
47            let _ = Box::from_raw(ptr as *mut DMSCLogger);
48        }
49    }
50}