EXPORT_C TInt CMTPTypeString::NextWriteChunk(TPtr8& aChunk)
    {
    TInt ret(KMTPChunkSequenceCompletion);
    
    if (iWriteSequenceState != ENumChars)
        {
        ret = KErrNotReady;
        }
    else
        {
        const TUint numChars(NumChars());
        __ASSERT_ALWAYS((numChars <= KMTPMaxStringLength), Panic(EMTPTypeSizeMismatch));
        if (numChars > 0)
            {
        	aChunk.Set(&iBuffer[KMTPStringCharactersOffset], 0, (iBuffer.MaxLength() - KMTPAlignmentSize - KMTPNumCharsSize));
            }
        else
            {
            aChunk.Set(NULL, 0, 0);
            }
            
        iWriteSequenceState = EStringChars;
        }
        
    return ret;
    }
EXPORT_C int WstringToTptr8(wstring& aSrc, char* cPtr, TPtr8& aDes)
{
    int retval = ESuccess;
    unsigned int wlen = 0, ilendes = 0;
    const wchar_t* wcharString = aSrc.c_str();
    int minusone = -1;
    
    if (L'\0' == wcharString[0])
    {
    	return EStringNoData;
    }
    
	wlen = wcslen(wcharString);
	ilendes = aDes.MaxLength();
	
	if (ilendes < 2*wlen)
	{
		return EInsufficientMemory;
	}
	
	if(minusone != wcstombs(cPtr, wcharString, wlen*2))
	{
		aDes.Set((unsigned char *)cPtr, wlen*2, ilendes);	
	}
	else
	{
		retval = EInvalidWCSSequence;
	}
		
	return retval;
}
EXPORT_C TInt CMTPTypeString::FirstWriteChunk(TPtr8& aChunk)
    {
    TInt ret(KErrNone);
    aChunk.Set(&iBuffer[KMTPNumCharsOffset], 0, KMTPNumCharsSize);
    iWriteSequenceState = ENumChars;        
    return ret;
    }
Example #4
0
void CDevCommIOBase::CreateL(TInt aSize)
	{
	iSize = aSize;
	if (iSize>0)
		iBuffer = (TUint8*)User::AllocL(iSize);
	iDes.Set(iBuffer, iSize, iSize);
	}
Example #5
0
HX_RESULT HXSymbianTCPReader::Read(RSocket& socket, UINT16 uSize)
{
    HX_RESULT res = HXR_FAILED;

    if (m_pParent)
    {
        res = HXSymbianSocketHelper::ResizeOrCreate(m_pCCF, uSize, m_pBuffer);
        
        if (HXR_OK == res)
        {
            IHXTimeStampedBuffer* pTSBuffer = 0;
	      if(HXR_OK == m_pBuffer->QueryInterface(IID_IHXTimeStampedBuffer, (void **)&pTSBuffer))
	      {
	      		pTSBuffer->SetTimeStamp(HX_GET_TICKCOUNT());
			HX_RELEASE(pTSBuffer);
		}		 
            m_bufDes.Set(m_pBuffer->GetBuffer(), 0, m_pBuffer->GetSize());

            iStatus = KRequestPending;
            socket.RecvOneOrMore(m_bufDes, 0, iStatus, m_amountRead);
            SetActive();
        }
    }

    return res;
}
EXPORT_C TInt CMTPTypeObjectPropList::FirstWriteChunk(TPtr8& aChunk, TUint aDataLength)
    {
    TInt ret = KMTPDataTypeInvalid;
    if (aDataLength <= KMTPPropListBufferPageSize - iTransportHeaderIndex)
        {
        aChunk.Set(&(iIOPages[0][iTransportHeaderIndex]), 0, aDataLength);
        ret = KMTPChunkSequenceCompletion;
        }
    else
        {
        aChunk.Set(&(iIOPages[0][iTransportHeaderIndex]), 0, KMTPPropListBufferPageSize - iTransportHeaderIndex);
        ret = KErrNone;
        }
    
    return ret;
    }
TInt CHbDeviceDialogSymbianPrivate::Initialize()
{
    if (!iBuffer) {
        TRAP_IGNORE(iBuffer = HBufC8::NewL(64));
        if (iBuffer) {
            iDataPtr.Set(iBuffer->Des());
        } else {
            return KErrNoMemory;
        }
    }

    TInt error(KErrNone);
    if (iFlags & CHbDeviceDialogSymbian::EASyncServerStartup) {
        HbDeviceDialogLaunchHelper *helper(0);
        TRAP(error, helper = HbDeviceDialogLaunchHelper::NewL());
        
        if (helper) {            
            helper->Start();
            error = helper->Error();
            delete helper;
            helper = 0;
            }        
    }

    if (error == KErrNone || error == KErrAlreadyExists) {
        error = iHbSession.Connect();
    }
    return error;
}
EXPORT_C TInt CMTPTypeObjectPropList::NextWriteChunk(TPtr8& aChunk, TUint aDataLength)
    {
    TInt ret = KMTPDataTypeInvalid;
    ReserveNewPage();
    if (aDataLength <= KMTPPropListBufferPageSize)
        {
        aChunk.Set(&(iIOPages[iIOPages.Count()-1][0]), 0, aDataLength);
        ret = KMTPChunkSequenceCompletion;
        }
    else
        {
        aChunk.Set(&(iIOPages[iIOPages.Count()-1][0]), 0, KMTPPropListBufferPageSize);
        ret = KErrNone;
        }
    
    return ret;    
    }
void CLocationEngine::InsertIntoPayload(TInt aPosition, const TDesC8& aString, TPtr8& aLogStanza) {
	if(aLogStanza.Length() + aString.Length() > aLogStanza.MaxLength()) {
		iLogStanza = iLogStanza->ReAlloc(aLogStanza.MaxLength() + aString.Length() + 32);
		aLogStanza.Set(iLogStanza->Des());
	}

	aLogStanza.Insert(aPosition, aString);
}
void CBBListenerImpl::GetLoca()
{
	if (IsActive()) return;

	iGetState=EGettingLoca;
	iSerializedData->Des().Zero();
	iP.Set(iSerializedData->Des());
	iBBClient.Get(KLocaMessageStatusTuple, KNullDesC, iFullArgs, iP, iStatus);
	SetActive();
}
void CBBListenerImpl::GetListener()
{
	if (IsActive()) return;

	iGetState=EGettingListener;
	iSerializedData->Des().Zero();
	iP.Set(iSerializedData->Des());
	iBBClient.Get(KListener, iFullArgs, iP, iStatus);
	SetActive();

}
EXPORT_C TBool CMTPTypeObjectPropList::ReserveTransportHeader(TUint aHeaderLength, TPtr8& aHeader)
	{
    if (aHeaderLength > KReservedTransportHeaderSize)
        {
        return EFalse;
        }
    
    iTransportHeaderIndex = KReservedTransportHeaderSize - aHeaderLength;
    
    aHeader.Set(&(iIOPages[0][iTransportHeaderIndex]), aHeaderLength, aHeaderLength);
    return ETrue;
	}
EXPORT_C TInt CMTPTypeOpaqueData::FirstWriteChunk(TPtr8& aChunk)
    {
    if(iPtrBuffer.MaxSize() == 0)
        {
        TInt err =  CreateBuffer( KMaxSizeOfWriteBuffer );
        if( KErrNone != err)
            return err;
        }
    
    aChunk.Set( const_cast<TUint8*>(iPtrBuffer.Ptr()), 0, iPtrBuffer.MaxSize());
    
    return KMTPChunkSequenceCompletion;
    }
void CBBListenerImpl::WaitForNotify()
{
	CALLSTACKITEM_N(_CL("CBBListenerImpl"), _CL("WaitForNotify"));

	Log(_L("CBBListener::WaitForNotify()"));

	if (IsActive()) return;

	iGetState=EWaitForNotify;
	iSerializedData->Des().Zero();
	iP.Set(iSerializedData->Des());
	iBBClient.WaitForNotify(iFullArgs, iP, iStatus);
	SetActive();
}
void CBBSessionImpl::ConstructL()
{
	CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("ConstructL"));

	iSubscriptions=CSubscriptions::NewL();
	User::LeaveIfError(iClientSession.Connect());

	iGetPutBuf=HBufC8::NewL(2048);
	iNotifyBuf=HBufC8::NewL(2048);

	CActiveScheduler::Add(this);
	iNotifyBufP.Set(iNotifyBuf->Des());
	iStatus=KRequestPending;
	SetActive();
	iClientSession.WaitForNotify(iFull, iNotifyBufP, iStatus);
}
Example #16
0
//
// Start asynchronous recv() operation
//
pj_status_t CIoqueueCallback::StartRead (pj_ioqueue_op_key_t *op_key,
        void *buf, pj_ssize_t *size,
        unsigned flags,
        pj_sockaddr_t *addr, int *addrlen)
{
    PJ_ASSERT_RETURN (IsActive() ==false, PJ_EBUSY);
    PJ_ASSERT_RETURN (pending_data_.common_.op_key_==NULL, PJ_EBUSY);

    flags &= ~PJ_IOQUEUE_ALWAYS_ASYNC;

    pending_data_.read_.op_key_ = op_key;
    pending_data_.read_.addr_ = addr;
    pending_data_.read_.addrlen_ = addrlen;

    aBufferPtr_.Set ( (TUint8*) buf, 0, (TInt) *size);

    type_ = TYPE_READ;

    if (addr && addrlen) {
        sock_->Socket().RecvFrom (aBufferPtr_, aAddress_, flags, iStatus);
    } else {
        aAddress_.SetAddress (0);
        aAddress_.SetPort (0);

        if (sock_->IsDatagram()) {
            sock_->Socket().Recv (aBufferPtr_, flags, iStatus);
        } else {
            // Using static like this is not pretty, but we don't need to use
            // the value anyway, hence doing it like this is probably most
            // optimal.
            static TSockXfrLength len;
            sock_->Socket().RecvOneOrMore (aBufferPtr_, flags, iStatus, len);
        }
    }

    SetActive();
    return PJ_EPENDING;
}
EXPORT_C TInt TMTPTypeFlatBase::NextWriteChunk(TPtr8& aChunk)
    {
    aChunk.Set(NULL, 0, 0);
    return KErrNotReady;
    }
EXPORT_C TInt TMTPTypeFlatBase::FirstWriteChunk(TPtr8& aChunk)
    {
    __ASSERT_ALWAYS(iBuffer.MaxLength() > 0, Panic(EMTPTypeBadStorage));
    aChunk.Set(&iBuffer[0], 0, iBuffer.MaxLength());
    return KMTPChunkSequenceCompletion;
    }
Example #19
0
size_t ReadData(const void* ptr, size_t size, size_t numItems, TSymbianFileEntry* handle) {
	TSymbianFileEntry* entry = ((TSymbianFileEntry *)(handle));
	TUint32 totsize = size*numItems;
	TPtr8 pointer ( (unsigned char*) ptr, totsize);

	// Nothing cached and we want to load at least KInputBufferLength bytes
	if (totsize >= KInputBufferLength) {
		TUint32 totLength = 0;
		if (entry->_inputPos != KErrNotFound) {
			TPtr8 cacheBuffer( (unsigned char*) entry->_inputBuffer+entry->_inputPos, entry->_inputBufferLen - entry->_inputPos, KInputBufferLength);
			pointer.Append(cacheBuffer);
			entry->_inputPos = KErrNotFound;
			totLength+=pointer.Length();
			pointer.Set(totLength+(unsigned char*) ptr, 0, totsize-totLength);
		}

		entry->_lastError = entry->_fileHandle.Read(pointer);

		totLength+=pointer.Length();

		pointer.Set((unsigned char*) ptr, totLength, totsize);

	} else {
		// Nothing in buffer
		if (entry->_inputPos == KErrNotFound) {
			TPtr8 cacheBuffer( (unsigned char*) entry->_inputBuffer, KInputBufferLength);
			entry->_lastError = entry->_fileHandle.Read(cacheBuffer);

			if (cacheBuffer.Length() >= totsize) {
				pointer.Copy(cacheBuffer.Left(totsize));
				entry->_inputPos = totsize;
				entry->_inputBufferLen = cacheBuffer.Length();
			} else {
				pointer.Copy(cacheBuffer);
				entry->_inputPos = KErrNotFound;
			}

		} else {
			TPtr8 cacheBuffer( (unsigned char*) entry->_inputBuffer, entry->_inputBufferLen, KInputBufferLength);

			if (entry->_inputPos+totsize < entry->_inputBufferLen) {
				pointer.Copy(cacheBuffer.Mid(entry->_inputPos, totsize));
				entry->_inputPos+=totsize;
			} else {

				pointer.Copy(cacheBuffer.Mid(entry->_inputPos, entry->_inputBufferLen-entry->_inputPos));
				cacheBuffer.SetLength(0);
				entry->_lastError = entry->_fileHandle.Read(cacheBuffer);

				if (cacheBuffer.Length() >= totsize-pointer.Length()) {
					TUint32 restSize = totsize-pointer.Length();
					pointer.Append(cacheBuffer.Left(restSize));
					entry->_inputPos = restSize;
					entry->_inputBufferLen = cacheBuffer.Length();
				} else {
					pointer.Append(cacheBuffer);
					entry->_inputPos = KErrNotFound;
				}
			}
		}
	}

	if ((numItems * size) != pointer.Length() && entry->_lastError == KErrNone) {
		entry->_eofReached = ETrue;
	}

	return pointer.Length() / size;
}
EXPORT_C TInt CMTPTypeOpaqueData::NextWriteChunk(TPtr8& aChunk)
    {
    aChunk.Set(NULL, 0, 0);
    return KErrNotReady;
    }
/**
@SYMTestCaseID			PDS-SQL-UT-4151
@SYMTestCaseDesc		Measures the performance of inserting multiple records
						into the Music Player MPX database.  This test is based on 
						a real Music Player Harvesting use case
@SYMTestPriority		Medium
@SYMTestActions			Reads SQL transactions from a file and executes them.  
						Records the time for executing each statement
@SYMTestExpectedResults All statements should be executed without error and 
						performance measurements logged
@SYMDEF					DEF142306
*/
void RunTest()
	{
	//Open the file with the sql statements 
	_LIT(KSqlFileName,"z:\\test\\t_sqlperformance4.sql");
	RFile sqlFile;
	TInt err = sqlFile.Open(TheFs, KSqlFileName, EFileRead); 
	TEST2(err, KErrNone);
	
	TInt fileLen = 0;
	err = sqlFile.Size(fileLen); 
	TEST2(err, KErrNone);
	
	HBufC8* sqlBuf = HBufC8::New(fileLen); 
	TEST(sqlBuf != NULL);
	TPtr8 sql = sqlBuf->Des();
	err = sqlFile.Read(sql);
	
	sqlFile.Close();
	TEST2(err, KErrNone);
	TEST2(sql.Length(), fileLen);
	
	//Open main database
	err = TheDbC.Open(TheDbFileName, &TheSqlConfigString);
	TEST2(err, KErrNone);
	
	TheTest.Printf(_L("Beginning INSERTS...\n"));
	
	const TInt KRecordCount = 6544;
	TInt recordCount = 0;
	TInt insertCnt = 0;
	TInt updateCnt = 0;
	TInt selectCnt = 0;
	TInt trnCnt = 0;
	TInt totalTime = 0;

	TInt insertTrnCnt = 0;
	TInt updateTrnCnt = 0;
	TInt selectTrnCnt = 0;
	
	for(;sql.Length()>0;)
		{
		TInt eolPos = sql.Locate(TChar('\n'));
		if(eolPos < 0)
			{
			break;//No more SQL statements
			}
		TInt stmtLength = eolPos;
		while (stmtLength > 0 && (sql[stmtLength-1] == '\r'))
			{
			--stmtLength; //Reduce length to remove carriage return characters from the end of the statement string
			}
		TPtrC8 sqlStmt8(sql.Ptr(), stmtLength);
		TPtrC8 ptr = sql.Mid(eolPos + 1);//"eolPos + 1" - first character after '\n'
		sql.Set(const_cast <TUint8*> (ptr.Ptr()), ptr.Length(), ptr.Length());
		++recordCount;
		
		//Convert to 16 bit query string
		TBuf<1024> query;
		query.Copy(sqlStmt8);
		
		//Execute the statement
		TInt start = User::FastCounter();
		err = TheDbC.Exec(query);
		TInt end = User::FastCounter();
		
		TEST(err >= 0);
		
		//Get the execution time for that statement
		TInt duration = GetDuration(start, end);
		totalTime += duration;
		
		if(query == KBeginTransaction)
			{		
			TheTest.Printf(_L("Execute Statement - BEGIN: %d us\n"), duration);
			}
		
		else if(query == KCommitTransaction)
			{
			++trnCnt;
			TheTest.Printf(_L("Execute Statement - COMMIT: %d us, Trn#%d, \"INSERT\" count: %d, \"UPDATE\" count: %d, \"SELECT\" count: %d\n"), 
					duration, trnCnt, insertTrnCnt, updateTrnCnt, selectTrnCnt);
			insertTrnCnt = updateTrnCnt = selectTrnCnt = 0;
			}

		else
			{	
			TPtrC queryType(query.Ptr(), 6);
			TheTest.Printf(_L("Execute Statement - %S: %d us\n"),&queryType, duration);
			if(queryType.FindF(_L("INSERT")) >= 0)
				{
				++insertCnt;
				++insertTrnCnt;
				}
			else if(queryType.FindF(_L("UPDATE")) >= 0)
				{
				++updateCnt;
				++updateTrnCnt;
				}
			else if(queryType.FindF(_L("SELECT")) >= 0)
				{
				++selectCnt;
				++selectTrnCnt;
				}
			}
		}
	delete sqlBuf;
	
	TheDbC.Close();
	
	TheTest.Printf(_L("Total time to process Songs: %d us\n"), totalTime);
	TheTest.Printf(_L("Transactions count: %d, \"INSERT\" count: %d, \"UPDATE\" count: %d, \"SELECT\" count: %d\n"), 
			               trnCnt, insertCnt, updateCnt, selectCnt);
	TEST2(recordCount, KRecordCount);
	}
Example #22
0
/** Main tests function
*/ 
void CallTestsL()
	{
	TBuf16<45> dir;
	TInt r = 0;
	
	
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
	test.Printf(_L("Disabling Lock Fail simulation ...\n"));
	// turn OFF lock failure mode (if cache is enabled)
	
	TBool simulatelockFailureMode = EFalse;
	r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
	test_Value(r, r == KErrNone  ||  r == KErrNotSupported);
#endif

	// FileNames/File generation
	test.Start(_L("Preparing the environment\n"));
	
	FileNameGen(gSmallFile, 8, gNextFile++);
	FileNameGen(gBigFile, 8, gNextFile++);
	
	dir = gSessionPath;
	dir.Append(gSmallFile);
	
	gSmallFile = dir;
	dir = gSessionPath;
	dir.Append(gBigFile);
	gBigFile = dir;

	TRAPD(res,gBuf = HBufC8::NewL(KBigBlockSize));
	TEST(res == KErrNone && gBuf != NULL);
		
	gBufWritePtr.Set(gBuf->Des());
	FillBuffer(gBufWritePtr, KBigBlockSize, 'B');
	
	TRAPD(res2, gBufSec = HBufC8::NewL(KBlockSize));
	TEST(res2 == KErrNone && gBufSec != NULL);
	gBufReadPtr.Set(gBufSec->Des());
	
	test.Next(_L("Benchmarking\n"));
	TimeTakenToWriteBigFile(0);  
	TimeTakenToWriteBigFileAsync(0);
	
	test.Printf(_L("second try, second timings account for the last comparison\n")); 
	TimeTakenToWriteBigFile(0);  
	TimeTakenToWriteBigFileAsync(0);
	
	TimeTakenToWriteBigBlock();
	
	test.Next(_L("Big file sync written, small file read from the media at the same time\n"));
	TestReadingWhileWriting();
	
	test.Next(_L("Big file written, small file written at the same time\n"));
	TestWritingWhileWriting();
	
  	test.Next(_L("Big file written async, deletion in the meantime\n"));
	TestDeletionWhileWriting();
	
	test.Next(_L("Two big files written at the same time\n"));
	TestTwoBigOnes();	
	
	test.Next(_L("Big file being written, start reading\n"));
	TestReadingWhileWritingSameFile();

	test.Next(_L("Client dying unexpectedly\n"));
	TestClientDies();

  	test.Next(_L("Ensure write order is preserved\n"));
	TestWriteOrder();
	
	// Format the drive to make sure no blocks are left to be erased in LFFS
	if (!Is_Win32(TheFs, gDrive))
		Format(gDrive);	
	
	r = TheFs.MkDirAll(gSessionPath);
	
	TimeTakenToWriteBigFile(1);  
	TimeTakenToWriteBigFileAsync(1);

	// Make sure that the difference between the first time and the last time the files are written doesn't
	// differ more than 3%
	test.Printf(_L("Abs(gTotalTimeSync[0]-gTotalTimeSync[1]) :%d\n"), Abs(gTotalTimeSync[0]-gTotalTimeSync[1]));
	test.Printf(_L("Abs(gTotalTimeAsync[0]-gTotalTimeAsync[1]) :%d\n"), Abs(gTotalTimeAsync[0]-gTotalTimeAsync[1]));
	test.Printf(_L("gTotalTimeSync[0] :%d\n"), gTotalTimeSync[0]);
	test.Printf(_L("gTotalTimeAsync[0] :%d\n"), gTotalTimeAsync[0]);
	
	#if !defined(__WINS__)
		test((Abs(gTotalTimeSync[0]-gTotalTimeSync[1])/gTotalTimeSync[0]) < 0.03);
		test((Abs(gTotalTimeAsync[0]-gTotalTimeAsync[1])/gTotalTimeAsync[0]) < 0.03);	
	#endif
	
	r = DeleteAll(gSessionPath);
	TESTERROR(r);
	
	delete gBuf;
	delete gBufSec;
	
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
	// turn lock failure mode back ON (if cache is enabled)
	simulatelockFailureMode = ETrue;
	r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
    test_Value(r, r == KErrNone  ||  r == KErrNotSupported);
#endif

	test.End();
	}
void CGpsDataHandler::RunL() {
#ifndef __SERIES60_3X__
	TPtr8 pBuffer = iBuffer->Des();

	THostName aHostName;
	TInquirySockAddr aInquiry;
	TInt aServiceClass;

	switch(iEngineStatus) {
		case EGpsResolving:
			if(iStatus == KErrNone) {
				// Next device found
				aHostName = iNameEntry().iName;

				aInquiry = TInquirySockAddr::Cast(iNameEntry().iAddr);
				aServiceClass = aInquiry.MajorServiceClass();
				iBTAddr.SetBTAddr(aInquiry.BTAddr());
				iBTAddr.SetPort(1);

				if(aServiceClass & 0x08 || aHostName.Find(_L("GPS")) != KErrNotFound || aHostName.Find(_L("gps")) != KErrNotFound) {
					// Found Positioning device
					if(iSocket.Open(iSocketServ, KBTAddrFamily, KSockStream, KRFCOMM) == KErrNone) {
						iEngineStatus = EGpsConnecting;
						//iResolver.Close();

						iSocket.Connect(iBTAddr, iStatus);
						SetActive();
					}
					else {
						iSocketServ.Close();
						iEngineStatus = EGpsDisconnected;
						iObserver->GpsError(EGpsConnectionFailed);
					}
				}
				else {
					// Get next
					iResolver.Next(iNameEntry, iStatus);
    				SetActive();
				}

				// TODO - Is correct device?

			}
			else if(iStatus == KErrHostResNoMoreResults) {
				// No (more) devices found
				iSocketServ.Close();
				iEngineStatus = EGpsDisconnected;
				iGpsDeviceResolved = false;
				iObserver->GpsError(EGpsDeviceUnavailable);
			}
			else {
				iSocketServ.Close();
				iEngineStatus = EGpsDisconnected;
				iObserver->GpsError(EGpsDeviceUnavailable);
			}
			break;
		case EGpsConnecting:
			if(iStatus == KErrNone) {
				iEngineStatus = EGpsReading;
				iGpsDeviceResolved = true;
				iResolver.Close();

				pBuffer.Zero();

				iSocket.Recv(iChar, 0, iStatus);
				SetActive();
			}
			else {
				if(iGpsDeviceResolved) {
					iSocket.Close();
					iSocketServ.Close();
					iEngineStatus = EGpsDisconnected;
					iObserver->GpsError(EGpsConnectionFailed);
				}
				else {
					// Get next
					iEngineStatus = EGpsResolving;
					iResolver.Next(iNameEntry, iStatus);
					SetActive();
				}
			}
			break;
		case EGpsReading:
			if(iStatus == KErrNone) {
				iEngineStatus = EGpsConnected;

				if(pBuffer.Length() + iChar.Length() > pBuffer.MaxLength()) {
					iBuffer = iBuffer->ReAlloc(pBuffer.MaxLength()+iChar.Length());
					pBuffer.Set(iBuffer->Des());
				}

				pBuffer.Append(iChar);
				ProcessData();
			}
			else {
				iSocket.Close();
				iSocketServ.Close();
				iEngineStatus = EGpsDisconnected;
				iObserver->GpsError(EGpsConnectionFailed);
			}
			break;
		case EGpsDisconnecting:
			iResolver.Close();
			iSocket.Close();
			iSocketServ.Close();
			iEngineStatus = EGpsDisconnected;
			break;
		default:;
	}
#else
	switch(iEngineStatus) {
		case EGpsReading:
			iEngineStatus = EGpsConnected;
			
			if(iStatus == KErrNone) {
				TPosition aPosition;
				iPositionInfo.GetPosition(aPosition);

				iObserver->GpsData(aPosition.Latitude(), aPosition.Longitude(), aPosition.HorizontalAccuracy());
				
				if( !iGpsWarmedUp ) {
					iGpsWarmedUp = true;
					
					TPositionUpdateOptions aOptions;
					aOptions.SetUpdateTimeOut(30000000);	
					aOptions.SetAcceptPartialUpdates(true);
					iPositioner.SetUpdateOptions(aOptions);
				}
			}
			else {
				iObserver->GpsError(EGpsDeviceUnavailable);
			}
			break;
		case EGpsDisconnecting:
			iPositioner.Close();
			iPositionServ.Close();
			iEngineStatus = EGpsDisconnected;
			break;
		default:;
	}
#endif
}
Example #24
0
EXPORT_C TInt TMTPTypeNull::NextWriteChunk(TPtr8& aChunk)
	{
    aChunk.Set(&iNullBuffer[0], 0, iNullBuffer.MaxLength());
    return KErrNone;
    }
Example #25
0
/**
*   List existing network interfaces, IP addresses bound to them 
*   and fill up array of IP addresses for all interfaces.
*/
void CTestStepLLMNR_Init::ListInterfacesL()
    {
    
    RSocket socket;
    TInt    nRes;
    TInt    exceed;
    TInt    idx;
    TName   tmpBuf;
    TName   tmpBuf1;
    
    nRes = socket.Open(ipTestServer->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp);
    TESTL(nRes == KErrNone);
    
    TUint   bufsize = 2048;
    
    HBufC8 *buffer =NULL;
    buffer = GetBuffer(buffer, bufsize);
    TESTL(buffer != NULL);
    
    TPtr8 bufdes = buffer->Des();
    
    //-- reset array of local addresses
    ipTestServer->iLocalAddrs.Reset();
    
    //-- list all available network interfaces
    INFO_PRINTF1(KNewLine);
    INFO_PRINTF1(_L("--- available network interfaces:"));
    
    do
        {//-- get list of network interfaces
        // if exceed>0, all interface could not fit into the buffer.
        // In that case allocate a bigger buffer and retry.
        // There should be no reason for this while loop to take more than 2 rounds.
        bufdes.Set(buffer->Des());
        exceed = socket.GetOpt(KSoInetInterfaceInfo, KSolInetIfQuery, bufdes);
        if(exceed > 0)
            {
            bufsize += exceed * sizeof(TInetInterfaceInfo);
            buffer = GetBuffer(buffer, bufsize);
            TESTL(buffer != NULL);
            }
        } while (exceed > 0);
        
        if (exceed < 0)
            {
            INFO_PRINTF1(_L("socket.GetOpt() error!"));
            TESTL(EFalse);
            }
        
        TOverlayArray<TInetInterfaceInfo> infoIface(bufdes);
        
        for(idx=0; idx < infoIface.Length(); ++idx)
            {
            TInetInterfaceInfo& iface = infoIface[idx];
            
            tmpBuf.Format(_L("index:%d, name: "),iface.iIndex);
            tmpBuf.Append(iface.iName );
            tmpBuf.AppendFormat(_L(" state:%d"), iface.iState);
            INFO_PRINTF1(tmpBuf);
            }
        
        //-- list all IP addresses, bound to the interfaces
        //-- and append this address to the array of host-local addresses
        INFO_PRINTF1(KNewLine);
        INFO_PRINTF1(_L("--- IP addresses bound to the interfaces:"));
        
        do
            {
            // if exceed>0, all interface could not fit into the buffer.
            // In that case allocate a bigger buffer and retry.
            // There should be no reason for this while loop to take more than 2 rounds.
	        bufdes.Set(buffer->Des());
            exceed = socket.GetOpt(KSoInetAddressInfo, KSolInetIfQuery, bufdes);
            if(exceed > 0)
                {
                bufsize += exceed * sizeof(TInetAddressInfo);
                buffer = GetBuffer(buffer, bufsize);
                }
            } while (exceed > 0);
            
            if (exceed < 0)
                {
                INFO_PRINTF1(_L("socket.GetOpt() error!"));
                TESTL(EFalse);
                }
            
            
            //-- print out IP addresses
            TOverlayArray<TInetAddressInfo> infoAddr(bufdes);
            TInetAddr inetAddr;
            
            for(idx=0; idx < infoAddr.Length(); ++idx)
                {
                TInetAddressInfo& addr = infoAddr[idx];
                
                tmpBuf.Format(_L("iface index: %d, scopeID: %d, state: %d, IP addr: "), addr.iInterface, addr.iScopeId, addr.iState);
                inetAddr.SetAddress(addr.iAddress);
                inetAddr.Output(tmpBuf1);
                tmpBuf.Append(tmpBuf1);
                INFO_PRINTF1(tmpBuf);
                
                //-- if obtained IP address is valid and not loopback, add it to the array.
                if(inetAddr.IsLoopback() || inetAddr.IsUnspecified())
                    {}
                else
                    ipTestServer->iLocalAddrs.Append(inetAddr);
                
                }
            
            
            delete buffer;
            socket.Close();
            
            INFO_PRINTF1(KNewLine);
}
/*!
    \internal
    RunL from CActive.
*/
void CHbDeviceDialogSymbianPrivate::RunL()
{
    TInt completionCode = iStatus.Int();
    int errorCode = SymToDeviceDialogError(completionCode);

    if (completionCode < KErrNone) {
        // Any Symbian error, stop requesting, sycnhoronous requests are stopped
        // in the end of the RunL
        iRequesting = EFalse;
        SetError(errorCode);
        if (CallDialogClosedObserver(errorCode)) {
            return; // observed deleted this object, do not touch it
        }
    }
    else {
        // Check that event is for latest device dialog. iDeviceDialogId was updated by server
        // during show()
        THbDeviceDialogSrvUpdateInfo &updateInfo = iUpdateInfo();
        if (updateInfo.iDeviceDialogId == iDeviceDialogId()) {
            switch(updateInfo.iUpdateType) {
            case EHbDeviceDialogUpdateData: {
                if (completionCode == KErrNone &&
                    updateInfo.iInfo.iDataInfo.iDataSize > 0) {
                    // Resize buffer and get new data synchronously
                    delete iBuffer;
                    iBuffer = NULL;
                    iBuffer = HBufC8::NewL(updateInfo.iInfo.iDataInfo.iDataSize);
                    iDataPtr.Set(iBuffer->Des());
                    completionCode = iHbSession.SendSyncRequest(EHbSrvUpdateData, iDataPtr);
                    errorCode = SymToDeviceDialogError(completionCode);

                    // data request failed
                    if (completionCode < KErrNone) {
                        iRequesting = EFalse;
                        SetError(errorCode);
                        if (CallDialogClosedObserver(errorCode)) {
                            return; // observed deleted this object, do not touch it
                        }
                    }
                }
                if (completionCode == KErrNone) {
                    // Signal data if there are connections. Otherwise keep a copy.
                    QByteArray resArray((const char*)iDataPtr.Ptr(), iDataPtr.Size());
                    QDataStream stream(&resArray, QIODevice::ReadOnly);

                    iDataReceived.clear();

                    QVariant var;
                    stream >> var;
                    QVariantMap varMap = var.toMap();

                    if (iObserver) {
                        CHbSymbianVariantMap* symbianMap =
                            HbSymbianVariantConverter::fromQVariantMapL(varMap);
                        bool thisIsDeleted = CallDataReceivedObserver(*symbianMap);
                        delete symbianMap;
                        symbianMap = 0;
                        if (thisIsDeleted) { // observer deleted this, do not touch anymore
                            return;
                        }
                    }
                    else {
                        iDataReceived = varMap;
                    }
                }
                break;
            }
            case EHbDeviceDialogUpdateClosed:
                // Signal possible cancelled error
                if (completionCode != KErrNone) {
                    SetError(errorCode);
                }
                iRequesting = EFalse;
                if (CallDialogClosedObserver(errorCode)) {
                    return; // observed deleted this object, do not touch it
                }
                break;
            default:
                break;
            }
        }
    }
void CBBSessionImpl::CheckedRunL()
{
	CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("CheckedRunL"));

	if (iStatus.Int() < KErrNone) {
		CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err"));
		if (iStatus.Int()==KClientBufferTooSmall) {
			CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("toosmall"));
			iNotifyBuf->Des().Zero();
			iNotifyBuf=iNotifyBuf->ReAllocL(iNotifyBuf->Des().MaxLength()*2);
			iNotifyBufP.Set(iNotifyBuf->Des());
			iStatus=KRequestPending;
			SetActive();
			iClientSession.WaitForNotify(iFull, iNotifyBufP, iStatus);
			return;
		} else if(iStatus.Int()==KErrServerTerminated) {
			CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("terminated"));
			ReconnectL();
			return;
		} else {
			CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("other"));
			User::Leave(iStatus.Int());
		}
	}
	if (iStatus.Int() == EDeleteNotification) {
		CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("deleted"));
		NotifyDeletedL(iFull.iTupleName, iFull.iSubName);
	} else if (iNotifyBuf->Des().Length()>0) {
		{
			CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("read"));
			RDesReadStream rs(*iNotifyBuf);
			TTypeName tn;
			TInt err;
			MBBData* datap=0;
			CC_TRAP(err, tn=TTypeName::IdFromStreamL(rs));
			if (err!=KErrNone) {
				CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err1"));
				TBBLongString* s=new (ELeave) TBBLongString(KEvent);
				datap=s;
				s->Value().Append(_L("error reading datatype: "));
				s->Value().AppendNum(err);
			}
			if (err==KErrNone) {
				CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("create"));
				CC_TRAP(err, datap=iFactory->CreateBBDataL(tn, KEvent, iFactory));
				if (err!=KErrNone) {
					CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err2"));
					TBBLongString* s=new (ELeave) TBBLongString(KEvent);
					datap=s;
					s->Value().Append(_L("error creating data: "));
					s->Value().AppendNum(err);
					s->Value().Append(_L(", type: "));
					tn.IntoStringL(s->Value());
				}
			}
			refcounted_ptr<CRefCountedData> data(CRefCountedData::NewL(datap));
			if (err==KErrNone) {
				CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("internalize"));
				CC_TRAP(err, data->Get()->InternalizeL(rs));
				if (err!=KErrNone) {
					CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err"));
					TBBLongString* s=new (ELeave) TBBLongString(KEvent);
					data.reset(CRefCountedData::NewL(s));
					s->Value().Append(_L("error internalizing data: "));
					s->Value().AppendNum(err);
					s->Value().Append(_L(", type: "));
					tn.IntoStringL(s->Value());
				}
			}
			{
			TNotifyType nt=EByTuple;
			if (iFull.iTupleType==ETuplePermanentSubscriptionEvent || 
				iFull.iTupleType==ETupleReply) {
					nt=EByComponent;
			}
			{
				CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("notify"));
				NotifyL(iFull.iId, iFull.iTupleName, iFull.iSubName, 
					iFull.iComponentName, data.get(), nt);
			}
			}
		}
	}

	{
		CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("next"));
		iNotifyBuf->Des().Zero();
		iNotifyBufP.Set(iNotifyBuf->Des());
		iStatus=KRequestPending;
		SetActive();
		iClientSession.WaitForNotify(iFull, iNotifyBufP, iStatus);
	}
}
EXPORT_C TInt CMTPTypeObjectPropList::FirstWriteChunk(TPtr8& aChunk)
	{
    aChunk.Set(&(iIOPages[0][iTransportHeaderIndex]), 0, KMTPPropListBufferPageSize - iTransportHeaderIndex);
    return KErrNone;
	}
Example #29
0
TPtr8 & CPjAudioInputEngine::GetFrame() 
{
    //iStreamBuffer_->Des().FillZ(frameLen_);
    iFramePtr_.Set((TUint8*)(iStreamBuffer_->Ptr()), frameLen_, frameLen_);
    return iFramePtr_;
}
EXPORT_C TInt CMTPTypeObjectPropList::NextWriteChunk(TPtr8& aChunk)
	{
	ReserveNewPage();
	aChunk.Set(&(iIOPages[iIOPages.Count()-1][0]), 0, KMTPPropListBufferPageSize);
    return KErrNone;
	}