mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-19 02:20:12 +01:00
164 lines
4.9 KiB
C#
164 lines
4.9 KiB
C#
// <auto-generated>
|
|
// This code is generated by csbindgen.
|
|
// DON'T CHANGE THIS DIRECTLY.
|
|
// </auto-generated>
|
|
#pragma warning disable CS8500
|
|
#pragma warning disable CS8981
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
namespace ServicePoint
|
|
{
|
|
|
|
public unsafe sealed partial class Connection: IDisposable
|
|
{
|
|
#nullable enable
|
|
/// <summary>
|
|
/// Creates a new instance of [SPConnection].
|
|
///
|
|
/// returns: NULL if connection fails, or connected instance
|
|
///
|
|
/// # Panics
|
|
///
|
|
/// - when `host` is null or an invalid host
|
|
///
|
|
/// # Safety
|
|
///
|
|
/// The caller has to make sure that:
|
|
///
|
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
|
/// by explicitly calling `sp_connection_free`.
|
|
/// </summary>
|
|
public static Connection? Open(byte* host)
|
|
{
|
|
var native = Connection.sp_connection_open(host);
|
|
return native == null ? null : new Connection(native);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends a [SPPacket] to the display using the [SPConnection].
|
|
///
|
|
/// The passed `packet` gets consumed.
|
|
///
|
|
/// returns: true in case of success
|
|
///
|
|
/// # Panics
|
|
///
|
|
/// - when `connection` is NULL
|
|
/// - when `packet` is NULL
|
|
///
|
|
/// # Safety
|
|
///
|
|
/// The caller has to make sure that:
|
|
///
|
|
/// - `connection` points to a valid instance of [SPConnection]
|
|
/// - `packet` points to a valid instance of [SPPacket]
|
|
/// - `packet` is not used concurrently or after this call
|
|
///
|
|
/// servicepoint_csbindgen_consumes: packet
|
|
/// </summary>
|
|
public bool SendPacket(Packet packet)
|
|
{
|
|
return Connection.sp_connection_send_packet(this.Instance, packet.Into());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends a [SPCommand] to the display using the [SPConnection].
|
|
///
|
|
/// The passed `command` gets consumed.
|
|
///
|
|
/// returns: true in case of success
|
|
///
|
|
/// # Panics
|
|
///
|
|
/// - when `connection` is NULL
|
|
/// - when `command` is NULL
|
|
///
|
|
/// # Safety
|
|
///
|
|
/// The caller has to make sure that:
|
|
///
|
|
/// - `connection` points to a valid instance of [SPConnection]
|
|
/// - `command` points to a valid instance of [SPPacket]
|
|
/// - `command` is not used concurrently or after this call
|
|
///
|
|
/// servicepoint_csbindgen_consumes: packet
|
|
/// </summary>
|
|
public bool SendCommand(Command command)
|
|
{
|
|
return Connection.sp_connection_send_command(this.Instance, command.Instance);
|
|
}
|
|
|
|
|
|
#region internal machinery
|
|
private SPConnection* _instance;
|
|
internal SPConnection* Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
throw new NullReferenceException("instance is null");
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
private Connection(SPConnection* instance)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(instance);
|
|
_instance = instance;
|
|
}
|
|
|
|
internal SPConnection* Into()
|
|
{
|
|
var instance = Instance;
|
|
_instance = null;
|
|
return instance;
|
|
}
|
|
|
|
private void Free()
|
|
{
|
|
if (_instance != null)
|
|
Connection.sp_connection_free(Into());
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Free();
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
~Connection() => Free();
|
|
|
|
#endregion
|
|
|
|
#nullable restore
|
|
#region native methods
|
|
const string __DllName = "servicepoint_binding_c";
|
|
[DllImport(__DllName, EntryPoint = "sp_connection_open", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
private static extern SPConnection* sp_connection_open(byte* host);
|
|
|
|
[DllImport(__DllName, EntryPoint = "sp_connection_send_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
[return: MarshalAs(UnmanagedType.U1)]
|
|
private static extern bool sp_connection_send_packet(SPConnection* connection, SPPacket* packet);
|
|
|
|
[DllImport(__DllName, EntryPoint = "sp_connection_send_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
[return: MarshalAs(UnmanagedType.U1)]
|
|
private static extern bool sp_connection_send_command(SPConnection* connection, SPCommand* command);
|
|
|
|
[DllImport(__DllName, EntryPoint = "sp_connection_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
|
private static extern void sp_connection_free(SPConnection* connection);
|
|
|
|
|
|
#endregion
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public unsafe partial struct SPConnection
|
|
{
|
|
}
|
|
|
|
|
|
|
|
}
|