1999-01-27 05:01:14 -05:00
/////////////////////////////////////////////////////////////////////////////
// Name: server.cpp
2000-01-15 17:34:29 -05:00
// Purpose: IPC sample: server
1999-01-27 05:01:14 -05:00
// Author: Julian Smart
2005-09-11 14:31:34 -04:00
// Modified by: Jurgen Doornik
1999-01-27 05:01:14 -05:00
// Created: 25/01/99
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
2000-01-15 17:34:29 -05:00
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
1999-01-27 05:01:14 -05:00
// For compilers that support precompilation, includes "wx.h".
# include "wx/wxprec.h"
# ifdef __BORLANDC__
2000-01-15 17:34:29 -05:00
# pragma hdrstop
1999-01-27 05:01:14 -05:00
# endif
# ifndef WX_PRECOMP
2000-01-15 17:34:29 -05:00
# include "wx/wx.h"
1999-01-27 05:01:14 -05:00
# endif
// Settings common to both executables: determines whether
// we're using TCP/IP or real DDE.
2005-09-11 14:31:34 -04:00
# include "ipcsetup.h"
1999-01-27 05:01:14 -05:00
2002-03-21 05:32:18 -05:00
# if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
2000-01-15 17:34:29 -05:00
# include "mondrian.xpm"
1999-01-27 05:01:14 -05:00
# endif
# include "server.h"
2005-09-11 14:31:34 -04:00
# include "wx/textdlg.h"
# include "wx/datetime.h"
1999-01-27 05:01:14 -05:00
2000-01-15 17:34:29 -05:00
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
1999-01-27 05:01:14 -05:00
IMPLEMENT_APP ( MyApp )
2000-01-15 17:34:29 -05:00
BEGIN_EVENT_TABLE ( MyFrame , wxFrame )
2005-09-11 14:31:34 -04:00
EVT_MENU ( wxID_EXIT , MyFrame : : OnExit )
EVT_CLOSE ( MyFrame : : OnClose )
EVT_BUTTON ( ID_START , MyFrame : : OnStart )
EVT_CHOICE ( ID_SERVERNAME , MyFrame : : OnServerName )
EVT_BUTTON ( ID_DISCONNECT , MyFrame : : OnDisconnect )
EVT_BUTTON ( ID_ADVISE , MyFrame : : OnAdvise )
2000-01-15 17:34:29 -05:00
END_EVENT_TABLE ( )
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// MyApp
// ----------------------------------------------------------------------------
1999-01-27 05:01:14 -05:00
bool MyApp : : OnInit ( )
{
2007-02-03 19:34:18 -05:00
if ( ! wxApp : : OnInit ( ) )
return false ;
2000-01-15 17:34:29 -05:00
// Create the main frame window
2005-09-11 14:31:34 -04:00
m_frame = new MyFrame ( NULL , _T ( " Server " ) ) ;
m_frame - > Show ( true ) ;
1999-01-27 05:01:14 -05:00
2004-06-02 13:03:20 -04:00
return true ;
2000-01-15 17:34:29 -05:00
}
1999-01-27 05:01:14 -05:00
2000-01-15 17:34:29 -05:00
int MyApp : : OnExit ( )
{
return 0 ;
}
1999-01-27 05:01:14 -05:00
2000-01-15 17:34:29 -05:00
// ----------------------------------------------------------------------------
// MyFrame
// ----------------------------------------------------------------------------
1999-01-27 05:01:14 -05:00
2000-01-15 17:34:29 -05:00
// Define my frame constructor
MyFrame : : MyFrame ( wxFrame * frame , const wxString & title )
2005-09-11 14:31:34 -04:00
: wxFrame ( frame , wxID_ANY , title , wxDefaultPosition , wxSize ( 400 , 300 ) )
2000-01-15 17:34:29 -05:00
{
2004-07-19 11:36:01 -04:00
# if wxUSE_STATUSBAR
2000-01-15 17:34:29 -05:00
CreateStatusBar ( ) ;
2004-07-19 11:36:01 -04:00
# endif // wxUSE_STATUSBAR
1999-01-27 05:01:14 -05:00
2000-01-15 17:34:29 -05:00
// Give it an icon
SetIcon ( wxICON ( mondrian ) ) ;
1999-01-27 05:01:14 -05:00
2000-01-15 17:34:29 -05:00
// Make a menubar
wxMenu * file_menu = new wxMenu ;
1999-01-27 05:01:14 -05:00
2005-09-11 14:31:34 -04:00
file_menu - > Append ( wxID_EXIT , _T ( " &Quit \t Ctrl-Q " ) ) ;
1999-01-27 05:01:14 -05:00
2000-01-15 17:34:29 -05:00
wxMenuBar * menu_bar = new wxMenuBar ;
1999-01-27 05:01:14 -05:00
2002-12-15 12:25:36 -05:00
menu_bar - > Append ( file_menu , _T ( " &File " ) ) ;
1999-01-27 05:01:14 -05:00
2000-01-15 17:34:29 -05:00
// Associate the menu bar with the frame
SetMenuBar ( menu_bar ) ;
1999-01-27 05:01:14 -05:00
2005-09-11 14:31:34 -04:00
// set a dialog background
SetBackgroundColour ( wxSystemSettings : : GetColour ( wxSYS_COLOUR_BTNFACE ) ) ;
// add the controls to the frame
wxBoxSizer * item0 = new wxBoxSizer ( wxVERTICAL ) ;
wxBoxSizer * item1 = new wxBoxSizer ( wxHORIZONTAL ) ;
wxFlexGridSizer * item2 = new wxFlexGridSizer ( 2 , 0 , 0 ) ;
item2 - > AddGrowableCol ( 1 ) ;
wxButton * item3 = new wxButton ( this , ID_START , wxT ( " Start Server " ) , wxDefaultPosition , wxDefaultSize , 0 ) ;
item2 - > Add ( item3 , 0 , wxGROW | wxALIGN_CENTER_VERTICAL | wxALL , 5 ) ;
wxString strs4 [ ] =
{
IPC_SERVICE , _T ( " ... " )
} ;
wxChoice * item4 = new wxChoice ( this , ID_SERVERNAME , wxDefaultPosition , wxSize ( 100 , - 1 ) , 2 , strs4 , 0 ) ;
item2 - > Add ( item4 , 0 , wxGROW | wxALIGN_CENTER_VERTICAL | wxALL , 5 ) ;
wxButton * item5 = new wxButton ( this , ID_DISCONNECT , wxT ( " Disconnect Client " ) , wxDefaultPosition , wxDefaultSize , 0 ) ;
item2 - > Add ( item5 , 0 , wxGROW | wxALIGN_CENTER_VERTICAL | wxALL , 5 ) ;
item2 - > Add ( 20 , 20 , 0 , wxALIGN_CENTER | wxALL , 5 ) ;
wxButton * item6 = new wxButton ( this , ID_ADVISE , wxT ( " Advise " ) , wxDefaultPosition , wxDefaultSize , 0 ) ;
item2 - > Add ( item6 , 0 , wxGROW | wxALIGN_CENTER_VERTICAL | wxALL , 5 ) ;
item2 - > Add ( 20 , 20 , 0 , wxALIGN_CENTER | wxALL , 5 ) ;
item1 - > Add ( item2 , 1 , wxALIGN_CENTER | wxALL , 5 ) ;
item0 - > Add ( item1 , 0 , wxGROW | wxALIGN_CENTER_VERTICAL | wxALL , 5 ) ;
wxStaticBox * item8 = new wxStaticBox ( this , - 1 , wxT ( " Server log " ) ) ;
wxStaticBoxSizer * item7 = new wxStaticBoxSizer ( item8 , wxVERTICAL ) ;
wxTextCtrl * item9 = new wxTextCtrl ( this , ID_LOG , wxT ( " " ) , wxDefaultPosition , wxSize ( 500 , 140 ) , wxTE_MULTILINE ) ;
item7 - > Add ( item9 , 1 , wxGROW | wxALIGN_CENTER_VERTICAL | wxALL , 5 ) ;
item0 - > Add ( item7 , 0 , wxGROW | wxALIGN_CENTER_VERTICAL | wxALL , 5 ) ;
SetSizer ( item0 ) ;
item0 - > SetSizeHints ( this ) ;
// status
m_server = NULL ;
GetServername ( ) - > SetSelection ( 0 ) ;
wxLogTextCtrl * logWindow = new wxLogTextCtrl ( GetLog ( ) ) ;
delete wxLog : : SetActiveTarget ( logWindow ) ;
wxLogMessage ( _T ( " Click on Start to start the server " ) ) ;
Enable ( ) ;
1999-01-27 05:01:14 -05:00
}
2005-09-11 14:31:34 -04:00
void MyFrame : : Enable ( )
1999-01-27 05:01:14 -05:00
{
2005-09-11 14:31:34 -04:00
GetStart ( ) - > Enable ( m_server = = NULL ) ;
GetServername ( ) - > Enable ( m_server = = NULL ) ;
GetAdvise ( ) - > Enable ( m_server & & m_server - > CanAdvise ( ) ) ;
2005-11-27 09:03:36 -05:00
GetDisconnect ( ) - > Enable ( m_server & & m_server - > IsConnected ( ) ) ;
2005-09-11 14:31:34 -04:00
}
Applied patch [ 600051 ] DDE and TCP improvements and fixes
By Michael Fielding
As discussed on wx-dev. some fixes and improvements for Interprocess Communication (IPC), using DDE and TCP.
1. DDE buffers were using a global buffer
2. TCP buffers were allocated each time needed, and Request would have caused memory leaks had it been used.
Fixed these both by using a self-resizing buffer in wxConnectionBase. Changed samples and docs to reflect the improved (but backward compatible) internal buffer management. wxConnectionBase could (in future) use wxMemoryBuffer.
3. IPC sample had trouble closing, causing crash, when closing server using window X button.
Because it was (effectively) trying to delete a window in OnExit, when that window was already destroyed. Fixed by making IPCDialog and MyConnection remember if they'd destroyed each other. It's not elegant, but either the connection or the window could be deleted first.
4. Docs for wxDDE... and wxTCP... duplicated eachother, supposed to have same API. Some parts unclear.
Patch removes dde and tcp-specific files (including from tipc.tex and classes.tex), and explains how ipc.h selects for you which one to use based on platform. Some other misc clarifications.
6. Client sample was suffering apparent memory leak because of not deleting connection object, and had a hack in there to do that.
In fact this was due to the derived OnDisconnect not deleting itself, as it does in base class. Mentioned need to do it in docs, fixed sample so that it does.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16907 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2002-09-01 10:48:16 -04:00
2005-09-11 14:31:34 -04:00
void MyFrame : : OnClose ( wxCloseEvent & event )
{
if ( m_server )
{
delete m_server ;
m_server = NULL ;
1999-01-27 05:01:14 -05:00
}
2005-09-11 14:31:34 -04:00
event . Skip ( ) ;
1999-01-27 05:01:14 -05:00
}
2000-07-15 15:51:35 -04:00
void MyFrame : : OnExit ( wxCommandEvent & WXUNUSED ( event ) )
{
2004-06-02 13:03:20 -04:00
Close ( true ) ;
2000-07-15 15:51:35 -04:00
}
2005-09-11 14:31:34 -04:00
void MyFrame : : OnStart ( wxCommandEvent & WXUNUSED ( event ) )
{
// Create a new server
m_server = new MyServer ;
wxString servername = GetServername ( ) - > GetStringSelection ( ) ;
if ( m_server - > Create ( servername ) )
{
wxLogMessage ( _T ( " Server %s started " ) , servername . c_str ( ) ) ;
# if wxUSE_DDE_FOR_IPC
wxLogMessage ( _T ( " Server uses DDE " ) ) ;
# else // !wxUSE_DDE_FOR_IPC
wxLogMessage ( _T ( " Server uses TCP " ) ) ;
# endif // wxUSE_DDE_FOR_IPC/!wxUSE_DDE_FOR_IPC
}
else
{
wxLogMessage ( _T ( " Server %s failed to start " ) , servername . c_str ( ) ) ;
delete m_server ;
m_server = NULL ;
}
Enable ( ) ;
}
1999-01-27 05:01:14 -05:00
2005-09-11 14:31:34 -04:00
void MyFrame : : OnServerName ( wxCommandEvent & WXUNUSED ( event ) )
1999-01-27 05:01:14 -05:00
{
2005-09-11 14:31:34 -04:00
if ( GetServername ( ) - > GetStringSelection ( ) = = _T ( " ... " ) )
{
wxString s = wxGetTextFromUser ( _T ( " Specify the name of the server " ) ,
_T ( " Server Name " ) , _ ( " " ) , this ) ;
if ( ! s . IsEmpty ( ) & & s ! = IPC_SERVICE )
{
GetServername ( ) - > Insert ( s , 0 ) ;
GetServername ( ) - > SetSelection ( 0 ) ;
}
}
1999-01-27 05:01:14 -05:00
}
2005-09-11 14:31:34 -04:00
void MyFrame : : Disconnect ( )
Applied patch [ 600051 ] DDE and TCP improvements and fixes
By Michael Fielding
As discussed on wx-dev. some fixes and improvements for Interprocess Communication (IPC), using DDE and TCP.
1. DDE buffers were using a global buffer
2. TCP buffers were allocated each time needed, and Request would have caused memory leaks had it been used.
Fixed these both by using a self-resizing buffer in wxConnectionBase. Changed samples and docs to reflect the improved (but backward compatible) internal buffer management. wxConnectionBase could (in future) use wxMemoryBuffer.
3. IPC sample had trouble closing, causing crash, when closing server using window X button.
Because it was (effectively) trying to delete a window in OnExit, when that window was already destroyed. Fixed by making IPCDialog and MyConnection remember if they'd destroyed each other. It's not elegant, but either the connection or the window could be deleted first.
4. Docs for wxDDE... and wxTCP... duplicated eachother, supposed to have same API. Some parts unclear.
Patch removes dde and tcp-specific files (including from tipc.tex and classes.tex), and explains how ipc.h selects for you which one to use based on platform. Some other misc clarifications.
6. Client sample was suffering apparent memory leak because of not deleting connection object, and had a hack in there to do that.
In fact this was due to the derived OnDisconnect not deleting itself, as it does in base class. Mentioned need to do it in docs, fixed sample so that it does.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16907 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2002-09-01 10:48:16 -04:00
{
2005-09-11 14:31:34 -04:00
m_server - > Disconnect ( ) ;
Enable ( ) ;
Applied patch [ 600051 ] DDE and TCP improvements and fixes
By Michael Fielding
As discussed on wx-dev. some fixes and improvements for Interprocess Communication (IPC), using DDE and TCP.
1. DDE buffers were using a global buffer
2. TCP buffers were allocated each time needed, and Request would have caused memory leaks had it been used.
Fixed these both by using a self-resizing buffer in wxConnectionBase. Changed samples and docs to reflect the improved (but backward compatible) internal buffer management. wxConnectionBase could (in future) use wxMemoryBuffer.
3. IPC sample had trouble closing, causing crash, when closing server using window X button.
Because it was (effectively) trying to delete a window in OnExit, when that window was already destroyed. Fixed by making IPCDialog and MyConnection remember if they'd destroyed each other. It's not elegant, but either the connection or the window could be deleted first.
4. Docs for wxDDE... and wxTCP... duplicated eachother, supposed to have same API. Some parts unclear.
Patch removes dde and tcp-specific files (including from tipc.tex and classes.tex), and explains how ipc.h selects for you which one to use based on platform. Some other misc clarifications.
6. Client sample was suffering apparent memory leak because of not deleting connection object, and had a hack in there to do that.
In fact this was due to the derived OnDisconnect not deleting itself, as it does in base class. Mentioned need to do it in docs, fixed sample so that it does.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16907 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2002-09-01 10:48:16 -04:00
}
2005-09-11 14:31:34 -04:00
void MyFrame : : OnDisconnect ( wxCommandEvent & WXUNUSED ( event ) )
1999-01-27 05:01:14 -05:00
{
2005-09-11 14:31:34 -04:00
Disconnect ( ) ;
}
void MyFrame : : OnAdvise ( wxCommandEvent & WXUNUSED ( event ) )
{
m_server - > Advise ( ) ;
1999-01-27 05:01:14 -05:00
}
2000-01-15 17:34:29 -05:00
// ----------------------------------------------------------------------------
// MyServer
// ----------------------------------------------------------------------------
2005-09-11 14:31:34 -04:00
MyServer : : MyServer ( ) : wxServer ( )
{
m_connection = NULL ;
}
MyServer : : ~ MyServer ( )
{
Disconnect ( ) ;
}
1999-01-27 05:01:14 -05:00
wxConnectionBase * MyServer : : OnAcceptConnection ( const wxString & topic )
{
2005-09-14 17:10:34 -04:00
wxLogMessage ( _T ( " OnAcceptConnection( \" %s \" ) " ) , topic . c_str ( ) ) ;
2002-04-15 14:24:46 -04:00
2005-09-11 14:31:34 -04:00
if ( topic = = IPC_TOPIC )
{
m_connection = new MyConnection ( ) ;
wxGetApp ( ) . GetFrame ( ) - > Enable ( ) ;
wxLogMessage ( _T ( " Connection accepted " ) ) ;
return m_connection ;
}
2002-04-15 14:24:46 -04:00
// unknown topic
return NULL ;
1999-01-27 05:01:14 -05:00
}
2005-09-11 14:31:34 -04:00
void MyServer : : Disconnect ( )
{
if ( m_connection )
{
m_connection - > Disconnect ( ) ;
delete m_connection ;
m_connection = NULL ;
wxGetApp ( ) . GetFrame ( ) - > Enable ( ) ;
wxLogMessage ( _T ( " Disconnected client " ) ) ;
}
}
void MyServer : : Advise ( )
{
if ( CanAdvise ( ) )
{
wxString s = wxDateTime : : Now ( ) . Format ( ) ;
2007-10-20 18:54:26 -04:00
m_connection - > Advise ( m_connection - > m_sAdvise , s ) ;
2005-09-11 14:31:34 -04:00
s = wxDateTime : : Now ( ) . FormatTime ( ) + _T ( " " ) + wxDateTime : : Now ( ) . FormatDate ( ) ;
2007-10-20 18:54:26 -04:00
m_connection - > Advise ( m_connection - > m_sAdvise , ( const char * ) s . c_str ( ) , s . Length ( ) + 1 ) ;
2005-09-11 14:31:34 -04:00
# 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 ' ;
2007-10-20 18:54:26 -04:00
m_connection - > Advise ( m_connection - > m_sAdvise , bytes , 3 , wxIPC_PRIVATE ) ;
2005-09-11 14:31:34 -04:00
// this works, but the log treats it as a string now
2007-10-20 18:54:26 -04:00
// m_connection->Advise(m_connection->m_sAdvise, bytes, 3, wxIPC_TEXT );
2005-09-11 14:31:34 -04:00
}
}
2000-01-15 17:34:29 -05:00
// ----------------------------------------------------------------------------
// MyConnection
// ----------------------------------------------------------------------------
Applied patch [ 600051 ] DDE and TCP improvements and fixes
By Michael Fielding
As discussed on wx-dev. some fixes and improvements for Interprocess Communication (IPC), using DDE and TCP.
1. DDE buffers were using a global buffer
2. TCP buffers were allocated each time needed, and Request would have caused memory leaks had it been used.
Fixed these both by using a self-resizing buffer in wxConnectionBase. Changed samples and docs to reflect the improved (but backward compatible) internal buffer management. wxConnectionBase could (in future) use wxMemoryBuffer.
3. IPC sample had trouble closing, causing crash, when closing server using window X button.
Because it was (effectively) trying to delete a window in OnExit, when that window was already destroyed. Fixed by making IPCDialog and MyConnection remember if they'd destroyed each other. It's not elegant, but either the connection or the window could be deleted first.
4. Docs for wxDDE... and wxTCP... duplicated eachother, supposed to have same API. Some parts unclear.
Patch removes dde and tcp-specific files (including from tipc.tex and classes.tex), and explains how ipc.h selects for you which one to use based on platform. Some other misc clarifications.
6. Client sample was suffering apparent memory leak because of not deleting connection object, and had a hack in there to do that.
In fact this was due to the derived OnDisconnect not deleting itself, as it does in base class. Mentioned need to do it in docs, fixed sample so that it does.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16907 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2002-09-01 10:48:16 -04:00
MyConnection : : MyConnection ( )
: wxConnection ( )
1999-01-27 05:01:14 -05:00
{
}
2000-01-15 17:34:29 -05:00
MyConnection : : ~ MyConnection ( )
1999-01-27 05:01:14 -05:00
{
2005-09-11 14:31:34 -04:00
}
bool MyConnection : : OnExecute ( const wxString & topic ,
2007-10-20 18:54:26 -04:00
const void * data , size_t size , wxIPCFormat format )
2005-09-11 14:31:34 -04:00
{
Log ( _T ( " OnExecute " ) , topic , _T ( " " ) , data , size , format ) ;
return true ;
}
bool MyConnection : : OnPoke ( const wxString & topic ,
2007-10-20 18:54:26 -04:00
const wxString & item , const void * data , size_t size , wxIPCFormat format )
2005-09-11 14:31:34 -04:00
{
Log ( _T ( " OnPoke " ) , topic , item , data , size , format ) ;
return wxConnection : : OnPoke ( topic , item , data , size , format ) ;
}
2007-10-20 18:54:26 -04:00
const void * MyConnection : : OnRequest ( const wxString & topic ,
const wxString & item , size_t * size , wxIPCFormat format )
2005-09-11 14:31:34 -04:00
{
2007-10-20 18:54:26 -04:00
const void * data ;
2005-09-11 14:31:34 -04:00
if ( item = = _T ( " Date " ) )
2000-01-15 17:34:29 -05:00
{
2005-09-11 14:31:34 -04:00
m_sRequestDate = wxDateTime : : Now ( ) . Format ( ) ;
2007-07-27 19:59:11 -04:00
data = m_sRequestDate . c_str ( ) ;
2007-10-20 18:54:26 -04:00
* size = wxNO_LEN ;
2005-09-11 14:31:34 -04:00
}
else if ( item = = _T ( " Date+len " ) )
{
m_sRequestDate = wxDateTime : : Now ( ) . FormatTime ( ) + _T ( " " ) + wxDateTime : : Now ( ) . FormatDate ( ) ;
2007-07-27 19:59:11 -04:00
data = m_sRequestDate . c_str ( ) ;
2007-10-20 18:54:26 -04:00
* size = m_sRequestDate . Length ( ) + 1 ;
2005-09-11 14:31:34 -04:00
}
else if ( item = = _T ( " bytes[3] " ) )
{
2007-07-27 19:59:11 -04:00
data = m_achRequestBytes ;
2005-09-11 14:31:34 -04:00
m_achRequestBytes [ 0 ] = ' 1 ' ; m_achRequestBytes [ 1 ] = ' 2 ' ; m_achRequestBytes [ 2 ] = ' 3 ' ;
* size = 3 ;
}
else
{
data = NULL ;
* size = 0 ;
2000-01-15 17:34:29 -05:00
}
2007-10-20 18:54:26 -04:00
Log ( _T ( " OnRequest " ) , topic , item , data , * size , format ) ;
2005-09-11 14:31:34 -04:00
return data ;
1999-01-27 05:01:14 -05:00
}
2005-09-11 14:31:34 -04:00
bool MyConnection : : OnStartAdvise ( const wxString & topic ,
const wxString & item )
1999-01-27 05:01:14 -05:00
{
2005-09-14 17:10:34 -04:00
wxLogMessage ( _T ( " OnStartAdvise( \" %s \" , \" %s \" ) " ) , topic . c_str ( ) , item . c_str ( ) ) ;
2005-09-11 14:31:34 -04:00
wxLogMessage ( _T ( " Returning true " ) ) ;
m_sAdvise = item ;
wxGetApp ( ) . GetFrame ( ) - > Enable ( ) ;
2004-06-02 13:03:20 -04:00
return true ;
1999-01-27 05:01:14 -05:00
}
2005-09-11 14:31:34 -04:00
bool MyConnection : : OnStopAdvise ( const wxString & topic ,
const wxString & item )
1999-01-27 05:01:14 -05:00
{
2005-09-14 17:10:34 -04:00
wxLogMessage ( _T ( " OnStopAdvise( \" %s \" , \" %s \" ) " ) , topic . c_str ( ) , item . c_str ( ) ) ;
2005-09-11 14:31:34 -04:00
wxLogMessage ( _T ( " Returning true " ) ) ;
m_sAdvise . Empty ( ) ;
wxGetApp ( ) . GetFrame ( ) - > Enable ( ) ;
2004-06-02 13:03:20 -04:00
return true ;
1999-01-27 05:01:14 -05:00
}
2005-09-11 14:31:34 -04:00
void MyConnection : : Log ( const wxString & command , const wxString & topic ,
2007-10-20 18:54:26 -04:00
const wxString & item , const void * data , size_t size , wxIPCFormat format )
2005-09-11 14:31:34 -04:00
{
wxString s ;
if ( topic . IsEmpty ( ) & & item . IsEmpty ( ) )
2005-09-14 17:10:34 -04:00
s . Printf ( _T ( " %s( " ) , command . c_str ( ) ) ;
2005-09-11 14:31:34 -04:00
else if ( topic . IsEmpty ( ) )
2005-09-14 17:10:34 -04:00
s . Printf ( _T ( " %s( \" %s \" , " ) , command . c_str ( ) , item . c_str ( ) ) ;
2005-09-11 14:31:34 -04:00
else if ( item . IsEmpty ( ) )
2005-09-14 17:10:34 -04:00
s . Printf ( _T ( " %s( \" %s \" , " ) , command . c_str ( ) , topic . c_str ( ) ) ;
2005-09-11 14:31:34 -04:00
else
2005-09-14 17:10:34 -04:00
s . Printf ( _T ( " %s( \" %s \" , \" %s \" , " ) , command . c_str ( ) , topic . c_str ( ) , item . c_str ( ) ) ;
2005-09-11 14:31:34 -04:00
2007-10-20 18:54:26 -04:00
switch ( format )
2005-09-11 14:31:34 -04:00
{
2007-10-20 18:54:26 -04:00
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 :
2005-09-11 14:31:34 -04:00
if ( size = = 3 )
{
char * bytes = ( char * ) data ;
2005-09-14 17:10:34 -04:00
wxLogMessage ( _T ( " %s'%c%c%c',%d) " ) , s . c_str ( ) , bytes [ 0 ] , bytes [ 1 ] , bytes [ 2 ] , size ) ;
2005-09-11 14:31:34 -04:00
}
else
2005-09-14 17:10:34 -04:00
wxLogMessage ( _T ( " %s...,%d) " ) , s . c_str ( ) , size ) ;
2007-10-20 18:54:26 -04:00
break ;
case wxIPC_INVALID :
2005-09-14 17:10:34 -04:00
wxLogMessage ( _T ( " %s[invalid data],%d) " ) , s . c_str ( ) , size ) ;
2007-10-20 18:54:26 -04:00
break ;
default :
wxLogMessage ( _T ( " %s[unknown data],%d) " ) , s . c_str ( ) , size ) ;
break ;
}
2005-09-11 14:31:34 -04:00
}
2007-10-20 18:54:26 -04:00
bool MyConnection : : DoAdvise ( const wxString & item , const void * data , size_t size , wxIPCFormat format )
1999-01-27 05:01:14 -05:00
{
2005-09-11 14:31:34 -04:00
Log ( _T ( " Advise " ) , _T ( " " ) , item , data , size , format ) ;
2007-10-20 18:54:26 -04:00
return wxConnection : : DoAdvise ( item , data , size , format ) ;
1999-01-27 05:01:14 -05:00
}
2005-09-11 14:31:34 -04:00
bool MyConnection : : OnDisconnect ( )
1999-01-27 05:01:14 -05:00
{
2005-09-11 14:31:34 -04:00
wxLogMessage ( _T ( " OnDisconnect() " ) ) ;
wxGetApp ( ) . GetFrame ( ) - > Disconnect ( ) ;
2004-06-02 13:03:20 -04:00
return true ;
1999-01-27 05:01:14 -05:00
}