servicepoint/crates/servicepoint_binding_c
2024-11-13 19:59:55 +01:00
..
examples/lang_c add fake connection to C API 2024-11-13 19:59:55 +01:00
src add fake connection to C API 2024-11-13 19:59:55 +01:00
build.rs add more documentation, add doc lint 2024-05-28 19:38:43 +02:00
Cargo.toml version 0.11.0 2024-11-13 18:49:50 +01:00
cbindgen.toml do not name struct in C api 2024-10-16 18:34:21 +02:00
README.md rename PixelGrid to Bitmap 2024-10-15 21:37:36 +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

Copy the header to your project and compile against.

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

Everything else

Look at the main project README for further information.