๐ Hello
Greetings. Welcome to the documentation of the dart-linux-interactor (DLI) library.
The main purpose of this project is to connect Dart-based applications and libraries with Linux-based libraries.
๐ง Reasoning
I am planning to create my own Linux Kernel-based operation system.
It will have only Dart and Linux pure C/C++ modules.
Thus to interact or communicate between Dart and Linux sides there is a need for the layer between.
For now, we have the most popular way to do it is Dart FFI. But it is too poor for my tasks.
I need something with the following features:
- multi-isolates to multi-thread interaction
- multi-threads to multi-isolate interaction
- pools for objects and buffers out-of-the-box
- lock-free (at least at user-code level)
So I've decided to combine all these features into a single library for Dart + Linux interaction.
๐จ Usage
There are two parts of DLI: Native and Dart.
How to use the Dart part?โ
Firstly you need to add dependency to your pubspec.yaml
:
dependencies:
linux_interactor:
git:
url: https://github.com/antonbashir/dart-linux-interactor
path: dart
Then you need to generate FFI bindings for your native code.
Now you can use DLI:
Future<void> main(List<String> args) async {
final interactor = Interactor();
final worker = InteractorWorker(interactor.worker(InteractorDefaults.worker()));
await worker.initialize();
final producer = worker.producer(/* Your producer here */);
worker.consumer(/* Your consumer here */);
worker.activate();
/* Your code here */
await interactor.shutdown();
}
How to use the Native part?โ
The native part placed here include.
You can use your own C/C++ manager to download and include the headers.
Then you need to load the library and you will be able to use DLI Native API.
๐ฅ Samples
A basic sample of usage lives here.
โ Limitations
The main limitation is resource control management on the user side.
It means that if you need to receive a string from the native part then you should allocate
the string in the Dart part and free
it also in the Dart part.
This limitation comes from the principle that: the requester controls the resources.h
This way allows us to use efficient lock-free single-thread pools and buffers because allocation
and free
operations happen on the same thread/isolate.
๐จโ๐ป Contribution
Issues about wanted functions or existing bugs are always welcome.