email_plat/email_client_api/inc/emailinterfacefactory.h
changeset 74 6c59112cfd31
parent 47 f83bd4ae1fe3
equal deleted inserted replaced
69:4e54af54a4a1 74:6c59112cfd31
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: ECom interface for Email Client API
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CEMAILINTERFACEFACTORY_H
       
    20 #define CEMAILINTERFACEFACTORY_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <ecom/ecom.h>
       
    24 #include <memailclientapi.h>
       
    25 #include <memailcontent.h>
       
    26 
       
    27 namespace EmailInterface {
       
    28     
       
    29 /**
       
    30  * ECom factory class for Email Client API.
       
    31  * @since S60 v5.0
       
    32  * 
       
    33  */
       
    34 NONSHARABLE_CLASS( CEmailInterfaceFactory ) : public CBase
       
    35 {
       
    36 public:       
       
    37         
       
    38     /**
       
    39      * Contructor
       
    40      * @return factory for creating interface instances.
       
    41      */
       
    42     inline static CEmailInterfaceFactory* NewL();
       
    43     
       
    44     /**
       
    45     * destructor
       
    46     */
       
    47     inline ~CEmailInterfaceFactory();
       
    48     
       
    49     /**
       
    50     * Returns email interface pointer by id
       
    51     * @param aInterfaceId interface id, see emailclientapi.hrh for available ids
       
    52     * @return pointer to interface
       
    53     * @exception KErrNotFound if unkown interface id is given
       
    54     *
       
    55     * @code
       
    56     
       
    57      #include <emailinterfacefactory.h>
       
    58     
       
    59      using namespace EmailInterface;
       
    60      
       
    61      CEmailInterfaceFactory* factory = CEmailInterfaceFactory::NewL();
       
    62      CleanupStack::PushL( factory );
       
    63      MEmailInterface* ifPtr = factory->InterfaceL( KEmailClientApiInterface );
       
    64      MEmailClientApi* clientApi = static_cast<MEmailClientApi*>( ifPtr );
       
    65      CleanupReleasePushL( *clientApi );
       
    66      // <do something with clientApi...>
       
    67      CleanupStack::PopAndDestroy( 2 ); // clientApi and factory
       
    68      @endcode
       
    69     * 
       
    70     */
       
    71     virtual EmailInterface::MEmailInterface* InterfaceL(  
       
    72         const TInt aInterfaceId ) = 0;
       
    73 
       
    74 private:
       
    75     
       
    76         // Unique instance identifier key
       
    77         TUid iDtor_ID_Key;
       
    78 };
       
    79 
       
    80     
       
    81 /**
       
    82  * Cleanup support for pointer arrays with MEmailInterface elements which are 
       
    83  * destroyed with Release() method.
       
    84  * @since S60 v5.0
       
    85    @code
       
    86        using namespace EmailInterface;
       
    87  
       
    88        RMailboxPtrArray mailboxes; // array of MEmailMailbox pointers
       
    89        // note: PushL can take any pointer array of elements with Release()
       
    90        // method
       
    91        CleanupResetAndRelease<MEmailMailbox>::PushL( mailboxes );
       
    92       // <here some code that might leave>
       
    93        mailClient->GetMailboxesL( mailboxes );
       
    94  
       
    95        // MEmailMailbox::Release() called for each array element and then
       
    96        // mailboxes.Reset() is called 
       
    97        CleanupStack::PopAndDestroy();  
       
    98    @endcode
       
    99  */
       
   100 template<class T>
       
   101 NONSHARABLE_CLASS( CleanupResetAndRelease )
       
   102 {
       
   103 public:
       
   104     /**
       
   105      * Cleanup for elements containing Release() method  
       
   106      */
       
   107     inline static void PushL( RPointerArray<T>& aItem );
       
   108 
       
   109     /**
       
   110      * Releases array elements and resets array.
       
   111      */
       
   112     inline static void ResetAndRelease( TAny* aPtr );  
       
   113 };
       
   114 
       
   115 #include "emailinterfacefactory.inl"
       
   116 
       
   117 } // namespace EmailInterface
       
   118 
       
   119 #endif // CEMAILINTERFACEFACTORY_H