jvmti_rs/wrapper/jvmtifns/
general.rs

1use std::{
2    ffi::c_void,
3    ptr,
4};
5
6use crate::{errors::*, JVMTIEnv, JvmtiError, JvmtiJlocationFormat, JvmtiPhase, JvmtiVerboseFlag, objects::*, sys::*, to_jboolean};
7
8impl<'a> JVMTIEnv<'a> {
9    pub fn dispose_environment(&self) -> Result<()> {
10        jvmti_call!(self.jvmti_raw(), DisposeEnvironment)
11    }
12
13    pub fn get_version_number(&self) -> Result<jint> {
14        Ok(jvmti_call_number_result!(self.jvmti_raw(), jint,
15            GetVersionNumber
16        ))
17    }
18
19    pub fn get_error_name(&self, error: JvmtiError) -> Result<String> {
20        let mut name = ptr::null_mut();
21        let err: jvmtiError = error.into();
22        let res = jvmti_call_result!(self.jvmti_raw(), GetErrorName,
23            err,
24            &mut name
25        );
26        jvmti_error_code_to_result(res)?;
27        Ok(self.build_string(name)?.into())
28    }
29
30    pub fn get_environment_local_storage(&self) -> Result<JLocalStorage> {
31        let mut data_ptr: *mut c_void = ptr::null_mut() as *mut c_void;
32        let res = jvmti_call_result!(self.jvmti_raw(), GetEnvironmentLocalStorage,
33            &mut data_ptr
34        );
35        jvmti_error_code_to_result(res)?;
36        Ok(JLocalStorage::new(data_ptr))
37    }
38
39    pub fn set_environment_local_storage(&self, data: &JLocalStorage) -> Result<()> {
40        jvmti_call!(self.jvmti_raw(), SetEnvironmentLocalStorage,
41            data.as_ptr()
42        )
43    }
44
45    pub fn set_verbose_flag(&self, flag: JvmtiVerboseFlag, value: bool) -> Result<()> {
46        jvmti_call!(self.jvmti_raw(), SetVerboseFlag,
47            flag.into(),
48            to_jboolean(value)
49        )
50    }
51
52    pub fn get_jlocation_format(&self) -> Result<JvmtiJlocationFormat> {
53        let res = jvmti_call_number_result!(self.jvmti_raw(), jvmtiJlocationFormat,
54            GetJLocationFormat
55        );
56        Ok(res.into())
57    }
58
59    pub fn get_phase(&self) -> Result<JvmtiPhase> {
60        let res = jvmti_call_number_result!(self.jvmti_raw(), jvmtiPhase,
61            GetPhase
62        );
63        Ok(res.into())
64    }
65}