1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Base classes for IPC
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_IPCBASEH__
13 #define _WX_IPCBASEH__
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "ipcbase.h"
20 #include "wx/object.h"
21 #include "wx/string.h"
26 wxIPC_TEXT
= 1, /* CF_TEXT */
27 wxIPC_BITMAP
= 2, /* CF_BITMAP */
28 wxIPC_METAFILE
= 3, /* CF_METAFILEPICT */
32 wxIPC_OEMTEXT
= 7, /* CF_OEMTEXT */
33 wxIPC_DIB
= 8, /* CF_DIB */
38 wxIPC_UNICODETEXT
= 13,
39 wxIPC_ENHMETAFILE
= 14,
40 wxIPC_FILENAME
= 15, /* CF_HDROP */
45 class WXDLLEXPORT wxServerBase
;
46 class WXDLLEXPORT wxClientBase
;
48 class WXDLLEXPORT wxConnectionBase
: public wxObject
50 DECLARE_CLASS(wxConnectionBase
)
53 wxConnectionBase(wxChar
*buffer
, int size
); // use external buffer
54 wxConnectionBase(); // use internal, adaptive buffer
55 wxConnectionBase(wxConnectionBase
& copy
);
56 ~wxConnectionBase(void);
58 void SetConnected( bool c
) { m_connected
= c
; }
59 bool GetConnected() { return m_connected
; }
61 // Calls that CLIENT can make
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
); }
64 virtual char *Request(const wxString
& item
, int *size
= (int *) NULL
, wxIPCFormat format
= wxIPC_TEXT
) = 0;
65 virtual bool Poke(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
) = 0;
66 virtual bool StartAdvise(const wxString
& item
) = 0;
67 virtual bool StopAdvise(const wxString
& item
) = 0;
69 // Calls that SERVER can make
70 virtual bool Advise(const wxString
& item
, wxChar
*data
, int size
= -1, wxIPCFormat format
= wxIPC_TEXT
) = 0;
72 // Calls that both can make
73 virtual bool Disconnect(void) = 0;
75 // Callbacks to SERVER - override at will
76 virtual bool OnExecute ( const wxString
& WXUNUSED(topic
),
79 wxIPCFormat
WXUNUSED(format
) )
82 virtual char *OnRequest ( const wxString
& WXUNUSED(topic
),
83 const wxString
& WXUNUSED(item
),
85 wxIPCFormat
WXUNUSED(format
) )
86 { return (char *) NULL
; };
88 virtual bool OnPoke ( const wxString
& WXUNUSED(topic
),
89 const wxString
& WXUNUSED(item
),
90 wxChar
*WXUNUSED(data
),
92 wxIPCFormat
WXUNUSED(format
) )
95 virtual bool OnStartAdvise ( const wxString
& WXUNUSED(topic
),
96 const wxString
& WXUNUSED(item
) )
99 virtual bool OnStopAdvise ( const wxString
& WXUNUSED(topic
),
100 const wxString
& WXUNUSED(item
) )
103 // Callbacks to CLIENT - override at will
104 virtual bool OnAdvise ( const wxString
& WXUNUSED(topic
),
105 const wxString
& WXUNUSED(item
),
106 char *WXUNUSED(data
),
108 wxIPCFormat
WXUNUSED(format
) )
111 // Callbacks to BOTH - override at will
112 // Default behaviour is to delete connection and return TRUE
113 virtual bool OnDisconnect(void) = 0;
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
);
124 bool m_deletebufferwhendone
;
128 class WXDLLEXPORT wxServerBase
: public wxObject
130 DECLARE_CLASS(wxServerBase
)
133 inline wxServerBase(void) {}
134 inline ~wxServerBase(void) {};
136 // Returns FALSE on error (e.g. port number is already in use)
137 virtual bool Create(const wxString
& serverName
) = 0;
139 // Callbacks to SERVER - override at will
140 virtual wxConnectionBase
*OnAcceptConnection(const wxString
& topic
) = 0;
143 class WXDLLEXPORT wxClientBase
: public wxObject
145 DECLARE_CLASS(wxClientBase
)
148 inline wxClientBase(void) {};
149 inline ~wxClientBase(void) {};
151 virtual bool ValidHost(const wxString
& host
) = 0;
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;
158 // Callbacks to CLIENT - override at will
159 virtual wxConnectionBase
*OnMakeConnection(void) = 0;