Files
BQP/srcs/RobotNet10/RobotApp/Communication/CeresSharp/Native/SafeHandles/ContextHandle.cs
2026-07-13 09:25:40 +07:00

34 lines
853 B
C#

using System;
using CeresSharp.Native;
namespace CeresSharp.Native.SafeHandles;
/// <summary>
/// Safe handle for Ceres Context.
/// </summary>
internal sealed class ContextHandle : BaseSafeHandle
{
private ContextHandle() : base()
{
}
private ContextHandle(IntPtr handle, bool ownsHandle) : base(handle, ownsHandle)
{
}
public static ContextHandle Create()
{
var handle = CeresNative.ceres_wrapper_create_context();
if (handle == IntPtr.Zero)
{
throw new Exceptions.CeresException(Exceptions.CeresErrorCode.OutOfMemory, "Failed to create context");
}
return new ContextHandle(handle, true);
}
protected override void ReleaseNativeHandle(IntPtr handle)
{
CeresNative.ceres_wrapper_free_context(handle);
}
}