2002-12-04 14:11:26 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: remhelp.cpp
|
|
|
|
// Purpose: Remote help controller class
|
|
|
|
// Author: Eric Dowty
|
2004-06-04 17:58:56 +00:00
|
|
|
// Modified by:
|
2002-12-04 14:11:26 +00:00
|
|
|
// Created: 2002-11-18
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "wx/process.h"
|
|
|
|
#include "wx/confbase.h"
|
|
|
|
|
|
|
|
// Settings common to both executables: determines whether
|
|
|
|
// we're using TCP/IP or real DDE.
|
|
|
|
|
|
|
|
//#include "ddesetup.h"
|
|
|
|
//#define wxUSE_DDE_FOR_IPC 0
|
|
|
|
|
|
|
|
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
|
|
|
#include "mondrian.xpm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "remhelp.h"
|
|
|
|
#include "client.h"
|
|
|
|
|
|
|
|
#if !defined(USE_REMOTE)
|
|
|
|
#include <wx/html/helpctrl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
//////////////////
|
|
|
|
// helper classes
|
|
|
|
|
|
|
|
rhhcClient::rhhcClient( bool *isconn_a )
|
|
|
|
{
|
|
|
|
isconn_2 = isconn_a;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxConnectionBase *rhhcClient::OnMakeConnection()
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
return new rhhcConnection( isconn_2 );
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rhhcConnection::rhhcConnection( bool *isconn_a )
|
|
|
|
: wxConnection()
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
isconn_3 = isconn_a;
|
|
|
|
*isconn_3 = true;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rhhcConnection::~rhhcConnection()
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
*isconn_3 = false;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool rhhcConnection::OnAdvise(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format)
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
return true;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool rhhcConnection::OnDisconnect()
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
*isconn_3 = false;
|
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
return wxConnection::OnDisconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
|
|
|
// wxRemoteHtmlHelpController class
|
|
|
|
|
|
|
|
IMPLEMENT_CLASS(wxRemoteHtmlHelpController, wxHelpControllerBase)
|
|
|
|
|
|
|
|
wxRemoteHtmlHelpController::wxRemoteHtmlHelpController(int style )
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
m_style = style;
|
|
|
|
m_connection = NULL;
|
|
|
|
m_client = NULL;
|
|
|
|
m_pid = 0;
|
|
|
|
isconn_1 = false;
|
|
|
|
m_process = NULL;
|
|
|
|
|
|
|
|
// defaults
|
|
|
|
//
|
|
|
|
// server app is assumed to be local
|
|
|
|
//
|
2002-12-04 14:11:26 +00:00
|
|
|
// for MSW (DDE classes), a_service is 'service name', apparently an arbitrary string
|
|
|
|
// for Unix, should be a valid file name (for a nonexistent file)
|
|
|
|
// for nonMSW, nonUnix, must be port number, for example "4242" (TCP/IP based classes)
|
|
|
|
// should be unique to the client app
|
2004-06-04 17:58:56 +00:00
|
|
|
|
|
|
|
wxString thename = wxGetApp().GetAppName();
|
2002-12-04 14:11:26 +00:00
|
|
|
#if defined(__WXMSW__)
|
2004-06-04 17:58:56 +00:00
|
|
|
m_appname = wxT("helpview.exe");
|
|
|
|
m_service = thename + wxString(wxT("_helpservice"));
|
2002-12-04 14:11:26 +00:00
|
|
|
#elif defined(__UNIX__)
|
2004-06-04 17:58:56 +00:00
|
|
|
m_appname = wxT("./helpview");
|
|
|
|
m_service = wxT("/tmp/") + thename + wxString(wxT("_helpservice"));
|
2002-12-04 14:11:26 +00:00
|
|
|
#else
|
2004-06-04 17:58:56 +00:00
|
|
|
m_appname = wxT("./helpview");
|
|
|
|
m_service = wxT("4242");
|
2002-12-04 14:11:26 +00:00
|
|
|
#endif
|
2004-06-04 17:58:56 +00:00
|
|
|
|
|
|
|
m_book = thename + wxT(".hhp"); // or .htb or .zip
|
|
|
|
m_windowname = thename + wxT(" Help: %s");
|
|
|
|
//underscores for spaces
|
|
|
|
m_windowname.Replace( wxT(" "), wxT("_") );
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxRemoteHtmlHelpController::SetService(wxString& a_service)
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
m_service = a_service;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
void wxRemoteHtmlHelpController::SetServer(wxString& a_appname)
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
m_appname = a_appname;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxRemoteHtmlHelpController::OnQuit()
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
//kill the Server here?
|
|
|
|
//this function is not called ?
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxRemoteHtmlHelpController::~wxRemoteHtmlHelpController()
|
|
|
|
{
|
|
|
|
if ( isconn_1 )
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
// if (!m_connection->Poke( wxT("--YouAreDead"), wxT("") ) )
|
|
|
|
// wxLogError(wxT("wxRemoteHtmlHelpController - YouAreDead Failed"));
|
|
|
|
|
|
|
|
// Kill the server. This could be an option.
|
|
|
|
Quit();
|
|
|
|
|
|
|
|
m_connection->Disconnect();
|
2002-12-04 14:11:26 +00:00
|
|
|
delete m_connection;
|
2004-06-04 17:58:56 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
delete m_process;
|
|
|
|
m_process = NULL;
|
|
|
|
}
|
|
|
|
if( m_client )
|
2004-06-04 17:58:56 +00:00
|
|
|
delete m_client; //should be automatic?
|
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxRemoteHtmlHelpController::DoConnection()
|
|
|
|
{
|
|
|
|
wxString cmd, blank;
|
|
|
|
int nsleep;
|
2004-06-04 17:58:56 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
blank = wxT(" ");
|
2004-06-04 17:58:56 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
// ignored under DDE, host name in TCP/IP based classes
|
|
|
|
wxString hostName = wxT("localhost");
|
2004-06-04 17:58:56 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
// Create a new client
|
|
|
|
if( !m_client ) m_client = new rhhcClient(&isconn_1);
|
2004-06-04 17:58:56 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
nsleep = 0;
|
2004-06-04 17:58:56 +00:00
|
|
|
|
|
|
|
// suppress the log messages from MakeConnection()
|
2002-12-04 14:11:26 +00:00
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
wxLogNull nolog;
|
|
|
|
|
|
|
|
//first try to connect assuming server is running
|
|
|
|
if( !isconn_1 )
|
|
|
|
m_connection = (rhhcConnection *)m_client->MakeConnection(hostName, m_service, wxT("HELP") );
|
|
|
|
|
|
|
|
//if not, start server
|
|
|
|
if( !isconn_1 ) {
|
|
|
|
|
|
|
|
wxString stylestr;
|
|
|
|
stylestr.Printf( wxT("--Style%d"), m_style );
|
|
|
|
|
|
|
|
cmd = m_appname + blank + m_service + blank + m_windowname + blank + m_book + blank + stylestr;
|
|
|
|
|
|
|
|
m_process = new wxProcess(NULL);
|
|
|
|
m_pid = wxExecute( cmd, false, m_process );
|
|
|
|
// leaks - wxExecute itself (if not deleted) and in wxExecute at
|
|
|
|
// wxExecuteData *data = new wxExecuteData;
|
|
|
|
if( m_pid <= 0 ) {
|
|
|
|
wxLogError( wxT("wxRemoteHtmlHelpController - Failed to start Help server") );
|
|
|
|
return false;
|
|
|
|
}
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
2004-06-04 17:58:56 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
while ( !isconn_1 )
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
//try every second for a while, then leave it to user
|
|
|
|
wxSleep(1);
|
|
|
|
if( nsleep > 4 ) {
|
|
|
|
if ( wxMessageBox( wxT("Failed to make connection to Help server.\nRetry?") ,
|
|
|
|
wxT("wxRemoteHtmlHelpController Error"),
|
|
|
|
wxICON_ERROR | wxYES_NO | wxCANCEL ) != wxYES )
|
|
|
|
{
|
|
|
|
// no server
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsleep++;
|
|
|
|
|
|
|
|
m_connection = (rhhcConnection *)m_client->MakeConnection(hostName, m_service, wxT("HELP") );
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-04 17:58:56 +00:00
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
if (!m_connection->StartAdvise(wxT("Item"))) {
|
2004-06-04 17:58:56 +00:00
|
|
|
wxLogError(wxT("wxRemoteHtmlHelpController - StartAdvise failed") );
|
|
|
|
return false;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
2004-06-04 17:58:56 +00:00
|
|
|
|
|
|
|
return true;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxRemoteHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
return true;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
bool wxRemoteHtmlHelpController::DisplaySection(int sectionNo)
|
|
|
|
{
|
|
|
|
Display(sectionNo);
|
2004-06-04 17:58:56 +00:00
|
|
|
return true;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
bool wxRemoteHtmlHelpController::DisplayBlock(long blockNo)
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
return DisplaySection((int)blockNo);
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxRemoteHtmlHelpController::Quit()
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
//this code from exec sample - branches left in for testing
|
|
|
|
// sig = 3, 6, 9 or 12 all kill server with no apparent problem
|
|
|
|
// but give error message on MSW - timout?
|
|
|
|
int sig = 15; //3 = quit; 6 = abort; 9 = kill; 15 = terminate
|
|
|
|
|
|
|
|
/*
|
|
|
|
switch ( sig )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( _T("unexpected return value") );
|
|
|
|
// fall through
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
// cancelled
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case wxSIGNONE:
|
|
|
|
case wxSIGHUP:
|
|
|
|
case wxSIGINT:
|
|
|
|
case wxSIGQUIT:
|
|
|
|
case wxSIGILL:
|
|
|
|
case wxSIGTRAP:
|
|
|
|
case wxSIGABRT:
|
|
|
|
case wxSIGEMT:
|
|
|
|
case wxSIGFPE:
|
|
|
|
case wxSIGKILL:
|
|
|
|
case wxSIGBUS:
|
|
|
|
case wxSIGSEGV:
|
|
|
|
case wxSIGSYS:
|
|
|
|
case wxSIGPIPE:
|
|
|
|
case wxSIGALRM:
|
|
|
|
case wxSIGTERM:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
if ( sig == 0 )
|
|
|
|
{
|
|
|
|
if ( wxProcess::Exists(m_pid) )
|
|
|
|
wxLogStatus(_T("Process %ld is running."), m_pid);
|
|
|
|
else
|
|
|
|
wxLogStatus(_T("No process with pid = %ld."), m_pid);
|
|
|
|
}
|
|
|
|
else // not SIGNONE
|
|
|
|
{
|
|
|
|
wxKillError rc = wxProcess::Kill(m_pid, (wxSignal)sig);
|
|
|
|
if ( rc == wxKILL_OK )
|
|
|
|
{
|
|
|
|
wxLogStatus(_T("Process %ld killed with signal %d."), m_pid, sig);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const wxChar *errorText[] =
|
|
|
|
{
|
|
|
|
_T(""), // no error
|
2004-06-04 17:58:56 +00:00
|
|
|
_T("signal not supported"),
|
|
|
|
_T("permission denied"),
|
|
|
|
_T("no such process"),
|
|
|
|
_T("unspecified error"),
|
2002-12-04 14:11:26 +00:00
|
|
|
};
|
2004-06-04 17:58:56 +00:00
|
|
|
|
|
|
|
// sig = 3, 6, 9 or 12 all kill server with no apparent problem
|
|
|
|
// but give error message on MSW - timout?
|
|
|
|
//
|
2002-12-04 14:11:26 +00:00
|
|
|
//wxLogError(_T("Failed to kill process %ld with signal %d: %s"),
|
|
|
|
// m_pid, sig, errorText[rc]);
|
|
|
|
}
|
|
|
|
}
|
2004-06-04 17:58:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxRemoteHtmlHelpController::Display(const wxString& helpfile)
|
|
|
|
{
|
|
|
|
if( !isconn_1 ) {
|
|
|
|
if( !DoConnection() ) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_connection->Execute( helpfile, -1 ) )
|
2004-06-04 17:58:56 +00:00
|
|
|
wxLogError(wxT("wxRemoteHtmlHelpController - Display Failed"));
|
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxRemoteHtmlHelpController::Display(const int id)
|
|
|
|
{
|
|
|
|
if( !isconn_1 ) {
|
|
|
|
if( !DoConnection() ) return;
|
|
|
|
}
|
2004-06-04 17:58:56 +00:00
|
|
|
|
|
|
|
wxString intstring;
|
|
|
|
intstring.Printf( "--intstring%d", id );
|
2002-12-04 14:11:26 +00:00
|
|
|
|
|
|
|
if (!m_connection->Execute( intstring, -1 ) )
|
2004-06-04 17:58:56 +00:00
|
|
|
wxLogError(wxT("wxRemoteHtmlHelpController - Display Failed"));
|
|
|
|
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxRemoteHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
//ignore show_wait_msg - there shouldn't be a delay in this step
|
|
|
|
//show_wait_msg = true could be transmitted with ++AddBook
|
|
|
|
m_book = book;
|
|
|
|
|
|
|
|
if( isconn_1 ) {
|
|
|
|
if (!m_connection->Poke( wxT("--AddBook"), (char*)book.c_str() ) )
|
|
|
|
wxLogError(wxT("wxRemoteHtmlHelpController - AddBook Failed"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wxRemoteHtmlHelpController::DisplayContents()
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
if( isconn_1 ) {
|
|
|
|
if (!m_connection->Poke( wxT("--DisplayContents"), wxT("") ) ) {
|
|
|
|
wxLogError(wxT("wxRemoteHtmlHelpController - DisplayContents Failed"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
void wxRemoteHtmlHelpController::DisplayIndex()
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
if( isconn_1 ) {
|
|
|
|
if (!m_connection->Poke( wxT("--DisplayIndex"), wxT("") ) )
|
|
|
|
wxLogError(wxT("wxRemoteHtmlHelpController - DisplayIndex Failed"));
|
|
|
|
}
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
bool wxRemoteHtmlHelpController::KeywordSearch(const wxString& keyword)
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
if( isconn_1 ) {
|
|
|
|
if (!m_connection->Poke( wxT("--KeywordSearch"), (char*)keyword.c_str() ) ) {
|
|
|
|
wxLogError(wxT("wxRemoteHtmlHelpController - KeywordSearch Failed"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxRemoteHtmlHelpController::SetTitleFormat(const wxString& format)
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
m_windowname = format;
|
|
|
|
m_windowname.Replace( wxT(" "), wxT("_") );
|
|
|
|
|
|
|
|
if( isconn_1 ) {
|
|
|
|
if (!m_connection->Poke( wxT("--SetTitleFormat"), (char*)format.c_str() ) )
|
|
|
|
wxLogError(wxT("wxRemoteHtmlHelpController - SetTitleFormat Failed"));
|
|
|
|
}
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxRemoteHtmlHelpController::SetTempDir(const wxString& path)
|
|
|
|
{
|
2004-06-04 17:58:56 +00:00
|
|
|
if( isconn_1 ) {
|
|
|
|
if (!m_connection->Poke( wxT("--SetTempDir"), (char*)path.c_str() ) )
|
|
|
|
wxLogError(wxT("wxRemoteHtmlHelpController - SetTempDir Failed"));
|
|
|
|
}
|
2002-12-04 14:11:26 +00:00
|
|
|
}
|
|
|
|
|