]>
Commit | Line | Data |
---|---|---|
7921cf2b JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: server.h | |
3 | // Purpose: DDE sample: server | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 25/01/99 | |
7921cf2b JS |
7 | // Copyright: (c) Julian Smart |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
521d3436 VZ |
11 | #include "connection.h" |
12 | ||
589c1174 VZ |
13 | enum |
14 | { | |
15 | ID_START = 10000, | |
16 | ID_DISCONNECT, | |
17 | ID_ADVISE, | |
18 | ID_SERVERNAME, | |
19 | }; | |
9d860992 | 20 | |
7921cf2b | 21 | // Define a new application |
4b89c618 | 22 | class MyServer; |
9d860992 JS |
23 | class MyFrame; |
24 | ||
4b89c618 | 25 | class MyApp : public wxApp |
7921cf2b | 26 | { |
4b89c618 VZ |
27 | public: |
28 | virtual bool OnInit(); | |
589c1174 | 29 | MyFrame *GetFrame() { return m_frame; } |
4b89c618 | 30 | |
9d860992 | 31 | protected: |
589c1174 | 32 | MyFrame *m_frame; |
7921cf2b JS |
33 | }; |
34 | ||
35 | DECLARE_APP(MyApp) | |
36 | ||
37 | // Define a new frame | |
4b89c618 | 38 | class MyFrame : public wxFrame |
7921cf2b | 39 | { |
4b89c618 VZ |
40 | public: |
41 | MyFrame(wxFrame *frame, const wxString& title); | |
7921cf2b | 42 | |
9d860992 JS |
43 | void OnClose(wxCloseEvent& event); |
44 | ||
589c1174 | 45 | void UpdateUI(); |
9d860992 JS |
46 | void Disconnect(); |
47 | ||
48 | protected: | |
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 ); } | |
4b89c618 | 53 | |
9d860992 | 54 | |
589c1174 | 55 | MyServer *m_server; |
9d860992 JS |
56 | |
57 | void OnStart( wxCommandEvent &event ); | |
58 | void OnServerName( wxCommandEvent &event ); | |
59 | void OnDisconnect( wxCommandEvent &event ); | |
60 | void OnAdvise( wxCommandEvent &event ); | |
4b89c618 VZ |
61 | |
62 | DECLARE_EVENT_TABLE() | |
7921cf2b JS |
63 | }; |
64 | ||
521d3436 | 65 | class MyConnection : public MyConnectionBase |
7921cf2b | 66 | { |
4b89c618 | 67 | public: |
50c549b9 VZ |
68 | virtual bool OnExecute(const wxString& topic, const void *data, size_t size, wxIPCFormat format); |
69 | virtual const void *OnRequest(const wxString& topic, const wxString& item, size_t *size, wxIPCFormat format); | |
70 | virtual bool OnPoke(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format); | |
9d860992 JS |
71 | virtual bool OnStartAdvise(const wxString& topic, const wxString& item); |
72 | virtual bool OnStopAdvise(const wxString& topic, const wxString& item); | |
50c549b9 | 73 | virtual bool DoAdvise(const wxString& item, const void *data, size_t size, wxIPCFormat format); |
9d860992 | 74 | virtual bool OnDisconnect(); |
521d3436 | 75 | |
589c1174 VZ |
76 | // topic for which we advise the client or empty if none |
77 | wxString m_advise; | |
521d3436 | 78 | |
9d860992 | 79 | protected: |
e536b750 | 80 | // the data returned by last OnRequest(): we keep it in this buffer to |
589c1174 | 81 | // ensure that the pointer we return from OnRequest() stays valid |
e536b750 | 82 | wxCharBuffer m_requestData; |
7921cf2b JS |
83 | }; |
84 | ||
589c1174 | 85 | class MyServer : public wxServer |
7921cf2b JS |
86 | { |
87 | public: | |
9d860992 | 88 | MyServer(); |
589c1174 VZ |
89 | virtual ~MyServer(); |
90 | ||
9d860992 | 91 | void Disconnect(); |
589c1174 VZ |
92 | bool IsConnected() { return m_connection != NULL; } |
93 | MyConnection *GetConnection() { return m_connection; } | |
94 | ||
9d860992 | 95 | void Advise(); |
589c1174 VZ |
96 | bool CanAdvise() { return m_connection && !m_connection->m_advise.empty(); } |
97 | ||
98 | virtual wxConnectionBase *OnAcceptConnection(const wxString& topic); | |
7921cf2b | 99 | |
9d860992 | 100 | protected: |
589c1174 | 101 | MyConnection *m_connection; |
7921cf2b JS |
102 | }; |
103 |