epoc32/include/etelutils.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
// Copyright (c) 2004-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
// Contains various utility classes which are used throughout Telephony.
williamr@2
    15
// 
williamr@2
    16
//
williamr@2
    17
williamr@2
    18
williamr@2
    19
williamr@2
    20
/**
williamr@2
    21
 @file
williamr@2
    22
 @publishedPartner
williamr@2
    23
 @released
williamr@2
    24
*/
williamr@2
    25
williamr@2
    26
#if !defined(__ETELUTILS_H__)
williamr@2
    27
/** @internalComponent */
williamr@2
    28
#define __ETELUTILS_H__
williamr@2
    29
williamr@2
    30
#include <e32base.h>
williamr@2
    31
williamr@2
    32
/**
williamr@2
    33
Base class for generic actions in retrieving a variable length buffer in two phases.
williamr@2
    34
williamr@2
    35
This class is abstract.
williamr@2
    36
williamr@2
    37
@publishedPartner
williamr@2
    38
@released
williamr@2
    39
*/
williamr@2
    40
class CAsyncRetrieveVariableLengthBufferV2 : public CActive
williamr@2
    41
	{
williamr@2
    42
protected:
williamr@2
    43
	//
williamr@2
    44
	// Start the retrieval
williamr@2
    45
	//
williamr@2
    46
williamr@2
    47
	IMPORT_C void Start(TRequestStatus& aReqStatus, TDes8* aPhase1Request, TDes8* aPhase2Request);
williamr@2
    48
	IMPORT_C CAsyncRetrieveVariableLengthBufferV2();
williamr@2
    49
	IMPORT_C virtual ~CAsyncRetrieveVariableLengthBufferV2();
williamr@2
    50
williamr@2
    51
	IMPORT_C TBool CompleteIfInUse(TRequestStatus& aReqStatus);
williamr@2
    52
	IMPORT_C void FreeBuffer();
williamr@2
    53
williamr@2
    54
private:
williamr@2
    55
	IMPORT_C virtual void RestoreListL();
williamr@2
    56
	virtual void Get(TInt aIpc, TRequestStatus& aReqStatus, TDes8& aDes1, TDes8& aDes2) = 0;
williamr@2
    57
	virtual void CancelReq(TInt aIpc1,TInt aIpc2) = 0;
williamr@2
    58
williamr@2
    59
	IMPORT_C virtual void DoCancel();
williamr@2
    60
	IMPORT_C virtual void RunL();
williamr@2
    61
williamr@2
    62
	void StartPhase2L();
williamr@2
    63
williamr@2
    64
protected:
williamr@2
    65
	/**
williamr@2
    66
	Maintains the current phase of buffer retrieval.
williamr@2
    67
	*/
williamr@2
    68
	enum {
williamr@2
    69
		EIdle,
williamr@2
    70
		ERetrievePhase1,
williamr@2
    71
		ERetrievePhase2
williamr@2
    72
		} iState;
williamr@2
    73
williamr@2
    74
	CBufBase* iResultsBuf;
williamr@2
    75
	TPtr8 iResultsPtr;
williamr@2
    76
	TInt iIpcPhase1;
williamr@2
    77
	TInt iIpcPhase2;
williamr@2
    78
	TInt iIpcCancel;
williamr@2
    79
private:
williamr@2
    80
	/**
williamr@2
    81
	Pointer to the user's asynchronous request status object.
williamr@2
    82
	*/
williamr@2
    83
	TRequestStatus* iUserStatus;
williamr@2
    84
	TDes8* iPhase1RequestData;
williamr@2
    85
	TDes8* iPhase2RequestData;
williamr@2
    86
	TPckgBuf<TInt> iBufferSize;
williamr@2
    87
	};
williamr@2
    88
	
williamr@2
    89
williamr@2
    90
///////////////////////////////////////////////////////////////////////////
williamr@2
    91
/* following classes define interface to  TLV ( TYPE- LENGTH-VALUE) structured data:
williamr@2
    92
-------------------------------------------------------------------------------------------------
williamr@2
    93
|       |                         |             |        |                          |           |
williamr@2
    94
|ItemId	| Length Of The Item Data |	Item Data	| ItemId |	Length Of The Item Data	| Item Data |
williamr@2
    95
|       |                         |             |        |                          |           |
williamr@2
    96
-------------------------------------------------------------------------------------------------
williamr@2
    97
*/
williamr@2
    98
williamr@2
    99
/**
williamr@2
   100
Defines interface for specifying the Tag of a TLV object.
williamr@2
   101
williamr@2
   102
@publishedPartner
williamr@2
   103
@released
williamr@2
   104
*/
williamr@2
   105
class MTlvItemIdType
williamr@2
   106
{
williamr@2
   107
public:
williamr@2
   108
/**Externalize object by serializing to provided descriptor*/
williamr@2
   109
	virtual void ExternalizeL(TDes8& aBuffer) const =0;
williamr@2
   110
/** Internalize object by de-serializing of data in provided buffer*/
williamr@2
   111
	virtual void InternalizeL(TDesC8& aBuffer)=0;
williamr@2
   112
/** The length of serialized data member */
williamr@2
   113
	virtual TUint SerializedLength() const =0;
williamr@2
   114
/**  compares whether two objects contains the same data*/
williamr@2
   115
	virtual TBool IsEqual(const MTlvItemIdType&) const=0;
williamr@2
   116
};
williamr@2
   117
williamr@2
   118
/**
williamr@2
   119
Defines interface for specifying the Length of a TLV object.
williamr@2
   120
williamr@2
   121
@publishedPartner
williamr@2
   122
@released
williamr@2
   123
*/
williamr@2
   124
class MTlvItemDataLengthType
williamr@2
   125
{
williamr@2
   126
public:
williamr@2
   127
/**Externalize object by serializing to provided descriptor*/
williamr@2
   128
	virtual void ExternalizeL(TDes8& aBuffer)const=0;
williamr@2
   129
/** Internalize object by de-serializing of data in provided buffer*/
williamr@2
   130
	virtual void InternalizeL(TDesC8& aBuffer)=0;
williamr@2
   131
/** The length of serialized data member */
williamr@2
   132
	virtual TUint SerializedLength() const=0;
williamr@2
   133
/** Sets length of the data it relates to*/
williamr@2
   134
	virtual void SetDataLength(TUint)=0;
williamr@2
   135
/** Gets length of the data it relates to*/
williamr@2
   136
	virtual TUint DataLength() const =0;
williamr@2
   137
};
williamr@2
   138
williamr@2
   139
/**
williamr@2
   140
Provides methods to append, remove or perform iterative lookup for items in container buffer.
williamr@2
   141
Classes ItemIdType and ItemDataLengthType have to implement interfaces MTlvItemIdType and
williamr@2
   142
MTlvItemDataLengthType in order to enable proper encoding and decoding of the first two fields
williamr@2
   143
in the unit.
williamr@2
   144
williamr@2
   145
@internalComponent
williamr@2
   146
@released
williamr@2
   147
*/
williamr@2
   148
class TTlvStructBase
williamr@2
   149
    {
williamr@2
   150
  protected:
williamr@2
   151
  	/** Default constructor initializes data members*/
williamr@2
   152
   	IMPORT_C TTlvStructBase(TPtr8&,TUint8);    
williamr@2
   153
 	/** Base class implementation of methods in the templated class*/
williamr@2
   154
   	IMPORT_C TInt AppendItemL(MTlvItemIdType& aId,MTlvItemDataLengthType& aDataLengthType,const TPtr8& aData);
williamr@2
   155
   	IMPORT_C TInt RemoveNextItemL(MTlvItemIdType& aIdToRemove,MTlvItemIdType& aId, MTlvItemDataLengthType& aDataLength);
williamr@2
   156
   	IMPORT_C TInt AnyNextItemL(MTlvItemIdType& aIdFound,TPtr8& aData,MTlvItemIdType& aId, MTlvItemDataLengthType& aDataLength);
williamr@2
   157
   	IMPORT_C TInt NextItemL(const MTlvItemIdType& aWantedId,TPtr8& aData,MTlvItemIdType& aId, MTlvItemDataLengthType& aDataLength);
williamr@2
   158
  public:
williamr@2
   159
	/** Sets position of the cursor to start position (0)*/
williamr@2
   160
	IMPORT_C void ResetCursorPos();
williamr@2
   161
williamr@2
   162
  protected:
williamr@2
   163
    /** Reference to external buffer that holds encoded TLV data*/
williamr@2
   164
    TPtr8& iPtr;
williamr@2
   165
    /** Cursor indicates last accessed item in the buffer*/
williamr@2
   166
	TUint iCursorPos;
williamr@2
   167
	/** Position in the buffer that indicates start of the zone that hasn't been assigned to any element.
williamr@2
   168
	 	this free zone ends at the end of the buffer*/
williamr@2
   169
	TUint iFreeSpacePos;
williamr@2
   170
	/** Character used to populate the zone that hasn't been assigned to any element.
williamr@2
   171
	this free zone ends at the end of the buffer*/
williamr@2
   172
	TUint8 iFreeSpaceChar;
williamr@2
   173
    };
williamr@2
   174
williamr@2
   175
/**
williamr@2
   176
Provides methods to append, remove or perform iterative lookup for items in container buffer.
williamr@2
   177
Classes ItemIdType and ItemDataLengthType have to implement interfaces MTlvItemIdType and 
williamr@2
   178
MTlvItemDataLengthType in order to enable proper encoding and decoding of the first two fields 
williamr@2
   179
in the unit. 
williamr@2
   180
williamr@2
   181
@publishedPartner
williamr@2
   182
@released
williamr@2
   183
*/  
williamr@2
   184
template <class ItemIdType, class ItemDataLengthType>
williamr@2
   185
class TTlvStruct: public TTlvStructBase
williamr@2
   186
    {
williamr@2
   187
 public:
williamr@2
   188
 	
williamr@2
   189
   	inline TTlvStruct(TPtr8&,TUint8);   
williamr@2
   190
	inline TInt NextItemL(ItemIdType aId,TPtr8& aData);
williamr@2
   191
	inline TInt AnyNextItemL(ItemIdType& aId, TPtr8& aData);
williamr@2
   192
	inline TInt AppendItemL(ItemIdType aId,const TPtr8& aData);
williamr@2
   193
	inline TInt RemoveNextItemL(ItemIdType aId);
williamr@2
   194
	
williamr@2
   195
 protected:
williamr@2
   196
	/** Default constructor is protected in order to enforce proper initialization of reference to external data buffer via provided public constructor*/
williamr@2
   197
    TTlvStruct();    	
williamr@2
   198
    /** Type of the identifier*/
williamr@2
   199
    ItemIdType iItemIdType;
williamr@2
   200
    /** The type used to define length of data portion of the item*/ 
williamr@2
   201
    ItemDataLengthType 	iItemDataLengthType;     
williamr@2
   202
};
williamr@2
   203
williamr@2
   204
/** 
williamr@2
   205
Default constructor initializes data members and cursor position to 0.
williamr@2
   206
williamr@2
   207
@param aPtr Ptr descriptor to TLV buffer that is to be read or written to.
williamr@2
   208
@param aFreeSpaceChar Character used to populate the zone that hasn't been assigned to any element.
williamr@2
   209
*/
williamr@2
   210
template <class ItemIdType,class ItemDataLengthType>
williamr@2
   211
	TTlvStruct<ItemIdType,ItemDataLengthType>::TTlvStruct(TPtr8& aPtr,TUint8 aFreeSpaceChar):TTlvStructBase(aPtr,aFreeSpaceChar)
williamr@2
   212
	{	
williamr@2
   213
	}
williamr@2
   214
	
williamr@2
   215
/**
williamr@2
   216
Look up in the buffer for an item with specified identifier.
williamr@2
   217
Look-up starts from the position of the cursor; 					
williamr@2
   218
Returns KErrNone if the item is present in the buffer, KErrNotFound otherwise.
williamr@2
   219
Sets supplied pointer so that it has length of item's data portion and points to it.
williamr@2
   220
Internal cursor is moved to first position after the end of the found item 
williamr@2
   221
(subsequent item start position in the buffer).
williamr@2
   222
williamr@2
   223
@param aId Id of item to find.
williamr@2
   224
@param aData Descriptor which will hold the found item.
williamr@2
   225
@return System-wide error code.. If item of requested Id was not found then KErrNotFound will be returned. 
williamr@2
   226
*/
williamr@2
   227
template <class ItemIdType, class ItemDataLengthType>
williamr@2
   228
TInt TTlvStruct<ItemIdType,ItemDataLengthType>::NextItemL(ItemIdType aId,TPtr8& aData)
williamr@2
   229
	{
williamr@2
   230
	return TTlvStructBase::NextItemL(aId,aData,iItemIdType,iItemDataLengthType);	
williamr@2
   231
	}
williamr@2
   232
williamr@2
   233
/**
williamr@2
   234
Look up in the buffer for the item with specified identifier.
williamr@2
   235
Look-up starts from the position of the cursor in the buffer. 
williamr@2
   236
			
williamr@2
   237
Returns KErrNone if item is found, KErrNotFound otherwise (end of buffer is reached).
williamr@2
   238
Sets supplied pointer so that it points to item data portion and has length set to value of data length. 
williamr@2
   239
Internal cursor is moved to first position after the end of the found item (subsequent item start position in the buffer).
williamr@2
   240
williamr@2
   241
@param aId Id of found item.
williamr@2
   242
@param aData Descriptor which will hold the found item.
williamr@2
   243
@return System-wide error code.. If no next item found then KErrNotFound will be returned. 
williamr@2
   244
*/
williamr@2
   245
template <class ItemIdType, class ItemDataLengthType>
williamr@2
   246
TInt TTlvStruct<ItemIdType,ItemDataLengthType>::AnyNextItemL(ItemIdType& aId,TPtr8& aData)
williamr@2
   247
	{
williamr@2
   248
	return TTlvStructBase::AnyNextItemL(aId,aData,iItemIdType,iItemDataLengthType);
williamr@2
   249
	}		
williamr@2
   250
	
williamr@2
   251
/**
williamr@2
   252
Removes item identified by specified identifier (aId) from the buffer, where look-up starts at current cursor position, or 0 if it's reset. 
williamr@2
   253
returns KErrNone if item is found ( and removed), otherwise error code - in the case where there is no more space in the assigned buffer, KErrOverflow is passed back. 
williamr@2
   254
williamr@2
   255
@param aId Id of item to remove.
williamr@2
   256
@return System-wide error code.. If item of requested Id was not found then KErrNotFound will be returned. 
williamr@2
   257
*/	
williamr@2
   258
template <class ItemIdType, class ItemDataLengthType>
williamr@2
   259
TInt TTlvStruct<ItemIdType,ItemDataLengthType>::RemoveNextItemL(ItemIdType aId)
williamr@2
   260
	{
williamr@2
   261
	return TTlvStructBase::RemoveNextItemL(aId,iItemIdType,iItemDataLengthType);	
williamr@2
   262
	}
williamr@2
   263
	
williamr@2
   264
/**
williamr@2
   265
Adds item identified by supplied aId argument to the buffer; content of the item is copied from provided descriptor to the buffer. 
williamr@2
   266
Supplied item identifier (aId) and length of the descriptor are used to set item identifier field and length field at the start of 
williamr@2
   267
item unit within the buffer.
williamr@2
   268
Returns KErrNone if successful, error code otherwise.	
williamr@2
   269
Internal cursor is moved to first position after the end of the found item (subsequent item start position in the buffer).
williamr@2
   270
williamr@2
   271
@param aId Id of item to add.
williamr@2
   272
@param aData Descriptor containing data to add.
williamr@2
   273
@return System-wide error code.. If size of item to be appended is greater than free space in buffer then KErrOverflow will be returned.
williamr@2
   274
*/	
williamr@2
   275
template <class ItemIdType, class ItemDataLengthType>
williamr@2
   276
TInt TTlvStruct<ItemIdType,ItemDataLengthType>::AppendItemL(ItemIdType aId,const TPtr8& aData)
williamr@2
   277
	{
williamr@2
   278
	return TTlvStructBase::AppendItemL(aId,iItemDataLengthType,aData);
williamr@2
   279
	}
williamr@2
   280
#endif