};
use anyhow::Result;
-use log::{error, info, trace, warn, debug};
+use log::{debug, error, info, trace, warn};
use windows::Win32::Foundation::{ERROR_SERVICE_DOES_NOT_EXIST, WIN32_ERROR};
use windows_service::{
service::{
.basename(consts::SERVICE_NAME),
)
.duplicate_to_stdout(flexi_logger::Duplicate::All)
- .format(if is_debug { flexi_logger::default_format } else { flexi_logger::detailed_format })
+ .format(if is_debug {
+ flexi_logger::default_format
+ } else {
+ flexi_logger::detailed_format
+ })
.rotate(
flexi_logger::Criterion::Size(1024 * 1024),
flexi_logger::Naming::Timestamps,
fn service_main(arguments: Vec<OsString>) {
if let Err(error) = run_service(arguments) {
- println!("Error: {error}");
+ error!("{error}");
}
}
let completed: Arc<AtomicBool> = Arc::new(AtomicBool::new(false));
let completed_event_handler = Arc::clone(&completed);
+
+ info!("Setuping the event handler...");
+
let event_handler = move |control_event| -> ServiceControlHandlerResult {
match control_event {
ServiceControl::Stop => {
// Register system service event handler
let status_handle = service_control_handler::register(consts::SERVICE_NAME, event_handler)?;
- let running_status = ServiceStatus {
- // Should match the one from system service registry
+ status_handle.set_service_status(ServiceStatus {
service_type: ServiceType::OWN_PROCESS,
-
- // The new state
current_state: ServiceState::Running,
-
- // Accept stop events when running
controls_accepted: ServiceControlAccept::STOP | ServiceControlAccept::SHUTDOWN,
-
- // Used to report an error when starting or stopping only, otherwise must be zero
exit_code: ServiceExitCode::Win32(0),
-
- // Only used for pending states, otherwise must be zero
checkpoint: 0,
-
- // Only used for pending states, otherwise must be zero
wait_hint: Duration::default(),
-
- process_id: None,
- };
-
- status_handle.set_service_status(running_status)?;
+ process_id: None, //Some(std::process::id()),
+ })?;
main_loop::main_loop(completed.clone());
exit_code: ServiceExitCode::Win32(0),
checkpoint: 0,
wait_hint: Duration::default(),
- process_id: None,
+ process_id: None, //Some(std::process::id()),
})?;
info!("Main loop stopped: Temperature to RGB will now shut down");