many wxIPC Unicode and UTF-8 fixes (use void* instead of wxChar* in the API and UTF-8 as wire format for wxStrings) (patch 1812926)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49281 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-10-20 22:54:26 +00:00
parent 30386aeb86
commit 50c549b98d
15 changed files with 475 additions and 343 deletions

View File

@@ -32,6 +32,11 @@ changes:
type "const char *", you need to remove wxT() or _T() around the values used type "const char *", you need to remove wxT() or _T() around the values used
to initialize them (which should normally always be ASCII). 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! Changes in behaviour not resulting in compilation errors, please read this!
@@ -143,6 +148,7 @@ Major new features in this release
All: All:
- Allow loading message catalogs from wxFileSystem (Axel Gembe) - 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 support for user-defined types to wxConfig (Marcin Wojdyr).
- Added wxJoin() and wxSplit() functions (Francesco Montorsi). - Added wxJoin() and wxSplit() functions (Francesco Montorsi).
- Added wxMutex::LockTimeout() (Aleksandr Napylov). - Added wxMutex::LockTimeout() (Aleksandr Napylov).

View File

@@ -49,10 +49,17 @@ enum wxIPCFormat
wxIPC_PENDATA = 10, wxIPC_PENDATA = 10,
wxIPC_RIFF = 11, wxIPC_RIFF = 11,
wxIPC_WAVE = 12, wxIPC_WAVE = 12,
wxIPC_UNICODETEXT = 13, wxIPC_UTF16TEXT = 13, /* CF_UNICODE */
wxIPC_ENHMETAFILE = 14, wxIPC_ENHMETAFILE = 14,
wxIPC_FILENAME = 15, /* CF_HDROP */ wxIPC_FILENAME = 15, /* CF_HDROP */
wxIPC_LOCALE = 16, 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 wxIPC_PRIVATE = 20
}; };
\end{verbatim} \end{verbatim}
@@ -67,7 +74,7 @@ enum wxIPCFormat
\func{}{wxDDEConnection}{\void} \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 Constructs a connection object. If no user-defined connection object is
to be derived from wxDDEConnection, then the constructor should not be to be derived from wxDDEConnection, then the constructor should not be
@@ -83,7 +90,13 @@ transactions.
\membersection{wxDDEConnection::Advise}\label{wxddeconnectionadvise} \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 Called by the server application to advise the client of a change in
the data associated with the given item. Causes the client the data associated with the given item. Causes the client
@@ -92,7 +105,13 @@ member to be called. Returns true if successful.
\membersection{wxDDEConnection::Execute}\label{wxddeconnectionexecute} \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 Called by the client application to execute a command on the server. Can
also be used to transfer arbitrary data to the server (similar also be used to transfer arbitrary data to the server (similar
@@ -114,7 +133,7 @@ successful.
\membersection{wxDDEConnection::OnAdvise}\label{wxddeconnectiononadvise} \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 Message sent to the client application when the server notifies it of a
change in the data associated with the given item. change in the data associated with the given item.
@@ -129,7 +148,7 @@ to delete the connection object.
\membersection{wxDDEConnection::OnExecute}\label{wxddeconnectiononexecute} \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 Message sent to the server application when the client notifies it to
execute the given data. Note that there is no item associated with execute the given data. Note that there is no item associated with
@@ -137,14 +156,14 @@ this message.
\membersection{wxDDEConnection::OnPoke}\label{wxddeconnectiononpoke} \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 Message sent to the server application when the client notifies it to
accept the given data. accept the given data.
\membersection{wxDDEConnection::OnRequest}\label{wxddeconnectiononrequest} \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 Message sent to the server application when the client
calls \helpref{wxDDEConnection::Request}{wxddeconnectionrequest}. The server calls \helpref{wxDDEConnection::Request}{wxddeconnectionrequest}. The server
@@ -170,7 +189,13 @@ this doesn't have much meaning in practice.
\membersection{wxDDEConnection::Poke}\label{wxddeconnectionpoke} \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 Called by the client application to poke data into the server. Can be
used to transfer arbitrary data to the server. Causes the server used to transfer arbitrary data to the server. Causes the server
@@ -179,7 +204,7 @@ to be called. Returns true if successful.
\membersection{wxDDEConnection::Request}\label{wxddeconnectionrequest} \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 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 the server connection's \helpref{wxDDEConnection::OnRequest}{wxddeconnectiononrequest} member to be called. Returns a

View File

@@ -44,10 +44,17 @@ enum wxIPCFormat
wxIPC_PENDATA = 10, wxIPC_PENDATA = 10,
wxIPC_RIFF = 11, wxIPC_RIFF = 11,
wxIPC_WAVE = 12, wxIPC_WAVE = 12,
wxIPC_UNICODETEXT = 13, wxIPC_UTF16TEXT = 13, /* CF_UNICODE */
wxIPC_ENHMETAFILE = 14, wxIPC_ENHMETAFILE = 14,
wxIPC_FILENAME = 15, /* CF_HDROP */ wxIPC_FILENAME = 15, /* CF_HDROP */
wxIPC_LOCALE = 16, 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 wxIPC_PRIVATE = 20
}; };
\end{verbatim} \end{verbatim}
@@ -63,7 +70,7 @@ enum wxIPCFormat
\func{}{wxConnection}{\void} \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 Constructs a connection object. If no user-defined connection
object is to be derived from wxConnection, then the constructor object is to be derived from wxConnection, then the constructor
@@ -84,7 +91,13 @@ mainly for backwards compatibility.
\membersection{wxConnection::Advise}\label{wxconnectionadvise} \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 Called by the server application to advise the client of a change
in the data associated with the given item. Causes the client in the data associated with the given item. Causes the client
@@ -93,7 +106,13 @@ to be called. Returns true if successful.
\membersection{wxConnection::Execute}\label{wxconnectionexecute} \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 Called by the client application to execute a command on the
server. Can also be used to transfer arbitrary data to the server server. Can also be used to transfer arbitrary data to the server
@@ -114,7 +133,7 @@ its side of the connection.
\membersection{wxConnection::OnAdvise}\label{wxconnectiononadvise} \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 Message sent to the client application when the server notifies
it of a change in the data associated with the given item, using it of a change in the data associated with the given item, using
@@ -133,7 +152,7 @@ the connection object is no longer available.
\membersection{wxConnection::OnExecute}\label{wxconnectiononexecute} \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 Message sent to the server application when the client notifies
it to execute the given data, using \helpref{Execute}{wxconnectionexecute}. it to execute the given data, using \helpref{Execute}{wxconnectionexecute}.
@@ -141,14 +160,14 @@ Note that there is no item associated with this message.
\membersection{wxConnection::OnPoke}\label{wxconnectiononpoke} \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 Message sent to the server application when the client notifies it to
accept the given data. accept the given data.
\membersection{wxConnection::OnRequest}\label{wxconnectiononrequest} \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 Message sent to the server application when the client calls
\helpref{wxConnection::Request}{wxconnectionrequest}. The \helpref{wxConnection::Request}{wxconnectionrequest}. The
@@ -176,7 +195,13 @@ this doesn't have much meaning in practice.
\membersection{wxConnection::Poke}\label{wxconnectionpoke} \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. Called by the client application to poke data into the server.
Can be used to transfer arbitrary data to the server. Causes the Can be used to transfer arbitrary data to the server. Causes the
@@ -188,7 +213,7 @@ Returns true if successful.
\membersection{wxConnection::Request}\label{wxconnectionrequest} \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. Called by the client application to request data from the server.
Causes the server connection's \helpref{wxConnection::OnRequest}{wxconnectiononrequest} Causes the server connection's \helpref{wxConnection::OnRequest}{wxconnectiononrequest}

View File

@@ -48,10 +48,17 @@ enum wxIPCFormat
wxIPC_PENDATA = 10, wxIPC_PENDATA = 10,
wxIPC_RIFF = 11, wxIPC_RIFF = 11,
wxIPC_WAVE = 12, wxIPC_WAVE = 12,
wxIPC_UNICODETEXT = 13, wxIPC_UTF16TEXT = 13, /* CF_UNICODE */
wxIPC_ENHMETAFILE = 14, wxIPC_ENHMETAFILE = 14,
wxIPC_FILENAME = 15, /* CF_HDROP */ wxIPC_FILENAME = 15, /* CF_HDROP */
wxIPC_LOCALE = 16, 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 wxIPC_PRIVATE = 20
}; };
\end{verbatim} \end{verbatim}
@@ -66,7 +73,7 @@ enum wxIPCFormat
\func{}{wxTCPConnection}{\void} \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 Constructs a connection object. If no user-defined connection object is
to be derived from wxTCPConnection, then the constructor should not be to be derived from wxTCPConnection, then the constructor should not be
@@ -82,7 +89,13 @@ transactions.
\membersection{wxTCPConnection::Advise}\label{wxtcpconnectionadvise} \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 Called by the server application to advise the client of a change in
the data associated with the given item. Causes the client the data associated with the given item. Causes the client
@@ -91,7 +104,13 @@ member to be called. Returns true if successful.
\membersection{wxTCPConnection::Execute}\label{wxtcpconnectionexecute} \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 Called by the client application to execute a command on the server. Can
also be used to transfer arbitrary data to the server (similar also be used to transfer arbitrary data to the server (similar
@@ -113,7 +132,7 @@ successful.
\membersection{wxTCPConnection::OnAdvise}\label{wxtcpconnectiononadvise} \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 Message sent to the client application when the server notifies it of a
change in the data associated with the given item. change in the data associated with the given item.
@@ -128,7 +147,7 @@ to delete the connection object.
\membersection{wxTCPConnection::OnExecute}\label{wxtcpconnectiononexecute} \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 Message sent to the server application when the client notifies it to
execute the given data. Note that there is no item associated with execute the given data. Note that there is no item associated with
@@ -136,14 +155,14 @@ this message.
\membersection{wxTCPConnection::OnPoke}\label{wxtcpconnectiononpoke} \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 Message sent to the server application when the client notifies it to
accept the given data. accept the given data.
\membersection{wxTCPConnection::OnRequest}\label{wxtcpconnectiononrequest} \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 Message sent to the server application when the client
calls \helpref{wxTCPConnection::Request}{wxtcpconnectionrequest}. The server calls \helpref{wxTCPConnection::Request}{wxtcpconnectionrequest}. The server
@@ -169,7 +188,13 @@ this doesn't have much meaning in practice.
\membersection{wxTCPConnection::Poke}\label{wxtcpconnectionpoke} \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 Called by the client application to poke data into the server. Can be
used to transfer arbitrary data to the server. Causes the server used to transfer arbitrary data to the server. Causes the server
@@ -178,7 +203,7 @@ to be called. Returns true if successful.
\membersection{wxTCPConnection::Request}\label{wxtcpconnectionrequest} \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 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 the server connection's \helpref{wxTCPConnection::OnRequest}{wxtcpconnectiononrequest} member to be called. Returns a

View File

@@ -31,10 +31,19 @@ enum wxIPCFormat
wxIPC_PENDATA = 10, wxIPC_PENDATA = 10,
wxIPC_RIFF = 11, wxIPC_RIFF = 11,
wxIPC_WAVE = 12, wxIPC_WAVE = 12,
wxIPC_UNICODETEXT = 13, wxIPC_UTF16TEXT = 13, /* CF_UNICODE */
wxIPC_ENHMETAFILE = 14, wxIPC_ENHMETAFILE = 14,
wxIPC_FILENAME = 15, /* CF_HDROP */ wxIPC_FILENAME = 15, /* CF_HDROP */
wxIPC_LOCALE = 16, 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 wxIPC_PRIVATE = 20
}; };
@@ -43,113 +52,165 @@ class WXDLLIMPEXP_FWD_BASE wxClientBase;
class WXDLLIMPEXP_BASE wxConnectionBase: public wxObject class WXDLLIMPEXP_BASE wxConnectionBase: public wxObject
{ {
DECLARE_CLASS(wxConnectionBase)
public: public:
wxConnectionBase(wxChar *buffer, int size); // use external buffer wxConnectionBase(void *buffer, size_t size); // use external buffer
wxConnectionBase(); // use internal, adaptive buffer wxConnectionBase(); // use internal, adaptive buffer
wxConnectionBase(const wxConnectionBase& copy); wxConnectionBase(const wxConnectionBase& copy);
virtual ~wxConnectionBase(void); virtual ~wxConnectionBase();
void SetConnected( bool c ) { m_connected = c; } void SetConnected( bool c ) { m_connected = c; }
bool GetConnected() { return m_connected; } bool GetConnected() { return m_connected; }
// Calls that CLIENT can make // Calls that CLIENT can make
virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT ) = 0; bool Execute(const void *data, size_t size, wxIPCFormat fmt = wxIPC_PRIVATE)
// FIXME-UTF8: review this code for compatibility implications, update { return DoExecute(data, size, fmt); }
// accordingly, don' use c_str() below bool Execute(const char *s, size_t size = wxNO_LEN)
virtual bool Execute(const wxString& str) { return DoExecute(s, size == wxNO_LEN ? strlen(s) + 1
{ return Execute(str.c_str(), -1, wxIPC_TEXT); } : size, wxIPC_TEXT); }
virtual wxChar *Request(const wxString& item, int *size = (int *) NULL, wxIPCFormat format = wxIPC_TEXT) = 0; bool Execute(const wchar_t *ws, size_t size = wxNO_LEN)
virtual bool Poke(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT) = 0; { 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 StartAdvise(const wxString& item) = 0;
virtual bool StopAdvise(const wxString& item) = 0; virtual bool StopAdvise(const wxString& item) = 0;
// Calls that SERVER can make // 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 // Calls that both can make
virtual bool Disconnect(void) = 0; virtual bool Disconnect() = 0;
// Callbacks to SERVER - override at will // Callbacks to SERVER - override at will
virtual bool OnExecute ( const wxString& WXUNUSED(topic), virtual bool OnExecute(const wxString& WXUNUSED(topic),
wxChar *WXUNUSED(data), const void *WXUNUSED(data),
int WXUNUSED(size), size_t WXUNUSED(size),
wxIPCFormat WXUNUSED(format) ) wxIPCFormat WXUNUSED(format))
{ return false; } { return false; }
virtual const wxChar *OnRequest ( const wxString& WXUNUSED(topic), virtual const void *OnRequest(const wxString& WXUNUSED(topic),
const wxString& WXUNUSED(item), const wxString& WXUNUSED(item),
int *WXUNUSED(size), size_t *size,
wxIPCFormat WXUNUSED(format) ) wxIPCFormat WXUNUSED(format))
{ return (wxChar *) NULL; } { *size = 0; return NULL; }
virtual bool OnPoke ( const wxString& WXUNUSED(topic), virtual bool OnPoke(const wxString& WXUNUSED(topic),
const wxString& WXUNUSED(item), const wxString& WXUNUSED(item),
wxChar *WXUNUSED(data), const void *WXUNUSED(data),
int WXUNUSED(size), size_t WXUNUSED(size),
wxIPCFormat WXUNUSED(format) ) wxIPCFormat WXUNUSED(format))
{ return false; } { return false; }
virtual bool OnStartAdvise ( const wxString& WXUNUSED(topic), virtual bool OnStartAdvise(const wxString& WXUNUSED(topic),
const wxString& WXUNUSED(item) ) const wxString& WXUNUSED(item))
{ return false; } { return false; }
virtual bool OnStopAdvise ( const wxString& WXUNUSED(topic), virtual bool OnStopAdvise(const wxString& WXUNUSED(topic),
const wxString& WXUNUSED(item) ) const wxString& WXUNUSED(item))
{ return false; } { return false; }
// Callbacks to CLIENT - override at will // Callbacks to CLIENT - override at will
virtual bool OnAdvise ( const wxString& WXUNUSED(topic), virtual bool OnAdvise(const wxString& WXUNUSED(topic),
const wxString& WXUNUSED(item), const wxString& WXUNUSED(item),
wxChar *WXUNUSED(data), const void *WXUNUSED(data),
int WXUNUSED(size), size_t WXUNUSED(size),
wxIPCFormat WXUNUSED(format) ) wxIPCFormat WXUNUSED(format))
{ return false; } { 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 // return a buffer at least this size, reallocating buffer if needed
// returns NULL if using an inadequate user buffer - it can't be resized // returns NULL if using an inadequate user buffer which can't be resized
wxChar * GetBufferAtLeast( size_t bytes ); void *GetBufferAtLeast(size_t bytes);
protected: 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: private:
wxChar * m_buffer; char *m_buffer;
size_t m_buffersize; size_t m_buffersize;
bool m_deletebufferwhendone; bool m_deletebufferwhendone;
// can't use DECLARE_NO_COPY_CLASS(wxConnectionBase) because we already protected:
// have copy ctor but still forbid the default assignment operator bool m_connected;
wxConnectionBase& operator=(const wxConnectionBase&);
DECLARE_NO_ASSIGN_CLASS(wxConnectionBase);
DECLARE_CLASS(wxConnectionBase)
}; };
class WXDLLIMPEXP_BASE wxServerBase: public wxObject class WXDLLIMPEXP_BASE wxServerBase : public wxObject
{ {
DECLARE_CLASS(wxServerBase)
public: public:
inline wxServerBase(void) {} wxServerBase() { }
inline ~wxServerBase(void) {} virtual ~wxServerBase() { }
// Returns false on error (e.g. port number is already in use) // Returns false on error (e.g. port number is already in use)
virtual bool Create(const wxString& serverName) = 0; virtual bool Create(const wxString& serverName) = 0;
// Callbacks to SERVER - override at will // Callbacks to SERVER - override at will
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic) = 0; 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: public:
inline wxClientBase(void) {} wxClientBase() { }
inline ~wxClientBase(void) {} virtual ~wxClientBase() { }
virtual bool ValidHost(const wxString& host) = 0; virtual bool ValidHost(const wxString& host) = 0;
@@ -159,8 +220,9 @@ public:
const wxString& topic) = 0; const wxString& topic) = 0;
// Callbacks to CLIENT - override at will // Callbacks to CLIENT - override at will
virtual wxConnectionBase *OnMakeConnection(void) = 0; virtual wxConnectionBase *OnMakeConnection() = 0;
DECLARE_CLASS(wxClientBase)
}; };
#endif #endif // _WX_IPCBASEH__
// _WX_IPCBASEH__

View File

@@ -41,107 +41,98 @@
class WXDLLIMPEXP_FWD_BASE wxDDEServer; class WXDLLIMPEXP_FWD_BASE wxDDEServer;
class WXDLLIMPEXP_FWD_BASE wxDDEClient; class WXDLLIMPEXP_FWD_BASE wxDDEClient;
class WXDLLIMPEXP_BASE wxDDEConnection: public wxConnectionBase class WXDLLIMPEXP_BASE wxDDEConnection : public wxConnectionBase
{ {
DECLARE_DYNAMIC_CLASS(wxDDEConnection)
public: public:
wxDDEConnection(wxChar *buffer, int size); // use external buffer wxDDEConnection(void *buffer, size_t size); // use external buffer
wxDDEConnection(); // use internal buffer wxDDEConnection(); // use internal buffer
virtual ~wxDDEConnection(void); virtual ~wxDDEConnection();
// Calls that CLIENT can make // implement base class pure virtual methods
virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT); virtual const void *Request(const wxString& item,
// FIXME-UTF8: change Execute() to DoExecute() to avoid having to do this; size_t *size = NULL,
// don't use c_str() below after removing ANSI build wxIPCFormat format = wxIPC_TEXT);
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 bool StartAdvise(const wxString& item); virtual bool StartAdvise(const wxString& item);
virtual bool StopAdvise(const wxString& item); virtual bool StopAdvise(const wxString& item);
virtual bool Disconnect();
// Calls that SERVER can make protected:
virtual bool Advise(const wxString& item, const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT); 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);
// Calls that both can make public:
virtual bool Disconnect(void);
// Default behaviour is to delete connection and return true
virtual bool OnDisconnect(void);
public:
wxString m_topicName; wxString m_topicName;
wxDDEServer* m_server; wxDDEServer* m_server;
wxDDEClient* m_client; wxDDEClient* m_client;
WXHCONV m_hConv; WXHCONV m_hConv;
const wxChar* m_sendingData; const void* m_sendingData;
int m_dataSize; int m_dataSize;
wxIPCFormat m_dataType; 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:
public: wxDDEServer();
bool Create(const wxString& server_name);
virtual ~wxDDEServer();
wxDDEServer(void); virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
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);
//////////////////////////////////////////////////////////// // Find/delete wxDDEConnection corresponding to the HCONV
// Implementation wxDDEConnection *FindConnection(WXHCONV conv);
bool DeleteConnection(WXHCONV conv);
wxString& GetServiceName() const { return (wxString&) m_serviceName; }
// Find/delete wxDDEConnection corresponding to the HCONV wxDDEConnectionList& GetConnections() const
wxDDEConnection *FindConnection(WXHCONV conv); { return (wxDDEConnectionList&) m_connections; }
bool DeleteConnection(WXHCONV conv);
inline wxString& GetServiceName(void) const { return (wxString&) m_serviceName; }
inline wxDDEConnectionList& GetConnections(void) const
{
return (wxDDEConnectionList&) m_connections;
}
protected: protected:
int m_lastError; int m_lastError;
wxString m_serviceName; wxString m_serviceName;
wxDDEConnectionList m_connections; wxDDEConnectionList m_connections;
DECLARE_DYNAMIC_CLASS(wxDDEServer)
}; };
class WXDLLIMPEXP_BASE wxDDEClient: public wxClientBase class WXDLLIMPEXP_BASE wxDDEClient: public wxClientBase
{ {
DECLARE_DYNAMIC_CLASS(wxDDEClient) public:
public: wxDDEClient();
wxDDEClient(void); virtual ~wxDDEClient();
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.
//////////////////////////////////////////////////////////// bool ValidHost(const wxString& host);
// Implementation
// Find/delete wxDDEConnection corresponding to the HCONV // Call this to make a connection. Returns NULL if cannot.
wxDDEConnection *FindConnection(WXHCONV conv); virtual wxConnectionBase *MakeConnection(const wxString& host,
bool DeleteConnection(WXHCONV conv); const wxString& server,
const wxString& topic);
inline wxDDEConnectionList& GetConnections(void) const // Tailor this to return own connection.
{ virtual wxConnectionBase *OnMakeConnection();
return (wxDDEConnectionList&) m_connections;
} // Find/delete wxDDEConnection corresponding to the HCONV
wxDDEConnection *FindConnection(WXHCONV conv);
bool DeleteConnection(WXHCONV conv);
wxDDEConnectionList& GetConnections() const
{ return (wxDDEConnectionList&) m_connections; }
protected: protected:
int m_lastError; int m_lastError;
wxDDEConnectionList m_connections; wxDDEConnectionList m_connections;
DECLARE_DYNAMIC_CLASS(wxDDEClient)
}; };
void WXDLLIMPEXP_BASE wxDDEInitialize(); void WXDLLIMPEXP_BASE wxDDEInitialize();
void WXDLLIMPEXP_BASE wxDDECleanUp(); void WXDLLIMPEXP_BASE wxDDECleanUp();
#endif #endif // _WX_DDE_H_
// _WX_DDE_H_

View File

@@ -52,42 +52,33 @@
class WXDLLIMPEXP_FWD_NET wxTCPServer; class WXDLLIMPEXP_FWD_NET wxTCPServer;
class WXDLLIMPEXP_FWD_NET wxTCPClient; class WXDLLIMPEXP_FWD_NET wxTCPClient;
class WXDLLIMPEXP_NET wxTCPConnection: public wxConnectionBase class WXDLLIMPEXP_NET wxTCPConnection : public wxConnectionBase
{ {
DECLARE_DYNAMIC_CLASS(wxTCPConnection)
public: public:
wxTCPConnection(wxChar *buffer, int size); wxTCPConnection(void *buffer, size_t size);
wxTCPConnection(); wxTCPConnection();
virtual ~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);
// 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);
// 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!) // To enable the compressor (NOTE: not implemented!)
void Compress(bool on); void Compress(bool on);
// unhide the Execute overload from wxConnectionBase
// FIXME-UTF8: change Execute() to DoExecute() to avoid having to do this; // implement base class pure virtual methods
// don't use c_str() below after removing ANSI build virtual const void *Request(const wxString& item,
virtual bool Execute(const wxString& str) size_t *size = NULL,
{ return Execute(str.c_str(), -1, wxIPC_TEXT); } wxIPCFormat format = wxIPC_TEXT);
virtual bool StartAdvise(const wxString& item);
virtual bool StopAdvise(const wxString& item);
virtual bool Disconnect(void);
protected: 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);
wxSocketBase *m_sock; wxSocketBase *m_sock;
wxSocketStream *m_sockstrm; wxSocketStream *m_sockstrm;
wxDataInputStream *m_codeci; wxDataInputStream *m_codeci;
@@ -99,22 +90,22 @@ protected:
friend class wxTCPEventHandler; friend class wxTCPEventHandler;
DECLARE_NO_COPY_CLASS(wxTCPConnection) DECLARE_NO_COPY_CLASS(wxTCPConnection)
DECLARE_DYNAMIC_CLASS(wxTCPConnection)
}; };
class WXDLLIMPEXP_NET wxTCPServer: public wxServerBase class WXDLLIMPEXP_NET wxTCPServer : public wxServerBase
{ {
public: public:
wxTCPConnection *topLevelConnection;
wxTCPServer(); wxTCPServer();
virtual ~wxTCPServer(); virtual ~wxTCPServer();
// Returns false on error (e.g. port number is already in use) // Returns false on error (e.g. port number is already in use)
virtual bool Create(const wxString& serverName); virtual bool Create(const wxString& serverName);
// Callbacks to SERVER - override at will
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic); virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
wxTCPConnection *topLevelConnection;
protected: protected:
wxSocketServer *m_server; wxSocketServer *m_server;
@@ -127,7 +118,7 @@ protected:
DECLARE_DYNAMIC_CLASS(wxTCPServer) DECLARE_DYNAMIC_CLASS(wxTCPServer)
}; };
class WXDLLIMPEXP_NET wxTCPClient: public wxClientBase class WXDLLIMPEXP_NET wxTCPClient : public wxClientBase
{ {
public: public:
wxTCPClient(); wxTCPClient();

View File

@@ -89,7 +89,7 @@
#define TEST_WCHAR #define TEST_WCHAR
#define TEST_ZIP #define TEST_ZIP
#else // #if TEST_ALL #else // #if TEST_ALL
#define TEST_MIME #define TEST_CMDLINE
#endif #endif
// some tests are interactive, define this to run them // some tests are interactive, define this to run them
@@ -4273,19 +4273,19 @@ int main(int argc, char **argv)
#if wxUSE_CMDLINE_PARSER #if wxUSE_CMDLINE_PARSER
static const wxCmdLineEntryDesc cmdLineDesc[] = 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_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_SWITCH, _T("v"), _T("verbose"), _T("be verbose") }, { wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" },
{ wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet") }, { wxCMD_LINE_SWITCH, "q", "quiet", "be quiet" },
{ wxCMD_LINE_OPTION, _T("o"), _T("output"), _T("output file") }, { wxCMD_LINE_OPTION, "o", "output", "output file" },
{ wxCMD_LINE_OPTION, _T("i"), _T("input"), _T("input dir") }, { wxCMD_LINE_OPTION, "i", "input", "input dir" },
{ wxCMD_LINE_OPTION, _T("s"), _T("size"), _T("output block size"), { wxCMD_LINE_OPTION, "s", "size", "output block size",
wxCMD_LINE_VAL_NUMBER }, 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_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_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE },
{ wxCMD_LINE_NONE } { wxCMD_LINE_NONE }

View File

@@ -337,14 +337,14 @@ void MyFrame::OnExecute(wxCommandEvent& WXUNUSED(event))
{ {
wxString s = _T("Date"); wxString s = _T("Date");
m_client->GetConnection()->Execute((const wxChar *)s.c_str()); m_client->GetConnection()->Execute(s);
m_client->GetConnection()->Execute((const wxChar *)s.c_str(), (s.Length() + 1) * sizeof(wxChar)); m_client->GetConnection()->Execute((const char *)s.c_str(), s.length() + 1);
#if wxUSE_DDE_FOR_IPC #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.")); 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 #endif
char bytes[3]; char bytes[3];
bytes[0] = '1'; bytes[1] = '2'; bytes[2] = '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);
} }
} }
@@ -353,12 +353,12 @@ void MyFrame::OnPoke(wxCommandEvent& WXUNUSED(event))
if (m_client->IsConnected()) if (m_client->IsConnected())
{ {
wxString s = wxDateTime::Now().Format(); 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(); 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]; char bytes[3];
bytes[0] = '1'; bytes[1] = '2'; bytes[2] = '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);
} }
} }
@@ -366,7 +366,7 @@ void MyFrame::OnRequest(wxCommandEvent& WXUNUSED(event))
{ {
if (m_client->IsConnected()) if (m_client->IsConnected())
{ {
int size; size_t size;
m_client->GetConnection()->Request(_T("Date")); m_client->GetConnection()->Request(_T("Date"));
m_client->GetConnection()->Request(_T("Date+len"), &size); m_client->GetConnection()->Request(_T("Date+len"), &size);
m_client->GetConnection()->Request(_T("bytes[3]"), &size, wxIPC_PRIVATE); m_client->GetConnection()->Request(_T("bytes[3]"), &size, wxIPC_PRIVATE);
@@ -417,7 +417,7 @@ MyClient::~MyClient()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void MyConnection::Log(const wxString& command, const wxString& topic, 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; wxString s;
if (topic.IsEmpty() && item.IsEmpty()) if (topic.IsEmpty() && item.IsEmpty())
@@ -429,10 +429,17 @@ void MyConnection::Log(const wxString& command, const wxString& topic,
else else
s.Printf(_T("%s(topic=\"%s\",item=\"%s\","), command.c_str(), topic.c_str(), item.c_str()); s.Printf(_T("%s(topic=\"%s\",item=\"%s\","), command.c_str(), topic.c_str(), item.c_str());
if (format == wxIPC_TEXT || format == wxIPC_UNICODETEXT) switch (format)
wxLogMessage(_T("%s\"%s\",%d)"), s.c_str(), data, size);
else if (format == wxIPC_PRIVATE)
{ {
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) if (size == 3)
{ {
char *bytes = (char *)data; char *bytes = (char *)data;
@@ -440,13 +447,18 @@ void MyConnection::Log(const wxString& command, const wxString& topic,
} }
else else
wxLogMessage(_T("%s...,%d)"), s.c_str(), size); wxLogMessage(_T("%s...,%d)"), s.c_str(), size);
} break;
else if (format == wxIPC_INVALID) case wxIPC_INVALID:
wxLogMessage(_T("%s[invalid data],%d)"), s.c_str(), size); 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, bool MyConnection::OnAdvise(const wxString& topic, const wxString& item, const void *data,
int size, wxIPCFormat format) size_t size, wxIPCFormat format)
{ {
Log(_T("OnAdvise"), topic, item, data, size, format); Log(_T("OnAdvise"), topic, item, data, size, format);
return true; return true;
@@ -459,24 +471,24 @@ bool MyConnection::OnDisconnect()
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); Log(_T("Execute"), wxEmptyString, wxEmptyString, data, size, format);
bool retval = wxConnection::Execute(data, size, format); bool retval = wxConnection::DoExecute(data, size, format);
if (!retval) if (!retval)
wxLogMessage(_T("Execute failed!")); wxLogMessage(_T("Execute failed!"));
return retval; 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); const void *data = wxConnection::Request(item, size, format);
Log(_T("Request"), wxEmptyString, item, data, size ? *size : -1, format); Log(_T("Request"), wxEmptyString, item, data, size ? *size : wxNO_LEN, format);
return data; 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); Log(_T("Poke"), wxEmptyString, item, data, size, format);
return wxConnection::Poke(item, data, size, format); return wxConnection::DoPoke(item, data, size, format);
} }

View File

@@ -81,14 +81,14 @@ protected:
class MyConnection: public wxConnection class MyConnection: public wxConnection
{ {
public: public:
virtual bool Execute(const wxChar *data, int size = -1, wxIPCFormat format = wxIPC_TEXT); virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format);
virtual wxChar *Request(const wxString& item, int *size = NULL, wxIPCFormat format = wxIPC_TEXT); virtual const void *Request(const wxString& item, size_t *size = NULL, wxIPCFormat format = wxIPC_TEXT);
virtual bool Poke(const wxString& item, const wxChar *data, int size = -1, 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, wxChar *data, int size, wxIPCFormat format); virtual bool OnAdvise(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format);
virtual bool OnDisconnect(); virtual bool OnDisconnect();
protected: protected:
void Log(const wxString& command, const wxString& topic, 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 class MyClient: public wxClient

View File

@@ -285,18 +285,18 @@ void MyServer::Advise()
if (CanAdvise()) if (CanAdvise())
{ {
wxString s = wxDateTime::Now().Format(); 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(); 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 #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.")); 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 #endif
char bytes[3]; char bytes[3];
bytes[0] = '1'; bytes[1] = '2'; bytes[2] = '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 // 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 );
} }
} }
@@ -314,34 +314,34 @@ MyConnection::~MyConnection()
} }
bool MyConnection::OnExecute(const wxString& topic, 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); Log(_T("OnExecute"), topic, _T(""), data, size, format);
return true; return true;
} }
bool MyConnection::OnPoke(const wxString& topic, 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); Log(_T("OnPoke"), topic, item, data, size, format);
return wxConnection::OnPoke(topic, item, data, size, format); return wxConnection::OnPoke(topic, item, data, size, format);
} }
const wxChar *MyConnection::OnRequest(const wxString& topic, const void *MyConnection::OnRequest(const wxString& topic,
const wxString& item, int * size, wxIPCFormat format) const wxString& item, size_t *size, wxIPCFormat format)
{ {
const wxChar *data; const void *data;
if (item == _T("Date")) if (item == _T("Date"))
{ {
m_sRequestDate = wxDateTime::Now().Format(); m_sRequestDate = wxDateTime::Now().Format();
data = m_sRequestDate.c_str(); data = m_sRequestDate.c_str();
*size = -1; *size = wxNO_LEN;
} }
else if (item == _T("Date+len")) else if (item == _T("Date+len"))
{ {
m_sRequestDate = wxDateTime::Now().FormatTime() + _T(" ") + wxDateTime::Now().FormatDate(); m_sRequestDate = wxDateTime::Now().FormatTime() + _T(" ") + wxDateTime::Now().FormatDate();
data = m_sRequestDate.c_str(); data = m_sRequestDate.c_str();
*size = (m_sRequestDate.Length() + 1) * sizeof(wxChar); *size = m_sRequestDate.Length() + 1;
} }
else if (item == _T("bytes[3]")) else if (item == _T("bytes[3]"))
{ {
@@ -354,7 +354,7 @@ const wxChar *MyConnection::OnRequest(const wxString& topic,
data = NULL; data = NULL;
*size = 0; *size = 0;
} }
Log(_T("OnRequest"), topic, item, data, *size, format); Log(_T("OnRequest"), topic, item, data, *size, format);
return data; return data;
} }
@@ -379,7 +379,7 @@ bool MyConnection::OnStopAdvise(const wxString& topic,
} }
void MyConnection::Log(const wxString& command, const wxString& topic, 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; wxString s;
if (topic.IsEmpty() && item.IsEmpty()) if (topic.IsEmpty() && item.IsEmpty())
@@ -391,10 +391,17 @@ void MyConnection::Log(const wxString& command, const wxString& topic,
else else
s.Printf(_T("%s(\"%s\",\"%s\","), command.c_str(), topic.c_str(), item.c_str()); s.Printf(_T("%s(\"%s\",\"%s\","), command.c_str(), topic.c_str(), item.c_str());
if (format == wxIPC_TEXT || format == wxIPC_UNICODETEXT) switch (format)
wxLogMessage(_T("%s\"%s\",%d)"), s.c_str(), data, size);
else if (format == wxIPC_PRIVATE)
{ {
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) if (size == 3)
{ {
char *bytes = (char *)data; char *bytes = (char *)data;
@@ -402,15 +409,20 @@ void MyConnection::Log(const wxString& command, const wxString& topic,
} }
else else
wxLogMessage(_T("%s...,%d)"), s.c_str(), size); wxLogMessage(_T("%s...,%d)"), s.c_str(), size);
} break;
else if (format == wxIPC_INVALID) case wxIPC_INVALID:
wxLogMessage(_T("%s[invalid data],%d)"), s.c_str(), size); 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); 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() bool MyConnection::OnDisconnect()

View File

@@ -69,20 +69,20 @@ public:
MyConnection(); MyConnection();
~MyConnection(); ~MyConnection();
virtual bool OnExecute(const wxString& topic, wxChar *data, int size, wxIPCFormat format); virtual bool OnExecute(const wxString& topic, const void *data, size_t size, wxIPCFormat format);
virtual const wxChar *OnRequest(const wxString& topic, const wxString& item, int *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, wxChar *data, int 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 OnStartAdvise(const wxString& topic, const wxString& item);
virtual bool OnStopAdvise(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(); virtual bool OnDisconnect();
protected: 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: public:
wxString m_sAdvise; wxString m_sAdvise;
protected: protected:
wxString m_sRequestDate; wxString m_sRequestDate;
char m_achRequestBytes[3]; char m_achRequestBytes[3];
}; };
class MyServer: public wxServer class MyServer: public wxServer

View File

@@ -25,13 +25,13 @@ IMPLEMENT_CLASS(wxServerBase, wxObject)
IMPLEMENT_CLASS(wxClientBase, wxObject) IMPLEMENT_CLASS(wxClientBase, wxObject)
IMPLEMENT_CLASS(wxConnectionBase, wxObject) IMPLEMENT_CLASS(wxConnectionBase, wxObject)
wxConnectionBase::wxConnectionBase(wxChar *buffer, int bytes) wxConnectionBase::wxConnectionBase(void *buffer, size_t bytes)
: m_connected(true), : m_buffer((char *)buffer),
m_buffer(buffer),
m_buffersize(bytes), m_buffersize(bytes),
m_deletebufferwhendone(false) m_deletebufferwhendone(false),
m_connected(true)
{ {
if ( buffer == (wxChar *)NULL ) if ( buffer == NULL )
{ // behave like next constructor { // behave like next constructor
m_buffersize = 0; m_buffersize = 0;
m_deletebufferwhendone = true; m_deletebufferwhendone = true;
@@ -39,19 +39,19 @@ wxConnectionBase::wxConnectionBase(wxChar *buffer, int bytes)
} }
wxConnectionBase::wxConnectionBase() wxConnectionBase::wxConnectionBase()
: m_connected(true), : m_buffer(NULL),
m_buffer(NULL),
m_buffersize(0), m_buffersize(0),
m_deletebufferwhendone(true) m_deletebufferwhendone(true),
m_connected(true)
{ {
} }
wxConnectionBase::wxConnectionBase(const wxConnectionBase& copy) wxConnectionBase::wxConnectionBase(const wxConnectionBase& copy)
: wxObject(), : wxObject(),
m_connected(copy.m_connected),
m_buffer(copy.m_buffer), m_buffer(copy.m_buffer),
m_buffersize(copy.m_buffersize), 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 // copy constructor would require ref-counted pointer to buffer
@@ -62,10 +62,10 @@ wxConnectionBase::wxConnectionBase(const wxConnectionBase& copy)
wxConnectionBase::~wxConnectionBase(void) wxConnectionBase::~wxConnectionBase(void)
{ {
if ( m_deletebufferwhendone && m_buffer ) 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 ) if ( m_buffersize >= bytes )
return m_buffer; return m_buffer;
@@ -75,10 +75,7 @@ wxChar *wxConnectionBase::GetBufferAtLeast( size_t bytes )
{ // we're in charge of buffer, increase it { // we're in charge of buffer, increase it
if ( m_buffer ) if ( m_buffer )
delete m_buffer; delete m_buffer;
// the argument specifies **byte size**, but m_buffer is of type m_buffer = new char[bytes];
// 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_buffersize = bytes; m_buffersize = bytes;
return m_buffer; return m_buffer;
} // user-supplied buffer, fail } // user-supplied buffer, fail

View File

@@ -344,7 +344,7 @@ wxTCPConnection::wxTCPConnection () : wxConnectionBase()
m_codeco = NULL; m_codeco = NULL;
} }
wxTCPConnection::wxTCPConnection(wxChar *buffer, int size) wxTCPConnection::wxTCPConnection(void *buffer, size_t size)
: wxConnectionBase(buffer, size) : wxConnectionBase(buffer, size)
{ {
m_sock = NULL; m_sock = NULL;
@@ -393,7 +393,7 @@ bool wxTCPConnection::Disconnect ()
return true; 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()) if (!m_sock->IsConnected())
return false; return false;
@@ -402,16 +402,13 @@ bool wxTCPConnection::Execute(const wxChar *data, int size, wxIPCFormat format)
m_codeco->Write8(IPC_EXECUTE); m_codeco->Write8(IPC_EXECUTE);
m_codeco->Write8(format); m_codeco->Write8(format);
if (size < 0)
size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
m_codeco->Write32(size); m_codeco->Write32(size);
m_sockstrm->Write(data, size); m_sockstrm->Write(data, size);
return true; 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()) if (!m_sock->IsConnected())
return NULL; return NULL;
@@ -428,11 +425,9 @@ wxChar *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat f
return NULL; return NULL;
else else
{ {
size_t s; size_t s = m_codeci->Read32();
s = m_codeci->Read32(); void *data = GetBufferAtLeast( s );
wxChar *data = GetBufferAtLeast( s );
wxASSERT_MSG(data != NULL, wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPConnection::Request") ); _T("Buffer too small in wxTCPConnection::Request") );
m_sockstrm->Read(data, s); m_sockstrm->Read(data, s);
@@ -443,7 +438,7 @@ wxChar *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat f
} }
} }
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()) if (!m_sock->IsConnected())
return false; return false;
@@ -452,9 +447,6 @@ bool wxTCPConnection::Poke (const wxString& item, const wxChar *data, int size,
m_codeco->WriteString(item); m_codeco->WriteString(item);
m_codeco->Write8(format); m_codeco->Write8(format);
if (size < 0)
size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
m_codeco->Write32(size); m_codeco->Write32(size);
m_sockstrm->Write(data, size); m_sockstrm->Write(data, size);
@@ -498,8 +490,8 @@ bool wxTCPConnection::StopAdvise (const wxString& item)
} }
// Calls that SERVER can make // Calls that SERVER can make
bool wxTCPConnection::Advise (const wxString& item, bool wxTCPConnection::DoAdvise (const wxString& item,
const wxChar *data, int size, wxIPCFormat format) const void *data, size_t size, wxIPCFormat format)
{ {
if (!m_sock->IsConnected()) if (!m_sock->IsConnected())
return false; return false;
@@ -508,9 +500,6 @@ bool wxTCPConnection::Advise (const wxString& item,
m_codeco->WriteString(item); m_codeco->WriteString(item);
m_codeco->Write8(format); m_codeco->Write8(format);
if (size < 0)
size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
m_codeco->Write32(size); m_codeco->Write32(size);
m_sockstrm->Write(data, size); m_sockstrm->Write(data, size);
@@ -564,7 +553,7 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
{ {
case IPC_EXECUTE: case IPC_EXECUTE:
{ {
wxChar *data; void *data;
size_t size; size_t size;
wxIPCFormat format; wxIPCFormat format;
@@ -582,14 +571,10 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
} }
case IPC_ADVISE: case IPC_ADVISE:
{ {
wxChar *data;
size_t size;
wxIPCFormat format;
item = codeci->ReadString(); item = codeci->ReadString();
format = (wxIPCFormat)codeci->Read8(); wxIPCFormat format = (wxIPCFormat)codeci->Read8();
size = codeci->Read32(); size_t size = codeci->Read32();
data = connection->GetBufferAtLeast( size ); void *data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL, wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") ); _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size); sockstrm->Read(data, size);
@@ -624,14 +609,10 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
} }
case IPC_POKE: case IPC_POKE:
{ {
wxIPCFormat format;
size_t size;
wxChar *data;
item = codeci->ReadString(); item = codeci->ReadString();
format = (wxIPCFormat)codeci->Read8(); wxIPCFormat format = (wxIPCFormat)codeci->Read8();
size = codeci->Read32(); size_t size = codeci->Read32();
data = connection->GetBufferAtLeast( size ); void *data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL, wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") ); _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size); sockstrm->Read(data, size);
@@ -647,15 +628,28 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
item = codeci->ReadString(); item = codeci->ReadString();
format = (wxIPCFormat)codeci->Read8(); format = (wxIPCFormat)codeci->Read8();
int user_size = -1; size_t user_size = wxNO_LEN;
const wxChar *user_data = connection->OnRequest (topic_name, item, &user_size, format); const void *user_data = connection->OnRequest (topic_name, item, &user_size, format);
if (user_data) if (user_data)
{ {
codeco->Write8(IPC_REQUEST_REPLY); codeco->Write8(IPC_REQUEST_REPLY);
if (user_size == -1) if (user_size == wxNO_LEN)
user_size = (wxStrlen(user_data) + 1) * sizeof(wxChar); // includes final NUL {
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); codeco->Write32(user_size);
sockstrm->Write(user_data, user_size); sockstrm->Write(user_data, user_size);

View File

@@ -498,7 +498,7 @@ bool wxDDEClient::DeleteConnection(WXHCONV conv)
// wxDDEConnection // wxDDEConnection
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxDDEConnection::wxDDEConnection(wxChar *buffer, int size) wxDDEConnection::wxDDEConnection(void *buffer, size_t size)
: wxConnectionBase(buffer, size) : wxConnectionBase(buffer, size)
{ {
m_client = NULL; m_client = NULL;
@@ -545,13 +545,9 @@ bool wxDDEConnection::Disconnect()
return ok; 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; DWORD result;
if (size < 0)
{
size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
}
bool ok = DdeClientTransaction((LPBYTE)data, bool ok = DdeClientTransaction((LPBYTE)data,
size, size,
@@ -572,7 +568,7 @@ bool wxDDEConnection::Execute(const wxChar *data, int size, wxIPCFormat WXUNUSED
return ok; 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 result;
@@ -593,7 +589,7 @@ wxChar *wxDDEConnection::Request(const wxString& item, int *size, wxIPCFormat fo
DWORD len = DdeGetData(returned_data, NULL, 0, 0); DWORD len = DdeGetData(returned_data, NULL, 0, 0);
wxChar *data = GetBufferAtLeast( len ); void *data = GetBufferAtLeast(len);
wxASSERT_MSG(data != NULL, wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxDDEConnection::Request") ); _T("Buffer too small in wxDDEConnection::Request") );
(void) DdeGetData(returned_data, (LPBYTE)data, len, 0); (void) DdeGetData(returned_data, (LPBYTE)data, len, 0);
@@ -601,18 +597,14 @@ wxChar *wxDDEConnection::Request(const wxString& item, int *size, wxIPCFormat fo
(void) DdeFreeDataHandle(returned_data); (void) DdeFreeDataHandle(returned_data);
if (size) if (size)
*size = (int)len; *size = (size_t)len;
return data; 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; DWORD result;
if (size < 0)
{
size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
}
HSZ item_atom = DDEGetAtom(item); HSZ item_atom = DDEGetAtom(item);
bool ok = DdeClientTransaction((LPBYTE)data, bool ok = DdeClientTransaction((LPBYTE)data,
@@ -669,16 +661,11 @@ bool wxDDEConnection::StopAdvise(const wxString& item)
} }
// Calls that SERVER can make // Calls that SERVER can make
bool wxDDEConnection::Advise(const wxString& item, bool wxDDEConnection::DoAdvise(const wxString& item,
const wxChar *data, const void *data,
int size, size_t size,
wxIPCFormat format) wxIPCFormat format)
{ {
if (size < 0)
{
size = (wxStrlen(data) + 1) * sizeof(wxChar); // includes final NUL
}
HSZ item_atom = DDEGetAtom(item); HSZ item_atom = DDEGetAtom(item);
HSZ topic_atom = DDEGetAtom(m_topicName); HSZ topic_atom = DDEGetAtom(m_topicName);
m_sendingData = data; // mrf: potential for scope problems here? m_sendingData = data; // mrf: potential for scope problems here?
@@ -695,12 +682,6 @@ bool wxDDEConnection::Advise(const wxString& item,
return ok; return ok;
} }
bool wxDDEConnection::OnDisconnect()
{
delete this;
return true;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// _DDECallback // _DDECallback
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -775,7 +756,7 @@ _DDECallback(WORD wType,
{ {
DWORD len = DdeGetData(hData, NULL, 0, 0); DWORD len = DdeGetData(hData, NULL, 0, 0);
wxChar *data = connection->GetBufferAtLeast( len ); void *data = connection->GetBufferAtLeast(len);
wxASSERT_MSG(data != NULL, wxASSERT_MSG(data != NULL,
_T("Buffer too small in _DDECallback (XTYP_EXECUTE)") ); _T("Buffer too small in _DDECallback (XTYP_EXECUTE)") );
@@ -804,15 +785,26 @@ _DDECallback(WORD wType,
{ {
wxString item_name = DDEStringFromAtom(hsz2); wxString item_name = DDEStringFromAtom(hsz2);
int user_size = -1; size_t user_size = wxNO_LEN;
const wxChar *data = connection->OnRequest(connection->m_topicName, const void *data = connection->OnRequest(connection->m_topicName,
item_name, item_name,
&user_size, &user_size,
(wxIPCFormat)wFmt); (wxIPCFormat)wFmt);
if (data) if (data)
{ {
if (user_size < 0) if (user_size == wxNO_LEN)
user_size = (wxStrlen((wxChar*)data) + 1) * sizeof(wxChar); // includes final NUL 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, HDDEDATA handle = DdeCreateDataHandle(DDEIdInst,
(LPBYTE)data, (LPBYTE)data,
@@ -837,7 +829,7 @@ _DDECallback(WORD wType,
DWORD len = DdeGetData(hData, NULL, 0, 0); DWORD len = DdeGetData(hData, NULL, 0, 0);
wxChar *data = connection->GetBufferAtLeast( len ); void *data = connection->GetBufferAtLeast(len);
wxASSERT_MSG(data != NULL, wxASSERT_MSG(data != NULL,
_T("Buffer too small in _DDECallback (XTYP_POKE)") ); _T("Buffer too small in _DDECallback (XTYP_POKE)") );
@@ -924,7 +916,7 @@ _DDECallback(WORD wType,
DWORD len = DdeGetData(hData, NULL, 0, 0); DWORD len = DdeGetData(hData, NULL, 0, 0);
wxChar *data = connection->GetBufferAtLeast( len ); void *data = connection->GetBufferAtLeast(len);
wxASSERT_MSG(data != NULL, wxASSERT_MSG(data != NULL,
_T("Buffer too small in _DDECallback (XTYP_ADVDATA)") ); _T("Buffer too small in _DDECallback (XTYP_ADVDATA)") );