From d5172a588cd037057afd632596dffe9217495375 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 15 Apr 2002 18:24:46 +0000 Subject: [PATCH] added wx/ipc.h and used/documented it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15144 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- distrib/msw/tmake/filelist.txt | 1 + docs/latex/wx/tipc.tex | 10 +++++++++ include/wx/ipc.h | 41 ++++++++++++++++++++++++++++++++++ samples/ipc/client.cpp | 7 +++--- samples/ipc/ddesetup.h | 36 ++++++++--------------------- samples/ipc/server.cpp | 11 ++++----- 6 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 include/wx/ipc.h diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index a99f89b92f..9f75a5646e 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -864,6 +864,7 @@ imagjpeg.h WXH imaglist.h WXH intl.h WXH Base ioswrap.h WXH Base +ipc.h WXH Base ipcbase.h WXH Base isql.h WXH Base isqlext.h WXH Base diff --git a/docs/latex/wx/tipc.tex b/docs/latex/wx/tipc.tex index d2c74699d7..6ad9d56b77 100644 --- a/docs/latex/wx/tipc.tex +++ b/docs/latex/wx/tipc.tex @@ -20,6 +20,16 @@ for programming popular Internet protocols. Further information on these classes will be available in due course. +Notice that by including {\tt } you may define convnient synonyms for +the IPC classes: {\tt wxServer} for either {\tt wxDDEServer} or +{\tt wxTCPServer} depending on whether DDE-based or socket-based implementation +is used and the same thing for {\tt wxClient} and {\tt wxConnection}. By +default, DDE implementation is used under Windows. If you want to use IPC +between the different workstations you should define {\tt wxUSE\_DDE\_FOR\_IPC} +as $0$ before including this header -- this will force using TCP/IP +implementation even under Windows. + + wxWindows has a high-level protocol based on Windows DDE. There are two implementations of this DDE-like protocol: one using real DDE running on Windows only, and another using TCP/IP (sockets) that runs diff --git a/include/wx/ipc.h b/include/wx/ipc.h new file mode 100644 index 0000000000..c096924fec --- /dev/null +++ b/include/wx/ipc.h @@ -0,0 +1,41 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/ipc.h +// Purpose: wrapper around different wxIPC classes implementations +// Author: Vadim Zeitlin +// Modified by: +// Created: 15.04.02 +// RCS-ID: $Id$ +// Copyright: (c) 2002 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// Set wxUSE_DDE_FOR_IPC to 1 to use DDE for IPC under Windows. If it is set to +// 0, or if the platform is not Windows, use TCP/IP for IPC implementation + +#if !defined(wxUSE_DDE_FOR_IPC) + #ifdef __WXMSW__ + #define wxUSE_DDE_FOR_IPC 1 + #else + #define wxUSE_DDE_FOR_IPC 0 + #endif +#endif // !defined(wxUSE_DDE_FOR_IPC) + +#if !defined(__WINDOWS__) + #undef wxUSE_DDE_FOR_IPC + #define wxUSE_DDE_FOR_IPC 0 +#endif + +#if wxUSE_DDE_FOR_IPC + #define wxConnection wxDDEConnection + #define wxServer wxDDEServer + #define wxClient wxDDEClient + + #include "wx/dde.h" +#else // !wxUSE_DDE_FOR_IPC + #define wxConnection wxTCPConnection + #define wxServer wxTCPServer + #define wxClient wxTCPClient + + #include "wx/sckipc.h" +#endif // wxUSE_DDE_FOR_IPC/!wxUSE_DDE_FOR_IPC + diff --git a/samples/ipc/client.cpp b/samples/ipc/client.cpp index e5e9b105f4..f4d1711fe5 100644 --- a/samples/ipc/client.cpp +++ b/samples/ipc/client.cpp @@ -75,7 +75,7 @@ MyClient *my_client; bool MyApp::OnInit() { // service name (DDE classes) or port number (TCP/IP based classes) - wxString service = "4242"; + wxString service = IPC_SERVICE; // ignored under DDE, host name in TCP/IP based classes wxString hostName = "localhost"; @@ -91,7 +91,8 @@ bool MyApp::OnInit() // suppress the log messages from MakeConnection() { wxLogNull nolog; - the_connection = (MyConnection *)my_client->MakeConnection(hostName, service, "IPC TEST"); + the_connection = (MyConnection *) + my_client->MakeConnection(hostName, service, IPC_TOPIC); while ( !the_connection ) { @@ -107,7 +108,7 @@ bool MyApp::OnInit() } } - if (!the_connection->StartAdvise("Item")) + if (!the_connection->StartAdvise(IPC_ADVISE_NAME)) wxMessageBox("StartAdvise failed", "Client Demo Error"); // Create the main frame window diff --git a/samples/ipc/ddesetup.h b/samples/ipc/ddesetup.h index 177d034b77..193f0d3b93 100644 --- a/samples/ipc/ddesetup.h +++ b/samples/ipc/ddesetup.h @@ -9,34 +9,16 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -/* - * Adjust this before compiling, to switch between real DDE and TCP/IP - * implementations. - */ +// You may set this to 0 to prevent DDE from being used even under Windows +//#define wxUSE_DDE_FOR_IPC 0 -// If 1, use real DDE. If 0, use TCP/IP +#include -#ifdef __WXMSW__ -#define wxUSE_DDE_FOR_SAMPLE 0 -#else -#define wxUSE_DDE_FOR_SAMPLE 0 -#endif +// the default service name +#define IPC_SERVICE "4242" -#if wxUSE_DDE_FOR_SAMPLE - -#define wxConnection wxDDEConnection -#define wxServer wxDDEServer -#define wxClient wxDDEClient - -#include - -#else - -#define wxConnection wxTCPConnection -#define wxServer wxTCPServer -#define wxClient wxTCPClient - -#include - -#endif +// the IPC topic +#define IPC_TOPIC "IPC TEST" +// the name of the item we're being advised about +#define IPC_ADVISE_NAME "Item" diff --git a/samples/ipc/server.cpp b/samples/ipc/server.cpp index f278b704e8..91a173313d 100644 --- a/samples/ipc/server.cpp +++ b/samples/ipc/server.cpp @@ -74,7 +74,7 @@ bool MyApp::OnInit() (new MyFrame(NULL, "Server"))->Show(TRUE); // service name (DDE classes) or port number (TCP/IP based classes) - wxString service = "4242"; + wxString service = IPC_SERVICE; if (argc > 1) service = argv[1]; @@ -136,7 +136,7 @@ void MyFrame::OnListBoxClick(wxCommandEvent& WXUNUSED(event)) wxString value = listBox->GetStringSelection(); if (the_connection) { - the_connection->Advise("Item", (wxChar *)value.c_str()); + the_connection->Advise(IPC_ADVISE_NAME, (wxChar *)value.c_str()); } } } @@ -173,10 +173,11 @@ void IPCDialogBox::OnQuit(wxCommandEvent& event) wxConnectionBase *MyServer::OnAcceptConnection(const wxString& topic) { - if (strcmp(topic, "STDIO") != 0 && strcmp(topic, "IPC TEST") == 0) + if ( topic == IPC_TOPIC ) return new MyConnection(ipc_buffer, WXSIZEOF(ipc_buffer)); - else - return NULL; + + // unknown topic + return NULL; } // ---------------------------------------------------------------------------- -- 2.45.2