// by Diplomat
#pragma warning disable 0105
using System;
using System.Runtime.InteropServices;
using Devolutions.IronRdp.Diplomat;
#pragma warning restore 0105
namespace Devolutions.IronRdp;
#nullable enable
public partial class DynState: IDisposable
{
private unsafe Raw.DynState* _inner;
public string Name
{
get
{
return GetName();
}
}
///
/// Creates a managed DynState from a raw handle.
///
///
/// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free).
///
/// This constructor assumes the raw struct is allocated on Rust side.
/// If implemented, the custom Drop implementation on Rust side WILL run on destruction.
///
public unsafe DynState(Raw.DynState* handle)
{
_inner = handle;
}
///
public void GetName(DiplomatWriteable writeable)
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DynState");
}
Raw.ConnectorFfiResultVoidBoxIronRdpError result = Raw.DynState.GetName(_inner, &writeable);
if (!result.isOk)
{
throw new IronRdpException(new IronRdpError(result.Err));
}
}
}
///
public string GetName()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DynState");
}
DiplomatWriteable writeable = new DiplomatWriteable();
Raw.ConnectorFfiResultVoidBoxIronRdpError result = Raw.DynState.GetName(_inner, &writeable);
if (!result.isOk)
{
throw new IronRdpException(new IronRdpError(result.Err));
}
string retVal = writeable.ToUnicode();
writeable.Dispose();
return retVal;
}
}
public bool IsTerminal()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DynState");
}
bool retVal = Raw.DynState.IsTerminal(_inner);
return retVal;
}
}
///
/// Returns the underlying raw handle.
///
public unsafe Raw.DynState* AsFFI()
{
return _inner;
}
///
/// Destroys the underlying object immediately.
///
public void Dispose()
{
unsafe
{
if (_inner == null)
{
return;
}
Raw.DynState.Destroy(_inner);
_inner = null;
GC.SuppressFinalize(this);
}
}
~DynState()
{
Dispose();
}
}