From edb8f1fd7ed441af5e0ad4b1e719306da733712d Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 14 Apr 2016 21:50:35 +0300 Subject: [PATCH] doc effort --- parity/hypervisor/mod.rs | 9 +++++++++ parity/hypervisor/service.rs.in | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/parity/hypervisor/mod.rs b/parity/hypervisor/mod.rs index 3ea16ad08..d65d5076e 100644 --- a/parity/hypervisor/mod.rs +++ b/parity/hypervisor/mod.rs @@ -21,6 +21,7 @@ pub mod service; +/// Default value for hypervisor ipc listener pub const HYPERVISOR_IPC_URL: &'static str = "ipc:///tmp/parity-internal-hyper-status.ipc"; use nanoipc; @@ -46,10 +47,13 @@ impl Hypervisor { Hypervisor::with_url(HYPERVISOR_IPC_URL) } + /// Starts on the specified address for ipc listener fn with_url(addr: &str) -> Hypervisor{ Hypervisor::with_url_and_service(addr, HypervisorService::new()) } + /// Starts with the specified address for the ipc listener and + /// the specified list of modules in form of created service fn with_url_and_service(addr: &str, service: Arc) -> Hypervisor { let worker = nanoipc::Worker::new(&service); Hypervisor{ @@ -70,6 +74,7 @@ impl Hypervisor { } } + /// Creates IPC listener and starts all binaries fn start(&self) { let mut worker = self.ipc_worker.write().unwrap(); worker.add_reqrep(&self.ipc_addr).unwrap_or_else(|e| panic!("Hypervisor ipc worker can not start - critical! ({:?})", e)); @@ -79,6 +84,9 @@ impl Hypervisor { } } + /// Start binary for the specified module + /// Does nothing when it is already started on module is inside the + /// main binary fn start_module(&self, module_id: IpcModuleId) { Self::match_module(&module_id).map(|binary_id| { @@ -96,6 +104,7 @@ impl Hypervisor { }); } + /// Reports if all modules are checked in pub fn modules_ready(&self) -> bool { self.service.unchecked_count() == 0 } diff --git a/parity/hypervisor/service.rs.in b/parity/hypervisor/service.rs.in index 155d3976e..2efef6ffd 100644 --- a/parity/hypervisor/service.rs.in +++ b/parity/hypervisor/service.rs.in @@ -21,8 +21,10 @@ use std::collections::HashMap; pub type IpcModuleId = u64; +/// Blockhain database module id pub const BLOCKCHAIN_MODULE_ID: IpcModuleId = 2000; +/// IPC service that handles module management pub struct HypervisorService { check_list: RwLock>, } @@ -37,10 +39,12 @@ impl HypervisorService { } impl HypervisorService { + /// New service with the default list of modules pub fn new() -> Arc { HypervisorService::with_modules(vec![]) } + /// New service with list of modules that will report for being ready pub fn with_modules(module_ids: Vec) -> Arc { let mut check_list = HashMap::new(); for module_id in module_ids { @@ -51,10 +55,12 @@ impl HypervisorService { }) } + /// Number of modules still being waited for check-in pub fn unchecked_count(&self) -> usize { self.check_list.read().unwrap().iter().filter(|&(_, status)| !status).count() } + /// List of all modules within this service pub fn module_ids(&self) -> Vec { self.check_list.read().unwrap().iter().map(|(module_id, _)| module_id).cloned().collect() }