emailservices/emailclientapi/inc/emailclientapiimpl.h
changeset 0 8466d47a6819
child 4 e7aa27f58ae1
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: Definition of Email API main interface.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef EMAILCLIENTAPIIMPL_H
       
    19 #define EMAILCLIENTAPIIMPL_H
       
    20 
       
    21 
       
    22 #include <ecom/ImplementationInformation.h> 
       
    23 #include "emailapiutils.h"
       
    24 #include "cfsmailcommon.h"
       
    25 //#include "emailinternalclientapi.h"
       
    26 #include "mfsmaileventobserver.h"    
       
    27 #include <memailclientapi.h>
       
    28 #include "emailclientpluginmanager.h"
       
    29 
       
    30 
       
    31 using namespace EmailInterface;
       
    32 
       
    33 class CFSMailBox;
       
    34 class MEmailEventObserver;
       
    35 class CVwsSessionWrapper;
       
    36 class CFSMailPlugin;
       
    37 class TFSMailMsgId;
       
    38 class CEmailMailboxCache;
       
    39 class CFSClientAPI;
       
    40 
       
    41 /**
       
    42 *  "Framework" class including plugin management
       
    43 * @since S60 v5.2
       
    44 */
       
    45 NONSHARABLE_CLASS( CEmailClientApi ) : public CBase, public MEmailClientApi, public MEmailClientPluginManager
       
    46 {
       
    47 public:
       
    48     /**
       
    49     * Constructor
       
    50     * @return
       
    51     */
       
    52     static CEmailClientApi* NewL();
       
    53     
       
    54     /**
       
    55      * Destructor
       
    56      */
       
    57     ~CEmailClientApi();
       
    58     
       
    59     /**
       
    60      *
       
    61      */
       
    62      CEmailClientApi();       
       
    63 
       
    64 public: // from MEmailInterface
       
    65     virtual TEmailTypeId InterfaceId() const;
       
    66     
       
    67     virtual void Release();
       
    68     
       
    69 public: // from MEmailClientApi
       
    70 
       
    71     /** @see MEmailClientApi */   
       
    72     virtual MEmailMailbox* MailboxL( const TMailboxId& aId );
       
    73    
       
    74     /** @see MEmailClientApi */   
       
    75     virtual MEmailMailbox* MailboxL( const TPtrC& aAddress );
       
    76            
       
    77     /**
       
    78     * Gets all mailboxes in pointer array. It is recommended to free other
       
    79     * mailboxes besides needed one to optimise memory usage.
       
    80     */    
       
    81     virtual TInt GetMailboxesL( RMailboxPtrArray& aMailboxes );
       
    82     
       
    83     /**
       
    84     */
       
    85     virtual void LaunchEmailL( const TLaunchPolicy aPolicy );
       
    86     
       
    87 public: // from MEmailPluginManager
       
    88     virtual CFSMailPlugin* GetPluginByUid(TUid aUid);    
       
    89 
       
    90 public: // new methods
       
    91 
       
    92     /**
       
    93      * Gets array of mailbox ids
       
    94      * @param aMailboxes mailbox ids from all plugins
       
    95      * @return number of mailboxes returned in aMailboxes
       
    96      */
       
    97     TInt GetMailboxIdsL( REmailMailboxIdArray& aMailboxes );
       
    98         
       
    99 private:
       
   100 
       
   101     /**
       
   102      * Constructor
       
   103      */
       
   104     void ConstructL();
       
   105 
       
   106     /**
       
   107      * Push ECom implementation info to cleanup operation to cleanup stack
       
   108      */
       
   109     void CleanupImplInfoPushL( RPointerArray<CImplementationInformation>& aArray );
       
   110     
       
   111     /**
       
   112      * Cleanup operation for ECom implementation info
       
   113      */
       
   114     static void CleanupImplInfo( TAny* aAny );
       
   115    
       
   116 
       
   117     // Group of methods for book keeping of loaded protocol plugins by this object.
       
   118     // In certain situations it is preferable to have a plugin in memory
       
   119     // instead of loading/unloading frequently.
       
   120     
       
   121     /** Increases plugin reference count if CEmailClientApi already doesn't
       
   122      *  have active instance. When plugin is needed internally, this method
       
   123      * should be accessor to a plugin. Counterpart is ReleasePlugin() when
       
   124      * CEmailClientApi doesn't itself need plugin any more.
       
   125      */
       
   126     CFSMailPlugin* UsePlugin( CPluginData& aPluginData );
       
   127     
       
   128     /**
       
   129     * For finding plugin data
       
   130     */
       
   131     TInt IndexOfLoadedPluginData( const TPluginData& aPluginData ) const;
       
   132     
       
   133     /**
       
   134     * Used in comparing plugin data in array (part of find algorithm)
       
   135     */    
       
   136     static TBool PluginDataEquals( const TPluginData& a1, const TPluginData& a2 );
       
   137     
       
   138     /**
       
   139     * This object doesn't need related protocol plugin
       
   140     */
       
   141     void ReleasePlugin( CPluginData& aPluginData );
       
   142     
       
   143     /**
       
   144     * This object doesn't need any protocol plugin
       
   145     */
       
   146     void ReleaseAllPlugins();
       
   147     
       
   148     /**
       
   149     * Return mailbox cache, creates it when called first time
       
   150     */
       
   151     CEmailMailboxCache& MailboxInfoCacheL();
       
   152     
       
   153     /**
       
   154     * Caches mailbox ids and their mapping to related plugin data for quick
       
   155     * lookup. When a mailbox with specific id is next time asked, related
       
   156     * protocol plugin is already known.
       
   157     */
       
   158     void UpdateMailboxInfoCacheL();
       
   159 
       
   160     /**
       
   161     * Internal, used from UpdateMailboxInfoCacheL
       
   162     */    
       
   163     TBool CachePluginMailboxesL( 
       
   164         CPluginData& aPluginData, 
       
   165         CFSMailPlugin& aPlugin );
       
   166     
       
   167 private:    
       
   168     typedef RPointerArray<CPluginData> RPluginDataArray;
       
   169     
       
   170     /**
       
   171     * Iterator for CPluginData elements in an array
       
   172     */
       
   173     class TPluginIterator
       
   174     {
       
   175     public:
       
   176         // constructor
       
   177         inline TPluginIterator( RPluginDataArray& aArray ) : 
       
   178             iArray( aArray ), iIndex( 0 ) {}
       
   179         
       
   180         /**
       
   181         * return next element
       
   182         */
       
   183         CPluginData* Next();
       
   184     private:
       
   185         // iterator array
       
   186         RPluginDataArray& iArray;
       
   187         // current iterator index
       
   188         TInt iIndex;
       
   189     };
       
   190 #if 0 // Not supported    
       
   191     /**
       
   192      * Internal helper class for handling events related to mailboxes
       
   193      *(adding/removal/rename).
       
   194      */
       
   195     class CObserverHandler : public CBase, public MFSMailEventObserver
       
   196     {
       
   197     public:
       
   198         static CObserverHandler* NewL( const RPluginDataArray& aArray  );
       
   199         ~CObserverHandler();
       
   200         CObserverHandler( const RPluginDataArray& aArray );
       
   201         void ConstructL();
       
   202         void AddObserverL( MMailboxEventObserver& aObserver );
       
   203         void RemoveObserver( MMailboxEventObserver& aObserver );
       
   204         
       
   205     public: // from MFSMailEventObserver
       
   206 
       
   207         virtual void EventL(TFSMailEvent aEvent, TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2, TAny* aParam3);
       
   208     
       
   209     private: // new methods
       
   210         
       
   211         // used for finding oberver
       
   212         static TBool Equals( const MMailboxEventObserver& a1, const MMailboxEventObserver& a2 );
       
   213         
       
   214         // Plugins needed when first observer subscribes events
       
   215         void ClaimPluginsAndStartObservingL();
       
   216         
       
   217         // plugins can be released when last observer removed
       
   218         void ReleasePlugins();
       
   219                 
       
   220     private: // data
       
   221 
       
   222         // Plugin refCount is incremented by one while any observer is 
       
   223         // registered. This prevents plugin unloading if no other entity uses 
       
   224         // the plugin. 
       
   225         class TEntry
       
   226         {
       
   227         public:
       
   228             inline TEntry( CPluginData& aData ) : iData( aData ), iPlugin( NULL ) {}
       
   229             CPluginData& iData;    
       
   230             
       
   231             // claimed from same object where iData refers to
       
   232             CFSMailPlugin* iPlugin;
       
   233         };
       
   234         
       
   235         // plugin entry array
       
   236         RArray<CObserverHandler::TEntry>     iEntryArray;
       
   237         
       
   238         // reference to CEmailClientApi::iPluginDataArray
       
   239         const RPluginDataArray&              iPluginDataArray;
       
   240         
       
   241         // registered observers
       
   242         RPointerArray<MMailboxEventObserver> iMailboxObservers;
       
   243     };
       
   244 #endif    
       
   245     /**
       
   246      * Returns reference to observer handler.
       
   247      */
       
   248 #if 0 // Not supported    
       
   249     CEmailClientApi::CObserverHandler& ObserverHandlerL();
       
   250 #endif    
       
   251     
       
   252 private:
       
   253     // plugin data array for all protocol plugins
       
   254     RPluginDataArray    iPluginDataArray;
       
   255     
       
   256     // book keeping of loaded plugins
       
   257     RArray<TPluginData> iLoadedPluginsArray;
       
   258     
       
   259 #if 0 // Not supported    
       
   260     // orchestrates event monitoring and related plugin references
       
   261     CEmailClientApi::CObserverHandler*   iObserverHandler;
       
   262     
       
   263 #endif
       
   264     
       
   265     // Mailbox ids are cached when first time listed. Related plugin uid
       
   266     // is include in the cache.
       
   267     CEmailMailboxCache* iMailboxCache;
       
   268 
       
   269     CFSClientAPI* iClientAPI;
       
   270     
       
   271 };
       
   272 
       
   273 /**
       
   274 * Email application launcher. 
       
   275 */
       
   276 NONSHARABLE_CLASS( CEmailLauncher ) : public CBase
       
   277 {
       
   278 public:
       
   279     static CEmailLauncher* NewL();
       
   280     
       
   281     ~CEmailLauncher();
       
   282                                     
       
   283     /**
       
   284     *
       
   285     */
       
   286      void LaunchL( const TMailboxId& aMailboxId );
       
   287 private:
       
   288     
       
   289     CEmailLauncher();
       
   290     
       
   291     void ConstructL();
       
   292     
       
   293     // Owned window server session.
       
   294     CVwsSessionWrapper* iViewSrvSession;
       
   295 };
       
   296 
       
   297 
       
   298 #endif // EMAILCLIENTAPIIMPL_H
       
   299 
       
   300 // End of file.