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

📄 bjackview.cpp

📁 手机文件浏览器 Here are the sources to SMan v1.2c 1.2 is a major jump from v1.1. You will see this from the
💻 CPP
📖 第 1 页 / 共 4 页
字号:
				btDevice[i].isBluejacked = statusValidNotBluejacked;
				
				break;
			}
		}
	}
	
	// Ok, device wasn't found. We should insert it. It may be possible our array is
	// full (with cache and decaying entries). In that case, we should issue a message
	// to the user informing thus
	if (!isExist)
	{
		// Only the following types of array entries can be overwritten.
		// - empty entries (isBluejacked == statusNoDevice)
		// - decaying entries who's decay time is up
		// - cached entries

		oldInterval = -1;
		for (int i = 0; i < MAX_BTDEV_ADDR; i++)
		{
			if (currentTime.SecondsFrom(btDevice[i].lastBluejackedTime, interval) != 0)
				interval = -1;

			// Is this a decaying item? If so, check if its time is up
			if (btDevice[i].isBluejacked == statusValidBluejacked)
			{
				if (interval.Int() >= configData->decayTime)
				{
					// This entry's decay time is up!
					isInserted = ETrue;
					btDevice[i].btDevAddr = btDevAddr;
					if (resolveAction != KHostResInquiry)
						btDevice[i].btNames = nameEntry().iName;
					btDevice[i].isBluejacked = statusValidNotBluejacked;
					// Since this is a new entry, we haven't done a SDP. Set port to -1
					btDevice[i].obexPort = -1;
					currentDeviceIndex = i;
					break;
				}
			}
			// Is this an empty entry? If so insert immediately!
			else if (btDevice[i].isBluejacked == statusNoDevice)
			{
				isInserted = ETrue;
				btDevice[i].btDevAddr = btDevAddr;
				if (resolveAction != KHostResInquiry)
					btDevice[i].btNames = nameEntry().iName;
				btDevice[i].isBluejacked = statusValidNotBluejacked;
				// Since this is a new entry, we haven't done a SDP. Set port to -1
				btDevice[i].obexPort = -1;
				
				currentDeviceIndex = i;
				break;
			}
			// Is this a cached entry? If so take the one with the oldest timestamp
			else if (btDevice[i].isBluejacked == statusCached)
			{
				if (currentTime.SecondsFrom(btDevice[i].lastBluejackedTime, interval) != 0)
					interval = -1;
				if (interval > oldInterval)
					cacheIndexToOverwrite = i;
			}
		}
		
		// Did we insert?
		if (isInserted)
		{
			HBufC* dataBuffer = CEikonEnv::Static()->AllocReadResourceL(R_TBUF_BJACKFOUNDDEVICE);
			logWithLookup(*dataBuffer, CLogger::logScanning);
			delete dataBuffer;

			/*
			CEikonEnv::Static()->ReadResource(txt, R_TBUF_BJACKFOUNDDEVICE);
			logWithLookup(txt, CLogger::logScanning);
			*/
		}
		// Did we find a suitable cached entry to overwrite?
		else if (cacheIndexToOverwrite > -1)
		{
			HBufC* dataBuffer = CEikonEnv::Static()->AllocReadResourceL(R_TBUF_BJACKCACHEFULL);
			logWithLookup(*dataBuffer, CLogger::logScanning);
			delete dataBuffer;

			/*
			CEikonEnv::Static()->ReadResource(txt, R_TBUF_BJACKCACHEFULL);
			logWithLookup(txt, CLogger::logScanning);
			*/
			btDevice[cacheIndexToOverwrite].btDevAddr = btDevAddr;
			if (resolveAction != KHostResInquiry)
				btDevice[cacheIndexToOverwrite].btNames = nameEntry().iName;
			btDevice[cacheIndexToOverwrite].isBluejacked = statusValidNotBluejacked;
			// Since this is a new entry, we haven't done a SDP. Set port to -1
			btDevice[cacheIndexToOverwrite].obexPort = -1;
		}
		// None of the above. This means buffer is full :(
		else
		{
			//CEikonEnv::Static()->ReadResource(txt, R_TBUF_BJACKCACHEFULLSKIP);
			HBufC* dataBuffer = CEikonEnv::Static()->AllocReadResourceL(R_TBUF_BJACKCACHEFULLSKIP);
			dataBuffer = dataBuffer->ReAllocL(dataBuffer->Length() + 0x100 + 3);
			
			if (resolveAction == KHostResInquiry)
			{
				TBuf<30> temp;
				temp.Format(_L("%x:%x:%x:%x:%x:%x - "), btDevAddr[0], btDevAddr[1], 
				btDevAddr[2], btDevAddr[3], btDevAddr[4], btDevAddr[5]);
				dataBuffer->Des().Insert(0, temp);
				logHelper->updateLog(dataBuffer, 0, CLogger::logScanning);
				
			/*
				TBuf<65> temp;
				temp.Format(_L("%x:%x:%x:%x:%x:%x - "), btDevAddr[0], btDevAddr[1], 
				btDevAddr[2], btDevAddr[3], btDevAddr[4], btDevAddr[5]);
				temp.Append(txt);
				logHelper->updateLog(&temp, 0, CLogger::logScanning);
			*/
			}
			else
			{
				dataBuffer->Des().Insert(0, _L(" - "));
				dataBuffer->Des().Insert(0, nameEntry().iName);
			
			/*			
				TBuf<0x100> temp;
				temp.Copy(nameEntry().iName);
				temp.Append(_L(" - "));
				temp.Append(txt);
				logHelper->updateLog(&temp, 0, CLogger::logScanning);
			*/
			}
			delete dataBuffer;
		}
	}	
	currentNoDeviceAttempts = 0;
	return isInserted;
}

void CScanner::DoCancel()
{
	if (obexClient)
	{
		//obexClient->Abort();
		delete obexClient;
		obexClient = NULL;
	}
	if (obexFile)
	{
		delete obexFile;
		obexFile = NULL;
	}

	if (hostResolverOpen)
	{
		hostResolver.Close();
		hostResolverOpen = EFalse;
	}
}

TInt CScanner::selectDevice(void)
{
	TBTDevAddr devAddress;
	TBTDeviceName devName;
	TBTDeviceClass devClass;

	CQBTUISelectDialog* selectDialog = new (ELeave) CQBTUISelectDialog(devAddress, devName, devClass, CQBTUISelectDialog::EQBTDeviceFilterAll, EMajorServiceObjectTransfer, EFalse);
	if (selectDialog->LaunchSingleSelectDialogLD() == 3)
	{
		insertAndUpdateBTList(devAddress, devName);
		return KErrNone;
	}
	else
		return KErrCancel;
}

void CScanner::playAudio(void)
{
	if (audioPlayerUtil)
	{
		delete audioPlayerUtil;
		audioPlayerUtil = NULL;
	}
	TPtrC audioFileNamePtr(*localAudioFile);
	if (localAudioFile->Length() > 0)
	{
		TRAPD(err, audioPlayerUtil = CMdaAudioPlayerUtility::NewFilePlayerL(audioFileNamePtr, *this));
		if (err)
		{
			MapcPlayComplete(err);
		}
	}
}

void CScanner::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
{
	if (aError)
		MapcPlayComplete(aError);
	else
		audioPlayerUtil->Play();
}

void CScanner::MapcPlayComplete(TInt /*aError*/)
{
	if (audioPlayerUtil)
	{
		delete audioPlayerUtil;
		audioPlayerUtil = NULL;
	}
}

/*************************************************************
*
* Search for OBEX and find its RFCOMM port
*
**************************************************************/

CFindOBEX::CFindOBEX()
{
	iSdpSearchPattern = NULL;
	iMatchList = NULL;
	iAgent = NULL;
}

void CFindOBEX::StartListL(CSdpAttrValueList& /*aList*/)
{
}

void CFindOBEX::EndListL()
{
}

void CFindOBEX::releaseObjects(void)
{
	if (iAgent)
	{
		delete iAgent;
		iAgent = NULL;
	}
	if (iSdpSearchPattern)
	{
		delete iSdpSearchPattern;
		iSdpSearchPattern = NULL;
	}
	if (iMatchList)
	{
		delete iMatchList;
		iMatchList = NULL;
	}
}

void CFindOBEX::start(TRequestStatus* theStatus, const TBTDevAddr* theAddress)
{
	releaseObjects();
	localStatus = theStatus;
	
    iSdpSearchPattern = CSdpSearchPattern::NewL();
    iSdpSearchPattern->AddL(KL2CAP);
    iMatchList = CSdpAttrIdMatchList::NewL();
    iMatchList->AddL(TAttrRange(0x0000, 0x0005));
    iAgent = CSdpAgent::NewL(*this, *theAddress);
	iAgent->SetRecordFilterL(*iSdpSearchPattern);
	RFCOMMPort = -1;

	// This is an asynchronous call. On completion it calls
	// MSdpAgentNotifier::NextRecordRequestComplete() 
    iAgent->NextRecordRequestL();
}

void CFindOBEX::searchDone(TUint errorNumber)
{
	releaseObjects();
	User::RequestComplete(localStatus, errorNumber);
}

// Called when an service record request (CSdpAgent::NextRecordRequestL()) 
// operation completes.
void CFindOBEX::NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
{
	if (foundOBEX == 8)
	{
		searchDone(0);
		return;
	}
	foundOBEX = 0;
	if (aError != KErrNone)
	{
		searchDone(aError);
		return;
	}
	if (aTotalRecordsCount > 0)
	{
		/*
		Gets the specified attribute for a remote service. The function is asynchronous: 
		on completion, it calls MSdpAgentNotifier::AttributeRequestComplete(). 
		If the attribute is found, the function passes it by also calling 
		MSdpAgentNotifier::AttributeRequestResult().
		*/
        iAgent->AttributeRequestL(aHandle, *iMatchList);
	}
	else
	{
		searchDone(KErrEof);
		return;
	}
}

// Called when an attribute request (CSdpAgent::AttributeRequestL()) finds 
// that there are no more attributes to be returned.
void CFindOBEX::AttributeRequestComplete(TSdpServRecordHandle /*aHandle*/, TInt aError)
{
	if (aError == KErrNone)
	{
		if (foundOBEX != 8)
			iAgent->NextRecordRequestL();
		else
		{
			searchDone(aError);
			return;
		}
	}
	else
	{
		searchDone(aError);
		return;
	}
}

// Called by the attribute request function (CSdpAgent::AttributeRequestL()) to pass the 
// results of a successful attribute request.
void CFindOBEX::AttributeRequestResult(TSdpServRecordHandle /*aHandle*/, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue)
{

	// We're past the protocol descriptor list
	if (aAttrID > 0x4)
		foundOBEX = 0;
		
	if (aAttrID == 0x4)
	{
		// Did we previously discover a service class attribute?
		if (foundOBEX == 3)
		{
			foundOBEX = 4;
		}
	}
	else if (aAttrID == 0x1)
	{
		foundOBEX = 1;
	}
	
	// When called on attributes that are not lists (not DEA or DES), then this calls 
	// MSdpAttributeValueVisitor::VisitAttributeValueL(), passing the attribute value
	// object itself (i.e. *this), and the value attribute type.
	if ((foundOBEX != 8) && (aAttrID <= 0x4))
	{
		aAttrValue->AcceptVisitorL(*this);
    
	}
    // Ownership has been transferred
    delete aAttrValue;
}

void CFindOBEX::VisitAttributeValueL(CSdpAttrValue& aValue, TSdpElementType aType)
{
	if (foundOBEX == 8)
		return;
		
	// Looking for service class attribute
	if (foundOBEX == 1)
	{
		if (aType == ETypeDES)
			foundOBEX = 2;
	}
	// Found service class attribute. Is it OBEX?
	else if (foundOBEX == 2)
	{
		if (aType == ETypeUUID)
		{
			if (aValue.UUID() == 0x1105)
				foundOBEX = 3;
		}
	}
	// Found OBEX service class and Protocol descriptor list. Is this RFCOMM?
	else if (foundOBEX == 4)
	{
		if (aType == ETypeDES)
			foundOBEX = 5;
	}
	else if (foundOBEX == 5)
	{
		if (aType == ETypeDES)
			foundOBEX = 6;
	}
	else if (foundOBEX == 6)
	{
		if (aType == ETypeUUID)
		{
			// Is it RFCOMM?
			if (aValue.UUID() == 0x0003)
				foundOBEX = 7;
			else
				foundOBEX = 5;
		}
		else if (foundOBEX != 8)
			foundOBEX = 5;
	}
	else if (foundOBEX == 7)
	{
		if (aType == ETypeUint)
		{
			RFCOMMPort = aValue.Uint();
			foundOBEX = 8;
		}
	}
}

/*************************************************************
*
* Timeout handler
*
**************************************************************/

CTimeout::CTimeout() : CTimer(EPriorityNormal)
{
	CTimer::ConstructL();
	CActiveScheduler::Add(this);
}

void CTimeout::RunL(void)
{
	TTime currentTime;
	TTimeIntervalSeconds interval;
			
	currentTime.HomeTime();
	if (currentTime.SecondsFrom(timeoutStart, interval) != 0)
		interval = localObexTimeout;
	if (interval.Int() >= localObexTimeout)
	{
		// Timed out. Is the scanner object still waiting?
		if (scanObj->IsActive())
		{
			HBufC* dataBuffer = CEikonEnv::Static()->AllocReadResourceL(R_TBUF_BJACKTIMEOUT);
			scanObj->logHelper->updateLog(dataBuffer, 0, CLogger::logOBEX);
			delete dataBuffer;

			/*
			TBuf<30> txt;
			CEikonEnv::Static()->ReadResource(txt, R_TBUF_BJACKTIMEOUT);
			*/

			// This is hard coded to be an OBEX log category since timeout is only used
			// by OBEX calls
			//scanObj->logHelper->updateLog(&txt, 0, CLogger::logOBEX);
			scanObj->timeoutAbort();
		}
	}
	else
		After(TIMER_GRANULARITY);
}

void CTimeout::startTimer(CScanner *theScanObj, TInt obexTimeout)
{
	scanObj = theScanObj;
	localObexTimeout = obexTimeout;
	timeoutStart.HomeTime();
	stopTimer();
	After(TIMER_GRANULARITY);
}

void CTimeout::stopTimer(void)
{
	if (IsActive())
		Cancel();
}

/*************************************************************
*
* Bluebeamer. Quite similar to scanner class
*
**************************************************************/

CBlueBeam::CBlueBeam(CConfig *cData) : CTimer(EPriorityNormal)
{
	beamerProtocol = -1;	// Undefined default protocol
	fakeAutoSaveFlag = EFalse;
	beamerStatus = isIdle;
	selectedFiles = 0;
	logHelper = new (ELeave) CLogger(cData);
	logHelper->controlId = cBluebeamLog;
	CTimer::ConstructL();
	CActiveScheduler::Add(this);
}

CBlueBeam::~CBlueBeam()
{
	delete logHelper;
}

void CBlueBeam::startBeam(void)
{
	CSMan2AppUi *tempUiObj = STATIC_CAST(CSMan2AppUi*, CEikonEnv::Static()->EikAppUi());
	if (selArray)
	{

⌨️ 快捷键说明

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