emailservices/emailframework/commonlib/inc/cemailextensionbase.h
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Meeting Request calendar info object extension
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CEMAILEXTENSIONBASE_H
       
    19 #define CEMAILEXTENSIONBASE_H
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 /**
       
    24 * Base class for extensions. Instances of subclasses are requested from
       
    25 * CExtendableEmail::ExtensionL() with specific extension UID.
       
    26 * When client has ended using an extension it must be released with
       
    27 * CExtendableEmail::ReleaseExtension().
       
    28 * @since s60 v5.0
       
    29 */
       
    30 class CEmailExtension : public CBase
       
    31 {
       
    32 
       
    33 public: 
       
    34     IMPORT_C ~CEmailExtension();
       
    35 protected:    
       
    36     IMPORT_C CEmailExtension( const TUid& aUid );
       
    37 public:
       
    38     
       
    39     /**         
       
    40     * returns extension uid
       
    41     * @return   uid of the extension.
       
    42     */
       
    43     IMPORT_C TUid Uid() const;
       
    44 
       
    45 public: // for internal use
       
    46                            
       
    47     /**
       
    48     * Decrement reference count.
       
    49     * @return new value of ref count
       
    50     */                           
       
    51     TUint DecRef();
       
    52     
       
    53     /**
       
    54     * Increment reference count.
       
    55     */                           
       
    56     void IncRef();
       
    57         
       
    58 private:
       
    59 
       
    60     
       
    61     // extension interface UID defined by specific interface.
       
    62     const TUid iUid;    
       
    63     
       
    64     // Reference count is needed because more than one client may request
       
    65     // same extension (e.g. UI and protocol plugin).
       
    66     TUint iRefCount;
       
    67 };
       
    68 
       
    69 /**
       
    70 * helper class for managing extensions. In most cases needed only
       
    71 * by CExtendableEmail when extensions are created/released. Proto
       
    72 * @since s60 v5.0
       
    73 */
       
    74 class TEmailExtensions
       
    75 {
       
    76 public:
       
    77 
       
    78     /**
       
    79      * c++ constructor
       
    80      */
       
    81     IMPORT_C TEmailExtensions();
       
    82     
       
    83     /**
       
    84      * Destructor
       
    85      */
       
    86     IMPORT_C ~TEmailExtensions();
       
    87                        
       
    88     /**
       
    89      * Returns extension index in iExtensions
       
    90      @ return extension index or KErrNotFound
       
    91      */
       
    92     IMPORT_C TInt FindExtension( const TUid& aUid ) const;
       
    93     
       
    94     /**
       
    95      * Returns extension by index or panics if invalid index is given
       
    96      * @param aIndex index in iExtensions
       
    97      * @panic EEmailExtensionIndexOutOfRange if index is out of range
       
    98      * @return extension
       
    99      */
       
   100     IMPORT_C CEmailExtension* Extension( const TInt aIndex ) const;
       
   101     
       
   102     /**
       
   103      * Adds extension to iExtensions array and increments its ref count by one.
       
   104      *
       
   105      * @param aExtenstion   extension to add
       
   106      * @leave KErrArgument  if aExtension is NULL
       
   107      */
       
   108     IMPORT_C void AddL( CEmailExtension* aExtension );
       
   109 
       
   110     /**
       
   111      * Removes extension from iExtensions
       
   112      * @param aExtenstion extension to remove
       
   113      */
       
   114     IMPORT_C void Remove( const CEmailExtension* aExtension );
       
   115     
       
   116 private:    
       
   117     // array of extensions
       
   118     RPointerArray<CEmailExtension> iExtensions;
       
   119 };
       
   120 
       
   121 /**                 
       
   122 * Classes that support email extension mechanism by returning extensions by
       
   123 * uid should have this as base class.
       
   124 *
       
   125 * @since s60 v5.0
       
   126 */                 
       
   127 class CExtendableEmail : public CBase
       
   128 {
       
   129 public:
       
   130     /**
       
   131     * Decrements extension reference count and deletes if count reaches 0.
       
   132     * Derived class must call this if it overrides this method.
       
   133     * @param aExtension extension to release
       
   134     */
       
   135     IMPORT_C virtual void ReleaseExtension( CEmailExtension* aExtension );
       
   136 
       
   137     /**
       
   138     * Requests extension. Default implementation performs lookup only and
       
   139     * derived class should implement actual instantiation because it knows
       
   140     * extensions it supports. Derived class must always call this to ensure
       
   141     * that extension is not created twice.
       
   142     *
       
   143     * @param aExtension extension to release
       
   144     */
       
   145     IMPORT_C virtual CEmailExtension* ExtensionL( const TUid& aInterfaceUid );
       
   146 
       
   147 protected:    
       
   148     // extension containment
       
   149     TEmailExtensions iExtensions;
       
   150 };
       
   151 
       
   152 #endif // CEMAILEXTENSIONBASE_H