// // 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 /// /// Creates a new instance of [SPConnection] that uses UDP to send. /// /// 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`. /// [System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public static Connection? Open(byte* host) { var native = Connection.sp_connection_open(host); return native == null ? null : new Connection(native); } /// /// 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 /// [System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public bool SendPacket(Packet packet) { return Connection.sp_connection_send_packet(this.__Instance, packet.__Into()); } /// /// 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: command /// [System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public bool SendCommand(Command command) { return Connection.sp_connection_send_command(this.__Instance, command.__Into()); } #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 { } }