client.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: client.h
  3. // Purpose: DDE sample: client
  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. #define ID_START 10000
  12. #define ID_DISCONNECT 10001
  13. #define ID_STARTADVISE 10002
  14. #define ID_LOG 10003
  15. #define ID_SERVERNAME 10004
  16. #define ID_STOPADVISE 10005
  17. #define ID_POKE 10006
  18. #define ID_REQUEST 10007
  19. #define ID_EXECUTE 10008
  20. #define ID_TOPIC 10009
  21. #define ID_HOSTNAME 10010
  22. // Define a new application
  23. class MyClient;
  24. class MyFrame;
  25. class MyApp: public wxApp
  26. {
  27. public:
  28. virtual bool OnInit();
  29. virtual int OnExit();
  30. MyFrame *GetFrame() { return m_frame; };
  31. protected:
  32. MyFrame *m_frame;
  33. };
  34. // Define a new frame
  35. class MyFrame: public wxFrame
  36. {
  37. public:
  38. MyFrame(wxFrame *frame, const wxString& title);
  39. void OnExit(wxCommandEvent& event);
  40. void OnClose(wxCloseEvent& event);
  41. void EnableControls();
  42. void Disconnect();
  43. protected:
  44. wxButton* GetStart() { return (wxButton*) FindWindow( ID_START ); }
  45. wxChoice* GetServername() { return (wxChoice*) FindWindow( ID_SERVERNAME ); }
  46. wxChoice* GetHostname() { return (wxChoice*) FindWindow( ID_HOSTNAME ); }
  47. wxChoice* GetTopic() { return (wxChoice*) FindWindow( ID_TOPIC ); }
  48. wxButton* GetDisconnect() { return (wxButton*) FindWindow( ID_DISCONNECT ); }
  49. wxButton* GetStartAdvise() { return (wxButton*) FindWindow( ID_STARTADVISE ); }
  50. wxButton* GetStopAdvise() { return (wxButton*) FindWindow( ID_STOPADVISE ); }
  51. wxButton* GetRequest() { return (wxButton*) FindWindow( ID_REQUEST ); }
  52. wxButton* GetPoke() { return (wxButton*) FindWindow( ID_POKE ); }
  53. wxButton* GetExecute() { return (wxButton*) FindWindow( ID_EXECUTE ); }
  54. wxTextCtrl* GetLog() { return (wxTextCtrl*) FindWindow( ID_LOG ); }
  55. MyClient *m_client;
  56. void OnStart( wxCommandEvent &event );
  57. void OnServername( wxCommandEvent &event );
  58. void OnHostname( wxCommandEvent &event );
  59. void OnTopic( wxCommandEvent &event );
  60. void OnDisconnect( wxCommandEvent &event );
  61. void OnStartAdvise( wxCommandEvent &event );
  62. void OnStopAdvise( wxCommandEvent &event );
  63. void OnExecute(wxCommandEvent& event);
  64. void OnPoke(wxCommandEvent& event);
  65. void OnRequest(wxCommandEvent& event);
  66. protected:
  67. wxDECLARE_EVENT_TABLE();
  68. };
  69. class MyConnection : public MyConnectionBase
  70. {
  71. public:
  72. virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format);
  73. virtual const void *Request(const wxString& item, size_t *size = NULL, wxIPCFormat format = wxIPC_TEXT);
  74. virtual bool DoPoke(const wxString& item, const void* data, size_t size, wxIPCFormat format);
  75. virtual bool OnAdvise(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format);
  76. virtual bool OnDisconnect();
  77. };
  78. class MyClient: public wxClient
  79. {
  80. public:
  81. MyClient();
  82. ~MyClient();
  83. bool Connect(const wxString& sHost, const wxString& sService, const wxString& sTopic);
  84. void Disconnect();
  85. wxConnectionBase *OnMakeConnection();
  86. bool IsConnected() { return m_connection != NULL; };
  87. MyConnection *GetConnection() { return m_connection; };
  88. protected:
  89. MyConnection *m_connection;
  90. };