]>
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$ | |
371a5b4e | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_IPCBASEH__ |
13 | #define _WX_IPCBASEH__ | |
c801d85f KB |
14 | |
15 | #include "wx/defs.h" | |
16 | #include "wx/object.h" | |
17 | #include "wx/string.h" | |
18 | ||
0d2a2b60 RR |
19 | enum wxIPCFormat |
20 | { | |
21 | wxIPC_INVALID = 0, | |
22 | wxIPC_TEXT = 1, /* CF_TEXT */ | |
23 | wxIPC_BITMAP = 2, /* CF_BITMAP */ | |
24 | wxIPC_METAFILE = 3, /* CF_METAFILEPICT */ | |
25 | wxIPC_SYLK = 4, | |
26 | wxIPC_DIF = 5, | |
27 | wxIPC_TIFF = 6, | |
28 | wxIPC_OEMTEXT = 7, /* CF_OEMTEXT */ | |
29 | wxIPC_DIB = 8, /* CF_DIB */ | |
30 | wxIPC_PALETTE = 9, | |
31 | wxIPC_PENDATA = 10, | |
32 | wxIPC_RIFF = 11, | |
33 | wxIPC_WAVE = 12, | |
50c549b9 | 34 | wxIPC_UTF16TEXT = 13, /* CF_UNICODE */ |
0d2a2b60 RR |
35 | wxIPC_ENHMETAFILE = 14, |
36 | wxIPC_FILENAME = 15, /* CF_HDROP */ | |
37 | wxIPC_LOCALE = 16, | |
50c549b9 VZ |
38 | wxIPC_UTF8TEXT = 17, |
39 | wxIPC_UTF32TEXT = 18, | |
40 | #if SIZEOF_WCHAR_T == 2 | |
41 | wxIPC_UNICODETEXT = wxIPC_UTF16TEXT, | |
42 | #elif SIZEOF_WCHAR_T == 4 | |
43 | wxIPC_UNICODETEXT = wxIPC_UTF32TEXT, | |
44 | #else | |
45 | # error "Unknown wchar_t size" | |
46 | #endif | |
0d2a2b60 RR |
47 | wxIPC_PRIVATE = 20 |
48 | }; | |
49 | ||
b5dbe15d VS |
50 | class WXDLLIMPEXP_FWD_BASE wxServerBase; |
51 | class WXDLLIMPEXP_FWD_BASE wxClientBase; | |
c801d85f | 52 | |
bddd7a8d | 53 | class WXDLLIMPEXP_BASE wxConnectionBase: public wxObject |
c801d85f | 54 | { |
f6bcfd97 | 55 | public: |
50c549b9 | 56 | wxConnectionBase(void *buffer, size_t size); // use external buffer |
f010ad48 | 57 | wxConnectionBase(); // use internal, adaptive buffer |
fbfb8bcc | 58 | wxConnectionBase(const wxConnectionBase& copy); |
50c549b9 | 59 | virtual ~wxConnectionBase(); |
f010ad48 JS |
60 | |
61 | void SetConnected( bool c ) { m_connected = c; } | |
62 | bool GetConnected() { return m_connected; } | |
c801d85f KB |
63 | |
64 | // Calls that CLIENT can make | |
50c549b9 VZ |
65 | bool Execute(const void *data, size_t size, wxIPCFormat fmt = wxIPC_PRIVATE) |
66 | { return DoExecute(data, size, fmt); } | |
67 | bool Execute(const char *s, size_t size = wxNO_LEN) | |
68 | { return DoExecute(s, size == wxNO_LEN ? strlen(s) + 1 | |
69 | : size, wxIPC_TEXT); } | |
70 | bool Execute(const wchar_t *ws, size_t size = wxNO_LEN) | |
71 | { return DoExecute(ws, size == wxNO_LEN ? (wcslen(ws) + 1)*sizeof(wchar_t) | |
72 | : size, wxIPC_UNICODETEXT); } | |
73 | bool Execute(const wxString& s) | |
74 | { | |
75 | const wxUTF8Buf buf = s.utf8_str(); | |
76 | return DoExecute(buf, strlen(buf) + 1, wxIPC_UTF8TEXT); | |
77 | } | |
78 | bool Execute(const wxCStrData& cs) | |
79 | { return Execute(cs.AsString()); } | |
80 | ||
81 | virtual const void *Request(const wxString& item, | |
82 | size_t *size = NULL, | |
83 | wxIPCFormat format = wxIPC_TEXT) = 0; | |
84 | ||
85 | bool Poke(const wxString& item, const void *data, size_t size, | |
86 | wxIPCFormat fmt = wxIPC_PRIVATE) | |
87 | { return DoPoke(item, data, size, fmt); } | |
88 | bool Poke(const wxString& item, const char *s, size_t size = wxNO_LEN) | |
89 | { return DoPoke(item, s, size == wxNO_LEN ? strlen(s) + 1 | |
90 | : size, wxIPC_TEXT); } | |
91 | bool Poke(const wxString& item, const wchar_t *ws, size_t size = wxNO_LEN) | |
92 | { return DoPoke(item, ws, | |
93 | size == wxNO_LEN ? (wcslen(ws) + 1)*sizeof(wchar_t) | |
94 | : size, wxIPC_UNICODETEXT); } | |
95 | bool Poke(const wxString& item, const wxString s) | |
96 | { | |
97 | const wxUTF8Buf buf = s.utf8_str(); | |
98 | return DoPoke(item, buf, strlen(buf) + 1, wxIPC_UTF8TEXT); | |
99 | } | |
100 | bool Poke(const wxString& item, const wxCStrData& cs) | |
101 | { return Poke(item, cs.AsString()); } | |
102 | ||
c801d85f KB |
103 | virtual bool StartAdvise(const wxString& item) = 0; |
104 | virtual bool StopAdvise(const wxString& item) = 0; | |
105 | ||
106 | // Calls that SERVER can make | |
50c549b9 VZ |
107 | bool Advise(const wxString& item, const void *data, size_t size, |
108 | wxIPCFormat fmt = wxIPC_PRIVATE) | |
109 | { return DoAdvise(item, data, size, fmt); } | |
110 | bool Advise(const wxString& item, const char *s, size_t size = wxNO_LEN) | |
111 | { return DoAdvise(item, s, size == wxNO_LEN ? strlen(s) + 1 | |
112 | : size, wxIPC_TEXT); } | |
113 | bool Advise(const wxString& item, const wchar_t *ws, size_t size = wxNO_LEN) | |
114 | { return DoAdvise(item, ws, | |
115 | size == wxNO_LEN ? (wcslen(ws) + 1)*sizeof(wchar_t) | |
116 | : size, wxIPC_UNICODETEXT); } | |
117 | bool Advise(const wxString& item, const wxString s) | |
118 | { | |
119 | const wxUTF8Buf buf = s.utf8_str(); | |
120 | return DoAdvise(item, buf, strlen(buf) + 1, wxIPC_UTF8TEXT); | |
121 | } | |
122 | bool Advise(const wxString& item, const wxCStrData& cs) | |
123 | { return Advise(item, cs.AsString()); } | |
c801d85f KB |
124 | |
125 | // Calls that both can make | |
50c549b9 VZ |
126 | virtual bool Disconnect() = 0; |
127 | ||
c801d85f KB |
128 | |
129 | // Callbacks to SERVER - override at will | |
50c549b9 VZ |
130 | virtual bool OnExecute(const wxString& WXUNUSED(topic), |
131 | const void *WXUNUSED(data), | |
132 | size_t WXUNUSED(size), | |
133 | wxIPCFormat WXUNUSED(format)) | |
134 | { return false; } | |
135 | ||
136 | virtual const void *OnRequest(const wxString& WXUNUSED(topic), | |
137 | const wxString& WXUNUSED(item), | |
138 | size_t *size, | |
139 | wxIPCFormat WXUNUSED(format)) | |
140 | { *size = 0; return NULL; } | |
141 | ||
142 | virtual bool OnPoke(const wxString& WXUNUSED(topic), | |
143 | const wxString& WXUNUSED(item), | |
144 | const void *WXUNUSED(data), | |
145 | size_t WXUNUSED(size), | |
146 | wxIPCFormat WXUNUSED(format)) | |
147 | { return false; } | |
148 | ||
149 | virtual bool OnStartAdvise(const wxString& WXUNUSED(topic), | |
150 | const wxString& WXUNUSED(item)) | |
151 | { return false; } | |
152 | ||
153 | virtual bool OnStopAdvise(const wxString& WXUNUSED(topic), | |
154 | const wxString& WXUNUSED(item)) | |
155 | { return false; } | |
c801d85f KB |
156 | |
157 | // Callbacks to CLIENT - override at will | |
50c549b9 VZ |
158 | virtual bool OnAdvise(const wxString& WXUNUSED(topic), |
159 | const wxString& WXUNUSED(item), | |
160 | const void *WXUNUSED(data), | |
161 | size_t WXUNUSED(size), | |
162 | wxIPCFormat WXUNUSED(format)) | |
163 | { return false; } | |
164 | ||
165 | // Callbacks to BOTH | |
166 | virtual bool OnDisconnect() { delete this; return true; } | |
c801d85f | 167 | |
f010ad48 JS |
168 | |
169 | // return a buffer at least this size, reallocating buffer if needed | |
50c549b9 VZ |
170 | // returns NULL if using an inadequate user buffer which can't be resized |
171 | void *GetBufferAtLeast(size_t bytes); | |
f010ad48 JS |
172 | |
173 | protected: | |
50c549b9 VZ |
174 | virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format) = 0; |
175 | virtual bool DoPoke(const wxString& item, const void *data, size_t size, | |
176 | wxIPCFormat format) = 0; | |
177 | virtual bool DoAdvise(const wxString& item, const void *data, size_t size, | |
178 | wxIPCFormat format) = 0; | |
179 | ||
180 | ||
f010ad48 | 181 | private: |
50c549b9 | 182 | char *m_buffer; |
f010ad48 JS |
183 | size_t m_buffersize; |
184 | bool m_deletebufferwhendone; | |
22f3361e | 185 | |
50c549b9 VZ |
186 | protected: |
187 | bool m_connected; | |
188 | ||
189 | DECLARE_NO_ASSIGN_CLASS(wxConnectionBase); | |
190 | DECLARE_CLASS(wxConnectionBase) | |
c801d85f KB |
191 | }; |
192 | ||
f010ad48 | 193 | |
50c549b9 | 194 | class WXDLLIMPEXP_BASE wxServerBase : public wxObject |
c801d85f | 195 | { |
f6bcfd97 | 196 | public: |
50c549b9 VZ |
197 | wxServerBase() { } |
198 | virtual ~wxServerBase() { } | |
c801d85f | 199 | |
7beb59f3 | 200 | // Returns false on error (e.g. port number is already in use) |
f6bcfd97 BP |
201 | virtual bool Create(const wxString& serverName) = 0; |
202 | ||
203 | // Callbacks to SERVER - override at will | |
204 | virtual wxConnectionBase *OnAcceptConnection(const wxString& topic) = 0; | |
50c549b9 VZ |
205 | |
206 | DECLARE_CLASS(wxServerBase) | |
c801d85f KB |
207 | }; |
208 | ||
50c549b9 | 209 | class WXDLLIMPEXP_BASE wxClientBase : public wxObject |
c801d85f | 210 | { |
f6bcfd97 | 211 | public: |
50c549b9 VZ |
212 | wxClientBase() { } |
213 | virtual ~wxClientBase() { } | |
f6bcfd97 | 214 | |
c801d85f | 215 | virtual bool ValidHost(const wxString& host) = 0; |
c801d85f | 216 | |
f6bcfd97 BP |
217 | // Call this to make a connection. Returns NULL if cannot. |
218 | virtual wxConnectionBase *MakeConnection(const wxString& host, | |
219 | const wxString& server, | |
220 | const wxString& topic) = 0; | |
221 | ||
222 | // Callbacks to CLIENT - override at will | |
50c549b9 VZ |
223 | virtual wxConnectionBase *OnMakeConnection() = 0; |
224 | ||
225 | DECLARE_CLASS(wxClientBase) | |
c801d85f KB |
226 | }; |
227 | ||
50c549b9 | 228 | #endif // _WX_IPCBASEH__ |