// // This code is generated by csbindgen. // DON'T CHANGE THIS DIRECTLY. // #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 public static Connection? Open(byte* host) { var native = Connection.sp_connection_open(host); return native == null ? null : new Connection(native); } public bool SendPacket(Packet packet) { return Connection.sp_connection_send_packet(Instance, packet.Instance); } public bool SendCommand(Command command) { return Connection.sp_connection_send_command(Instance, command.Instance); } 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(); const string __DllName = "servicepoint_binding_c"; #nullable restore /// /// 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`. /// [DllImport(__DllName, EntryPoint = "sp_connection_open", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPConnection* sp_connection_open(byte* host); /// /// 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 /// [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); /// /// 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 /// [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); /// /// Closes and deallocates a [SPConnection]. /// /// # Panics /// /// - when `connection` is NULL /// /// # Safety /// /// The caller has to make sure that: /// /// - `connection` points to a valid [SPConnection] /// - `connection` is not used concurrently or after this call /// [DllImport(__DllName, EntryPoint = "sp_connection_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_connection_free(SPConnection* connection); } [StructLayout(LayoutKind.Sequential)] public unsafe partial struct SPConnection { } }