williamr@2: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // 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: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // Contains various utility classes which are used throughout Telephony. williamr@2: // williamr@2: // williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: @file williamr@2: @publishedPartner williamr@2: @released williamr@2: */ williamr@2: williamr@2: #if !defined(__ETELUTILS_H__) williamr@2: /** @internalComponent */ williamr@2: #define __ETELUTILS_H__ williamr@2: williamr@2: #include williamr@2: williamr@2: /** williamr@2: Base class for generic actions in retrieving a variable length buffer in two phases. williamr@2: williamr@2: This class is abstract. williamr@2: williamr@2: @publishedPartner williamr@2: @released williamr@2: */ williamr@2: class CAsyncRetrieveVariableLengthBufferV2 : public CActive williamr@2: { williamr@2: protected: williamr@2: // williamr@2: // Start the retrieval williamr@2: // williamr@2: williamr@2: IMPORT_C void Start(TRequestStatus& aReqStatus, TDes8* aPhase1Request, TDes8* aPhase2Request); williamr@2: IMPORT_C CAsyncRetrieveVariableLengthBufferV2(); williamr@2: IMPORT_C virtual ~CAsyncRetrieveVariableLengthBufferV2(); williamr@2: williamr@2: IMPORT_C TBool CompleteIfInUse(TRequestStatus& aReqStatus); williamr@2: IMPORT_C void FreeBuffer(); williamr@2: williamr@2: private: williamr@2: IMPORT_C virtual void RestoreListL(); williamr@2: virtual void Get(TInt aIpc, TRequestStatus& aReqStatus, TDes8& aDes1, TDes8& aDes2) = 0; williamr@2: virtual void CancelReq(TInt aIpc1,TInt aIpc2) = 0; williamr@2: williamr@2: IMPORT_C virtual void DoCancel(); williamr@2: IMPORT_C virtual void RunL(); williamr@2: williamr@2: void StartPhase2L(); williamr@2: williamr@2: protected: williamr@2: /** williamr@2: Maintains the current phase of buffer retrieval. williamr@2: */ williamr@2: enum { williamr@2: EIdle, williamr@2: ERetrievePhase1, williamr@2: ERetrievePhase2 williamr@2: } iState; williamr@2: williamr@2: CBufBase* iResultsBuf; williamr@2: TPtr8 iResultsPtr; williamr@2: TInt iIpcPhase1; williamr@2: TInt iIpcPhase2; williamr@2: TInt iIpcCancel; williamr@2: private: williamr@2: /** williamr@2: Pointer to the user's asynchronous request status object. williamr@2: */ williamr@2: TRequestStatus* iUserStatus; williamr@2: TDes8* iPhase1RequestData; williamr@2: TDes8* iPhase2RequestData; williamr@2: TPckgBuf iBufferSize; williamr@2: }; williamr@2: williamr@2: williamr@2: /////////////////////////////////////////////////////////////////////////// williamr@2: /* following classes define interface to TLV ( TYPE- LENGTH-VALUE) structured data: williamr@2: ------------------------------------------------------------------------------------------------- williamr@2: | | | | | | | williamr@2: |ItemId | Length Of The Item Data | Item Data | ItemId | Length Of The Item Data | Item Data | williamr@2: | | | | | | | williamr@2: ------------------------------------------------------------------------------------------------- williamr@2: */ williamr@2: williamr@2: /** williamr@2: Defines interface for specifying the Tag of a TLV object. williamr@2: williamr@2: @publishedPartner williamr@2: @released williamr@2: */ williamr@2: class MTlvItemIdType williamr@2: { williamr@2: public: williamr@2: /**Externalize object by serializing to provided descriptor*/ williamr@2: virtual void ExternalizeL(TDes8& aBuffer) const =0; williamr@2: /** Internalize object by de-serializing of data in provided buffer*/ williamr@2: virtual void InternalizeL(TDesC8& aBuffer)=0; williamr@2: /** The length of serialized data member */ williamr@2: virtual TUint SerializedLength() const =0; williamr@2: /** compares whether two objects contains the same data*/ williamr@2: virtual TBool IsEqual(const MTlvItemIdType&) const=0; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Defines interface for specifying the Length of a TLV object. williamr@2: williamr@2: @publishedPartner williamr@2: @released williamr@2: */ williamr@2: class MTlvItemDataLengthType williamr@2: { williamr@2: public: williamr@2: /**Externalize object by serializing to provided descriptor*/ williamr@2: virtual void ExternalizeL(TDes8& aBuffer)const=0; williamr@2: /** Internalize object by de-serializing of data in provided buffer*/ williamr@2: virtual void InternalizeL(TDesC8& aBuffer)=0; williamr@2: /** The length of serialized data member */ williamr@2: virtual TUint SerializedLength() const=0; williamr@2: /** Sets length of the data it relates to*/ williamr@2: virtual void SetDataLength(TUint)=0; williamr@2: /** Gets length of the data it relates to*/ williamr@2: virtual TUint DataLength() const =0; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Provides methods to append, remove or perform iterative lookup for items in container buffer. williamr@2: Classes ItemIdType and ItemDataLengthType have to implement interfaces MTlvItemIdType and williamr@2: MTlvItemDataLengthType in order to enable proper encoding and decoding of the first two fields williamr@2: in the unit. williamr@2: williamr@2: @internalComponent williamr@2: @released williamr@2: */ williamr@2: class TTlvStructBase williamr@2: { williamr@2: protected: williamr@2: /** Default constructor initializes data members*/ williamr@2: IMPORT_C TTlvStructBase(TPtr8&,TUint8); williamr@2: /** Base class implementation of methods in the templated class*/ williamr@2: IMPORT_C TInt AppendItemL(MTlvItemIdType& aId,MTlvItemDataLengthType& aDataLengthType,const TPtr8& aData); williamr@2: IMPORT_C TInt RemoveNextItemL(MTlvItemIdType& aIdToRemove,MTlvItemIdType& aId, MTlvItemDataLengthType& aDataLength); williamr@2: IMPORT_C TInt AnyNextItemL(MTlvItemIdType& aIdFound,TPtr8& aData,MTlvItemIdType& aId, MTlvItemDataLengthType& aDataLength); williamr@2: IMPORT_C TInt NextItemL(const MTlvItemIdType& aWantedId,TPtr8& aData,MTlvItemIdType& aId, MTlvItemDataLengthType& aDataLength); williamr@2: public: williamr@2: /** Sets position of the cursor to start position (0)*/ williamr@2: IMPORT_C void ResetCursorPos(); williamr@2: williamr@2: protected: williamr@2: /** Reference to external buffer that holds encoded TLV data*/ williamr@2: TPtr8& iPtr; williamr@2: /** Cursor indicates last accessed item in the buffer*/ williamr@2: TUint iCursorPos; williamr@2: /** Position in the buffer that indicates start of the zone that hasn't been assigned to any element. williamr@2: this free zone ends at the end of the buffer*/ williamr@2: TUint iFreeSpacePos; williamr@2: /** Character used to populate the zone that hasn't been assigned to any element. williamr@2: this free zone ends at the end of the buffer*/ williamr@2: TUint8 iFreeSpaceChar; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Provides methods to append, remove or perform iterative lookup for items in container buffer. williamr@2: Classes ItemIdType and ItemDataLengthType have to implement interfaces MTlvItemIdType and williamr@2: MTlvItemDataLengthType in order to enable proper encoding and decoding of the first two fields williamr@2: in the unit. williamr@2: williamr@2: @publishedPartner williamr@2: @released williamr@2: */ williamr@2: template williamr@2: class TTlvStruct: public TTlvStructBase williamr@2: { williamr@2: public: williamr@2: williamr@2: inline TTlvStruct(TPtr8&,TUint8); williamr@2: inline TInt NextItemL(ItemIdType aId,TPtr8& aData); williamr@2: inline TInt AnyNextItemL(ItemIdType& aId, TPtr8& aData); williamr@2: inline TInt AppendItemL(ItemIdType aId,const TPtr8& aData); williamr@2: inline TInt RemoveNextItemL(ItemIdType aId); williamr@2: williamr@2: protected: williamr@2: /** Default constructor is protected in order to enforce proper initialization of reference to external data buffer via provided public constructor*/ williamr@2: TTlvStruct(); williamr@2: /** Type of the identifier*/ williamr@2: ItemIdType iItemIdType; williamr@2: /** The type used to define length of data portion of the item*/ williamr@2: ItemDataLengthType iItemDataLengthType; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Default constructor initializes data members and cursor position to 0. williamr@2: williamr@2: @param aPtr Ptr descriptor to TLV buffer that is to be read or written to. williamr@2: @param aFreeSpaceChar Character used to populate the zone that hasn't been assigned to any element. williamr@2: */ williamr@2: template williamr@2: TTlvStruct::TTlvStruct(TPtr8& aPtr,TUint8 aFreeSpaceChar):TTlvStructBase(aPtr,aFreeSpaceChar) williamr@2: { williamr@2: } williamr@2: williamr@2: /** williamr@2: Look up in the buffer for an item with specified identifier. williamr@2: Look-up starts from the position of the cursor; williamr@2: Returns KErrNone if the item is present in the buffer, KErrNotFound otherwise. williamr@2: Sets supplied pointer so that it has length of item's data portion and points to it. williamr@2: Internal cursor is moved to first position after the end of the found item williamr@2: (subsequent item start position in the buffer). williamr@2: williamr@2: @param aId Id of item to find. williamr@2: @param aData Descriptor which will hold the found item. williamr@2: @return System-wide error code.. If item of requested Id was not found then KErrNotFound will be returned. williamr@2: */ williamr@2: template williamr@2: TInt TTlvStruct::NextItemL(ItemIdType aId,TPtr8& aData) williamr@2: { williamr@2: return TTlvStructBase::NextItemL(aId,aData,iItemIdType,iItemDataLengthType); williamr@2: } williamr@2: williamr@2: /** williamr@2: Look up in the buffer for the item with specified identifier. williamr@2: Look-up starts from the position of the cursor in the buffer. williamr@2: williamr@2: Returns KErrNone if item is found, KErrNotFound otherwise (end of buffer is reached). williamr@2: Sets supplied pointer so that it points to item data portion and has length set to value of data length. williamr@2: Internal cursor is moved to first position after the end of the found item (subsequent item start position in the buffer). williamr@2: williamr@2: @param aId Id of found item. williamr@2: @param aData Descriptor which will hold the found item. williamr@2: @return System-wide error code.. If no next item found then KErrNotFound will be returned. williamr@2: */ williamr@2: template williamr@2: TInt TTlvStruct::AnyNextItemL(ItemIdType& aId,TPtr8& aData) williamr@2: { williamr@2: return TTlvStructBase::AnyNextItemL(aId,aData,iItemIdType,iItemDataLengthType); williamr@2: } williamr@2: williamr@2: /** williamr@2: 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: 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: williamr@2: @param aId Id of item to remove. williamr@2: @return System-wide error code.. If item of requested Id was not found then KErrNotFound will be returned. williamr@2: */ williamr@2: template williamr@2: TInt TTlvStruct::RemoveNextItemL(ItemIdType aId) williamr@2: { williamr@2: return TTlvStructBase::RemoveNextItemL(aId,iItemIdType,iItemDataLengthType); williamr@2: } williamr@2: williamr@2: /** williamr@2: Adds item identified by supplied aId argument to the buffer; content of the item is copied from provided descriptor to the buffer. williamr@2: 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: item unit within the buffer. williamr@2: Returns KErrNone if successful, error code otherwise. williamr@2: Internal cursor is moved to first position after the end of the found item (subsequent item start position in the buffer). williamr@2: williamr@2: @param aId Id of item to add. williamr@2: @param aData Descriptor containing data to add. williamr@2: @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: */ williamr@2: template williamr@2: TInt TTlvStruct::AppendItemL(ItemIdType aId,const TPtr8& aData) williamr@2: { williamr@2: return TTlvStructBase::AppendItemL(aId,iItemDataLengthType,aData); williamr@2: } williamr@2: #endif