made strings used in wxIPC methods const as a temporary compilation fix (they will...
[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 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #define ID_START 10000
13 #define ID_DISCONNECT 10001
14 #define ID_ADVISE 10002
15 #define ID_LOG 10003
16 #define ID_SERVERNAME 10004
17
18 // Define a new application
19 class MyServer;
20 class MyConnection;
21 class MyFrame;
22
23 class MyApp : public wxApp
24 {
25 public:
26 virtual bool OnInit();
27 virtual int OnExit();
28 MyFrame *GetFrame() { return m_frame; };
29
30 protected:
31 MyFrame *m_frame;
32 };
33
34 DECLARE_APP(MyApp)
35
36 // Define a new frame
37 class MyFrame : public wxFrame
38 {
39 public:
40 MyFrame(wxFrame *frame, const wxString& title);
41
42 void OnExit(wxCommandEvent& event);
43 void OnClose(wxCloseEvent& event);
44
45 void Enable();
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 wxTextCtrl* GetLog() { return (wxTextCtrl*) FindWindow( ID_LOG ); }
54
55
56 MyServer *m_server;
57
58 void OnStart( wxCommandEvent &event );
59 void OnServerName( wxCommandEvent &event );
60 void OnDisconnect( wxCommandEvent &event );
61 void OnAdvise( wxCommandEvent &event );
62
63 DECLARE_EVENT_TABLE()
64 };
65
66 class MyConnection : public wxConnection
67 {
68 public:
69 MyConnection();
70 ~MyConnection();
71
72 virtual bool OnExecute(const wxString& topic, wxChar *data, int size, wxIPCFormat format);
73 virtual const wxChar *OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format);
74 virtual bool OnPoke(const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format);
75 virtual bool OnStartAdvise(const wxString& topic, const wxString& item);
76 virtual bool OnStopAdvise(const wxString& topic, const wxString& item);
77 virtual bool Advise(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
78 virtual bool OnDisconnect();
79 protected:
80 void Log(const wxString& command, const wxString& topic, const wxString& item, const wxChar *data, int size, wxIPCFormat format);
81 public:
82 wxString m_sAdvise;
83 protected:
84 wxString m_sRequestDate;
85 char m_achRequestBytes[3];
86 };
87
88 class MyServer: public wxServer
89 {
90 public:
91 MyServer();
92 ~MyServer();
93 void Disconnect();
94 bool IsConnected() { return m_connection != NULL; };
95 MyConnection *GetConnection() { return m_connection; };
96 void Advise();
97 bool CanAdvise() { return m_connection != NULL && !m_connection->m_sAdvise.IsEmpty(); };
98 wxConnectionBase *OnAcceptConnection(const wxString& topic);
99
100 protected:
101 MyConnection *m_connection;
102 };
103