]> git.saurik.com Git - wxWidgets.git/blob - samples/ipc/server.h
Somehow, setting a tint color makes gauge work :/.
[wxWidgets.git] / samples / ipc / server.h
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
11 #include "connection.h"
12
13 enum
14 {
15 ID_START = 10000,
16 ID_DISCONNECT,
17 ID_ADVISE,
18 ID_SERVERNAME,
19 };
20
21 // Define a new application
22 class MyServer;
23 class MyFrame;
24
25 class MyApp : public wxApp
26 {
27 public:
28 virtual bool OnInit();
29 MyFrame *GetFrame() { return m_frame; }
30
31 protected:
32 MyFrame *m_frame;
33 };
34
35 DECLARE_APP(MyApp)
36
37 // Define a new frame
38 class MyFrame : public wxFrame
39 {
40 public:
41 MyFrame(wxFrame *frame, const wxString& title);
42
43 void OnClose(wxCloseEvent& event);
44
45 void UpdateUI();
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 ); }
53
54
55 MyServer *m_server;
56
57 void OnStart( wxCommandEvent &event );
58 void OnServerName( wxCommandEvent &event );
59 void OnDisconnect( wxCommandEvent &event );
60 void OnAdvise( wxCommandEvent &event );
61
62 DECLARE_EVENT_TABLE()
63 };
64
65 class MyConnection : public MyConnectionBase
66 {
67 public:
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);
71 virtual bool OnStartAdvise(const wxString& topic, const wxString& item);
72 virtual bool OnStopAdvise(const wxString& topic, const wxString& item);
73 virtual bool DoAdvise(const wxString& item, const void *data, size_t size, wxIPCFormat format);
74 virtual bool OnDisconnect();
75
76 // topic for which we advise the client or empty if none
77 wxString m_advise;
78
79 protected:
80 // the data returned by last OnRequest(): we keep it in this buffer to
81 // ensure that the pointer we return from OnRequest() stays valid
82 wxCharBuffer m_requestData;
83 };
84
85 class MyServer : public wxServer
86 {
87 public:
88 MyServer();
89 virtual ~MyServer();
90
91 void Disconnect();
92 bool IsConnected() { return m_connection != NULL; }
93 MyConnection *GetConnection() { return m_connection; }
94
95 void Advise();
96 bool CanAdvise() { return m_connection && !m_connection->m_advise.empty(); }
97
98 virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
99
100 protected:
101 MyConnection *m_connection;
102 };
103