Added some basic IPC functionality using wxServer, wxClient and wxConnection.
authorsirius-m <sirius-m@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Thu, 4 Feb 2010 15:31:46 +0000 (15:31 +0000)
committersirius-m <sirius-m@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Thu, 4 Feb 2010 15:31:46 +0000 (15:31 +0000)
Added the -blockamount command line option for an example of usage.

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@56 1a98c847-1fd6-4fd8-948a-caf3550aa51b

headers.h
ipc.cpp [new file with mode: 0644]
ipc.h [new file with mode: 0644]
makefile
makefile.unix.wx2.8
makefile.unix.wx2.9
ui.cpp

index 45be4b6..fb5e3ec 100644 (file)
--- a/headers.h
+++ b/headers.h
@@ -24,6 +24,8 @@
 #include <wx/taskbar.h>\r
 #include <wx/stdpaths.h>\r
 #include <wx/utils.h>\r
+#include <wx/ipc.h>\r
+#include <wx/ipcbase.h>\r
 #include <openssl/ecdsa.h>\r
 #include <openssl/evp.h>\r
 #include <openssl/rand.h>\r
@@ -102,6 +104,7 @@ using namespace boost;
 #include "market.h"\r
 #include "uibase.h"\r
 #include "ui.h"\r
+#include "ipc.h"\r
 \r
 #include "xpm/addressbook16.xpm"\r
 #include "xpm/addressbook20.xpm"\r
diff --git a/ipc.cpp b/ipc.cpp
new file mode 100644 (file)
index 0000000..86e5767
--- /dev/null
+++ b/ipc.cpp
@@ -0,0 +1,33 @@
+/*
+ * Inter-process calling functionality
+ */
+
+#include "headers.h"
+
+wxConnectionBase * CServer::OnAcceptConnection (const wxString &topic) {
+    return new CServerConnection;
+}
+
+wxConnectionBase * CClient::OnMakeConnection () {
+    return new CClientConnection;
+}
+
+// For request based handling
+const void * CServerConnection::OnRequest (const wxString &topic, const wxString &item, size_t *size, wxIPCFormat format) {
+    const char * output;
+
+    if (item == "blockamount") {
+        stringstream stream;
+        stream << nBestHeight + 1;
+        output = stream.str().c_str();
+    }
+    else
+        output = "Unknown identifier";
+    
+    return output;
+}
+
+// For event based handling
+bool CClientConnection::OnAdvise (const wxString &topic, const wxString &item, const void *data, size_t size, wxIPCFormat format) {
+    return false;
+}
\ No newline at end of file
diff --git a/ipc.h b/ipc.h
new file mode 100644 (file)
index 0000000..777d31b
--- /dev/null
+++ b/ipc.h
@@ -0,0 +1,28 @@
+#ifndef _IPC_H
+#define        _IPC_H
+
+class CServer : public wxServer {
+public:
+    wxConnectionBase * OnAcceptConnection (const wxString &topic);
+};
+
+class CClient : public wxClient {
+public:
+    wxConnectionBase * OnMakeConnection ();
+};
+
+class CServerConnection : public wxConnection {
+public:
+    const void * OnRequest (const wxString &topic, const wxString &item, size_t *size, wxIPCFormat format);
+};
+
+class CClientConnection : public wxConnection {
+public:
+    CClientConnection() : wxConnection() {}
+    ~CClientConnection() {}
+    
+    bool OnAdvise (const wxString &topic, const wxString &item, const void *data, size_t size, wxIPCFormat format);
+};
+
+#endif /* _IPC_H */
+
index 0dd6221..efdfc7a 100644 (file)
--- a/makefile
+++ b/makefile
@@ -67,10 +67,12 @@ obj/irc.o: irc.cpp                  $(HEADERS)
 obj/ui_res.o: ui.rc  rc/bitcoin.ico rc/check.ico rc/send16.bmp rc/send16mask.bmp rc/send16masknoshadow.bmp rc/send20.bmp rc/send20mask.bmp rc/addressbook16.bmp rc/addressbook16mask.bmp rc/addressbook20.bmp rc/addressbook20mask.bmp\r
        windres $(WXDEFS) $(INCLUDEPATHS) -o $@ -i $<\r
 \r
+obj/ipc.o: ipc.cpp                  $(HEADERS)\r
+       g++ -c $(CFLAGS) -o $@ $<\r
 \r
 \r
 OBJS=obj/util.o obj/script.o obj/db.o obj/net.o obj/main.o obj/market.o \\r
-        obj/ui.o obj/uibase.o obj/sha.o obj/irc.o obj/ui_res.o\r
+        obj/ui.o obj/uibase.o obj/sha.o obj/irc.o obj/ui_res.o obj/ipc.o\r
 \r
 bitcoin.exe: headers.h.gch $(OBJS)\r
        -kill /f bitcoin.exe\r
index b9826d6..899ce29 100644 (file)
@@ -75,11 +75,12 @@ obj/sha.o: sha.cpp                  sha.h
 obj/irc.o: irc.cpp                  $(HEADERS)\r
        g++ -c $(CFLAGS) -o $@ $<\r
 \r
-\r
+obj/ipc.o: ipc.cpp                  $(HEADERS)\r
+       g++ -c $(CFLAGS) -o $@ $<\r
 \r
 \r
 OBJS=obj/util.o obj/script.o obj/db.o obj/net.o obj/main.o obj/market.o \\r
-        obj/ui.o obj/uibase.o obj/sha.o obj/irc.o\r
+        obj/ui.o obj/uibase.o obj/sha.o obj/irc.o obj/ipc.o\r
 \r
 bitcoin: headers.h.gch $(OBJS)\r
        g++ $(CFLAGS) -o $@ $(LIBPATHS) $(OBJS) $(LIBS)\r
index 81dcbd7..d2c4eb5 100644 (file)
@@ -31,7 +31,7 @@ LIBS= \
    -l wx_gtk2u$(D)-2.9 \\r
  -Wl,-Bdynamic \\r
    -l crypto \\r
-   -l gtk-x11-2.0 -l gthread-2.0 -l SM\r
+   -l gtk-x11-2.0 -l gthread-2.0 -l SM \\r
 \r
 WXDEFS=-D__WXGTK__ -DNOPCH\r
 CFLAGS=-O0 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)\r
@@ -75,11 +75,12 @@ obj/sha.o: sha.cpp                  sha.h
 obj/irc.o: irc.cpp                  $(HEADERS)\r
        g++ -c $(CFLAGS) -o $@ $<\r
 \r
-\r
+obj/ipc.o: ipc.cpp                  $(HEADERS)\r
+       g++ -c $(CFLAGS) -o $@ $<\r
 \r
 \r
 OBJS=obj/util.o obj/script.o obj/db.o obj/net.o obj/main.o obj/market.o \\r
-        obj/ui.o obj/uibase.o obj/sha.o obj/irc.o\r
+        obj/ui.o obj/uibase.o obj/sha.o obj/irc.o obj/ipc.o\r
 \r
 bitcoin: headers.h.gch $(OBJS)\r
        g++ $(CFLAGS) -o $@ $(LIBPATHS) $(OBJS) $(LIBS)\r
diff --git a/ui.cpp b/ui.cpp
index 5d93ad2..1f22170 100644 (file)
--- a/ui.cpp
+++ b/ui.cpp
@@ -21,6 +21,7 @@ DEFINE_EVENT_TYPE(wxEVT_REPLY3)
 \r
 CMainFrame* pframeMain = NULL;\r
 CMyTaskBarIcon* ptaskbaricon = NULL;\r
+CServer* pserver = NULL;\r
 map<string, string> mapAddressBook;\r
 bool fRandSendTest = false;\r
 void RandSend();\r
@@ -384,6 +385,8 @@ CMainFrame::~CMainFrame()
     pframeMain = NULL;\r
     delete ptaskbaricon;\r
     ptaskbaricon = NULL;\r
+    delete pserver;\r
+    pserver = NULL;\r
 }\r
 \r
 void ExitTimeout(void* parg)\r
@@ -1687,8 +1690,8 @@ CAboutDialog::CAboutDialog(wxWindow* parent) : CAboutDialogBase(parent)
 #if !wxUSE_UNICODE\r
     // Workaround until upgrade to wxWidgets supporting UTF-8\r
     wxString str = m_staticTextMain->GetLabel();\r
-    if (str.Find('Â') != wxNOT_FOUND)\r
-        str.Remove(str.Find('Â'), 1);\r
+    if (str.Find('�') != wxNOT_FOUND)\r
+        str.Remove(str.Find('�'), 1);\r
     m_staticTextMain->SetLabel(str);\r
 #endif\r
 #ifndef __WXMSW__\r
@@ -3548,6 +3551,26 @@ bool CMyApp::OnInit2()
         return false;\r
     }\r
 \r
+    if (mapArgs.count("-blockamount")) {\r
+        CClient client;\r
+        wxString hostname = "localhost";\r
+        wxString server = GetDataDir() + "service";\r
+        CClientConnection * pconnection = (CClientConnection *)client.MakeConnection(hostname, server, "ipc test");\r
+        string output = "";\r
+        if (pconnection) {\r
+            char * pbuffer = (char *)pconnection->Request("blockamount");\r
+            while (*pbuffer != '\n') {\r
+                output += *pbuffer;\r
+                pbuffer++;\r
+            }\r
+        }\r
+        else {\r
+            output = "Cannot access Bitcoin. Are you sure the program is running?\n";\r
+        }\r
+        fprintf(stderr, "%s", output.c_str());\r
+        return false;\r
+    }\r
+\r
     if (mapArgs.count("-datadir"))\r
         strlcpy(pszSetDataDir, mapArgs["-datadir"].c_str(), sizeof(pszSetDataDir));\r
 \r
@@ -3755,6 +3778,8 @@ bool CMyApp::OnInit2()
     if (fFirstRun)\r
         SetStartOnSystemStartup(true);\r
 \r
+    pserver = new CServer;\r
+    pserver->Create(GetDataDir() + "service");\r
 \r
     //\r
     // Tests\r