⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btserviceseng.cpp

📁 蓝牙通迅服务,挺有用的东东,希望对大家有所帮助
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			{
			unicode.Delete(unicode.Length() - 1, 1); // remove NULL-termination
			}
		iTextArray->AppendL(unicode);
		iView->ListBox().HandleItemAdditionL();
		}

	CleanupStack::PopAndDestroy(aAttrValue);  
	}

void CBtServicesEng::NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt /* aTotalRecordsCount */)
	{
	if ((aError == KErrNone) || (aError == KErrEof))
		{
		TRAPD(err, DoNextRecordRequestCompleteL(aHandle, aError));
		if (err != KErrNone)
			{
			aError = err;
			}
		}
	if (aError != KErrNone && aError != KErrEof)
		{
		iView->GetEikonEnv()->BusyMsgCancel();
		SdpCompletedWithError(aError);
		}
	}

void CBtServicesEng::DoNextRecordRequestCompleteL(TSdpServRecordHandle aHandle, TInt aError)
	{
	if (aError == KErrNone)    
		{
		iHandleArray.Append(aHandle);
		iSdpAgent->NextRecordRequestL();
		}
	else if (aError == KErrEof)
		{
		iHandleCounter = 0;
		iCurrentAttributeRequest = EGettingNamesOnly;
		GetServiceNamesL();
		}
	}

void CBtServicesEng::SdpCompletedWithError(const TInt aError)
	{
	HBufC* buf = HBufC::NewLC(KMaxDescriptorLength);
	TPtr errorText = buf->Des();
	AppendErrorMessage(aError,errorText);
	TGulAlignment position(EHRightVTop);
	iView->GetEikonEnv()->InfoMsgWithAlignmentAndDuration(position,errorText,KErrorMsgDuration);
	CleanupStack::PopAndDestroy();
	iSdpAgent->Cancel();
	iView->DimRefreshButton(EFalse);
	iView->DimCancelButton(ETrue);
	}

void CBtServicesEng::AppendErrorMessage(const TInt aError, TDes& aBuf) const
	{
	for (TInt i = 0; i < iErrorCodes.Count(); i++)
		{
		if (iErrorCodes[i] == aError)
			{
			aBuf.Append(*(iErrorMessages[i]));
			return;
			}
		}
	_LIT(KErrorTextOther, "Error: ");
	aBuf.Append(KErrorTextOther);
	aBuf.AppendNum(aError);
	}

void CBtServicesEng::Panic(TBtPanicCode aPanicCode)
	{
	_LIT(KBtPanicText, "BTSU::Panic ");
	User::Panic(KBtPanicText, aPanicCode);
	}

///////////////////////////////////////
// CBtAttributeBuilder functions
///////////////////////////////////////

CBtAttributeBuilder* CBtAttributeBuilder::NewL(CBtServicesEng& aEngine)
	{
	CBtAttributeBuilder* self = new(ELeave) CBtAttributeBuilder(aEngine);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
	}

CBtAttributeBuilder::CBtAttributeBuilder(CBtServicesEng& aEngine)
: iEngine(aEngine)
	{
	}

void CBtAttributeBuilder::ConstructL()
	{
	HBufC8* buf = CEikonEnv::Static()->AllocReadResourceAsDes8LC(R_ATTR_ID_MNEMONICS);

	TResourceReader res;
	res.SetBuffer(buf);

	TInt arrayCount = res.ReadInt16();
	for (TInt i = 0; i < arrayCount; i++)
		{
		TUint attrID = res.ReadUint32();
		iAttrIDs.Append(attrID);
		HBufC* mnemonic = res.ReadHBufCL();
		iAttrMnemonics.Append(mnemonic);
		}
	CleanupStack::PopAndDestroy(); // buf
	}

CBtAttributeBuilder::~CBtAttributeBuilder()
	{
	iAttrIDs.Close();
	iAttrMnemonics.ResetAndDestroy();
	iAttrMnemonics.Close();
	}

void CBtAttributeBuilder::Reset()
	{
	iIndentation = 0;
	iCurrentLine.Zero();
	}

void CBtAttributeBuilder::SetHandle(TSdpServRecordHandle aHandle)
	{
	iHandle = aHandle;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildUnknownL(TUint8 aType, TUint8 /* aSizeDesc */, const TDesC8& /* aData */)
	{
	if (iStatus == EExpectingAttrID)
		{
		_LIT(KErrorText,"**Error: Unexpected UNKNOWN");
		iCurrentLine.Append(KErrorText);
		}
	else
		{
		_LIT(KTextUnknown,"UNKNOWN");
		iCurrentLine.Append(KTextUnknown);
		iCurrentLine.AppendNum((TInt) aType);
		}		
	LineFinishedL();
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildNilL()
	{
	if (iStatus == EExpectingAttrID)
		{
		_LIT(KErrorText,"**Error: Unexpected NIL");
		iCurrentLine.Append(KErrorText);
		}
	else
		{
		_LIT(KTextNULL,"NULL");
		iCurrentLine.Append(KTextNULL);
		}
	LineFinishedL();
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildUintL(const TDesC8& aUint)
	{

	if (iStatus == EExpectingAttrValue)
		{
		iCurrentLine.Append(KTextHexPrefix);
		for (TInt i = 0; i < aUint.Length(); i++)
			{
			iCurrentLine.AppendNumFixedWidth(aUint[i], EHex,2);
			}
		LineFinishedL();
		}
	else if (iStatus == EExpectingAttrID)
		{
		TUint value = 0;
		for (TInt i = 0; i < aUint.Length(); i++)
			{
			value <<= 8;
			value += aUint[i];
			}
		AppendAttrMnemonic(iCurrentLine,value);
		iStatus = EExpectingAttrValue;
		}

	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildIntL(const TDesC8& aInt)
	{
	if (iStatus == EExpectingAttrID)
		{
		_LIT(KErrorText,"**Error: Unexpected Int");
		iCurrentLine.Append(KErrorText);
		}
	else
		{
		iCurrentLine.Append(KTextHexPrefix);
		for (TInt i = 0; i < aInt.Length(); i++)
			{
			iCurrentLine.AppendNumFixedWidth(aInt[i], EHex,2);
			}
		}
	LineFinishedL();
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildUUIDL(const TUUID& aUUID)
	{
	if (iStatus == EExpectingAttrID)
		{
		_LIT(KErrorText,"**Error: Unexpected UUID");
		iCurrentLine.Append(KErrorText);
		}
	else
		{
		iEngine.AppendUUIDText(iCurrentLine,aUUID);
		}
	LineFinishedL();
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildBooleanL(TBool aBool)
	{
	if (iStatus == EExpectingAttrID)
		{
		_LIT(KErrorText,"**Error: Unexpected Boolean");
		iCurrentLine.Append(KErrorText);
		}
	else
		{
		if (aBool)
			{
			_LIT(KTextTrue,"TRUE");
			iCurrentLine.Append(KTextTrue);
			}
		else
			{
			_LIT(KTextFalse,"FALSE");
			iCurrentLine.Append(KTextFalse);
			}
		}
	LineFinishedL();
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildStringL(const TDesC8& aString)
	{
	if (iStatus == EExpectingAttrID)
		{
		_LIT(KErrorText,"**Error: Unexpected String");
		iCurrentLine.Append(KErrorText);
		}
	else
		{
		TBuf16<KMaxDescriptorLength> unicode;
		CnvUtfConverter::ConvertToUnicodeFromUtf8(unicode,aString);
		if (unicode[unicode.Length() - 1] == NULL)
			{
			unicode.Delete(unicode.Length() - 1, 1); // remove NULL-termination
			}
		iCurrentLine.Append(unicode);
		}
	LineFinishedL();
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildDESL()
	{
	if (iIndentation == 1)
		{
		iEngine.AddAttributeLineL(iCurrentLine);
		}
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildDEAL()
	{
	_LIT(KTextDEAL,"Data Element Alternate List");
	iCurrentLine.Append(KTextDEAL);
	iEngine.AddAttributeLineL(iCurrentLine);
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::StartListL()
	{
	iIndentation++;
	iCurrentLine.Zero();
	__ASSERT_ALWAYS(iIndentation > 0, CBtServicesEng::Panic(EBtIndentationZeroInStartList));
	iCurrentLine.AppendFill(' ', (iIndentation - 1) * KIndentationFactor);
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::EndListL()
	{
	_LIT(KTextEndListDashes,"--------");
	iCurrentLine.Append(KTextEndListDashes);
	iEngine.AddAttributeLineL(iCurrentLine);
	iIndentation--;
	iCurrentLine.Zero();
	if (iIndentation)
		{
		iCurrentLine.AppendFill(' ', (iIndentation - 1) * KIndentationFactor); // in this case indentation has already been checked to be greater than zero
		}
	if (iIndentation == 1)
		{
		iStatus = EExpectingAttrID;
		}
	return this;
	}

MSdpElementBuilder* CBtAttributeBuilder::BuildURLL(const TDesC8& aURL)
	{
	TBuf16<KMaxDescriptorLength> unicode;
	CnvUtfConverter::ConvertToUnicodeFromUtf8(unicode,aURL);
	iCurrentLine.Append(unicode);
	LineFinishedL();
	return this;
	}

void CBtAttributeBuilder::AppendAttrMnemonic(TDes& aBuf, TUint aAttrID) const
	{
	for (TInt i = 0; i < iAttrIDs.Count(); i++)
		{
		if (iAttrIDs[i] == aAttrID)
			{
			aBuf.Append(*(iAttrMnemonics[i]));
			return;
			}
		}
	if (aAttrID == 0x0200 && iHandle == 0)
		{
		_LIT(KVersionNoPrefix,"VersionNo.: ");
		aBuf.Append(KVersionNoPrefix);
		}
	else if (aAttrID == 0x0201 && iHandle == 0)
		{
		_LIT(KDatabaseStatePrefix,"DatabaseState: ");
		aBuf.Append(KDatabaseStatePrefix);
		}
	else
		{
		_LIT(KTextAttrIDHex,"AttrID 0x");
		aBuf.Append(KTextAttrIDHex);
		aBuf.AppendNum(aAttrID,EHex);
		_LIT(KTextColonSpace,": ");
		aBuf.Append(KTextColonSpace);
		}
	}

void CBtAttributeBuilder::LineFinishedL()
	{
	iEngine.AddAttributeLineL(iCurrentLine);
	iCurrentLine.Zero();
	__ASSERT_ALWAYS(iIndentation > 0, CBtServicesEng::Panic(EBtIndentationZeroInLineFinished));
	iCurrentLine.AppendFill(' ', (iIndentation - 1) * KIndentationFactor);
	if (iIndentation == 1)
		{
		iStatus = EExpectingAttrID;
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -