Blame src/win/detect-wakeup.c

Packit Service e2ebee
/* Copyright libuv project contributors. All rights reserved.
Packit Service e2ebee
 *
Packit Service e2ebee
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit Service e2ebee
 * of this software and associated documentation files (the "Software"), to
Packit Service e2ebee
 * deal in the Software without restriction, including without limitation the
Packit Service e2ebee
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Packit Service e2ebee
 * sell copies of the Software, and to permit persons to whom the Software is
Packit Service e2ebee
 * furnished to do so, subject to the following conditions:
Packit Service e2ebee
 *
Packit Service e2ebee
 * The above copyright notice and this permission notice shall be included in
Packit Service e2ebee
 * all copies or substantial portions of the Software.
Packit Service e2ebee
 *
Packit Service e2ebee
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service e2ebee
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service e2ebee
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit Service e2ebee
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit Service e2ebee
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit Service e2ebee
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Packit Service e2ebee
 * IN THE SOFTWARE.
Packit Service e2ebee
 */
Packit Service e2ebee
Packit Service 7c31a4
#include "uv.h"
Packit Service 7c31a4
#include "internal.h"
Packit Service 7c31a4
#include "winapi.h"
Packit Service 7c31a4
Packit Service 7c31a4
static void uv__register_system_resume_callback(void);
Packit Service 7c31a4
Packit Service 7c31a4
void uv__init_detect_system_wakeup(void) {
Packit Service 7c31a4
  /* Try registering system power event callback. This is the cleanest
Packit Service 7c31a4
   * method, but it will only work on Win8 and above.
Packit Service 7c31a4
   */
Packit Service 7c31a4
  uv__register_system_resume_callback();
Packit Service 7c31a4
}
Packit Service 7c31a4
Packit Service 7c31a4
static ULONG CALLBACK uv__system_resume_callback(PVOID Context,
Packit Service 7c31a4
                                                 ULONG Type,
Packit Service 7c31a4
                                                 PVOID Setting) {
Packit Service 7c31a4
  if (Type == PBT_APMRESUMESUSPEND || Type == PBT_APMRESUMEAUTOMATIC)
Packit Service 7c31a4
    uv__wake_all_loops();
Packit Service 7c31a4
Packit Service 7c31a4
  return 0;
Packit Service 7c31a4
}
Packit Service 7c31a4
Packit Service 7c31a4
static void uv__register_system_resume_callback(void) {
Packit Service 7c31a4
  _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS recipient;
Packit Service 7c31a4
  _HPOWERNOTIFY registration_handle;
Packit Service 7c31a4
Packit Service 7c31a4
  if (pPowerRegisterSuspendResumeNotification == NULL)
Packit Service 7c31a4
    return;
Packit Service 7c31a4
Packit Service 7c31a4
  recipient.Callback = uv__system_resume_callback;
Packit Service 7c31a4
  recipient.Context = NULL;
Packit Service 7c31a4
  (*pPowerRegisterSuspendResumeNotification)(DEVICE_NOTIFY_CALLBACK,
Packit Service 7c31a4
                                             &recipient,
Packit Service 7c31a4
                                             &registration_handle);
Packit Service 7c31a4
}