changeset 2642:8bc3131c2449 draft

Make testcases build, prevent windows symbol collision
author Wladimir J. van der Laan <laanwj@gmail.com>
date Sat, 19 May 2012 09:35:26 +0200
parents 8c808b8dcf02
children da82af3de0ff
files src/bitcoinrpc.cpp src/init.cpp src/init.h src/main.cpp src/makefile.linux-mingw src/makefile.mingw src/makefile.osx src/makefile.unix src/noui.cpp src/qt/bitcoin.cpp src/test/test_bitcoin.cpp src/ui_interface.h src/util.cpp
diffstat 13 files changed, 103 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -2630,7 +2630,7 @@
                 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 @@
     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;
     }
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -91,41 +91,6 @@
 // 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 @@
         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;
 }
 
--- 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();
 
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1858,7 +1858,7 @@
         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;
     }
--- a/src/makefile.linux-mingw
+++ b/src/makefile.linux-mingw
@@ -64,7 +64,8 @@
     obj/sync.o \
     obj/util.o \
     obj/wallet.o \
-    obj/walletdb.o
+    obj/walletdb.o \
+    obj/noui.o
 
 all: bitcoind.exe
 
--- a/src/makefile.mingw
+++ b/src/makefile.mingw
@@ -61,7 +61,8 @@
     obj/sync.o \
     obj/util.o \
     obj/wallet.o \
-    obj/walletdb.o
+    obj/walletdb.o \
+    obj/noui.o
 
 
 all: bitcoind.exe
--- a/src/makefile.osx
+++ b/src/makefile.osx
@@ -88,7 +88,8 @@
     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)
--- a/src/makefile.unix
+++ b/src/makefile.unix
@@ -108,7 +108,8 @@
     obj/sync.o \
     obj/util.o \
     obj/wallet.o \
-    obj/walletdb.o
+    obj/walletdb.o \
+    obj/noui.o
 
 
 all: bitcoind
new file mode 100644
--- /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 <string>
+
+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);
+}
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -42,7 +42,7 @@
     // 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,
--- 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);
     }
--- a/src/ui_interface.h
+++ b/src/ui_interface.h
@@ -13,39 +13,6 @@
 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 @@
 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<void (const std::string& message, const std::string& caption, int style)> ThreadSafeMessageBox;
 
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -1000,7 +1000,7 @@
                     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);
                 }
             }
         }