--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emailservices/emailcommon/src/cemailextensionbase.cpp Mon May 03 12:23:15 2010 +0300
@@ -0,0 +1,205 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: email internal extension base class
+*
+*/
+
+#include "cemailextensionbase.h"
+#include "emailtrace.h"
+
+/**
+*
+*/
+enum TEmailFwPanic {
+ EEmailExtensionIndexOutOfRange
+ };
+
+_LIT( KEmailExtensionPanic, "EmailFw" );
+
+void Panic( TEmailFwPanic aPanic )
+ {
+ FUNC_LOG;
+ User::Panic( KEmailExtensionPanic, aPanic );
+ }
+
+// ---------------------------------------------------------------------------
+// c++ constructor
+// ---------------------------------------------------------------------------
+//
+CEmailExtension::CEmailExtension( const TUid& aUid ) :
+ iUid( TUid::Uid(aUid.iUid ) )
+ {
+ }
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+CEmailExtension::~CEmailExtension()
+ {
+ }
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+TUid CEmailExtension::Uid() const
+ {
+ return iUid;
+ }
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+TUint CEmailExtension::DecRef()
+ {
+ if ( iRefCount )
+ {
+ iRefCount--;
+ }
+ return iRefCount;
+ }
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void CEmailExtension::IncRef()
+ {
+ ++iRefCount;
+ }
+
+// ---------------------------------------------------------------------------
+// deletes extension and removes it from extension array
+// ---------------------------------------------------------------------------
+//
+void CExtendableEmail::ReleaseExtension( CEmailExtension* aExtension )
+ {
+ FUNC_LOG;
+ if ( !aExtension->DecRef() )
+ {
+ iExtensions.Remove( aExtension );
+ delete aExtension;
+ }
+ }
+
+// ---------------------------------------------------------------------------
+// Finds and returns extension
+// ---------------------------------------------------------------------------
+//
+CEmailExtension* CExtendableEmail::ExtensionL( const TUid& aInterfaceUid )
+ {
+ FUNC_LOG;
+ TInt index = iExtensions.FindExtension( aInterfaceUid );
+ CEmailExtension* ext = NULL;
+ if ( index != KErrNotFound )
+ {
+ ext = iExtensions.Extension( index );
+ ext->IncRef();
+ }
+ return ext;
+ }
+
+//<qmail>
+// ---------------------------------------------------------------------------
+// Constructor is required for sbs2 to generate the same .defs for urel/udeb
+// ---------------------------------------------------------------------------
+//
+CExtendableEmail::CExtendableEmail()
+ {
+ FUNC_LOG;
+ }
+//</qmail>
+
+// ---------------------------------------------------------------------------
+// destructor
+// ---------------------------------------------------------------------------
+//
+TEmailExtensions::~TEmailExtensions()
+ {
+ iExtensions.Close();
+ }
+
+// ---------------------------------------------------------------------------
+// c++ constructor
+// ---------------------------------------------------------------------------
+//
+TEmailExtensions::TEmailExtensions() : iExtensions( 1 )
+ {
+ }
+
+// ---------------------------------------------------------------------------
+// returns index of extension in extension array
+// ---------------------------------------------------------------------------
+//
+TInt TEmailExtensions::FindExtension( const TUid& aUid ) const
+ {
+ TInt index = KErrNotFound;
+ for ( TInt i = 0; i < iExtensions.Count(); i++ )
+ {
+ const CEmailExtension* tested = iExtensions[i];
+ if ( aUid == tested->Uid() )
+ {
+ index = i;
+ break;
+ }
+ }
+ return index;
+ }
+
+// ---------------------------------------------------------------------------
+// Returns extension by index. Panics if index is out of range.
+// ---------------------------------------------------------------------------
+//
+CEmailExtension* TEmailExtensions::Extension( const TInt aIndex ) const
+ {
+ __ASSERT_ALWAYS( aIndex>=0 && aIndex < iExtensions.Count(),
+ Panic( EEmailExtensionIndexOutOfRange ) );
+ return iExtensions[aIndex];
+ }
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void TEmailExtensions::AddL( CEmailExtension* aExtension )
+ {
+ FUNC_LOG;
+ if ( !aExtension )
+ {
+ User::Leave( KErrArgument );
+ }
+ CleanupStack::PushL( aExtension );
+ iExtensions.AppendL( aExtension );
+ CleanupStack::Pop();
+ aExtension->IncRef();
+ }
+
+// ---------------------------------------------------------------------------
+// Removes extension from array
+// ---------------------------------------------------------------------------
+//
+void TEmailExtensions::Remove(
+ const CEmailExtension* aExtension )
+ {
+ FUNC_LOG;
+ const TInt index( FindExtension( aExtension->Uid() ) );
+ if ( index != KErrNotFound )
+ {
+ iExtensions.Remove( index );
+ }
+ }
+
+// End of file