server.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: server.h
  3. // Purpose: DDE sample: server
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 25/01/99
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #include "connection.h"
  11. enum
  12. {
  13. ID_START = 10000,
  14. ID_DISCONNECT,
  15. ID_ADVISE,
  16. ID_SERVERNAME,
  17. };
  18. // Define a new application
  19. class MyServer;
  20. class MyFrame;
  21. class MyApp : public wxApp
  22. {
  23. public:
  24. virtual bool OnInit();
  25. MyFrame *GetFrame() { return m_frame; }
  26. protected:
  27. MyFrame *m_frame;
  28. };
  29. DECLARE_APP(MyApp)
  30. // Define a new frame
  31. class MyFrame : public wxFrame
  32. {
  33. public:
  34. MyFrame(wxFrame *frame, const wxString& title);
  35. void OnClose(wxCloseEvent& event);
  36. void UpdateUI();
  37. void Disconnect();
  38. protected:
  39. wxButton* GetStart() { return (wxButton*) FindWindow( ID_START ); }
  40. wxChoice* GetServername() { return (wxChoice*) FindWindow( ID_SERVERNAME ); }
  41. wxButton* GetDisconnect() { return (wxButton*) FindWindow( ID_DISCONNECT ); }
  42. wxButton* GetAdvise() { return (wxButton*) FindWindow( ID_ADVISE ); }
  43. MyServer *m_server;
  44. void OnStart( wxCommandEvent &event );
  45. void OnServerName( wxCommandEvent &event );
  46. void OnDisconnect( wxCommandEvent &event );
  47. void OnAdvise( wxCommandEvent &event );
  48. wxDECLARE_EVENT_TABLE();
  49. };
  50. class MyConnection : public MyConnectionBase
  51. {
  52. public:
  53. virtual bool OnExecute(const wxString& topic, const void *data, size_t size, wxIPCFormat format);
  54. virtual const void *OnRequest(const wxString& topic, const wxString& item, size_t *size, wxIPCFormat format);
  55. virtual bool OnPoke(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format);
  56. virtual bool OnStartAdvise(const wxString& topic, const wxString& item);
  57. virtual bool OnStopAdvise(const wxString& topic, const wxString& item);
  58. virtual bool DoAdvise(const wxString& item, const void *data, size_t size, wxIPCFormat format);
  59. virtual bool OnDisconnect();
  60. // topic for which we advise the client or empty if none
  61. wxString m_advise;
  62. protected:
  63. // the data returned by last OnRequest(): we keep it in this buffer to
  64. // ensure that the pointer we return from OnRequest() stays valid
  65. wxCharBuffer m_requestData;
  66. };
  67. class MyServer : public wxServer
  68. {
  69. public:
  70. MyServer();
  71. virtual ~MyServer();
  72. void Disconnect();
  73. bool IsConnected() { return m_connection != NULL; }
  74. MyConnection *GetConnection() { return m_connection; }
  75. void Advise();
  76. bool CanAdvise() { return m_connection && !m_connection->m_advise.empty(); }
  77. virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
  78. protected:
  79. MyConnection *m_connection;
  80. };