realtimenetprots/sipfw/SigComp/CompDeflate/inc/DeflateComp.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2003-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:
       
    15 * Name        : CDeflateComp.h
       
    16 * Part of     : deflatecomp / deflatecomp
       
    17 * This ifle is main part of deflatecomp,
       
    18 * implements CSigCompCompressor.
       
    19 * Version     : 1.0
       
    20 *
       
    21 */
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 /**
       
    27  @internalComponent
       
    28 */
       
    29 
       
    30 #ifndef CDEFLATECOMP_H
       
    31 #define CDEFLATECOMP_H
       
    32 
       
    33 #include "Compressor.h"
       
    34 #include "Sigcomp.h"
       
    35 #include "DeflateCompBytecode.h"
       
    36 
       
    37 class CDeflate;
       
    38 class TStateItem;
       
    39 class CSigCompDeflateContext;
       
    40 class CMessageWriter;
       
    41 
       
    42 /** minimum state hash length */
       
    43 const TInt KMinPartialStateLength = 6;
       
    44 
       
    45 class CDeflateComp : public CSigCompCompressor
       
    46     {
       
    47     public:
       
    48         /**
       
    49         * aInitParams are in fact TCompressorInitParams, as defined
       
    50         * in Compressor.h
       
    51         */
       
    52         static CDeflateComp* NewL(TAny* aInitParams);
       
    53         ~CDeflateComp();
       
    54 
       
    55         /**
       
    56         * This function compresses given message, and outputs complete
       
    57         * sigcomp message.
       
    58         * 
       
    59         * @param aCompartmentContext compartment context
       
    60         * @param aMessage Message to compress.
       
    61         * @param aForStreamBasedProtocol indicates what kind of
       
    62         *                       protocol is used (a delimeter at
       
    63         *                       the end of message
       
    64         *                       is added based on this parameter).
       
    65         *
       
    66         * @returns complete sigcomp message, the ownership is transferred
       
    67         */ 
       
    68         CBufBase* CompressMessageL(
       
    69                               MSigCompCompartmentContext* aCompartmentContext,
       
    70                               const TDesC8& aMessage,
       
    71                               TBool aForStreamBasedProtocol);
       
    72 
       
    73         /**
       
    74         * This method is used to ask compressor whenever it supports
       
    75         * dynamic compression or not
       
    76         *
       
    77         * @returns ETrue if it supports dynamic compression, EFalse otherwise
       
    78         */
       
    79         TBool IsDynamicCompressionSupported();
       
    80 
       
    81     private:
       
    82         /** constructor */
       
    83         CDeflateComp(TAny* aInitParams);
       
    84 
       
    85         /** 
       
    86         * Preload given dictionary for gived CDeflate object
       
    87         *
       
    88         * @param aDictionaryState dictionary state, NULL if its not available
       
    89         * @param aDeflateComp CDeflate object for which dictionary should be
       
    90         *                     preloaded.
       
    91         * @param aDeflateContext deflate context
       
    92         *
       
    93         * @returns 1 if dictionary was preloaded, 0 if not. this value is send
       
    94         *          to the other side in compressed message header.
       
    95         *
       
    96         */
       
    97         TUint SetDictionary(const TStateItem* aDictionaryState,
       
    98                             CDeflate* aDeflateComp,
       
    99                             CSigCompDeflateContext* aDeflateContext) const;
       
   100 
       
   101         /** 
       
   102         * Calculate memory size in bytes based on bit representation.
       
   103         *
       
   104         * @param aMemorySize bit representation of memory size
       
   105         *                    
       
   106         * @returns TMemorySize, memory size in bytes
       
   107         */
       
   108         CSigComp::TMemorySize DecodeMemorySize(TInt aMemorySize);
       
   109     
       
   110         /** 
       
   111         * Calculate bits representation of given cycles per bit
       
   112         *
       
   113         * @param aCyclesPerBit cycles per bit (in cycles)
       
   114         *                    
       
   115         * @returns bit represenation of given cycles per bit value
       
   116         */
       
   117         TInt EncodeCyclesPerBit(CSigComp::TCyclesPerBit aCyclesPerBit) const;
       
   118     
       
   119         /** 
       
   120         * Calculate bits representation of given memory size value
       
   121         *
       
   122         * @param aMemorySize memory size (in bytes)
       
   123         *                    
       
   124         * @returns bit represenation of given memory size
       
   125         */
       
   126         TInt EncodeMemorySize(CSigComp::TMemorySize aMemorySize) const;
       
   127 
       
   128         /** 
       
   129         * Append given value at the end of output buffer
       
   130         *
       
   131         * @param aWriter writer to which value will be appended
       
   132         * @param aValue value to be appended
       
   133         *                    
       
   134         */
       
   135         void AppendDataL(CMessageWriter* aWriter, TUint8 aValue);
       
   136 
       
   137         /** 
       
   138         * Append given value at the end of output buffer
       
   139         *
       
   140         * @param aWriter writer to which value will be appended
       
   141         * @param aValue value to be appended
       
   142         *                    
       
   143         */
       
   144         void AppendDataL(CMessageWriter* aWriter, TUint16 aValue);
       
   145 
       
   146         /** 
       
   147         * Append given descriptor at the end of output buffer
       
   148         *
       
   149         * @param aWriter writer to which value will be appended
       
   150         * @param aValue descriptor to be appended
       
   151         *                    
       
   152         */
       
   153         void AppendDataL(CMessageWriter* aWriter, const TDesC8& aData);
       
   154 
       
   155         /** 
       
   156         * Append requested feedback at the end of given buffer.
       
   157         * Feedback may be NULL.
       
   158         *
       
   159         * @param aWriter writer to which value will be appended
       
   160         * @param aRequestedFeedback feedback. may be NULL.
       
   161         *                    
       
   162         */
       
   163         void AppendRequestedFeedbackL(CMessageWriter* aWriter,
       
   164                                       const TDesC8& aRequestedFeedback);
       
   165 
       
   166         /** 
       
   167         * Encode local parameters to returned parameters format.
       
   168         *
       
   169         * @param aCompartmentContext compartment context
       
   170         * @returns encoded parameters
       
   171         *                    
       
   172         */
       
   173         TUint8 EncodeReturnedParameters(
       
   174                               MSigCompCompartmentContext* aCompartmentContext);
       
   175 
       
   176         /** 
       
   177         * Decode remote returned parameters.
       
   178         *
       
   179         * @param aReturnedParameters parameters to decode
       
   180         * @param aDeflateContext deflate context
       
   181         *                    
       
   182         */
       
   183         void ParseReturnedParameters(const TDesC8& aReturnedParameters,
       
   184                                      CSigCompDeflateContext* aDeflateContext);
       
   185 
       
   186         /**
       
   187         * Get deflate context from compartment, allocate new and set it
       
   188         * in compartment if needed
       
   189         *
       
   190         * @param aCompartmentContext compartment context.
       
   191         *
       
   192         * @returns deflate context
       
   193         */
       
   194         CSigCompDeflateContext* DeflateContextL(
       
   195                               MSigCompCompartmentContext* aCompartmentContext);
       
   196 
       
   197         /** 
       
   198         * Calculate hash of bytecode state (SHA-1).
       
   199         *
       
   200         * @param aDeflateContext deflate context
       
   201         * @param aBytecode bytecode id
       
   202         * @param aReturnedParameters local encoded parameters
       
   203         *                    
       
   204         */
       
   205         void CalculateBytecodeHashL(CSigCompDeflateContext* aDeflateContext,
       
   206                                     TDeflateCompBytecodeId aBytecode,
       
   207                                     TUint8 aReturnedParameters);
       
   208 
       
   209         /** 
       
   210         * Append header before compressed data.
       
   211         *
       
   212         * @param aWriter writer to which value will be appended
       
   213         * @param aBytecode bytecode id
       
   214         * @param aReturnedParameters local encoded parameters
       
   215         * @param aUdvmSize udvm memory size
       
   216         * @param aFirstMessage is first message
       
   217         * @param aDeflateContext deflate context
       
   218         *                    
       
   219         */
       
   220         void AppendDataHeaderL(CMessageWriter* aWriter,
       
   221                                TDeflateCompBytecodeId aBytecode,
       
   222                                TUint8 aReturnedParameters,
       
   223                                TInt aUdvmSize,
       
   224                                TBool aFirstMessage,
       
   225                                CSigCompDeflateContext* aDeflateContext);
       
   226 
       
   227         /** 
       
   228         * Calculate circular buffer size.
       
   229         *
       
   230         * @param aUdvmSize udvm memory size
       
   231         * @param aBytecode bytecode id
       
   232         * @param aDeflateContext deflate context
       
   233         *
       
   234         * @returns calculated size
       
   235         *                    
       
   236         */
       
   237         TInt CalcCBSizeL(TInt& aUdvmSize,
       
   238                          TDeflateCompBytecodeId aBytecode,
       
   239                          CSigCompDeflateContext* aDeflateContext);
       
   240 
       
   241     private:
       
   242         /** StateMgr Interace */
       
   243         MSigCompStateMgr* iStateMgr;
       
   244 
       
   245         /** user provided state item, dictionaru usually, may be NULL*/
       
   246         TStateItem* iStateItem;
       
   247 
       
   248         /** length of the user provided state item */
       
   249         TInt iStateItemLength;
       
   250 
       
   251         /** upload state? */
       
   252         TBool iUploadState;
       
   253 
       
   254     };  
       
   255 
       
   256 #endif