Skip to content

Commit

Permalink
feat(ffi): expose InclusiveRectangle attributes (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
irvingoujAtDevolution authored Jun 19, 2024
1 parent e339346 commit d5c00d0
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ffi/dotnet/Devolutions.IronRdp/Generated/DiplomatRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public DiplomatWriteable()

IntPtr flushFuncPtr = Marshal.GetFunctionPointerForDelegate(flushFunc);
IntPtr growFuncPtr = Marshal.GetFunctionPointerForDelegate(growFunc);

// flushFunc and growFunc are managed objects and might be disposed of by the garbage collector.
// To prevent this, we make the context hold the references and protect the context itself
// for automatic disposal by moving it behind a GCHandle.
DiplomatWriteableContext ctx = new DiplomatWriteableContext();
DiplomatWriteableContext ctx = new DiplomatWriteableContext();
ctx.flushFunc = flushFunc;
ctx.growFunc = growFunc;
GCHandle ctxHandle = GCHandle.Alloc(ctx);
Expand Down Expand Up @@ -81,7 +81,7 @@ public string ToUnicode()
{
throw new IndexOutOfRangeException("DiplomatWriteable buffer is too big");
}
return Marshal.PtrToStringUTF8(buf, (int)len);
return Marshal.PtrToStringUTF8(buf, (int) len);
#else
byte[] utf8 = ToUtf8Bytes();
return DiplomatUtils.Utf8ToString(utf8);
Expand Down
126 changes: 126 additions & 0 deletions ffi/dotnet/Devolutions.IronRdp/Generated/InclusiveRectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,54 @@ public partial class InclusiveRectangle: IDisposable
{
private unsafe Raw.InclusiveRectangle* _inner;

public ushort Bottom
{
get
{
return GetBottom();
}
}

public ushort Height
{
get
{
return GetHeight();
}
}

public ushort Left
{
get
{
return GetLeft();
}
}

public ushort Right
{
get
{
return GetRight();
}
}

public ushort Top
{
get
{
return GetTop();
}
}

public ushort Width
{
get
{
return GetWidth();
}
}

/// <summary>
/// Creates a managed <c>InclusiveRectangle</c> from a raw handle.
/// </summary>
Expand All @@ -29,6 +77,84 @@ public unsafe InclusiveRectangle(Raw.InclusiveRectangle* handle)
_inner = handle;
}

public ushort GetLeft()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("InclusiveRectangle");
}
ushort retVal = Raw.InclusiveRectangle.GetLeft(_inner);
return retVal;
}
}

public ushort GetTop()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("InclusiveRectangle");
}
ushort retVal = Raw.InclusiveRectangle.GetTop(_inner);
return retVal;
}
}

public ushort GetRight()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("InclusiveRectangle");
}
ushort retVal = Raw.InclusiveRectangle.GetRight(_inner);
return retVal;
}
}

public ushort GetBottom()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("InclusiveRectangle");
}
ushort retVal = Raw.InclusiveRectangle.GetBottom(_inner);
return retVal;
}
}

public ushort GetWidth()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("InclusiveRectangle");
}
ushort retVal = Raw.InclusiveRectangle.GetWidth(_inner);
return retVal;
}
}

public ushort GetHeight()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("InclusiveRectangle");
}
ushort retVal = Raw.InclusiveRectangle.GetHeight(_inner);
return retVal;
}
}

/// <summary>
/// Returns the underlying raw handle.
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions ffi/dotnet/Devolutions.IronRdp/Generated/RawInclusiveRectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ public partial struct InclusiveRectangle
{
private const string NativeLib = "DevolutionsIronRdp";

[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_left", ExactSpelling = true)]
public static unsafe extern ushort GetLeft(InclusiveRectangle* self);

[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_top", ExactSpelling = true)]
public static unsafe extern ushort GetTop(InclusiveRectangle* self);

[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_right", ExactSpelling = true)]
public static unsafe extern ushort GetRight(InclusiveRectangle* self);

[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_bottom", ExactSpelling = true)]
public static unsafe extern ushort GetBottom(InclusiveRectangle* self);

[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_width", ExactSpelling = true)]
public static unsafe extern ushort GetWidth(InclusiveRectangle* self);

[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_get_height", ExactSpelling = true)]
public static unsafe extern ushort GetHeight(InclusiveRectangle* self);

[DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "InclusiveRectangle_destroy", ExactSpelling = true)]
public static unsafe extern void Destroy(InclusiveRectangle* self);
}
28 changes: 28 additions & 0 deletions ffi/src/pdu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[diplomat::bridge]
pub mod ffi {

use ironrdp::pdu::geometry::Rectangle;

use crate::{error::ffi::IronRdpError, utils::ffi::VecU8};

#[diplomat::opaque]
Expand Down Expand Up @@ -34,6 +36,32 @@ pub mod ffi {
#[diplomat::opaque]
pub struct InclusiveRectangle(pub ironrdp::pdu::geometry::InclusiveRectangle);

impl InclusiveRectangle {
pub fn get_left(&self) -> u16 {
self.0.left
}

pub fn get_top(&self) -> u16 {
self.0.top
}

pub fn get_right(&self) -> u16 {
self.0.right
}

pub fn get_bottom(&self) -> u16 {
self.0.bottom
}

pub fn get_width(&self) -> u16 {
self.0.width()
}

pub fn get_height(&self) -> u16 {
self.0.height()
}
}

#[diplomat::opaque]
pub struct IronRdpPdu; // A struct representing the ironrdp_pdu crate

Expand Down

0 comments on commit d5c00d0

Please sign in to comment.