static LRESULT CALLBACK message_pump_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { int rc; switch (msg) { case WM_USER: log_debug("Destroying message pump window"); if (!DestroyWindow(hwnd)) { rc = ERRNO_WINAPI_OFFSET + GetLastError(); log_warn("Could not destroy message pump window: %s (%d)", get_errno_name(rc), rc); } return 0; case WM_DESTROY: log_debug("Posting quit message message loop"); PostQuitMessage(0); return 0; case WM_DEVICECHANGE: handle_device_event(wparam); return TRUE; } return DefWindowProc(hwnd, msg, wparam, lparam); }
static DWORD WINAPI service_control_handler(DWORD control, DWORD event_type, LPVOID event_data, LPVOID context) { (void)event_data; (void)context; switch (control) { case SERVICE_CONTROL_INTERROGATE: return NO_ERROR; case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_STOP: if (control == SERVICE_CONTROL_SHUTDOWN) { log_info("Received shutdown command"); } else { log_info("Received stop command"); } service_set_status(SERVICE_STOP_PENDING, NO_ERROR); event_stop(); return NO_ERROR; case SERVICE_CONTROL_DEVICEEVENT: handle_device_event(event_type); return NO_ERROR; } return ERROR_CALL_NOT_IMPLEMENTED; }
void handle_device_fd(int sock) { char msg[UEVENT_MSG_LEN+2]; int n; while ((n = uevent_kernel_multicast_recv(sock, msg, UEVENT_MSG_LEN)) > 0) { if(n >= UEVENT_MSG_LEN) /* overflow -- discard */ continue; msg[n] = '\0'; msg[n+1] = '\0'; struct uevent uevent; parse_event(msg, &uevent); handle_device_event(&uevent); } }