]>
Commit | Line | Data |
---|---|---|
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_IPCBASEH__ | |
13 | #define _WX_IPCBASEH__ | |
14 | ||
15 | #include "wx/defs.h" | |
16 | #include "wx/object.h" | |
17 | #include "wx/string.h" | |
18 | ||
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, | |
34 | wxIPC_UNICODETEXT = 13, | |
35 | wxIPC_ENHMETAFILE = 14, | |
36 | wxIPC_FILENAME = 15, /* CF_HDROP */ | |
37 | wxIPC_LOCALE = 16, | |
38 | wxIPC_PRIVATE = 20 | |
39 | }; | |
40 | ||
41 | class WXDLLIMPEXP_BASE wxServerBase; | |
42 | class WXDLLIMPEXP_BASE wxClientBase; | |
43 | ||
44 | class WXDLLIMPEXP_BASE wxConnectionBase: public wxObject | |
45 | { | |
46 | DECLARE_CLASS(wxConnectionBase) | |
47 | ||
48 | public: | |
49 | wxConnectionBase(wxChar *buffer, int size); // use external buffer | |
50 | wxConnectionBase(); // use internal, adaptive buffer | |
51 | wxConnectionBase(const wxConnectionBase& copy); | |
52 | virtual ~wxConnectionBase(void); | |
53 | ||
54 | void SetConnected( bool c ) { m_connected = c; } | |
55 | bool GetConnected() { return m_connected; } | |
56 | ||
57 | // Calls that CLIENT can make | |
58 | virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT ) = 0; | |
59 | virtual bool Execute(const wxString& str) { return Execute(str, -1, wxIPC_TEXT); } | |
60 | virtual wxChar *Request(const wxString& item, int *size = (int *) NULL, wxIPCFormat format = wxIPC_TEXT) = 0; | |
61 | virtual bool Poke(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT) = 0; | |
62 | virtual bool StartAdvise(const wxString& item) = 0; | |
63 | virtual bool StopAdvise(const wxString& item) = 0; | |
64 | ||
65 | // Calls that SERVER can make | |
66 | virtual bool Advise(const wxString& item, wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT) = 0; | |
67 | ||
68 | // Calls that both can make | |
69 | virtual bool Disconnect(void) = 0; | |
70 | ||
71 | // Callbacks to SERVER - override at will | |
72 | virtual bool OnExecute ( const wxString& WXUNUSED(topic), | |
73 | wxChar *WXUNUSED(data), | |
74 | int WXUNUSED(size), | |
75 | wxIPCFormat WXUNUSED(format) ) | |
76 | { return false; } | |
77 | ||
78 | virtual wxChar *OnRequest ( const wxString& WXUNUSED(topic), | |
79 | const wxString& WXUNUSED(item), | |
80 | int *WXUNUSED(size), | |
81 | wxIPCFormat WXUNUSED(format) ) | |
82 | { return (wxChar *) NULL; } | |
83 | ||
84 | virtual bool OnPoke ( const wxString& WXUNUSED(topic), | |
85 | const wxString& WXUNUSED(item), | |
86 | wxChar *WXUNUSED(data), | |
87 | int WXUNUSED(size), | |
88 | wxIPCFormat WXUNUSED(format) ) | |
89 | { return false; } | |
90 | ||
91 | virtual bool OnStartAdvise ( const wxString& WXUNUSED(topic), | |
92 | const wxString& WXUNUSED(item) ) | |
93 | { return false; } | |
94 | ||
95 | virtual bool OnStopAdvise ( const wxString& WXUNUSED(topic), | |
96 | const wxString& WXUNUSED(item) ) | |
97 | { return false; } | |
98 | ||
99 | // Callbacks to CLIENT - override at will | |
100 | virtual bool OnAdvise ( const wxString& WXUNUSED(topic), | |
101 | const wxString& WXUNUSED(item), | |
102 | wxChar *WXUNUSED(data), | |
103 | int WXUNUSED(size), | |
104 | wxIPCFormat WXUNUSED(format) ) | |
105 | { return false; } | |
106 | ||
107 | // Callbacks to BOTH - override at will | |
108 | // Default behaviour is to delete connection and return true | |
109 | virtual bool OnDisconnect(void) = 0; | |
110 | ||
111 | // return a buffer at least this size, reallocating buffer if needed | |
112 | // returns NULL if using an inadequate user buffer - it can't be resized | |
113 | wxChar * GetBufferAtLeast( size_t bytes ); | |
114 | ||
115 | protected: | |
116 | bool m_connected; | |
117 | private: | |
118 | wxChar * m_buffer; | |
119 | size_t m_buffersize; | |
120 | bool m_deletebufferwhendone; | |
121 | ||
122 | // can't use DECLARE_NO_COPY_CLASS(wxConnectionBase) because we already | |
123 | // have copy ctor but still forbid the default assignment operator | |
124 | wxConnectionBase& operator=(const wxConnectionBase&); | |
125 | }; | |
126 | ||
127 | ||
128 | class WXDLLIMPEXP_BASE wxServerBase: public wxObject | |
129 | { | |
130 | DECLARE_CLASS(wxServerBase) | |
131 | ||
132 | public: | |
133 | inline wxServerBase(void) {} | |
134 | inline ~wxServerBase(void) {} | |
135 | ||
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; | |
141 | }; | |
142 | ||
143 | class WXDLLIMPEXP_BASE wxClientBase: public wxObject | |
144 | { | |
145 | DECLARE_CLASS(wxClientBase) | |
146 | ||
147 | public: | |
148 | inline wxClientBase(void) {} | |
149 | inline ~wxClientBase(void) {} | |
150 | ||
151 | virtual bool ValidHost(const wxString& host) = 0; | |
152 | ||
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; | |
160 | }; | |
161 | ||
162 | #endif | |
163 | // _WX_IPCBASEH__ |