webengine/osswebengine/cache/inc/HttpCachePostponeWriteUtilities.h
changeset 10 a359256acfc6
child 11 c8a366e56285
equal deleted inserted replaced
5:10e98eab6f85 10:a359256acfc6
       
     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 the License "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:  Implementation of CHttpCachePostponeWriteUtilities
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CHTTPCACHEPOSTPONEWRITEUTILS_H
       
    19 #define CHTTPCACHEPOSTPONEWRITEUTILS_H
       
    20 
       
    21 //  INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <f32file.h>
       
    24 #include <s32file.h>
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 // MACROS
       
    29 #define CACHE_POSTPONE_DEBUG_PRINT
       
    30 // DATA TYPES
       
    31 
       
    32 // FUNCTION PROTOTYPES
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class CHttpCacheEntry;
       
    36 class RFileWriteStream;
       
    37 class RFileReadStream;
       
    38 class CHttpCacheFileWriteHandler;
       
    39 class CHttpCacheHandler;
       
    40 class MHttpCacheWriteSource;
       
    41 
       
    42 /*
       
    43  * CHttpCacheEntryAsyncWriteHelper is responsible for asynchronously writing out the data from a CHttpCacheStreamEntry object.
       
    44  *
       
    45  * It is used in CHttpCacheHandler::FlushAsync() to provide the async write capability.
       
    46  *
       
    47  * At creation, it begins to write the first segment of body data.  As each segment completes, the next is written.
       
    48  * Once the body data is written, the headers are written and the status from the header write is returned to the observer.
       
    49  */
       
    50 NONSHARABLE_CLASS(CHttpCacheEntryAsyncWriteHelper) : public CActive
       
    51     {
       
    52 public:
       
    53     virtual ~CHttpCacheEntryAsyncWriteHelper();
       
    54 
       
    55     static CHttpCacheEntryAsyncWriteHelper* NewL(MHttpCacheWriteSource* aSource, TRequestStatus& aStatus);
       
    56     TInt GetResult();   // KRequestPending, or a completion code.
       
    57 
       
    58 private:
       
    59     CHttpCacheEntryAsyncWriteHelper(TRequestStatus& aStatus, MHttpCacheWriteSource* aSource, TInt aPriority = EPriorityNormal);
       
    60 
       
    61     virtual void DoCancel();
       
    62     virtual void RunL();
       
    63 
       
    64     void ConstructL();
       
    65     void WriteNextBodyBlock();
       
    66 
       
    67 private:
       
    68     const TRequestStatus& iSignalStatus;
       
    69     MHttpCacheWriteSource* iSource;
       
    70     TInt iBodyPart;
       
    71     TBool iDone;
       
    72     };
       
    73 
       
    74 
       
    75 
       
    76 /*
       
    77  * CSegmentedHeapBuffer is a simple segmented buffer.  You can add data progressively and storage will
       
    78  * be automatically provided.
       
    79  *
       
    80  * When creating one of these, you provide aBufferSize which is the segment size and aCompressGranularity which is the
       
    81  * multiple which is used to determine if the final block should be shrunk when Compress() is called.
       
    82  */
       
    83 NONSHARABLE_CLASS(CSegmentedHeapBuffer) : public CBase
       
    84     {
       
    85 public:
       
    86     virtual ~CSegmentedHeapBuffer();
       
    87     /*
       
    88      * aBufferSize is the size of each segment used for storage.
       
    89      * aCompressGranularity is the multiple used when Compress()ing the last block.
       
    90      */
       
    91     static CSegmentedHeapBuffer * NewL(TInt aBufferSize = 32768, TInt aCompressGranularity = 4096);
       
    92 
       
    93     /*
       
    94      * @since 5.0
       
    95      * @param aRemainder [out] - returns the amount of data not consumed from aDes.
       
    96      * @param aDes [in] - the data to append.
       
    97      * @return void
       
    98      * Add some data to the buffer.
       
    99      *
       
   100      * This function will append the data from aDes in chunks of iBufferSize.
       
   101      * aRemainder will normally be zero after completion of this call, however if AppendL
       
   102      * does leave, then aRemainder will tell you how many bytes from aDes have not been consumed.
       
   103      * This is intended for calling code to cope in the case where the buffer cannot be extended (KErrNoMemory)
       
   104      * to contain the whole descriptor.  Calling code can take remedial action and know exactly how much data
       
   105      * is left to handle.
       
   106      */
       
   107     void AppendL(TInt& aRemainder, const TDesC8& aDes);
       
   108 
       
   109     /*
       
   110      * @since 5.0
       
   111      * @param aSegment [in & out] - in -> the segment to address, out -> next segment.
       
   112      * @return Segment data descriptor.
       
   113      *
       
   114      * Access data in the buffer.
       
   115      *
       
   116      * Simply returns descriptor giving access to the desired segment.
       
   117      * Normal usage is to call with aSegment initialised to zero.
       
   118      * Repeated calls with same aSegment will result in iterator behaviour.
       
   119      * Do not call past number of available segments as returned by Count() - this will result in a panic from
       
   120      * addressing past the end of the RPointerArray.
       
   121      */
       
   122     TPtrC8 GetSegmentData(TInt& aSegment);
       
   123 
       
   124     /*
       
   125      * @since 5.0
       
   126      * @param aSegment [in] - the segment to free.
       
   127      * @return void
       
   128      *
       
   129      * Release data in the buffer.
       
   130      *
       
   131      * Frees the requested segment without changing segment numbering and order.
       
   132      */
       
   133     void ReleaseSegmentData(const TInt aSegment);
       
   134 
       
   135     TInt Length();          // amount of data stored
       
   136     TInt SpareCapacity();   // spare space in last block
       
   137     TInt Count();           // number of blocks
       
   138 
       
   139     void Compress();        // release space at end of last block.
       
   140     void Reset();           // release all allocated storage
       
   141 private:
       
   142     void ConstructL();
       
   143     CSegmentedHeapBuffer(TInt aBufferSize, TInt aCompressGranularity);
       
   144 
       
   145 private:
       
   146     const TInt iBufferSize;
       
   147     const TInt iCompressGranularity;
       
   148     RPointerArray<HBufC8> iBufferList;
       
   149     };
       
   150 // CLASS DECLARATION
       
   151 
       
   152 
       
   153 NONSHARABLE_CLASS(MHttpCacheWriteSource)
       
   154     {
       
   155 public:
       
   156     virtual RFile& BodyFile() = 0;
       
   157     virtual void   BodyWriteInProgress() = 0;
       
   158     virtual void   BodyWriteComplete() = 0;
       
   159     virtual CSegmentedHeapBuffer& BodyData() = 0;
       
   160     };
       
   161 
       
   162 // calls the given function when the preset timer expires.
       
   163 NONSHARABLE_CLASS(CHttpCacheWriteTimeout) : public CActive
       
   164     {
       
   165     public:
       
   166         // Cancel and destroy
       
   167         ~CHttpCacheWriteTimeout ();
       
   168 
       
   169         // Two-phased constructor.
       
   170         static CHttpCacheWriteTimeout* NewL (const TInt aTimeout);
       
   171 
       
   172         // Two-phased constructor.
       
   173         static CHttpCacheWriteTimeout* NewLC (const TInt aTimeout);
       
   174 
       
   175     public:
       
   176         // New functions
       
   177         // Function for making the initial request
       
   178         void Start(TCallBack aCallbackFn, TAny *aToken);
       
   179 
       
   180     private:
       
   181         // C++ constructor
       
   182         CHttpCacheWriteTimeout (const TInt aTimeout);
       
   183 
       
   184         // Second-phase constructor
       
   185         void ConstructL ();
       
   186 
       
   187     private:
       
   188         // From CActive
       
   189         // Handle completion
       
   190         void RunL ();
       
   191 
       
   192         // How to cancel me
       
   193         void DoCancel ();
       
   194 
       
   195         // Override to handle leaves from RunL(). Default implementation causes
       
   196         // the active scheduler to panic.
       
   197         TInt RunError (TInt aError);
       
   198 
       
   199     private:
       
   200         TInt    iTimeout;
       
   201         RTimer iTimer; // Provides async timing service
       
   202         TCallBack iCallbackFn;
       
   203         TAny *iToken;
       
   204     };
       
   205 
       
   206 
       
   207 
       
   208 #endif      // CHTTPCACHEPOSTPONEWRITEUTILS_H
       
   209 
       
   210 // End of File