Find a file
Vinzenz Schroeter 577ba02d22
Some checks failed
Rust / build (pull_request) Failing after 3m11s
build all variations in CI to keep track of what works
2025-04-24 23:31:34 +02:00
.github/workflows build all variations in CI to keep track of what works 2025-04-24 23:31:34 +02:00
example wip broken version of Makefile with a bunch of options 2025-04-24 22:47:27 +02:00
include add functions to convert containers directly into packet 2025-04-12 22:13:29 +02:00
src features, cargo fmt 2025-04-12 23:14:04 +02:00
.gitignore first CMD_UTF8_DATA implementation 2025-01-12 15:22:54 +01:00
build.rs use NotNull for parameters 2025-04-12 16:25:20 +02:00
Cargo.lock add command code constants, send header 2025-04-12 21:47:23 +02:00
Cargo.toml features, cargo fmt 2025-04-12 23:14:04 +02:00
cbindgen.toml sp_brightness_grid_load ignore out of range 2025-04-12 18:49:12 +02:00
flake.lock split crate into own repository 2025-02-15 12:39:31 +01:00
flake.nix wip broken version of Makefile with a bunch of options 2025-04-24 22:47:27 +02:00
generate-binding.sh extend installation instructions, fix perm 2025-02-16 18:17:08 +01:00
LICENSE Create LICENSE 2024-05-12 00:10:34 +02:00
README.md move generic safety information into README 2025-04-12 16:25:20 +02:00
rustfmt.toml reformat with max width 2024-05-11 23:28:08 +02:00

servicepoint_binding_c

crates.io Crates.io Total Downloads docs.rs GPLv3 licensed

In CCCB, 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

#include <stdio.h>
#include "servicepoint.h"

int main(void) {
    SPConnection *connection = sp_connection_open("172.23.42.29:2342");
    if (connection == NULL)
        return 1;

    SPBitmap *pixels = sp_bitmap_new(SP_PIXEL_WIDTH, SP_PIXEL_HEIGHT);
    sp_bitmap_fill(pixels, true);

    SPCommand *command = sp_command_bitmap_linear_win(0, 0, pixels, Uncompressed);
    while (sp_connection_send_command(connection, sp_command_clone(command)));

    sp_command_free(command);
    sp_connection_free(connection);
    return 0;
}

A full example including Makefile 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. Please specify the full version including patch in your Cargo.toml until 1.0 is released.

Installation

  1. Add this repo as a submodule:
    git submodule add https://git.berlin.ccc.de/servicepoint/servicepoint-binding-c.git
    git commit -m "add servicepoint-binding-c submodule"
    
  2. Add a build step for the servicepoint library. If you use make, this could look something like this:
    dependencies: FORCE
    	cargo build --manifest-path=servicepoint-binding-c/Cargo.toml --release
    FORCE: ; 
    
  3. Link against the library. If you are on linux and linking statically:
    ${CC} main.c \
    	-I servicepoint-binding-c/include \
    	-L servicepoint-binding-c/target/release \
    	-Wl,-Bstatic -lservicepoint_binding_c \
    	-Wl,-Bdynamic -llzma \
    	-o out/example
    

You have the choice of linking statically (recommended) or dynamically.

  • The C example shows how to link statically against the staticlib variant.
  • When linked dynamically, you have to provide the cdylib at runtime in the same version, as there are no API/ABI guarantees yet.

Notes on differences to rust library

  • function names are: sp_ <struct_name> <rust name>.
  • Instances get consumed in the same way they do when writing rust code. Do not use an instance after an (implicit!) free.
  • Option or Result<T, E> turn into nullable return values - check for NULL!
  • There are no specifics for C++ here yet. You might get a nicer header when generating directly for C++, but it should be usable.
  • Reading and writing to instances concurrently is not safe. Only reading concurrently is safe.
  • documentation is included in the header and available online

Safety

Functions expect that C code honors NonNull annotations.

Any created instances have to be freed in some way. Pointers to those instances cannot be used anymore after that.

Instances cannot be shared between threads and need to be locked in the using code.

Enum values have to be used as-is. Do not pass values that are not part of the enum.

UTF-8 or UTF-32 encoding has to be used properly.

Brightness values provided as u8 parameters must be in range.

Everything else

Look at the main project README for further information.