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
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
#if !defined(__WXMSW__) && !defined(__WXPM__)
|
|
|
|
#include "../sample.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_CLOSE( MyFrame::OnClose )
|
2008-07-13 21:20:33 -04:00
|
|
|
|
|
|
|
EVT_BUTTON( ID_START, MyFrame::OnStart )
|
|
|
|
EVT_CHOICE( ID_SERVERNAME, MyFrame::OnServerName )
|
2005-09-11 14:31:34 -04:00
|
|
|
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
|
2008-07-13 21:20:33 -04:00
|
|
|
m_frame = new MyFrame(NULL, "Server");
|
2005-09-11 14:31:34 -04:00
|
|
|
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
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
SetIcon(wxICON(sample));
|
1999-01-27 05:01:14 -05:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
m_server = NULL;
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
wxPanel * const panel = new wxPanel(this);
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
wxBoxSizer * const sizerMain = new wxBoxSizer( wxVERTICAL );
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
wxFlexGridSizer * const sizerCmds = new wxFlexGridSizer( 2, 0, 0 );
|
|
|
|
sizerCmds->AddGrowableCol( 1 );
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
wxButton *btn;
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
btn = new wxButton(panel, ID_START, "&Start Server");
|
|
|
|
sizerCmds->Add(btn, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
const wxString choices[] = { IPC_SERVICE, "..." };
|
|
|
|
wxChoice * const choice = new wxChoice
|
|
|
|
(
|
|
|
|
panel,
|
|
|
|
ID_SERVERNAME,
|
|
|
|
wxDefaultPosition, wxSize(100, -1),
|
|
|
|
WXSIZEOF(choices), choices
|
|
|
|
);
|
|
|
|
sizerCmds->Add(choice, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
btn = new wxButton(panel, ID_DISCONNECT, "&Disconnect Client");
|
|
|
|
sizerCmds->Add(btn, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
|
|
|
sizerCmds->AddSpacer(20);
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
btn = new wxButton( panel, ID_ADVISE, "&Advise");
|
|
|
|
sizerCmds->Add(btn, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
|
|
|
sizerCmds->AddSpacer(20);
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
sizerMain->Add(sizerCmds, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
wxStaticBoxSizer * const
|
|
|
|
sizerLog = new wxStaticBoxSizer(wxVERTICAL, panel, "Server &log");
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
wxTextCtrl * const textLog = new wxTextCtrl
|
|
|
|
(
|
|
|
|
panel,
|
|
|
|
wxID_ANY,
|
|
|
|
"",
|
|
|
|
wxDefaultPosition, wxSize(500, 140),
|
|
|
|
wxTE_MULTILINE
|
|
|
|
);
|
|
|
|
sizerLog->Add(textLog, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
sizerMain->Add(sizerLog, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
panel->SetSizer(sizerMain);
|
|
|
|
sizerMain->SetSizeHints(panel);
|
|
|
|
SetClientSize(panel->GetSize());
|
2005-09-11 14:31:34 -04:00
|
|
|
|
|
|
|
GetServername()->SetSelection(0);
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogTextCtrl *logWindow = new wxLogTextCtrl(textLog);
|
2005-09-11 14:31:34 -04:00
|
|
|
delete wxLog::SetActiveTarget(logWindow);
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("Click on Start to start the server");
|
|
|
|
UpdateUI();
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
void MyFrame::UpdateUI()
|
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
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("Server %s started", servername);
|
2005-09-11 14:31:34 -04:00
|
|
|
#if wxUSE_DDE_FOR_IPC
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("Server uses DDE");
|
2005-09-11 14:31:34 -04:00
|
|
|
#else // !wxUSE_DDE_FOR_IPC
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("Server uses TCP");
|
2005-09-11 14:31:34 -04:00
|
|
|
#endif // wxUSE_DDE_FOR_IPC/!wxUSE_DDE_FOR_IPC
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("Server %s failed to start", servername);
|
2005-09-11 14:31:34 -04:00
|
|
|
delete m_server;
|
|
|
|
m_server = NULL;
|
|
|
|
}
|
2008-07-13 21:20:33 -04:00
|
|
|
UpdateUI();
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
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
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
if ( GetServername()->GetStringSelection() == "..." )
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
wxString s = wxGetTextFromUser
|
|
|
|
(
|
|
|
|
"Specify the name of the server",
|
|
|
|
"Server Name",
|
|
|
|
"",
|
|
|
|
this
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( !s.empty() && s != IPC_SERVICE )
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
|
|
|
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();
|
2008-07-13 21:20:33 -04:00
|
|
|
UpdateUI();
|
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
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
Disconnect();
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("OnAcceptConnection(\"%s\")", topic);
|
2002-04-15 14:24:46 -04:00
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
if ( topic == IPC_TOPIC )
|
|
|
|
{
|
|
|
|
m_connection = new MyConnection();
|
2008-07-13 21:20:33 -04:00
|
|
|
wxGetApp().GetFrame()->UpdateUI();
|
|
|
|
wxLogMessage("Connection accepted");
|
2005-09-11 14:31:34 -04:00
|
|
|
return m_connection;
|
|
|
|
}
|
2008-07-13 21:20:33 -04:00
|
|
|
//else: unknown topic
|
|
|
|
|
|
|
|
wxLogMessage("Unknown topic, connection refused");
|
2002-04-15 14:24:46 -04:00
|
|
|
return NULL;
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
void MyServer::Disconnect()
|
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
if ( m_connection )
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
|
|
|
delete m_connection;
|
|
|
|
m_connection = NULL;
|
2008-07-13 21:20:33 -04:00
|
|
|
wxGetApp().GetFrame()->UpdateUI();
|
|
|
|
wxLogMessage("Disconnected client");
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyServer::Advise()
|
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
if ( CanAdvise() )
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
const wxDateTime now = wxDateTime::Now();
|
|
|
|
|
|
|
|
m_connection->Advise(m_connection->m_advise, now.Format());
|
|
|
|
|
|
|
|
const wxString s = now.FormatTime() + " " + now.FormatDate();
|
|
|
|
m_connection->Advise(m_connection->m_advise, s.mb_str(), wxNO_LEN);
|
2005-09-11 14:31:34 -04:00
|
|
|
|
|
|
|
#if wxUSE_DDE_FOR_IPC
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("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.");
|
2005-09-11 14:31:34 -04:00
|
|
|
#endif
|
2008-07-13 21:20:33 -04:00
|
|
|
char bytes[3] = { '1', '2', '3' };
|
|
|
|
m_connection->Advise(m_connection->m_advise, bytes, 3, wxIPC_PRIVATE);
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-15 17:34:29 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyConnection
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
bool
|
|
|
|
MyConnection::OnExecute(const wxString& topic,
|
|
|
|
const void *data,
|
|
|
|
size_t size,
|
|
|
|
wxIPCFormat format)
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
Log("OnExecute", topic, "", data, size, format);
|
2005-09-11 14:31:34 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
bool
|
|
|
|
MyConnection::OnPoke(const wxString& topic,
|
|
|
|
const wxString& item,
|
|
|
|
const void *data,
|
|
|
|
size_t size,
|
|
|
|
wxIPCFormat format)
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
Log("OnPoke", topic, item, data, size, format);
|
2005-09-11 14:31:34 -04:00
|
|
|
return wxConnection::OnPoke(topic, item, data, size, format);
|
|
|
|
}
|
|
|
|
|
2008-07-13 21:20:33 -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
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
*size = 0;
|
|
|
|
|
2008-11-17 06:00:32 -05:00
|
|
|
wxString s,
|
|
|
|
afterDate;
|
2008-07-13 21:20:33 -04:00
|
|
|
if ( item.StartsWith("Date", &afterDate) )
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
const wxDateTime now = wxDateTime::Now();
|
|
|
|
|
|
|
|
if ( afterDate.empty() )
|
|
|
|
{
|
2008-11-17 06:00:32 -05:00
|
|
|
s = now.Format();
|
2008-07-13 21:20:33 -04:00
|
|
|
*size = wxNO_LEN;
|
|
|
|
}
|
|
|
|
else if ( afterDate == "+len" )
|
|
|
|
{
|
2008-11-17 06:00:32 -05:00
|
|
|
s = now.FormatTime() + " " + now.FormatDate();
|
|
|
|
*size = strlen(s.mb_str()) + 1;
|
2008-07-13 21:20:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( item == "bytes[3]" )
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2008-11-17 06:00:32 -05:00
|
|
|
s = "123";
|
2005-09-11 14:31:34 -04:00
|
|
|
*size = 3;
|
|
|
|
}
|
2008-07-13 21:20:33 -04:00
|
|
|
|
|
|
|
if ( !*size )
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("Unknown request for \"%s\"", item);
|
|
|
|
return NULL;
|
2000-01-15 17:34:29 -05:00
|
|
|
}
|
2008-07-13 21:20:33 -04:00
|
|
|
|
2008-11-17 06:00:32 -05:00
|
|
|
// store the data pointer to which we return in a member variable to ensure
|
|
|
|
// that the pointer remains valid even after we return
|
|
|
|
m_requestData = s.mb_str();
|
|
|
|
const void * const data = m_requestData;
|
2008-07-13 21:20:33 -04:00
|
|
|
Log("OnRequest", topic, item, data, *size, format);
|
2005-09-11 14:31:34 -04:00
|
|
|
return data;
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
bool MyConnection::OnStartAdvise(const wxString& topic, const wxString& item)
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("OnStartAdvise(\"%s\", \"%s\")", topic, item);
|
|
|
|
wxLogMessage("Returning true");
|
|
|
|
m_advise = item;
|
|
|
|
wxGetApp().GetFrame()->UpdateUI();
|
2004-06-02 13:03:20 -04:00
|
|
|
return true;
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
bool MyConnection::OnStopAdvise(const wxString& topic, const wxString& item)
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("OnStopAdvise(\"%s\",\"%s\")", topic, item);
|
|
|
|
wxLogMessage("Returning true");
|
|
|
|
m_advise.clear();
|
|
|
|
wxGetApp().GetFrame()->UpdateUI();
|
2004-06-02 13:03:20 -04:00
|
|
|
return true;
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2008-07-13 21:20:33 -04:00
|
|
|
bool
|
|
|
|
MyConnection::DoAdvise(const wxString& item,
|
|
|
|
const void *data,
|
|
|
|
size_t size,
|
|
|
|
wxIPCFormat format)
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
Log("Advise", "", 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
|
|
|
{
|
2008-07-13 21:20:33 -04:00
|
|
|
wxLogMessage("OnDisconnect()");
|
2005-09-11 14:31:34 -04:00
|
|
|
wxGetApp().GetFrame()->Disconnect();
|
2004-06-02 13:03:20 -04:00
|
|
|
return true;
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|