emailservices/emailstore/message_store/server/inc/bufferedmessagecreator.h
changeset 0 8466d47a6819
child 10 f5907b1a1053
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2006 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:
       
    15 *
       
    16 */
       
    17 #ifndef BUFFEREDMESSAGECREATOR_H
       
    18 #define BUFFEREDMESSAGECREATOR_H
       
    19 
       
    20 #include <bautils.h>
       
    21 #include "MessageStoreClientServer.h"
       
    22 #include "ContainerStore.h"
       
    23 
       
    24 
       
    25 class CContainerStoreContentManager;
       
    26 
       
    27 
       
    28 /**
       
    29  * In this subdirectory uncommitted content files are being stored.
       
    30  */
       
    31 _LIT( KUncommittedDirName, "uncommitted\\" );
       
    32 
       
    33 
       
    34 /**
       
    35  * This class buffers all the container requests made during the creation of a
       
    36  * message store message. This usually involves the message container,
       
    37  * few parts (probably three for the message body plus one for each attachment)
       
    38  * and the parts' content files. When the message container is committed then
       
    39  * all of the writes to the message store are done in a single transactions.
       
    40  * 
       
    41  * Container ids are allocated before and during the buffering and if for some
       
    42  * reason the message is not committed the ids will be lost.
       
    43  * 
       
    44  * Public APIs often require a CContainerStore instance as this instance may get
       
    45  * deleted in certain cases so it cannot be cached internally.
       
    46  * 
       
    47  * Buffering is not supported when encryption is enabled. It will be
       
    48  * automatically turned off if the encryption is on. 
       
    49  */
       
    50 NONSHARABLE_CLASS( CBufferedMessageCreator ) : public CBase
       
    51     {
       
    52     
       
    53     /**
       
    54      * Collects all of the information about a container.
       
    55      */
       
    56     class ContainerDescriptor
       
    57         {
       
    58     public:
       
    59         
       
    60         /**
       
    61          * @param aProperties - the ownership is transferred ("Assign"-ed) to
       
    62          * the current instance thus the caller should not "Close" the RBuf. 
       
    63          */
       
    64         ContainerDescriptor(
       
    65             TMsgStoreCreateContainerCmdParams& aParams,
       
    66             const RBuf8& aProperties );
       
    67         
       
    68         ~ContainerDescriptor();
       
    69         
       
    70     public:
       
    71         RBuf8 iProperties;
       
    72         TMsgStoreCreateContainerCmdParams iParams;
       
    73         };
       
    74 
       
    75 
       
    76 public:
       
    77 
       
    78     static CBufferedMessageCreator* CBufferedMessageCreator::NewL(
       
    79         CContainerStore& aStore );
       
    80     
       
    81     virtual ~CBufferedMessageCreator();
       
    82 
       
    83     /**
       
    84      * Tries to buffer this request to create a container. A request to create
       
    85      * a message container starts the buffering and all of the related
       
    86      * containers will be buffered until the message container is committed. If
       
    87      * another message container is created while a different one is in progress
       
    88      * then the one in progress will be aborted. There is no technical reason
       
    89      * for that other than simplification.
       
    90      * 
       
    91      * @return ETrue if the request was buffered and thus the direct request
       
    92      * handling must be skipped.
       
    93      */
       
    94     TBool EnqueueL(
       
    95         CContainerStore& aStore,
       
    96         TMsgStoreCreateContainerCmdParams& aParams,
       
    97         const RBuf8& aProperties );    
       
    98 
       
    99     /**
       
   100      * Determines whether the specified id belongs to a container that has been
       
   101      * buffered.
       
   102      */
       
   103     TBool IsContainerBuffered( TMsgStoreId aId ) const;
       
   104     
       
   105     void CommitMessageL(
       
   106         CContainerStore& aStore,
       
   107         MContainerStoreObserver* aObserver );    
       
   108     
       
   109     void AbandonMessageL(
       
   110         CContainerStore& aStore,
       
   111         TMsgStoreId aId );
       
   112 
       
   113     void AppendContentL(
       
   114         CContainerStore& aStore,
       
   115         TMsgStoreId aId,
       
   116         RBuf8& aContentBuf );
       
   117 
       
   118     void PrependContentL(
       
   119         CContainerStore& aStore,
       
   120         TMsgStoreId aId,
       
   121         RBuf8& aContentBuf );
       
   122     
       
   123     void ReplaceContentL(
       
   124         CContainerStore& aStore,
       
   125         TMsgStoreId aId,
       
   126         RBuf8& aContentBuf );
       
   127     
       
   128     void ReplaceContentL(
       
   129         CContainerStore& aStore,
       
   130         TMsgStoreId aId,
       
   131         RFile& aFile );
       
   132 
       
   133     /**
       
   134      * Empties the current contents, cleans up content files and resets the
       
   135      * internal state so a new message creation can be buffered.
       
   136      */
       
   137     void ResetL( CContainerStore& aStore );
       
   138     
       
   139     void BeginBatchInsertL( CContainerStore& aStore );
       
   140     
       
   141     void FinishBatchInsertL(
       
   142         CContainerStore& aStore,
       
   143         MContainerStoreObserver* aObserver );
       
   144     
       
   145 private:
       
   146     
       
   147     void CommitMessagesL(
       
   148         CContainerStore& aStore,
       
   149         MContainerStoreObserver* aObserver );    
       
   150 
       
   151     void CommitMessagesImplL(
       
   152         CContainerStore& aStore,
       
   153         MContainerStoreObserver* aObserver );    
       
   154 
       
   155     void AddRequestL(
       
   156         CContainerStore& aStore,
       
   157         TMsgStoreCreateContainerCmdParams& aParams,
       
   158         const RBuf8& aProperties );    
       
   159 
       
   160     TContainerId GetNextContainerIdL( CContainerStore& aStore );
       
   161     
       
   162     void GetUncommittedContentPath(
       
   163         CContainerStore& aStore,
       
   164         TMsgStoreId aId,
       
   165         TFileName& aFilePath );
       
   166     
       
   167     void ConstructL(
       
   168         CContainerStore& aStore );
       
   169     
       
   170     CBufferedMessageCreator();
       
   171     
       
   172     //disallow these.
       
   173     CBufferedMessageCreator( const CBufferedMessageCreator& );
       
   174     CBufferedMessageCreator& operator= ( const CBufferedMessageCreator& );        
       
   175     
       
   176 private:
       
   177     TBool iInProgress;
       
   178     RPointerArray<CBufferedMessageCreator::ContainerDescriptor> iContainers;
       
   179     RArray<TContainerId> iIds;
       
   180     TBool iIsBatchInsert;
       
   181     };
       
   182 
       
   183 	
       
   184 #endif // BUFFEREDMESSAGECREATOR_H