use crate::{lldb_pid_t, sys, SBFileSpec};
use std::ffi::CStr;
#[derive(Debug)]
pub struct SBProcessInfo {
pub raw: sys::SBProcessInfoRef,
}
impl SBProcessInfo {
pub(crate) fn wrap(raw: sys::SBProcessInfoRef) -> SBProcessInfo {
SBProcessInfo { raw }
}
#[allow(missing_docs)]
pub fn name(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBProcessInfoGetName(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
#[allow(missing_docs)]
pub fn executable_file(&self) -> SBFileSpec {
SBFileSpec::wrap(unsafe { sys::SBProcessInfoGetExecutableFile(self.raw) })
}
#[allow(missing_docs)]
pub fn process_id(&self) -> lldb_pid_t {
unsafe { sys::SBProcessInfoGetProcessID(self.raw) }
}
#[allow(missing_docs)]
pub fn user_id(&self) -> Option<u32> {
if unsafe { sys::SBProcessInfoUserIDIsValid(self.raw) } {
Some(unsafe { sys::SBProcessInfoGetUserID(self.raw) })
} else {
None
}
}
#[allow(missing_docs)]
pub fn group_id(&self) -> Option<u32> {
if unsafe { sys::SBProcessInfoGroupIDIsValid(self.raw) } {
Some(unsafe { sys::SBProcessInfoGetGroupID(self.raw) })
} else {
None
}
}
#[allow(missing_docs)]
pub fn effective_user_id(&self) -> Option<u32> {
if unsafe { sys::SBProcessInfoEffectiveUserIDIsValid(self.raw) } {
Some(unsafe { sys::SBProcessInfoGetEffectiveUserID(self.raw) })
} else {
None
}
}
#[allow(missing_docs)]
pub fn effective_group_id(&self) -> Option<u32> {
if unsafe { sys::SBProcessInfoEffectiveGroupIDIsValid(self.raw) } {
Some(unsafe { sys::SBProcessInfoGetEffectiveGroupID(self.raw) })
} else {
None
}
}
#[allow(missing_docs)]
pub fn parent_process_id(&self) -> lldb_pid_t {
unsafe { sys::SBProcessInfoGetParentProcessID(self.raw) }
}
pub fn triple(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBProcessInfoGetTriple(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
}
impl Clone for SBProcessInfo {
fn clone(&self) -> SBProcessInfo {
SBProcessInfo {
raw: unsafe { sys::CloneSBProcessInfo(self.raw) },
}
}
}
impl Drop for SBProcessInfo {
fn drop(&mut self) {
unsafe { sys::DisposeSBProcessInfo(self.raw) };
}
}
unsafe impl Send for SBProcessInfo {}
unsafe impl Sync for SBProcessInfo {}
#[cfg(feature = "graphql")]
#[juniper::graphql_object]
impl SBProcessInfo {
fn name() -> &str {
self.name()
}
fn executable_file() -> SBFileSpec {
self.executable_file()
}
fn process_id() -> i32 {
self.process_id() as i32
}
fn user_id() -> Option<i32> {
self.user_id().map(|i| i as i32)
}
fn group_id() -> Option<i32> {
self.group_id().map(|i| i as i32)
}
fn effective_user_id() -> Option<i32> {
self.effective_user_id().map(|i| i as i32)
}
fn effective_group_id() -> Option<i32> {
self.effective_group_id().map(|i| i as i32)
}
fn parent_process_id() -> i32 {
self.parent_process_id() as i32
}
fn triple() -> &str {
self.triple()
}
}