]> git.saurik.com Git - wxWidgets.git/commitdiff
Use CF socket manager in GUI OS X applications.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 16 Aug 2009 23:13:55 +0000 (23:13 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 16 Aug 2009 23:13:55 +0000 (23:13 +0000)
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

include/wx/unix/apptrait.h
src/osx/core/sockosx.cpp
src/osx/core/utilsexc_base.cpp
src/osx/core/utilsexc_cf.cpp

index cd46c08eb5c69f0a394c3565a7f7215ceed19a96..59cb7595cca3e90bd5dcb39b8d21dc37333c4184 100644 (file)
@@ -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:
index 917b821ce1e233b3de9150f53989e8aa77ae88e2..fcd10dbc6ea1826a666ea2f44b122ef69f2b46e9 100644 (file)
@@ -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
index 2720f704aa36e1c2c17b42d0922d5f7780e9fdd9..fe8b87c45e532b26ae44a153d16b1324459bf699 100644 (file)
 // 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 ...
index d503bd59754062d6402559eea007931380c43e9e..95f8bd51d2557638146a801c71ed09539d5a50ad 100644 (file)
@@ -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