1999-01-27 05:01:14 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
#define ID_START 10000
|
|
|
|
#define ID_DISCONNECT 10001
|
|
|
|
#define ID_ADVISE 10002
|
|
|
|
#define ID_LOG 10003
|
|
|
|
#define ID_SERVERNAME 10004
|
|
|
|
|
1999-01-27 05:01:14 -05:00
|
|
|
// Define a new application
|
2000-01-15 17:34:29 -05:00
|
|
|
class MyServer;
|
2005-09-11 14:31:34 -04:00
|
|
|
class MyConnection;
|
|
|
|
class MyFrame;
|
|
|
|
|
2000-01-15 17:34:29 -05:00
|
|
|
class MyApp : public wxApp
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2000-01-15 17:34:29 -05:00
|
|
|
public:
|
|
|
|
virtual bool OnInit();
|
|
|
|
virtual int OnExit();
|
2005-09-11 14:31:34 -04:00
|
|
|
MyFrame *GetFrame() { return m_frame; };
|
2000-01-15 17:34:29 -05:00
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
protected:
|
|
|
|
MyFrame *m_frame;
|
1999-01-27 05:01:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_APP(MyApp)
|
|
|
|
|
|
|
|
// Define a new frame
|
2000-01-15 17:34:29 -05:00
|
|
|
class MyFrame : public wxFrame
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2000-01-15 17:34:29 -05:00
|
|
|
public:
|
|
|
|
MyFrame(wxFrame *frame, const wxString& title);
|
1999-01-27 05:01:14 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
void OnExit(wxCommandEvent& event);
|
2005-09-11 14:31:34 -04:00
|
|
|
void OnClose(wxCloseEvent& event);
|
|
|
|
|
|
|
|
void Enable();
|
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxButton* GetStart() { return (wxButton*) FindWindow( ID_START ); }
|
|
|
|
wxChoice* GetServername() { return (wxChoice*) FindWindow( ID_SERVERNAME ); }
|
|
|
|
wxButton* GetDisconnect() { return (wxButton*) FindWindow( ID_DISCONNECT ); }
|
|
|
|
wxButton* GetAdvise() { return (wxButton*) FindWindow( ID_ADVISE ); }
|
|
|
|
wxTextCtrl* GetLog() { return (wxTextCtrl*) FindWindow( ID_LOG ); }
|
2000-01-15 17:34:29 -05:00
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
|
|
|
|
MyServer *m_server;
|
|
|
|
|
|
|
|
void OnStart( wxCommandEvent &event );
|
|
|
|
void OnServerName( wxCommandEvent &event );
|
|
|
|
void OnDisconnect( wxCommandEvent &event );
|
|
|
|
void OnAdvise( wxCommandEvent &event );
|
2000-01-15 17:34:29 -05:00
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
1999-01-27 05:01:14 -05:00
|
|
|
};
|
|
|
|
|
2000-01-15 17:34:29 -05:00
|
|
|
class MyConnection : public wxConnection
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2000-01-15 17:34:29 -05:00
|
|
|
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();
|
2000-01-15 17:34:29 -05:00
|
|
|
~MyConnection();
|
1999-01-27 05:01:14 -05:00
|
|
|
|
2007-10-20 18:54:26 -04:00
|
|
|
virtual bool OnExecute(const wxString& topic, const void *data, size_t size, wxIPCFormat format);
|
|
|
|
virtual const void *OnRequest(const wxString& topic, const wxString& item, size_t *size, wxIPCFormat format);
|
|
|
|
virtual bool OnPoke(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format);
|
2005-09-11 14:31:34 -04:00
|
|
|
virtual bool OnStartAdvise(const wxString& topic, const wxString& item);
|
|
|
|
virtual bool OnStopAdvise(const wxString& topic, const wxString& item);
|
2007-10-20 18:54:26 -04:00
|
|
|
virtual bool DoAdvise(const wxString& item, const void *data, size_t size, wxIPCFormat format);
|
2005-09-11 14:31:34 -04:00
|
|
|
virtual bool OnDisconnect();
|
|
|
|
protected:
|
2007-10-20 18:54:26 -04:00
|
|
|
void Log(const wxString& command, const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format);
|
2005-09-11 14:31:34 -04:00
|
|
|
public:
|
|
|
|
wxString m_sAdvise;
|
|
|
|
protected:
|
|
|
|
wxString m_sRequestDate;
|
2007-10-20 18:54:26 -04:00
|
|
|
char m_achRequestBytes[3];
|
1999-01-27 05:01:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class MyServer: public wxServer
|
|
|
|
{
|
|
|
|
public:
|
2005-09-11 14:31:34 -04:00
|
|
|
MyServer();
|
|
|
|
~MyServer();
|
|
|
|
void Disconnect();
|
|
|
|
bool IsConnected() { return m_connection != NULL; };
|
|
|
|
MyConnection *GetConnection() { return m_connection; };
|
|
|
|
void Advise();
|
|
|
|
bool CanAdvise() { return m_connection != NULL && !m_connection->m_sAdvise.IsEmpty(); };
|
1999-01-27 05:01:14 -05:00
|
|
|
wxConnectionBase *OnAcceptConnection(const wxString& topic);
|
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
protected:
|
|
|
|
MyConnection *m_connection;
|
1999-01-27 05:01:14 -05:00
|
|
|
};
|
|
|
|
|