use crate::{lldb_pid_t, sys, SBError, SBLaunchInfo};
use std::ffi::CStr;
#[derive(Debug)]
pub struct SBPlatform {
pub raw: sys::SBPlatformRef,
}
impl SBPlatform {
pub(crate) fn wrap(raw: sys::SBPlatformRef) -> SBPlatform {
SBPlatform { raw }
}
#[allow(dead_code)]
pub(crate) fn maybe_wrap(raw: sys::SBPlatformRef) -> Option<SBPlatform> {
if unsafe { sys::SBPlatformIsValid(raw) } {
Some(SBPlatform { raw })
} else {
None
}
}
pub fn is_valid(&self) -> bool {
unsafe { sys::SBPlatformIsValid(self.raw) }
}
#[allow(missing_docs)]
pub fn get_host_platform() -> SBPlatform {
SBPlatform::wrap(unsafe { sys::SBPlatformGetHostPlatform() })
}
pub fn working_directory(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBPlatformGetWorkingDirectory(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn name(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBPlatformGetName(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn triple(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBPlatformGetTriple(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn hostname(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBPlatformGetHostname(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn os_build(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBPlatformGetOSBuild(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn os_description(&self) -> &str {
unsafe {
match CStr::from_ptr(sys::SBPlatformGetOSDescription(self.raw)).to_str() {
Ok(s) => s,
_ => panic!("Invalid string?"),
}
}
}
pub fn os_major_version(&self) -> u32 {
unsafe { sys::SBPlatformGetOSMajorVersion(self.raw) }
}
pub fn os_minor_version(&self) -> u32 {
unsafe { sys::SBPlatformGetOSMinorVersion(self.raw) }
}
pub fn os_update_version(&self) -> u32 {
unsafe { sys::SBPlatformGetOSUpdateVersion(self.raw) }
}
pub fn launch(&self, launch_info: &SBLaunchInfo) -> Result<(), SBError> {
let error = SBError::wrap(unsafe { sys::SBPlatformLaunch(self.raw, launch_info.raw) });
if error.is_success() {
Ok(())
} else {
Err(error)
}
}
pub fn kill(&self, pid: lldb_pid_t) -> Result<(), SBError> {
let error = SBError::wrap(unsafe { sys::SBPlatformKill(self.raw, pid) });
if error.is_success() {
Ok(())
} else {
Err(error)
}
}
}
impl Clone for SBPlatform {
fn clone(&self) -> SBPlatform {
SBPlatform {
raw: unsafe { sys::CloneSBPlatform(self.raw) },
}
}
}
impl Drop for SBPlatform {
fn drop(&mut self) {
unsafe { sys::DisposeSBPlatform(self.raw) };
}
}
unsafe impl Send for SBPlatform {}
unsafe impl Sync for SBPlatform {}
#[cfg(feature = "graphql")]
#[graphql_object]
impl SBPlatform {
fn working_directory() -> &str {
self.working_directory()
}
fn name() -> &str {
self.name()
}
fn triple() -> &str {
self.triple()
}
fn hostname() -> &str {
self.hostname()
}
fn os_build() -> &str {
self.os_build()
}
fn os_description() -> &str {
self.os_description()
}
fn os_major_version() -> i32 {
self.os_major_version() as i32
}
fn os_minor_version() -> i32 {
self.os_minor_version() as i32
}
fn os_update_version() -> i32 {
self.os_update_version() as i32
}
}