Skip to content

Commit

Permalink
Start to write Daemon wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
lbirkert committed Aug 22, 2024
1 parent 54ca65c commit eaab5e6
Show file tree
Hide file tree
Showing 24 changed files with 575 additions and 206 deletions.
27 changes: 20 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ members = [
"qb-core",
"qb-proto",
"qb-ext",
"qb-daemon",
# Extensions
"qb-ext-local",
"qb-ext-tcp",
# Binaries
"qb-daemon",
# Application Clients
"qb-cli",
# Applications
"qb-app-cli",

# Needed for FFI
"qb-mobile/rust",
"qb-mobile/rust", "qb-app-daemon",
]

[workspace.package]
Expand Down
6 changes: 5 additions & 1 deletion qb-cli/Cargo.toml → qb-app-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "qb-cli"
name = "qb-app-cli"
version.workspace = true
edition.workspace = true

Expand All @@ -14,3 +14,7 @@ tracing = "0.1.40"
qb-core = { path = "../qb-core" }
qb-proto = { path = "../qb-proto" }
qb-ext = { path = "../qb-ext" }

[[bin]]
name = "qb-cli"
path = "src/main.rs"
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions qb-app-daemon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "qb-app-daemon"
version.workspace = true
edition.workspace = true

[dependencies]
tracing-subscriber = "0.3.18"
tracing-panic = "0.1.2"
tracing = "0.1.40"
interprocess = { version = "2.2.0", features = ["tokio"], optional = true }
tokio = { version = "1.37.0", features = [
"rt",
"rt-multi-thread",
"sync",
"macros",
] }
clap = { version = "4.5.9", features = ["derive"] }
qb-core = { path = "../qb-core" }
qb-daemon = { path = "../qb-daemon" }
qb-ext-local = { path = "../qb-ext-local" }
qb-ext-tcp = { path = "../qb-ext-tcp", default-features = false }

[features]
default = ["ipc", "aws_lc_rs"]
ipc = ["dep:interprocess"]
aws_lc_rs = ["qb-ext-tcp/aws_lc_rs"]
aws-lc-rs = ["aws_lc_rs"]
ring = ["qb-ext-tcp/ring"]

[[bin]]
name = "qb-daemon"
path = "src/main.rs"
65 changes: 65 additions & 0 deletions qb-app-daemon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## qb-app-daemon

This binary starts a daemon that manages a master
and listens on a socket for a controlling task, which
its instructions it then further processes, allowing
the controlling task to manage the daemon over IPC.

This binary is a daemon, meaning it should run somewhere
in the background and only should be interacted by the user
over other tools, which use the socket to control the daemon.

### Running

- Using `cargo run` (for development)
```sh
$ cargo run --bin qb-daemon -- <args>
```
- Or [install qb-daemon locally](#installation)

### Installation

- Using `cargo install`
```sh
# In the project root directory
$ cargo install --path qb-daemon
# Make sure that ~/.cargo/bin is in $PATH
$ qb-daemon <args>
```
- Build manually
```sh
# In the project root directory
$ cargo build --release --bin qb-daemon
$ target/release/qb-daemon <args>
```

### Commands

See: `qb-daemon --help`
```
$ qb-daemon --help
Usage: qb-daemon [OPTIONS]
Options:
--ípc Bind to a socket for IPC [default]
--no-ipc Do not bind to a socket for IPC
--stdio Use STDIN/STDOUT for controlling (disables std logging)
--no-stdio Do not use STDIN/STDOUT for controlling [default]
-p, --path <PATH> The path, where the daemon stores its files [default: ./run/daemon1]
-h, --help Print help
-V, --version Print version
```

You can use the LOG_LEVEL environment variable to specify which log level to use:

command prefix|level description
---|---
LOG_LEVEL=trace|Designates very low priority, often extremely verbose, information.
LOG_LEVEL=debug|Designates lower priority information.
LOG_LEVEL=info|Designates useful information.
LOG_LEVEL=warn|Designates hazardous situations.
LOG_LEVEL=error|Designates very serious errors.

----

&copy; 2024 The QuixByte Project Authors - All Rights Reserved
17 changes: 2 additions & 15 deletions qb-daemon/src/main.rs → qb-app-daemon/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
//! # qb-daemon
//!
//! This crate houses the daemon of the application,
//! that is, the application that runs in the background,
//! which handles interface tasks and their respective communication.
//!
//! We can communicate with the daemon using the [qb-control] messages.
#![warn(missing_docs)]

use std::{pin::Pin, str::FromStr, sync::Arc};

use clap::Parser;
use daemon::QBDaemon;
use master::QBMaster;
use qb_core::fs::wrapper::QBFSWrapper;
use qb_daemon::daemon::QBDaemon;
use qb_daemon::master::QBMaster;
use qb_ext_local::QBILocal;
use qb_ext_tcp::{server::QBHTCPServerSetup, QBHTCPServer, QBITCPClient, QBITCPServer};
use tokio::io::{AsyncRead, AsyncWrite};
Expand All @@ -26,9 +16,6 @@ use interprocess::local_socket::{
traits::tokio::Listener, GenericNamespaced, ListenerNonblockingMode, ListenerOptions, ToNsName,
};

pub mod daemon;
pub mod master;

#[derive(Parser)]
#[command(version, about)]
struct Cli {
Expand Down
20 changes: 1 addition & 19 deletions qb-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,9 @@ edition.workspace = true

[dependencies]
bitcode = "0.6.0"
tokio = { version = "1.37.0", features = [
"rt",
"rt-multi-thread",
"sync",
"macros",
] }
interprocess = { version = "2.2.0", features = ["tokio"], optional = true }
tracing-subscriber = "0.3.18"
tracing-panic = "0.1.2"
tokio = { version = "1.37.0", features = ["rt", "sync", "time", "macros"] }
tracing = "0.1.40"
thiserror = "1.0.63"
clap = { version = "4.5.9", features = ["derive"] }
qb-core = { path = "../qb-core" }
qb-proto = { path = "../qb-proto" }
qb-ext = { path = "../qb-ext" }
qb-ext-local = { path = "../qb-ext-local" }
qb-ext-tcp = { path = "../qb-ext-tcp", default-features = false }

[features]
default = ["ipc", "aws_lc_rs"]
ipc = ["dep:interprocess"]
aws_lc_rs = ["qb-ext-tcp/aws_lc_rs"]
aws-lc-rs = ["aws_lc_rs"]
ring = ["qb-ext-tcp/ring"]
60 changes: 1 addition & 59 deletions qb-daemon/README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,6 @@
## qb-daemon

This binary starts a daemon that manages a master
and listens on a socket for a controlling task, which
its instructions it then further processes, allowing
the controlling task to manage the daemon over IPC.

This binary is a daemon, meaning it should run somewhere
in the background and only should be interacted by the user
over other tools, which use the socket to control the daemon.

### Running

- Using `cargo run` (for development)
```sh
$ cargo run --bin qb-daemon -- <args>
```
- Or [install qb-daemon locally](#installation)

### Installation

- Using `cargo install`
```sh
# In the project root directory
$ cargo install --path qb-daemon
# Make sure that ~/.cargo/bin is in $PATH
$ qb-daemon <args>
```
- Build manually
```sh
# In the project root directory
$ cargo build --release --bin qb-daemon
$ target/release/qb-daemon <args>
```

### Commands

See: `qb-daemon --help`
```
$ qb-daemon --help
Usage: qb-daemon [OPTIONS]
Options:
--ípc Bind to a socket for IPC [default]
--no-ipc Do not bind to a socket for IPC
--stdio Use STDIN/STDOUT for controlling (disables std logging)
--no-stdio Do not use STDIN/STDOUT for controlling [default]
-p, --path <PATH> The path, where the daemon stores its files [default: ./run/daemon1]
-h, --help Print help
-V, --version Print version
```

You can use the LOG_LEVEL environment variable to specify which log level to use:

command prefix|level description
---|---
LOG_LEVEL=trace|Designates very low priority, often extremely verbose, information.
LOG_LEVEL=debug|Designates lower priority information.
LOG_LEVEL=info|Designates useful information.
LOG_LEVEL=warn|Designates hazardous situations.
LOG_LEVEL=error|Designates very serious errors.
This crate exposes primitives related to the daemon and master process.

----

Expand Down
12 changes: 12 additions & 0 deletions qb-daemon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! # qb-daemon
//!
//! This crate houses the daemon of the application,
//! that is, the application that runs in the background,
//! which handles interface tasks and their respective communication.
//!
//! We can communicate with the daemon using the [qb-control] messages.
#![warn(missing_docs)]

pub mod daemon;
pub mod master;
3 changes: 2 additions & 1 deletion qb-mobile/flutter_rust_bridge.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rust_input: crate::api
rust_root: rust/
dart_output: lib/src/rust
dart_output: lib/src/rust
enable_lifetime: true
8 changes: 6 additions & 2 deletions qb-mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@
//

import 'package:flutter/material.dart';
import 'package:qb_mobile/src/rust/api/simple.dart';
import 'package:path_provider/path_provider.dart';
import 'package:qb_mobile/src/rust/api/daemon.dart';
import 'package:qb_mobile/src/rust/frb_generated.dart';

Future<void> main() async {
await RustLib.init();
final dir = await getApplicationDocumentsDirectory();
final daemon = await DaemonWrapper.init(path: '$dir');
print(daemon);
runApp(const MyApp());
}

Expand All @@ -113,7 +117,7 @@ class MyApp extends StatelessWidget {
appBar: AppBar(title: const Text('flutter_rust_bridge quickstart')),
body: Center(
child: Text(
'Action: Call Rust `greet("Tom")`\nResult: `${greet(name: "Tom")}`'),
'Action: Call Rust `greet("Tom")`\nResult:`'),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
import '../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

String greet({required String name}) =>
RustLib.instance.api.crateApiSimpleGreet(name: name);
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<DaemonWrapper>>
abstract class DaemonWrapper implements RustOpaqueInterface {
static Future<DaemonWrapper> init({required String path}) =>
RustLib.instance.api.crateApiDaemonDaemonWrapperInit(path: path);
}
Loading

0 comments on commit eaab5e6

Please sign in to comment.