// 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 GeneratorState: IDisposable
{
private unsafe Raw.GeneratorState* _inner;
public ClientState ClientStateIfCompleted
{
get
{
return GetClientStateIfCompleted();
}
}
public NetworkRequest? NetworkRequestIfSuspended
{
get
{
return GetNetworkRequestIfSuspended();
}
}
///
/// Creates a managed GeneratorState 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 GeneratorState(Raw.GeneratorState* handle)
{
_inner = handle;
}
public bool IsSuspended()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("GeneratorState");
}
bool retVal = Raw.GeneratorState.IsSuspended(_inner);
return retVal;
}
}
public bool IsCompleted()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("GeneratorState");
}
bool retVal = Raw.GeneratorState.IsCompleted(_inner);
return retVal;
}
}
///
/// A NetworkRequest allocated on Rust side.
///
public NetworkRequest? GetNetworkRequestIfSuspended()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("GeneratorState");
}
Raw.NetworkRequest* retVal = Raw.GeneratorState.GetNetworkRequestIfSuspended(_inner);
if (retVal == null)
{
return null;
}
return new NetworkRequest(retVal);
}
}
///
///
/// A ClientState allocated on Rust side.
///
public ClientState GetClientStateIfCompleted()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("GeneratorState");
}
Raw.CredsspNetworkFfiResultBoxClientStateBoxIronRdpError result = Raw.GeneratorState.GetClientStateIfCompleted(_inner);
if (!result.isOk)
{
throw new IronRdpException(new IronRdpError(result.Err));
}
Raw.ClientState* retVal = result.Ok;
return new ClientState(retVal);
}
}
///
/// Returns the underlying raw handle.
///
public unsafe Raw.GeneratorState* AsFFI()
{
return _inner;
}
///
/// Destroys the underlying object immediately.
///
public void Dispose()
{
unsafe
{
if (_inner == null)
{
return;
}
Raw.GeneratorState.Destroy(_inner);
_inner = null;
GC.SuppressFinalize(this);
}
}
~GeneratorState()
{
Dispose();
}
}