log Unicode data correctly, extract the logging code in MyConnectionBase class instea...
[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 #include "connection.h"
13
14 #define ID_START 10000
15 #define ID_DISCONNECT 10001
16 #define ID_ADVISE 10002
17 #define ID_LOG 10003
18 #define ID_SERVERNAME 10004
19
20 // Define a new application
21 class MyServer;
22 class MyFrame;
23
24 class MyApp : public wxApp
25 {
26 public:
27 virtual bool OnInit();
28 virtual int OnExit();
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 OnExit(wxCommandEvent& event);
44 void OnClose(wxCloseEvent& event);
45
46 void Enable();
47 void Disconnect();
48
49 protected:
50 wxButton* GetStart() { return (wxButton*) FindWindow( ID_START ); }
51 wxChoice* GetServername() { return (wxChoice*) FindWindow( ID_SERVERNAME ); }
52 wxButton* GetDisconnect() { return (wxButton*) FindWindow( ID_DISCONNECT ); }
53 wxButton* GetAdvise() { return (wxButton*) FindWindow( ID_ADVISE ); }
54 wxTextCtrl* GetLog() { return (wxTextCtrl*) FindWindow( ID_LOG ); }
55
56
57 MyServer *m_server;
58
59 void OnStart( wxCommandEvent &event );
60 void OnServerName( wxCommandEvent &event );
61 void OnDisconnect( wxCommandEvent &event );
62 void OnAdvise( wxCommandEvent &event );
63
64 DECLARE_EVENT_TABLE()
65 };
66
67 class MyConnection : public MyConnectionBase
68 {
69 public:
70 virtual bool OnExecute(const wxString& topic, const void *data, size_t size, wxIPCFormat format);
71 virtual const void *OnRequest(const wxString& topic, const wxString& item, size_t *size, wxIPCFormat format);
72 virtual bool OnPoke(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format);
73 virtual bool OnStartAdvise(const wxString& topic, const wxString& item);
74 virtual bool OnStopAdvise(const wxString& topic, const wxString& item);
75 virtual bool DoAdvise(const wxString& item, const void *data, size_t size, wxIPCFormat format);
76 virtual bool OnDisconnect();
77
78 wxString m_sAdvise;
79
80 protected:
81 wxString m_sRequestDate;
82 char m_achRequestBytes[3];
83 };
84
85 class MyServer: public wxServer
86 {
87 public:
88 MyServer();
89 ~MyServer();
90 void Disconnect();
91 bool IsConnected() { return m_connection != NULL; };
92 MyConnection *GetConnection() { return m_connection; };
93 void Advise();
94 bool CanAdvise() { return m_connection != NULL && !m_connection->m_sAdvise.IsEmpty(); };
95 wxConnectionBase *OnAcceptConnection(const wxString& topic);
96
97 protected:
98 MyConnection *m_connection;
99 };
100