large rewrite to make mize run on every platform
This commit is contained in:
16
src/core/instance/connection.rs
Normal file
16
src/core/instance/connection.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use log::{trace, debug, info, warn, error};
|
||||
use tokio::sync::mpsc::{Sender, Receiver};
|
||||
|
||||
use crate::proto::MizeMessage;
|
||||
use crate::error::{MizeError, MizeResult, IntoMizeResult};
|
||||
|
||||
pub trait Connection {
|
||||
}
|
||||
|
||||
|
||||
//#[derive(Debug)]
|
||||
//pub struct Connection {
|
||||
//tx: Sender<MizeMessage>,
|
||||
//rx: Receiver<MizeMessage>,
|
||||
//}
|
||||
|
||||
71
src/core/instance/mod.rs
Normal file
71
src/core/instance/mod.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs::create_dir;
|
||||
use log::{trace, debug, info, warn, error};
|
||||
use uuid::Uuid;
|
||||
use std::fs::File;
|
||||
use colored::Colorize;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::error::{MizeError, MizeResult, IntoMizeResult, MizeResultTrait};
|
||||
use crate::instance::store::Store;
|
||||
use crate::instance::connection::Connection;
|
||||
use crate::id::MizeId;
|
||||
use crate::instance::subscription::Subscription;
|
||||
use crate::item::{Item, ItemData};
|
||||
use crate::memstore::MemStore;
|
||||
|
||||
pub mod connection;
|
||||
pub mod store;
|
||||
pub mod subscription;
|
||||
|
||||
static MSG_CHANNEL_SIZE: usize = 200;
|
||||
|
||||
/// The Instance type is the heart of the mize system
|
||||
pub struct Instance<S: Store> {
|
||||
// question vec of stores???
|
||||
// would mean replication logic and such things is handeled by the instance
|
||||
// i think it would be better thogh to then implement a ReplicatedStore
|
||||
store: S,
|
||||
peers: Vec<Box<dyn Connection>>,
|
||||
subs: HashMap<MizeId, Subscription>
|
||||
}
|
||||
|
||||
/*
|
||||
pub enum RealmId {
|
||||
Uuid(Uuid),
|
||||
Local(Vec<String>),
|
||||
Tld(Vec<String>),
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
impl<S: Store> Instance<S> {
|
||||
// new() opens a
|
||||
pub async fn new() -> MizeResult<Instance<MemStore>> {
|
||||
trace!("[ {} ] Instance::new()", "CALL".yellow());
|
||||
|
||||
let memstore = MemStore::new();
|
||||
let instance = Instance {store: memstore, peers: Vec::new(), subs: HashMap::new()};
|
||||
|
||||
// platform specific init code
|
||||
// TODO
|
||||
|
||||
return Ok(instance);
|
||||
}
|
||||
|
||||
pub fn new_item(self) -> MizeResult<Item<S>> {
|
||||
let id = self.store.new_id()?;
|
||||
return Ok(Item {id, instance: self});
|
||||
}
|
||||
|
||||
pub fn get<I: Into<MizeId>>(self, id: I) -> MizeResult<Item<S>> {
|
||||
return Ok(Item {id: id.into(), instance: self});
|
||||
}
|
||||
|
||||
pub fn set<I: Into<MizeId>, V: Into<ItemData>>(self, id: I, value: V) -> MizeResult<()> {
|
||||
self.store.set(id.into(), value)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
27
src/core/instance/store.rs
Normal file
27
src/core/instance/store.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use crate::error::MizeResult;
|
||||
use crate::item::{Item, ItemData};
|
||||
use crate::id::MizeId;
|
||||
|
||||
pub trait Store {
|
||||
// should have the ability to be multi threaded, if the underlying implementation supports
|
||||
// multithreaded IO operations
|
||||
// for now all refs to a store hold a Mutex but this mutex is part of where the MizeStore trait
|
||||
// is implemented, so that there can be a multithreaded implementation
|
||||
//fn get(self, id: MizeId) -> MizeResult<Item<Self>> where Self: Sized;
|
||||
|
||||
fn set<T: Into<ItemData>>(self, id: MizeId, data: T) -> MizeResult<()>;
|
||||
|
||||
// in the future should implement transactions, ....
|
||||
|
||||
// funcs to do with links, backlinks
|
||||
fn get_links(self, item: Item<Self>) -> MizeResult<Vec<MizeId>> where Self: Sized;
|
||||
|
||||
fn get_backlinks(self, item: Item<Self>) -> MizeResult<Vec<MizeId>> where Self: Sized;
|
||||
|
||||
fn new_id(&self) -> MizeResult<MizeId>;
|
||||
}
|
||||
|
||||
/// references an item that is stored in a store
|
||||
pub trait StoreRef {
|
||||
// do we need this or is this basically an item
|
||||
}
|
||||
3
src/core/instance/subscription.rs
Normal file
3
src/core/instance/subscription.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
pub struct Subscription;
|
||||
Reference in New Issue
Block a user