elara-ffi
Foreign Function Interface (FFI) for the ELARA Protocol - providing C bindings and platform-specific integrations for mobile SDKs and cross-language interoperability.
Features
- C API Bindings: Complete C-compatible API surface
- Mobile SDK Support: iOS and Android integration
- Cross-Platform: Windows, macOS, Linux support
- Memory Safe: Automatic memory management
- Thread Safe: Concurrent access support
- Zero-Copy: Efficient data transfer
Quick Start
C Integration
// Generate identity
ElaraIdentity* identity = ;
// Create session
ElaraSession* session = ;
// Send message
const char* message = "Hello from C!";
;
// Cleanup
;
;
Rust Usage
use ;
unsafe
API Reference
Identity Management
// Generate new identity
ElaraIdentity* ;
// Free identity
void ;
// Get node ID from identity
ElaraNodeId ;
Session Management
// Create new session
ElaraSession* ;
// Free session
void ;
// Process events
int ;
Messaging
// Send message
int ;
// Set message callback
int ;
// Receive message
int ;
Platform Support
Android
// Load native library
System.;
// JNI interface
public native long ;
public native long ;
iOS
// Import framework
import Elara
// Swift wrapper
let identity = ElaraIdentity.generate()
let session = ElaraSession(identity: identity, port: 1)
Windows
// Load DLL
HMODULE elara = ;
// Get function pointer
auto generate = ;
Memory Management
Automatic Cleanup
- RAII-based resource management
- Automatic reference counting
- Memory leak detection
Manual Management
// Explicit cleanup required
ElaraIdentity* identity = ;
// ... use identity ...
; // Required!
Thread Safety
Concurrent Access
- All functions are thread-safe
- Internal synchronization
- Lock-free operations where possible
Example
// Multiple threads can safely use same session
pthread_t threads;
for
Error Handling
Return Codes
Error Strings
const char* ;
Performance
Zero-Copy Operations
- Direct memory access where possible
- Minimal allocations
- Efficient buffer management
Benchmarks
- Identity Generation: < 1ms
- Session Creation: < 5ms
- Message Send: < 100μs
- Memory Overhead: < 1MB per session
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.