checkpoint before android work
This commit is contained in:
parent
2a9522cc24
commit
82f680b35f
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4295,6 +4295,7 @@ dependencies = [
|
||||
"daemonize",
|
||||
"directories",
|
||||
"failure",
|
||||
"flume",
|
||||
"futures",
|
||||
"lazy_static",
|
||||
"log",
|
||||
|
@ -4,7 +4,7 @@
|
||||
use veilid_core::xx::*;
|
||||
|
||||
use async_std::prelude::*;
|
||||
use clap::{App, Arg, ColorChoice};
|
||||
use clap::{Arg, ColorChoice, Command};
|
||||
use flexi_logger::*;
|
||||
use std::ffi::OsStr;
|
||||
use std::net::ToSocketAddrs;
|
||||
@ -20,7 +20,7 @@ pub mod veilid_client_capnp {
|
||||
}
|
||||
|
||||
fn parse_command_line(default_config_path: &OsStr) -> Result<clap::ArgMatches, String> {
|
||||
let matches = App::new("veilid-cli")
|
||||
let matches = Command::new("veilid-cli")
|
||||
.version("0.1")
|
||||
.color(ColorChoice::Auto)
|
||||
.about("Veilid Console Client")
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::core_context::*;
|
||||
use crate::intf::*;
|
||||
use crate::veilid_api::*;
|
||||
use crate::xx::*;
|
||||
use log::{set_boxed_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record};
|
||||
@ -8,8 +7,7 @@ use once_cell::sync::OnceCell;
|
||||
struct ApiLoggerInner {
|
||||
level: LevelFilter,
|
||||
filter_ignore: Cow<'static, [Cow<'static, str>]>,
|
||||
join_handle: Option<JoinHandle<()>>,
|
||||
tx: Option<flume::Sender<(VeilidLogLevel, String)>>,
|
||||
update_callback: UpdateCallback,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -21,21 +19,10 @@ static API_LOGGER: OnceCell<ApiLogger> = OnceCell::new();
|
||||
|
||||
impl ApiLogger {
|
||||
fn new_inner(level: LevelFilter, update_callback: UpdateCallback) -> ApiLoggerInner {
|
||||
let (tx, rx) = flume::unbounded::<(VeilidLogLevel, String)>();
|
||||
let join_handle: Option<JoinHandle<()>> = Some(spawn(async move {
|
||||
while let Ok(v) = rx.recv_async().await {
|
||||
(update_callback)(VeilidUpdate::Log {
|
||||
log_level: v.0,
|
||||
message: v.1,
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}));
|
||||
ApiLoggerInner {
|
||||
level,
|
||||
filter_ignore: Default::default(),
|
||||
join_handle,
|
||||
tx: Some(tx),
|
||||
update_callback,
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,20 +41,8 @@ impl ApiLogger {
|
||||
|
||||
pub async fn terminate() {
|
||||
if let Some(api_logger) = API_LOGGER.get() {
|
||||
let mut join_handle = None;
|
||||
{
|
||||
let mut inner = api_logger.inner.lock();
|
||||
|
||||
// Terminate channel
|
||||
if let Some(inner) = (*inner).as_mut() {
|
||||
inner.tx = None;
|
||||
join_handle = inner.join_handle.take();
|
||||
}
|
||||
*inner = None;
|
||||
}
|
||||
if let Some(jh) = join_handle {
|
||||
jh.await;
|
||||
}
|
||||
let mut inner = api_logger.inner.lock();
|
||||
*inner = None;
|
||||
|
||||
// Clear everything and we're done
|
||||
set_max_level(LevelFilter::Off);
|
||||
@ -139,9 +114,10 @@ impl Log for ApiLogger {
|
||||
|
||||
let s = format!("{}{}{}", tgt, loc, record.args());
|
||||
|
||||
if let Some(tx) = &inner.tx {
|
||||
let _ = tx.try_send((ll, s));
|
||||
}
|
||||
(inner.update_callback)(VeilidUpdate::Log {
|
||||
log_level: ll,
|
||||
message: s,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,12 @@ pub use rust_fsm::*;
|
||||
cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
pub type StateChangeCallback<T> = Arc<
|
||||
dyn Fn(<T as StateMachineImpl>::State, <T as StateMachineImpl>::State) -> SystemPinBoxFuture<()>
|
||||
dyn Fn(<T as StateMachineImpl>::State, <T as StateMachineImpl>::State)
|
||||
+ 'static,
|
||||
>;
|
||||
} else {
|
||||
pub type StateChangeCallback<T> = Arc<
|
||||
dyn Fn(<T as StateMachineImpl>::State, <T as StateMachineImpl>::State) -> SystemPinBoxFuture<()>
|
||||
dyn Fn(<T as StateMachineImpl>::State, <T as StateMachineImpl>::State)
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
@ -88,7 +88,7 @@ where
|
||||
(inner.callback.clone(), eventual)
|
||||
};
|
||||
if let Some(cb) = callback {
|
||||
cb(old_state, new_state).await;
|
||||
cb(old_state, new_state);
|
||||
}
|
||||
eventual.resolve(new_state).await;
|
||||
Ok(output)
|
||||
|
@ -8,9 +8,9 @@ use crate::xx::*;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) -> SystemPinBoxFuture<()>>;
|
||||
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate)>;
|
||||
} else {
|
||||
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) -> SystemPinBoxFuture<()> + Send + Sync>;
|
||||
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) + Send + Sync>;
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ impl ServicesContext {
|
||||
info!("Veilid API logging initialized");
|
||||
}
|
||||
|
||||
trace!("startup starting");
|
||||
info!("Veilid API starting up");
|
||||
|
||||
// Set up protected store
|
||||
trace!("init protected store");
|
||||
@ -134,12 +134,12 @@ impl ServicesContext {
|
||||
}
|
||||
self.attachment_manager = Some(attachment_manager);
|
||||
|
||||
trace!("startup complete");
|
||||
info!("Veilid API startup complete");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn shutdown(&mut self) {
|
||||
trace!("shutdown starting");
|
||||
info!("Veilid API shutting down");
|
||||
|
||||
if let Some(attachment_manager) = &mut self.attachment_manager {
|
||||
trace!("terminate attachment manager");
|
||||
@ -162,13 +162,13 @@ impl ServicesContext {
|
||||
protected_store.terminate().await;
|
||||
}
|
||||
|
||||
trace!("shutdown complete");
|
||||
info!("Veilid API shutdown complete");
|
||||
|
||||
// api logger terminate is idempotent
|
||||
ApiLogger::terminate().await;
|
||||
|
||||
// send final shutdown update
|
||||
(self.update_callback)(VeilidUpdate::Shutdown).await;
|
||||
(self.update_callback)(VeilidUpdate::Shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +221,6 @@ impl VeilidCoreContext {
|
||||
if #[cfg(target_os = "android")] {
|
||||
if utils::android::ANDROID_GLOBALS.lock().is_none() {
|
||||
error!("Android globals are not set up");
|
||||
config.terminate().await;
|
||||
return Err(VeilidAPIError::Internal { message: "Android globals are not set up".to_owned() });
|
||||
}
|
||||
}
|
||||
|
@ -160,13 +160,9 @@ cfg_if! {
|
||||
|
||||
pub fn setup_veilid_core() -> (UpdateCallback, ConfigCallback) {
|
||||
(
|
||||
Arc::new(
|
||||
move |veilid_update: VeilidUpdate| -> SystemPinBoxFuture<()> {
|
||||
Box::pin(async move {
|
||||
trace!("update_callback: {:?}", veilid_update);
|
||||
})
|
||||
},
|
||||
),
|
||||
Arc::new(move |veilid_update: VeilidUpdate| {
|
||||
println!("update_callback: {:?}", veilid_update);
|
||||
}),
|
||||
Arc::new(config_callback),
|
||||
)
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.veilid.veilid">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
|
||||
</manifest>
|
||||
|
@ -64,5 +64,6 @@ flutter {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ Future<VeilidConfig> getDefaultVeilidConfig() async {
|
||||
return VeilidConfig(
|
||||
programName: "Veilid Plugin Test",
|
||||
namespace: "",
|
||||
apiLogLevel: VeilidConfigLogLevel.trace,
|
||||
apiLogLevel: VeilidConfigLogLevel.info,
|
||||
capabilities: VeilidConfigCapabilities(
|
||||
protocolUDP: !kIsWeb,
|
||||
protocolConnectTCP: !kIsWeb,
|
||||
|
@ -42,9 +42,9 @@ void setRootLogLevel(LogLevel? level) {
|
||||
|
||||
void initLoggy() {
|
||||
Loggy.initLoggy(
|
||||
logPrinter: ConsolePrinter(
|
||||
logPrinter: StreamPrinter(ConsolePrinter(
|
||||
const PrettyDeveloperPrinter(),
|
||||
),
|
||||
)),
|
||||
logOptions: getLogOptions(null),
|
||||
);
|
||||
}
|
||||
@ -90,14 +90,16 @@ class _MyAppState extends State<MyApp> with UiLoggy {
|
||||
// We also handle the message potentially returning null.
|
||||
try {
|
||||
veilidVersion = Veilid.instance.veilidVersionString();
|
||||
} on PlatformException {
|
||||
} on Exception {
|
||||
veilidVersion = 'Failed to get veilid version.';
|
||||
}
|
||||
loggy.error("Error test");
|
||||
loggy.warning("Warning test");
|
||||
loggy.info("Info test");
|
||||
loggy.debug("Debug test");
|
||||
loggy.trace("Trace test");
|
||||
|
||||
// In case of hot restart shut down first
|
||||
try {
|
||||
await Veilid.instance.shutdownVeilidCore();
|
||||
} on Exception {
|
||||
//
|
||||
}
|
||||
|
||||
// If the widget was removed from the tree while the asynchronous platform
|
||||
// message was in flight, we want to discard the reply rather than calling
|
||||
|
@ -115,21 +115,17 @@ pub extern "C" fn startup_veilid_core(port: i64, config: FfiStr) {
|
||||
}
|
||||
|
||||
let sink = stream.clone();
|
||||
let update_callback = Arc::new(
|
||||
move |update: veilid_core::VeilidUpdate| -> veilid_core::SystemPinBoxFuture<()> {
|
||||
let sink = sink.clone();
|
||||
Box::pin(async move {
|
||||
match update {
|
||||
veilid_core::VeilidUpdate::Shutdown => {
|
||||
sink.close();
|
||||
}
|
||||
_ => {
|
||||
sink.item_json(update);
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
);
|
||||
let update_callback = Arc::new(move |update: veilid_core::VeilidUpdate| {
|
||||
let sink = sink.clone();
|
||||
match update {
|
||||
veilid_core::VeilidUpdate::Shutdown => {
|
||||
sink.close();
|
||||
}
|
||||
_ => {
|
||||
sink.item_json(update);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let res = veilid_core::api_startup_json(update_callback, config_json).await;
|
||||
let veilid_api = check_err_json!(stream, res);
|
||||
|
@ -32,6 +32,7 @@ url = "^2"
|
||||
ctrlc = "^3"
|
||||
lazy_static = "^1"
|
||||
bugsalot = "^0"
|
||||
flume = { version = "^0", features = ["async"] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows-service = "^0"
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::client_api;
|
||||
use crate::settings::*;
|
||||
use crate::veilid_logs::*;
|
||||
use async_std::channel::{bounded, Receiver, Sender};
|
||||
use flume::{bounded, Receiver, Sender};
|
||||
use lazy_static::*;
|
||||
use log::*;
|
||||
use parking_lot::Mutex;
|
||||
@ -31,16 +31,11 @@ pub async fn run_veilid_server(settings: Settings, logs: VeilidLogs) -> Result<(
|
||||
) = bounded(1);
|
||||
|
||||
// Create VeilidCore setup
|
||||
let update_callback = Arc::new(
|
||||
move |change: veilid_core::VeilidUpdate| -> veilid_core::SystemPinBoxFuture<()> {
|
||||
let sender = sender.clone();
|
||||
Box::pin(async move {
|
||||
if sender.send(change).await.is_err() {
|
||||
error!("error sending veilid update callback");
|
||||
}
|
||||
})
|
||||
},
|
||||
);
|
||||
let update_callback = Arc::new(move |change: veilid_core::VeilidUpdate| {
|
||||
if sender.send(change).is_err() {
|
||||
error!("error sending veilid update callback");
|
||||
}
|
||||
});
|
||||
let config_callback = settings.get_core_config_callback();
|
||||
|
||||
// Start Veilid Core and get API
|
||||
@ -66,7 +61,7 @@ pub async fn run_veilid_server(settings: Settings, logs: VeilidLogs) -> Result<(
|
||||
// Handle state changes on main thread for capnproto rpc
|
||||
let update_receiver_jh = capi.clone().map(|capi| {
|
||||
async_std::task::spawn_local(async move {
|
||||
while let Ok(change) = receiver.recv().await {
|
||||
while let Ok(change) = receiver.recv_async().await {
|
||||
capi.clone().handle_update(change);
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user