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