diff --git a/crates/servicepoint_binding_cs/ServicePoint/BitVec.g.cs b/crates/servicepoint_binding_cs/ServicePoint/BitVec.g.cs index 83eaeb5..1aea6f3 100644 --- a/crates/servicepoint_binding_cs/ServicePoint/BitVec.g.cs +++ b/crates/servicepoint_binding_cs/ServicePoint/BitVec.g.cs @@ -14,43 +14,214 @@ namespace ServicePoint public unsafe sealed partial class BitVec: IDisposable { #nullable enable + /// + /// Creates a new [SPBitVec] instance. + /// + /// # Arguments + /// + /// - `size`: size in bits. + /// + /// returns: [SPBitVec] with all bits set to false. Will never return NULL. + /// + /// # Panics + /// + /// - when `size` is not divisible by 8. + /// + /// # 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_bitvec_free`. + /// public BitVec(nuint size) : this(sp_bitvec_new(size)) {} + /// + /// Interpret the data as a series of bits and load then into a new [SPBitVec] instance. + /// + /// returns: [SPBitVec] instance containing data. Will never return NULL. + /// + /// # Panics + /// + /// - when `data` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `data` points to a valid memory location of at least `data_length` + /// bytes in size. + /// - the returned instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_bitvec_free`. + /// public static BitVec Load(byte* data, nuint data_length) { return new BitVec(BitVec.sp_bitvec_load(data, data_length)); } + /// + /// Clones a [SPBitVec]. + /// + /// returns: new [SPBitVec] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `bit_vec` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid [SPBitVec] + /// - `bit_vec` is not written to concurrently + /// - the returned instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_bitvec_free`. + /// public BitVec Clone() { return new BitVec(BitVec.sp_bitvec_clone(Instance)); } + /// + /// Gets the value of a bit from the [SPBitVec]. + /// + /// # Arguments + /// + /// - `bit_vec`: instance to read from + /// - `index`: the bit index to read + /// + /// returns: value of the bit + /// + /// # Panics + /// + /// - when `bit_vec` is NULL + /// - when accessing `index` out of bounds + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid [SPBitVec] + /// - `bit_vec` is not written to concurrently + /// public bool Get(nuint index) { return BitVec.sp_bitvec_get(Instance, index); } + /// + /// Sets the value of a bit in the [SPBitVec]. + /// + /// # Arguments + /// + /// - `bit_vec`: instance to write to + /// - `index`: the bit index to edit + /// - `value`: the value to set the bit to + /// + /// # Panics + /// + /// - when `bit_vec` is NULL + /// - when accessing `index` out of bounds + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid [SPBitVec] + /// - `bit_vec` is not written to or read from concurrently + /// public void Set(nuint index, bool value) { BitVec.sp_bitvec_set(Instance, index, value); } + /// + /// Sets the value of all bits in the [SPBitVec]. + /// + /// # Arguments + /// + /// - `bit_vec`: instance to write to + /// - `value`: the value to set all bits to + /// + /// # Panics + /// + /// - when `bit_vec` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid [SPBitVec] + /// - `bit_vec` is not written to or read from concurrently + /// public void Fill(bool value) { BitVec.sp_bitvec_fill(Instance, value); } + /// + /// Gets the length of the [SPBitVec] in bits. + /// + /// # Arguments + /// + /// - `bit_vec`: instance to write to + /// + /// # Panics + /// + /// - when `bit_vec` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid [SPBitVec] + /// public nuint Len() { return BitVec.sp_bitvec_len(Instance); } + /// + /// Returns true if length is 0. + /// + /// # Arguments + /// + /// - `bit_vec`: instance to write to + /// + /// # Panics + /// + /// - when `bit_vec` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid [SPBitVec] + /// public bool IsEmpty() { return BitVec.sp_bitvec_is_empty(Instance); } + /// + /// Gets an unsafe reference to the data of the [SPBitVec] instance. + /// + /// # Arguments + /// + /// - `bit_vec`: instance to write to + /// + /// # Panics + /// + /// - when `bit_vec` is NULL + /// + /// ## Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid [SPBitVec] + /// - the returned memory range is never accessed after the passed [SPBitVec] has been freed + /// - the returned memory range is never accessed concurrently, either via the [SPBitVec] or directly + /// public SPByteSlice UnsafeDataRef() { return BitVec.sp_bitvec_unsafe_data_ref(Instance); @@ -97,221 +268,35 @@ namespace ServicePoint const string __DllName = "servicepoint_binding_c"; #nullable restore - /// - /// Creates a new [SPBitVec] instance. - /// - /// # Arguments - /// - /// - `size`: size in bits. - /// - /// returns: [SPBitVec] with all bits set to false. Will never return NULL. - /// - /// # Panics - /// - /// - when `size` is not divisible by 8. - /// - /// # 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_bitvec_free`. - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBitVec* sp_bitvec_new(nuint size); - /// - /// Interpret the data as a series of bits and load then into a new [SPBitVec] instance. - /// - /// returns: [SPBitVec] instance containing data. Will never return NULL. - /// - /// # Panics - /// - /// - when `data` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `data` points to a valid memory location of at least `data_length` - /// bytes in size. - /// - the returned instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_bitvec_free`. - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBitVec* sp_bitvec_load(byte* data, nuint data_length); - /// - /// Clones a [SPBitVec]. - /// - /// returns: new [SPBitVec] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `bit_vec` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid [SPBitVec] - /// - `bit_vec` is not written to concurrently - /// - the returned instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_bitvec_free`. - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBitVec* sp_bitvec_clone(SPBitVec* bit_vec); - /// - /// Deallocates a [SPBitVec]. - /// - /// # Panics - /// - /// - when `but_vec` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid [SPBitVec] - /// - `bit_vec` is not used concurrently or after this call - /// - `bit_vec` was not passed to another consuming function, e.g. to create a [SPCommand] - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_bitvec_free(SPBitVec* bit_vec); - /// - /// Gets the value of a bit from the [SPBitVec]. - /// - /// # Arguments - /// - /// - `bit_vec`: instance to read from - /// - `index`: the bit index to read - /// - /// returns: value of the bit - /// - /// # Panics - /// - /// - when `bit_vec` is NULL - /// - when accessing `index` out of bounds - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid [SPBitVec] - /// - `bit_vec` is not written to concurrently - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool sp_bitvec_get(SPBitVec* bit_vec, nuint index); - /// - /// Sets the value of a bit in the [SPBitVec]. - /// - /// # Arguments - /// - /// - `bit_vec`: instance to write to - /// - `index`: the bit index to edit - /// - `value`: the value to set the bit to - /// - /// # Panics - /// - /// - when `bit_vec` is NULL - /// - when accessing `index` out of bounds - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid [SPBitVec] - /// - `bit_vec` is not written to or read from concurrently - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_bitvec_set(SPBitVec* bit_vec, nuint index, [MarshalAs(UnmanagedType.U1)] bool value); - /// - /// Sets the value of all bits in the [SPBitVec]. - /// - /// # Arguments - /// - /// - `bit_vec`: instance to write to - /// - `value`: the value to set all bits to - /// - /// # Panics - /// - /// - when `bit_vec` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid [SPBitVec] - /// - `bit_vec` is not written to or read from concurrently - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_bitvec_fill(SPBitVec* bit_vec, [MarshalAs(UnmanagedType.U1)] bool value); - /// - /// Gets the length of the [SPBitVec] in bits. - /// - /// # Arguments - /// - /// - `bit_vec`: instance to write to - /// - /// # Panics - /// - /// - when `bit_vec` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid [SPBitVec] - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_len", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern nuint sp_bitvec_len(SPBitVec* bit_vec); - /// - /// Returns true if length is 0. - /// - /// # Arguments - /// - /// - `bit_vec`: instance to write to - /// - /// # Panics - /// - /// - when `bit_vec` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid [SPBitVec] - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_is_empty", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool sp_bitvec_is_empty(SPBitVec* bit_vec); - /// - /// Gets an unsafe reference to the data of the [SPBitVec] instance. - /// - /// # Arguments - /// - /// - `bit_vec`: instance to write to - /// - /// # Panics - /// - /// - when `bit_vec` is NULL - /// - /// ## Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid [SPBitVec] - /// - the returned memory range is never accessed after the passed [SPBitVec] has been freed - /// - the returned memory range is never accessed concurrently, either via the [SPBitVec] or directly - /// [DllImport(__DllName, EntryPoint = "sp_bitvec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPByteSlice sp_bitvec_unsafe_data_ref(SPBitVec* bit_vec); diff --git a/crates/servicepoint_binding_cs/ServicePoint/Bitmap.g.cs b/crates/servicepoint_binding_cs/ServicePoint/Bitmap.g.cs index e3023ef..974149f 100644 --- a/crates/servicepoint_binding_cs/ServicePoint/Bitmap.g.cs +++ b/crates/servicepoint_binding_cs/ServicePoint/Bitmap.g.cs @@ -14,43 +14,217 @@ namespace ServicePoint public unsafe sealed partial class Bitmap: IDisposable { #nullable enable + /// + /// Creates a new [SPBitmap] with the specified dimensions. + /// + /// # Arguments + /// + /// - `width`: size in pixels in x-direction + /// - `height`: size in pixels in y-direction + /// + /// returns: [SPBitmap] initialized to all pixels off. Will never return NULL. + /// + /// # Panics + /// + /// - when the width is not dividable by 8 + /// + /// # 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_bitmap_free`. + /// public Bitmap(nuint width, nuint height) : this(sp_bitmap_new(width, height)) {} + /// + /// Loads a [SPBitmap] with the specified dimensions from the provided data. + /// + /// # Arguments + /// + /// - `width`: size in pixels in x-direction + /// - `height`: size in pixels in y-direction + /// + /// returns: [SPBitmap] that contains a copy of the provided data. Will never return NULL. + /// + /// # Panics + /// + /// - when `data` is NULL + /// - when the dimensions and data size do not match exactly. + /// - when the width is not dividable by 8 + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `data` points to a valid memory location of at least `data_length` bytes in size. + /// - the returned instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_bitmap_free`. + /// public static Bitmap Load(nuint width, nuint height, byte* data, nuint data_length) { return new Bitmap(Bitmap.sp_bitmap_load(width, height, data, data_length)); } + /// + /// Clones a [SPBitmap]. + /// + /// Will never return NULL. + /// + /// # Panics + /// + /// - when `bitmap` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bitmap` points to a valid [SPBitmap] + /// - `bitmap` is not written to concurrently + /// - the returned instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_bitmap_free`. + /// public Bitmap Clone() { return new Bitmap(Bitmap.sp_bitmap_clone(Instance)); } + /// + /// Gets the current value at the specified position in the [SPBitmap]. + /// + /// # Arguments + /// + /// - `bitmap`: instance to read from + /// - `x` and `y`: position of the cell to read + /// + /// # Panics + /// + /// - when `bitmap` is NULL + /// - when accessing `x` or `y` out of bounds + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bitmap` points to a valid [SPBitmap] + /// - `bitmap` is not written to concurrently + /// public bool Get(nuint x, nuint y) { return Bitmap.sp_bitmap_get(Instance, x, y); } + /// + /// Sets the value of the specified position in the [SPBitmap]. + /// + /// # Arguments + /// + /// - `bitmap`: instance to write to + /// - `x` and `y`: position of the cell + /// - `value`: the value to write to the cell + /// + /// returns: old value of the cell + /// + /// # Panics + /// + /// - when `bitmap` is NULL + /// - when accessing `x` or `y` out of bounds + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bitmap` points to a valid [SPBitmap] + /// - `bitmap` is not written to or read from concurrently + /// public void Set(nuint x, nuint y, bool value) { Bitmap.sp_bitmap_set(Instance, x, y, value); } + /// + /// Sets the state of all pixels in the [SPBitmap]. + /// + /// # Arguments + /// + /// - `bitmap`: instance to write to + /// - `value`: the value to set all pixels to + /// + /// # Panics + /// + /// - when `bitmap` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bitmap` points to a valid [SPBitmap] + /// - `bitmap` is not written to or read from concurrently + /// public void Fill(bool value) { Bitmap.sp_bitmap_fill(Instance, value); } + /// + /// Gets the width in pixels of the [SPBitmap] instance. + /// + /// # Arguments + /// + /// - `bitmap`: instance to read from + /// + /// # Panics + /// + /// - when `bitmap` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bitmap` points to a valid [SPBitmap] + /// public nuint Width() { return Bitmap.sp_bitmap_width(Instance); } + /// + /// Gets the height in pixels of the [SPBitmap] instance. + /// + /// # Arguments + /// + /// - `bitmap`: instance to read from + /// + /// # Panics + /// + /// - when `bitmap` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bitmap` points to a valid [SPBitmap] + /// public nuint Height() { return Bitmap.sp_bitmap_height(Instance); } + /// + /// Gets an unsafe reference to the data of the [SPBitmap] instance. + /// + /// # Panics + /// + /// - when `bitmap` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bitmap` points to a valid [SPBitmap] + /// - the returned memory range is never accessed after the passed [SPBitmap] has been freed + /// - the returned memory range is never accessed concurrently, either via the [SPBitmap] or directly + /// public SPByteSlice UnsafeDataRef() { return Bitmap.sp_bitmap_unsafe_data_ref(Instance); @@ -97,223 +271,34 @@ namespace ServicePoint const string __DllName = "servicepoint_binding_c"; #nullable restore - /// - /// Creates a new [SPBitmap] with the specified dimensions. - /// - /// # Arguments - /// - /// - `width`: size in pixels in x-direction - /// - `height`: size in pixels in y-direction - /// - /// returns: [SPBitmap] initialized to all pixels off. Will never return NULL. - /// - /// # Panics - /// - /// - when the width is not dividable by 8 - /// - /// # 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_bitmap_free`. - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBitmap* sp_bitmap_new(nuint width, nuint height); - /// - /// Loads a [SPBitmap] with the specified dimensions from the provided data. - /// - /// # Arguments - /// - /// - `width`: size in pixels in x-direction - /// - `height`: size in pixels in y-direction - /// - /// returns: [SPBitmap] that contains a copy of the provided data. Will never return NULL. - /// - /// # Panics - /// - /// - when `data` is NULL - /// - when the dimensions and data size do not match exactly. - /// - when the width is not dividable by 8 - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `data` points to a valid memory location of at least `data_length` bytes in size. - /// - the returned instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_bitmap_free`. - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBitmap* sp_bitmap_load(nuint width, nuint height, byte* data, nuint data_length); - /// - /// Clones a [SPBitmap]. - /// - /// Will never return NULL. - /// - /// # Panics - /// - /// - when `bitmap` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bitmap` points to a valid [SPBitmap] - /// - `bitmap` is not written to concurrently - /// - the returned instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_bitmap_free`. - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBitmap* sp_bitmap_clone(SPBitmap* bitmap); - /// - /// Deallocates a [SPBitmap]. - /// - /// # Panics - /// - /// - when `bitmap` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bitmap` points to a valid [SPBitmap] - /// - `bitmap` is not used concurrently or after bitmap call - /// - `bitmap` was not passed to another consuming function, e.g. to create a [SPCommand] - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_bitmap_free(SPBitmap* bitmap); - /// - /// Gets the current value at the specified position in the [SPBitmap]. - /// - /// # Arguments - /// - /// - `bitmap`: instance to read from - /// - `x` and `y`: position of the cell to read - /// - /// # Panics - /// - /// - when `bitmap` is NULL - /// - when accessing `x` or `y` out of bounds - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bitmap` points to a valid [SPBitmap] - /// - `bitmap` is not written to concurrently - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool sp_bitmap_get(SPBitmap* bitmap, nuint x, nuint y); - /// - /// Sets the value of the specified position in the [SPBitmap]. - /// - /// # Arguments - /// - /// - `bitmap`: instance to write to - /// - `x` and `y`: position of the cell - /// - `value`: the value to write to the cell - /// - /// returns: old value of the cell - /// - /// # Panics - /// - /// - when `bitmap` is NULL - /// - when accessing `x` or `y` out of bounds - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bitmap` points to a valid [SPBitmap] - /// - `bitmap` is not written to or read from concurrently - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_bitmap_set(SPBitmap* bitmap, nuint x, nuint y, [MarshalAs(UnmanagedType.U1)] bool value); - /// - /// Sets the state of all pixels in the [SPBitmap]. - /// - /// # Arguments - /// - /// - `bitmap`: instance to write to - /// - `value`: the value to set all pixels to - /// - /// # Panics - /// - /// - when `bitmap` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bitmap` points to a valid [SPBitmap] - /// - `bitmap` is not written to or read from concurrently - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_bitmap_fill(SPBitmap* bitmap, [MarshalAs(UnmanagedType.U1)] bool value); - /// - /// Gets the width in pixels of the [SPBitmap] instance. - /// - /// # Arguments - /// - /// - `bitmap`: instance to read from - /// - /// # Panics - /// - /// - when `bitmap` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bitmap` points to a valid [SPBitmap] - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern nuint sp_bitmap_width(SPBitmap* bitmap); - /// - /// Gets the height in pixels of the [SPBitmap] instance. - /// - /// # Arguments - /// - /// - `bitmap`: instance to read from - /// - /// # Panics - /// - /// - when `bitmap` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bitmap` points to a valid [SPBitmap] - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern nuint sp_bitmap_height(SPBitmap* bitmap); - /// - /// Gets an unsafe reference to the data of the [SPBitmap] instance. - /// - /// # Panics - /// - /// - when `bitmap` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bitmap` points to a valid [SPBitmap] - /// - the returned memory range is never accessed after the passed [SPBitmap] has been freed - /// - the returned memory range is never accessed concurrently, either via the [SPBitmap] or directly - /// [DllImport(__DllName, EntryPoint = "sp_bitmap_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPByteSlice sp_bitmap_unsafe_data_ref(SPBitmap* bitmap); diff --git a/crates/servicepoint_binding_cs/ServicePoint/BrightnessGrid.g.cs b/crates/servicepoint_binding_cs/ServicePoint/BrightnessGrid.g.cs index 0cad03a..3c8696b 100644 --- a/crates/servicepoint_binding_cs/ServicePoint/BrightnessGrid.g.cs +++ b/crates/servicepoint_binding_cs/ServicePoint/BrightnessGrid.g.cs @@ -25,43 +25,221 @@ namespace ServicePoint public unsafe sealed partial class BrightnessGrid: IDisposable { #nullable enable + /// + /// Creates a new [SPBrightnessGrid] with the specified dimensions. + /// + /// returns: [SPBrightnessGrid] initialized to 0. Will never return NULL. + /// + /// # 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_brightness_grid_free`. + /// public BrightnessGrid(nuint width, nuint height) : this(sp_brightness_grid_new(width, height)) {} + /// + /// Loads a [SPBrightnessGrid] with the specified dimensions from the provided data. + /// + /// returns: new [SPBrightnessGrid] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `data` is NULL + /// - when the provided `data_length` does not match `height` and `width` + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `data` points to a valid memory location of at least `data_length` + /// bytes in size. + /// - the returned instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_brightness_grid_free`. + /// public static BrightnessGrid Load(nuint width, nuint height, byte* data, nuint data_length) { return new BrightnessGrid(BrightnessGrid.sp_brightness_grid_load(width, height, data, data_length)); } + /// + /// Clones a [SPBrightnessGrid]. + /// + /// # Arguments + /// + /// - `brightness_grid`: instance to read from + /// + /// returns: new [SPBrightnessGrid] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `brightness_grid` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `brightness_grid` points to a valid [SPBrightnessGrid] + /// - `brightness_grid` is not written to concurrently + /// - the returned instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_brightness_grid_free`. + /// public BrightnessGrid Clone() { return new BrightnessGrid(BrightnessGrid.sp_brightness_grid_clone(Instance)); } + /// + /// Gets the current value at the specified position. + /// + /// # Arguments + /// + /// - `brightness_grid`: instance to read from + /// - `x` and `y`: position of the cell to read + /// + /// returns: value at position + /// + /// # Panics + /// + /// - when `brightness_grid` is NULL + /// - When accessing `x` or `y` out of bounds. + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `brightness_grid` points to a valid [SPBrightnessGrid] + /// - `brightness_grid` is not written to concurrently + /// public byte Get(nuint x, nuint y) { return BrightnessGrid.sp_brightness_grid_get(Instance, x, y); } + /// + /// Sets the value of the specified position in the [SPBrightnessGrid]. + /// + /// # Arguments + /// + /// - `brightness_grid`: instance to write to + /// - `x` and `y`: position of the cell + /// - `value`: the value to write to the cell + /// + /// returns: old value of the cell + /// + /// # Panics + /// + /// - when `brightness_grid` is NULL + /// - When accessing `x` or `y` out of bounds. + /// - When providing an invalid brightness value + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `brightness_grid` points to a valid [SPBitVec] + /// - `brightness_grid` is not written to or read from concurrently + /// public void Set(nuint x, nuint y, byte value) { BrightnessGrid.sp_brightness_grid_set(Instance, x, y, value); } + /// + /// Sets the value of all cells in the [SPBrightnessGrid]. + /// + /// # Arguments + /// + /// - `brightness_grid`: instance to write to + /// - `value`: the value to set all cells to + /// + /// # Panics + /// + /// - when `brightness_grid` is NULL + /// - When providing an invalid brightness value + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `brightness_grid` points to a valid [SPBrightnessGrid] + /// - `brightness_grid` is not written to or read from concurrently + /// public void Fill(byte value) { BrightnessGrid.sp_brightness_grid_fill(Instance, value); } + /// + /// Gets the width of the [SPBrightnessGrid] instance. + /// + /// # Arguments + /// + /// - `brightness_grid`: instance to read from + /// + /// returns: width + /// + /// # Panics + /// + /// - when `brightness_grid` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `brightness_grid` points to a valid [SPBrightnessGrid] + /// public nuint Width() { return BrightnessGrid.sp_brightness_grid_width(Instance); } + /// + /// Gets the height of the [SPBrightnessGrid] instance. + /// + /// # Arguments + /// + /// - `brightness_grid`: instance to read from + /// + /// returns: height + /// + /// # Panics + /// + /// - when `brightness_grid` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `brightness_grid` points to a valid [SPBrightnessGrid] + /// public nuint Height() { return BrightnessGrid.sp_brightness_grid_height(Instance); } + /// + /// Gets an unsafe reference to the data of the [SPBrightnessGrid] instance. + /// + /// # Arguments + /// + /// - `brightness_grid`: instance to read from + /// + /// returns: slice of bytes underlying the `brightness_grid`. + /// + /// # Panics + /// + /// - when `brightness_grid` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `brightness_grid` points to a valid [SPBrightnessGrid] + /// - the returned memory range is never accessed after the passed [SPBrightnessGrid] has been freed + /// - the returned memory range is never accessed concurrently, either via the [SPBrightnessGrid] or directly + /// public SPByteSlice UnsafeDataRef() { return BrightnessGrid.sp_brightness_grid_unsafe_data_ref(Instance); @@ -108,230 +286,33 @@ namespace ServicePoint const string __DllName = "servicepoint_binding_c"; #nullable restore - /// - /// Creates a new [SPBrightnessGrid] with the specified dimensions. - /// - /// returns: [SPBrightnessGrid] initialized to 0. Will never return NULL. - /// - /// # 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_brightness_grid_free`. - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBrightnessGrid* sp_brightness_grid_new(nuint width, nuint height); - /// - /// Loads a [SPBrightnessGrid] with the specified dimensions from the provided data. - /// - /// returns: new [SPBrightnessGrid] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `data` is NULL - /// - when the provided `data_length` does not match `height` and `width` - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `data` points to a valid memory location of at least `data_length` - /// bytes in size. - /// - the returned instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_brightness_grid_free`. - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBrightnessGrid* sp_brightness_grid_load(nuint width, nuint height, byte* data, nuint data_length); - /// - /// Clones a [SPBrightnessGrid]. - /// - /// # Arguments - /// - /// - `brightness_grid`: instance to read from - /// - /// returns: new [SPBrightnessGrid] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `brightness_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `brightness_grid` points to a valid [SPBrightnessGrid] - /// - `brightness_grid` is not written to concurrently - /// - the returned instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_brightness_grid_free`. - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPBrightnessGrid* sp_brightness_grid_clone(SPBrightnessGrid* brightness_grid); - /// - /// Deallocates a [SPBrightnessGrid]. - /// - /// # Arguments - /// - /// - `brightness_grid`: instance to read from - /// - /// # Panics - /// - /// - when `brightness_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `brightness_grid` points to a valid [SPBrightnessGrid] - /// - `brightness_grid` is not used concurrently or after this call - /// - `brightness_grid` was not passed to another consuming function, e.g. to create a [SPCommand] - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_brightness_grid_free(SPBrightnessGrid* brightness_grid); - /// - /// Gets the current value at the specified position. - /// - /// # Arguments - /// - /// - `brightness_grid`: instance to read from - /// - `x` and `y`: position of the cell to read - /// - /// returns: value at position - /// - /// # Panics - /// - /// - when `brightness_grid` is NULL - /// - When accessing `x` or `y` out of bounds. - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `brightness_grid` points to a valid [SPBrightnessGrid] - /// - `brightness_grid` is not written to concurrently - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern byte sp_brightness_grid_get(SPBrightnessGrid* brightness_grid, nuint x, nuint y); - /// - /// Sets the value of the specified position in the [SPBrightnessGrid]. - /// - /// # Arguments - /// - /// - `brightness_grid`: instance to write to - /// - `x` and `y`: position of the cell - /// - `value`: the value to write to the cell - /// - /// returns: old value of the cell - /// - /// # Panics - /// - /// - when `brightness_grid` is NULL - /// - When accessing `x` or `y` out of bounds. - /// - When providing an invalid brightness value - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `brightness_grid` points to a valid [SPBitVec] - /// - `brightness_grid` is not written to or read from concurrently - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_brightness_grid_set(SPBrightnessGrid* brightness_grid, nuint x, nuint y, byte value); - /// - /// Sets the value of all cells in the [SPBrightnessGrid]. - /// - /// # Arguments - /// - /// - `brightness_grid`: instance to write to - /// - `value`: the value to set all cells to - /// - /// # Panics - /// - /// - when `brightness_grid` is NULL - /// - When providing an invalid brightness value - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `brightness_grid` points to a valid [SPBrightnessGrid] - /// - `brightness_grid` is not written to or read from concurrently - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_brightness_grid_fill(SPBrightnessGrid* brightness_grid, byte value); - /// - /// Gets the width of the [SPBrightnessGrid] instance. - /// - /// # Arguments - /// - /// - `brightness_grid`: instance to read from - /// - /// returns: width - /// - /// # Panics - /// - /// - when `brightness_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `brightness_grid` points to a valid [SPBrightnessGrid] - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern nuint sp_brightness_grid_width(SPBrightnessGrid* brightness_grid); - /// - /// Gets the height of the [SPBrightnessGrid] instance. - /// - /// # Arguments - /// - /// - `brightness_grid`: instance to read from - /// - /// returns: height - /// - /// # Panics - /// - /// - when `brightness_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `brightness_grid` points to a valid [SPBrightnessGrid] - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern nuint sp_brightness_grid_height(SPBrightnessGrid* brightness_grid); - /// - /// Gets an unsafe reference to the data of the [SPBrightnessGrid] instance. - /// - /// # Arguments - /// - /// - `brightness_grid`: instance to read from - /// - /// returns: slice of bytes underlying the `brightness_grid`. - /// - /// # Panics - /// - /// - when `brightness_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `brightness_grid` points to a valid [SPBrightnessGrid] - /// - the returned memory range is never accessed after the passed [SPBrightnessGrid] has been freed - /// - the returned memory range is never accessed concurrently, either via the [SPBrightnessGrid] or directly - /// [DllImport(__DllName, EntryPoint = "sp_brightness_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPByteSlice sp_brightness_grid_unsafe_data_ref(SPBrightnessGrid* brightness_grid); diff --git a/crates/servicepoint_binding_cs/ServicePoint/Command.g.cs b/crates/servicepoint_binding_cs/ServicePoint/Command.g.cs index 4749448..10aa5e4 100644 --- a/crates/servicepoint_binding_cs/ServicePoint/Command.g.cs +++ b/crates/servicepoint_binding_cs/ServicePoint/Command.g.cs @@ -14,67 +14,338 @@ namespace ServicePoint public unsafe sealed partial class Command: IDisposable { #nullable enable + /// + /// Tries to turn a [SPPacket] into a [SPCommand]. + /// + /// The packet is deallocated in the process. + /// + /// Returns: pointer to new [SPCommand] instance or NULL if parsing failed. + /// + /// # Panics + /// + /// - when `packet` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - [SPPacket] points to a valid instance of [SPPacket] + /// - [SPPacket] is not used concurrently or after this call + /// - the result is checked for NULL + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command? TryFromPacket(Packet packet) { var native = Command.sp_command_try_from_packet(packet.Instance); return native == null ? null : new Command(native); } + /// + /// Clones a [SPCommand] instance. + /// + /// returns: new [SPCommand] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `command` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `command` points to a valid instance of [SPCommand] + /// - `command` is not written to concurrently + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public Command Clone() { return new Command(Command.sp_command_clone(Instance)); } + /// + /// Set all pixels to the off state. + /// + /// Does not affect brightness. + /// + /// Returns: a new [Command::Clear] instance. Will never return NULL. + /// + /// # Examples + /// + /// ```C + /// sp_connection_send_command(connection, sp_command_clear()); + /// ``` + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command Clear() { return new Command(Command.sp_command_clear()); } + /// + /// Kills the udp daemon on the display, which usually results in a restart. + /// + /// Please do not send this in your normal program flow. + /// + /// Returns: a new [Command::HardReset] instance. Will never return NULL. + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command HardReset() { return new Command(Command.sp_command_hard_reset()); } + /// + /// A yet-to-be-tested command. + /// + /// Returns: a new `Command::FadeOut` instance. Will never return NULL. + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command FadeOut() { return new Command(Command.sp_command_fade_out()); } + /// + /// Set the brightness of all tiles to the same value. + /// + /// Returns: a new [Command::Brightness] instance. Will never return NULL. + /// + /// # Panics + /// + /// - When the provided brightness value is out of range (0-11). + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command Brightness(byte brightness) { return new Command(Command.sp_command_brightness(brightness)); } + /// + /// Set the brightness of individual tiles in a rectangular area of the display. + /// + /// The passed [SPBrightnessGrid] gets consumed. + /// + /// Returns: a new [Command::CharBrightness] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `grid` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `grid` points to a valid instance of [SPBrightnessGrid] + /// - `grid` is not used concurrently or after this call + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command CharBrightness(nuint x, nuint y, BrightnessGrid grid) { return new Command(Command.sp_command_char_brightness(x, y, grid.Instance)); } + /// + /// Set pixel data starting at the pixel offset on screen. + /// + /// The screen will continuously overwrite more pixel data without regarding the offset, meaning + /// once the starting row is full, overwriting will continue on column 0. + /// + /// The contained [SPBitVec] is always uncompressed. + /// + /// The passed [SPBitVec] gets consumed. + /// + /// Returns: a new [Command::BitmapLinear] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `bit_vec` is null + /// - when `compression_code` is not a valid value + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid instance of [SPBitVec] + /// - `bit_vec` is not used concurrently or after this call + /// - `compression` matches one of the allowed enum values + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command BitmapLinear(nuint offset, BitVec bit_vec, CompressionCode compression) { return new Command(Command.sp_command_bitmap_linear(offset, bit_vec.Instance, compression)); } + /// + /// Set pixel data according to an and-mask starting at the offset. + /// + /// The screen will continuously overwrite more pixel data without regarding the offset, meaning + /// once the starting row is full, overwriting will continue on column 0. + /// + /// The contained [SPBitVec] is always uncompressed. + /// + /// The passed [SPBitVec] gets consumed. + /// + /// Returns: a new [Command::BitmapLinearAnd] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `bit_vec` is null + /// - when `compression_code` is not a valid value + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid instance of [SPBitVec] + /// - `bit_vec` is not used concurrently or after this call + /// - `compression` matches one of the allowed enum values + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command BitmapLinearAnd(nuint offset, BitVec bit_vec, CompressionCode compression) { return new Command(Command.sp_command_bitmap_linear_and(offset, bit_vec.Instance, compression)); } + /// + /// Set pixel data according to an or-mask starting at the offset. + /// + /// The screen will continuously overwrite more pixel data without regarding the offset, meaning + /// once the starting row is full, overwriting will continue on column 0. + /// + /// The contained [SPBitVec] is always uncompressed. + /// + /// The passed [SPBitVec] gets consumed. + /// + /// Returns: a new [Command::BitmapLinearOr] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `bit_vec` is null + /// - when `compression_code` is not a valid value + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid instance of [SPBitVec] + /// - `bit_vec` is not used concurrently or after this call + /// - `compression` matches one of the allowed enum values + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command BitmapLinearOr(nuint offset, BitVec bit_vec, CompressionCode compression) { return new Command(Command.sp_command_bitmap_linear_or(offset, bit_vec.Instance, compression)); } + /// + /// Set pixel data according to a xor-mask starting at the offset. + /// + /// The screen will continuously overwrite more pixel data without regarding the offset, meaning + /// once the starting row is full, overwriting will continue on column 0. + /// + /// The contained [SPBitVec] is always uncompressed. + /// + /// The passed [SPBitVec] gets consumed. + /// + /// Returns: a new [Command::BitmapLinearXor] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `bit_vec` is null + /// - when `compression_code` is not a valid value + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bit_vec` points to a valid instance of [SPBitVec] + /// - `bit_vec` is not used concurrently or after this call + /// - `compression` matches one of the allowed enum values + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command BitmapLinearXor(nuint offset, BitVec bit_vec, CompressionCode compression) { return new Command(Command.sp_command_bitmap_linear_xor(offset, bit_vec.Instance, compression)); } + /// + /// Show text on the screen. + /// + /// The passed [SPCp437Grid] gets consumed. + /// + /// Returns: a new [Command::Cp437Data] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `grid` is null + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `grid` points to a valid instance of [SPCp437Grid] + /// - `grid` is not used concurrently or after this call + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command Cp437Data(nuint x, nuint y, Cp437Grid grid) { return new Command(Command.sp_command_cp437_data(x, y, grid.Instance)); } + /// + /// Sets a window of pixels to the specified values. + /// + /// The passed [SPBitmap] gets consumed. + /// + /// Returns: a new [Command::BitmapLinearWin] instance. Will never return NULL. + /// + /// # Panics + /// + /// - when `bitmap` is null + /// - when `compression_code` is not a valid value + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `bitmap` points to a valid instance of [SPBitmap] + /// - `bitmap` is not used concurrently or after this call + /// - `compression` matches one of the allowed enum values + /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_command_free`. + /// public static Command BitmapLinearWin(nuint x, nuint y, Bitmap bitmap, CompressionCode compression_code) { return new Command(Command.sp_command_bitmap_linear_win(x, y, bitmap.Instance, compression_code)); @@ -121,338 +392,45 @@ namespace ServicePoint const string __DllName = "servicepoint_binding_c"; #nullable restore - /// - /// Tries to turn a [SPPacket] into a [SPCommand]. - /// - /// The packet is deallocated in the process. - /// - /// Returns: pointer to new [SPCommand] instance or NULL if parsing failed. - /// - /// # Panics - /// - /// - when `packet` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - [SPPacket] points to a valid instance of [SPPacket] - /// - [SPPacket] is not used concurrently or after this call - /// - the result is checked for NULL - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_try_from_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_try_from_packet(SPPacket* packet); - /// - /// Clones a [SPCommand] instance. - /// - /// returns: new [SPCommand] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `command` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `command` points to a valid instance of [SPCommand] - /// - `command` is not written to concurrently - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_clone(SPCommand* command); - /// - /// Set all pixels to the off state. - /// - /// Does not affect brightness. - /// - /// Returns: a new [Command::Clear] instance. Will never return NULL. - /// - /// # Examples - /// - /// ```C - /// sp_connection_send_command(connection, sp_command_clear()); - /// ``` - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_clear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_clear(); - /// - /// Kills the udp daemon on the display, which usually results in a restart. - /// - /// Please do not send this in your normal program flow. - /// - /// Returns: a new [Command::HardReset] instance. Will never return NULL. - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_hard_reset", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_hard_reset(); - /// - /// A yet-to-be-tested command. - /// - /// Returns: a new `Command::FadeOut` instance. Will never return NULL. - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_fade_out", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_fade_out(); - /// - /// Set the brightness of all tiles to the same value. - /// - /// Returns: a new [Command::Brightness] instance. Will never return NULL. - /// - /// # Panics - /// - /// - When the provided brightness value is out of range (0-11). - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_brightness(byte brightness); - /// - /// Set the brightness of individual tiles in a rectangular area of the display. - /// - /// The passed [SPBrightnessGrid] gets consumed. - /// - /// Returns: a new [Command::CharBrightness] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `grid` points to a valid instance of [SPBrightnessGrid] - /// - `grid` is not used concurrently or after this call - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_char_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_char_brightness(nuint x, nuint y, SPBrightnessGrid* grid); - /// - /// Set pixel data starting at the pixel offset on screen. - /// - /// The screen will continuously overwrite more pixel data without regarding the offset, meaning - /// once the starting row is full, overwriting will continue on column 0. - /// - /// The contained [SPBitVec] is always uncompressed. - /// - /// The passed [SPBitVec] gets consumed. - /// - /// Returns: a new [Command::BitmapLinear] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `bit_vec` is null - /// - when `compression_code` is not a valid value - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid instance of [SPBitVec] - /// - `bit_vec` is not used concurrently or after this call - /// - `compression` matches one of the allowed enum values - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_bitmap_linear(nuint offset, SPBitVec* bit_vec, CompressionCode compression); - /// - /// Set pixel data according to an and-mask starting at the offset. - /// - /// The screen will continuously overwrite more pixel data without regarding the offset, meaning - /// once the starting row is full, overwriting will continue on column 0. - /// - /// The contained [SPBitVec] is always uncompressed. - /// - /// The passed [SPBitVec] gets consumed. - /// - /// Returns: a new [Command::BitmapLinearAnd] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `bit_vec` is null - /// - when `compression_code` is not a valid value - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid instance of [SPBitVec] - /// - `bit_vec` is not used concurrently or after this call - /// - `compression` matches one of the allowed enum values - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_and", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_bitmap_linear_and(nuint offset, SPBitVec* bit_vec, CompressionCode compression); - /// - /// Set pixel data according to an or-mask starting at the offset. - /// - /// The screen will continuously overwrite more pixel data without regarding the offset, meaning - /// once the starting row is full, overwriting will continue on column 0. - /// - /// The contained [SPBitVec] is always uncompressed. - /// - /// The passed [SPBitVec] gets consumed. - /// - /// Returns: a new [Command::BitmapLinearOr] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `bit_vec` is null - /// - when `compression_code` is not a valid value - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid instance of [SPBitVec] - /// - `bit_vec` is not used concurrently or after this call - /// - `compression` matches one of the allowed enum values - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_or", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_bitmap_linear_or(nuint offset, SPBitVec* bit_vec, CompressionCode compression); - /// - /// Set pixel data according to a xor-mask starting at the offset. - /// - /// The screen will continuously overwrite more pixel data without regarding the offset, meaning - /// once the starting row is full, overwriting will continue on column 0. - /// - /// The contained [SPBitVec] is always uncompressed. - /// - /// The passed [SPBitVec] gets consumed. - /// - /// Returns: a new [Command::BitmapLinearXor] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `bit_vec` is null - /// - when `compression_code` is not a valid value - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bit_vec` points to a valid instance of [SPBitVec] - /// - `bit_vec` is not used concurrently or after this call - /// - `compression` matches one of the allowed enum values - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_xor", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_bitmap_linear_xor(nuint offset, SPBitVec* bit_vec, CompressionCode compression); - /// - /// Show text on the screen. - /// - /// The passed [SPCp437Grid] gets consumed. - /// - /// Returns: a new [Command::Cp437Data] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `grid` is null - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `grid` points to a valid instance of [SPCp437Grid] - /// - `grid` is not used concurrently or after this call - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_cp437_data", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_cp437_data(nuint x, nuint y, SPCp437Grid* grid); - /// - /// Sets a window of pixels to the specified values. - /// - /// The passed [SPBitmap] gets consumed. - /// - /// Returns: a new [Command::BitmapLinearWin] instance. Will never return NULL. - /// - /// # Panics - /// - /// - when `bitmap` is null - /// - when `compression_code` is not a valid value - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `bitmap` points to a valid instance of [SPBitmap] - /// - `bitmap` is not used concurrently or after this call - /// - `compression` matches one of the allowed enum values - /// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_command_free`. - /// [DllImport(__DllName, EntryPoint = "sp_command_bitmap_linear_win", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCommand* sp_command_bitmap_linear_win(nuint x, nuint y, SPBitmap* bitmap, CompressionCode compression_code); - /// - /// Deallocates a [SPCommand]. - /// - /// # Examples - /// - /// ```C - /// SPCommand c = sp_command_clear(); - /// sp_command_free(c); - /// ``` - /// - /// # Panics - /// - /// - when `command` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `command` points to a valid [SPCommand] - /// - `command` is not used concurrently or after this call - /// - `command` was not passed to another consuming function, e.g. to create a [SPPacket] - /// [DllImport(__DllName, EntryPoint = "sp_command_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_command_free(SPCommand* command); diff --git a/crates/servicepoint_binding_cs/ServicePoint/Connection.g.cs b/crates/servicepoint_binding_cs/ServicePoint/Connection.g.cs index 07bccc0..543ebd5 100644 --- a/crates/servicepoint_binding_cs/ServicePoint/Connection.g.cs +++ b/crates/servicepoint_binding_cs/ServicePoint/Connection.g.cs @@ -14,17 +14,73 @@ namespace ServicePoint public unsafe sealed partial class Connection: IDisposable { #nullable enable + /// + /// 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`. + /// 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 + /// public bool SendPacket(Packet packet) { return Connection.sp_connection_send_packet(Instance, packet.Instance); } + /// + /// 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 + /// public bool SendCommand(Command command) { return Connection.sp_connection_send_command(Instance, command.Instance); @@ -71,87 +127,17 @@ namespace ServicePoint 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); diff --git a/crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.g.cs b/crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.g.cs index 13e1fa6..e47922d 100644 --- a/crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.g.cs +++ b/crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.g.cs @@ -14,43 +14,205 @@ namespace ServicePoint public unsafe sealed partial class Cp437Grid: IDisposable { #nullable enable + /// + /// Creates a new [SPCp437Grid] with the specified dimensions. + /// + /// returns: [SPCp437Grid] initialized to 0. Will never return NULL. + /// + /// # 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_cp437_grid_free`. + /// public Cp437Grid(nuint width, nuint height) : this(sp_cp437_grid_new(width, height)) {} + /// + /// Loads a [SPCp437Grid] with the specified dimensions from the provided data. + /// + /// Will never return NULL. + /// + /// # Panics + /// + /// - when `data` is NULL + /// - when the provided `data_length` does not match `height` and `width` + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `data` points to a valid memory location of at least `data_length` + /// bytes in size. + /// - the returned instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_cp437_grid_free`. + /// public static Cp437Grid Load(nuint width, nuint height, byte* data, nuint data_length) { return new Cp437Grid(Cp437Grid.sp_cp437_grid_load(width, height, data, data_length)); } + /// + /// Clones a [SPCp437Grid]. + /// + /// Will never return NULL. + /// + /// # Panics + /// + /// - when `cp437_grid` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `cp437_grid` points to a valid [SPCp437Grid] + /// - `cp437_grid` is not written to concurrently + /// - the returned instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_cp437_grid_free`. + /// public Cp437Grid Clone() { return new Cp437Grid(Cp437Grid.sp_cp437_grid_clone(Instance)); } + /// + /// Gets the current value at the specified position. + /// + /// # Arguments + /// + /// - `cp437_grid`: instance to read from + /// - `x` and `y`: position of the cell to read + /// + /// # Panics + /// + /// - when `cp437_grid` is NULL + /// - when accessing `x` or `y` out of bounds + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `cp437_grid` points to a valid [SPCp437Grid] + /// - `cp437_grid` is not written to concurrently + /// public byte Get(nuint x, nuint y) { return Cp437Grid.sp_cp437_grid_get(Instance, x, y); } + /// + /// Sets the value of the specified position in the [SPCp437Grid]. + /// + /// # Arguments + /// + /// - `cp437_grid`: instance to write to + /// - `x` and `y`: position of the cell + /// - `value`: the value to write to the cell + /// + /// returns: old value of the cell + /// + /// # Panics + /// + /// - when `cp437_grid` is NULL + /// - when accessing `x` or `y` out of bounds + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `cp437_grid` points to a valid [SPBitVec] + /// - `cp437_grid` is not written to or read from concurrently + /// public void Set(nuint x, nuint y, byte value) { Cp437Grid.sp_cp437_grid_set(Instance, x, y, value); } + /// + /// Sets the value of all cells in the [SPCp437Grid]. + /// + /// # Arguments + /// + /// - `cp437_grid`: instance to write to + /// - `value`: the value to set all cells to + /// + /// # Panics + /// + /// - when `cp437_grid` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `cp437_grid` points to a valid [SPCp437Grid] + /// - `cp437_grid` is not written to or read from concurrently + /// public void Fill(byte value) { Cp437Grid.sp_cp437_grid_fill(Instance, value); } + /// + /// Gets the width of the [SPCp437Grid] instance. + /// + /// # Arguments + /// + /// - `cp437_grid`: instance to read from + /// + /// # Panics + /// + /// - when `cp437_grid` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `cp437_grid` points to a valid [SPCp437Grid] + /// public nuint Width() { return Cp437Grid.sp_cp437_grid_width(Instance); } + /// + /// Gets the height of the [SPCp437Grid] instance. + /// + /// # Arguments + /// + /// - `cp437_grid`: instance to read from + /// + /// # Panics + /// + /// - when `cp437_grid` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `cp437_grid` points to a valid [SPCp437Grid] + /// public nuint Height() { return Cp437Grid.sp_cp437_grid_height(Instance); } + /// + /// Gets an unsafe reference to the data of the [SPCp437Grid] instance. + /// + /// Will never return NULL. + /// + /// # Panics + /// + /// - when `cp437_grid` is NULL + /// + /// ## Safety + /// + /// The caller has to make sure that: + /// + /// - `cp437_grid` points to a valid [SPCp437Grid] + /// - the returned memory range is never accessed after the passed [SPCp437Grid] has been freed + /// - the returned memory range is never accessed concurrently, either via the [SPCp437Grid] or directly + /// public SPByteSlice UnsafeDataRef() { return Cp437Grid.sp_cp437_grid_unsafe_data_ref(Instance); @@ -97,210 +259,33 @@ namespace ServicePoint const string __DllName = "servicepoint_binding_c"; #nullable restore - /// - /// Creates a new [SPCp437Grid] with the specified dimensions. - /// - /// returns: [SPCp437Grid] initialized to 0. Will never return NULL. - /// - /// # 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_cp437_grid_free`. - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCp437Grid* sp_cp437_grid_new(nuint width, nuint height); - /// - /// Loads a [SPCp437Grid] with the specified dimensions from the provided data. - /// - /// Will never return NULL. - /// - /// # Panics - /// - /// - when `data` is NULL - /// - when the provided `data_length` does not match `height` and `width` - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `data` points to a valid memory location of at least `data_length` - /// bytes in size. - /// - the returned instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_cp437_grid_free`. - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCp437Grid* sp_cp437_grid_load(nuint width, nuint height, byte* data, nuint data_length); - /// - /// Clones a [SPCp437Grid]. - /// - /// Will never return NULL. - /// - /// # Panics - /// - /// - when `cp437_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `cp437_grid` points to a valid [SPCp437Grid] - /// - `cp437_grid` is not written to concurrently - /// - the returned instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_cp437_grid_free`. - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPCp437Grid* sp_cp437_grid_clone(SPCp437Grid* cp437_grid); - /// - /// Deallocates a [SPCp437Grid]. - /// - /// # Panics - /// - /// - when `cp437_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `cp437_grid` points to a valid [SPCp437Grid] - /// - `cp437_grid` is not used concurrently or after cp437_grid call - /// - `cp437_grid` was not passed to another consuming function, e.g. to create a [SPCommand] - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_cp437_grid_free(SPCp437Grid* cp437_grid); - /// - /// Gets the current value at the specified position. - /// - /// # Arguments - /// - /// - `cp437_grid`: instance to read from - /// - `x` and `y`: position of the cell to read - /// - /// # Panics - /// - /// - when `cp437_grid` is NULL - /// - when accessing `x` or `y` out of bounds - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `cp437_grid` points to a valid [SPCp437Grid] - /// - `cp437_grid` is not written to concurrently - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern byte sp_cp437_grid_get(SPCp437Grid* cp437_grid, nuint x, nuint y); - /// - /// Sets the value of the specified position in the [SPCp437Grid]. - /// - /// # Arguments - /// - /// - `cp437_grid`: instance to write to - /// - `x` and `y`: position of the cell - /// - `value`: the value to write to the cell - /// - /// returns: old value of the cell - /// - /// # Panics - /// - /// - when `cp437_grid` is NULL - /// - when accessing `x` or `y` out of bounds - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `cp437_grid` points to a valid [SPBitVec] - /// - `cp437_grid` is not written to or read from concurrently - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_cp437_grid_set(SPCp437Grid* cp437_grid, nuint x, nuint y, byte value); - /// - /// Sets the value of all cells in the [SPCp437Grid]. - /// - /// # Arguments - /// - /// - `cp437_grid`: instance to write to - /// - `value`: the value to set all cells to - /// - /// # Panics - /// - /// - when `cp437_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `cp437_grid` points to a valid [SPCp437Grid] - /// - `cp437_grid` is not written to or read from concurrently - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_cp437_grid_fill(SPCp437Grid* cp437_grid, byte value); - /// - /// Gets the width of the [SPCp437Grid] instance. - /// - /// # Arguments - /// - /// - `cp437_grid`: instance to read from - /// - /// # Panics - /// - /// - when `cp437_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `cp437_grid` points to a valid [SPCp437Grid] - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern nuint sp_cp437_grid_width(SPCp437Grid* cp437_grid); - /// - /// Gets the height of the [SPCp437Grid] instance. - /// - /// # Arguments - /// - /// - `cp437_grid`: instance to read from - /// - /// # Panics - /// - /// - when `cp437_grid` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `cp437_grid` points to a valid [SPCp437Grid] - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern nuint sp_cp437_grid_height(SPCp437Grid* cp437_grid); - /// - /// Gets an unsafe reference to the data of the [SPCp437Grid] instance. - /// - /// Will never return NULL. - /// - /// # Panics - /// - /// - when `cp437_grid` is NULL - /// - /// ## Safety - /// - /// The caller has to make sure that: - /// - /// - `cp437_grid` points to a valid [SPCp437Grid] - /// - the returned memory range is never accessed after the passed [SPCp437Grid] has been freed - /// - the returned memory range is never accessed concurrently, either via the [SPCp437Grid] or directly - /// [DllImport(__DllName, EntryPoint = "sp_cp437_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPByteSlice sp_cp437_grid_unsafe_data_ref(SPCp437Grid* cp437_grid); diff --git a/crates/servicepoint_binding_cs/ServicePoint/Packet.g.cs b/crates/servicepoint_binding_cs/ServicePoint/Packet.g.cs index ceaa982..ab6014c 100644 --- a/crates/servicepoint_binding_cs/ServicePoint/Packet.g.cs +++ b/crates/servicepoint_binding_cs/ServicePoint/Packet.g.cs @@ -14,17 +14,72 @@ namespace ServicePoint public unsafe sealed partial class Packet: IDisposable { #nullable enable + /// + /// Turns a [SPCommand] into a [SPPacket]. + /// The [SPCommand] gets consumed. + /// + /// Will never return NULL. + /// + /// # Panics + /// + /// - when `command` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - [SPCommand] points to a valid instance of [SPCommand] + /// - [SPCommand] is not used concurrently or after this call + /// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_packet_free`. + /// public static Packet FromCommand(Command command) { return new Packet(Packet.sp_packet_from_command(command.Instance)); } + /// + /// Tries to load a [SPPacket] from the passed array with the specified length. + /// + /// returns: NULL in case of an error, pointer to the allocated packet otherwise + /// + /// # Panics + /// + /// - when `data` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `data` points to a valid memory region of at least `length` bytes + /// - `data` is not written to concurrently + /// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_packet_free`. + /// public static Packet? TryLoad(byte* data, nuint length) { var native = Packet.sp_packet_try_load(data, length); return native == null ? null : new Packet(native); } + /// + /// Clones a [SPPacket]. + /// + /// Will never return NULL. + /// + /// # Panics + /// + /// - when `packet` is NULL + /// + /// # Safety + /// + /// The caller has to make sure that: + /// + /// - `packet` points to a valid [SPPacket] + /// - `packet` is not written to concurrently + /// - the returned instance is freed in some way, either by using a consuming function or + /// by explicitly calling `sp_packet_free`. + /// public Packet Clone() { return new Packet(Packet.sp_packet_clone(Instance)); @@ -71,84 +126,15 @@ namespace ServicePoint const string __DllName = "servicepoint_binding_c"; #nullable restore - /// - /// Turns a [SPCommand] into a [SPPacket]. - /// The [SPCommand] gets consumed. - /// - /// Will never return NULL. - /// - /// # Panics - /// - /// - when `command` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - [SPCommand] points to a valid instance of [SPCommand] - /// - [SPCommand] is not used concurrently or after this call - /// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_packet_free`. - /// [DllImport(__DllName, EntryPoint = "sp_packet_from_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPPacket* sp_packet_from_command(SPCommand* command); - /// - /// Tries to load a [SPPacket] from the passed array with the specified length. - /// - /// returns: NULL in case of an error, pointer to the allocated packet otherwise - /// - /// # Panics - /// - /// - when `data` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `data` points to a valid memory region of at least `length` bytes - /// - `data` is not written to concurrently - /// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_packet_free`. - /// [DllImport(__DllName, EntryPoint = "sp_packet_try_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPPacket* sp_packet_try_load(byte* data, nuint length); - /// - /// Clones a [SPPacket]. - /// - /// Will never return NULL. - /// - /// # Panics - /// - /// - when `packet` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `packet` points to a valid [SPPacket] - /// - `packet` is not written to concurrently - /// - the returned instance is freed in some way, either by using a consuming function or - /// by explicitly calling `sp_packet_free`. - /// [DllImport(__DllName, EntryPoint = "sp_packet_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern SPPacket* sp_packet_clone(SPPacket* packet); - /// - /// Deallocates a [SPPacket]. - /// - /// # Panics - /// - /// - when `sp_packet_free` is NULL - /// - /// # Safety - /// - /// The caller has to make sure that: - /// - /// - `packet` points to a valid [SPPacket] - /// - `packet` is not used concurrently or after this call - /// [DllImport(__DllName, EntryPoint = "sp_packet_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void sp_packet_free(SPPacket* packet); diff --git a/crates/servicepoint_binding_cs/build.rs b/crates/servicepoint_binding_cs/build.rs index edb2fbc..caa22d6 100644 --- a/crates/servicepoint_binding_cs/build.rs +++ b/crates/servicepoint_binding_cs/build.rs @@ -47,8 +47,7 @@ fn main() { "SPBrightnessGrid", ) .csharp_type_rename(move |name| { - if name == "SPCompressionCode" - { + if name == "SPCompressionCode" { "CompressionCode".to_string() } else { name