1999-01-27 05:01:14 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: server.h
|
|
|
|
// Purpose: DDE sample: server
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 25/01/99
|
|
|
|
// Copyright: (c) Julian Smart
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-02-10 18:43:39 -05:00
|
|
|
#include "connection.h"
|
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ID_START = 10000,
|
|
|
|
ID_DISCONNECT,
|
|
|
|
ID_ADVISE,
|
|
|
|
ID_SERVERNAME,
|
|
|
|
};
|
2005-09-11 14:31:34 -04:00
|
|
|
|
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 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:
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool OnInit() wxOVERRIDE;
|
2008-07-13 21:20:33 -04:00
|
|
|
MyFrame *GetFrame() { return m_frame; }
|
2000-01-15 17:34:29 -05:00
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
protected:
|
2008-07-13 21:20:33 -04:00
|
|
|
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
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
void OnClose(wxCloseEvent& event);
|
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
void UpdateUI();
|
2005-09-11 14:31:34 -04:00
|
|
|
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 ); }
|
2000-01-15 17:34:29 -05:00
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
MyServer *m_server;
|
2005-09-11 14:31:34 -04:00
|
|
|
|
|
|
|
void OnStart( wxCommandEvent &event );
|
|
|
|
void OnServerName( wxCommandEvent &event );
|
|
|
|
void OnDisconnect( wxCommandEvent &event );
|
|
|
|
void OnAdvise( wxCommandEvent &event );
|
2000-01-15 17:34:29 -05:00
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
1999-01-27 05:01:14 -05:00
|
|
|
};
|
|
|
|
|
2008-02-10 18:43:39 -05:00
|
|
|
class MyConnection : public MyConnectionBase
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2000-01-15 17:34:29 -05:00
|
|
|
public:
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool OnExecute(const wxString& topic, const void *data, size_t size, wxIPCFormat format) wxOVERRIDE;
|
|
|
|
virtual const void *OnRequest(const wxString& topic, const wxString& item, size_t *size, wxIPCFormat format) wxOVERRIDE;
|
|
|
|
virtual bool OnPoke(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format) wxOVERRIDE;
|
|
|
|
virtual bool OnStartAdvise(const wxString& topic, const wxString& item) wxOVERRIDE;
|
|
|
|
virtual bool OnStopAdvise(const wxString& topic, const wxString& item) wxOVERRIDE;
|
|
|
|
virtual bool DoAdvise(const wxString& item, const void *data, size_t size, wxIPCFormat format) wxOVERRIDE;
|
|
|
|
virtual bool OnDisconnect() wxOVERRIDE;
|
2008-02-10 18:43:39 -05:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
// topic for which we advise the client or empty if none
|
|
|
|
wxString m_advise;
|
2008-02-10 18:43:39 -05:00
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
protected:
|
2008-11-17 06:00:32 -05:00
|
|
|
// the data returned by last OnRequest(): we keep it in this buffer to
|
2008-07-13 21:20:33 -04:00
|
|
|
// ensure that the pointer we return from OnRequest() stays valid
|
2008-11-17 06:00:32 -05:00
|
|
|
wxCharBuffer m_requestData;
|
1999-01-27 05:01:14 -05:00
|
|
|
};
|
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
class MyServer : public wxServer
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
|
|
|
public:
|
2005-09-11 14:31:34 -04:00
|
|
|
MyServer();
|
2008-07-13 21:20:33 -04:00
|
|
|
virtual ~MyServer();
|
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
void Disconnect();
|
2008-07-13 21:20:33 -04:00
|
|
|
bool IsConnected() { return m_connection != NULL; }
|
|
|
|
MyConnection *GetConnection() { return m_connection; }
|
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
void Advise();
|
2008-07-13 21:20:33 -04:00
|
|
|
bool CanAdvise() { return m_connection && !m_connection->m_advise.empty(); }
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic) wxOVERRIDE;
|
1999-01-27 05:01:14 -05:00
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
protected:
|
2008-07-13 21:20:33 -04:00
|
|
|
MyConnection *m_connection;
|
1999-01-27 05:01:14 -05:00
|
|
|
};
|
|
|
|
|