flutter and macos work
This commit is contained in:
@@ -54,6 +54,7 @@ macro_rules! check_err_json {
|
||||
/////////////////////////////////////////
|
||||
// Initializer
|
||||
#[no_mangle]
|
||||
#[instrument]
|
||||
pub extern "C" fn initialize_veilid_flutter(dart_post_c_object_ptr: ffi::DartPostCObjectFnType) {
|
||||
unsafe {
|
||||
store_dart_post_cobject(dart_post_c_object_ptr);
|
||||
@@ -91,6 +92,7 @@ pub extern "C" fn initialize_veilid_flutter(dart_post_c_object_ptr: ffi::DartPos
|
||||
/// C-compatible FFI Functions
|
||||
|
||||
#[no_mangle]
|
||||
#[instrument]
|
||||
pub extern "C" fn startup_veilid_core(port: i64, config: FfiStr) {
|
||||
let config = config.into_opt_string();
|
||||
let stream = DartIsolateStream::new(port);
|
||||
@@ -141,6 +143,7 @@ pub extern "C" fn get_veilid_state(port: i64) {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[instrument(level = "debug")]
|
||||
pub extern "C" fn change_api_log_level(port: i64, log_level: FfiStr) {
|
||||
let log_level = log_level.into_opt_string();
|
||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
||||
@@ -153,6 +156,7 @@ pub extern "C" fn change_api_log_level(port: i64, log_level: FfiStr) {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[instrument]
|
||||
pub extern "C" fn shutdown_veilid_core(port: i64) {
|
||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
||||
let veilid_api = take_veilid_api().await?;
|
||||
@@ -184,6 +188,7 @@ pub struct VeilidVersion {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[instrument]
|
||||
pub extern "C" fn veilid_version() -> VeilidVersion {
|
||||
let (major, minor, patch) = veilid_core::veilid_version();
|
||||
VeilidVersion {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
pub use allo_isolate::ffi::DartCObject;
|
||||
pub use allo_isolate::IntoDart;
|
||||
use allo_isolate::Isolate;
|
||||
use core::fmt::Debug;
|
||||
use core::future::Future;
|
||||
use parking_lot::Mutex;
|
||||
use serde::*;
|
||||
@@ -31,8 +32,8 @@ impl DartIsolateWrapper {
|
||||
pub fn spawn_result<F, T, E>(self, future: F)
|
||||
where
|
||||
F: Future<Output = Result<T, E>> + Send + 'static,
|
||||
T: IntoDart,
|
||||
E: Serialize,
|
||||
T: IntoDart + Debug,
|
||||
E: Serialize + Debug,
|
||||
{
|
||||
async_std::task::spawn(async move {
|
||||
self.result(future.await);
|
||||
@@ -42,21 +43,24 @@ impl DartIsolateWrapper {
|
||||
pub fn spawn_result_json<F, T, E>(self, future: F)
|
||||
where
|
||||
F: Future<Output = Result<T, E>> + Send + 'static,
|
||||
T: Serialize,
|
||||
E: Serialize,
|
||||
T: Serialize + Debug,
|
||||
E: Serialize + Debug,
|
||||
{
|
||||
async_std::task::spawn(async move {
|
||||
self.result_json(future.await);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn result<T: IntoDart, E: Serialize>(self, result: Result<T, E>) -> bool {
|
||||
pub fn result<T: IntoDart + Debug, E: Serialize + Debug>(self, result: Result<T, E>) -> bool {
|
||||
match result {
|
||||
Ok(v) => self.ok(v),
|
||||
Err(e) => self.err_json(e),
|
||||
}
|
||||
}
|
||||
pub fn result_json<T: Serialize, E: Serialize>(self, result: Result<T, E>) -> bool {
|
||||
pub fn result_json<T: Serialize + Debug, E: Serialize + Debug>(
|
||||
self,
|
||||
result: Result<T, E>,
|
||||
) -> bool {
|
||||
match result {
|
||||
Ok(v) => self.ok_json(v),
|
||||
Err(e) => self.err_json(e),
|
||||
@@ -67,19 +71,19 @@ impl DartIsolateWrapper {
|
||||
.post(vec![MESSAGE_OK.into_dart(), value.into_dart()])
|
||||
}
|
||||
|
||||
pub fn ok_json<T: Serialize>(self, value: T) -> bool {
|
||||
pub fn ok_json<T: Serialize + Debug>(self, value: T) -> bool {
|
||||
self.isolate.post(vec![
|
||||
MESSAGE_OK_JSON.into_dart(),
|
||||
veilid_core::serialize_json(value).into_dart(),
|
||||
])
|
||||
}
|
||||
|
||||
// pub fn err<E: IntoDart>(self, error: E) -> bool {
|
||||
// pub fn err<E: IntoDart + Debug>(self, error: E) -> bool {
|
||||
// self.isolate
|
||||
// .post(vec![MESSAGE_ERR.into_dart(), error.into_dart()])
|
||||
// }
|
||||
|
||||
pub fn err_json<E: Serialize>(self, error: E) -> bool {
|
||||
pub fn err_json<E: Serialize + Debug>(self, error: E) -> bool {
|
||||
self.isolate.post(vec![
|
||||
MESSAGE_ERR_JSON.into_dart(),
|
||||
veilid_core::serialize_json(error).into_dart(),
|
||||
@@ -122,7 +126,7 @@ impl DartIsolateStream {
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn item_json<T: Serialize>(&self, value: T) -> bool {
|
||||
pub fn item_json<T: Serialize + Debug>(&self, value: T) -> bool {
|
||||
let inner = self.inner.lock();
|
||||
if let Some(isolate) = &inner.isolate {
|
||||
isolate.post(vec![
|
||||
@@ -134,7 +138,7 @@ impl DartIsolateStream {
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn abort<E: IntoDart>(self, error: E) -> bool {
|
||||
// pub fn abort<E: IntoDart + Debug>(self, error: E) -> bool {
|
||||
// let mut inner = self.inner.lock();
|
||||
// if let Some(isolate) = inner.isolate.take() {
|
||||
// isolate.post(vec![MESSAGE_STREAM_ABORT.into_dart(), error.into_dart()])
|
||||
@@ -143,7 +147,7 @@ impl DartIsolateStream {
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn abort_json<E: Serialize>(self, error: E) -> bool {
|
||||
pub fn abort_json<E: Serialize + Debug>(self, error: E) -> bool {
|
||||
let mut inner = self.inner.lock();
|
||||
if let Some(isolate) = inner.isolate.take() {
|
||||
isolate.post(vec![
|
||||
|
Reference in New Issue
Block a user