Camure - Foreign Function Interface
This repository contains the foreign function interface for the camure library.
Documentation
All exposed functions wrap a corresponding function in the camure library (with few exceptions). Thus, see the camure documentation for more information on the functions.
Building
This project uses CMake and requires cargo to be installed. The library can then be build using
&& && &&
Naming Conventions
All identifiers have been prefixed with camure_ to avoid name conflicts with other libraries.
The names of structs have been converted to snake_case with a _t suffix to conform to the C naming conventions.
Member functions are prefixed with the name of the struct they belong to (without the '_t' suffix).
Differences to the Rust API
- The C API only supports IPv4 addresses and corresponding functions have the
_ipv4suffix. - The C API only exposes simplified message writing and reading functions.
is roughtly equivalent tobool ;
andsender.write_message.write_all
is roughly equivalent toboollet mut message = receiver.recv.read; let message_len = message.read; - Error handling is currently very limited.
Constructor frunction return
NULLon failure and other function will return anboolthat indicates success or failure. There is currently no way to get more information on the error.
Examples
The following code highlights how to use barrier/broadcast groups in C.
In particular, it ignores all errors for the sake of clarity.
For the complete code with basic error handling, look at the examples directory.
Barrier Groups
Coordinator
camure_socket_addr_ipv4_t bind_addr = ;
camure_socket_addr_ipv4_t multicast_addr = ;
camure_coordinator_t* coordinator = ;
camure_barrier_group_coordinator_t* barrier_group = ;
camure_socket_addr_ipv4_t member;
;
for
;
;
Member
camure_socket_addr_ipv4_t bind_addr = ;
camure_member_t* member = ;
camure_barrier_group_member_t* barrier_group = ;
for
;
;
Broadcast Group
Coordinator
camure_socket_addr_ipv4_t bind_addr = ;
camure_socket_addr_ipv4_t multicast_addr = ;
camure_coordinator_t* coordinator = ;
camure_broadcast_group_sender_t* sender = ;
while
;
;
Member
camure_socket_addr_ipv4_t bind_addr = ;
camure_member_t* member = ;
camure_broadcast_group_receiver_t* receiver = ;
uint8_t buffer = ;
for
;
;
Versioning
The project uses semantic versioning and is versioned independently of the camure library.