type "const char *", you need to remove wxT() or _T() around the values used
to initialize them (which should normally always be ASCII).
+- wxIPC classes didn't work correctly in Unicode build before, this was fixed
+ but at a price of breaking backwards compatibility: many methods which used
+ to work with "wxChar *" before use "void *" now (some int parameters were
+ also changed to size_t). While wxIPC_TEXT can still be used to transfer 7
+ bit text, the new wxIPC_UTF8TEXT format is used for transferring wxStrings.
Changes in behaviour not resulting in compilation errors, please read this!
All:
- Allow loading message catalogs from wxFileSystem (Axel Gembe)
+- Use UTF-8 for Unicode data in wxIPC classes (Anders Larsen)
- Added support for user-defined types to wxConfig (Marcin Wojdyr).
- Added wxJoin() and wxSplit() functions (Francesco Montorsi).
- Added wxMutex::LockTimeout() (Aleksandr Napylov).
wxIPC_PENDATA = 10,
wxIPC_RIFF = 11,
wxIPC_WAVE = 12,
- wxIPC_UNICODETEXT = 13,
+ wxIPC_UTF16TEXT = 13, /* CF_UNICODE */
wxIPC_ENHMETAFILE = 14,
wxIPC_FILENAME = 15, /* CF_HDROP */
wxIPC_LOCALE = 16,
+ wxIPC_UTF8TEXT = 17,
+ wxIPC_UTF32TEXT = 18,
+#if SIZEOF_WCHAR_T == 2
+ wxIPC_UNICODETEXT = wxIPC_UTF16TEXT,
+#elif SIZEOF_WCHAR_T == 4
+ wxIPC_UNICODETEXT = wxIPC_UTF32TEXT,
+#endif
wxIPC_PRIVATE = 20
};
\end{verbatim}
\func{}{wxDDEConnection}{\void}
-\func{}{wxDDEConnection}{\param{char* }{buffer}, \param{int}{ size}}
+\func{}{wxDDEConnection}{\param{void* }{buffer}, \param{size_t}{ size}}
Constructs a connection object. If no user-defined connection object is
to be derived from wxDDEConnection, then the constructor should not be
\membersection{wxDDEConnection::Advise}\label{wxddeconnectionadvise}
-\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{int}{ size = -1}, \param{wxIPCFormat}{ format = wxCF\_TEXT}}
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format = wxIPC\_PRIVATE}}
+
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const wchar_t* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const wxString& }{data}}
Called by the server application to advise the client of a change in
the data associated with the given item. Causes the client
\membersection{wxDDEConnection::Execute}\label{wxddeconnectionexecute}
-\func{bool}{Execute}{\param{char* }{data}, \param{int}{ size = -1}, \param{wxIPCFormat}{ format = wxCF\_TEXT}}
+\func{bool}{Execute}{\param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format = wxIPC\_PRIVATE}}
+
+\func{bool}{Execute}{\param{const char* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Execute}{\param{const wchar_t* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Execute}{\param{const wxString& }{data}}
Called by the client application to execute a command on the server. Can
also be used to transfer arbitrary data to the server (similar
\membersection{wxDDEConnection::OnAdvise}\label{wxddeconnectiononadvise}
-\func{virtual bool}{OnAdvise}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{char* }{data}, \param{int}{ size}, \param{wxIPCFormat}{ format}}
+\func{virtual bool}{OnAdvise}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format}}
Message sent to the client application when the server notifies it of a
change in the data associated with the given item.
\membersection{wxDDEConnection::OnExecute}\label{wxddeconnectiononexecute}
-\func{virtual bool}{OnExecute}{\param{const wxString\& }{topic}, \param{char* }{data}, \param{int}{ size}, \param{wxIPCFormat}{ format}}
+\func{virtual bool}{OnExecute}{\param{const wxString\& }{topic}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat}{ format}}
Message sent to the server application when the client notifies it to
execute the given data. Note that there is no item associated with
\membersection{wxDDEConnection::OnPoke}\label{wxddeconnectiononpoke}
-\func{virtual bool}{OnPoke}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{char* }{data}, \param{int}{ size}, \param{wxIPCFormat}{ format}}
+\func{virtual bool}{OnPoke}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format}}
Message sent to the server application when the client notifies it to
accept the given data.
\membersection{wxDDEConnection::OnRequest}\label{wxddeconnectiononrequest}
-\func{virtual const char*}{OnRequest}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{int *}{size}, \param{wxIPCFormat}{ format}}
+\func{virtual const void*}{OnRequest}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{size_t * }{size}, \param{wxIPCFormat }{format}}
Message sent to the server application when the client
calls \helpref{wxDDEConnection::Request}{wxddeconnectionrequest}. The server
\membersection{wxDDEConnection::Poke}\label{wxddeconnectionpoke}
-\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{int}{ size = -1}, \param{wxIPCFormat}{ format = wxCF\_TEXT}}
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format = wxIPC\_PRIVATE}}
+
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const wchar_t* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const wxString& }{data}}
Called by the client application to poke data into the server. Can be
used to transfer arbitrary data to the server. Causes the server
\membersection{wxDDEConnection::Request}\label{wxddeconnectionrequest}
-\func{char*}{Request}{\param{const wxString\& }{item}, \param{int *}{size}, \param{wxIPCFormat}{ format = wxIPC\_TEXT}}
+\func{const void*}{Request}{\param{const wxString\& }{item}, \param{size_t *}{size}, \param{wxIPCFormat }{format = wxIPC\_TEXT}}
Called by the client application to request data from the server. Causes
the server connection's \helpref{wxDDEConnection::OnRequest}{wxddeconnectiononrequest} member to be called. Returns a
wxIPC_PENDATA = 10,
wxIPC_RIFF = 11,
wxIPC_WAVE = 12,
- wxIPC_UNICODETEXT = 13,
+ wxIPC_UTF16TEXT = 13, /* CF_UNICODE */
wxIPC_ENHMETAFILE = 14,
wxIPC_FILENAME = 15, /* CF_HDROP */
wxIPC_LOCALE = 16,
+ wxIPC_UTF8TEXT = 17,
+ wxIPC_UTF32TEXT = 18,
+#if SIZEOF_WCHAR_T == 2
+ wxIPC_UNICODETEXT = wxIPC_UTF16TEXT,
+#elif SIZEOF_WCHAR_T == 4
+ wxIPC_UNICODETEXT = wxIPC_UTF32TEXT,
+#endif
wxIPC_PRIVATE = 20
};
\end{verbatim}
\func{}{wxConnection}{\void}
-\func{}{wxConnection}{\param{char* }{buffer}, \param{int}{ size}}
+\func{}{wxConnection}{\param{void* }{buffer}, \param{size_t}{ size}}
Constructs a connection object. If no user-defined connection
object is to be derived from wxConnection, then the constructor
\membersection{wxConnection::Advise}\label{wxconnectionadvise}
-\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{int}{ size = -1}, \param{wxIPCFormat}{ format = wxCF\_TEXT}}
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format = wxIPC\_PRIVATE}}
+
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const wchar_t* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const wxString& }{data}}
Called by the server application to advise the client of a change
in the data associated with the given item. Causes the client
\membersection{wxConnection::Execute}\label{wxconnectionexecute}
-\func{bool}{Execute}{\param{char* }{data}, \param{int}{ size = -1}, \param{wxIPCFormat}{ format = wxCF\_TEXT}}
+\func{bool}{Execute}{\param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format = wxIPC\_PRIVATE}}
+
+\func{bool}{Execute}{\param{const char* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Execute}{\param{const wchar_t* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Execute}{\param{const wxString& }{data}}
Called by the client application to execute a command on the
server. Can also be used to transfer arbitrary data to the server
\membersection{wxConnection::OnAdvise}\label{wxconnectiononadvise}
-\func{virtual bool}{OnAdvise}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{char* }{data}, \param{int}{ size}, \param{wxIPCFormat}{ format}}
+\func{virtual bool}{OnAdvise}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format}}
Message sent to the client application when the server notifies
it of a change in the data associated with the given item, using
\membersection{wxConnection::OnExecute}\label{wxconnectiononexecute}
-\func{virtual bool}{OnExecute}{\param{const wxString\& }{topic}, \param{char* }{data}, \param{int}{ size}, \param{wxIPCFormat}{ format}}
+\func{virtual bool}{OnExecute}{\param{const wxString\& }{topic}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat}{ format}}
Message sent to the server application when the client notifies
it to execute the given data, using \helpref{Execute}{wxconnectionexecute}.
\membersection{wxConnection::OnPoke}\label{wxconnectiononpoke}
-\func{virtual bool}{OnPoke}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{char* }{data}, \param{int}{ size}, \param{wxIPCFormat}{ format}}
+\func{virtual bool}{OnPoke}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format}}
Message sent to the server application when the client notifies it to
accept the given data.
\membersection{wxConnection::OnRequest}\label{wxconnectiononrequest}
-\func{virtual const char*}{OnRequest}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{int *}{size}, \param{wxIPCFormat}{ format}}
+\func{virtual const void*}{OnRequest}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{size_t * }{size}, \param{wxIPCFormat }{format}}
Message sent to the server application when the client calls
\helpref{wxConnection::Request}{wxconnectionrequest}. The
\membersection{wxConnection::Poke}\label{wxconnectionpoke}
-\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{int}{ size = -1}, \param{wxIPCFormat}{ format = wxCF\_TEXT}}
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format = wxIPC\_PRIVATE}}
+
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const wchar_t* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const wxString& }{data}}
Called by the client application to poke data into the server.
Can be used to transfer arbitrary data to the server. Causes the
\membersection{wxConnection::Request}\label{wxconnectionrequest}
-\func{char*}{Request}{\param{const wxString\& }{item}, \param{int *}{size}, \param{wxIPCFormat}{ format = wxIPC\_TEXT}}
+\func{const void*}{Request}{\param{const wxString\& }{item}, \param{size_t *}{size}, \param{wxIPCFormat }{format = wxIPC\_TEXT}}
Called by the client application to request data from the server.
Causes the server connection's \helpref{wxConnection::OnRequest}{wxconnectiononrequest}
wxIPC_PENDATA = 10,
wxIPC_RIFF = 11,
wxIPC_WAVE = 12,
- wxIPC_UNICODETEXT = 13,
+ wxIPC_UTF16TEXT = 13, /* CF_UNICODE */
wxIPC_ENHMETAFILE = 14,
wxIPC_FILENAME = 15, /* CF_HDROP */
wxIPC_LOCALE = 16,
+ wxIPC_UTF8TEXT = 17,
+ wxIPC_UTF32TEXT = 18,
+#if SIZEOF_WCHAR_T == 2
+ wxIPC_UNICODETEXT = wxIPC_UTF16TEXT,
+#elif SIZEOF_WCHAR_T == 4
+ wxIPC_UNICODETEXT = wxIPC_UTF32TEXT,
+#endif
wxIPC_PRIVATE = 20
};
\end{verbatim}
\func{}{wxTCPConnection}{\void}
-\func{}{wxTCPConnection}{\param{char* }{buffer}, \param{int}{ size}}
+\func{}{wxTCPConnection}{\param{void* }{buffer}, \param{size_t}{ size}}
Constructs a connection object. If no user-defined connection object is
to be derived from wxTCPConnection, then the constructor should not be
\membersection{wxTCPConnection::Advise}\label{wxtcpconnectionadvise}
-\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{int}{ size = -1}, \param{wxIPCFormat}{ format = wxCF\_TEXT}}
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format = wxIPC\_PRIVATE}}
+
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const wchar_t* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Advise}{\param{const wxString\& }{item}, \param{const wxString& }{data}}
Called by the server application to advise the client of a change in
the data associated with the given item. Causes the client
\membersection{wxTCPConnection::Execute}\label{wxtcpconnectionexecute}
-\func{bool}{Execute}{\param{char* }{data}, \param{int}{ size = -1}, \param{wxIPCFormat}{ format = wxCF\_TEXT}}
+\func{bool}{Execute}{\param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format = wxIPC\_PRIVATE}}
+
+\func{bool}{Execute}{\param{const char* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Execute}{\param{const wchar_t* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Execute}{\param{const wxString& }{data}}
Called by the client application to execute a command on the server. Can
also be used to transfer arbitrary data to the server (similar
\membersection{wxTCPConnection::OnAdvise}\label{wxtcpconnectiononadvise}
-\func{virtual bool}{OnAdvise}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{char* }{data}, \param{int}{ size}, \param{wxIPCFormat}{ format}}
+\func{virtual bool}{OnAdvise}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format}}
Message sent to the client application when the server notifies it of a
change in the data associated with the given item.
\membersection{wxTCPConnection::OnExecute}\label{wxtcpconnectiononexecute}
-\func{virtual bool}{OnExecute}{\param{const wxString\& }{topic}, \param{char* }{data}, \param{int}{ size}, \param{wxIPCFormat}{ format}}
+\func{virtual bool}{OnExecute}{\param{const wxString\& }{topic}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat}{ format}}
Message sent to the server application when the client notifies it to
execute the given data. Note that there is no item associated with
\membersection{wxTCPConnection::OnPoke}\label{wxtcpconnectiononpoke}
-\func{virtual bool}{OnPoke}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{char* }{data}, \param{int}{ size}, \param{wxIPCFormat}{ format}}
+\func{virtual bool}{OnPoke}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format}}
Message sent to the server application when the client notifies it to
accept the given data.
\membersection{wxTCPConnection::OnRequest}\label{wxtcpconnectiononrequest}
-\func{virtual const char*}{OnRequest}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{int *}{size}, \param{wxIPCFormat}{ format}}
+\func{virtual const void*}{OnRequest}{\param{const wxString\& }{topic}, \param{const wxString\& }{item}, \param{size_t *}{size}, \param{wxIPCFormat }{format}}
Message sent to the server application when the client
calls \helpref{wxTCPConnection::Request}{wxtcpconnectionrequest}. The server
\membersection{wxTCPConnection::Poke}\label{wxtcpconnectionpoke}
-\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{int}{ size = -1}, \param{wxIPCFormat}{ format = wxCF\_TEXT}}
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const void* }{data}, \param{size_t }{size}, \param{wxIPCFormat }{format = wxIPC\_PRIVATE}}
+
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const char* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const wchar_t* }{data}, \param{size_t }{size = (size_t)-1}}
+
+\func{bool}{Poke}{\param{const wxString\& }{item}, \param{const wxString& }{data}}
Called by the client application to poke data into the server. Can be
used to transfer arbitrary data to the server. Causes the server
\membersection{wxTCPConnection::Request}\label{wxtcpconnectionrequest}
-\func{char*}{Request}{\param{const wxString\& }{item}, \param{int *}{size}, \param{wxIPCFormat}{ format = wxIPC\_TEXT}}
+\func{const void*}{Request}{\param{const wxString\& }{item}, \param{size_t *}{size}, \param{wxIPCFormat }{format = wxIPC\_TEXT}}
Called by the client application to request data from the server. Causes
the server connection's \helpref{wxTCPConnection::OnRequest}{wxtcpconnectiononrequest} member to be called. Returns a
wxIPC_PENDATA = 10,
wxIPC_RIFF = 11,
wxIPC_WAVE = 12,
- wxIPC_UNICODETEXT = 13,
+ wxIPC_UTF16TEXT = 13, /* CF_UNICODE */
wxIPC_ENHMETAFILE = 14,
wxIPC_FILENAME = 15, /* CF_HDROP */
wxIPC_LOCALE = 16,
+ wxIPC_UTF8TEXT = 17,
+ wxIPC_UTF32TEXT = 18,
+#if SIZEOF_WCHAR_T == 2
+ wxIPC_UNICODETEXT = wxIPC_UTF16TEXT,
+#elif SIZEOF_WCHAR_T == 4
+ wxIPC_UNICODETEXT = wxIPC_UTF32TEXT,
+#else
+# error "Unknown wchar_t size"
+#endif
wxIPC_PRIVATE = 20
};
class WXDLLIMPEXP_BASE wxConnectionBase: public wxObject
{
- DECLARE_CLASS(wxConnectionBase)
-
public:
- wxConnectionBase(wxChar *buffer, int size); // use external buffer
+ wxConnectionBase(void *buffer, size_t size); // use external buffer
wxConnectionBase(); // use internal, adaptive buffer
wxConnectionBase(const wxConnectionBase& copy);
- virtual ~wxConnectionBase(void);
+ virtual ~wxConnectionBase();
void SetConnected( bool c ) { m_connected = c; }
bool GetConnected() { return m_connected; }
// Calls that CLIENT can make
- virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT ) = 0;
- // FIXME-UTF8: review this code for compatibility implications, update
- // accordingly, don' use c_str() below
- virtual bool Execute(const wxString& str)
- { return Execute(str.c_str(), -1, wxIPC_TEXT); }
- virtual wxChar *Request(const wxString& item, int *size = (int *) NULL, wxIPCFormat format = wxIPC_TEXT) = 0;
- virtual bool Poke(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT) = 0;
+ bool Execute(const void *data, size_t size, wxIPCFormat fmt = wxIPC_PRIVATE)
+ { return DoExecute(data, size, fmt); }
+ bool Execute(const char *s, size_t size = wxNO_LEN)
+ { return DoExecute(s, size == wxNO_LEN ? strlen(s) + 1
+ : size, wxIPC_TEXT); }
+ bool Execute(const wchar_t *ws, size_t size = wxNO_LEN)
+ { return DoExecute(ws, size == wxNO_LEN ? (wcslen(ws) + 1)*sizeof(wchar_t)
+ : size, wxIPC_UNICODETEXT); }
+ bool Execute(const wxString& s)
+ {
+ const wxUTF8Buf buf = s.utf8_str();
+ return DoExecute(buf, strlen(buf) + 1, wxIPC_UTF8TEXT);
+ }
+ bool Execute(const wxCStrData& cs)
+ { return Execute(cs.AsString()); }
+
+ virtual const void *Request(const wxString& item,
+ size_t *size = NULL,
+ wxIPCFormat format = wxIPC_TEXT) = 0;
+
+ bool Poke(const wxString& item, const void *data, size_t size,
+ wxIPCFormat fmt = wxIPC_PRIVATE)
+ { return DoPoke(item, data, size, fmt); }
+ bool Poke(const wxString& item, const char *s, size_t size = wxNO_LEN)
+ { return DoPoke(item, s, size == wxNO_LEN ? strlen(s) + 1
+ : size, wxIPC_TEXT); }
+ bool Poke(const wxString& item, const wchar_t *ws, size_t size = wxNO_LEN)
+ { return DoPoke(item, ws,
+ size == wxNO_LEN ? (wcslen(ws) + 1)*sizeof(wchar_t)
+ : size, wxIPC_UNICODETEXT); }
+ bool Poke(const wxString& item, const wxString s)
+ {
+ const wxUTF8Buf buf = s.utf8_str();
+ return DoPoke(item, buf, strlen(buf) + 1, wxIPC_UTF8TEXT);
+ }
+ bool Poke(const wxString& item, const wxCStrData& cs)
+ { return Poke(item, cs.AsString()); }
+
virtual bool StartAdvise(const wxString& item) = 0;
virtual bool StopAdvise(const wxString& item) = 0;
// Calls that SERVER can make
- virtual bool Advise(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT) = 0;
+ bool Advise(const wxString& item, const void *data, size_t size,
+ wxIPCFormat fmt = wxIPC_PRIVATE)
+ { return DoAdvise(item, data, size, fmt); }
+ bool Advise(const wxString& item, const char *s, size_t size = wxNO_LEN)
+ { return DoAdvise(item, s, size == wxNO_LEN ? strlen(s) + 1
+ : size, wxIPC_TEXT); }
+ bool Advise(const wxString& item, const wchar_t *ws, size_t size = wxNO_LEN)
+ { return DoAdvise(item, ws,
+ size == wxNO_LEN ? (wcslen(ws) + 1)*sizeof(wchar_t)
+ : size, wxIPC_UNICODETEXT); }
+ bool Advise(const wxString& item, const wxString s)
+ {
+ const wxUTF8Buf buf = s.utf8_str();
+ return DoAdvise(item, buf, strlen(buf) + 1, wxIPC_UTF8TEXT);
+ }
+ bool Advise(const wxString& item, const wxCStrData& cs)
+ { return Advise(item, cs.AsString()); }
// Calls that both can make
- virtual bool Disconnect(void) = 0;
+ virtual bool Disconnect() = 0;
+
// Callbacks to SERVER - override at will
- virtual bool OnExecute ( const wxString& WXUNUSED(topic),
- wxChar *WXUNUSED(data),
- int WXUNUSED(size),
- wxIPCFormat WXUNUSED(format) )
- { return false; }
-
- virtual const wxChar *OnRequest ( const wxString& WXUNUSED(topic),
- const wxString& WXUNUSED(item),
- int *WXUNUSED(size),
- wxIPCFormat WXUNUSED(format) )
- { return (wxChar *) NULL; }
-
- virtual bool OnPoke ( const wxString& WXUNUSED(topic),
- const wxString& WXUNUSED(item),
- wxChar *WXUNUSED(data),
- int WXUNUSED(size),
- wxIPCFormat WXUNUSED(format) )
- { return false; }
-
- virtual bool OnStartAdvise ( const wxString& WXUNUSED(topic),
- const wxString& WXUNUSED(item) )
- { return false; }
-
- virtual bool OnStopAdvise ( const wxString& WXUNUSED(topic),
- const wxString& WXUNUSED(item) )
- { return false; }
+ virtual bool OnExecute(const wxString& WXUNUSED(topic),
+ const void *WXUNUSED(data),
+ size_t WXUNUSED(size),
+ wxIPCFormat WXUNUSED(format))
+ { return false; }
+
+ virtual const void *OnRequest(const wxString& WXUNUSED(topic),
+ const wxString& WXUNUSED(item),
+ size_t *size,
+ wxIPCFormat WXUNUSED(format))
+ { *size = 0; return NULL; }
+
+ virtual bool OnPoke(const wxString& WXUNUSED(topic),
+ const wxString& WXUNUSED(item),
+ const void *WXUNUSED(data),
+ size_t WXUNUSED(size),
+ wxIPCFormat WXUNUSED(format))
+ { return false; }
+
+ virtual bool OnStartAdvise(const wxString& WXUNUSED(topic),
+ const wxString& WXUNUSED(item))
+ { return false; }
+
+ virtual bool OnStopAdvise(const wxString& WXUNUSED(topic),
+ const wxString& WXUNUSED(item))
+ { return false; }
// Callbacks to CLIENT - override at will
- virtual bool OnAdvise ( const wxString& WXUNUSED(topic),
- const wxString& WXUNUSED(item),
- wxChar *WXUNUSED(data),
- int WXUNUSED(size),
- wxIPCFormat WXUNUSED(format) )
- { return false; }
+ virtual bool OnAdvise(const wxString& WXUNUSED(topic),
+ const wxString& WXUNUSED(item),
+ const void *WXUNUSED(data),
+ size_t WXUNUSED(size),
+ wxIPCFormat WXUNUSED(format))
+ { return false; }
+
+ // Callbacks to BOTH
+ virtual bool OnDisconnect() { delete this; return true; }
- // Callbacks to BOTH - override at will
- // Default behaviour is to delete connection and return true
- virtual bool OnDisconnect(void) = 0;
// return a buffer at least this size, reallocating buffer if needed
- // returns NULL if using an inadequate user buffer - it can't be resized
- wxChar * GetBufferAtLeast( size_t bytes );
+ // returns NULL if using an inadequate user buffer which can't be resized
+ void *GetBufferAtLeast(size_t bytes);
protected:
- bool m_connected;
+ virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format) = 0;
+ virtual bool DoPoke(const wxString& item, const void *data, size_t size,
+ wxIPCFormat format) = 0;
+ virtual bool DoAdvise(const wxString& item, const void *data, size_t size,
+ wxIPCFormat format) = 0;
+
+
private:
- wxChar * m_buffer;
+ char *m_buffer;
size_t m_buffersize;
bool m_deletebufferwhendone;
- // can't use DECLARE_NO_COPY_CLASS(wxConnectionBase) because we already
- // have copy ctor but still forbid the default assignment operator
- wxConnectionBase& operator=(const wxConnectionBase&);
+protected:
+ bool m_connected;
+
+ DECLARE_NO_ASSIGN_CLASS(wxConnectionBase);
+ DECLARE_CLASS(wxConnectionBase)
};
-class WXDLLIMPEXP_BASE wxServerBase: public wxObject
+class WXDLLIMPEXP_BASE wxServerBase : public wxObject
{
- DECLARE_CLASS(wxServerBase)
-
public:
- inline wxServerBase(void) {}
- inline ~wxServerBase(void) {}
+ wxServerBase() { }
+ virtual ~wxServerBase() { }
// Returns false on error (e.g. port number is already in use)
virtual bool Create(const wxString& serverName) = 0;
// Callbacks to SERVER - override at will
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic) = 0;
+
+ DECLARE_CLASS(wxServerBase)
};
-class WXDLLIMPEXP_BASE wxClientBase: public wxObject
+class WXDLLIMPEXP_BASE wxClientBase : public wxObject
{
- DECLARE_CLASS(wxClientBase)
-
public:
- inline wxClientBase(void) {}
- inline ~wxClientBase(void) {}
+ wxClientBase() { }
+ virtual ~wxClientBase() { }
virtual bool ValidHost(const wxString& host) = 0;
const wxString& topic) = 0;
// Callbacks to CLIENT - override at will
- virtual wxConnectionBase *OnMakeConnection(void) = 0;
+ virtual wxConnectionBase *OnMakeConnection() = 0;
+
+ DECLARE_CLASS(wxClientBase)
};
-#endif
- // _WX_IPCBASEH__
+#endif // _WX_IPCBASEH__
class WXDLLIMPEXP_FWD_BASE wxDDEServer;
class WXDLLIMPEXP_FWD_BASE wxDDEClient;
-class WXDLLIMPEXP_BASE wxDDEConnection: public wxConnectionBase
+class WXDLLIMPEXP_BASE wxDDEConnection : public wxConnectionBase
{
- DECLARE_DYNAMIC_CLASS(wxDDEConnection)
public:
- wxDDEConnection(wxChar *buffer, int size); // use external buffer
+ wxDDEConnection(void *buffer, size_t size); // use external buffer
wxDDEConnection(); // use internal buffer
- virtual ~wxDDEConnection(void);
-
- // Calls that CLIENT can make
- virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
- // FIXME-UTF8: change Execute() to DoExecute() to avoid having to do this;
- // don't use c_str() below after removing ANSI build
- virtual bool Execute(const wxString& str)
- { return Execute(str.c_str(), -1, wxIPC_TEXT); }
- virtual wxChar *Request(const wxString& item, int *size = NULL, wxIPCFormat format = wxIPC_TEXT);
- virtual bool Poke(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
+ virtual ~wxDDEConnection();
+
+ // implement base class pure virtual methods
+ virtual const void *Request(const wxString& item,
+ size_t *size = NULL,
+ wxIPCFormat format = wxIPC_TEXT);
virtual bool StartAdvise(const wxString& item);
virtual bool StopAdvise(const wxString& item);
+ virtual bool Disconnect();
- // Calls that SERVER can make
- virtual bool Advise(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
-
- // Calls that both can make
- virtual bool Disconnect(void);
-
- // Default behaviour is to delete connection and return true
- virtual bool OnDisconnect(void);
+protected:
+ virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format);
+ virtual bool DoPoke(const wxString& item, const void *data, size_t size,
+ wxIPCFormat format);
+ virtual bool DoAdvise(const wxString& item, const void *data, size_t size,
+ wxIPCFormat format);
- public:
+public:
wxString m_topicName;
wxDDEServer* m_server;
wxDDEClient* m_client;
WXHCONV m_hConv;
- const wxChar* m_sendingData;
+ const void* m_sendingData;
int m_dataSize;
wxIPCFormat m_dataType;
- DECLARE_NO_COPY_CLASS(wxDDEConnection)
+ DECLARE_NO_COPY_CLASS(wxDDEConnection)
+ DECLARE_DYNAMIC_CLASS(wxDDEConnection)
};
-class WXDLLIMPEXP_BASE wxDDEServer: public wxServerBase
+class WXDLLIMPEXP_BASE wxDDEServer : public wxServerBase
{
- DECLARE_DYNAMIC_CLASS(wxDDEServer)
- public:
-
- wxDDEServer(void);
- virtual ~wxDDEServer(void);
- bool Create(const wxString& server_name); // Returns false if can't create server (e.g. port
- // number is already in use)
- virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
-
- ////////////////////////////////////////////////////////////
- // Implementation
-
- // Find/delete wxDDEConnection corresponding to the HCONV
- wxDDEConnection *FindConnection(WXHCONV conv);
- bool DeleteConnection(WXHCONV conv);
- inline wxString& GetServiceName(void) const { return (wxString&) m_serviceName; }
- inline wxDDEConnectionList& GetConnections(void) const
- {
- return (wxDDEConnectionList&) m_connections;
- }
+public:
+ wxDDEServer();
+ bool Create(const wxString& server_name);
+ virtual ~wxDDEServer();
+
+ virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
+
+ // Find/delete wxDDEConnection corresponding to the HCONV
+ wxDDEConnection *FindConnection(WXHCONV conv);
+ bool DeleteConnection(WXHCONV conv);
+ wxString& GetServiceName() const { return (wxString&) m_serviceName; }
+
+ wxDDEConnectionList& GetConnections() const
+ { return (wxDDEConnectionList&) m_connections; }
protected:
int m_lastError;
wxString m_serviceName;
wxDDEConnectionList m_connections;
+
+ DECLARE_DYNAMIC_CLASS(wxDDEServer)
};
class WXDLLIMPEXP_BASE wxDDEClient: public wxClientBase
{
- DECLARE_DYNAMIC_CLASS(wxDDEClient)
- public:
- wxDDEClient(void);
- virtual ~wxDDEClient(void);
- bool ValidHost(const wxString& host);
- virtual wxConnectionBase *MakeConnection(const wxString& host, const wxString& server, const wxString& topic);
- // Call this to make a connection.
- // Returns NULL if cannot.
- virtual wxConnectionBase *OnMakeConnection(void); // Tailor this to return own connection.
-
- ////////////////////////////////////////////////////////////
- // Implementation
-
- // Find/delete wxDDEConnection corresponding to the HCONV
- wxDDEConnection *FindConnection(WXHCONV conv);
- bool DeleteConnection(WXHCONV conv);
-
- inline wxDDEConnectionList& GetConnections(void) const
- {
- return (wxDDEConnectionList&) m_connections;
- }
+public:
+ wxDDEClient();
+ virtual ~wxDDEClient();
+
+ bool ValidHost(const wxString& host);
+
+ // Call this to make a connection. Returns NULL if cannot.
+ virtual wxConnectionBase *MakeConnection(const wxString& host,
+ const wxString& server,
+ const wxString& topic);
+
+ // Tailor this to return own connection.
+ virtual wxConnectionBase *OnMakeConnection();
+
+ // Find/delete wxDDEConnection corresponding to the HCONV
+ wxDDEConnection *FindConnection(WXHCONV conv);
+ bool DeleteConnection(WXHCONV conv);
+
+ wxDDEConnectionList& GetConnections() const
+ { return (wxDDEConnectionList&) m_connections; }
protected:
int m_lastError;
wxDDEConnectionList m_connections;
+
+ DECLARE_DYNAMIC_CLASS(wxDDEClient)
};
void WXDLLIMPEXP_BASE wxDDEInitialize();
void WXDLLIMPEXP_BASE wxDDECleanUp();
-#endif
- // _WX_DDE_H_
+#endif // _WX_DDE_H_
class WXDLLIMPEXP_FWD_NET wxTCPServer;
class WXDLLIMPEXP_FWD_NET wxTCPClient;
-class WXDLLIMPEXP_NET wxTCPConnection: public wxConnectionBase
+class WXDLLIMPEXP_NET wxTCPConnection : public wxConnectionBase
{
- DECLARE_DYNAMIC_CLASS(wxTCPConnection)
-
public:
- wxTCPConnection(wxChar *buffer, int size);
+ wxTCPConnection(void *buffer, size_t size);
wxTCPConnection();
virtual ~wxTCPConnection();
- // Calls that CLIENT can make
- virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
- virtual wxChar *Request(const wxString& item, int *size = NULL, wxIPCFormat format = wxIPC_TEXT);
- virtual bool Poke(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
- virtual bool StartAdvise(const wxString& item);
- virtual bool StopAdvise(const wxString& item);
+ // To enable the compressor (NOTE: not implemented!)
+ void Compress(bool on);
- // Calls that SERVER can make
- virtual bool Advise(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
- // Calls that both can make
+ // implement base class pure virtual methods
+ virtual const void *Request(const wxString& item,
+ size_t *size = NULL,
+ wxIPCFormat format = wxIPC_TEXT);
+ virtual bool StartAdvise(const wxString& item);
+ virtual bool StopAdvise(const wxString& item);
virtual bool Disconnect(void);
- // Callbacks to BOTH - override at will
- // Default behaviour is to delete connection and return true
- virtual bool OnDisconnect(void) { delete this; return true; }
-
- // To enable the compressor (NOTE: not implemented!)
- void Compress(bool on);
+protected:
+ virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format);
+ virtual bool DoPoke(const wxString& item, const void *data, size_t size,
+ wxIPCFormat format);
+ virtual bool DoAdvise(const wxString& item, const void *data, size_t size,
+ wxIPCFormat format);
- // unhide the Execute overload from wxConnectionBase
- // FIXME-UTF8: change Execute() to DoExecute() to avoid having to do this;
- // don't use c_str() below after removing ANSI build
- virtual bool Execute(const wxString& str)
- { return Execute(str.c_str(), -1, wxIPC_TEXT); }
-protected:
wxSocketBase *m_sock;
wxSocketStream *m_sockstrm;
wxDataInputStream *m_codeci;
friend class wxTCPEventHandler;
DECLARE_NO_COPY_CLASS(wxTCPConnection)
+ DECLARE_DYNAMIC_CLASS(wxTCPConnection)
};
-class WXDLLIMPEXP_NET wxTCPServer: public wxServerBase
+class WXDLLIMPEXP_NET wxTCPServer : public wxServerBase
{
public:
- wxTCPConnection *topLevelConnection;
-
wxTCPServer();
virtual ~wxTCPServer();
// Returns false on error (e.g. port number is already in use)
virtual bool Create(const wxString& serverName);
- // Callbacks to SERVER - override at will
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
+ wxTCPConnection *topLevelConnection;
+
protected:
wxSocketServer *m_server;
DECLARE_DYNAMIC_CLASS(wxTCPServer)
};
-class WXDLLIMPEXP_NET wxTCPClient: public wxClientBase
+class WXDLLIMPEXP_NET wxTCPClient : public wxClientBase
{
public:
wxTCPClient();
#define TEST_WCHAR
#define TEST_ZIP
#else // #if TEST_ALL
- #define TEST_MIME
+ #define TEST_CMDLINE
#endif
// some tests are interactive, define this to run them
#if wxUSE_CMDLINE_PARSER
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
- { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show this help message"),
+ { wxCMD_LINE_SWITCH, "h", "help", "show this help message",
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
- { wxCMD_LINE_SWITCH, _T("v"), _T("verbose"), _T("be verbose") },
- { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet") },
+ { wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" },
+ { wxCMD_LINE_SWITCH, "q", "quiet", "be quiet" },
- { wxCMD_LINE_OPTION, _T("o"), _T("output"), _T("output file") },
- { wxCMD_LINE_OPTION, _T("i"), _T("input"), _T("input dir") },
- { wxCMD_LINE_OPTION, _T("s"), _T("size"), _T("output block size"),
+ { wxCMD_LINE_OPTION, "o", "output", "output file" },
+ { wxCMD_LINE_OPTION, "i", "input", "input dir" },
+ { wxCMD_LINE_OPTION, "s", "size", "output block size",
wxCMD_LINE_VAL_NUMBER },
- { wxCMD_LINE_OPTION, _T("d"), _T("date"), _T("output file date"),
+ { wxCMD_LINE_OPTION, "d", "date", "output file date",
wxCMD_LINE_VAL_DATE },
- { wxCMD_LINE_PARAM, NULL, NULL, _T("input file"),
+ { wxCMD_LINE_PARAM, NULL, NULL, "input file",
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE },
{ wxCMD_LINE_NONE }
{
wxString s = _T("Date");
- m_client->GetConnection()->Execute((const wxChar *)s.c_str());
- m_client->GetConnection()->Execute((const wxChar *)s.c_str(), (s.Length() + 1) * sizeof(wxChar));
+ m_client->GetConnection()->Execute(s);
+ m_client->GetConnection()->Execute((const char *)s.c_str(), s.length() + 1);
#if wxUSE_DDE_FOR_IPC
wxLogMessage(_T("DDE Execute can only be used to send text strings, not arbitrary data.\nThe type argument will be ignored, text truncated, converted to Unicode and null terminated."));
#endif
char bytes[3];
bytes[0] = '1'; bytes[1] = '2'; bytes[2] = '3';
- m_client->GetConnection()->Execute((wxChar *)bytes, 3, wxIPC_PRIVATE);
+ m_client->GetConnection()->Execute(bytes, 3, wxIPC_PRIVATE);
}
}
if (m_client->IsConnected())
{
wxString s = wxDateTime::Now().Format();
- m_client->GetConnection()->Poke(_T("Date"), (const wxChar *)s.c_str());
+ m_client->GetConnection()->Poke(_T("Date"), s);
s = wxDateTime::Now().FormatTime() + _T(" ") + wxDateTime::Now().FormatDate();
- m_client->GetConnection()->Poke(_T("Date"), (const wxChar *)s.c_str(), (s.Length() + 1) * sizeof(wxChar));
+ m_client->GetConnection()->Poke(_T("Date"), (const char *)s.c_str(), s.length() + 1);
char bytes[3];
bytes[0] = '1'; bytes[1] = '2'; bytes[2] = '3';
- m_client->GetConnection()->Poke(_T("bytes[3]"), (wxChar *)bytes, 3, wxIPC_PRIVATE);
+ m_client->GetConnection()->Poke(_T("bytes[3]"), bytes, 3, wxIPC_PRIVATE);
}
}
{
if (m_client->IsConnected())
{
- int size;
+ size_t size;
m_client->GetConnection()->Request(_T("Date"));
m_client->GetConnection()->Request(_T("Date+len"), &size);
m_client->GetConnection()->Request(_T("bytes[3]"), &size, wxIPC_PRIVATE);
// ----------------------------------------------------------------------------
void MyConnection::Log(const wxString& command, const wxString& topic,
- const wxString& item, const wxChar *data, int size, wxIPCFormat format)
+ const wxString& item, const void *data, size_t size, wxIPCFormat format)
{
wxString s;
if (topic.IsEmpty() && item.IsEmpty())
else
s.Printf(_T("%s(topic=\"%s\",item=\"%s\","), command.c_str(), topic.c_str(), item.c_str());
- if (format == wxIPC_TEXT || format == wxIPC_UNICODETEXT)
- wxLogMessage(_T("%s\"%s\",%d)"), s.c_str(), data, size);
- else if (format == wxIPC_PRIVATE)
+ switch (format)
{
+ case wxIPC_TEXT:
+ case wxIPC_UTF8TEXT:
+#if !wxUSE_UNICODE || wxUSE_UNICODE_UTF8
+ wxLogMessage(_T("%s\"%s\",%d)"), s.c_str(), data, size);
+#else
+ wxLogMessage(_T("%s\"%s\",%d)"), s.c_str(), wxConvUTF8.cMB2WC((const char*)data), size);
+#endif
+ break;
+ case wxIPC_PRIVATE:
if (size == 3)
{
char *bytes = (char *)data;
}
else
wxLogMessage(_T("%s...,%d)"), s.c_str(), size);
- }
- else if (format == wxIPC_INVALID)
+ break;
+ case wxIPC_INVALID:
wxLogMessage(_T("%s[invalid data],%d)"), s.c_str(), size);
+ break;
+ default:
+ wxLogMessage(_T("%s[unknown data],%d)"), s.c_str(), size);
+ break;
+ }
}
-bool MyConnection::OnAdvise(const wxString& topic, const wxString& item, wxChar *data,
- int size, wxIPCFormat format)
+bool MyConnection::OnAdvise(const wxString& topic, const wxString& item, const void *data,
+ size_t size, wxIPCFormat format)
{
Log(_T("OnAdvise"), topic, item, data, size, format);
return true;
return true;
}
-bool MyConnection::Execute(const wxChar *data, int size, wxIPCFormat format)
+bool MyConnection::DoExecute(const void *data, size_t size, wxIPCFormat format)
{
- Log(_T("Execute"), wxEmptyString, wxEmptyString, (wxChar *)data, size, format);
- bool retval = wxConnection::Execute(data, size, format);
+ Log(_T("Execute"), wxEmptyString, wxEmptyString, data, size, format);
+ bool retval = wxConnection::DoExecute(data, size, format);
if (!retval)
wxLogMessage(_T("Execute failed!"));
return retval;
}
-wxChar *MyConnection::Request(const wxString& item, int *size, wxIPCFormat format)
+const void *MyConnection::Request(const wxString& item, size_t *size, wxIPCFormat format)
{
- wxChar *data = wxConnection::Request(item, size, format);
- Log(_T("Request"), wxEmptyString, item, data, size ? *size : -1, format);
+ const void *data = wxConnection::Request(item, size, format);
+ Log(_T("Request"), wxEmptyString, item, data, size ? *size : wxNO_LEN, format);
return data;
}
-bool MyConnection::Poke(const wxString& item, const wxChar *data, int size, wxIPCFormat format)
+bool MyConnection::DoPoke(const wxString& item, const void *data, size_t size, wxIPCFormat format)
{
Log(_T("Poke"), wxEmptyString, item, data, size, format);
- return wxConnection::Poke(item, data, size, format);
+ return wxConnection::DoPoke(item, data, size, format);
}
class MyConnection: public wxConnection
{
public:
- virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
- virtual wxChar *Request(const wxString& item, int *size = NULL, wxIPCFormat format = wxIPC_TEXT);
- virtual bool Poke(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
- virtual bool OnAdvise(const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format);
+ virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format);
+ virtual const void *Request(const wxString& item, size_t *size = NULL, wxIPCFormat format = wxIPC_TEXT);
+ virtual bool DoPoke(const wxString& item, const void* data, size_t size, wxIPCFormat format);
+ virtual bool OnAdvise(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format);
virtual bool OnDisconnect();
protected:
void Log(const wxString& command, const wxString& topic,
- const wxString& item, const wxChar *data, int size, wxIPCFormat format);
+ const wxString& item, const void *data, size_t size, wxIPCFormat format);
};
class MyClient: public wxClient
if (CanAdvise())
{
wxString s = wxDateTime::Now().Format();
- m_connection->Advise(m_connection->m_sAdvise, s.c_str());
+ m_connection->Advise(m_connection->m_sAdvise, s);
s = wxDateTime::Now().FormatTime() + _T(" ") + wxDateTime::Now().FormatDate();
- m_connection->Advise(m_connection->m_sAdvise, s.c_str(), (s.Length() + 1) * sizeof(wxChar));
+ m_connection->Advise(m_connection->m_sAdvise, (const char *)s.c_str(), s.Length() + 1);
#if wxUSE_DDE_FOR_IPC
wxLogMessage(_T("DDE Advise type argument cannot be wxIPC_PRIVATE. The client will receive it as wxIPC_TEXT, and receive the correct no of bytes, but not print a correct log entry."));
#endif
char bytes[3];
bytes[0] = '1'; bytes[1] = '2'; bytes[2] = '3';
- m_connection->Advise(m_connection->m_sAdvise, (wxChar *)bytes, 3, wxIPC_PRIVATE);
+ m_connection->Advise(m_connection->m_sAdvise, bytes, 3, wxIPC_PRIVATE);
// this works, but the log treats it as a string now
-// m_connection->Advise(m_connection->m_sAdvise, (wxChar *)bytes, 3, wxIPC_TEXT );
+// m_connection->Advise(m_connection->m_sAdvise, bytes, 3, wxIPC_TEXT );
}
}
}
bool MyConnection::OnExecute(const wxString& topic,
- wxChar *data, int size, wxIPCFormat format)
+ const void *data, size_t size, wxIPCFormat format)
{
Log(_T("OnExecute"), topic, _T(""), data, size, format);
return true;
}
bool MyConnection::OnPoke(const wxString& topic,
- const wxString& item, wxChar *data, int size, wxIPCFormat format)
+ const wxString& item, const void *data, size_t size, wxIPCFormat format)
{
Log(_T("OnPoke"), topic, item, data, size, format);
return wxConnection::OnPoke(topic, item, data, size, format);
}
-const wxChar *MyConnection::OnRequest(const wxString& topic,
- const wxString& item, int * size, wxIPCFormat format)
+const void *MyConnection::OnRequest(const wxString& topic,
+ const wxString& item, size_t *size, wxIPCFormat format)
{
- const wxChar *data;
+ const void *data;
if (item == _T("Date"))
{
m_sRequestDate = wxDateTime::Now().Format();
data = m_sRequestDate.c_str();
- *size = -1;
+ *size = wxNO_LEN;
}
else if (item == _T("Date+len"))
{
m_sRequestDate = wxDateTime::Now().FormatTime() + _T(" ") + wxDateTime::Now().FormatDate();
data = m_sRequestDate.c_str();
- *size = (m_sRequestDate.Length() + 1) * sizeof(wxChar);
+ *size = m_sRequestDate.Length() + 1;
}
else if (item == _T("bytes[3]"))
{
data = NULL;
*size = 0;
}
- Log(_T("OnRequest"), topic, item, data, *size, format);
+ Log(_T("OnRequest"), topic, item, data, *size, format);
return data;
}
}
void MyConnection::Log(const wxString& command, const wxString& topic,
- const wxString& item, const wxChar *data, int size, wxIPCFormat format)
+ const wxString& item, const void *data, size_t size, wxIPCFormat format)
{
wxString s;
if (topic.IsEmpty() && item.IsEmpty())
else
s.Printf(_T("%s(\"%s\",\"%s\","), command.c_str(), topic.c_str(), item.c_str());
- if (format == wxIPC_TEXT || format == wxIPC_UNICODETEXT)
- wxLogMessage(_T("%s\"%s\",%d)"), s.c_str(), data, size);
- else if (format == wxIPC_PRIVATE)
+ switch (format)
{
+ case wxIPC_TEXT:
+ case wxIPC_UTF8TEXT:
+#if !wxUSE_UNICODE || wxUSE_UNICODE_UTF8
+ wxLogMessage(_T("%s\"%s\",%d)"), s.c_str(), data, size);
+#else
+ wxLogMessage(_T("%s\"%s\",%d)"), s.c_str(), wxConvUTF8.cMB2WC((const char*)data), size);
+#endif
+ break;
+ case wxIPC_PRIVATE:
if (size == 3)
{
char *bytes = (char *)data;
}
else
wxLogMessage(_T("%s...,%d)"), s.c_str(), size);
- }
- else if (format == wxIPC_INVALID)
+ break;
+ case wxIPC_INVALID:
wxLogMessage(_T("%s[invalid data],%d)"), s.c_str(), size);
+ break;
+ default:
+ wxLogMessage(_T("%s[unknown data],%d)"), s.c_str(), size);
+ break;
+ }
}
-bool MyConnection::Advise(const wxString& item, const wxChar *data, int size, wxIPCFormat format)
+bool MyConnection::DoAdvise(const wxString& item, const void *data, size_t size, wxIPCFormat format)
{
Log(_T("Advise"), _T(""), item, data, size, format);
- return wxConnection::Advise(item, data, size, format);
+ return wxConnection::DoAdvise(item, data, size, format);
}
bool MyConnection::OnDisconnect()
MyConnection();
~MyConnection();
- virtual bool OnExecute(const wxString& topic, wxChar *data, int size, wxIPCFormat format);
- virtual const wxChar *OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format);
- virtual bool OnPoke(const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format);
+ virtual bool OnExecute(const wxString& topic, const void *data, size_t size, wxIPCFormat format);
+ virtual const void *OnRequest(const wxString& topic, const wxString& item, size_t *size, wxIPCFormat format);
+ virtual bool OnPoke(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format);
virtual bool OnStartAdvise(const wxString& topic, const wxString& item);
virtual bool OnStopAdvise(const wxString& topic, const wxString& item);
- virtual bool Advise(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT);
+ virtual bool DoAdvise(const wxString& item, const void *data, size_t size, wxIPCFormat format);
virtual bool OnDisconnect();
protected:
- void Log(const wxString& command, const wxString& topic, const wxString& item, const wxChar *data, int size, wxIPCFormat format);
+ void Log(const wxString& command, const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format);
public:
wxString m_sAdvise;
protected:
wxString m_sRequestDate;
- char m_achRequestBytes[3];
+ char m_achRequestBytes[3];
};
class MyServer: public wxServer
IMPLEMENT_CLASS(wxClientBase, wxObject)
IMPLEMENT_CLASS(wxConnectionBase, wxObject)
-wxConnectionBase::wxConnectionBase(wxChar *buffer, int bytes)
- : m_connected(true),
- m_buffer(buffer),
+wxConnectionBase::wxConnectionBase(void *buffer, size_t bytes)
+ : m_buffer((char *)buffer),
m_buffersize(bytes),
- m_deletebufferwhendone(false)
+ m_deletebufferwhendone(false),
+ m_connected(true)
{
- if ( buffer == (wxChar *)NULL )
+ if ( buffer == NULL )
{ // behave like next constructor
m_buffersize = 0;
m_deletebufferwhendone = true;
}
wxConnectionBase::wxConnectionBase()
- : m_connected(true),
- m_buffer(NULL),
+ : m_buffer(NULL),
m_buffersize(0),
- m_deletebufferwhendone(true)
+ m_deletebufferwhendone(true),
+ m_connected(true)
{
}
wxConnectionBase::wxConnectionBase(const wxConnectionBase& copy)
: wxObject(),
- m_connected(copy.m_connected),
m_buffer(copy.m_buffer),
m_buffersize(copy.m_buffersize),
- m_deletebufferwhendone(false)
+ m_deletebufferwhendone(false),
+ m_connected(copy.m_connected)
{
// copy constructor would require ref-counted pointer to buffer
wxConnectionBase::~wxConnectionBase(void)
{
if ( m_deletebufferwhendone && m_buffer )
- delete m_buffer;
+ delete m_buffer;
}
-wxChar *wxConnectionBase::GetBufferAtLeast( size_t bytes )
+void *wxConnectionBase::GetBufferAtLeast( size_t bytes )
{
if ( m_buffersize >= bytes )
return m_buffer;
{ // we're in charge of buffer, increase it
if ( m_buffer )
delete m_buffer;
- // the argument specifies **byte size**, but m_buffer is of type
- // wxChar. Under unicode: sizeof(wxChar) > 1, so the buffer size is
- // bytes / sizeof(wxChar) rounded upwards.
- m_buffer = new wxChar[(bytes + sizeof(wxChar) - 1) / sizeof(wxChar)];
+ m_buffer = new char[bytes];
m_buffersize = bytes;
return m_buffer;
} // user-supplied buffer, fail
m_codeco = NULL;
}
-wxTCPConnection::wxTCPConnection(wxChar *buffer, int size)
+wxTCPConnection::wxTCPConnection(void *buffer, size_t size)
: wxConnectionBase(buffer, size)
{
m_sock = NULL;
return true;
}
-bool wxTCPConnection::Execute(const wxChar *data, int size, wxIPCFormat format)
+bool wxTCPConnection::DoExecute(const void *data, size_t size, wxIPCFormat format)
{
if (!m_sock->IsConnected())
return false;
m_codeco->Write8(IPC_EXECUTE);
m_codeco->Write8(format);
- if (size < 0)
- size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
-
m_codeco->Write32(size);
m_sockstrm->Write(data, size);
return true;
}
-wxChar *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat format)
+const void *wxTCPConnection::Request (const wxString& item, size_t *size, wxIPCFormat format)
{
if (!m_sock->IsConnected())
return NULL;
return NULL;
else
{
- size_t s;
-
- s = m_codeci->Read32();
+ size_t s = m_codeci->Read32();
- wxChar *data = GetBufferAtLeast( s );
+ void *data = GetBufferAtLeast( s );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPConnection::Request") );
m_sockstrm->Read(data, s);
}
}
-bool wxTCPConnection::Poke (const wxString& item, const wxChar *data, int size, wxIPCFormat format)
+bool wxTCPConnection::DoPoke (const wxString& item, const void *data, size_t size, wxIPCFormat format)
{
if (!m_sock->IsConnected())
return false;
m_codeco->WriteString(item);
m_codeco->Write8(format);
- if (size < 0)
- size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
-
m_codeco->Write32(size);
m_sockstrm->Write(data, size);
}
// Calls that SERVER can make
-bool wxTCPConnection::Advise (const wxString& item,
- const wxChar *data, int size, wxIPCFormat format)
+bool wxTCPConnection::DoAdvise (const wxString& item,
+ const void *data, size_t size, wxIPCFormat format)
{
if (!m_sock->IsConnected())
return false;
m_codeco->WriteString(item);
m_codeco->Write8(format);
- if (size < 0)
- size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
-
m_codeco->Write32(size);
m_sockstrm->Write(data, size);
{
case IPC_EXECUTE:
{
- wxChar *data;
+ void *data;
size_t size;
wxIPCFormat format;
}
case IPC_ADVISE:
{
- wxChar *data;
- size_t size;
- wxIPCFormat format;
-
item = codeci->ReadString();
- format = (wxIPCFormat)codeci->Read8();
- size = codeci->Read32();
- data = connection->GetBufferAtLeast( size );
+ wxIPCFormat format = (wxIPCFormat)codeci->Read8();
+ size_t size = codeci->Read32();
+ void *data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size);
}
case IPC_POKE:
{
- wxIPCFormat format;
- size_t size;
- wxChar *data;
-
item = codeci->ReadString();
- format = (wxIPCFormat)codeci->Read8();
- size = codeci->Read32();
- data = connection->GetBufferAtLeast( size );
+ wxIPCFormat format = (wxIPCFormat)codeci->Read8();
+ size_t size = codeci->Read32();
+ void *data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size);
item = codeci->ReadString();
format = (wxIPCFormat)codeci->Read8();
- int user_size = -1;
- const wxChar *user_data = connection->OnRequest (topic_name, item, &user_size, format);
+ size_t user_size = wxNO_LEN;
+ const void *user_data = connection->OnRequest (topic_name, item, &user_size, format);
if (user_data)
{
codeco->Write8(IPC_REQUEST_REPLY);
- if (user_size == -1)
- user_size = (wxStrlen(user_data) + 1) * sizeof(wxChar); // includes final NUL
+ if (user_size == wxNO_LEN)
+ {
+ switch (format)
+ {
+ case wxIPC_TEXT:
+ case wxIPC_UTF8TEXT:
+ user_size = strlen((const char *)user_data) + 1; // includes final NUL
+ break;
+ case wxIPC_UNICODETEXT:
+ user_size = (wcslen((const wchar_t *)user_data) + 1) * sizeof(wchar_t); // includes final NUL
+ break;
+ default:
+ user_size = 0;
+ }
+ }
codeco->Write32(user_size);
sockstrm->Write(user_data, user_size);
// wxDDEConnection
// ----------------------------------------------------------------------------
-wxDDEConnection::wxDDEConnection(wxChar *buffer, int size)
+wxDDEConnection::wxDDEConnection(void *buffer, size_t size)
: wxConnectionBase(buffer, size)
{
m_client = NULL;
return ok;
}
-bool wxDDEConnection::Execute(const wxChar *data, int size, wxIPCFormat WXUNUSED(format))
+bool wxDDEConnection::DoExecute(const void *data, size_t size, wxIPCFormat WXUNUSED(format))
{
DWORD result;
- if (size < 0)
- {
- size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
- }
bool ok = DdeClientTransaction((LPBYTE)data,
size,
return ok;
}
-wxChar *wxDDEConnection::Request(const wxString& item, int *size, wxIPCFormat format)
+const void *wxDDEConnection::Request(const wxString& item, size_t *size, wxIPCFormat format)
{
DWORD result;
DWORD len = DdeGetData(returned_data, NULL, 0, 0);
- wxChar *data = GetBufferAtLeast( len );
+ void *data = GetBufferAtLeast(len);
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxDDEConnection::Request") );
(void) DdeGetData(returned_data, (LPBYTE)data, len, 0);
(void) DdeFreeDataHandle(returned_data);
if (size)
- *size = (int)len;
+ *size = (size_t)len;
return data;
}
-bool wxDDEConnection::Poke(const wxString& item, const wxChar *data, int size, wxIPCFormat format)
+bool wxDDEConnection::DoPoke(const wxString& item, const void *data, size_t size, wxIPCFormat format)
{
DWORD result;
- if (size < 0)
- {
- size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
- }
HSZ item_atom = DDEGetAtom(item);
bool ok = DdeClientTransaction((LPBYTE)data,
}
// Calls that SERVER can make
-bool wxDDEConnection::Advise(const wxString& item,
- const wxChar *data,
- int size,
- wxIPCFormat format)
+bool wxDDEConnection::DoAdvise(const wxString& item,
+ const void *data,
+ size_t size,
+ wxIPCFormat format)
{
- if (size < 0)
- {
- size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
- }
-
HSZ item_atom = DDEGetAtom(item);
HSZ topic_atom = DDEGetAtom(m_topicName);
m_sendingData = data; // mrf: potential for scope problems here?
return ok;
}
-bool wxDDEConnection::OnDisconnect()
-{
- delete this;
- return true;
-}
-
// ----------------------------------------------------------------------------
// _DDECallback
// ----------------------------------------------------------------------------
{
DWORD len = DdeGetData(hData, NULL, 0, 0);
- wxChar *data = connection->GetBufferAtLeast( len );
+ void *data = connection->GetBufferAtLeast(len);
wxASSERT_MSG(data != NULL,
_T("Buffer too small in _DDECallback (XTYP_EXECUTE)") );
{
wxString item_name = DDEStringFromAtom(hsz2);
- int user_size = -1;
- const wxChar *data = connection->OnRequest(connection->m_topicName,
- item_name,
- &user_size,
- (wxIPCFormat)wFmt);
+ size_t user_size = wxNO_LEN;
+ const void *data = connection->OnRequest(connection->m_topicName,
+ item_name,
+ &user_size,
+ (wxIPCFormat)wFmt);
if (data)
{
- if (user_size < 0)
- user_size = (wxStrlen((wxChar*)data) + 1) * sizeof(wxChar); // includes final NUL
+ if (user_size == wxNO_LEN)
+ switch (wFmt)
+ {
+ case wxIPC_TEXT:
+ case wxIPC_UTF8TEXT:
+ user_size = strlen((const char*)data) + 1; // includes final NUL
+ break;
+ case wxIPC_UNICODETEXT:
+ user_size = (wcslen((const wchar_t*)data) + 1) * sizeof(wchar_t); // includes final NUL
+ break;
+ default:
+ user_size = 0;
+ }
HDDEDATA handle = DdeCreateDataHandle(DDEIdInst,
(LPBYTE)data,
DWORD len = DdeGetData(hData, NULL, 0, 0);
- wxChar *data = connection->GetBufferAtLeast( len );
+ void *data = connection->GetBufferAtLeast(len);
wxASSERT_MSG(data != NULL,
_T("Buffer too small in _DDECallback (XTYP_POKE)") );
DWORD len = DdeGetData(hData, NULL, 0, 0);
- wxChar *data = connection->GetBufferAtLeast( len );
+ void *data = connection->GetBufferAtLeast(len);
wxASSERT_MSG(data != NULL,
_T("Buffer too small in _DDECallback (XTYP_ADVDATA)") );