From 12ba47a281644b35cac7ea9c582d36c6f5b621b5 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Wed, 13 Nov 2024 19:37:48 +0100 Subject: [PATCH] remove servicepoint_binding_cs --- Cargo.toml | 1 - crates/servicepoint_binding_cs/Cargo.toml | 20 - crates/servicepoint_binding_cs/README.md | 65 - .../servicepoint_binding_cs/ServicePoint.sln | 28 - .../ServicePoint/BindGen/ServicePoint.g.cs | 1463 ----------------- .../ServicePoint/BitVec.cs | 88 - .../ServicePoint/Bitmap.cs | 100 -- .../ServicePoint/BrightnessGrid.cs | 100 -- .../ServicePoint/Command.cs | 129 -- .../ServicePoint/Connection.cs | 40 - .../ServicePoint/Constants.cs | 24 - .../ServicePoint/Cp437Grid.cs | 131 -- .../ServicePoint/GlobalUsings.cs | 1 - .../ServicePoint/Packet.cs | 36 - .../ServicePoint/ServicePoint.csproj | 57 - .../ServicePoint/ServicePointExtensions.cs | 16 - .../ServicePoint/SpNativeInstance.cs | 51 - crates/servicepoint_binding_cs/build.rs | 39 - .../examples/lang_cs/Program.cs | 20 - .../examples/lang_cs/lang_cs.csproj | 15 - crates/servicepoint_binding_cs/src/lib.rs | 1 - 21 files changed, 2425 deletions(-) delete mode 100644 crates/servicepoint_binding_cs/Cargo.toml delete mode 100644 crates/servicepoint_binding_cs/README.md delete mode 100644 crates/servicepoint_binding_cs/ServicePoint.sln delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/BindGen/ServicePoint.g.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/BitVec.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/Bitmap.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/BrightnessGrid.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/Command.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/Connection.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/Constants.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/GlobalUsings.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/Packet.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/ServicePoint.csproj delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/ServicePointExtensions.cs delete mode 100644 crates/servicepoint_binding_cs/ServicePoint/SpNativeInstance.cs delete mode 100644 crates/servicepoint_binding_cs/build.rs delete mode 100644 crates/servicepoint_binding_cs/examples/lang_cs/Program.cs delete mode 100644 crates/servicepoint_binding_cs/examples/lang_cs/lang_cs.csproj delete mode 100644 crates/servicepoint_binding_cs/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 9bc62fc..ddc5168 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ resolver = "2" members = [ "crates/servicepoint", "crates/servicepoint_binding_c", - "crates/servicepoint_binding_cs", "crates/servicepoint_binding_c/examples/lang_c" ] diff --git a/crates/servicepoint_binding_cs/Cargo.toml b/crates/servicepoint_binding_cs/Cargo.toml deleted file mode 100644 index 01282ac..0000000 --- a/crates/servicepoint_binding_cs/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "servicepoint_binding_cs" -version.workspace = true -edition = "2021" -publish = false -readme = "README.md" - -[lib] -crate-type = ["cdylib"] -test = false - -[build-dependencies] -csbindgen = "1.9.3" - -[dependencies] -servicepoint_binding_c = { version = "0.11.0", path = "../servicepoint_binding_c" } -servicepoint = { version = "0.11.0", path = "../servicepoint" } - -[lints] -workspace = true diff --git a/crates/servicepoint_binding_cs/README.md b/crates/servicepoint_binding_cs/README.md deleted file mode 100644 index bd2107a..0000000 --- a/crates/servicepoint_binding_cs/README.md +++ /dev/null @@ -1,65 +0,0 @@ -# ServicePoint - -In [CCCB](https://berlin.ccc.de/), there is a big pixel matrix hanging on the wall. It is called "Service Point -Display" or "Airport Display". -This crate contains C# bindings for the `servicepoint` library, enabling users to parse, encode and send packets to this display via UDP. - -## Examples - -```csharp -using ServicePoint; - -// using statement calls Dispose() on scope exit, which frees unmanaged instances -using var connection = Connection.Open("127.0.0.1:2342"); -using var pixels = Bitmap.New(Constants.PixelWidth, Constants.PixelHeight); - -while (true) -{ - pixels.Fill(true); - connection.Send(Command.BitmapLinearWin(0, 0, pixels.Clone())); - Thread.Sleep(5000); - - pixels.Fill(false); - connection.Send(Command.BitmapLinearWin(0, 0, pixels.Clone())); - Thread.Sleep(5000); -} -``` - -A full example including project files is available as part of this crate. - -## Note on stability - -This library is still in early development. -You can absolutely use it, and it works, but expect minor breaking changes with every version bump. - -## Installation - -NuGet packages are not a good way to distribute native projects ([relevant issue](https://github.com/dotnet/sdk/issues/33845)). -Because of that, there is no NuGet package you can use directly. -Including this repository as a submodule and building from source is the recommended way of using the library. - -```bash -git submodule add https://github.com/cccb/servicepoint.git -git commit -m "add servicepoint submodule" -``` - -You can now reference `servicepoint-bindings-cs/src/ServicePoint.csproj` in your project. -The rust library will automatically be built. - -Please provide more information in the form of an issue if you need the build to copy a different library file for your platform. - -## Notes on differences to rust library - -Uses C bindings internally to provide a similar API to rust. Things to keep in mind: - -- You will get a `NullPointerException` when trying to call a method where the native instance has been consumed already (e.g. when `Send`ing a command instance twice). Send a clone instead of the original if you want to keep using it. -- Some lower-level APIs _will_ panic in native code when used improperly. - Example: manipulating the `Span` of an object after freeing the instance. -- C# specifics are documented in the library. Use the rust documentation for everything else. Naming and semantics are the same apart from CamelCase instead of kebab_case. -- You will only get rust backtraces in debug builds of the native code. -- F# is not explicitly tested. If there are usability or functionality problems, please open an issue. -- Reading and writing to instances concurrently is not safe. Only reading concurrently is safe. - -## Everything else - -Look at the main project [README](https://github.com/cccb/servicepoint/blob/main/README.md) for further information. diff --git a/crates/servicepoint_binding_cs/ServicePoint.sln b/crates/servicepoint_binding_cs/ServicePoint.sln deleted file mode 100644 index c4d9165..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicePoint", "ServicePoint/ServicePoint.csproj", "{70EFFA3F-012A-4518-9627-466BEAE4252E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lang-cs", "examples/lang_cs/lang_cs.csproj", "{DA3B8B6E-993A-47DA-844B-F92AF520FF59}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{C2F8EC4A-2426-4DC3-990F-C43810B183F5}" - ProjectSection(SolutionItems) = preProject - ..\..\shell.nix = ..\..\shell.nix - ..\..\.envrc = ..\..\.envrc - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {70EFFA3F-012A-4518-9627-466BEAE4252E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {70EFFA3F-012A-4518-9627-466BEAE4252E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {70EFFA3F-012A-4518-9627-466BEAE4252E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {70EFFA3F-012A-4518-9627-466BEAE4252E}.Release|Any CPU.Build.0 = Release|Any CPU - {DA3B8B6E-993A-47DA-844B-F92AF520FF59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DA3B8B6E-993A-47DA-844B-F92AF520FF59}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DA3B8B6E-993A-47DA-844B-F92AF520FF59}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DA3B8B6E-993A-47DA-844B-F92AF520FF59}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/crates/servicepoint_binding_cs/ServicePoint/BindGen/ServicePoint.g.cs b/crates/servicepoint_binding_cs/ServicePoint/BindGen/ServicePoint.g.cs deleted file mode 100644 index 8f41ab4..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/BindGen/ServicePoint.g.cs +++ /dev/null @@ -1,1463 +0,0 @@ -// -// 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.BindGen -{ - public static unsafe partial class NativeMethods - { - const string __DllName = "servicepoint_binding_c"; - - public const byte SP_BRIGHTNESS_MIN = 0; - public const byte SP_BRIGHTNESS_MAX = 11; - public const byte SP_BRIGHTNESS_LEVELS = 12; - public const nuint SP_TILE_SIZE = 8; - public const nuint SP_TILE_WIDTH = 56; - public const nuint SP_TILE_HEIGHT = 20; - - - /// - /// 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)] - public static extern Bitmap* 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)] - public static extern Bitmap* 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)] - public static extern Bitmap* sp_bitmap_clone(Bitmap* 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] - /// - /// [SPCommand]: [crate::SPCommand] - /// - [DllImport(__DllName, EntryPoint = "sp_bitmap_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void sp_bitmap_free(Bitmap* 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)] - public static extern bool sp_bitmap_get(Bitmap* 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)] - public static extern void sp_bitmap_set(Bitmap* 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)] - public static extern void sp_bitmap_fill(Bitmap* 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)] - public static extern nuint sp_bitmap_width(Bitmap* 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)] - public static extern nuint sp_bitmap_height(Bitmap* 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)] - public static extern ByteSlice sp_bitmap_unsafe_data_ref(Bitmap* bitmap); - - /// - /// 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)] - public static extern BitVec* 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)] - public static extern BitVec* 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)] - public static extern BitVec* sp_bitvec_clone(BitVec* 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] - /// - /// [SPCommand]: [crate::SPCommand] - /// - [DllImport(__DllName, EntryPoint = "sp_bitvec_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void sp_bitvec_free(BitVec* 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)] - public static extern bool sp_bitvec_get(BitVec* 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)] - public static extern void sp_bitvec_set(BitVec* 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)] - public static extern void sp_bitvec_fill(BitVec* 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)] - public static extern nuint sp_bitvec_len(BitVec* 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)] - public static extern bool sp_bitvec_is_empty(BitVec* 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)] - public static extern ByteSlice sp_bitvec_unsafe_data_ref(BitVec* bit_vec); - - /// - /// 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)] - public static extern BrightnessGrid* 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)] - public static extern BrightnessGrid* 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)] - public static extern BrightnessGrid* sp_brightness_grid_clone(BrightnessGrid* 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] - /// - /// [SPCommand]: [crate::SPCommand] - /// - [DllImport(__DllName, EntryPoint = "sp_brightness_grid_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void sp_brightness_grid_free(BrightnessGrid* 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)] - public static extern byte sp_brightness_grid_get(BrightnessGrid* 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 [SPBrightnessGrid] - /// - `brightness_grid` is not written to or read from concurrently - /// - [DllImport(__DllName, EntryPoint = "sp_brightness_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void sp_brightness_grid_set(BrightnessGrid* 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)] - public static extern void sp_brightness_grid_fill(BrightnessGrid* 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)] - public static extern nuint sp_brightness_grid_width(BrightnessGrid* 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)] - public static extern nuint sp_brightness_grid_height(BrightnessGrid* 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)] - public static extern ByteSlice sp_brightness_grid_unsafe_data_ref(BrightnessGrid* brightness_grid); - - /// - /// 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)] - public static extern Command* sp_command_try_from_packet(Packet* 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)] - public static extern Command* sp_command_clone(Command* command); - - /// - /// Set all pixels to the off state. - /// - /// Does not affect brightness. - /// - /// Returns: a new [servicepoint::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)] - public static extern 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 [servicepoint::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)] - public static extern Command* sp_command_hard_reset(); - - /// - /// A yet-to-be-tested command. - /// - /// Returns: a new [servicepoint::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)] - public static extern Command* sp_command_fade_out(); - - /// - /// Set the brightness of all tiles to the same value. - /// - /// Returns: a new [servicepoint::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)] - public static extern Command* 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 [servicepoint::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)] - public static extern Command* sp_command_char_brightness(nuint x, nuint y, BrightnessGrid* 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 [servicepoint::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)] - public static extern Command* sp_command_bitmap_linear(nuint offset, BitVec* 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 [servicepoint::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)] - public static extern Command* sp_command_bitmap_linear_and(nuint offset, BitVec* 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 [servicepoint::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)] - public static extern Command* sp_command_bitmap_linear_or(nuint offset, BitVec* 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 [servicepoint::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)] - public static extern Command* sp_command_bitmap_linear_xor(nuint offset, BitVec* bit_vec, CompressionCode compression); - - /// - /// Show text on the screen. - /// - /// The passed [SPCp437Grid] gets consumed. - /// - /// Returns: a new [servicepoint::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)] - public static extern Command* sp_command_cp437_data(nuint x, nuint y, Cp437Grid* grid); - - /// - /// Sets a window of pixels to the specified values. - /// - /// The passed [SPBitmap] gets consumed. - /// - /// Returns: a new [servicepoint::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)] - public static extern Command* sp_command_bitmap_linear_win(nuint x, nuint y, Bitmap* 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)] - public static extern void sp_command_free(Command* command); - - /// - /// 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)] - public static extern Connection* 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)] - public static extern bool sp_connection_send_packet(Connection* connection, Packet* 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)] - public static extern bool sp_connection_send_command(Connection* connection, Command* 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)] - public static extern void sp_connection_free(Connection* connection); - - /// - /// 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)] - public static extern Cp437Grid* 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)] - public static extern Cp437Grid* 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)] - public static extern Cp437Grid* sp_cp437_grid_clone(Cp437Grid* 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] - /// - /// [SPCommand]: [crate::SPCommand] - /// - [DllImport(__DllName, EntryPoint = "sp_cp437_grid_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void sp_cp437_grid_free(Cp437Grid* 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)] - public static extern byte sp_cp437_grid_get(Cp437Grid* 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 - /// - /// [SPBitVec]: [crate::SPBitVec] - /// - [DllImport(__DllName, EntryPoint = "sp_cp437_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void sp_cp437_grid_set(Cp437Grid* 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)] - public static extern void sp_cp437_grid_fill(Cp437Grid* 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)] - public static extern nuint sp_cp437_grid_width(Cp437Grid* 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)] - public static extern nuint sp_cp437_grid_height(Cp437Grid* 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)] - public static extern ByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid* cp437_grid); - - /// - /// 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)] - public static extern Packet* sp_packet_from_command(Command* 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)] - public static extern Packet* 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)] - public static extern Packet* sp_packet_clone(Packet* 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)] - public static extern void sp_packet_free(Packet* packet); - - - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe partial struct Bitmap - { - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe partial struct BitVec - { - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe partial struct BrightnessGrid - { - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe partial struct ByteSlice - { - public byte* start; - public nuint length; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe partial struct Command - { - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe partial struct Connection - { - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe partial struct Cp437Grid - { - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe partial struct Packet - { - } - - - public enum CompressionCode : ushort - { - Uncompressed = 0, - Zlib = 26490, - Bzip2 = 25210, - Lzma = 27770, - Zstd = 31347, - } - - -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs b/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs deleted file mode 100644 index ab697e0..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs +++ /dev/null @@ -1,88 +0,0 @@ -using ServicePoint.BindGen; - -namespace ServicePoint; - -public sealed class BitVec : SpNativeInstance -{ - public static BitVec New(int size) - { - unsafe - { - return new BitVec(NativeMethods.sp_bitvec_new((nuint)size)); - } - } - - public static BitVec Load(Span bytes) - { - unsafe - { - fixed (byte* bytesPtr = bytes) - { - return new BitVec(NativeMethods.sp_bitvec_load(bytesPtr, (nuint)bytes.Length)); - } - } - } - - public BitVec Clone() - { - unsafe - { - return new BitVec(NativeMethods.sp_bitvec_clone(Instance)); - } - } - - public bool this[int index] - { - get - { - unsafe - { - return NativeMethods.sp_bitvec_get(Instance, (nuint)index); - } - } - set - { - unsafe - { - NativeMethods.sp_bitvec_set(Instance, (nuint)index, value); - } - } - } - - public void Fill(bool value) - { - unsafe - { - NativeMethods.sp_bitvec_fill(Instance, value); - } - } - - public int Length - { - get - { - unsafe - { - return (int)NativeMethods.sp_bitvec_len(Instance); - } - } - } - - public Span Data - { - get - { - unsafe - { - var slice = NativeMethods.sp_bitvec_unsafe_data_ref(Instance); - return new Span(slice.start, (int)slice.length); - } - } - } - - private unsafe BitVec(BindGen.BitVec* instance) : base(instance) - { - } - - private protected override unsafe void Free() => NativeMethods.sp_bitvec_free(Instance); -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/Bitmap.cs b/crates/servicepoint_binding_cs/ServicePoint/Bitmap.cs deleted file mode 100644 index 6747483..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/Bitmap.cs +++ /dev/null @@ -1,100 +0,0 @@ -using ServicePoint.BindGen; - -namespace ServicePoint; - -public sealed class Bitmap : SpNativeInstance -{ - public static Bitmap New(int width, int height) - { - unsafe - { - return new Bitmap(NativeMethods.sp_bitmap_new((nuint)width, (nuint)height)); - } - } - - public static Bitmap Load(int width, int height, Span bytes) - { - unsafe - { - fixed (byte* bytesPtr = bytes) - { - return new Bitmap(NativeMethods.sp_bitmap_load((nuint)width, (nuint)height, bytesPtr, - (nuint)bytes.Length)); - } - } - } - - public Bitmap Clone() - { - unsafe - { - return new Bitmap(NativeMethods.sp_bitmap_clone(Instance)); - } - } - - public bool this[int x, int y] - { - get - { - unsafe - { - return NativeMethods.sp_bitmap_get(Instance, (nuint)x, (nuint)y); - } - } - set - { - unsafe - { - NativeMethods.sp_bitmap_set(Instance, (nuint)x, (nuint)y, value); - } - } - } - - public void Fill(bool value) - { - unsafe - { - NativeMethods.sp_bitmap_fill(Instance, value); - } - } - - public int Width - { - get - { - unsafe - { - return (int)NativeMethods.sp_bitmap_width(Instance); - } - } - } - - public int Height - { - get - { - unsafe - { - return (int)NativeMethods.sp_bitmap_height(Instance); - } - } - } - - public Span Data - { - get - { - unsafe - { - var slice = NativeMethods.sp_bitmap_unsafe_data_ref(Instance); - return new Span(slice.start, (int)slice.length); - } - } - } - - private unsafe Bitmap(BindGen.Bitmap* instance) : base(instance) - { - } - - private protected override unsafe void Free() => NativeMethods.sp_bitmap_free(Instance); -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/BrightnessGrid.cs b/crates/servicepoint_binding_cs/ServicePoint/BrightnessGrid.cs deleted file mode 100644 index 53970b5..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/BrightnessGrid.cs +++ /dev/null @@ -1,100 +0,0 @@ -using ServicePoint.BindGen; - -namespace ServicePoint; - -public sealed class BrightnessGrid : SpNativeInstance -{ - public static BrightnessGrid New(int width, int height) - { - unsafe - { - return new BrightnessGrid(NativeMethods.sp_brightness_grid_new((nuint)width, (nuint)height)); - } - } - - public static BrightnessGrid Load(int width, int height, Span bytes) - { - unsafe - { - fixed (byte* bytesPtr = bytes) - { - return new BrightnessGrid(NativeMethods.sp_brightness_grid_load((nuint)width, (nuint)height, bytesPtr, - (nuint)bytes.Length)); - } - } - } - - public BrightnessGrid Clone() - { - unsafe - { - return new BrightnessGrid(NativeMethods.sp_brightness_grid_clone(Instance)); - } - } - - public byte this[int x, int y] - { - get - { - unsafe - { - return NativeMethods.sp_brightness_grid_get(Instance, (nuint)x, (nuint)y); - } - } - set - { - unsafe - { - NativeMethods.sp_brightness_grid_set(Instance, (nuint)x, (nuint)y, value); - } - } - } - - public void Fill(byte value) - { - unsafe - { - NativeMethods.sp_brightness_grid_fill(Instance, value); - } - } - - public int Width - { - get - { - unsafe - { - return (int)NativeMethods.sp_brightness_grid_width(Instance); - } - } - } - - public int Height - { - get - { - unsafe - { - return (int)NativeMethods.sp_brightness_grid_height(Instance); - } - } - } - - public Span Data - { - get - { - unsafe - { - var slice = NativeMethods.sp_brightness_grid_unsafe_data_ref(Instance); - return new Span(slice.start, (int)slice.length); - } - } - } - - private unsafe BrightnessGrid(BindGen.BrightnessGrid* instance) : base(instance) - { - } - - private protected override unsafe void Free() => NativeMethods.sp_brightness_grid_free(Instance); -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/Command.cs b/crates/servicepoint_binding_cs/ServicePoint/Command.cs deleted file mode 100644 index b62d511..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/Command.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using ServicePoint.BindGen; - -namespace ServicePoint; - -public sealed class Command : SpNativeInstance -{ - public static bool TryFromPacket(Packet packet, [MaybeNullWhen(false)] out Command command) - { - unsafe - { - var result = NativeMethods.sp_command_try_from_packet(packet.Into()); - if (result == null) - { - command = null; - return false; - } - - command = new Command(result); - return true; - } - } - - public Command Clone() - { - unsafe - { - return new Command(NativeMethods.sp_command_clone(Instance)); - } - } - - public static Command Clear() - { - unsafe - { - return new Command(NativeMethods.sp_command_clear()); - } - } - - public static Command HardReset() - { - unsafe - { - return new Command(NativeMethods.sp_command_hard_reset()); - } - } - - public static Command FadeOut() - { - unsafe - { - return new Command(NativeMethods.sp_command_fade_out()); - } - } - - public static Command Brightness(byte brightness) - { - unsafe - { - return new Command(NativeMethods.sp_command_brightness(brightness)); - } - } - - public static Command CharBrightness(int x, int y, BrightnessGrid grid) - { - unsafe - { - return new Command(NativeMethods.sp_command_char_brightness((ushort)x, (ushort)y, grid.Into())); - } - } - - public static Command BitmapLinear(int offset, BitVec bitVec, CompressionCode compressionCode) - { - unsafe - { - return new Command( - NativeMethods.sp_command_bitmap_linear((ushort)offset, bitVec.Into(), compressionCode)); - } - } - - public static Command BitmapLinearAnd(int offset, BitVec bitVec, CompressionCode compressionCode) - { - unsafe - { - return new Command( - NativeMethods.sp_command_bitmap_linear_and((ushort)offset, bitVec.Into(), compressionCode)); - } - } - - public static Command BitmapLinearOr(int offset, BitVec bitVec, CompressionCode compressionCode) - { - unsafe - { - return new Command( - NativeMethods.sp_command_bitmap_linear_or((ushort)offset, bitVec.Into(), compressionCode)); - } - } - - public static Command BitmapLinearXor(int offset, BitVec bitVec, CompressionCode compressionCode) - { - unsafe - { - return new Command( - NativeMethods.sp_command_bitmap_linear_xor((ushort)offset, bitVec.Into(), compressionCode)); - } - } - - public static Command BitmapLinearWin(int x, int y, Bitmap bitmap, CompressionCode compression) - { - unsafe - { - return new Command(NativeMethods.sp_command_bitmap_linear_win((ushort)x, (ushort)y, bitmap.Into(), compression)); - } - } - - public static Command Cp437Data(int x, int y, Cp437Grid byteGrid) - { - unsafe - { - return new Command(NativeMethods.sp_command_cp437_data((ushort)x, (ushort)y, byteGrid.Into())); - } - } - - private unsafe Command(BindGen.Command* instance) : base(instance) - { - } - - private protected override unsafe void Free() => NativeMethods.sp_command_free(Instance); -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/Connection.cs b/crates/servicepoint_binding_cs/ServicePoint/Connection.cs deleted file mode 100644 index eff3b32..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/Connection.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Text; -using ServicePoint.BindGen; - -namespace ServicePoint; - -public sealed class Connection : SpNativeInstance -{ - public static Connection Open(string host) - { - unsafe - { - fixed (byte* bytePtr = Encoding.UTF8.GetBytes(host)) - { - return new Connection(NativeMethods.sp_connection_open(bytePtr)); - } - } - } - - public bool Send(Packet packet) - { - unsafe - { - return NativeMethods.sp_connection_send_packet(Instance, packet.Into()); - } - } - - public bool Send(Command command) - { - unsafe - { - return NativeMethods.sp_connection_send_command(Instance, command.Into()); - } - } - - private protected override unsafe void Free() => NativeMethods.sp_connection_free(Instance); - - private unsafe Connection(BindGen.Connection* instance) : base(instance) - { - } -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/Constants.cs b/crates/servicepoint_binding_cs/ServicePoint/Constants.cs deleted file mode 100644 index 14ea940..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/Constants.cs +++ /dev/null @@ -1,24 +0,0 @@ -using ServicePoint.BindGen; - -namespace ServicePoint; - -public static class Constants -{ - /// size of a single tile in one dimension - public const nuint TileSize = NativeMethods.SP_TILE_SIZE; - - /// tile count in the x-direction - public const nuint TileWidth = NativeMethods.SP_TILE_WIDTH; - - /// tile count in the y-direction - public const nuint TileHeight = NativeMethods.SP_TILE_SIZE; - - /// screen width in pixels - public const nuint PixelWidth = TileWidth * TileSize; - - /// screen height in pixels - public const nuint PixelHeight = TileHeight * TileSize; - - /// pixel count on whole screen - public const nuint PixelCount = PixelWidth * PixelHeight; -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.cs b/crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.cs deleted file mode 100644 index 905828b..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/Cp437Grid.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System.Text; -using ServicePoint.BindGen; - -namespace ServicePoint; - -public sealed class Cp437Grid : SpNativeInstance -{ - public static Cp437Grid New(int width, int height) - { - unsafe - { - return new Cp437Grid(NativeMethods.sp_cp437_grid_new((nuint)width, (nuint)height)); - } - } - - public static Cp437Grid Load(int width, int height, Span bytes) - { - unsafe - { - fixed (byte* bytesPtr = bytes) - { - return new Cp437Grid(NativeMethods.sp_cp437_grid_load((nuint)width, (nuint)height, bytesPtr, - (nuint)bytes.Length)); - } - } - } - - public Cp437Grid Clone() - { - unsafe - { - return new Cp437Grid(NativeMethods.sp_cp437_grid_clone(Instance)); - } - } - - public byte this[int x, int y] - { - get - { - unsafe - { - return NativeMethods.sp_cp437_grid_get(Instance, (nuint)x, (nuint)y); - } - } - set - { - unsafe - { - NativeMethods.sp_cp437_grid_set(Instance, (nuint)x, (nuint)y, value); - } - } - } - - public string this[int y] - { - set - { - var width = Width; - ArgumentOutOfRangeException.ThrowIfGreaterThan(value.Length, width); - - var x = 0; - for (; x < value.Length; x++) - this[x, y] = (byte)value[x]; - - for (; x < width; x++) - this[x, y] = 0; - } - - get - { - var sb = new StringBuilder(); - for (int x = 0; x < Width; x++) - { - var val = this[x, y]; - if (val == 0) - break; - sb.Append((char)val); - } - - return sb.ToString(); - } - } - - public void Fill(byte value) - { - unsafe - { - NativeMethods.sp_cp437_grid_fill(Instance, value); - } - } - - public int Width - { - get - { - unsafe - { - return (int)NativeMethods.sp_cp437_grid_width(Instance); - } - } - } - - public int Height - { - get - { - unsafe - { - return (int)NativeMethods.sp_cp437_grid_height(Instance); - } - } - } - - public Span Data - { - get - { - unsafe - { - var slice = NativeMethods.sp_cp437_grid_unsafe_data_ref(Instance); - return new Span(slice.start, (int)slice.length); - } - } - } - - private unsafe Cp437Grid(BindGen.Cp437Grid* instance) : base(instance) - { - } - - private protected override unsafe void Free() => NativeMethods.sp_cp437_grid_free(Instance); -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/GlobalUsings.cs b/crates/servicepoint_binding_cs/ServicePoint/GlobalUsings.cs deleted file mode 100644 index 911a584..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ -global using System; \ No newline at end of file diff --git a/crates/servicepoint_binding_cs/ServicePoint/Packet.cs b/crates/servicepoint_binding_cs/ServicePoint/Packet.cs deleted file mode 100644 index 24c2c18..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/Packet.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using ServicePoint.BindGen; - -namespace ServicePoint; - -public sealed class Packet : SpNativeInstance -{ - public static Packet FromCommand(Command command) - { - unsafe - { - return new Packet(NativeMethods.sp_packet_from_command(command.Into())); - } - } - - public static bool TryFromBytes(Span bytes, [MaybeNullWhen(false)] out Packet packet) - { - unsafe - { - fixed (byte* bytesPtr = bytes) - { - var instance = NativeMethods.sp_packet_try_load(bytesPtr, (nuint)bytes.Length); - packet = instance == null - ? null - : new Packet(instance); - return packet != null; - } - } - } - - private unsafe Packet(BindGen.Packet* instance) : base(instance) - { - } - - private protected override unsafe void Free() => NativeMethods.sp_packet_free(Instance); -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/ServicePoint.csproj b/crates/servicepoint_binding_cs/ServicePoint/ServicePoint.csproj deleted file mode 100644 index e806186..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/ServicePoint.csproj +++ /dev/null @@ -1,57 +0,0 @@ - - - - net8.0 - disable - enable - true - - true - - - - ServicePoint - 0.11.0 - Repository Authors - None - ServicePoint - CCCB - - C# bindings for the rust crate servicepoint. You will need a suitable native shared library to use this. - For documentation, see the rust documentation: https://docs.rs/servicepoint/latest/servicepoint/. - Note that this library is still in early development. Breaking changes are expected before 1.0 is released. - - README.md - true - - - - - - - - - - - - - - - - libservicepoint_binding_c.so - - - - - libservicepoint_binding_c.so - - - - - - - - - - - diff --git a/crates/servicepoint_binding_cs/ServicePoint/ServicePointExtensions.cs b/crates/servicepoint_binding_cs/ServicePoint/ServicePointExtensions.cs deleted file mode 100644 index 0e569ff..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/ServicePointExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Diagnostics.CodeAnalysis; - -namespace ServicePoint; - -public static class ServicePointExtensions -{ - public static Packet IntoPacket(this Command command) - { - return Packet.FromCommand(command); - } - - public static bool TryIntoCommand(this Packet packet, [MaybeNullWhen(false)] out Command command) - { - return Command.TryFromPacket(packet, out command); - } -} diff --git a/crates/servicepoint_binding_cs/ServicePoint/SpNativeInstance.cs b/crates/servicepoint_binding_cs/ServicePoint/SpNativeInstance.cs deleted file mode 100644 index b6c492e..0000000 --- a/crates/servicepoint_binding_cs/ServicePoint/SpNativeInstance.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace ServicePoint; - -public abstract class SpNativeInstance - : IDisposable - where T : unmanaged -{ - private unsafe T* _instance; - - internal unsafe T* Instance - { - get - { - if (_instance == null) - throw new NullReferenceException("instance is null"); - return _instance; - } - } - - private protected unsafe SpNativeInstance(T* instance) - { - ArgumentNullException.ThrowIfNull(instance); - _instance = instance; - } - - private protected abstract void Free(); - - internal unsafe T* Into() - { - var instance = _instance; - _instance = null; - return instance; - } - - private unsafe void ReleaseUnmanagedResources() - { - if (_instance != null) - Free(); - _instance = null; - } - - public void Dispose() - { - ReleaseUnmanagedResources(); - GC.SuppressFinalize(this); - } - - ~SpNativeInstance() - { - ReleaseUnmanagedResources(); - } -} diff --git a/crates/servicepoint_binding_cs/build.rs b/crates/servicepoint_binding_cs/build.rs deleted file mode 100644 index 8caf589..0000000 --- a/crates/servicepoint_binding_cs/build.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! Build script generating the C# code needed to call methods from the `servicepoint` C library. - -use std::fs; - -fn main() { - println!("cargo::rerun-if-changed=../servicepoint_binding_c/src"); - println!("cargo::rerun-if-changed=build.rs"); - - let mut builder = csbindgen::Builder::default(); - - let mut paths = fs::read_dir("../servicepoint_binding_c/src").unwrap() - .map(|x| x.unwrap().path()) - .collect::>(); - paths.sort(); - - for path in paths { - println!("cargo:rerun-if-changed={}", path.display()); - builder = builder.input_extern_file(path); - } - - builder - .csharp_dll_name("servicepoint_binding_c") - .csharp_namespace("ServicePoint.BindGen") - .csharp_use_nint_types(true) - .csharp_class_accessibility("public") - .csharp_generate_const_filter(|_| true) - .csharp_type_rename(move |name| { - if name.len() > 2 - && name.starts_with("SP") - && name.chars().nth(2).unwrap().is_uppercase() - { - name[2..].to_string() - } else { - name - } - }) - .generate_csharp_file("ServicePoint/BindGen/ServicePoint.g.cs") - .unwrap(); -} diff --git a/crates/servicepoint_binding_cs/examples/lang_cs/Program.cs b/crates/servicepoint_binding_cs/examples/lang_cs/Program.cs deleted file mode 100644 index 89c0eef..0000000 --- a/crates/servicepoint_binding_cs/examples/lang_cs/Program.cs +++ /dev/null @@ -1,20 +0,0 @@ -using ServicePoint; -using CompressionCode = ServicePoint.BindGen.CompressionCode; - -using var connection = Connection.Open("127.0.0.1:2342"); - -connection.Send(Command.Clear().IntoPacket()); -connection.Send(Command.Brightness(128).IntoPacket()); - -using var pixels = Bitmap.New(Constants.PixelWidth, Constants.PixelHeight); - -for (var offset = 0; offset < int.MaxValue; offset++) -{ - pixels.Fill(false); - - for (var y = 0; y < pixels.Height; y++) - pixels[(y + offset) % Constants.PixelWidth, y] = true; - - connection.Send(Command.BitmapLinearWin(0, 0, pixels.Clone(), CompressionCode.Lzma).IntoPacket()); - Thread.Sleep(14); -} diff --git a/crates/servicepoint_binding_cs/examples/lang_cs/lang_cs.csproj b/crates/servicepoint_binding_cs/examples/lang_cs/lang_cs.csproj deleted file mode 100644 index e83a385..0000000 --- a/crates/servicepoint_binding_cs/examples/lang_cs/lang_cs.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - Exe - net8.0 - lang_cs - enable - enable - - - - - - - diff --git a/crates/servicepoint_binding_cs/src/lib.rs b/crates/servicepoint_binding_cs/src/lib.rs deleted file mode 100644 index c7bcac6..0000000 --- a/crates/servicepoint_binding_cs/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -//! This crate is intentionally left empty. Only the build script is relevant here.