]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: ipcbase.h | |
3 | // Purpose: Base classes for IPC | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 4/1/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
f010ad48 | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_IPCBASEH__ |
13 | #define _WX_IPCBASEH__ | |
c801d85f | 14 | |
af49c4b8 | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
0d3820b3 JS |
16 | #pragma interface "ipcbase.h" |
17 | #endif | |
18 | ||
c801d85f KB |
19 | #include "wx/defs.h" |
20 | #include "wx/object.h" | |
21 | #include "wx/string.h" | |
22 | ||
0d2a2b60 RR |
23 | enum wxIPCFormat |
24 | { | |
25 | wxIPC_INVALID = 0, | |
26 | wxIPC_TEXT = 1, /* CF_TEXT */ | |
27 | wxIPC_BITMAP = 2, /* CF_BITMAP */ | |
28 | wxIPC_METAFILE = 3, /* CF_METAFILEPICT */ | |
29 | wxIPC_SYLK = 4, | |
30 | wxIPC_DIF = 5, | |
31 | wxIPC_TIFF = 6, | |
32 | wxIPC_OEMTEXT = 7, /* CF_OEMTEXT */ | |
33 | wxIPC_DIB = 8, /* CF_DIB */ | |
34 | wxIPC_PALETTE = 9, | |
35 | wxIPC_PENDATA = 10, | |
36 | wxIPC_RIFF = 11, | |
37 | wxIPC_WAVE = 12, | |
38 | wxIPC_UNICODETEXT = 13, | |
39 | wxIPC_ENHMETAFILE = 14, | |
40 | wxIPC_FILENAME = 15, /* CF_HDROP */ | |
41 | wxIPC_LOCALE = 16, | |
42 | wxIPC_PRIVATE = 20 | |
43 | }; | |
44 | ||
07e829dc GRG |
45 | class WXDLLEXPORT wxServerBase; |
46 | class WXDLLEXPORT wxClientBase; | |
c801d85f KB |
47 | |
48 | class WXDLLEXPORT wxConnectionBase: public wxObject | |
49 | { | |
50 | DECLARE_CLASS(wxConnectionBase) | |
f6bcfd97 BP |
51 | |
52 | public: | |
f010ad48 JS |
53 | wxConnectionBase(wxChar *buffer, int size); // use external buffer |
54 | wxConnectionBase(); // use internal, adaptive buffer | |
55 | wxConnectionBase(wxConnectionBase& copy); | |
56 | ~wxConnectionBase(void); | |
57 | ||
58 | void SetConnected( bool c ) { m_connected = c; } | |
59 | bool GetConnected() { return m_connected; } | |
c801d85f KB |
60 | |
61 | // Calls that CLIENT can make | |
e90c1d2a VZ |
62 | virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT ) = 0; |
63 | virtual bool Execute(const wxString& str) { return Execute(str, -1, wxIPC_TEXT); } | |
d38e8d5f | 64 | virtual wxChar *Request(const wxString& item, int *size = (int *) NULL, wxIPCFormat format = wxIPC_TEXT) = 0; |
9d2f3c71 | 65 | virtual bool Poke(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT) = 0; |
c801d85f KB |
66 | virtual bool StartAdvise(const wxString& item) = 0; |
67 | virtual bool StopAdvise(const wxString& item) = 0; | |
68 | ||
69 | // Calls that SERVER can make | |
9d2f3c71 | 70 | virtual bool Advise(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT) = 0; |
c801d85f KB |
71 | |
72 | // Calls that both can make | |
73 | virtual bool Disconnect(void) = 0; | |
74 | ||
75 | // Callbacks to SERVER - override at will | |
85ac091e | 76 | virtual bool OnExecute ( const wxString& WXUNUSED(topic), |
d38e8d5f | 77 | wxChar *WXUNUSED(data), |
85ac091e GRG |
78 | int WXUNUSED(size), |
79 | wxIPCFormat WXUNUSED(format) ) | |
80 | { return FALSE; }; | |
81 | ||
d38e8d5f | 82 | virtual wxChar *OnRequest ( const wxString& WXUNUSED(topic), |
85ac091e GRG |
83 | const wxString& WXUNUSED(item), |
84 | int *WXUNUSED(size), | |
85 | wxIPCFormat WXUNUSED(format) ) | |
d38e8d5f | 86 | { return (wxChar *) NULL; }; |
85ac091e GRG |
87 | |
88 | virtual bool OnPoke ( const wxString& WXUNUSED(topic), | |
89 | const wxString& WXUNUSED(item), | |
90 | wxChar *WXUNUSED(data), | |
91 | int WXUNUSED(size), | |
92 | wxIPCFormat WXUNUSED(format) ) | |
93 | { return FALSE; }; | |
94 | ||
95 | virtual bool OnStartAdvise ( const wxString& WXUNUSED(topic), | |
96 | const wxString& WXUNUSED(item) ) | |
97 | { return FALSE; }; | |
98 | ||
99 | virtual bool OnStopAdvise ( const wxString& WXUNUSED(topic), | |
100 | const wxString& WXUNUSED(item) ) | |
c801d85f KB |
101 | { return FALSE; }; |
102 | ||
103 | // Callbacks to CLIENT - override at will | |
85ac091e GRG |
104 | virtual bool OnAdvise ( const wxString& WXUNUSED(topic), |
105 | const wxString& WXUNUSED(item), | |
d38e8d5f | 106 | wxChar *WXUNUSED(data), |
85ac091e GRG |
107 | int WXUNUSED(size), |
108 | wxIPCFormat WXUNUSED(format) ) | |
109 | { return FALSE; }; | |
c801d85f | 110 | |
f6bcfd97 | 111 | // Callbacks to BOTH - override at will |
c801d85f KB |
112 | // Default behaviour is to delete connection and return TRUE |
113 | virtual bool OnDisconnect(void) = 0; | |
f010ad48 JS |
114 | |
115 | // return a buffer at least this size, reallocating buffer if needed | |
116 | // returns NULL if using an inadequate user buffer - it can't be resized | |
117 | wxChar * GetBufferAtLeast( size_t bytes ); | |
118 | ||
119 | protected: | |
120 | bool m_connected; | |
121 | private: | |
122 | wxChar * m_buffer; | |
123 | size_t m_buffersize; | |
124 | bool m_deletebufferwhendone; | |
c801d85f KB |
125 | }; |
126 | ||
f010ad48 | 127 | |
c801d85f KB |
128 | class WXDLLEXPORT wxServerBase: public wxObject |
129 | { | |
130 | DECLARE_CLASS(wxServerBase) | |
c801d85f | 131 | |
f6bcfd97 | 132 | public: |
c801d85f KB |
133 | inline wxServerBase(void) {} |
134 | inline ~wxServerBase(void) {}; | |
c801d85f | 135 | |
f6bcfd97 BP |
136 | // Returns FALSE on error (e.g. port number is already in use) |
137 | virtual bool Create(const wxString& serverName) = 0; | |
138 | ||
139 | // Callbacks to SERVER - override at will | |
140 | virtual wxConnectionBase *OnAcceptConnection(const wxString& topic) = 0; | |
c801d85f KB |
141 | }; |
142 | ||
143 | class WXDLLEXPORT wxClientBase: public wxObject | |
144 | { | |
145 | DECLARE_CLASS(wxClientBase) | |
f6bcfd97 BP |
146 | |
147 | public: | |
c801d85f KB |
148 | inline wxClientBase(void) {}; |
149 | inline ~wxClientBase(void) {}; | |
f6bcfd97 | 150 | |
c801d85f | 151 | virtual bool ValidHost(const wxString& host) = 0; |
c801d85f | 152 | |
f6bcfd97 BP |
153 | // Call this to make a connection. Returns NULL if cannot. |
154 | virtual wxConnectionBase *MakeConnection(const wxString& host, | |
155 | const wxString& server, | |
156 | const wxString& topic) = 0; | |
157 | ||
158 | // Callbacks to CLIENT - override at will | |
159 | virtual wxConnectionBase *OnMakeConnection(void) = 0; | |
c801d85f KB |
160 | }; |
161 | ||
162 | #endif | |
34138703 | 163 | // _WX_IPCBASEH__ |