Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

DCCache.h

00001 /*
00002  * DCCache
00003  *
00004  * Copyright (C) 2001 Barnaby Gray <barnaby@beedesign.co.uk>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef DCCACHE_H
00023 #define DCCACHE_H
00024 
00025 #include <libicq2000/Cache.h>
00026 
00027 #include <sigc++/signal_system.h>
00028 
00029 using SigC::Signal1;
00030 
00031 namespace ICQ2000 {
00032 
00033   /* fd -> DirectClient cache
00034    *
00035    * Where the party is at. Once a DirectClient object is added to the
00036    * cache MM for it is assumed on the cache. Also lookups for a
00037    * Contact are done in linear time now, it was just too much of a
00038    * head-ache maintaining the uin map in Client.
00039    */
00040   class DCCache : public Cache<int, DirectClient*> {
00041    public:
00042     DCCache() { }
00043 
00044     void removeItem(const DCCache::literator& l) {
00045       delete ((*l).getValue());
00046       Cache<int, DirectClient*>::removeItem(l);
00047     }
00048 
00049     void expireItem(const DCCache::literator& l) {
00050       expired.emit( (*l).getValue() );
00051       Cache<int, DirectClient*>::expireItem(l);
00052       /* this will removeItem(..), which'll delete the DirectClient
00053        * (see above).
00054        */
00055     }
00056 
00057     void removeContact(const ContactRef& c) {
00058       literator curr = m_list.begin();
00059       literator next = curr;
00060       while ( curr != m_list.end() ) {
00061         DirectClient *dc = (*curr).getValue();
00062         ++next;
00063         if ( dc->getContact()->getUIN() == c->getUIN() ) {
00064           dc->setContact( ContactRef() ); // invalidate contact so the DC doesn't attempt to redeliver
00065           removeItem(curr);
00066         }
00067         curr = next;
00068       }
00069     }
00070 
00071     DirectClient* getByContact(const ContactRef& c)
00072     {
00073       // linear lookup
00074       literator curr = m_list.begin();
00075       while ( curr != m_list.end() ) {
00076         DirectClient *dc = (*curr).getValue();
00077         if ( dc->getContact()->getUIN() == c->getUIN() )
00078           return dc; // found it
00079 
00080         ++curr;
00081       }
00082 
00083       return NULL; // not found
00084     }
00085 
00086     void clearoutMessagesPoll() {
00087       literator curr = m_list.begin();
00088       while ( curr != m_list.end() ) {
00089         DirectClient *dc = (*curr).getValue();
00090         dc->clearoutMessagesPoll();
00091         ++curr;
00092       }
00093     }
00094 
00095     Signal1<void,DirectClient*> expired;
00096   };
00097   
00098 }
00099 
00100 #endif

Generated on Tue Apr 16 22:12:38 2002 for libicq2000 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002