diff --git a/.idea/appflowy_client.iml b/.idea/appflowy_client.iml
index ab4b547fce..505f9c01d4 100644
--- a/.idea/appflowy_client.iml
+++ b/.idea/appflowy_client.iml
@@ -11,6 +11,7 @@
+
diff --git a/rust-lib/dart-ffi/src/c.rs b/rust-lib/dart-ffi/src/c.rs
index f5ed57fa59..431cdcde4c 100644
--- a/rust-lib/dart-ffi/src/c.rs
+++ b/rust-lib/dart-ffi/src/c.rs
@@ -1,5 +1,4 @@
use byteorder::{BigEndian, ByteOrder};
-use flowy_protobuf::ResponsePacket;
use std::mem::{forget, size_of};
pub fn forget_rust(buf: Vec) -> *const u8 {
diff --git a/rust-lib/dart-ffi/src/lib.rs b/rust-lib/dart-ffi/src/lib.rs
index a3dddad424..cdf7d33d57 100644
--- a/rust-lib/dart-ffi/src/lib.rs
+++ b/rust-lib/dart-ffi/src/lib.rs
@@ -13,23 +13,37 @@ pub extern "C" fn init_sdk(path: *mut c_char) -> i64 {
return 1;
}
+pub struct FFICommand {
+ event: String,
+ payload: Vec,
+}
+
+impl FFICommand {
+ pub fn from_bytes(bytes: Vec) -> Self { unimplemented!() }
+
+ pub fn from_u8_pointer(pointer: *const u8, len: usize) -> Self {
+ let bytes = unsafe { std::slice::from_raw_parts(pointer, len) }.to_vec();
+ unimplemented!()
+ }
+}
+
#[no_mangle]
pub extern "C" fn async_command(port: i64, input: *const u8, len: usize) {
- let bytes = unsafe { std::slice::from_raw_parts(input, len) }.to_vec();
- let payload = SenderPayload::from_data(bytes);
+ let FFICommand { event, payload } = FFICommand::from_u8_pointer(input, len);
- let stream_data = SenderData::new(port, payload).callback(Box::new(|_config, response| {
- log::info!("async resp: {:?}", response);
- }));
+ let mut request = SenderRequest::new(port, event).callback(|_, resp| {
+ log::info!("async resp: {:?}", resp);
+ });
- async_send(stream_data);
+ if !payload.is_empty() {
+ request = request.payload(Payload::Bytes(bytes));
+ }
+
+ async_send(request);
}
#[no_mangle]
-pub extern "C" fn sync_command(input: *const u8, len: usize) -> *const u8 {
- let bytes = unsafe { std::slice::from_raw_parts(input, len) }.to_vec();
- forget_rust(bytes)
-}
+pub extern "C" fn sync_command(input: *const u8, len: usize) -> *const u8 { unimplemented!() }
#[inline(never)]
#[no_mangle]
diff --git a/rust-lib/flowy-sdk/Cargo.toml b/rust-lib/flowy-sdk/Cargo.toml
index a4576af753..23fe08189d 100644
--- a/rust-lib/flowy-sdk/Cargo.toml
+++ b/rust-lib/flowy-sdk/Cargo.toml
@@ -7,4 +7,15 @@ edition = "2018"
[dependencies]
flowy-sys = { path = "../flowy-sys" }
-flowy-log = { path = "../flowy-log" }
\ No newline at end of file
+flowy-log = { path = "../flowy-log" }
+flowy-user = { path = "../flowy-user" }
+
+log = "0.4.14"
+
+[dev-dependencies]
+serde = { version = "1.0", features = ["derive"] }
+bincode = { version = "1.3"}
+protobuf = {version = "2.24.1"}
+claim = "0.5.0"
+tokio = { version = "1", features = ["full"]}
+futures-util = "0.3.15"
\ No newline at end of file
diff --git a/rust-lib/flowy-sdk/src/lib.rs b/rust-lib/flowy-sdk/src/lib.rs
index 035f8a9639..3b52dbe263 100644
--- a/rust-lib/flowy-sdk/src/lib.rs
+++ b/rust-lib/flowy-sdk/src/lib.rs
@@ -1,21 +1,24 @@
-use flowy_sys::prelude::*;
-use std::cell::RefCell;
+pub mod module;
+pub use module::*;
+use flowy_sys::prelude::*;
+use module::build_modules;
+use std::cell::RefCell;
pub struct FlowySDK {}
impl FlowySDK {
pub fn init(path: &str) {
- let modules = init_modules();
- init_system(modules);
+ flowy_log::init_log("flowy", "Debug").unwrap();
+
+ log::info!("🔥🔥🔥 System start running");
+ match init_system(build_modules()).run() {
+ Ok(_) => {},
+ Err(e) => log::error!("System run fail with error: {:?}", e),
+ }
}
}
-pub fn init_modules() -> Vec {
- let modules = vec![];
- modules
-}
-
-pub fn init_system(modules: Vec) {
+pub fn init_system(modules: Vec) -> SystemRunner {
FlowySystem::construct(
|| modules,
|module_map, runtime| {
@@ -27,22 +30,20 @@ pub fn init_system(modules: Vec) {
});
},
)
- .run()
- .unwrap();
}
thread_local!(
static SENDER: RefCell