[test] Add getblockchaininfo functional test
[bitcoinplatinum.git] / src / qt / winshutdownmonitor.cpp
blobd78d9a2358ac2e48640a942cc661dd1e2593e04a
1 // Copyright (c) 2014-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include "winshutdownmonitor.h"
7 #if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
8 #include "init.h"
9 #include "util.h"
11 #include <windows.h>
13 #include <QDebug>
15 #include <openssl/rand.h>
17 // If we don't want a message to be processed by Qt, return true and set result to
18 // the value that the window procedure should return. Otherwise return false.
19 bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult)
21 Q_UNUSED(eventType);
23 MSG *pMsg = static_cast<MSG *>(pMessage);
25 // Seed OpenSSL PRNG with Windows event data (e.g. mouse movements and other user interactions)
26 if (RAND_event(pMsg->message, pMsg->wParam, pMsg->lParam) == 0) {
27 // Warn only once as this is performance-critical
28 static bool warned = false;
29 if (!warned) {
30 LogPrintf("%s: OpenSSL RAND_event() failed to seed OpenSSL PRNG with enough data.\n", __func__);
31 warned = true;
35 switch(pMsg->message)
37 case WM_QUERYENDSESSION:
39 // Initiate a client shutdown after receiving a WM_QUERYENDSESSION and block
40 // Windows session end until we have finished client shutdown.
41 StartShutdown();
42 *pnResult = FALSE;
43 return true;
46 case WM_ENDSESSION:
48 *pnResult = FALSE;
49 return true;
53 return false;
56 void WinShutdownMonitor::registerShutdownBlockReason(const QString& strReason, const HWND& mainWinId)
58 typedef BOOL (WINAPI *PSHUTDOWNBRCREATE)(HWND, LPCWSTR);
59 PSHUTDOWNBRCREATE shutdownBRCreate = (PSHUTDOWNBRCREATE)GetProcAddress(GetModuleHandleA("User32.dll"), "ShutdownBlockReasonCreate");
60 if (shutdownBRCreate == nullptr) {
61 qWarning() << "registerShutdownBlockReason: GetProcAddress for ShutdownBlockReasonCreate failed";
62 return;
65 if (shutdownBRCreate(mainWinId, strReason.toStdWString().c_str()))
66 qWarning() << "registerShutdownBlockReason: Successfully registered: " + strReason;
67 else
68 qWarning() << "registerShutdownBlockReason: Failed to register: " + strReason;
70 #endif