From 239c11d0dd4287e74286c40fb338aea85f4b1996 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sat, 19 May 2012 09:35:26 +0200 Subject: [PATCH] Make testcases build, prevent windows symbol collision --- src/bitcoinrpc.cpp | 4 +-- src/init.cpp | 55 +++++++++++--------------------- src/init.h | 1 - src/main.cpp | 2 +- src/makefile.linux-mingw | 3 +- src/makefile.mingw | 3 +- src/makefile.osx | 3 +- src/makefile.unix | 3 +- src/noui.cpp | 35 +++++++++++++++++++++ src/qt/bitcoin.cpp | 2 +- src/test/test_bitcoin.cpp | 4 +++ src/ui_interface.h | 66 +++++++++++++++++++-------------------- src/util.cpp | 2 +- 13 files changed, 103 insertions(+), 80 deletions(-) create mode 100644 src/noui.cpp diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index cc4d85cb..6c51bad6 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2630,7 +2630,7 @@ void ThreadRPCServer2(void* parg) strWhatAmI.c_str(), GetConfigFile().string().c_str(), EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()), - _("Error"), MF_OK | MF_MODAL); + _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL); uiInterface.QueueShutdown(); return; } @@ -2651,7 +2651,7 @@ void ThreadRPCServer2(void* parg) catch(boost::system::system_error &e) { uiInterface.ThreadSafeMessageBox(strprintf(_("An error occured while setting up the RPC port %i for listening: %s"), endpoint.port(), e.what()), - _("Error"), MF_OK | MF_MODAL); + _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL); uiInterface.QueueShutdown(); return; } diff --git a/src/init.cpp b/src/init.cpp index 096f2896..e0c0c893 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -91,41 +91,6 @@ void HandleSIGTERM(int) // Start // #if !defined(QT_GUI) -static int noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style) -{ - printf("%s: %s\n", caption.c_str(), message.c_str()); - fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str()); - return 4; -} - -static bool noui_ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption) -{ - return true; -} - -static void noui_QueueShutdown() -{ - // Without UI, Shutdown can simply be started in a new thread - CreateThread(Shutdown, NULL); -} - -int main(int argc, char* argv[]) -{ - bool fRet = false; - - // Connect bitcoind signal handlers - uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox); - uiInterface.ThreadSafeAskFee.connect(noui_ThreadSafeAskFee); - uiInterface.QueueShutdown.connect(noui_QueueShutdown); - - fRet = AppInit(argc, argv); - - if (fRet && fDaemon) - return 0; - - return 1; -} - bool AppInit(int argc, char* argv[]) { bool fRet = false; @@ -181,17 +146,33 @@ bool AppInit(int argc, char* argv[]) Shutdown(NULL); return fRet; } + +extern void noui_connect(); +int main(int argc, char* argv[]) +{ + bool fRet = false; + + // Connect bitcoind signal handlers + noui_connect(); + + fRet = AppInit(argc, argv); + + if (fRet && fDaemon) + return 0; + + return 1; +} #endif bool static InitError(const std::string &str) { - uiInterface.ThreadSafeMessageBox(str, _("Bitcoin"), MF_OK|MF_MODAL); + uiInterface.ThreadSafeMessageBox(str, _("Bitcoin"), CClientUIInterface::OK | CClientUIInterface::MODAL); return false; } bool static InitWarning(const std::string &str) { - uiInterface.ThreadSafeMessageBox(str, _("Bitcoin"), MF_OK | MF_ICON_EXCLAMATION | MF_MODAL); + uiInterface.ThreadSafeMessageBox(str, _("Bitcoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL); return true; } diff --git a/src/init.h b/src/init.h index 9a8f98cc..970527c7 100644 --- a/src/init.h +++ b/src/init.h @@ -10,7 +10,6 @@ extern CWallet* pwalletMain; void Shutdown(void* parg); -bool AppInit(int argc, char* argv[]); bool AppInit2(); std::string HelpMessage(); diff --git a/src/main.cpp b/src/main.cpp index 8410b9af..e62331de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1858,7 +1858,7 @@ bool CheckDiskSpace(uint64 nAdditionalBytes) string strMessage = _("Warning: Disk space is low"); strMiscWarning = strMessage; printf("*** %s\n", strMessage.c_str()); - uiInterface.ThreadSafeMessageBox(strMessage, "Bitcoin", MF_OK | MF_ICON_EXCLAMATION | MF_MODAL); + uiInterface.ThreadSafeMessageBox(strMessage, "Bitcoin", CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL); uiInterface.QueueShutdown(); return false; } diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw index 1e9dd687..61b38a66 100644 --- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -64,7 +64,8 @@ OBJS= \ obj/sync.o \ obj/util.o \ obj/wallet.o \ - obj/walletdb.o + obj/walletdb.o \ + obj/noui.o all: bitcoind.exe diff --git a/src/makefile.mingw b/src/makefile.mingw index fdd4f463..47bf8d53 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -61,7 +61,8 @@ OBJS= \ obj/sync.o \ obj/util.o \ obj/wallet.o \ - obj/walletdb.o + obj/walletdb.o \ + obj/noui.o all: bitcoind.exe diff --git a/src/makefile.osx b/src/makefile.osx index d6433a69..227756f2 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -88,7 +88,8 @@ OBJS= \ obj/sync.o \ obj/util.o \ obj/wallet.o \ - obj/walletdb.o + obj/walletdb.o \ + obj/noui.o ifdef USE_UPNP DEFS += -DUSE_UPNP=$(USE_UPNP) diff --git a/src/makefile.unix b/src/makefile.unix index ec6609f9..04e17866 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -108,7 +108,8 @@ OBJS= \ obj/sync.o \ obj/util.o \ obj/wallet.o \ - obj/walletdb.o + obj/walletdb.o \ + obj/noui.o all: bitcoind diff --git a/src/noui.cpp b/src/noui.cpp new file mode 100644 index 00000000..57f53b1c --- /dev/null +++ b/src/noui.cpp @@ -0,0 +1,35 @@ +// Copyright (c) 2010 Satoshi Nakamoto +// Copyright (c) 2009-2012 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file license.txt or http://www.opensource.org/licenses/mit-license.php. +#include "ui_interface.h" +#include "init.h" +#include "bitcoinrpc.h" + +#include + +static int noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style) +{ + printf("%s: %s\n", caption.c_str(), message.c_str()); + fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str()); + return 4; +} + +static bool noui_ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption) +{ + return true; +} + +static void noui_QueueShutdown() +{ + // Without UI, Shutdown can simply be started in a new thread + CreateThread(Shutdown, NULL); +} + +void noui_connect() +{ + // Connect bitcoind signal handlers + uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox); + uiInterface.ThreadSafeAskFee.connect(noui_ThreadSafeAskFee); + uiInterface.QueueShutdown.connect(noui_QueueShutdown); +} diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index c5592b28..07bdee08 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -42,7 +42,7 @@ static void ThreadSafeMessageBox(const std::string& message, const std::string& // Message from network thread if(guiref) { - bool modal = (style & MF_MODAL); + bool modal = (style & CClientUIInterface::MODAL); // in case of modal message, use blocking connection to wait for user to click OK QMetaObject::invokeMethod(guiref, "error", modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection, diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index 7ff7545a..bf597c9b 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -5,11 +5,15 @@ #include "wallet.h" CWallet* pwalletMain; +CClientUIInterface uiInterface; extern bool fPrintToConsole; +extern void noui_connect(); + struct TestingSetup { TestingSetup() { fPrintToConsole = true; // don't want to write to debug.log file + noui_connect(); pwalletMain = new CWallet(); RegisterWallet(pwalletMain); } diff --git a/src/ui_interface.h b/src/ui_interface.h index 954a7810..711a56d5 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -13,39 +13,6 @@ class CBasicKeyStore; class CWallet; class uint256; -/** Flags for CClientUIInterface::ThreadSafeMessageBox */ -enum MessageBoxFlags -{ - MF_YES = 0x00000002, - MF_OK = 0x00000004, - MF_NO = 0x00000008, - MF_YES_NO = (MF_YES|MF_NO), - MF_CANCEL = 0x00000010, - MF_APPLY = 0x00000020, - MF_CLOSE = 0x00000040, - MF_OK_DEFAULT = 0x00000000, - MF_YES_DEFAULT = 0x00000000, - MF_NO_DEFAULT = 0x00000080, - MF_CANCEL_DEFAULT = 0x80000000, - MF_ICON_EXCLAMATION = 0x00000100, - MF_ICON_HAND = 0x00000200, - MF_ICON_WARNING = MF_ICON_EXCLAMATION, - MF_ICON_ERROR = MF_ICON_HAND, - MF_ICON_QUESTION = 0x00000400, - MF_ICON_INFORMATION = 0x00000800, - MF_ICON_STOP = MF_ICON_HAND, - MF_ICON_ASTERISK = MF_ICON_INFORMATION, - MF_ICON_MASK = (0x00000100|0x00000200|0x00000400|0x00000800), - MF_FORWARD = 0x00001000, - MF_BACKWARD = 0x00002000, - MF_RESET = 0x00004000, - MF_HELP = 0x00008000, - MF_MORE = 0x00010000, - MF_SETUP = 0x00020000, -// Force blocking, modal message box dialog (not just OS notification) - MF_MODAL = 0x00040000 -}; - /** General change type (added, updated, removed). */ enum ChangeType { @@ -58,6 +25,39 @@ enum ChangeType class CClientUIInterface { public: + /** Flags for CClientUIInterface::ThreadSafeMessageBox */ + enum MessageBoxFlags + { + YES = 0x00000002, + OK = 0x00000004, + NO = 0x00000008, + YES_NO = (YES|NO), + CANCEL = 0x00000010, + APPLY = 0x00000020, + CLOSE = 0x00000040, + OK_DEFAULT = 0x00000000, + YES_DEFAULT = 0x00000000, + NO_DEFAULT = 0x00000080, + CANCEL_DEFAULT = 0x80000000, + ICON_EXCLAMATION = 0x00000100, + ICON_HAND = 0x00000200, + ICON_WARNING = ICON_EXCLAMATION, + ICON_ERROR = ICON_HAND, + ICON_QUESTION = 0x00000400, + ICON_INFORMATION = 0x00000800, + ICON_STOP = ICON_HAND, + ICON_ASTERISK = ICON_INFORMATION, + ICON_MASK = (0x00000100|0x00000200|0x00000400|0x00000800), + FORWARD = 0x00001000, + BACKWARD = 0x00002000, + RESET = 0x00004000, + HELP = 0x00008000, + MORE = 0x00010000, + SETUP = 0x00020000, + // Force blocking, modal message box dialog (not just OS notification) + MODAL = 0x00040000 + }; + /** Show message box. */ boost::signals2::signal ThreadSafeMessageBox; diff --git a/src/util.cpp b/src/util.cpp index a9b65ed9..108f33b7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1000,7 +1000,7 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) string strMessage = _("Warning: Please check that your computer's date and time are correct. If your clock is wrong Bitcoin will not work properly."); strMiscWarning = strMessage; printf("*** %s\n", strMessage.c_str()); - uiInterface.ThreadSafeMessageBox(strMessage+" ", string("Bitcoin"), MF_OK | MF_ICON_EXCLAMATION); + uiInterface.ThreadSafeMessageBox(strMessage+" ", string("Bitcoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION); } } }