Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

stanzaextensionfactory.cpp

00001 /*
00002   Copyright (c) 2006-2009 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 
00014 #include "stanzaextensionfactory.h"
00015 
00016 #include "gloox.h"
00017 #include "mutexguard.h"
00018 #include "util.h"
00019 #include "stanza.h"
00020 #include "stanzaextension.h"
00021 #include "tag.h"
00022 
00023 namespace gloox
00024 {
00025 
00026   StanzaExtensionFactory::StanzaExtensionFactory()
00027   {
00028   }
00029 
00030   StanzaExtensionFactory::~StanzaExtensionFactory()
00031   {
00032     m_extensionsMutex.lock();
00033     util::clearList( m_extensions );
00034     m_extensionsMutex.unlock();
00035   }
00036 
00037   void StanzaExtensionFactory::registerExtension( StanzaExtension* ext )
00038   {
00039     if( !ext )
00040       return;
00041 
00042     util::MutexGuard m( m_extensionsMutex );
00043     SEList::iterator it = m_extensions.begin();
00044     SEList::iterator it2;
00045     while( it != m_extensions.end() )
00046     {
00047       it2 = it++;
00048       if( ext->extensionType() == (*it2)->extensionType() )
00049       {
00050         delete (*it2);
00051         m_extensions.erase( it2 );
00052       }
00053     }
00054     m_extensions.push_back( ext );
00055   }
00056 
00057   bool StanzaExtensionFactory::removeExtension( int ext )
00058   {
00059     util::MutexGuard m( m_extensionsMutex );
00060     SEList::iterator it = m_extensions.begin();
00061     for( ; it != m_extensions.end(); ++it )
00062     {
00063       if( (*it)->extensionType() == ext )
00064       {
00065         delete (*it);
00066         m_extensions.erase( it );
00067         return true;
00068       }
00069     }
00070     return false;
00071   }
00072 
00073   void StanzaExtensionFactory::addExtensions( Stanza& stanza, Tag* tag )
00074   {
00075     ConstTagList::const_iterator it;
00076 
00077     util::MutexGuard m( m_extensionsMutex );
00078     SEList::const_iterator ite = m_extensions.begin();
00079     for( ; ite != m_extensions.end(); ++ite )
00080     {
00081       const ConstTagList& match = tag->findTagList( (*ite)->filterString() );
00082       it = match.begin();
00083       for( ; it != match.end(); ++it )
00084       {
00085         StanzaExtension* se = (*ite)->newInstance( (*it) );
00086         if( se )
00087           stanza.addExtension( se );
00088       }
00089     }
00090   }
00091 
00092 }

Generated on Wed Sep 8 10:30:15 2010 for gloox by  doxygen 1.4.1