perfsrv/piprofiler/piprofiler_plat/inc/ProfilerGenericClassesUsr.inl
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  
    14 * Description:   
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <f32file.h>
    19 #include <f32file.h>
    54 inline void CProfilerBufferHandler::ConstructL()
    54 inline void CProfilerBufferHandler::ConstructL()
    55 	{
    55 	{
    56 	LOGTEXT(_L("CProfilerBufferHandler::ConstructL - entry"));
    56 	LOGTEXT(_L("CProfilerBufferHandler::ConstructL - entry"));
    57 	iBufferInProcess = 0;
    57 	iBufferInProcess = 0;
    58 	iEndOfStreamDetected = false;
    58 	iEndOfStreamDetected = false;
    59 
    59 	
    60 	iFinished = 0;
    60 	iFinished = 0;
    61 	// add the buffer handler to the active scheduler
    61 	// add the buffer handler to the active scheduler
    62 	CActiveScheduler::Add(this);
    62 	CActiveScheduler::Add(this);
    63 	}
    63 	}
    64 
    64 
    91     return aError;
    91     return aError;
    92     }
    92     }
    93 
    93 
    94 inline void CProfilerBufferHandler::HandleEndOfStream()
    94 inline void CProfilerBufferHandler::HandleEndOfStream()
    95     {
    95     {
    96     LOGTEXT(_L("CProfilerBufferHandler::RunError - entry"));
    96     LOGTEXT(_L("CProfilerBufferHandler::HandleEndOfStream - entry"));
    97     // Cancel has been called, the stream should be about to end now,
    97     // Cancel has been called, the stream should be about to end now,
    98     // we will wait for the rest of the buffers to be filled synchronously
    98     // we will wait for the rest of the buffers to be filled synchronously
    99     // the end of the stream will be indicated through an empty buffer
    99     // the end of the stream will be indicated through an empty buffer
   100     // at first, complete the ongoing request
   100     // at first, complete the ongoing request
   101     if(iStatus == KRequestPending && iBufferInProcess != 0)
   101     if(iStatus == KRequestPending && iBufferInProcess != 0)
   102         {
   102         {
   103         LOGTEXT(_L("CProfilerBufferHandler::DoCancel - case 1"));
   103         LOGTEXT(_L("CProfilerBufferHandler::HandleEndOfStream - case 1"));
   104 
   104 
   105         // wait for the buffer to be filled synchronously
   105         // wait for the buffer to be filled synchronously
   106         User::WaitForRequest(iStatus);
   106         User::WaitForRequest(iStatus);
   107         
   107         
   108         // add the received buffer to the list of filled buffers
   108         // add the received buffer to the list of filled buffers
   120         // there will be no more asynchronous requests
   120         // there will be no more asynchronous requests
   121         iBufferInProcess = 0;
   121         iBufferInProcess = 0;
   122         }
   122         }
   123     else if (iBufferInProcess != 0)
   123     else if (iBufferInProcess != 0)
   124         {
   124         {
   125         LOGTEXT(_L("CProfilerBufferHandler::DoCancel - case 2"));
   125         LOGTEXT(_L("CProfilerBufferHandler::HandleEndOfStream - case 2"));
   126 
   126 
   127         // add the buffer into filled, i.e. ready-to-write buffers
   127         // add the buffer into filled, i.e. ready-to-write buffers
   128         iObserver.AddToFilledBuffers(iBufferInProcess);
   128         iObserver.AddToFilledBuffers(iBufferInProcess);
   129         iObserver.NotifyWriter();
   129         iObserver.NotifyWriter();
   130         
   130         
   131         if(iBufferInProcess->iDataSize == 0)
   131         if(iBufferInProcess->iDataSize == 0)
   132             {
   132             {
   133             // a buffer with size 0 was received
   133             // a buffer with size 0 was received
   134             LOGTEXT(_L("CProfilerBufferHandler::DoCancel - case 2.1"));
   134             LOGTEXT(_L("CProfilerBufferHandler::HandleEndOfStream - case 2.1"));
   135             iEndOfStreamDetected = true;
   135             iEndOfStreamDetected = true;
   136             }       
   136             }       
   137         // there will be no more asynchronous requests
   137         // there will be no more asynchronous requests
   138         iBufferInProcess = 0;   
   138         iBufferInProcess = 0;
   139         }
   139         //delete iBufferInProcess;
   140 
   140         //iBufferInProcess = NULL;    
       
   141         //iObserver.AddToFreeBuffers(iBufferInProcess);
       
   142         }
   141     // then, continue until end of stream has been reached
   143     // then, continue until end of stream has been reached
   142     while(iEndOfStreamDetected == false)
   144     while(iEndOfStreamDetected == false)
   143         {
   145         {
   144         // the end of stream has not yet been detected, so get more
   146         // the end of stream has not yet been detected, so get more
   145         // buffers from the sampler, until we get an empty one
   147         // buffers from the sampler, until we get an empty one
   146 
   148 
   147         if(iStatus == KRequestPending)
   149         if(iStatus == KRequestPending)
   148             {
   150             {
   149             LOGTEXT(_L("CProfilerBufferHandler::DoCancel - ERROR 1"));
   151             LOGTEXT(_L("CProfilerBufferHandler::HandleEndOfStream - ERROR 1"));
   150             }
   152             }
   151 
   153 
   152         LOGTEXT(_L("CProfilerBufferHandler::DoCancel - case 3"));
   154         LOGTEXT(_L("CProfilerBufferHandler::HandleEndOfStream - case 3"));
   153 
   155 
   154         TBapBuf* nextFree = iObserver.GetNextFreeBuffer();  
   156         TBapBuf* nextFree = iObserver.GetNextFreeBuffer();  
   155         iSampler.FillThisStreamBuffer(nextFree,iStatus);
   157         iSampler.FillThisStreamBuffer(nextFree,iStatus);
   156         // wait for the buffer to be filled synchronously
   158         // wait for the buffer to be filled synchronously
   157         User::WaitForRequest(iStatus);
   159         User::WaitForRequest(iStatus);
   161         iObserver.NotifyWriter();
   163         iObserver.NotifyWriter();
   162         
   164         
   163         // check if end-of-data message (i.e. data size is 0 sized) received
   165         // check if end-of-data message (i.e. data size is 0 sized) received
   164         if(nextFree->iDataSize == 0)
   166         if(nextFree->iDataSize == 0)
   165             {
   167             {
   166             LOGTEXT(_L("CProfilerBufferHandler::DoCancel - case 3.1"));
   168             LOGTEXT(_L("CProfilerBufferHandler::HandleEndOfStream - case 3.1"));
   167             // a buffer with size 0 was received
   169             // a buffer with size 0 was received
   168             iEndOfStreamDetected = true;
   170             iEndOfStreamDetected = true;
   169             nextFree = 0;
   171             nextFree = 0;
   170             }
   172             }
   171         }   
   173         }
   172     }
   174     }
   173 
   175 
   174 inline void CProfilerBufferHandler::RunL()
   176 inline void CProfilerBufferHandler::RunL()
   175 	{
   177 	{
   176 	LOGTEXT(_L("CProfilerBufferHandler::RunL - entry"));
   178 	LOGTEXT(_L("CProfilerBufferHandler::RunL - entry"));
   177 
       
   178 	// is called by the active scheduler
   179 	// is called by the active scheduler
   179 	// when a buffer has been received
   180 	// when a buffer has been received
   180 
   181 
   181 	// buffer with dataSize 0 is returned when the sampling ends
   182 	// buffer with dataSize 0 is returned when the sampling ends
   182 	if(iBufferInProcess->iDataSize != 0)
   183 	if(iBufferInProcess->iDataSize != 0)
   183 	    {
   184 	    {
   184 	    LOGTEXT(_L("CProfilerBufferHandler::RunL - buffer received"));
   185 	    LOGTEXT(_L("CProfilerBufferHandler::RunL - buffer received"));
   185 
   186 
   186 		TBapBuf* nextFree = iObserver.GetNextFreeBuffer();
   187 		TBapBuf* nextFree = iObserver.GetNextFreeBuffer();
   187 		
   188 		if(nextFree == 0)
   188 		LOGSTRING5("CProfilerBufferHandler::RunL - 0x%x -> b:0x%x s:%d d:%d",
   189 		    {
       
   190 		    LOGTEXT(_L("CProfilerSampleStream::RunL - GetNextFreeBuffer failed!!"));
       
   191 		    }
       
   192 		else{
       
   193 		    LOGSTRING5("CProfilerBufferHandler::RunL - 0x%x -> b:0x%x s:%d d:%d",
   189 					nextFree,
   194 					nextFree,
   190 					nextFree->iBuffer,
   195 					nextFree->iBuffer,
   191 					nextFree->iBufferSize,
   196 					nextFree->iBufferSize,
   192 					nextFree->iDataSize);
   197 					nextFree->iDataSize);
   193 
   198 
   194 		iSampler.FillThisStreamBuffer(nextFree,iStatus);
   199             iSampler.FillThisStreamBuffer(nextFree,iStatus);
   195 
   200             SetActive();        
   196 		LOGTEXT(_L("CProfilerBufferHandler::RunL - issued new sample command"));
   201     
   197 
   202             LOGTEXT(_L("CProfilerBufferHandler::RunL - issued new sample command"));
   198 		// add the received buffer to the list of filled buffers
   203     
   199 		iObserver.AddToFilledBuffers(iBufferInProcess);
   204             // add the received buffer to the list of filled buffers
   200 		iObserver.NotifyWriter();
   205             iObserver.AddToFilledBuffers(iBufferInProcess);
   201 
   206             iObserver.NotifyWriter();
   202         // the empty buffer is now the one being processed
   207     
   203         iBufferInProcess = nextFree;
   208             // the empty buffer is now the one being processed
   204         
   209             iBufferInProcess = nextFree;
   205         LOGTEXT(_L("CProfilerBufferHandler::RunL - SetActive"));
   210             }
   206         SetActive();        
   211 //        LOGTEXT(_L("CProfilerBufferHandler::RunL - SetActive"));
       
   212 //        SetActive();        
   207 		}
   213 		}
   208 	else
   214 	else
   209 		{
   215 		{
   210 		LOGTEXT(_L("CProfilerBufferHandler::RunL - end of stream detected"));
   216 		LOGTEXT(_L("CProfilerBufferHandler::RunL - end of stream detected"));
   211 		iEndOfStreamDetected = true;
   217 		iEndOfStreamDetected = true;
   250 inline CProfilerSampleStream::CProfilerSampleStream(TInt aBufSize) : 
   256 inline CProfilerSampleStream::CProfilerSampleStream(TInt aBufSize) : 
   251     iBufferSize(aBufSize)
   257     iBufferSize(aBufSize)
   252 	{
   258 	{
   253 	LOGTEXT(_L("CProfilerSampleStream::CProfilerSampleStream - entry"));
   259 	LOGTEXT(_L("CProfilerSampleStream::CProfilerSampleStream - entry"));
   254 	
   260 	
   255 	iFilledBuffers = 0;
   261     iFilledBuffers = 0;
   256     iFreeBuffers = 0;
   262     iFreeBuffers = 0;
   257     iFinished = 0;
   263     iFinished = 0;
   258     
   264     
   259 	LOGTEXT(_L("CProfilerSampleStream::CProfilerSampleStream - exit"));	
   265 	LOGTEXT(_L("CProfilerSampleStream::CProfilerSampleStream - exit"));	
   260 	}
   266 	}
   263 	{
   269 	{
   264 	LOGTEXT(_L("CProfilerSampleStream::~CProfilerSampleStream - entry"));
   270 	LOGTEXT(_L("CProfilerSampleStream::~CProfilerSampleStream - entry"));
   265 
   271 
   266 	// empty all buffers
   272 	// empty all buffers
   267 	EmptyBuffers();
   273 	EmptyBuffers();
       
   274 	User::Free(iFilledBuffers);
       
   275     	User::Free(iFreeBuffers);
       
   276 	//delete iFilledBuffers;
       
   277 	//delete iFreeBuffers;
   268 	    
   278 	    
   269 	LOGTEXT(_L("CProfilerSampleStream::~CProfilerSampleStream - exit"));
   279 	LOGTEXT(_L("CProfilerSampleStream::~CProfilerSampleStream - exit"));
   270 	}
   280 	}
   271 
   281 
   272 inline void CProfilerSampleStream::ConstructL()
   282 inline void CProfilerSampleStream::ConstructL()
   306     // list of free buffers
   316     // list of free buffers
   307     for(TInt i(0);i<KInitialFreeBufferAmount;i++)
   317     for(TInt i(0);i<KInitialFreeBufferAmount;i++)
   308         {
   318         {
   309         // alloc new buffer
   319         // alloc new buffer
   310         TBapBuf* newBuf = (TBapBuf*)User::Alloc(sizeof(TBapBuf));
   320         TBapBuf* newBuf = (TBapBuf*)User::Alloc(sizeof(TBapBuf));
   311         newBuf->iBuffer = (TUint8*)User::Alloc(iBufferSize);
   321         if(newBuf != 0)
   312 
   322             {
   313         // initialize the new buffer
   323             newBuf->iBuffer = (TUint8*)User::Alloc(iBufferSize);
   314         newBuf->iBufferSize = iBufferSize;
   324             if(newBuf->iBuffer != 0)
   315         newBuf->iDataSize = 0;
   325                 {
   316         newBuf->iNext = 0;
   326                 // initialize the new buffer
   317         newBuf->iDes = new TPtr8((TUint8*)newBuf,sizeof(TBapBuf));
   327                 newBuf->iBufferSize = iBufferSize;
   318         newBuf->iDes->SetLength(sizeof(TBapBuf));
   328                 newBuf->iDataSize = 0;
   319         newBuf->iBufDes = new TPtr8((TUint8*)newBuf->iBuffer,iBufferSize);
   329                 newBuf->iNext = 0;
   320         newBuf->iBufDes->SetLength(iBufferSize);
   330                 newBuf->iDes = new TPtr8((TUint8*)newBuf,sizeof(TBapBuf));
   321         AddToFreeBuffers(newBuf);
   331                 newBuf->iDes->SetLength(sizeof(TBapBuf));
       
   332                 newBuf->iBufDes = new TPtr8((TUint8*)newBuf->iBuffer,iBufferSize);
       
   333                 newBuf->iBufDes->SetLength(iBufferSize);
       
   334                 LOGSTRING3("CProfilerSampleStream::InitialiseBuffers - newBuf 0x%x newBuf->iNext 0x%x",newBuf, newBuf->iNext);
       
   335                 AddToFreeBuffers(newBuf);
       
   336                 }
       
   337             else
       
   338                 {
       
   339                 delete newBuf->iBuffer;
       
   340                 delete newBuf;
       
   341                 LOGTEXT(_L("CProfilerSampleStream::InitialiseBuffers - Out of memory (1)!!"));
       
   342                 }
       
   343             }
       
   344         else
       
   345             {
       
   346             LOGTEXT(_L("CProfilerSampleStream::InitialiseBuffers - Out of memory (2)!!"));
       
   347             delete newBuf;
       
   348             }       
   322         }
   349         }
   323     }
   350     }
   324 
   351 
   325 inline void CProfilerSampleStream::EmptyBuffers()
   352 inline void CProfilerSampleStream::EmptyBuffers()
   326     {
   353     {
   335 		TBapBuf* nextFree = iFreeBuffers->iNext;
   362 		TBapBuf* nextFree = iFreeBuffers->iNext;
   336 		// delete the first one in the list
   363 		// delete the first one in the list
   337 		delete iFreeBuffers->iBufDes;
   364 		delete iFreeBuffers->iBufDes;
   338 		delete iFreeBuffers->iDes;
   365 		delete iFreeBuffers->iDes;
   339 		delete iFreeBuffers->iBuffer;
   366 		delete iFreeBuffers->iBuffer;
   340 		delete iFreeBuffers;
   367 		//delete iFreeBuffers;
       
   368 		User::Free(iFreeBuffers);
   341 		// set the list start to the next buffer
   369 		// set the list start to the next buffer
   342 		iFreeBuffers = nextFree;
   370 		iFreeBuffers = nextFree;
   343 	    }
   371 	    }
   344 	iFreeBuffers = 0;
   372 	iFreeBuffers = 0;
       
   373 	// delete all filled buffers
       
   374 	    while(iFilledBuffers != 0)
       
   375 	        {
       
   376 	        LOGSTRING2("CProfilerSampleStream::EmptyBuffers - deleting 0x%x",iFilledBuffers);
       
   377 
       
   378 	        // store the next buffer in the list
       
   379 	        TBapBuf* nextFilled = iFilledBuffers->iNext;
       
   380 	        // delete the first one in the list
       
   381 	        delete iFilledBuffers->iBufDes;
       
   382 	        delete iFilledBuffers->iDes;
       
   383 	        delete iFilledBuffers->iBuffer;
       
   384 	        delete iFilledBuffers;
       
   385 	        User::Free(iFilledBuffers);
       
   386 	        // set the list start to the next buffer
       
   387 	        iFilledBuffers = nextFilled;
       
   388 	        }
       
   389 	    iFilledBuffers = 0;
   345 	LOGTEXT(_L("CProfilerSampleStream::EmptyBuffers - exit"));
   390 	LOGTEXT(_L("CProfilerSampleStream::EmptyBuffers - exit"));
   346     }
   391     }
   347 
   392 
   348 inline TBapBuf* CProfilerSampleStream::GetNextFreeBuffer()
   393 inline TBapBuf* CProfilerSampleStream::GetNextFreeBuffer()
   349     {
   394 	{
   350     LOGTEXT(_L("CProfilerSampleStream::GetNextFreeBuffer - entry"));
   395 	LOGTEXT(_L("CProfilerSampleStream::GetNextFreeBuffer - entry"));
   351 
   396 
   352 	// get a new buffer from the free buffers list
   397 	// get a new buffer from the free buffers list
   353 	TBapBuf* nextFree = iFreeBuffers;
   398 	TBapBuf* nextFree = iFreeBuffers;
   354 	
   399 	
   355 	// check if we got a buffer or not
   400 	// check if we got a buffer or not
   373 				newBuf->iBufDes->SetLength(iBufferSize);
   418 				newBuf->iBufDes->SetLength(iBufferSize);
   374 				nextFree = newBuf;
   419 				nextFree = newBuf;
   375 			    }
   420 			    }
   376 			else
   421 			else
   377 			    {
   422 			    {
       
   423 			    delete newBuf->iBufDes;
       
   424 			    delete newBuf->iDes;
       
   425 			    delete newBuf->iBuffer;
       
   426 			    delete newBuf;
       
   427 			    delete nextFree;
   378 				LOGTEXT(_L("CProfilerSampleStream::GetNextFreeBuffer - Out of memory (1)!!"));
   428 				LOGTEXT(_L("CProfilerSampleStream::GetNextFreeBuffer - Out of memory (1)!!"));
   379 				return 0;
   429 				return 0;
   380 			    }
   430 			    }
   381 		    }
   431 		    }
   382 		else
   432 		else
   383 		    {
   433 		    {
   384 			LOGTEXT(_L("CProfilerSampleStream::GetNextFreeBuffer - Out of memory (2)!!"));
   434 			LOGTEXT(_L("CProfilerSampleStream::GetNextFreeBuffer - Out of memory (2)!!"));
   385 			delete newBuf;
   435 			delete newBuf;
       
   436 			delete nextFree;
   386 			return 0;
   437 			return 0;
   387 		    }		
   438 		    }		
   388 	    }
   439 	    }// nextFree != 0
   389 	else
   440 	else
   390 	    {
   441 	    {
   391 		// set the list to point to next free buffer
   442 		// set the list to point to next free buffer
       
   443 	    LOGSTRING3("CProfilerSampleStream::GetNextFreeBuffer 0x%x buf 0x%x inext", nextFree, nextFree->iNext);
   392 		iFreeBuffers = nextFree->iNext;
   444 		iFreeBuffers = nextFree->iNext;
   393 	    }
   445 	    }
   394 
   446 
   395 	LOGTEXT(_L("CProfilerSampleStream::GetNextFreeBuffer - exit"));
   447 	LOGTEXT(_L("CProfilerSampleStream::GetNextFreeBuffer - exit"));
   396 	return nextFree;
   448 	return nextFree;
   397     }
   449     }
   398 
   450 
   399 inline void CProfilerSampleStream::AddToFilledBuffers(TBapBuf* aFilledBuffer)
   451 inline void CProfilerSampleStream::AddToFilledBuffers(TBapBuf* aFilledBuffer)
   400     {
   452     {
   401     LOGSTRING2("CProfilerSampleStream::AddToFilledBuffers - entry, size %d", aFilledBuffer->iDataSize);
   453     LOGSTRING4("CProfilerSampleStream::AddToFilledBuffers - entry, size %d aFilledBuffer* 0x%x iNext 0x%x", aFilledBuffer->iDataSize, aFilledBuffer, aFilledBuffer->iNext);
   402 
   454     //LOGSTRING3("CProfilerSampleStream::AddToFilledBuffers  iFilledBuffers* 0x%x iNext 0x%x",iFilledBuffers, iFilledBuffers->iNext);
   403     // add this buffer to the list of filled buffers
   455     // add this buffer to the list of filled buffers
   404     if(iFilledBuffers == 0)
   456     if(iFilledBuffers == 0)
   405         {
   457         {
       
   458         LOGSTRING("CProfilerSampleStream::AddToFilledBuffers iFilledBuffers == 0");
   406         // the list is empty, so add the the beginning of the list
   459         // the list is empty, so add the the beginning of the list
   407         // there is no next buffer in the list at the moment
   460         // there is no next buffer in the list at the moment
   408         aFilledBuffer->iNext = 0;
   461         aFilledBuffer->iNext = 0;
   409         iFilledBuffers = aFilledBuffer;
   462         iFilledBuffers = aFilledBuffer;
   410         }
   463         }
   411     else
   464     else
   412         {
   465         {
       
   466         LOGSTRING("CProfilerSampleStream::AddToFilledBuffers iFilledBuffers != 0");
   413         // there are buffers in the list, add this buffer to the beginning of the list
   467         // there are buffers in the list, add this buffer to the beginning of the list
   414         aFilledBuffer->iNext = iFilledBuffers;
   468         if(aFilledBuffer == iFilledBuffers)
   415         iFilledBuffers = aFilledBuffer;
   469             {
   416         }
   470             LOGSTRING("CProfilerSampleStream::AddToFilledBuffers iFilledBuffers same");
   417     LOGTEXT(_L("CProfilerSampleStream::AddToFilledBuffers - exit"));
   471             }
       
   472         else
       
   473             {
       
   474             LOGSTRING("CProfilerSampleStream::AddToFilledBuffers iFilledBuffers different");
       
   475             LOGSTRING3("iFilledBuffers 0x%x iFilledBuffers->iNext 0x%x", iFilledBuffers, iFilledBuffers->iNext);
       
   476             if(iFilledBuffers->iNext != 0)
       
   477                 {
       
   478                 LOGSTRING3("next buf 0x%x ->iNext 0x%x", iFilledBuffers->iNext,iFilledBuffers->iNext->iNext );
       
   479                 }
       
   480             }
       
   481             aFilledBuffer->iNext = iFilledBuffers;
       
   482             iFilledBuffers = aFilledBuffer;
       
   483         }
       
   484     LOGSTRING3("CProfilerSampleStream::AddToFilledBuffers - exit, iFilledBuffer* 0x%x ->iNext 0x%x", iFilledBuffers, iFilledBuffers->iNext);
       
   485     //LOGTEXT(_L("CProfilerSampleStream::AddToFilledBuffers - exit "));
   418     }
   486     }
   419 
   487 
   420 TBapBuf* CProfilerSampleStream::GetNextFilledBuffer()
   488 TBapBuf* CProfilerSampleStream::GetNextFilledBuffer()
   421     {
   489     {
   422     LOGTEXT(_L("CProfilerSampleStream::GetNextFilledBuffer - entry"));
   490     LOGTEXT(_L("CProfilerSampleStream::GetNextFilledBuffer - entry"));
   423 
       
   424     if(iFilledBuffers == 0)
   491     if(iFilledBuffers == 0)
   425         {
   492         {
   426         // there are no filled buffers in the list
   493         // there are no filled buffers in the list
   427         LOGTEXT(_L("CProfilerSampleStream::GetNextFilledBuffer - no filled bufs"));
   494         LOGTEXT(_L("CProfilerSampleStream::GetNextFilledBuffer - no filled bufs"));
   428         return 0;
   495         return 0;
   430     else
   497     else
   431         {   
   498         {   
   432         // get a buffer from the end of the list
   499         // get a buffer from the end of the list
   433         TBapBuf* buf = iFilledBuffers;
   500         TBapBuf* buf = iFilledBuffers;
   434         TBapBuf* prev = 0;
   501         TBapBuf* prev = 0;
   435 
   502         if(buf)
   436         if(buf->iNext == 0)
   503             {
   437             {
   504             LOGSTRING3("CProfilerSampleStream::GetNextFilledBuffer buf 0x%x, inext 0x%x", buf, buf->iNext);
   438             // this was the last (and only) buffer
   505             if(buf->iNext == 0)
   439             iFilledBuffers = 0;
       
   440             LOGTEXT(_L("CProfilerSampleStream::GetNextFilledBuffer - last filled"));
       
   441             return buf;
       
   442             }
       
   443         else
       
   444             {
       
   445             LOGTEXT(_L("CProfilerSampleStream::GetNextFilledBuffer - searching last filled"));
       
   446             while(buf->iNext != 0)
       
   447                 {
   506                 {
   448                 // there are two or more buffers in the list
   507                 // this was the last (and only) buffer
   449                 // proceed until the end of the list is found
   508                 iFilledBuffers = 0;
   450                 prev = buf;
   509                 LOGTEXT(_L("CProfilerSampleStream::GetNextFilledBuffer - last filled"));
   451                 buf = buf->iNext;
   510                 return buf;
   452                 }
   511                 }
   453             // now buf->next is 0, return buf and set the next
   512             else
   454             // element of prev to NULL
   513                 {
   455             prev->iNext = 0;
   514                 LOGSTRING2("CProfilerSampleStream::GetNextFilledBuffer - searching last filled, inext 0x%x ", buf->iNext);
   456             LOGTEXT(_L("CProfilerSampleStream::GetNextFilledBuffer - found last"));
   515                 while(buf->iNext != 0)
   457             return buf;
   516                     {
   458             }
   517                     // there are two or more buffers in the list
       
   518                     // proceed until the end of the list is found
       
   519                     LOGSTRING3("CProfilerSampleStream::GetNextFilledBuffer - searching. buf 0x%x, inext 0x%x", buf, buf->iNext);
       
   520                     prev = buf;
       
   521                     buf = buf->iNext;
       
   522                     }
       
   523                 // now buf->next is 0, return buf and set the next
       
   524                 // element of prev to NULL
       
   525                 prev->iNext = 0;
       
   526                 LOGSTRING3("CProfilerSampleStream::GetNextFilledBuffer - found last. buf 0x%x, iNext 0x%x", buf, buf->iNext);
       
   527                 return buf;
       
   528                 }
       
   529             }
       
   530         else{
       
   531             LOGTEXT(_L("CProfilerSampleStream::GetNextFilledBuffer - nullihan se siellä"));
       
   532             }   
   459         }
   533         }
   460     }
   534     }
   461 
   535 
   462 inline void CProfilerSampleStream::AddToFreeBuffers(TBapBuf* aFreeBuffer)
   536 inline void CProfilerSampleStream::AddToFreeBuffers(TBapBuf* aFreeBuffer)
   463     {
   537     {
   479 	    }
   553 	    }
   480 
   554 
   481 	// set this buffer to be the first one in the list
   555 	// set this buffer to be the first one in the list
   482 	iFreeBuffers = aFreeBuffer;
   556 	iFreeBuffers = aFreeBuffer;
   483 
   557 
   484 	LOGTEXT(_L("CProfilerSampleStream::AddToFreeBuffers - exit"));
   558 	LOGSTRING3("CProfilerSampleStream::AddToFreeBuffers - exit iFreeBuffers 0x%x iFreeBuffers->iNext 0x%x",iFreeBuffers, iFreeBuffers->iNext);
   485     }
   559     }
   486 
   560 
   487 void CProfilerSampleStream::NotifyWriter()
   561 void CProfilerSampleStream::NotifyWriter()
   488     {
   562     {
   489     // notify writer plugin to write data from filled buffer list
   563     // notify writer plugin to write data from filled buffer list