1///////////////////////////////////////////////////////////////////////////// 2// Name: server.h 3// Purpose: DDE sample: server 4// Author: Julian Smart 5// Modified by: 6// Created: 25/01/99 7// RCS-ID: $Id: server.h 35470 2005-09-11 18:31:34Z JS $ 8// Copyright: (c) Julian Smart 9// Licence: wxWindows licence 10///////////////////////////////////////////////////////////////////////////// 11 12#define ID_START 10000 13#define ID_DISCONNECT 10001 14#define ID_ADVISE 10002 15#define ID_LOG 10003 16#define ID_SERVERNAME 10004 17 18// Define a new application 19class MyServer; 20class MyConnection; 21class MyFrame; 22 23class MyApp : public wxApp 24{ 25public: 26 virtual bool OnInit(); 27 virtual int OnExit(); 28 MyFrame *GetFrame() { return m_frame; }; 29 30protected: 31 MyFrame *m_frame; 32}; 33 34DECLARE_APP(MyApp) 35 36// Define a new frame 37class MyFrame : public wxFrame 38{ 39public: 40 MyFrame(wxFrame *frame, const wxString& title); 41 42 void OnExit(wxCommandEvent& event); 43 void OnClose(wxCloseEvent& event); 44 45 void Enable(); 46 void Disconnect(); 47 48protected: 49 wxButton* GetStart() { return (wxButton*) FindWindow( ID_START ); } 50 wxChoice* GetServername() { return (wxChoice*) FindWindow( ID_SERVERNAME ); } 51 wxButton* GetDisconnect() { return (wxButton*) FindWindow( ID_DISCONNECT ); } 52 wxButton* GetAdvise() { return (wxButton*) FindWindow( ID_ADVISE ); } 53 wxTextCtrl* GetLog() { return (wxTextCtrl*) FindWindow( ID_LOG ); } 54 55 56 MyServer *m_server; 57 58 void OnStart( wxCommandEvent &event ); 59 void OnServerName( wxCommandEvent &event ); 60 void OnDisconnect( wxCommandEvent &event ); 61 void OnAdvise( wxCommandEvent &event ); 62 63 DECLARE_EVENT_TABLE() 64}; 65 66class MyConnection : public wxConnection 67{ 68public: 69 MyConnection(); 70 ~MyConnection(); 71 72 virtual bool OnExecute(const wxString& topic, wxChar *data, int size, wxIPCFormat format); 73 virtual wxChar *OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format); 74 virtual bool OnPoke(const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format); 75 virtual bool OnStartAdvise(const wxString& topic, const wxString& item); 76 virtual bool OnStopAdvise(const wxString& topic, const wxString& item); 77 virtual bool Advise(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT); 78 virtual bool OnDisconnect(); 79protected: 80 void Log(const wxString& command, const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format); 81public: 82 wxString m_sAdvise; 83protected: 84 wxString m_sRequestDate; 85 char m_achRequestBytes[3]; 86}; 87 88class MyServer: public wxServer 89{ 90public: 91 MyServer(); 92 ~MyServer(); 93 void Disconnect(); 94 bool IsConnected() { return m_connection != NULL; }; 95 MyConnection *GetConnection() { return m_connection; }; 96 void Advise(); 97 bool CanAdvise() { return m_connection != NULL && !m_connection->m_sAdvise.IsEmpty(); }; 98 wxConnectionBase *OnAcceptConnection(const wxString& topic); 99 100protected: 101 MyConnection *m_connection; 102}; 103 104