1999-01-27 05:01:14 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: client.cpp
|
|
|
|
// Purpose: DDE sample: client
|
|
|
|
// 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
|
|
|
|
// 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
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
#include "wx/datetime.h"
|
1999-01-27 05:01:14 -05:00
|
|
|
#include "client.h"
|
|
|
|
|
2012-03-03 19:28:58 -05:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2010-06-20 13:42:33 -04:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
2000-01-15 17:34:29 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxWin macros
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-01-27 05:01:14 -05:00
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_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_CHOICE( ID_HOSTNAME, MyFrame::OnHostname )
|
|
|
|
EVT_CHOICE( ID_TOPIC, MyFrame::OnTopic )
|
|
|
|
EVT_BUTTON( ID_DISCONNECT, MyFrame::OnDisconnect )
|
|
|
|
EVT_BUTTON( ID_STARTADVISE, MyFrame::OnStartAdvise )
|
|
|
|
EVT_BUTTON( ID_STOPADVISE, MyFrame::OnStopAdvise )
|
|
|
|
EVT_BUTTON( ID_POKE, MyFrame::OnPoke )
|
|
|
|
EVT_BUTTON( ID_EXECUTE, MyFrame::OnExecute )
|
|
|
|
EVT_BUTTON( ID_REQUEST, MyFrame::OnRequest )
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2000-01-15 17:34:29 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// globals
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-01-27 05:01:14 -05:00
|
|
|
// The `main program' equivalent, creating the windows and returning the
|
|
|
|
// main frame
|
|
|
|
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
|
2009-07-23 16:30:22 -04:00
|
|
|
m_frame = new MyFrame(NULL, wxT("Client"));
|
2005-09-11 14:31:34 -04:00
|
|
|
m_frame->Show(true);
|
2000-01-05 20:21:26 -05:00
|
|
|
|
2004-06-02 13:03:20 -04:00
|
|
|
return true;
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int MyApp::OnExit()
|
|
|
|
{
|
2002-03-17 09:16:03 -05:00
|
|
|
|
1999-01-27 05:01:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define my frame constructor
|
2000-01-15 17:34:29 -05:00
|
|
|
MyFrame::MyFrame(wxFrame *frame, const wxString& title)
|
2005-09-11 14:31:34 -04:00
|
|
|
: wxFrame(frame, wxID_ANY, title, wxDefaultPosition, wxSize(400, 300))
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2000-01-15 17:34:29 -05:00
|
|
|
// Give it an icon
|
2010-06-20 13:42:33 -04:00
|
|
|
SetIcon(wxICON(sample));
|
2000-01-15 17:34:29 -05:00
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
file_menu->Append(wxID_EXIT, wxT("&Quit\tCtrl-Q"));
|
2000-01-15 17:34:29 -05:00
|
|
|
|
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
menu_bar->Append(file_menu, wxT("&File"));
|
2000-01-15 17:34:29 -05:00
|
|
|
|
|
|
|
// Associate the menu bar with the frame
|
|
|
|
SetMenuBar(menu_bar);
|
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
// set a dialog background
|
|
|
|
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
|
|
|
|
|
|
|
// add the controls to the frame
|
2006-01-16 11:09:49 -05:00
|
|
|
wxString strs4[] =
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
IPC_SERVICE, wxT("...")
|
2005-09-11 14:31:34 -04:00
|
|
|
};
|
2006-01-16 11:09:49 -05:00
|
|
|
wxString strs5[] =
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
IPC_HOST, wxT("...")
|
2005-09-11 14:31:34 -04:00
|
|
|
};
|
2006-01-16 11:09:49 -05:00
|
|
|
wxString strs6[] =
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
IPC_TOPIC, wxT("...")
|
2005-09-11 14:31:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
|
|
|
wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
|
|
|
wxGridSizer *item2 = new wxGridSizer( 4, 0, 0 );
|
|
|
|
|
|
|
|
wxButton *item3 = new wxButton( this, ID_START, wxT("Connect to server"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
item2->Add( item3, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
wxChoice *item5 = new wxChoice( this, ID_HOSTNAME, wxDefaultPosition, wxSize(100,-1), 2, strs5, 0 );
|
|
|
|
item2->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
wxChoice *item4 = new wxChoice( this, ID_SERVERNAME, wxDefaultPosition, wxSize(100,-1), 2, strs4, 0 );
|
|
|
|
item2->Add( item4, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
wxChoice *item6 = new wxChoice( this, ID_TOPIC, wxDefaultPosition, wxSize(100,-1), 2, strs6, 0 );
|
|
|
|
item2->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
wxButton *item7 = new wxButton( this, ID_DISCONNECT, wxT("Disconnect "), wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
item2->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
wxButton *item8 = new wxButton( this, ID_STARTADVISE, wxT("StartAdvise"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
item2->Add( item8, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
wxButton *item9 = new wxButton( this, ID_STOPADVISE, wxT("StopAdvise"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
item2->Add( item9, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
wxButton *item10 = new wxButton( this, ID_EXECUTE, wxT("Execute"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
item2->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
wxButton *item11 = new wxButton( this, ID_POKE, wxT("Poke"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
item2->Add( item11, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
item2->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
|
|
|
|
|
|
|
|
wxButton *item12 = new wxButton( this, ID_REQUEST, wxT("Request"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
item2->Add( item12, 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 *item14 = new wxStaticBox( this, -1, wxT("Client log") );
|
|
|
|
wxStaticBoxSizer *item13 = new wxStaticBoxSizer( item14, wxVERTICAL );
|
|
|
|
|
2006-01-16 11:09:49 -05:00
|
|
|
wxTextCtrl *item15 = new wxTextCtrl( this, ID_LOG, wxEmptyString, wxDefaultPosition, wxSize(500,140), wxTE_MULTILINE );
|
2005-09-11 14:31:34 -04:00
|
|
|
item13->Add( item15, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
item0->Add( item13, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
this->SetSizer( item0 );
|
|
|
|
item0->SetSizeHints( this );
|
|
|
|
|
|
|
|
// status
|
|
|
|
m_client = NULL;
|
|
|
|
GetServername()->SetSelection(0);
|
|
|
|
GetHostname()->SetSelection(0);
|
|
|
|
GetTopic()->SetSelection(0);
|
|
|
|
wxLogTextCtrl *logWindow = new wxLogTextCtrl(GetLog());
|
|
|
|
delete wxLog::SetActiveTarget(logWindow);
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Click on Connect to connect to the server"));
|
2006-01-16 11:09:49 -05:00
|
|
|
EnableControls();
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
|
2006-01-16 11:09:49 -05:00
|
|
|
void MyFrame::EnableControls()
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
|
|
|
GetStart()->Enable(m_client == NULL);
|
|
|
|
GetServername()->Enable(m_client == NULL);
|
|
|
|
GetHostname()->Enable(m_client == NULL);
|
|
|
|
GetTopic()->Enable(m_client == NULL);
|
2005-11-27 09:03:36 -05:00
|
|
|
|
2006-10-26 12:49:39 -04:00
|
|
|
const bool isConnected = (m_client != NULL && m_client->IsConnected());
|
2005-11-27 09:03:36 -05:00
|
|
|
GetDisconnect()->Enable(m_client != NULL && isConnected);
|
|
|
|
GetStartAdvise()->Enable(m_client != NULL && isConnected);
|
|
|
|
GetStopAdvise()->Enable(m_client != NULL && isConnected);
|
|
|
|
GetExecute()->Enable(m_client != NULL && isConnected);
|
|
|
|
GetPoke()->Enable(m_client != NULL && isConnected);
|
|
|
|
GetRequest()->Enable(m_client != NULL && isConnected);
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
2010-10-07 16:43:20 -04:00
|
|
|
wxDELETE(m_client);
|
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnStart(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// Connect to the client
|
|
|
|
wxString servername = GetServername()->GetStringSelection();
|
|
|
|
wxString hostname = GetHostname()->GetStringSelection();
|
|
|
|
wxString topic = GetTopic()->GetStringSelection();
|
|
|
|
|
|
|
|
m_client = new MyClient;
|
|
|
|
bool retval = m_client->Connect(hostname, servername, topic);
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Client host=\"%s\" port=\"%s\" topic=\"%s\" %s"),
|
2005-09-11 14:31:34 -04:00
|
|
|
hostname.c_str(), servername.c_str(), topic.c_str(),
|
2009-07-23 16:30:22 -04:00
|
|
|
retval ? wxT("connected") : wxT("failed to connect"));
|
2005-09-11 14:31:34 -04:00
|
|
|
|
|
|
|
if (!retval)
|
|
|
|
{
|
2010-06-20 14:18:23 -04:00
|
|
|
wxDELETE(m_client);
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
2006-10-26 12:49:39 -04:00
|
|
|
EnableControls();
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnServername( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
if (GetServername()->GetStringSelection() == wxT("..."))
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxString s = wxGetTextFromUser(wxT("Specify the name of the server"),
|
|
|
|
wxT("Server Name"), wxEmptyString, this);
|
2005-09-11 14:31:34 -04:00
|
|
|
if (!s.IsEmpty() && s != IPC_SERVICE)
|
|
|
|
{
|
|
|
|
GetServername()->Insert(s, 0);
|
|
|
|
GetServername()->SetSelection(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnHostname( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
if (GetHostname()->GetStringSelection() == wxT("..."))
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxString s = wxGetTextFromUser(wxT("Specify the name of the host (ignored under DDE)"),
|
|
|
|
wxT("Host Name"), wxEmptyString, this);
|
2005-09-11 14:31:34 -04:00
|
|
|
if (!s.IsEmpty() && s != IPC_HOST)
|
|
|
|
{
|
|
|
|
GetHostname()->Insert(s, 0);
|
|
|
|
GetHostname()->SetSelection(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnTopic( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
if (GetTopic()->GetStringSelection() == wxT("..."))
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxString s = wxGetTextFromUser(wxT("Specify the name of the topic"),
|
|
|
|
wxT("Topic Name"), wxEmptyString, this);
|
2005-09-11 14:31:34 -04:00
|
|
|
if (!s.IsEmpty() && s != IPC_TOPIC)
|
|
|
|
{
|
|
|
|
GetTopic()->Insert(s, 0);
|
|
|
|
GetTopic()->SetSelection(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnDisconnect(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2006-01-16 11:09:49 -05:00
|
|
|
Disconnect();
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::Disconnect()
|
|
|
|
{
|
2010-06-20 14:18:23 -04:00
|
|
|
wxDELETE(m_client);
|
2006-10-26 12:49:39 -04:00
|
|
|
EnableControls();
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnStartAdvise(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
m_client->GetConnection()->StartAdvise(wxT("something"));
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnStopAdvise(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
m_client->GetConnection()->StopAdvise(wxT("something"));
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2003-09-09 16:24:34 -04:00
|
|
|
void MyFrame::OnExecute(wxCommandEvent& WXUNUSED(event))
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2005-09-11 14:31:34 -04:00
|
|
|
if (m_client->IsConnected())
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxString s = wxT("Date");
|
2005-09-11 14:31:34 -04:00
|
|
|
|
2007-10-20 18:54:26 -04:00
|
|
|
m_client->GetConnection()->Execute(s);
|
|
|
|
m_client->GetConnection()->Execute((const char *)s.c_str(), s.length() + 1);
|
2005-09-11 14:31:34 -04:00
|
|
|
char bytes[3];
|
2008-02-10 18:43:39 -05:00
|
|
|
bytes[0] = '1';
|
|
|
|
bytes[1] = '2';
|
|
|
|
bytes[2] = '3';
|
|
|
|
m_client->GetConnection()->Execute(bytes, WXSIZEOF(bytes));
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2003-09-09 16:24:34 -04:00
|
|
|
void MyFrame::OnPoke(wxCommandEvent& WXUNUSED(event))
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2005-09-11 14:31:34 -04:00
|
|
|
if (m_client->IsConnected())
|
|
|
|
{
|
|
|
|
wxString s = wxDateTime::Now().Format();
|
2009-07-23 16:30:22 -04:00
|
|
|
m_client->GetConnection()->Poke(wxT("Date"), s);
|
|
|
|
s = wxDateTime::Now().FormatTime() + wxT(" ") + wxDateTime::Now().FormatDate();
|
|
|
|
m_client->GetConnection()->Poke(wxT("Date"), (const char *)s.c_str(), s.length() + 1);
|
2005-09-11 14:31:34 -04:00
|
|
|
char bytes[3];
|
|
|
|
bytes[0] = '1'; bytes[1] = '2'; bytes[2] = '3';
|
2009-07-23 16:30:22 -04:00
|
|
|
m_client->GetConnection()->Poke(wxT("bytes[3]"), bytes, 3, wxIPC_PRIVATE);
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2003-09-09 16:24:34 -04:00
|
|
|
void MyFrame::OnRequest(wxCommandEvent& WXUNUSED(event))
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2005-09-11 14:31:34 -04:00
|
|
|
if (m_client->IsConnected())
|
2000-01-15 17:34:29 -05:00
|
|
|
{
|
2007-10-20 18:54:26 -04:00
|
|
|
size_t size;
|
2009-07-23 16:30:22 -04:00
|
|
|
m_client->GetConnection()->Request(wxT("Date"));
|
|
|
|
m_client->GetConnection()->Request(wxT("Date+len"), &size);
|
|
|
|
m_client->GetConnection()->Request(wxT("bytes[3]"), &size, wxIPC_PRIVATE);
|
2000-01-15 17:34:29 -05:00
|
|
|
}
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyClient
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
MyClient::MyClient() : wxClient()
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2005-09-11 14:31:34 -04:00
|
|
|
m_connection = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MyClient::Connect(const wxString& sHost, const wxString& sService, const wxString& sTopic)
|
|
|
|
{
|
|
|
|
// suppress the log messages from MakeConnection()
|
|
|
|
wxLogNull nolog;
|
2006-01-16 11:09:49 -05:00
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
m_connection = (MyConnection *)MakeConnection(sHost, sService, sTopic);
|
|
|
|
return m_connection != NULL;
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2000-01-15 17:34:29 -05:00
|
|
|
wxConnectionBase *MyClient::OnMakeConnection()
|
1999-01-27 05:01:14 -05:00
|
|
|
{
|
2000-01-15 17:34:29 -05:00
|
|
|
return new MyConnection;
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
2005-09-11 14:31:34 -04:00
|
|
|
void MyClient::Disconnect()
|
|
|
|
{
|
|
|
|
if (m_connection)
|
|
|
|
{
|
|
|
|
m_connection->Disconnect();
|
2010-06-20 14:18:23 -04:00
|
|
|
wxDELETE(m_connection);
|
2006-10-26 12:49:39 -04:00
|
|
|
wxGetApp().GetFrame()->EnableControls();
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Client disconnected from server"));
|
2005-09-11 14:31:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MyClient::~MyClient()
|
|
|
|
{
|
|
|
|
Disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyConnection
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2007-10-20 18:54:26 -04:00
|
|
|
bool MyConnection::OnAdvise(const wxString& topic, const wxString& item, const void *data,
|
|
|
|
size_t size, wxIPCFormat format)
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
Log(wxT("OnAdvise"), topic, item, data, size, format);
|
2004-06-02 13:03:20 -04:00
|
|
|
return true;
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MyConnection::OnDisconnect()
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("OnDisconnect()"));
|
2005-09-11 14:31:34 -04:00
|
|
|
wxGetApp().GetFrame()->Disconnect();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-10-20 18:54:26 -04:00
|
|
|
bool MyConnection::DoExecute(const void *data, size_t size, wxIPCFormat format)
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
Log(wxT("Execute"), wxEmptyString, wxEmptyString, data, size, format);
|
2007-10-20 18:54:26 -04:00
|
|
|
bool retval = wxConnection::DoExecute(data, size, format);
|
2005-09-11 14:31:34 -04:00
|
|
|
if (!retval)
|
2009-07-20 12:47:54 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Execute failed!"));
|
2009-07-20 12:47:54 -04:00
|
|
|
}
|
2005-09-11 14:31:34 -04:00
|
|
|
return retval;
|
|
|
|
}
|
1999-01-27 05:01:14 -05:00
|
|
|
|
2007-10-20 18:54:26 -04:00
|
|
|
const void *MyConnection::Request(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 = wxConnection::Request(item, size, format);
|
2009-07-23 16:30:22 -04:00
|
|
|
Log(wxT("Request"), wxEmptyString, item, data, size ? *size : wxNO_LEN, format);
|
2005-09-11 14:31:34 -04:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2007-10-20 18:54:26 -04:00
|
|
|
bool MyConnection::DoPoke(const wxString& item, const void *data, size_t size, wxIPCFormat format)
|
2005-09-11 14:31:34 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
Log(wxT("Poke"), wxEmptyString, item, data, size, format);
|
2007-10-20 18:54:26 -04:00
|
|
|
return wxConnection::DoPoke(item, data, size, format);
|
1999-01-27 05:01:14 -05:00
|
|
|
}
|