diff -r 000000000000 -r 29b1cd4cb562 bluetooth/btsdp/database/sdputil.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetooth/btsdp/database/sdputil.h Fri Jan 15 08:13:17 2010 +0200 @@ -0,0 +1,204 @@ + +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#ifndef SDPUTIL_H +#define SDPUTIL_H + +#include +#include + +enum TSdpLeaveError + { + ESdpUnexpectedAttributeValueType = -1, + }; + +_LIT(KSdpDatabasePanicString, "SDP-Database"); +_LIT(KSdpParsePanicString, "SDP-Parse"); + +/** +Panic values: + ESdpDbBadAttrValueGetter Panics if the virtual base class method is called. Must be overriden in derived classes. + ESdpDbBadSearchPattern Panics if a bad search pattern is provided. + ESdpDbRecordBadHandle Panics if a bad handle to a record is provided. + ESdpCSdpStackFixIsEmpty Panics if CSdpStackFix is empty + ESdpNoAttrValue Panics if an attribute value is missing. + ESdpAttrValueBadSize Panics if an attribute value is a bad size. + ESDPServerNoDatabase Panics if there is no server database + ESdpDbAttributeEncodingFailed Panics if the attribute cannot be encoded because it is of unknown type. + ESdpDbStoredAttrValNotEncoded Panics if the attribute was not correctly encoded. + ESdpDbOrderedQueueItemIsHead Panics if the queue iterator has failed. + ESdpDbOrderedQueuePositionClash Panics if there is a position clash in the queue. + */ +enum TSdpDbPanic + { + ESdpDbBadAttrValueGetter = 0, + ESdpDbBadSearchPattern = 1, + ESdpDbRecordBadHandle = 2, + ESdpCSdpStackFixIsEmpty = 3, + ESdpNoAttrValue = 4, + ESdpAttrValueBadSize = 5, + ESDPServerNoDatabase = 6, + ESdpDbAttributeEncodingFailed = 7, + ESdpDbStoredAttrValNotEncoded = 8, + ESdpDbOrderedQueueItemIsHead = 9, + ESdpDbOrderedQueuePositionClash = 10, + }; + +void DbPanic(TSdpDbPanic aCode); + +//TSdpAgPanic - see ..\agent\agutil.h + + +/** +Panic values: + EGetUintBadDescriptorLength Panics if the descriptor has a bad length + EFrameOverrun Panics if the frame has overrun + EListOverrun Panics if the list has overrun + EGetUint64BadDescriptorLength Panics if the descriptor does not contain a parsable Uint64 + EGetUint128BadDescriptorLength Panics if the descriptor does not contain a parsable Uint128 +*/ +enum TSdpParsePanic + { + EGetUintBadDescriptorLength = 0, + EFrameOverrun = 1, + EListOverrun = 2, + EGetUint64BadDescriptorLength = 3, + EGetUint128BadDescriptorLength = 4, + }; + +void ParsePanic(TSdpParsePanic); + +template +class TOrderedQue : public TDblQue + { +public: + inline TOrderedQue(TInt aOffset); + void AddInOrder(T& aRef); + void ResetAndDestroy(); + }; + +const TInt KStackGranularity=4; + +template +class CSdpStackFix : public CArrayFixSeg + { +public: + inline CSdpStackFix(); + inline ~CSdpStackFix(); + + inline TBool IsEmpty() const; + inline void PushL(T aItem); + inline T Pop(); + inline const T& Head() const; + inline T& Head(); + inline const T& Last() const; + }; + + +// +// Inlines +// + +template +inline TOrderedQue::TOrderedQue(TInt aOffset) +: TDblQue(aOffset) + { + } + +template +void TOrderedQue::AddInOrder(T& aRef) + { + if (TDblQue::IsEmpty() || aRef > (*TDblQue::Last())) + { + TDblQue::AddLast(aRef); + return; + } + + TDblQueIter iter (*this); + while (aRef > *iter) + iter++; + + __ASSERT_DEBUG(!TDblQue::IsHead(iter), DbPanic(ESdpDbOrderedQueueItemIsHead)); + __ASSERT_DEBUG(*iter > aRef, DbPanic(ESdpDbOrderedQueuePositionClash)); // If this fails, there is a position clash! + PtrAdd((TDblQueLink*)&aRef, TDblQue::iOffset)->AddBefore(PtrAdd((TDblQueLink*)&(*iter), TDblQue::iOffset)); + } + +template +void TOrderedQue::ResetAndDestroy() + { + while (!TDblQue::IsEmpty()) + { + delete TDblQue::First(); + } + } + +template +inline CSdpStackFix::CSdpStackFix() +: CArrayFixSeg(KStackGranularity) + { + CArrayFixSeg::Reset(); + } + +template +inline CSdpStackFix::~CSdpStackFix() + { + CArrayFixSeg::Reset(); + } + +template +inline TBool CSdpStackFix::IsEmpty() const + { + return CArrayFixSeg::Count()==0; + } + +template +inline void CSdpStackFix::PushL(T aItem) + { + CArrayFixSeg::AppendL(aItem); + } + +template +inline T CSdpStackFix::Pop() + { + __ASSERT_DEBUG(!IsEmpty(), DbPanic(ESdpCSdpStackFixIsEmpty)); + T item=Head(); + CArrayFixSeg::Delete(CArrayFixSeg::Count()-1); + return item; + } + +template +inline const T &CSdpStackFix::Head() const + { + __ASSERT_DEBUG(!IsEmpty(), DbPanic(ESdpCSdpStackFixIsEmpty)); + return CArrayFixSeg::At(CArrayFixSeg::Count()-1); + } + +template +inline T &CSdpStackFix::Head() + { + __ASSERT_DEBUG(!IsEmpty(), DbPanic(ESdpCSdpStackFixIsEmpty)); + return CArrayFixSeg::At(CArrayFixSeg::Count()-1); + } + +template +inline const T &CSdpStackFix::Last() const + { + __ASSERT_DEBUG(!IsEmpty(), DbPanic(ESdpCSdpStackFixIsEmpty)); + return CArrayFixSeg::At(0); + } + + +#endif