rename old wxAppConsole to wxAppConsoleBase and wxAppConsoleUnix to wxAppConsole for consistency with wxAppBase/wxApp and to fix the bug 1729377 (crash when using timers under Unix in console app); also #define wxApp as wxAppConsole instead of declaring it as a real class in console build to avoid problems with ODR violation

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46325 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-06-04 13:39:23 +00:00
parent 74e10fcc6a
commit e0954e729d
4 changed files with 101 additions and 105 deletions

View File

@@ -51,15 +51,15 @@ enum
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAppConsole: wxApp for non-GUI applications // wxAppConsoleBase: wxApp for non-GUI applications
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxAppConsole : public wxEvtHandler class WXDLLIMPEXP_BASE wxAppConsoleBase : public wxEvtHandler
{ {
public: public:
// ctor and dtor // ctor and dtor
wxAppConsole(); wxAppConsoleBase();
virtual ~wxAppConsole(); virtual ~wxAppConsoleBase();
// the virtual functions which may/must be overridden in the derived class // the virtual functions which may/must be overridden in the derived class
@@ -208,11 +208,7 @@ public:
// return true if we're running event loop, i.e. if the events can // return true if we're running event loop, i.e. if the events can
// (already) be dispatched // (already) be dispatched
static bool IsMainLoopRunning() static bool IsMainLoopRunning();
{
const wxAppConsole * const app = GetInstance();
return app && app->m_mainLoop != NULL;
}
// process all events in the wxPendingEvents list -- it is necessary to // process all events in the wxPendingEvents list -- it is necessary to
// call this function to process posted events. This happens during each // call this function to process posted events. This happens during each
@@ -343,9 +339,15 @@ protected:
// the application object is a singleton anyhow, there is no sense in // the application object is a singleton anyhow, there is no sense in
// copying it // copying it
DECLARE_NO_COPY_CLASS(wxAppConsole) DECLARE_NO_COPY_CLASS(wxAppConsoleBase)
}; };
#if defined(__UNIX__)
#include "wx/unix/app.h"
#else
typedef wxAppConsoleBase wxAppConsole;
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAppBase: the common part of wxApp implementations for all platforms // wxAppBase: the common part of wxApp implementations for all platforms
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -537,46 +539,40 @@ protected:
inline bool wxAppBase::Initialized() { return true; } inline bool wxAppBase::Initialized() { return true; }
#endif // WXWIN_COMPATIBILITY_2_6 #endif // WXWIN_COMPATIBILITY_2_6
#endif // wxUSE_GUI
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// now include the declaration of the real class // now include the declaration of the real class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if wxUSE_GUI #if defined(__WXPALMOS__)
#if defined(__WXPALMOS__)
#include "wx/palmos/app.h" #include "wx/palmos/app.h"
#elif defined(__WXMSW__) #elif defined(__WXMSW__)
#include "wx/msw/app.h" #include "wx/msw/app.h"
#elif defined(__WXMOTIF__) #elif defined(__WXMOTIF__)
#include "wx/motif/app.h" #include "wx/motif/app.h"
#elif defined(__WXMGL__) #elif defined(__WXMGL__)
#include "wx/mgl/app.h" #include "wx/mgl/app.h"
#elif defined(__WXDFB__) #elif defined(__WXDFB__)
#include "wx/dfb/app.h" #include "wx/dfb/app.h"
#elif defined(__WXGTK20__) #elif defined(__WXGTK20__)
#include "wx/gtk/app.h" #include "wx/gtk/app.h"
#elif defined(__WXGTK__) #elif defined(__WXGTK__)
#include "wx/gtk1/app.h" #include "wx/gtk1/app.h"
#elif defined(__WXX11__) #elif defined(__WXX11__)
#include "wx/x11/app.h" #include "wx/x11/app.h"
#elif defined(__WXMAC__) #elif defined(__WXMAC__)
#include "wx/mac/app.h" #include "wx/mac/app.h"
#elif defined(__WXCOCOA__) #elif defined(__WXCOCOA__)
#include "wx/cocoa/app.h" #include "wx/cocoa/app.h"
#elif defined(__WXPM__) #elif defined(__WXPM__)
#include "wx/os2/app.h" #include "wx/os2/app.h"
#endif #endif
#else // !GUI #else // !GUI
// wxApp is defined in core and we cannot define another one in wxBase,
// so we create a different class and typedef it to wxApp instead // wxApp is defined in core and we cannot define another one in wxBase,
#if defined(__UNIX__) // so use the preprocessor to allow using wxApp in console programs too
#include "wx/unix/app.h" #define wxApp wxAppConsole
class wxApp : public wxAppConsoleUnix { };
#else
// allow using just wxApp (instead of wxAppConsole) in console programs
class wxApp : public wxAppConsole { };
#endif
#endif // GUI/!GUI #endif // GUI/!GUI
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -12,7 +12,7 @@
#include <signal.h> #include <signal.h>
// wxApp subclass implementing event processing for console applications // wxApp subclass implementing event processing for console applications
class WXDLLIMPEXP_BASE wxAppConsoleUnix : public wxAppConsole class WXDLLIMPEXP_BASE wxAppConsole : public wxAppConsoleBase
{ {
public: public:
// override base class initialization // override base class initialization

View File

@@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: src/common/appbase.cpp // Name: src/common/appbase.cpp
// Purpose: implements wxAppConsole class // Purpose: implements wxAppConsoleBase class
// Author: Vadim Zeitlin // Author: Vadim Zeitlin
// Modified by: // Modified by:
// Created: 19.06.2003 (extracted from common/appcmn.cpp) // Created: 19.06.2003 (extracted from common/appcmn.cpp)
@@ -110,9 +110,9 @@
// global vars // global vars
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxAppConsole *wxAppConsole::ms_appInstance = NULL; wxAppConsole *wxAppConsoleBase::ms_appInstance = NULL;
wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL; wxAppInitializerFunction wxAppConsoleBase::ms_appInitFn = NULL;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxEventLoopPtr // wxEventLoopPtr
@@ -122,19 +122,19 @@ wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL;
wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopBase) wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopBase)
// ============================================================================ // ============================================================================
// wxAppConsole implementation // wxAppConsoleBase implementation
// ============================================================================ // ============================================================================
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// ctor/dtor // ctor/dtor
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxAppConsole::wxAppConsole() wxAppConsoleBase::wxAppConsoleBase()
{ {
m_traits = NULL; m_traits = NULL;
m_mainLoop = NULL; m_mainLoop = NULL;
ms_appInstance = this; ms_appInstance = wx_static_cast(wxAppConsole *, this);
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
SetTraceMasks(); SetTraceMasks();
@@ -148,7 +148,7 @@ wxAppConsole::wxAppConsole()
#endif #endif
} }
wxAppConsole::~wxAppConsole() wxAppConsoleBase::~wxAppConsoleBase()
{ {
delete m_traits; delete m_traits;
} }
@@ -157,7 +157,7 @@ wxAppConsole::~wxAppConsole()
// initilization/cleanup // initilization/cleanup
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxAppConsole::Initialize(int& argcOrig, wxChar **argvOrig) bool wxAppConsoleBase::Initialize(int& argcOrig, wxChar **argvOrig)
{ {
#if wxUSE_INTL #if wxUSE_INTL
GetTraits()->SetLocale(); GetTraits()->SetLocale();
@@ -182,12 +182,12 @@ bool wxAppConsole::Initialize(int& argcOrig, wxChar **argvOrig)
return true; return true;
} }
wxEventLoopBase *wxAppConsole::CreateMainLoop() wxEventLoopBase *wxAppConsoleBase::CreateMainLoop()
{ {
return GetTraits()->CreateEventLoop(); return GetTraits()->CreateEventLoop();
} }
void wxAppConsole::CleanUp() void wxAppConsoleBase::CleanUp()
{ {
if ( m_mainLoop ) if ( m_mainLoop )
{ {
@@ -208,7 +208,7 @@ void wxAppConsole::CleanUp()
// OnXXX() callbacks // OnXXX() callbacks
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxAppConsole::OnInit() bool wxAppConsoleBase::OnInit()
{ {
#if wxUSE_CMDLINE_PARSER #if wxUSE_CMDLINE_PARSER
wxCmdLineParser parser(argc, argv); wxCmdLineParser parser(argc, argv);
@@ -238,12 +238,12 @@ bool wxAppConsole::OnInit()
return true; return true;
} }
int wxAppConsole::OnRun() int wxAppConsoleBase::OnRun()
{ {
return MainLoop(); return MainLoop();
} }
int wxAppConsole::OnExit() int wxAppConsoleBase::OnExit()
{ {
#if wxUSE_CONFIG #if wxUSE_CONFIG
// delete the config object if any (don't use Get() here, but Set() // delete the config object if any (don't use Get() here, but Set()
@@ -254,7 +254,7 @@ int wxAppConsole::OnExit()
return 0; return 0;
} }
void wxAppConsole::Exit() void wxAppConsoleBase::Exit()
{ {
if (m_mainLoop != NULL) if (m_mainLoop != NULL)
ExitMainLoop(); ExitMainLoop();
@@ -266,12 +266,12 @@ void wxAppConsole::Exit()
// traits stuff // traits stuff
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxAppTraits *wxAppConsole::CreateTraits() wxAppTraits *wxAppConsoleBase::CreateTraits()
{ {
return new wxConsoleAppTraits; return new wxConsoleAppTraits;
} }
wxAppTraits *wxAppConsole::GetTraits() wxAppTraits *wxAppConsoleBase::GetTraits()
{ {
// FIXME-MT: protect this with a CS? // FIXME-MT: protect this with a CS?
if ( !m_traits ) if ( !m_traits )
@@ -288,14 +288,14 @@ wxAppTraits *wxAppConsole::GetTraits()
// event processing // event processing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
int wxAppConsole::MainLoop() int wxAppConsoleBase::MainLoop()
{ {
wxEventLoopBaseTiedPtr mainLoop(&m_mainLoop, CreateMainLoop()); wxEventLoopBaseTiedPtr mainLoop(&m_mainLoop, CreateMainLoop());
return m_mainLoop ? m_mainLoop->Run() : -1; return m_mainLoop ? m_mainLoop->Run() : -1;
} }
void wxAppConsole::ExitMainLoop() void wxAppConsoleBase::ExitMainLoop()
{ {
// we should exit from the main event loop, not just any currently active // we should exit from the main event loop, not just any currently active
// (e.g. modal dialog) event loop // (e.g. modal dialog) event loop
@@ -305,7 +305,7 @@ void wxAppConsole::ExitMainLoop()
} }
} }
bool wxAppConsole::Pending() bool wxAppConsoleBase::Pending()
{ {
// use the currently active message loop here, not m_mainLoop, because if // use the currently active message loop here, not m_mainLoop, because if
// we're showing a modal dialog (with its own event loop) currently the // we're showing a modal dialog (with its own event loop) currently the
@@ -315,7 +315,7 @@ bool wxAppConsole::Pending()
return loop && loop->Pending(); return loop && loop->Pending();
} }
bool wxAppConsole::Dispatch() bool wxAppConsoleBase::Dispatch()
{ {
// see comment in Pending() // see comment in Pending()
wxEventLoopBase * const loop = wxEventLoopBase::GetActive(); wxEventLoopBase * const loop = wxEventLoopBase::GetActive();
@@ -323,7 +323,7 @@ bool wxAppConsole::Dispatch()
return loop && loop->Dispatch(); return loop && loop->Dispatch();
} }
bool wxAppConsole::HasPendingEvents() const bool wxAppConsoleBase::HasPendingEvents() const
{ {
// ensure that we're the only thread to modify the pending events list // ensure that we're the only thread to modify the pending events list
wxENTER_CRIT_SECT( *wxPendingEventsLocker ); wxENTER_CRIT_SECT( *wxPendingEventsLocker );
@@ -337,7 +337,15 @@ bool wxAppConsole::HasPendingEvents() const
return true; return true;
} }
void wxAppConsole::ProcessPendingEvents() /* static */
bool wxAppConsoleBase::IsMainLoopRunning()
{
const wxAppConsole * const app = GetInstance();
return app && app->m_mainLoop != NULL;
}
void wxAppConsoleBase::ProcessPendingEvents()
{ {
#if wxUSE_THREADS #if wxUSE_THREADS
if ( !wxPendingEventsLocker ) if ( !wxPendingEventsLocker )
@@ -370,13 +378,13 @@ void wxAppConsole::ProcessPendingEvents()
wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
} }
void wxAppConsole::WakeUpIdle() void wxAppConsoleBase::WakeUpIdle()
{ {
if ( m_mainLoop ) if ( m_mainLoop )
m_mainLoop->WakeUp(); m_mainLoop->WakeUp();
} }
bool wxAppConsole::ProcessIdle() bool wxAppConsoleBase::ProcessIdle()
{ {
wxIdleEvent event; wxIdleEvent event;
@@ -385,7 +393,7 @@ bool wxAppConsole::ProcessIdle()
return event.MoreRequested(); return event.MoreRequested();
} }
int wxAppConsole::FilterEvent(wxEvent& WXUNUSED(event)) int wxAppConsoleBase::FilterEvent(wxEvent& WXUNUSED(event))
{ {
// process the events normally by default // process the events normally by default
return -1; return -1;
@@ -398,7 +406,7 @@ int wxAppConsole::FilterEvent(wxEvent& WXUNUSED(event))
#if wxUSE_EXCEPTIONS #if wxUSE_EXCEPTIONS
void void
wxAppConsole::HandleEvent(wxEvtHandler *handler, wxAppConsoleBase::HandleEvent(wxEvtHandler *handler,
wxEventFunction func, wxEventFunction func,
wxEvent& event) const wxEvent& event) const
{ {
@@ -412,7 +420,7 @@ wxAppConsole::HandleEvent(wxEvtHandler *handler,
#if wxUSE_EXCEPTIONS #if wxUSE_EXCEPTIONS
bool wxAppConsole::OnExceptionInMainLoop() bool wxAppConsoleBase::OnExceptionInMainLoop()
{ {
throw; throw;
@@ -435,7 +443,7 @@ bool wxAppConsole::OnExceptionInMainLoop()
#define OPTION_VERBOSE _T("verbose") #define OPTION_VERBOSE _T("verbose")
void wxAppConsole::OnInitCmdLine(wxCmdLineParser& parser) void wxAppConsoleBase::OnInitCmdLine(wxCmdLineParser& parser)
{ {
// the standard command line options // the standard command line options
static const wxCmdLineEntryDesc cmdLineDesc[] = static const wxCmdLineEntryDesc cmdLineDesc[] =
@@ -474,7 +482,7 @@ void wxAppConsole::OnInitCmdLine(wxCmdLineParser& parser)
parser.SetDesc(cmdLineDesc); parser.SetDesc(cmdLineDesc);
} }
bool wxAppConsole::OnCmdLineParsed(wxCmdLineParser& parser) bool wxAppConsoleBase::OnCmdLineParsed(wxCmdLineParser& parser)
{ {
#if wxUSE_LOG #if wxUSE_LOG
if ( parser.Found(OPTION_VERBOSE) ) if ( parser.Found(OPTION_VERBOSE) )
@@ -488,14 +496,14 @@ bool wxAppConsole::OnCmdLineParsed(wxCmdLineParser& parser)
return true; return true;
} }
bool wxAppConsole::OnCmdLineHelp(wxCmdLineParser& parser) bool wxAppConsoleBase::OnCmdLineHelp(wxCmdLineParser& parser)
{ {
parser.Usage(); parser.Usage();
return false; return false;
} }
bool wxAppConsole::OnCmdLineError(wxCmdLineParser& parser) bool wxAppConsoleBase::OnCmdLineError(wxCmdLineParser& parser)
{ {
parser.Usage(); parser.Usage();
@@ -509,7 +517,7 @@ bool wxAppConsole::OnCmdLineError(wxCmdLineParser& parser)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/* static */ /* static */
bool wxAppConsole::CheckBuildOptions(const char *optionsSignature, bool wxAppConsoleBase::CheckBuildOptions(const char *optionsSignature,
const char *componentName) const char *componentName)
{ {
#if 0 // can't use wxLogTrace, not up and running yet #if 0 // can't use wxLogTrace, not up and running yet
@@ -539,7 +547,7 @@ bool wxAppConsole::CheckBuildOptions(const char *optionsSignature,
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
void wxAppConsole::OnAssertFailure(const wxChar *file, void wxAppConsoleBase::OnAssertFailure(const wxChar *file,
int line, int line,
const wxChar *func, const wxChar *func,
const wxChar *cond, const wxChar *cond,
@@ -548,7 +556,7 @@ void wxAppConsole::OnAssertFailure(const wxChar *file,
ShowAssertDialog(file, line, func, cond, msg, GetTraits()); ShowAssertDialog(file, line, func, cond, msg, GetTraits());
} }
void wxAppConsole::OnAssert(const wxChar *file, void wxAppConsoleBase::OnAssert(const wxChar *file,
int line, int line,
const wxChar *cond, const wxChar *cond,
const wxChar *msg) const wxChar *msg)

View File

@@ -12,19 +12,12 @@
#include "wx/log.h" #include "wx/log.h"
#include "wx/evtloop.h" #include "wx/evtloop.h"
//this code should not be compiled when GUI is defined
//(monolithic build issue)
#if !wxUSE_GUI
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
bool wxAppConsoleUnix::Initialize(int& argc, wxChar** argv) bool wxAppConsole::Initialize(int& argc, wxChar** argv)
{ {
if ( !wxAppConsole::Initialize(argc,argv) ) if ( !wxAppConsoleBase::Initialize(argc,argv) )
return false;
if ( !m_mainLoop->IsOk() )
return false; return false;
sigemptyset(&m_signalsCaught); sigemptyset(&m_signalsCaught);
@@ -32,9 +25,9 @@ bool wxAppConsoleUnix::Initialize(int& argc, wxChar** argv)
return true; return true;
} }
void wxAppConsoleUnix::HandleSignal(int signal) void wxAppConsole::HandleSignal(int signal)
{ {
wxAppConsoleUnix * const app = wxTheApp; wxAppConsole * const app = wxTheApp;
if ( !app ) if ( !app )
return; return;
@@ -42,7 +35,7 @@ void wxAppConsoleUnix::HandleSignal(int signal)
app->WakeUpIdle(); app->WakeUpIdle();
} }
void wxAppConsoleUnix::CheckSignal() void wxAppConsole::CheckSignal()
{ {
for ( SignalHandlerHash::iterator it = m_signalHandlerHash.begin(); for ( SignalHandlerHash::iterator it = m_signalHandlerHash.begin();
it != m_signalHandlerHash.end(); it != m_signalHandlerHash.end();
@@ -57,13 +50,13 @@ void wxAppConsoleUnix::CheckSignal()
} }
} }
bool wxAppConsoleUnix::SetSignalHandler(int signal, SignalHandler handler) bool wxAppConsole::SetSignalHandler(int signal, SignalHandler handler)
{ {
const bool install = handler != SIG_DFL && handler != SIG_IGN; const bool install = handler != SIG_DFL && handler != SIG_IGN;
struct sigaction sa; struct sigaction sa;
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sa_handler = &wxAppConsoleUnix::HandleSignal; sa.sa_handler = &wxAppConsole::HandleSignal;
sa.sa_flags = SA_RESTART; sa.sa_flags = SA_RESTART;
int res = sigaction(signal, &sa, 0); int res = sigaction(signal, &sa, 0);
if ( res != 0 ) if ( res != 0 )
@@ -80,4 +73,3 @@ bool wxAppConsoleUnix::SetSignalHandler(int signal, SignalHandler handler)
return true; return true;
} }
#endif // !wxUSE_GUI