From: Vadim Zeitlin Date: Sun, 16 Aug 2009 23:13:55 +0000 (+0000) Subject: Use CF socket manager in GUI OS X applications. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5815e95907dbecbac1e6d4d9cf3290f8d36eca48 Use CF socket manager in GUI OS X applications. wxSocketManagerMac was never created under OS X since wxSocket code refactoring as wxGUIAppTraits::GetSocketManager() wasn't overridden. Doing this required an extra nasty hack with a global variable in the base library which is used just to pass the socket manager pointer from the net library to the core one without creating a dependency between them but this seems unfortunately unavoidable. See #11030. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61676 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/unix/apptrait.h b/include/wx/unix/apptrait.h index cd46c08eb5..59cb7595cc 100644 --- a/include/wx/unix/apptrait.h +++ b/include/wx/unix/apptrait.h @@ -35,16 +35,12 @@ public: // // TODO: Should we use XtAddInput() for wxX11 too? Or, vice versa, if there is // no advantage in doing this compared to the generic way currently used -// by wxX11, should we continue to use GTK/Motif- specific stuff? -#if defined(__WXGTK__) || defined(__WXMOTIF__) +// by wxX11, should we continue to use GTK/Motif-specific stuff? +#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) #define wxHAS_GUI_PROCESS_CALLBACKS #define wxHAS_GUI_SOCKET_MANAGER #endif -#ifdef __DARWIN__ - #define wxHAS_GUI_PROCESS_CALLBACKS -#endif - class WXDLLIMPEXP_CORE wxGUIAppTraits : public wxGUIAppTraitsBase { public: diff --git a/src/osx/core/sockosx.cpp b/src/osx/core/sockosx.cpp index 917b821ce1..fcd10dbc6e 100644 --- a/src/osx/core/sockosx.cpp +++ b/src/osx/core/sockosx.cpp @@ -254,17 +254,21 @@ void wxSocketManagerMac::Uninstall_Callback(wxSocketImpl *socket_, CFSocketDisableCallBacks(socket->GetSocket(), GetCFCallback(socket, event)); } -// set the wxBase variable to point to our wxSocketManager implementation +// set the wxBase variable to point to CF wxSocketManager implementation so +// that the GUI code in utilsexc_cf.cpp could return it from its traits method // -// see comments in wx/apptrait.h for the explanation of why do we do it -// like this -static struct ManagerSetter +// this is very roundabout but necessary to allow us to have different +// behaviours in console and GUI applications while avoiding dependencies of +// GUI library on the network one +extern WXDLLIMPEXP_BASE wxSocketManager *wxOSXSocketManagerCF; + +static struct OSXManagerSetter { - ManagerSetter() + OSXManagerSetter() { static wxSocketManagerMac s_manager; - wxAppTraits::SetDefaultSocketManager(&s_manager); + wxOSXSocketManagerCF = &s_manager; } -} gs_managerSetter; +} gs_OSXManagerSetter; #endif // wxUSE_SOCKETS diff --git a/src/osx/core/utilsexc_base.cpp b/src/osx/core/utilsexc_base.cpp index 2720f704aa..fe8b87c45e 100644 --- a/src/osx/core/utilsexc_base.cpp +++ b/src/osx/core/utilsexc_base.cpp @@ -45,6 +45,15 @@ // Default path style #define kDefaultPathStyle kCFURLPOSIXPathStyle +#if wxUSE_SOCKETS +// global pointer which lives in the base library, set from the net one (see +// sockosx.cpp) and used from the GUI code (see utilsexc_cf.cpp) -- ugly but +// needed hack, see the above-mentioned files for more information +class wxSocketManager; +extern WXDLLIMPEXP_BASE wxSocketManager *wxOSXSocketManagerCF; +wxSocketManager *wxOSXSocketManagerCF = NULL; +#endif // wxUSE_SOCKETS + extern bool WXDLLEXPORT wxIsDebuggerRunning() { // TODO : try to find out ... diff --git a/src/osx/core/utilsexc_cf.cpp b/src/osx/core/utilsexc_cf.cpp index d503bd5975..95f8bd51d2 100644 --- a/src/osx/core/utilsexc_cf.cpp +++ b/src/osx/core/utilsexc_cf.cpp @@ -116,3 +116,19 @@ wxStandardPaths& wxGUIAppTraits::GetStandardPaths() } #endif +#if wxUSE_SOCKETS + +// we need to implement this method in a file of the core library as it should +// only be used for the GUI applications but we can't use socket stuff from it +// directly as this would create unwanted dependencies of core on net library +// +// so we have this global pointer which is set from sockosx.cpp when it is +// linked in and we simply return it from here +extern WXDLLIMPEXP_BASE wxSocketManager *wxOSXSocketManagerCF; +wxSocketManager *wxGUIAppTraits::GetSocketManager() +{ + return wxOSXSocketManagerCF ? wxOSXSocketManagerCF + : wxGUIAppTraitsBase::GetSocketManager(); +} + +#endif // wxUSE_SOCKETS