1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Base classes for IPC
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_IPCBASEH__
13 #define _WX_IPCBASEH__
16 #include "wx/object.h"
17 #include "wx/string.h"
22 wxIPC_TEXT
= 1, /* CF_TEXT */
23 wxIPC_BITMAP
= 2, /* CF_BITMAP */
24 wxIPC_METAFILE
= 3, /* CF_METAFILEPICT */
28 wxIPC_OEMTEXT
= 7, /* CF_OEMTEXT */
29 wxIPC_DIB
= 8, /* CF_DIB */
34 wxIPC_UNICODETEXT
= 13,
35 wxIPC_ENHMETAFILE
= 14,
36 wxIPC_FILENAME
= 15, /* CF_HDROP */
41 class WXDLLIMPEXP_BASE wxServerBase
;
42 class WXDLLIMPEXP_BASE wxClientBase
;
44 class WXDLLIMPEXP_BASE wxConnectionBase
: public wxObject
46 DECLARE_CLASS(wxConnectionBase
)
49 wxConnectionBase(wxChar
*buffer
, int size
); // use external buffer
50 wxConnectionBase(); // use internal, adaptive buffer
51 wxConnectionBase(const wxConnectionBase
& copy
);
52 virtual ~wxConnectionBase(void);
54 void SetConnected( bool c
) { m_connected
= c
; }
55 bool GetConnected() { return m_connected
; }
57 // Calls that CLIENT can make
58 virtual bool Execute(const wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
) = 0;
59 // FIXME-UTF8: review this code for compatibility implications, update
60 // accordingly, don' use c_str() below
61 virtual bool Execute(const wxString
& str
)
62 { return Execute(str
.c_str(), -1, wxIPC_TEXT
); }
63 virtual wxChar
*Request(const wxString
& item
, int *size
= (int *) NULL
, wxIPCFormat format
= wxIPC_TEXT
) = 0;
64 virtual bool Poke(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
) = 0;
65 virtual bool StartAdvise(const wxString
& item
) = 0;
66 virtual bool StopAdvise(const wxString
& item
) = 0;
68 // Calls that SERVER can make
69 virtual bool Advise(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
) = 0;
71 // Calls that both can make
72 virtual bool Disconnect(void) = 0;
74 // Callbacks to SERVER - override at will
75 virtual bool OnExecute ( const wxString
& WXUNUSED(topic
),
76 wxChar
*WXUNUSED(data
),
78 wxIPCFormat
WXUNUSED(format
) )
81 virtual wxChar
*OnRequest ( const wxString
& WXUNUSED(topic
),
82 const wxString
& WXUNUSED(item
),
84 wxIPCFormat
WXUNUSED(format
) )
85 { return (wxChar
*) NULL
; }
87 virtual bool OnPoke ( const wxString
& WXUNUSED(topic
),
88 const wxString
& WXUNUSED(item
),
89 wxChar
*WXUNUSED(data
),
91 wxIPCFormat
WXUNUSED(format
) )
94 virtual bool OnStartAdvise ( const wxString
& WXUNUSED(topic
),
95 const wxString
& WXUNUSED(item
) )
98 virtual bool OnStopAdvise ( const wxString
& WXUNUSED(topic
),
99 const wxString
& WXUNUSED(item
) )
102 // Callbacks to CLIENT - override at will
103 virtual bool OnAdvise ( const wxString
& WXUNUSED(topic
),
104 const wxString
& WXUNUSED(item
),
105 wxChar
*WXUNUSED(data
),
107 wxIPCFormat
WXUNUSED(format
) )
110 // Callbacks to BOTH - override at will
111 // Default behaviour is to delete connection and return true
112 virtual bool OnDisconnect(void) = 0;
114 // return a buffer at least this size, reallocating buffer if needed
115 // returns NULL if using an inadequate user buffer - it can't be resized
116 wxChar
* GetBufferAtLeast( size_t bytes
);
123 bool m_deletebufferwhendone
;
125 // can't use DECLARE_NO_COPY_CLASS(wxConnectionBase) because we already
126 // have copy ctor but still forbid the default assignment operator
127 wxConnectionBase
& operator=(const wxConnectionBase
&);
131 class WXDLLIMPEXP_BASE wxServerBase
: public wxObject
133 DECLARE_CLASS(wxServerBase
)
136 inline wxServerBase(void) {}
137 inline ~wxServerBase(void) {}
139 // Returns false on error (e.g. port number is already in use)
140 virtual bool Create(const wxString
& serverName
) = 0;
142 // Callbacks to SERVER - override at will
143 virtual wxConnectionBase
*OnAcceptConnection(const wxString
& topic
) = 0;
146 class WXDLLIMPEXP_BASE wxClientBase
: public wxObject
148 DECLARE_CLASS(wxClientBase
)
151 inline wxClientBase(void) {}
152 inline ~wxClientBase(void) {}
154 virtual bool ValidHost(const wxString
& host
) = 0;
156 // Call this to make a connection. Returns NULL if cannot.
157 virtual wxConnectionBase
*MakeConnection(const wxString
& host
,
158 const wxString
& server
,
159 const wxString
& topic
) = 0;
161 // Callbacks to CLIENT - override at will
162 virtual wxConnectionBase
*OnMakeConnection(void) = 0;