2021-07-19 08:15:20 +00:00
|
|
|
mod deps_resolve;
|
2021-07-14 13:12:52 +00:00
|
|
|
mod flowy_server;
|
2021-06-30 15:11:27 +00:00
|
|
|
pub mod module;
|
|
|
|
|
2021-07-17 02:26:05 +00:00
|
|
|
pub use crate::flowy_server::{ArcFlowyServer, FlowyServerMocker};
|
2021-07-08 13:23:44 +00:00
|
|
|
use flowy_dispatch::prelude::*;
|
2021-06-30 15:11:27 +00:00
|
|
|
use module::build_modules;
|
2021-07-14 13:12:52 +00:00
|
|
|
pub use module::*;
|
|
|
|
use std::sync::{
|
|
|
|
atomic::{AtomicBool, Ordering},
|
|
|
|
Arc,
|
|
|
|
};
|
2021-07-09 15:31:44 +00:00
|
|
|
|
2021-07-13 05:14:49 +00:00
|
|
|
static INIT_LOG: AtomicBool = AtomicBool::new(false);
|
2021-07-14 13:12:52 +00:00
|
|
|
pub struct FlowySDK {
|
|
|
|
root: String,
|
|
|
|
server: ArcFlowyServer,
|
|
|
|
}
|
2021-06-28 15:58:43 +00:00
|
|
|
|
|
|
|
impl FlowySDK {
|
2021-07-14 13:12:52 +00:00
|
|
|
pub fn new(root: &str) -> Self {
|
2021-07-17 02:26:05 +00:00
|
|
|
let server = Arc::new(FlowyServerMocker {});
|
2021-07-14 13:12:52 +00:00
|
|
|
Self {
|
|
|
|
root: root.to_owned(),
|
|
|
|
server,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-17 02:26:05 +00:00
|
|
|
pub fn construct(self) { FlowySDK::construct_with(&self.root, self.server.clone()) }
|
2021-07-14 13:12:52 +00:00
|
|
|
|
2021-07-17 02:26:05 +00:00
|
|
|
pub fn construct_with(root: &str, server: ArcFlowyServer) {
|
|
|
|
FlowySDK::init_log(root);
|
|
|
|
|
|
|
|
tracing::info!("🔥 Root path: {}", root);
|
2021-07-19 08:15:20 +00:00
|
|
|
match flowy_infra::kv::KVStore::init(root) {
|
|
|
|
Ok(_) => {},
|
|
|
|
Err(e) => tracing::error!("Init kv store failedL: {}", e),
|
|
|
|
}
|
2021-07-17 02:26:05 +00:00
|
|
|
FlowySDK::init_modules(root, server);
|
2021-07-14 13:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn init_log(directory: &str) {
|
2021-07-13 05:14:49 +00:00
|
|
|
if !INIT_LOG.load(Ordering::SeqCst) {
|
|
|
|
INIT_LOG.store(true, Ordering::SeqCst);
|
|
|
|
flowy_log::init_log("flowy", directory, "Debug").unwrap();
|
|
|
|
}
|
|
|
|
}
|
2021-06-28 15:58:43 +00:00
|
|
|
|
2021-07-14 13:12:52 +00:00
|
|
|
fn init_modules(root: &str, server: ArcFlowyServer) {
|
2021-07-09 15:31:44 +00:00
|
|
|
let config = ModuleConfig {
|
2021-07-14 13:12:52 +00:00
|
|
|
root: root.to_owned(),
|
2021-07-09 15:31:44 +00:00
|
|
|
};
|
2021-07-14 13:12:52 +00:00
|
|
|
EventDispatch::construct(|| build_modules(config, server));
|
2021-06-30 15:11:27 +00:00
|
|
|
}
|
2021-06-28 15:58:43 +00:00
|
|
|
}
|