epoc32/include/wspencoder.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 wspencoder.h
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 /**
       
    19  @file WSPEncoder.h
       
    20  @publishedAll
       
    21  @released
       
    22 */
       
    23 
       
    24 #ifndef __WSPENCODER_H__
       
    25 #define __WSPENCODER_H__
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <f32file.h>		// RFs
       
    29 #include <badesca.h>		// arrays etc.
       
    30 #include <stringpool.h>
       
    31 
       
    32 /**
       
    33 enum CodecPanic
       
    34 @publishedAll
       
    35 @released
       
    36 */
       
    37 enum TWspCodecPanic
       
    38 	{
       
    39 	/**  Due to failure to call StartValueLength function */
       
    40 	EWspCodecPanicStartValueLengthNotCalled=0,
       
    41 	/** Due to failure to call EndValueLength matching a call to StartValueLength */
       
    42 	EWspCodecPanicEndValueLengthNotCalled,
       
    43 	/** Due to failure to call StartHeaderL function */
       
    44 	EWspCodecPanicStartHeaderLNotCalled,
       
    45 	/** Due to StartHeaderL function being called twice without EndHeaderL */
       
    46 	EWspCodecPanicStartHeaderCalledTwice,
       
    47 	/** Due to parameter Token not having the top bit set */
       
    48 	EWspCodecPanicInvalidToken
       
    49 	};
       
    50  
       
    51 /** 
       
    52 This class can be used to encode one header field at a time,
       
    53 with all its values and parameters.
       
    54 
       
    55 It has no knowledge of encoding the BNF of a particular header field, but
       
    56 the functions provided can be used in combination, producing an 8-bit buffer 
       
    57 containing the encoded header.
       
    58 
       
    59 Intended usage would be to call a series of functions. The first one being StartHeader,
       
    60 The final one being EndHeader, which would return a buffer containing 
       
    61 the complete encoded header field.
       
    62 eg:
       
    63 	encoder->StartHeaderL();
       
    64 	encoder->AddLongIntL();
       
    65 	encoder->AddTextStringL();
       
    66 	HBufC8* output = encoder->EndHeaderL();
       
    67 @publishedAll
       
    68 @released
       
    69 */
       
    70 class CWspHeaderEncoder : public CBase
       
    71 	{
       
    72 public:
       
    73 	IMPORT_C static CWspHeaderEncoder* NewL();
       
    74 
       
    75 	IMPORT_C static CWspHeaderEncoder* NewLC();
       
    76 
       
    77 
       
    78     IMPORT_C virtual ~CWspHeaderEncoder(); 
       
    79 
       
    80 	IMPORT_C void StartHeaderL(TUint8 aToken);	
       
    81 
       
    82 
       
    83 	IMPORT_C void StartHeaderL(const TDesC8& aString);	
       
    84 
       
    85 	IMPORT_C void StartHeaderL(const RStringF aString);	
       
    86 
       
    87 
       
    88 	IMPORT_C HBufC8* EndHeaderL();
       
    89 
       
    90 
       
    91 
       
    92 	IMPORT_C void AddIntegerL(const TUint aInt);
       
    93 
       
    94 	
       
    95 	IMPORT_C void AddShortIntL(const TUint8 aValue);
       
    96 
       
    97 	IMPORT_C void AddShortLengthL(const TUint8 aValue);
       
    98 
       
    99 
       
   100 	IMPORT_C void AddLongIntL(const TUint32 aValue);
       
   101 	
       
   102 	
       
   103 	IMPORT_C void AddUintVarL(const TUint aInt);
       
   104 
       
   105 	
       
   106 	IMPORT_C void AddTextStringL(const RString& aText);
       
   107 
       
   108 	IMPORT_C void AddTextStringL(const TDesC8& aText);
       
   109 
       
   110 	IMPORT_C void AddDateL(const TDateTime aDate);
       
   111 
       
   112 	IMPORT_C void AddTokenL(const TUint8 aToken);
       
   113 
       
   114 	IMPORT_C void AddTokenTextL(const TDesC8& aTokenText);
       
   115 
       
   116 	IMPORT_C void AddDataL(const TDesC8& aData);
       
   117 
       
   118 
       
   119 
       
   120 	IMPORT_C void StartValueLengthL();
       
   121 
       
   122 	IMPORT_C void EndValueLengthL();
       
   123 
       
   124 private:
       
   125 
       
   126 	CWspHeaderEncoder();
       
   127 
       
   128 	void Init();
       
   129 
       
   130 
       
   131 	void ConstructL();
       
   132 
       
   133 private:
       
   134 	/**
       
   135 	Array for storing the partial encoded header.
       
   136 	Each time StartValueLength is called a new array
       
   137 	element is used. When EndValueLength is called,
       
   138 	the array is decremented, data from the last 
       
   139 	element being added to the one before.
       
   140 	*/
       
   141 	RPointerArray<CDesC8Array> iArray;
       
   142 
       
   143 	/**
       
   144 	Value incremented as the encoded header increases in size.
       
   145 	Used to allocate the buffer for storing the final	
       
   146 	encoded header, output when EndHeader is called.
       
   147 	*/
       
   148 	TInt iTotalLength;
       
   149 	};
       
   150 
       
   151 /** 
       
   152 Class encapsulating primitive encoding methods which are defined in the WSP standard.
       
   153 Input will be encoded and returned in an 8 bit buffer.
       
   154 @publishedAll
       
   155 @released
       
   156 */
       
   157 class TWspPrimitiveEncoder
       
   158 	{
       
   159 public:
       
   160 	IMPORT_C static TUint8  ShortInt(const TUint8 aValue);
       
   161 
       
   162 	IMPORT_C static HBufC8* LongIntL(const TUint32 aValue);
       
   163 
       
   164 	IMPORT_C static HBufC8* UintVarL(const TUint32 aInt);
       
   165 
       
   166 	IMPORT_C static HBufC8* TextStringL(const RString aText);
       
   167 
       
   168 	IMPORT_C static HBufC8* TextStringL(const TDesC8& aText);
       
   169 
       
   170 	IMPORT_C static HBufC8* DateL(const TDateTime aDate);
       
   171 	};
       
   172 
       
   173 #endif	// __WSPENCODER_H__