#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Deserialize, Serialize)]
#[repr(transparent)]
pub struct ThreadName(CommandName);
impl Display for ThreadName
{
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
{
write!(f, "{}", self.0)
}
}
impl From<CommandName> for ThreadName
{
#[inline(always)]
fn from(value: CommandName) -> Self
{
Self(value)
}
}
impl From<ObjectName16> for ThreadName
{
#[inline(always)]
fn from(value: ObjectName16) -> Self
{
Self::from(CommandName::from(value))
}
}
impl Into<CommandName> for ThreadName
{
#[inline(always)]
fn into(self) -> CommandName
{
self.0
}
}
impl Into<ObjectName16> for ThreadName
{
#[inline(always)]
fn into(self) -> ObjectName16
{
(self.0).into()
}
}
impl Deref for ThreadName
{
type Target = CommandName;
#[inline(always)]
fn deref(&self) -> &Self::Target
{
&self.0
}
}
impl Default for ThreadName
{
#[inline(always)]
fn default() -> Self
{
Self(CommandName::from(ObjectName16::from_bytes(b"unnamed").unwrap()))
}
}
impl ThreadName
{
#[inline(always)]
pub fn get_current_thread_name() -> Self
{
let object_name = ObjectName16::construct_from_c_function_call
(
|buffer| process_control_wrapper2(PR_GET_NAME, buffer.as_mut_ptr() as usize,result_must_be_zero, error_number_to_io_error),
|| io_error_other("DoesNotEndWithAsciiNulError")
).expect("No good reason to fail");
Self(CommandName::from(object_name))
}
#[inline(always)]
pub fn set_current_thread_name(&self) -> Result<(), Errno>
{
let pointer = self.0.as_ptr();
process_control_wrapper2(PR_SET_NAME,pointer as usize,result_must_be_zero, Err)
}
#[inline(always)]
pub fn set_thread_name(&self, process_identifier: ProcessIdentifierChoice, thread_identifier: ThreadIdentifier, proc_path: &ProcPath) -> io::Result<()>
{
let file_path = proc_path.process_thread_file_path(process_identifier, thread_identifier, "comm");
self.0.write_to_file_line_feed_terminated(&file_path)
}
#[inline(always)]
pub fn get_thread_name(process_identifier: ProcessIdentifierChoice, thread_identifier: ThreadIdentifier, proc_path: &ProcPath) -> io::Result<Self>
{
let file_path = proc_path.process_thread_file_path(process_identifier, thread_identifier, "comm");
CommandName::read_from_file_line_feed_terminated(&file_path).map(|object_name| Self(object_name))
}
}