--- a/bluetooth/btsdp/database/responsesizevisitor.cpp Thu Sep 23 17:06:47 2010 +0300
+++ b/bluetooth/btsdp/database/responsesizevisitor.cpp Wed Oct 13 16:20:29 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2000-2010 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"
@@ -19,30 +19,40 @@
#include "mignorer.h"
#include "DataEncoder.h"
+#include <bluetooth/logger.h>
+DEFINE_LOG_COMPONENT(LOG_COMPONENT_SDPDATABASE)
+
+DEBUG_PANIC_CATEGORY("sdprspvis")
+
// Class CHandleItem
-EXPORT_C CHandleItem* CHandleItem::NewLC()
+
+CHandleItem* CHandleItem::NewLC(TSdpServRecordHandle aHandleID, CSdpServRecord* aRecord)
{
- CHandleItem* self = new(ELeave)CHandleItem();
+ LOG_STATIC_FUNC
+ CHandleItem* self = new(ELeave) CHandleItem(aHandleID, aRecord);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
-EXPORT_C CHandleItem* CHandleItem::NewL()
+CHandleItem::CHandleItem(TSdpServRecordHandle aHandleID, CSdpServRecord* aRecord)
+ : CBase()
+ , iHandleID(aHandleID)
+ , iRecord(aRecord)
{
- CHandleItem* self = CHandleItem::NewLC();
- CleanupStack::Pop();
- return self;
+ LOG_FUNC
}
void CHandleItem::ConstructL()
{
- iAttrSizeList = new (ELeave) CArrayPtrFlat<CAttrSizeItem>(KSDPAttListGran);
+ LOG_FUNC
+ iAttrSizeList = new (ELeave) CArrayPtrFlat<TAttrSizeItem>(KSDPAttListGran);
}
CHandleItem::~CHandleItem()
{
+ LOG_FUNC
if (iAttrSizeList)
{
iAttrSizeList->ResetAndDestroy();
@@ -50,16 +60,7 @@
}
}
-EXPORT_C CHandleItem* CHandleItem::CHandleItemL(TSdpServRecordHandle aHandleID, CSdpServRecord* aRecord)
- {
- CHandleItem* self = NewL();
- self->iHandleID = aHandleID;
- self->iRecord = aRecord;
- self->iRecordSize = 0;
- return self;
- }
-
-void CHandleItem::AddAttrItemL(CAttrSizeItem* aItem)
+void CHandleItem::AddAttrItemL(TAttrSizeItem* aItem)
{
iAttrSizeList->AppendL(aItem);
iRecordSize += aItem->Size() + 3; // add the attrID header size;
@@ -67,8 +68,10 @@
void CHandleItem::AddAttrItemL(const TSdpAttributeID aAttributeID, TUint aSize, CSdpAttr* aAttribute)
{
- CAttrSizeItem* sizeItem = new (ELeave) CAttrSizeItem(aAttributeID, aSize, aAttribute);
+ TAttrSizeItem* sizeItem = new (ELeave) TAttrSizeItem(aAttributeID, aSize, aAttribute);
+ CleanupStack::PushL(sizeItem);
AddAttrItemL(sizeItem);
+ CleanupStack::Pop(sizeItem);
}
@@ -116,13 +119,12 @@
{
for (TInt j = 0; j<AttrCount(i); j++)
{
- CAttrSizeItem* attr = AttributeOf(i,j);
+ TAttrSizeItem* attr = AttributeOf(i,j);
CSdpAttrValue& theVal = attr->Attr()->Value();
Mem::Crc(totalCrc, reinterpret_cast<const TAny*>(theVal.Des()[0]), attr->Size());
}
}
return totalCrc;
-
}
/**
@@ -160,7 +162,7 @@
TInt attrCount = AttrCount(i); // for testing
for (TInt j = iFirstAtt; j < attrCount; j++)
{
- CAttrSizeItem* attr = AttributeOf(i,j);
+ TAttrSizeItem* attr = AttributeOf(i,j);
recordSize += attr->Size();
recordSize +=3; // the size of a attribute ID in the list
}
@@ -284,7 +286,7 @@
totalSize += desSize;
while (more && (iFirstAtt < topAtt))
{
- CAttrSizeItem* attr = AttributeOf(iFirstRec, iFirstAtt);
+ TAttrSizeItem* attr = AttributeOf(iFirstRec, iFirstAtt);
TUint nextSize = attr->Size();
nextSize += 3; // Attribute ID and its header
if (totalSize + nextSize > aOffset)
@@ -309,7 +311,6 @@
aAtt = iFirstAtt;
aPartSent = aOffset - totalSize;
return ETrue;
-// __ASSERT_DEBUG(totalSize != aOffset, DbPanic(ESdpDbBadSearchPattern));
}
EXPORT_C TInt CSizeAccumulator::HandleCount()
@@ -330,77 +331,69 @@
EXPORT_C TInt CSizeAccumulator::AttrCount(TInt aOffset)
{
- if (iHandleList->Count() == 0) return 0;
+ if (iHandleList->Count() == 0)
+ {
+ return 0;
+ }
__ASSERT_DEBUG(aOffset <= iHandleList->Count(), DbPanic(ESdpDbBadSearchPattern));
- if (iHandleList->At(aOffset) == NULL) return 0;
- return iHandleList->At(aOffset)->CHandleItem::iAttrSizeList->Count();
- }
-
-EXPORT_C CAttrSizeItem* CSizeAccumulator::AttributeOf(TInt aHandleOffset, TInt aAttOffset)
- {
- if (iHandleList->Count() == 0) return (CAttrSizeItem*)0;
- __ASSERT_DEBUG(aHandleOffset < iHandleList->Count(), DbPanic(ESdpDbBadSearchPattern));
- CHandleItem* hnd = iHandleList->At(aHandleOffset);
- if (hnd->iAttrSizeList->Count() == 0) return (CAttrSizeItem*)0;
- __ASSERT_DEBUG(aAttOffset < hnd->iAttrSizeList->Count(), DbPanic(ESdpDbBadSearchPattern));
-// return iHandleList->At(aHandleOffset)->CHandleItem::iAttrSizeList->At(aAttOffset);
- return hnd->iAttrSizeList->At(aAttOffset);
+
+ if (!iHandleList->At(aOffset))
+ {
+ return 0;
+ }
+
+ return iHandleList->At(aOffset)->iAttrSizeList->Count();
}
-
-
-// need this because CResponseSizeVisitor already has start list method...
-class CSizeEncVisitorAdaptor : public MIgnorer
+EXPORT_C TAttrSizeItem* CSizeAccumulator::AttributeOf(TInt aHandleOffset, TInt aAttOffset)
{
-public:
- CSizeEncVisitorAdaptor(CResponseSizeVisitor& aVisitor)
- :iVisitor(aVisitor)
- {}
- MSdpElementBuilder* BuildUUIDL(const TUUID& aUUID)
+ if (iHandleList->Count() == 0)
{
- iVisitor.FoundUUIDL(aUUID);
- return this;
+ return NULL;
}
-private:
- CResponseSizeVisitor& iVisitor;
- };
-
-
+ __ASSERT_DEBUG(aHandleOffset < iHandleList->Count(), DbPanic(ESdpDbBadSearchPattern));
+
+ CHandleItem* hnd = iHandleList->At(aHandleOffset);
+
+ if (hnd->iAttrSizeList->Count() == 0)
+ {
+ return NULL;
+ }
+ __ASSERT_DEBUG(aAttOffset < hnd->iAttrSizeList->Count(), DbPanic(ESdpDbBadSearchPattern));
+
+ return hnd->iAttrSizeList->At(aAttOffset);
+ }
// Class CResponseSizeVisitor
CResponseSizeVisitor::CResponseSizeVisitor()
+ : CBase()
+ , iAdapter(*this)
{
+ LOG_FUNC
}
CResponseSizeVisitor::~CResponseSizeVisitor()
{
+ LOG_FUNC
delete iFoundIndex;
- delete iCurrentRec;
- delete iAdapter;
delete iParser;
}
CResponseSizeVisitor* CResponseSizeVisitor::NewLC()
{
- CResponseSizeVisitor* self = new(ELeave)CResponseSizeVisitor();
+ LOG_STATIC_FUNC
+ CResponseSizeVisitor* self = new(ELeave) CResponseSizeVisitor();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
-CResponseSizeVisitor* CResponseSizeVisitor::NewL()
- {
- CResponseSizeVisitor* self = CResponseSizeVisitor::NewLC();
- CleanupStack::Pop();
- return self;
- }
-
void CResponseSizeVisitor::ConstructL()
{
- iAdapter = new(ELeave) CSizeEncVisitorAdaptor(*this);
- iParser = CElementParser::NewL(iAdapter);
+ LOG_FUNC
+ iParser = CElementParser::NewL(&iAdapter);
}
// Iterate thru attributes in record
@@ -412,121 +405,138 @@
*/
void CResponseSizeVisitor::SearchRecordL(CSdpServRecord& aRec)
{
-// could be in calling routine
+ LOG_FUNC
+ // could be in calling routine
if (iSearchPattern)
- {
- if (iFoundIndex)
- {
- delete iFoundIndex;
- iFoundIndex = 0;
- }
+ {
+ delete iFoundIndex;
+ iFoundIndex = NULL;
iFoundIndex = CBitMapAllocator::NewL(iSearchSize);
iUseThis = EFalse;
- }
+ }
else
+ {
iUseThis = ETrue;
-// if (iCurrentRec) delete iCurrentRec; // I want a reset.
- iCurrentRec = CHandleItem::CHandleItemL(aRec.Handle(), &aRec);
+ }
+
+ CHandleItem* currentRec = CHandleItem::NewLC(aRec.Handle(), &aRec);
for(TServAttrIter attrIter(aRec.AttributeIter()); attrIter; attrIter++)
{
-/*
- we are checking every attribute, searching for the UUIDs. We don't exit if
- we find them all because we also want to get the sizes of any attributes which
- match our list if we have one.
- The array of sizes is built, then thrown away if it doesn't match.
-
-*/
+ // we are checking every attribute, searching for the UUIDs. We don't exit if
+ // we find them all because we also want to get the sizes of any attributes which
+ // match our list if we have one.
+ // The array of sizes is built, then thrown away if it doesn't match.
+
+ CSdpAttr* attr = attrIter;
+
if (iAtMatList)
{
- TSdpAttributeID theAttrID = (*attrIter).AttributeID();
+ TSdpAttributeID theAttrID = attr->AttributeID();
if(iAtMatList->InMatchList(theAttrID))
{// create a new array entry
- TUint size = (*attrIter).Value().DataSize();
- TSdpElementType type = (*attrIter).Value().Type();
+ TUint size = attr->Value().DataSize();
+ TSdpElementType type = attr->Value().Type();
if (type != ETypeEncoded)
{
-// some server records may be un-encoded
+ // some server records may be un-encoded
size += TElementEncoder::HeaderSize(type, size); // add the header size
}
- if(!(type==ETypeNil)&&!(type==ETypeEncoded&&size<=1))
- { // only include attribute if not either null or encoded null ...
- // (size of encoded (which INCLUDES header) in all non-null cases is > 1
- // because other attribute types either have
- // to have a header plus at least one byte, or they have at least a two byte header.)
- iCurrentRec->AddAttrItemL(theAttrID, size, attrIter);
+ if(type != ETypeNil && !(type == ETypeEncoded && size <= 1))
+ {
+ // only include attribute if not either null or encoded null ...
+ // (size of encoded (which INCLUDES header) in all non-null cases is > 1
+ // because other attribute types either have
+ // to have a header plus at least one byte, or they have at least a two byte header.)
+ currentRec->AddAttrItemL(theAttrID, size, attr);
}
}
}
// check if any UUIDs match only if we have a UUIDList.
- if (iSearchPattern) (*attrIter).AcceptVisitorL(*this);
+ if (iSearchPattern)
+ {
+ attr->AcceptVisitorL(*this);
+ }
}
+
if (iUseThis)
{
// now we have to copy the array(s) we've built up.
- iCollector->AddHandleL(iCurrentRec);
- iCurrentRec = 0;
+ iCollector->AddHandleL(currentRec);
+ CleanupStack::Pop(currentRec);
}
else
{
- delete iCurrentRec; // I don't want a heap fault.
- iCurrentRec = 0;
+ CleanupStack::PopAndDestroy(currentRec);
}
}
-// static void SizeRespSSL(CSdpDatabase& aDb, const CSdpSearchPattern &aPattern, const CSizeAccumulator& aCollector);
-// static void SizeRespARL(CSdpServRecord& aRec, CSdpAttrIdMatchList &aList, const CSizeAccumulator& aCollector);
-// static void SizeRespSAL(CSdpDatabase &aDb, const CSdpSearchPattern &aPattern, CSdpAttrIdMatchList &aList, const CSizeAccumulator& aCollector);
-// we need three of these calls, all slightly different
- EXPORT_C void CResponseSizeVisitor::SizeRespSSL(CSdpDatabase& aDb, const CSdpSearchPattern& aPattern, CSizeAccumulator& aCollector)
- {
- if (aPattern.Count() == 0) User::Leave(KErrArgument); // this is part of spec.
-// SDP_DEBUG(3, FPrint(_L("Sizing SDP DB for pattern with %d entries\n"), aPattern.Count()));
+EXPORT_C void CResponseSizeVisitor::SizeRespSSL(CSdpDatabase& aDb, const CSdpSearchPattern& aPattern, CSizeAccumulator& aCollector)
+ {
+ LOG_STATIC_FUNC
+ if (aPattern.Count() == 0)
+ {
+ User::Leave(KErrArgument); // this is part of spec.
+ }
+
+ LOG1(_L8("Sizing SDP DB for pattern with %d entries"), aPattern.Count());
CResponseSizeVisitor* theVisitor = CResponseSizeVisitor::NewLC();
+
theVisitor->iCollector = &aCollector;
- theVisitor->iAtMatList = NULL; // using it as a flag...
+ theVisitor->iAtMatList = NULL; // using it as a flag...
theVisitor->iSearchPattern = &aPattern;
theVisitor->iSearchSize = theVisitor->iSearchPattern->Count();
-
+
for(TServRecordIter recIter(aDb.RecordIter()); recIter; recIter++)
{// Iterate thru records in Db
theVisitor->SearchRecordL(*recIter);
}
- CleanupStack::PopAndDestroy();//theVisitor
+
+ CleanupStack::PopAndDestroy(theVisitor);
}
- EXPORT_C void CResponseSizeVisitor::SizeRespARL(CSdpServRecord& aRec, const CSdpAttrIdMatchList& aList, CSizeAccumulator& aCollector)
+EXPORT_C void CResponseSizeVisitor::SizeRespARL(CSdpServRecord& aRec, const CSdpAttrIdMatchList& aList, CSizeAccumulator& aCollector)
{
-// SDP_DEBUG(3, FPrint(_L("Sizing SDP DB for single record\n")));
+ LOG_STATIC_FUNC
+
+ LOG(_L8("Sizing SDP DB for single record"));
CResponseSizeVisitor* theVisitor = CResponseSizeVisitor::NewLC();
+
theVisitor->iCollector = &aCollector;
- theVisitor->iAtMatList = &aList; // using it as a flag...
+ theVisitor->iAtMatList = &aList; // using it as a flag...
theVisitor->iSearchPattern = NULL;
theVisitor->iSearchSize = 0;
+
theVisitor->SearchRecordL(aRec);
- CleanupStack::PopAndDestroy();//theVisitor
+
+ CleanupStack::PopAndDestroy(theVisitor);
}
- EXPORT_C void CResponseSizeVisitor::SizeRespSAL(CSdpDatabase &aDb, const CSdpSearchPattern &aPattern, const CSdpAttrIdMatchList& aList, CSizeAccumulator& aCollector)
+EXPORT_C void CResponseSizeVisitor::SizeRespSAL(CSdpDatabase &aDb, const CSdpSearchPattern &aPattern, const CSdpAttrIdMatchList& aList, CSizeAccumulator& aCollector)
{
- if (aPattern.Count() == 0) User::Leave(KErrArgument); // this is part of spec.
-// SDP_DEBUG(3, FPrint(_L("Sizing SDP DB (and attribs) with %d UUIDs\n"), aPattern.Count()));
+ LOG_STATIC_FUNC
+ if (aPattern.Count() == 0)
+ {
+ User::Leave(KErrArgument); // this is part of spec.
+ }
+
+ LOG1(_L8("Sizing SDP DB (and attribs) with %d UUIDs"), aPattern.Count());
CResponseSizeVisitor* theVisitor = CResponseSizeVisitor::NewLC();
+
theVisitor->iCollector = &aCollector;
- theVisitor->iAtMatList = &aList; // using it as a flag...
+ theVisitor->iAtMatList = &aList; // using it as a flag...
theVisitor->iSearchPattern = &aPattern;
theVisitor->iSearchSize = theVisitor->iSearchPattern->Count();
-
+
for(TServRecordIter recIter(aDb.RecordIter()); recIter; recIter++)
{// Iterate thru records in Db
theVisitor->SearchRecordL(*recIter);
}
- CleanupStack::PopAndDestroy();//theVisitor
+
+ CleanupStack::PopAndDestroy(theVisitor);
}
-
-
void CResponseSizeVisitor::VisitAttributeL(CSdpAttr& /*aAttribute*/)
{
}
@@ -538,13 +548,15 @@
case ETypeUUID:
FoundUUIDL(aValue.UUID());
break;
- case ETypeEncoded:
-// parse out any UUIDs in this encoded attribute
+
+ case ETypeEncoded:
+ // parse out any UUIDs in this encoded attribute
iParser->Reset();
/*rem = */iParser->ParseElementsL(aValue.Des());
break;
+
default:
- return;
+ break;
}
}
@@ -558,6 +570,8 @@
void CResponseSizeVisitor::FoundUUIDL(const TUUID& aUUID)
{
+ ASSERT_DEBUG(iSearchPattern);
+ ASSERT_DEBUG(iFoundIndex);
TInt pos;
if (iSearchPattern->Find(aUUID, pos)==0 &&
iFoundIndex->IsFree(pos))
@@ -569,3 +583,14 @@
}
}
}
+
+
+TSizeEncVisitorAdaptor::TSizeEncVisitorAdaptor(CResponseSizeVisitor& aVisitor)
+ :iVisitor(aVisitor)
+ {}
+
+MSdpElementBuilder* TSizeEncVisitorAdaptor::BuildUUIDL(const TUUID& aUUID)
+ {
+ iVisitor.FoundUUIDL(aUUID);
+ return this;
+ }