piprofiler/piprofiler_plat/inc/SamplerPluginInterface.inl
branchRCL_3
changeset 13 da2cedce4920
equal deleted inserted replaced
12:d27dfa8884ad 13:da2cedce4920
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // LITERALS
       
    20 _LIT8(KTrue, "true");
       
    21 _LIT8(KFalse, "false");
       
    22 
       
    23 inline CSamplerPluginInterface::CSamplerPluginInterface()
       
    24     : iOrder( KSamplerPluginNotIndexed )
       
    25     {
       
    26     iBuffer = 0;
       
    27     iStream = 0;
       
    28     }
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CSamplerPluginInterface::~CSamplerPluginInterface()
       
    32 // Destructor.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 inline CSamplerPluginInterface::~CSamplerPluginInterface()
       
    36     {
       
    37     iBuffer = 0;
       
    38     REComSession::DestroyedImplementation(iDtor_ID_Key);
       
    39     }
       
    40 
       
    41 
       
    42 inline CSamplerPluginInterface* CSamplerPluginInterface::NewL(const TUid aImplementationUid, TAny* aInitParams)
       
    43     {
       
    44     // Define options, how the default resolver will find appropriate
       
    45     // implementation.
       
    46     return REINTERPRET_CAST(CSamplerPluginInterface*, 
       
    47                             REComSession::CreateImplementationL(aImplementationUid,
       
    48                                                                 _FOFF( CSamplerPluginInterface, iDtor_ID_Key ),
       
    49                                                                 aInitParams)); 
       
    50     }
       
    51 
       
    52 inline void CSamplerPluginInterface::ListAllImplementationsL(RImplInfoPtrArray& aImplInfoArray)
       
    53     {
       
    54     REComSession::ListImplementationsL(KSamplerPluginInterfaceUid, aImplInfoArray);
       
    55     }
       
    56 
       
    57 inline void CSamplerPluginInterface::SetOrder( TInt aOrder )
       
    58     {
       
    59     iOrder = aOrder;
       
    60     }
       
    61 
       
    62 inline TInt CSamplerPluginInterface::Flush() 
       
    63     {
       
    64 	// complete the header
       
    65 	TUint32 header;
       
    66 	header = (iBuffer->iDataSize & 0x00ffffff) - 4;
       
    67 	header += (iSamplerId << 24);
       
    68 
       
    69 	// flush the header info
       
    70 	iBuffer->iBuffer[0] = header;
       
    71 	iBuffer->iBuffer[1] = header >> 8;
       
    72 	iBuffer->iBuffer[2] = header >> 16;
       
    73 	iBuffer->iBuffer[3] = header >> 24;
       
    74 	
       
    75     // write data to filled buffers
       
    76     iStream->AddToFilledBuffers(iBuffer);
       
    77     // notify selected writer plugin to write data to output
       
    78     iStream->NotifyWriter();
       
    79 
       
    80     iBuffer = 0;
       
    81 
       
    82 	return KErrNone;
       
    83 }
       
    84 
       
    85 
       
    86 inline TInt CSamplerPluginInterface::AddSample(TUint8* aSample, TUint32 aLength, TInt aLimitSize)
       
    87     {
       
    88     LOGTEXT(_L("CSamplerPluginInterface::AddSample - entry"));
       
    89 	if(iBuffer == 0) 
       
    90 	    {
       
    91 	    // get next free buffer where to write data
       
    92 		iBuffer = iStream->GetNextFreeBuffer();
       
    93 		iBuffer->iBufDes->Zero();
       
    94 		
       
    95 		// get space for the header
       
    96 		TUint32 header = 0;
       
    97 		iBuffer->iBufDes->Append((TUint8*)&header, 4);	
       
    98 		iBuffer->iDataSize += 4;
       
    99 	    }
       
   100 		
       
   101 	// add data to the buffer...
       
   102 	// if all data fit to the current buffer
       
   103 	if(iBuffer->iBufferSize - iBuffer->iDataSize >= (TInt)aLength)
       
   104 	    {
       
   105 		iBuffer->iBufDes->Append(aSample, (TInt)aLength);
       
   106 		iBuffer->iDataSize += (TInt)aLength;
       
   107 	    }
       
   108 	else 
       
   109 	    {	
       
   110 		// fill in the buffer
       
   111 		TUint32 rest = iBuffer->iBufferSize - iBuffer->iDataSize;
       
   112 		iBuffer->iBufDes->Append(aSample, rest);
       
   113 		iBuffer->iDataSize += (TInt)rest;
       
   114 		
       
   115 		// The buffer is full now, complete the header
       
   116 		TUint32 header;
       
   117 		header = (iBuffer->iDataSize & 0x00ffffff) - 4;
       
   118 		header += (iSamplerId << 24);
       
   119 		iBuffer->iBuffer[0] = header;
       
   120 		iBuffer->iBuffer[1] = header >> 8;
       
   121 		iBuffer->iBuffer[2] = header >> 16;
       
   122 		iBuffer->iBuffer[3] = header >> 24;
       
   123 		
       
   124 		// write data to filled buffers
       
   125 		iStream->AddToFilledBuffers(iBuffer);
       
   126 	    // notify selected writer plugin to write data to output
       
   127 	    iStream->NotifyWriter();
       
   128 		
       
   129 		// Fetch an empty buffer and reserve space for the header
       
   130 		iBuffer = iStream->GetNextFreeBuffer();
       
   131 		iBuffer->iBufDes->Zero();
       
   132 		header = 0;
       
   133 		iBuffer->iBufDes->Append((TUint8*)&header, 4);	
       
   134 		iBuffer->iDataSize += 4;
       
   135 			
       
   136 		// copy the rest of data to the new buffer
       
   137 		iBuffer->iBufDes->Append(aSample+rest, aLength-rest);
       
   138 		iBuffer->iDataSize += (TInt)aLength-rest;
       
   139 	    }
       
   140 	
       
   141 	// Once iBuffer->dataSize reaches the limitSize, data from iBuffer is flushed to file/debug port.
       
   142 	// If limitSize is set to zero, buffer is not changed until iBuffer gets full.
       
   143 	if(aLimitSize != 0) 
       
   144 	    {
       
   145 		if(iBuffer->iDataSize >= aLimitSize) 
       
   146 		    {
       
   147 			// The buffer is full now, complete the header
       
   148 			TUint32 header;
       
   149 			header = (iBuffer->iDataSize & 0x00ffffff) - 4;
       
   150 			header += (iSamplerId << 24);
       
   151 			iBuffer->iBuffer[0] = header;
       
   152 			iBuffer->iBuffer[1] = header >> 8;
       
   153 			iBuffer->iBuffer[2] = header >> 16;
       
   154 			iBuffer->iBuffer[3] = header >> 24;
       
   155 	
       
   156 
       
   157             // write data to filled buffers
       
   158             iStream->AddToFilledBuffers(iBuffer);
       
   159             // notify selected writer plugin to write data to output
       
   160             iStream->NotifyWriter();
       
   161 		    
       
   162 			// Fetch an empty buffer and reserve space for the header
       
   163 			iBuffer = iStream->GetNextFreeBuffer();
       
   164 			iBuffer->iBufDes->Zero();
       
   165 			header = 0;
       
   166 			iBuffer->iBufDes->Append((TUint8*)&header, 4);	
       
   167 			iBuffer->iDataSize += 4;
       
   168 		    }
       
   169 	    }
       
   170 	return KErrNone;
       
   171     }
       
   172 
       
   173 // ----------------------------------------------------------------------------
       
   174 // Converts given descriptor into TBool value.
       
   175 // ----------------------------------------------------------------------------
       
   176 //
       
   177 inline void CSamplerPluginInterface::Str2Bool(const TDesC8& aBuf, TBool& aValue)
       
   178     {
       
   179     if (aBuf.CompareF(KFalse) == 0)
       
   180         aValue = EFalse;
       
   181     else
       
   182         aValue = ETrue;
       
   183     }
       
   184 
       
   185 // ----------------------------------------------------------------------------
       
   186 // Converts given descriptor into TInt value.
       
   187 // ----------------------------------------------------------------------------
       
   188 //
       
   189 inline void CSamplerPluginInterface::Str2Int(const TDesC8& aBuf, TInt& aValue)
       
   190     {
       
   191     TLex8 conv;
       
   192     conv.Assign(aBuf);
       
   193     
       
   194     if (conv.Val(aValue) != KErrNone)
       
   195         aValue = 0;
       
   196     }
       
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // Converts given descriptor into TInt value.
       
   200 // ----------------------------------------------------------------------------
       
   201 //
       
   202 inline void CSamplerPluginInterface::Str2Int(const TDesC8& aBuf, TUint32& aValue)
       
   203     {
       
   204     TInt temp(0);
       
   205     
       
   206     TLex8 conv;
       
   207     conv.Assign(aBuf);
       
   208     
       
   209     if (conv.Val(temp) != KErrNone)
       
   210         aValue = 0;
       
   211     else
       
   212         aValue = (TUint32)temp;
       
   213     }
       
   214 
       
   215 // End of file