1 #include "uv.h"
2 #include "internal.h"
3 #include "winapi.h"
4 
5 static void uv__register_system_resume_callback(void);
6 
uv__init_detect_system_wakeup(void)7 void uv__init_detect_system_wakeup(void) {
8   /* Try registering system power event callback. This is the cleanest
9    * method, but it will only work on Win8 and above.
10    */
11   uv__register_system_resume_callback();
12 }
13 
uv__system_resume_callback(PVOID Context,ULONG Type,PVOID Setting)14 static ULONG CALLBACK uv__system_resume_callback(PVOID Context,
15                                                  ULONG Type,
16                                                  PVOID Setting) {
17   if (Type == PBT_APMRESUMESUSPEND || Type == PBT_APMRESUMEAUTOMATIC)
18     uv__wake_all_loops();
19 
20   return 0;
21 }
22 
uv__register_system_resume_callback(void)23 static void uv__register_system_resume_callback(void) {
24   _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS recipient;
25   _HPOWERNOTIFY registration_handle;
26 
27   if (pPowerRegisterSuspendResumeNotification == NULL)
28     return;
29 
30   recipient.Callback = uv__system_resume_callback;
31   recipient.Context = NULL;
32   (*pPowerRegisterSuspendResumeNotification)(DEVICE_NOTIFY_CALLBACK,
33                                              &recipient,
34                                              &registration_handle);
35 }
36