• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kget

authenticationmonitor.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Joris Guisson                                   *
00003  *   joris.guisson@gmail.com                                               *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
00019  ***************************************************************************/
00020 #include "authenticationmonitor.h"
00021 #include <math.h>
00022 #include <unistd.h>
00023 #ifndef Q_WS_WIN
00024 #include <sys/poll.h>
00025 #else
00026 #include <util/mingw.h>
00027 #endif
00028 #include <util/functions.h>
00029 #include <util/log.h>
00030 #include <mse/streamsocket.h>
00031 #include "authenticatebase.h"
00032 #include <kdebug.h>
00033 
00034 
00035 namespace bt
00036 {
00037     AuthenticationMonitor AuthenticationMonitor::self;
00038 
00039     AuthenticationMonitor::AuthenticationMonitor()
00040     {}
00041 
00042 
00043     AuthenticationMonitor::~AuthenticationMonitor()
00044     {
00045         
00046     }
00047     
00048     void AuthenticationMonitor::clear()
00049     {
00050         std::list<AuthenticateBase*>::iterator itr = auths.begin();
00051         while (itr != auths.end())
00052         {
00053             AuthenticateBase* ab = *itr;
00054             ab->deleteLater();
00055             itr++;
00056         }
00057         auths.clear();
00058     }
00059 
00060 
00061     void AuthenticationMonitor::add(AuthenticateBase* s)
00062     {
00063         auths.push_back(s);
00064     }
00065     
00066     void AuthenticationMonitor::remove(AuthenticateBase* s)
00067     {
00068         auths.remove(s);
00069     }
00070     
00071     void AuthenticationMonitor::update()
00072     {
00073         if (auths.size() == 0)
00074             return;
00075         
00076         int i = 0;
00077         
00078         std::list<AuthenticateBase*>::iterator itr = auths.begin();
00079         while (itr != auths.end())
00080         {
00081             AuthenticateBase* ab = *itr;
00082             if (!ab || ab->isFinished())
00083             {
00084                 if (ab)
00085                     ab->deleteLater();
00086                 
00087                 itr = auths.erase(itr);
00088             }
00089             else
00090             {
00091                 ab->setPollIndex(-1);
00092                 if (ab->getSocket() && ab->getSocket()->fd() >= 0)
00093                 {
00094                     int fd = ab->getSocket()->fd();
00095                     if (i >= fd_vec.size())
00096                     {
00097                         struct pollfd pfd = {-1,0,0};
00098                         fd_vec.push_back(pfd);
00099                     }
00100                     
00101                     struct pollfd & pfd = fd_vec[i];
00102                     pfd.fd = fd;
00103                     pfd.revents = 0;
00104                     if (!ab->getSocket()->connecting())
00105                         pfd.events = POLLIN;
00106                     else
00107                         pfd.events = POLLOUT;
00108                     ab->setPollIndex(i);
00109                     i++;
00110                 }
00111                 itr++;
00112             }
00113         }
00114         
00115 #ifndef Q_WS_WIN
00116         if (poll(&fd_vec[0],i,1) > 0)
00117 #else
00118         if (mingw_poll(&fd_vec[0],i,1) > 0)
00119 #endif
00120         {
00121             handleData();
00122         }
00123     }
00124     
00125     void AuthenticationMonitor::handleData()
00126     {
00127         std::list<AuthenticateBase*>::iterator itr = auths.begin();
00128         while (itr != auths.end())
00129         {
00130             AuthenticateBase* ab = *itr;
00131             if (ab && ab->getSocket() && ab->getSocket()->fd() >= 0 && ab->getPollIndex() >= 0)
00132             {
00133                 int pi = ab->getPollIndex();
00134                 if (fd_vec[pi].revents & POLLIN)
00135                 {
00136                     ab->onReadyRead();
00137                 }
00138                 else if (fd_vec[pi].revents & POLLOUT)
00139                 {
00140                     ab->onReadyWrite();
00141                 }
00142             }
00143             
00144             if (!ab || ab->isFinished())
00145             {
00146                 ab->deleteLater();
00147                 itr = auths.erase(itr);
00148             }
00149             else
00150                 itr++;
00151         }
00152     }
00153     
00154 }

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal