]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/gsocketiohandler.cpp
Rework the wxCusor ctor taking wx stock number to provide as many cursors as
[wxWidgets.git] / src / common / gsocketiohandler.cpp
index 35fd89640e56916f87bb90588bed38c8231c6ed5..ece535c02cf910f62727c2b758b5d3a955afaad4 100644 (file)
@@ -2,7 +2,6 @@
 // Name:        src/common/gsocketiohandler.cpp
 // Purpose:     implementation of wxFDIOHandler for GSocket
 // Author:      Angel Vidal, Lukasz Michalski
-// Modified by:
 // Created:     08.24.06
 // RCS-ID:      $Id$
 // Copyright:   (c) 2006 Angel vidal
@@ -20,7 +19,7 @@
 // for compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
-#if wxUSE_SOCKETS
+#if wxUSE_SOCKETS && wxUSE_SELECT_DISPATCHER
 
 #include "wx/private/gsocketiohandler.h"
 #include "wx/unix/private.h"
 // wxGSocketIOHandler
 // ----------------------------------------------------------------------------
 
-wxGSocketIOHandler::wxGSocketIOHandler(GSocket* socket) 
+wxGSocketIOHandler::wxGSocketIOHandler(GSocket* socket)
                   : m_socket(socket),
                     m_flags(0)
 {
 
-};
+}
 
-void wxGSocketIOHandler::OnReadWaiting(int fd)
+void wxGSocketIOHandler::OnReadWaiting()
 {
     m_socket->Detected_Read();
-};
+}
 
-void wxGSocketIOHandler::OnWriteWaiting(int fd) 
+void wxGSocketIOHandler::OnWriteWaiting()
 {
     m_socket->Detected_Write();
-};
+}
 
-void wxGSocketIOHandler::OnExceptionWaiting(int fd) 
+void wxGSocketIOHandler::OnExceptionWaiting()
 {
     m_socket->Detected_Read();
-};
+}
 
-int wxGSocketIOHandler::GetFlags() const 
+int wxGSocketIOHandler::GetFlags() const
 {
     return m_flags;
-};
+}
 
 
-void wxGSocketIOHandler::RemoveFlag(wxSelectDispatcherEntryFlags flag)
+void wxGSocketIOHandler::RemoveFlag(wxFDIODispatcherEntryFlags flag)
 {
     m_flags &= ~flag;
-};
+}
 
-void wxGSocketIOHandler::AddFlag(wxSelectDispatcherEntryFlags flag)
+void wxGSocketIOHandler::AddFlag(wxFDIODispatcherEntryFlags flag)
 {
     m_flags |= flag;
-};
+}
 
 // ----------------------------------------------------------------------------
 // GSocket interface
@@ -113,11 +112,12 @@ void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket,
                                                         GSocketEvent event)
 {
   int *m_id = (int *)(socket->m_gui_dependent);
-  int c;
+  const int fd = socket->m_fd;
 
-  if (socket->m_fd == -1)
+  if ( fd == -1 )
     return;
 
+  int c;
   switch (event)
   {
     case GSOCK_LOST:       /* fall-through */
@@ -127,24 +127,39 @@ void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket,
     default: return;
   }
 
-  wxGSocketIOHandler* handler = (wxGSocketIOHandler*)(wxSelectDispatcher::Get().FindHandler(socket->m_fd));
-  if (handler == NULL)
+  wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
+  if ( !dispatcher )
+      return;
+
+  wxGSocketIOHandler *& handler = socket->m_handler;
+
+  // we should register the new handlers but modify the existing ones in place
+  bool registerHandler;
+  if ( handler )
   {
+      registerHandler = false;
+  }
+  else // no existing handler
+  {
+      registerHandler = true;
       handler = new wxGSocketIOHandler(socket);
-  };
+  }
 
   if (c == 0)
   {
-      m_id[0] = socket->m_fd;
-      handler->AddFlag(wxSelectInput);
+      m_id[0] = fd;
+      handler->AddFlag(wxFDIO_INPUT);
   }
   else
   {
-      m_id[1] = socket->m_fd;
-      handler->AddFlag(wxSelectOutput);
+      m_id[1] = fd;
+      handler->AddFlag(wxFDIO_OUTPUT);
   }
 
-  wxSelectDispatcher::Get().RegisterFD(socket->m_fd,handler,handler->GetFlags());
+  if ( registerHandler )
+      dispatcher->RegisterFD(fd, handler, handler->GetFlags());
+  else
+      dispatcher->ModifyFD(fd, handler, handler->GetFlags());
 }
 
 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket,
@@ -162,26 +177,37 @@ void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket,
     default: return;
   }
 
-  wxGSocketIOHandler* handler = NULL;
-  if ( m_id[c] != -1 )
+  if ( m_id[c] == -1 )
+      return;
+
+  int fd = m_id[c];
+  m_id[c] = -1;
+
+  const wxFDIODispatcherEntryFlags flag = c == 0 ? wxFDIO_INPUT : wxFDIO_OUTPUT;
+
+  wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
+  if ( !dispatcher )
+      return;
+
+  wxGSocketIOHandler *& handler = socket->m_handler;
+  if ( handler )
   {
-      if ( c == 0 )
+      handler->RemoveFlag(flag);
+
+      if ( !handler->GetFlags() )
       {
-          handler = (wxGSocketIOHandler*)wxSelectDispatcher::Get().UnregisterFD(m_id[c], wxSelectInput);
-          if (handler != NULL)
-              handler->RemoveFlag(wxSelectInput);
+          dispatcher->UnregisterFD(fd);
+          delete handler;
       }
       else
       {
-          handler = (wxGSocketIOHandler*)wxSelectDispatcher::Get().UnregisterFD(m_id[c], wxSelectOutput);
-          if (handler != NULL)
-              handler->RemoveFlag(wxSelectOutput);
+          dispatcher->ModifyFD(fd, handler, handler->GetFlags());
       }
-      if (handler && handler->GetFlags() == 0)
-          delete handler;
   }
-
-  m_id[c] = -1;
+  else
+  {
+      dispatcher->UnregisterFD(fd);
+  }
 }
 
 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)