1999-01-27 10:01:14 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: server.cpp
|
2000-01-15 22:34:29 +00:00
|
|
|
// Purpose: IPC sample: server
|
1999-01-27 10:01:14 +00:00
|
|
|
// Author: Julian Smart
|
2005-09-11 18:31:34 +00:00
|
|
|
// Modified by: Jurgen Doornik
|
1999-01-27 10:01:14 +00:00
|
|
|
// Created: 25/01/99
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-01-15 22:34:29 +00:00
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-01-27 10:01:14 +00:00
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
2000-01-15 22:34:29 +00:00
|
|
|
#pragma hdrstop
|
1999-01-27 10:01:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
2000-01-15 22:34:29 +00:00
|
|
|
#include "wx/wx.h"
|
1999-01-27 10:01:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Settings common to both executables: determines whether
|
|
|
|
// we're using TCP/IP or real DDE.
|
2005-09-11 18:31:34 +00:00
|
|
|
#include "ipcsetup.h"
|
1999-01-27 10:01:14 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
#if !defined(__WXMSW__) && !defined(__WXPM__)
|
|
|
|
#include "../sample.xpm"
|
1999-01-27 10:01:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "server.h"
|
2005-09-11 18:31:34 +00:00
|
|
|
#include "wx/textdlg.h"
|
|
|
|
#include "wx/datetime.h"
|
1999-01-27 10:01:14 +00:00
|
|
|
|
2000-01-15 22:34:29 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxWin macros
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-27 10:01:14 +00:00
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2000-01-15 22:34:29 +00:00
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2005-09-11 18:31:34 +00:00
|
|
|
EVT_CLOSE( MyFrame::OnClose )
|
2008-07-14 01:20:33 +00:00
|
|
|
|
|
|
|
EVT_BUTTON( ID_START, MyFrame::OnStart )
|
|
|
|
EVT_CHOICE( ID_SERVERNAME, MyFrame::OnServerName )
|
2005-09-11 18:31:34 +00:00
|
|
|
EVT_BUTTON( ID_DISCONNECT, MyFrame::OnDisconnect )
|
|
|
|
EVT_BUTTON( ID_ADVISE, MyFrame::OnAdvise )
|
2000-01-15 22:34:29 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-27 10:01:14 +00:00
|
|
|
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-04 00:34:18 +00:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2000-01-15 22:34:29 +00:00
|
|
|
// Create the main frame window
|
2008-07-14 01:20:33 +00:00
|
|
|
m_frame = new MyFrame(NULL, "Server");
|
2005-09-11 18:31:34 +00:00
|
|
|
m_frame->Show(true);
|
1999-01-27 10:01:14 +00:00
|
|
|
|
2004-06-02 17:03:20 +00:00
|
|
|
return true;
|
2000-01-15 22:34:29 +00:00
|
|
|
}
|
1999-01-27 10:01:14 +00:00
|
|
|
|
2000-01-15 22:34:29 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-27 10:01:14 +00:00
|
|
|
|
2000-01-15 22:34:29 +00:00
|
|
|
// Define my frame constructor
|
|
|
|
MyFrame::MyFrame(wxFrame *frame, const wxString& title)
|
2005-09-11 18:31:34 +00:00
|
|
|
: wxFrame(frame, wxID_ANY, title, wxDefaultPosition, wxSize(400, 300))
|
2000-01-15 22:34:29 +00:00
|
|
|
{
|
2004-07-19 15:36:01 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2000-01-15 22:34:29 +00:00
|
|
|
CreateStatusBar();
|
2004-07-19 15:36:01 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1999-01-27 10:01:14 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
SetIcon(wxICON(sample));
|
1999-01-27 10:01:14 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
m_server = NULL;
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
wxPanel * const panel = new wxPanel(this);
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
wxBoxSizer * const sizerMain = new wxBoxSizer( wxVERTICAL );
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
wxFlexGridSizer * const sizerCmds = new wxFlexGridSizer( 2, 0, 0 );
|
|
|
|
sizerCmds->AddGrowableCol( 1 );
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
wxButton *btn;
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
btn = new wxButton(panel, ID_START, "&Start Server");
|
|
|
|
sizerCmds->Add(btn, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00: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 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00: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 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
btn = new wxButton( panel, ID_ADVISE, "&Advise");
|
|
|
|
sizerCmds->Add(btn, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
|
|
|
sizerCmds->AddSpacer(20);
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
sizerMain->Add(sizerCmds, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
wxStaticBoxSizer * const
|
|
|
|
sizerLog = new wxStaticBoxSizer(wxVERTICAL, panel, "Server &log");
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00: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 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
sizerMain->Add(sizerLog, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
2005-09-11 18:31:34 +00:00
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
panel->SetSizer(sizerMain);
|
|
|
|
sizerMain->SetSizeHints(panel);
|
|
|
|
SetClientSize(panel->GetSize());
|
2005-09-11 18:31:34 +00:00
|
|
|
|
|
|
|
GetServername()->SetSelection(0);
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogTextCtrl *logWindow = new wxLogTextCtrl(textLog);
|
2005-09-11 18:31:34 +00:00
|
|
|
delete wxLog::SetActiveTarget(logWindow);
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogMessage("Click on Start to start the server");
|
|
|
|
UpdateUI();
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
void MyFrame::UpdateUI()
|
1999-01-27 10:01:14 +00:00
|
|
|
{
|
2005-09-11 18:31:34 +00:00
|
|
|
GetStart()->Enable(m_server == NULL);
|
|
|
|
GetServername()->Enable(m_server == NULL);
|
|
|
|
GetAdvise()->Enable(m_server && m_server->CanAdvise());
|
2005-11-27 14:03:36 +00:00
|
|
|
GetDisconnect()->Enable(m_server && m_server->IsConnected());
|
2005-09-11 18:31:34 +00: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 14:48:16 +00:00
|
|
|
|
2005-09-11 18:31:34 +00:00
|
|
|
void MyFrame::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
|
|
|
if (m_server)
|
|
|
|
{
|
|
|
|
delete m_server;
|
|
|
|
m_server = NULL;
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
2005-09-11 18:31:34 +00:00
|
|
|
event.Skip();
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:31:34 +00: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-14 01:20:33 +00:00
|
|
|
wxLogMessage("Server %s started", servername);
|
2005-09-11 18:31:34 +00:00
|
|
|
#if wxUSE_DDE_FOR_IPC
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogMessage("Server uses DDE");
|
2005-09-11 18:31:34 +00:00
|
|
|
#else // !wxUSE_DDE_FOR_IPC
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogMessage("Server uses TCP");
|
2005-09-11 18:31:34 +00:00
|
|
|
#endif // wxUSE_DDE_FOR_IPC/!wxUSE_DDE_FOR_IPC
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogMessage("Server %s failed to start", servername);
|
2005-09-11 18:31:34 +00:00
|
|
|
delete m_server;
|
|
|
|
m_server = NULL;
|
|
|
|
}
|
2008-07-14 01:20:33 +00:00
|
|
|
UpdateUI();
|
2005-09-11 18:31:34 +00:00
|
|
|
}
|
1999-01-27 10:01:14 +00:00
|
|
|
|
2005-09-11 18:31:34 +00:00
|
|
|
void MyFrame::OnServerName( wxCommandEvent& WXUNUSED(event) )
|
1999-01-27 10:01:14 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
if ( GetServername()->GetStringSelection() == "..." )
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
wxString s = wxGetTextFromUser
|
|
|
|
(
|
|
|
|
"Specify the name of the server",
|
|
|
|
"Server Name",
|
|
|
|
"",
|
|
|
|
this
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( !s.empty() && s != IPC_SERVICE )
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
|
|
|
GetServername()->Insert(s, 0);
|
|
|
|
GetServername()->SetSelection(0);
|
|
|
|
}
|
|
|
|
}
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:31:34 +00: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 14:48:16 +00:00
|
|
|
{
|
2005-09-11 18:31:34 +00:00
|
|
|
m_server->Disconnect();
|
2008-07-14 01:20:33 +00: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 14:48:16 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:31:34 +00:00
|
|
|
void MyFrame::OnDisconnect(wxCommandEvent& WXUNUSED(event))
|
1999-01-27 10:01:14 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
Disconnect();
|
2005-09-11 18:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAdvise(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_server->Advise();
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
|
|
|
|
2000-01-15 22:34:29 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyServer
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-09-11 18:31:34 +00:00
|
|
|
MyServer::MyServer() : wxServer()
|
|
|
|
{
|
|
|
|
m_connection = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyServer::~MyServer()
|
|
|
|
{
|
|
|
|
Disconnect();
|
|
|
|
}
|
|
|
|
|
1999-01-27 10:01:14 +00:00
|
|
|
wxConnectionBase *MyServer::OnAcceptConnection(const wxString& topic)
|
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogMessage("OnAcceptConnection(\"%s\")", topic);
|
2002-04-15 18:24:46 +00:00
|
|
|
|
2005-09-11 18:31:34 +00:00
|
|
|
if ( topic == IPC_TOPIC )
|
|
|
|
{
|
|
|
|
m_connection = new MyConnection();
|
2008-07-14 01:20:33 +00:00
|
|
|
wxGetApp().GetFrame()->UpdateUI();
|
|
|
|
wxLogMessage("Connection accepted");
|
2005-09-11 18:31:34 +00:00
|
|
|
return m_connection;
|
|
|
|
}
|
2008-07-14 01:20:33 +00:00
|
|
|
//else: unknown topic
|
|
|
|
|
|
|
|
wxLogMessage("Unknown topic, connection refused");
|
2002-04-15 18:24:46 +00:00
|
|
|
return NULL;
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:31:34 +00:00
|
|
|
void MyServer::Disconnect()
|
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
if ( m_connection )
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
|
|
|
delete m_connection;
|
|
|
|
m_connection = NULL;
|
2008-07-14 01:20:33 +00:00
|
|
|
wxGetApp().GetFrame()->UpdateUI();
|
|
|
|
wxLogMessage("Disconnected client");
|
2005-09-11 18:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyServer::Advise()
|
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
if ( CanAdvise() )
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00: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 18:31:34 +00:00
|
|
|
|
|
|
|
#if wxUSE_DDE_FOR_IPC
|
2008-07-14 01:20:33 +00: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 18:31:34 +00:00
|
|
|
#endif
|
2008-07-14 01:20:33 +00:00
|
|
|
char bytes[3] = { '1', '2', '3' };
|
|
|
|
m_connection->Advise(m_connection->m_advise, bytes, 3, wxIPC_PRIVATE);
|
2005-09-11 18:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-15 22:34:29 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyConnection
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
bool
|
|
|
|
MyConnection::OnExecute(const wxString& topic,
|
|
|
|
const void *data,
|
|
|
|
size_t size,
|
|
|
|
wxIPCFormat format)
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
Log("OnExecute", topic, "", data, size, format);
|
2005-09-11 18:31:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
bool
|
|
|
|
MyConnection::OnPoke(const wxString& topic,
|
|
|
|
const wxString& item,
|
|
|
|
const void *data,
|
|
|
|
size_t size,
|
|
|
|
wxIPCFormat format)
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
Log("OnPoke", topic, item, data, size, format);
|
2005-09-11 18:31:34 +00:00
|
|
|
return wxConnection::OnPoke(topic, item, data, size, format);
|
|
|
|
}
|
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
const void *
|
|
|
|
MyConnection::OnRequest(const wxString& topic,
|
|
|
|
const wxString& item,
|
|
|
|
size_t *size,
|
|
|
|
wxIPCFormat format)
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
wxString afterDate;
|
|
|
|
if ( item.StartsWith("Date", &afterDate) )
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
const wxDateTime now = wxDateTime::Now();
|
|
|
|
|
|
|
|
if ( afterDate.empty() )
|
|
|
|
{
|
|
|
|
m_requestData = now.Format();
|
|
|
|
*size = wxNO_LEN;
|
|
|
|
}
|
|
|
|
else if ( afterDate == "+len" )
|
|
|
|
{
|
|
|
|
m_requestData = now.FormatTime() + " " + now.FormatDate();
|
|
|
|
*size = strlen(m_requestData.mb_str()) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( item == "bytes[3]" )
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
m_requestData = "123";
|
2005-09-11 18:31:34 +00:00
|
|
|
*size = 3;
|
|
|
|
}
|
2008-07-14 01:20:33 +00:00
|
|
|
|
|
|
|
if ( !*size )
|
2005-09-11 18:31:34 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogMessage("Unknown request for \"%s\"", item);
|
|
|
|
return NULL;
|
2000-01-15 22:34:29 +00:00
|
|
|
}
|
2008-07-14 01:20:33 +00:00
|
|
|
|
|
|
|
const void * const data = m_requestData.mb_str();
|
|
|
|
Log("OnRequest", topic, item, data, *size, format);
|
2005-09-11 18:31:34 +00:00
|
|
|
return data;
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
bool MyConnection::OnStartAdvise(const wxString& topic, const wxString& item)
|
1999-01-27 10:01:14 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogMessage("OnStartAdvise(\"%s\", \"%s\")", topic, item);
|
|
|
|
wxLogMessage("Returning true");
|
|
|
|
m_advise = item;
|
|
|
|
wxGetApp().GetFrame()->UpdateUI();
|
2004-06-02 17:03:20 +00:00
|
|
|
return true;
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
bool MyConnection::OnStopAdvise(const wxString& topic, const wxString& item)
|
1999-01-27 10:01:14 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogMessage("OnStopAdvise(\"%s\",\"%s\")", topic, item);
|
|
|
|
wxLogMessage("Returning true");
|
|
|
|
m_advise.clear();
|
|
|
|
wxGetApp().GetFrame()->UpdateUI();
|
2004-06-02 17:03:20 +00:00
|
|
|
return true;
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
|
|
|
|
2008-07-14 01:20:33 +00:00
|
|
|
bool
|
|
|
|
MyConnection::DoAdvise(const wxString& item,
|
|
|
|
const void *data,
|
|
|
|
size_t size,
|
|
|
|
wxIPCFormat format)
|
1999-01-27 10:01:14 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
Log("Advise", "", item, data, size, format);
|
2007-10-20 22:54:26 +00:00
|
|
|
return wxConnection::DoAdvise(item, data, size, format);
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:31:34 +00:00
|
|
|
bool MyConnection::OnDisconnect()
|
1999-01-27 10:01:14 +00:00
|
|
|
{
|
2008-07-14 01:20:33 +00:00
|
|
|
wxLogMessage("OnDisconnect()");
|
2005-09-11 18:31:34 +00:00
|
|
|
wxGetApp().GetFrame()->Disconnect();
|
2004-06-02 17:03:20 +00:00
|
|
|
return true;
|
1999-01-27 10:01:14 +00:00
|
|
|
}
|