wxWidgets/samples/ipc/server.h

82 lines
1.9 KiB
C
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////
// Name: server.h
// Purpose: DDE sample: server
// Author: Julian Smart
// Modified by:
// Created: 25/01/99
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Define a new application
class MyServer;
class MyApp : public wxApp
{
public:
virtual bool OnInit();
virtual int OnExit();
private:
MyServer *m_server;
};
DECLARE_APP(MyApp)
// Define a new frame
class MyFrame : public wxFrame
{
public:
MyFrame(wxFrame *frame, const wxString& title);
void OnListBoxClick(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
private:
wxPanel *panel;
DECLARE_EVENT_TABLE()
};
class IPCDialogBox;
class MyConnection : public wxConnection
{
public:
Applied patch [ 600051 ] DDE and TCP improvements and fixes By Michael Fielding As discussed on wx-dev. some fixes and improvements for Interprocess Communication (IPC), using DDE and TCP. 1. DDE buffers were using a global buffer 2. TCP buffers were allocated each time needed, and Request would have caused memory leaks had it been used. Fixed these both by using a self-resizing buffer in wxConnectionBase. Changed samples and docs to reflect the improved (but backward compatible) internal buffer management. wxConnectionBase could (in future) use wxMemoryBuffer. 3. IPC sample had trouble closing, causing crash, when closing server using window X button. Because it was (effectively) trying to delete a window in OnExit, when that window was already destroyed. Fixed by making IPCDialog and MyConnection remember if they'd destroyed each other. It's not elegant, but either the connection or the window could be deleted first. 4. Docs for wxDDE... and wxTCP... duplicated eachother, supposed to have same API. Some parts unclear. Patch removes dde and tcp-specific files (including from tipc.tex and classes.tex), and explains how ipc.h selects for you which one to use based on platform. Some other misc clarifications. 6. Client sample was suffering apparent memory leak because of not deleting connection object, and had a hack in there to do that. In fact this was due to the derived OnDisconnect not deleting itself, as it does in base class. Mentioned need to do it in docs, fixed sample so that it does. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16907 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2002-09-01 10:48:16 -04:00
MyConnection();
~MyConnection();
bool OnExecute(const wxString& topic, wxChar *data, int size, wxIPCFormat format);
wxChar *OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format);
bool OnPoke(const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format);
bool OnStartAdvise(const wxString& topic, const wxString& item);
IPCDialogBox *dialog;
};
class MyServer: public wxServer
{
public:
wxConnectionBase *OnAcceptConnection(const wxString& topic);
};
class IPCDialogBox: public wxDialog
{
public:
IPCDialogBox(wxWindow *parent,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
MyConnection *the_connection);
Applied patch [ 600051 ] DDE and TCP improvements and fixes By Michael Fielding As discussed on wx-dev. some fixes and improvements for Interprocess Communication (IPC), using DDE and TCP. 1. DDE buffers were using a global buffer 2. TCP buffers were allocated each time needed, and Request would have caused memory leaks had it been used. Fixed these both by using a self-resizing buffer in wxConnectionBase. Changed samples and docs to reflect the improved (but backward compatible) internal buffer management. wxConnectionBase could (in future) use wxMemoryBuffer. 3. IPC sample had trouble closing, causing crash, when closing server using window X button. Because it was (effectively) trying to delete a window in OnExit, when that window was already destroyed. Fixed by making IPCDialog and MyConnection remember if they'd destroyed each other. It's not elegant, but either the connection or the window could be deleted first. 4. Docs for wxDDE... and wxTCP... duplicated eachother, supposed to have same API. Some parts unclear. Patch removes dde and tcp-specific files (including from tipc.tex and classes.tex), and explains how ipc.h selects for you which one to use based on platform. Some other misc clarifications. 6. Client sample was suffering apparent memory leak because of not deleting connection object, and had a hack in there to do that. In fact this was due to the derived OnDisconnect not deleting itself, as it does in base class. Mentioned need to do it in docs, fixed sample so that it does. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16907 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2002-09-01 10:48:16 -04:00
~IPCDialogBox( );
void OnQuit(wxCommandEvent& event);
MyConnection *m_connection;
DECLARE_EVENT_TABLE()
};
#define SERVER_EXIT wxID_EXIT
#define SERVER_LISTBOX 500
#define SERVER_QUIT_BUTTON 501