X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/50c549b98d8e61e19f59c61989af293bb58319f8..43cb7161a01924c1fc29e01f6df740215c33b4ff:/samples/ipc/server.h?ds=inline diff --git a/samples/ipc/server.h b/samples/ipc/server.h index c0450f99c4..a81a4421cc 100644 --- a/samples/ipc/server.h +++ b/samples/ipc/server.h @@ -9,26 +9,28 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#define ID_START 10000 -#define ID_DISCONNECT 10001 -#define ID_ADVISE 10002 -#define ID_LOG 10003 -#define ID_SERVERNAME 10004 +#include "connection.h" + +enum +{ + ID_START = 10000, + ID_DISCONNECT, + ID_ADVISE, + ID_SERVERNAME, +}; // Define a new application class MyServer; -class MyConnection; class MyFrame; class MyApp : public wxApp { public: virtual bool OnInit(); - virtual int OnExit(); - MyFrame *GetFrame() { return m_frame; }; + MyFrame *GetFrame() { return m_frame; } protected: - MyFrame *m_frame; + MyFrame *m_frame; }; DECLARE_APP(MyApp) @@ -39,10 +41,9 @@ class MyFrame : public wxFrame public: MyFrame(wxFrame *frame, const wxString& title); - void OnExit(wxCommandEvent& event); void OnClose(wxCloseEvent& event); - void Enable(); + void UpdateUI(); void Disconnect(); protected: @@ -50,10 +51,9 @@ protected: 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 ); } - MyServer *m_server; + MyServer *m_server; void OnStart( wxCommandEvent &event ); void OnServerName( wxCommandEvent &event ); @@ -63,12 +63,9 @@ protected: DECLARE_EVENT_TABLE() }; -class MyConnection : public wxConnection +class MyConnection : public MyConnectionBase { public: - MyConnection(); - ~MyConnection(); - 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); @@ -76,28 +73,32 @@ public: virtual bool OnStopAdvise(const wxString& topic, const wxString& item); virtual bool DoAdvise(const wxString& item, const void *data, size_t size, wxIPCFormat format); virtual bool OnDisconnect(); + + // topic for which we advise the client or empty if none + wxString m_advise; + protected: - void Log(const wxString& command, const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format); -public: - wxString m_sAdvise; -protected: - wxString m_sRequestDate; - char m_achRequestBytes[3]; + // the data returned by last OnRequest(): we keep it in this buffer to + // ensure that the pointer we return from OnRequest() stays valid + wxCharBuffer m_requestData; }; -class MyServer: public wxServer +class MyServer : public wxServer { public: MyServer(); - ~MyServer(); + virtual ~MyServer(); + void Disconnect(); - bool IsConnected() { return m_connection != NULL; }; - MyConnection *GetConnection() { return m_connection; }; + bool IsConnected() { return m_connection != NULL; } + MyConnection *GetConnection() { return m_connection; } + void Advise(); - bool CanAdvise() { return m_connection != NULL && !m_connection->m_sAdvise.IsEmpty(); }; - wxConnectionBase *OnAcceptConnection(const wxString& topic); + bool CanAdvise() { return m_connection && !m_connection->m_advise.empty(); } + + virtual wxConnectionBase *OnAcceptConnection(const wxString& topic); protected: - MyConnection *m_connection; + MyConnection *m_connection; };