Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create lib and bin #20

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,45 @@
name = "ping-viewer-next"
version = "0.0.0"
edition = "2021"
authors = ["Raul Victor Trombin <[email protected]>"]
description = "This crate serves as the entry point for embedding applications using Rust on Blue Robotics's Ping devices family"
repository = "https://github.com/bluerobotics/ping-viewer-next"
license = "MIT"

[dependencies]
actix = "0.13.3"
actix-web = "4.6.0"
actix-web = "4.9.0"
bluerobotics-ping = "0.3.0"
actix-web-actors = "4.3.0"
chrono = "0.4.38"
clap = {version = "4.5.4", features = ["derive"] }
lazy_static = "1.4.0"
clap = {version = "4.5.17", features = ["derive"] }
lazy_static = "1.5.0"
mime_guess = "2.0.4"
paperclip = { version = "0.8.2" , features = ["actix4", "swagger-ui", "uuid"] }
serde = { version = "1.0.197", features = ["derive"] }
regex = "1.10.4"
paperclip = { version = "0.9.1" , features = ["actix4", "swagger-ui", "uuid"] }
serde = { version = "1.0.210", features = ["derive"] }
regex = "1.10.6"
rust-embed = "8.4.0"
serde_json = "1.0.117"
tokio = { version = "1.37.0", features = ["full"] }
serde_json = "1.0.128"
tokio = { version = "1.40.0", features = ["full"] }
tokio-serial = "5.4.4"
tracing = { version = "0.1.40", features = ["log", "async-await"] }
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing-appender = { git = "https://github.com/joaoantoniocardoso/tracing", branch = "tracing-appender-0.2.2-with-filename-suffix" }
tracing-tracy = "0.11.0"
udp-stream = "0.0.12"
uuid = { version = "1.8", features = ["serde"] }
uuid = { version = "1.10.0", features = ["serde"] }
validator = "0.18.1"
thiserror = "1.0.61"
thiserror = "1.0.63"
shellexpand = "3.1"

[build-dependencies]
vergen-gix = { version = "1.0.0-beta.2", default-features = false, features = ["build", "cargo"] }
vergen-gix = { version = "1.0.1", default-features = false, features = ["build", "cargo"] }

[lib]
name = "ping_viewer_next"
path = "src/lib.rs"

[[bin]]
name = "ping-viewer-next"
path = "src/main.rs"
9 changes: 5 additions & 4 deletions src/cli/manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap;
use clap::Parser;
use lazy_static::lazy_static;
use std::sync::Arc;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -30,8 +31,8 @@ struct Args {
enable_tracing_level_log_file: bool,

/// Filter to show only own crate related logs
#[arg(long, default_value = "true")]
log_current_crate_only: bool,
#[arg(long, default_value = "false")]
log_include_all_dependencies: bool,

/// Turns on the Tracy tool integration.
#[arg(long)]
Expand Down Expand Up @@ -73,8 +74,8 @@ pub fn is_tracy() -> bool {
MANAGER.clap_matches.enable_tracy
}

pub fn log_current_crate_only() -> bool {
MANAGER.clap_matches.log_current_crate_only
pub fn is_log_all_dependencies() -> bool {
MANAGER.clap_matches.log_include_all_dependencies
}

pub fn is_enable_auto_create() -> bool {
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub mod cli;
pub mod device;
pub mod logger;
pub mod server;

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "module")]
pub enum ModuleType {
DeviceManager(device::manager::Request),
}
20 changes: 11 additions & 9 deletions src/logger/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,35 @@ pub fn init() {
// Configure the default subscriber
match (
cli::manager::is_tracy(),
cli::manager::log_current_crate_only(),
cli::manager::is_log_all_dependencies(),
) {
(true, true) => {
(true, false) => {
let lib_name = env!("CARGO_PKG_NAME").replace('-', "_");
let subscriber = subscriber.with(EnvFilter::new(format!(
"{}={level}",
env!("CARGO_PKG_NAME").replace('-', "_")
"{lib_name}={level},lib{lib_name}={level}"
)));
let tracy_layer = tracing_tracy::TracyLayer::default();
let subscriber = subscriber.with(tracy_layer);
tracing::subscriber::set_global_default(subscriber)
.expect("Unable to set a global subscriber");
}
(false, true) => {
(false, false) => {
let lib_name = env!("CARGO_PKG_NAME").replace('-', "_");
let subscriber = subscriber.with(EnvFilter::new(format!(
"{}={level}",
env!("CARGO_PKG_NAME").replace('-', "_")
"{lib_name}={level},lib{lib_name}={level}"
)));
tracing::subscriber::set_global_default(subscriber)
.expect("Unable to set a global subscriber");
}
(true, false) => {
(true, true) => {
let subscriber = subscriber.with(EnvFilter::new(level.to_string()));
let tracy_layer = tracing_tracy::TracyLayer::default();
let subscriber = subscriber.with(tracy_layer);
tracing::subscriber::set_global_default(subscriber)
.expect("Unable to set a global subscriber");
}
(false, false) => {
(false, true) => {
let subscriber = subscriber.with(EnvFilter::new(level.to_string()));
tracing::subscriber::set_global_default(subscriber)
.expect("Unable to set a global subscriber");
}
Expand Down
16 changes: 1 addition & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
use serde::{Deserialize, Serialize};
use tracing::info;

#[macro_use]
extern crate lazy_static;

mod cli;
/// The Device module consists of two main modules: devices and manager.
mod device;
mod logger;
mod server;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "module")]
pub enum ModuleType {
DeviceManager(device::manager::Request),
}
use ping_viewer_next::{cli, device, logger, server};

#[tokio::main]
async fn main() {
Expand Down