#![allow(clippy::module_inception)]
mod manager;
mod service;
mod status;
mod types;
pub use manager::ServiceManager;
pub use service::Service;
pub use status::ServiceStatus;
pub use types::{ServiceAccess, ServiceControl, ServiceManagerAccess, ServiceState};
use std::time::Duration;
use crate::Result;
pub fn query(name: &str) -> Result<ServiceStatus> {
Service::open(name)?.query()
}
pub fn start(name: &str) -> Result<()> {
Service::open_with_access(name, ServiceAccess::Start)?.start()
}
pub fn stop(name: &str) -> Result<()> {
Service::open_with_access(name, ServiceAccess::Stop)?.stop()
}
pub fn restart(name: &str, timeout: Duration) -> Result<()> {
Service::open_with_access(
name,
ServiceAccess::Custom(
ServiceAccess::QueryStatus.to_windows()
| ServiceAccess::Start.to_windows()
| ServiceAccess::Stop.to_windows(),
),
)?
.restart(timeout)
}
pub fn list() -> Result<Vec<ServiceStatus>> {
ServiceManager::connect()?.list()
}
pub fn list_with_buffer(out_services: &mut Vec<ServiceStatus>) -> Result<usize> {
ServiceManager::connect()?.list_with_buffer(out_services)
}
pub fn list_with_filter<F>(out_services: &mut Vec<ServiceStatus>, filter: F) -> Result<usize>
where
F: Fn(&ServiceStatus) -> bool,
{
ServiceManager::connect()?.list_with_filter(out_services, filter)
}