profilesservices/RingingTone3DPlugin/src/C3DAudioXMLParser.cpp
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     1 /*
       
     2 * Copyright (c) 2005 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:  XML-Parser used to parse motion patterns.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "C3DAudioXMLParser.h"
       
    21 #include "tdaudioconstants.h"	// K3DAudioRepositoryUid
       
    22 #include <f32file.h>			// RFs
       
    23 #include <s32mem.h>				// RBufWriteStream
       
    24 #include <centralrepository.h>	// CRepository
       
    25 
       
    26 
       
    27 #include "RingingTone3DPluginDebug.h"
       
    28 #include <ProfileInternal.hrh> // for TProfile3DToneEffect and TProfile3DToneEcho
       
    29 
       
    30 #include <pathinfo.h>
       
    31 #include <driveinfo.h>
       
    32 #include <data_caging_path_literals.hrh>
       
    33 
       
    34 
       
    35 //CONSTANTS
       
    36 const TInt32 KRingingTone3DAudioEComPluginUID = 0x10208ADF;
       
    37 
       
    38 
       
    39 // 3DTone pattern dir
       
    40 _LIT( K3DTonesDir, "3DTones" );
       
    41 
       
    42 // 3DTone pattern files
       
    43 _LIT( KPatternCircle,     "1circular.xml" );
       
    44 _LIT( KPatternFlyBy,      "2flyby.xml" );
       
    45 _LIT( KPatternZigZag,     "3zigzag.xml" );
       
    46 _LIT( KPatternRandomWalk, "4meander.xml" );
       
    47 _LIT( KPatternChaos,      "5random.xml" );
       
    48 
       
    49 
       
    50 // Elements
       
    51 _LIT8( KInitElement, "initialization");
       
    52 _LIT8( KPositionElement, "position" );
       
    53 _LIT8( KUpdateElement, "update" );
       
    54 _LIT8( KVelocityElement, "velocity" );
       
    55 _LIT8( KLoopElement, "loop" );
       
    56 
       
    57 // Attribute names.
       
    58 _LIT8( KPatternName, "name" );
       
    59 _LIT8( KPatternReverb, "reverb" );
       
    60 _LIT8( KPatternDoppler, "doppler" );
       
    61 _LIT8( KXCoordinate, "x" );
       
    62 _LIT8( KYCoordinate, "y" );
       
    63 _LIT8( KZCoordinate, "z" );
       
    64 _LIT8( KDTime, "dTime" );
       
    65 _LIT8( KScalarVelocity, "scalar" );
       
    66 _LIT8( KLoopCount, "count" );
       
    67 
       
    68 // Attribute values
       
    69 _LIT8( KReverbPresetOne, "Livingroom" );
       
    70 _LIT8( KReverbPresetTwo, "Cave" );
       
    71 _LIT8( KReverbPresetThree, "Stone Corridor" );
       
    72 _LIT8( KReverbPresetFour, "Forest" );
       
    73 _LIT8( KReverbPresetFive, "Sewerpipe" );
       
    74 _LIT8( KReverbPresetSix, "Underwater" );
       
    75 _LIT8( KBooleanTrue, "true" );
       
    76 
       
    77 
       
    78 
       
    79 /******************************************************************************
       
    80  * class C3DAudioXMLParser
       
    81  ******************************************************************************/
       
    82 
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // C3DAudioXMLParser::NewL
       
    87 // Two-phased constructor.
       
    88 // -----------------------------------------------------------------------------
       
    89 //		
       
    90 C3DAudioXMLParser* C3DAudioXMLParser::NewL()
       
    91 	{
       
    92 	C3DAudioXMLParser* self = C3DAudioXMLParser::NewLC();
       
    93     CleanupStack::Pop( self );
       
    94     return self;
       
    95 	}
       
    96 
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // C3DAudioXMLParser::NewLC
       
   100 // Two-phased constructor. Leaves pointer on cleanup stack.
       
   101 // -----------------------------------------------------------------------------
       
   102 //		
       
   103 C3DAudioXMLParser* C3DAudioXMLParser::NewLC()
       
   104 	{
       
   105 	C3DAudioXMLParser * self = new ( ELeave ) C3DAudioXMLParser();
       
   106     CleanupStack::PushL( self );
       
   107     self->ConstructL();
       
   108     return self;	
       
   109 	}
       
   110 
       
   111 
       
   112 // Destructor
       
   113 C3DAudioXMLParser::~C3DAudioXMLParser()
       
   114 	{
       
   115 	delete iParser;
       
   116 	delete iParsedPattern;
       
   117    	iFsSession.Close();
       
   118 	}
       
   119 
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // C3DAudioXMLParser::C3DAudioXMLParser
       
   123 // C++ default constructor can NOT contain any code, that
       
   124 // might leave.
       
   125 // -----------------------------------------------------------------------------
       
   126 //		
       
   127 C3DAudioXMLParser::C3DAudioXMLParser():
       
   128 	iParser( NULL ),
       
   129 	iParsedPattern( NULL )
       
   130 	{
       
   131 	}
       
   132 
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // C3DAudioXMLParser::ConstructL
       
   136 // Symbian 2nd phase constructor can leave.
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void C3DAudioXMLParser::ConstructL()
       
   140     {
       
   141     _LIT8( KParserMimeType, "text/xml" );
       
   142     
       
   143 	iPatternId = KErrNotFound;
       
   144 	
       
   145 	iParser = Xml::CParser::NewL( KParserMimeType, *this );
       
   146 	
       
   147 	User::LeaveIfError( iFsSession.Connect() );
       
   148     }	
       
   149     
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // C3DAudioXMLParser::Count
       
   153 //
       
   154 // -----------------------------------------------------------------------------
       
   155 //		
       
   156 TInt C3DAudioXMLParser::CountL()
       
   157     {
       
   158     User::LeaveIfNull( iParsedPattern );
       
   159     const RArray<T3DScriptUpdate>& script = iParsedPattern->Script();
       
   160     
       
   161     return script.Count();
       
   162     }
       
   163 
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // C3DAudioXMLParser::PositionL
       
   167 //
       
   168 // -----------------------------------------------------------------------------
       
   169 //		
       
   170 const T3DPosition& C3DAudioXMLParser::PositionL( TInt aIndex )
       
   171     {
       
   172     User::LeaveIfNull( iParsedPattern );
       
   173     const RArray<T3DScriptUpdate>& script = iParsedPattern->Script();
       
   174     
       
   175     if ( aIndex < 0 || aIndex >= script.Count() )
       
   176         {
       
   177         User::Leave( KErrArgument );
       
   178         }
       
   179         
       
   180     return script[ aIndex ].iPosition;
       
   181     }
       
   182 
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // C3DAudioXMLParser::VelocityL
       
   186 //
       
   187 // -----------------------------------------------------------------------------
       
   188 //		
       
   189 const T3DVelocity& C3DAudioXMLParser::VelocityL( TInt aIndex )
       
   190     {
       
   191     User::LeaveIfNull( iParsedPattern );
       
   192     const RArray<T3DScriptUpdate>& script = iParsedPattern->Script();
       
   193     
       
   194     if ( aIndex < 0 || aIndex >= script.Count() )
       
   195         {
       
   196         User::Leave( KErrArgument );
       
   197         }
       
   198         
       
   199     return script[ aIndex ].iVelocity;
       
   200     }
       
   201 
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // C3DAudioXMLParser::TimeL
       
   205 //
       
   206 // -----------------------------------------------------------------------------
       
   207 //		
       
   208 const TInt& C3DAudioXMLParser::TimeL( TInt aIndex )
       
   209     {
       
   210     User::LeaveIfNull( iParsedPattern );    
       
   211     const RArray<T3DScriptUpdate>& script = iParsedPattern->Script();
       
   212     
       
   213     if ( aIndex < 0 || aIndex >= script.Count() )
       
   214         {
       
   215         User::Leave( KErrArgument );
       
   216         }
       
   217         
       
   218     return script[ aIndex ].iDTime;
       
   219     }
       
   220 
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // C3DAudioXMLParser::Attribute
       
   224 //
       
   225 // -----------------------------------------------------------------------------
       
   226 //		
       
   227 TInt C3DAudioXMLParser::Attribute( TInt aKey )
       
   228     {
       
   229     TInt num = KErrNotFound;
       
   230     
       
   231     switch ( aKey )
       
   232         {
       
   233         case EKeyPatternId:
       
   234             {
       
   235             num = iPatternId;
       
   236             break;
       
   237             }
       
   238         case EKeyDopplerUsed:
       
   239             {
       
   240             num = iParsedPattern->DopplerAvailable();
       
   241             break;
       
   242             }
       
   243         case EKeyVelocity:
       
   244             {
       
   245             num = KMotionPatternDefaultVelocity;
       
   246             break;
       
   247             }
       
   248         default:
       
   249             {
       
   250             break;    
       
   251             }
       
   252         }
       
   253         
       
   254     return num;
       
   255     }
       
   256 
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // C3DAudioXMLParser::ParseL
       
   260 //
       
   261 // -----------------------------------------------------------------------------
       
   262 //		
       
   263 void C3DAudioXMLParser::ParseL( TInt aPatternId )
       
   264 	{
       
   265 	FLOG( _L("C3DAudioXMLParser::ParseL START") );
       
   266 
       
   267 	if ( ReadFromPatternCacheL( aPatternId ) )
       
   268 	    {
       
   269 
       
   270 #ifdef _DEBUG
       
   271         // parsed pattern data found in cache (publish and subcribe)
       
   272         FlogPatternL( aPatternId );
       
   273 #endif
       
   274 
       
   275 	    }
       
   276 	else
       
   277 	    {
       
   278     	GetPatternFullPathL( iFullPath, aPatternId );
       
   279 	    ParseL( iFullPath );
       
   280 
       
   281 	    WriteToPatternCacheL( aPatternId );
       
   282 	    
       
   283 	    FLOG( _L("pattern '%S' parsed and written to cache"), &iFullPath );
       
   284 	    }
       
   285 	    
       
   286 	iPatternId = aPatternId;
       
   287 	
       
   288 #ifdef _DEBUG                         
       
   289     AssertParseDataL( aPatternId );
       
   290 #endif
       
   291 
       
   292 	
       
   293 	FLOG( _L("C3DAudioXMLParser::ParseL END") );
       
   294 	}
       
   295 
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // C3DAudioXMLParser::ParseL
       
   299 //
       
   300 // -----------------------------------------------------------------------------
       
   301 //		
       
   302 void C3DAudioXMLParser::ParseL( const TDesC& aFileName )
       
   303 	{
       
   304 	delete iParsedPattern;
       
   305     iParsedPattern = NULL;
       
   306 	iParsedPattern = C3DAudioPattern::NewL();
       
   307 	
       
   308 	//
       
   309 	// read xml-format pattern file into descriptor
       
   310 	//
       
   311 	CBufFlat* buf = ReadPatternFileL( aFileName );
       
   312 	CleanupStack::PushL( buf );
       
   313 	
       
   314 	//
       
   315 	// parse xml-format pattern into C3DAudioPattern
       
   316 	//
       
   317 	TPtr8 ptr = buf->Ptr( 0 );
       
   318     iParser->ParseL( ptr );
       
   319     iParser->ParseEndL();
       
   320     
       
   321     RArray<T3DScriptUpdate> script = iParsedPattern->Script();
       
   322 	if ( script.Count() == 0 )
       
   323 	    {
       
   324         User::Leave( KErrNotFound );
       
   325 	    }
       
   326 
       
   327    	CleanupStack::PopAndDestroy( buf );
       
   328 	}
       
   329 
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // C3DAudioXMLParser::ReadFromPatternCacheL
       
   333 //
       
   334 // -----------------------------------------------------------------------------
       
   335 //		
       
   336 TBool C3DAudioXMLParser::ReadFromPatternCacheL( TInt aPatternId )
       
   337 	{
       
   338    	C3DPatternPS* pubSub = C3DPatternPS::NewLC( KRingingTone3DAudioEComPluginUID );
       
   339     
       
   340     TInt patternId = pubSub->IntL( C3DPatternPS::EKeyPatternId );
       
   341     if ( patternId == aPatternId )
       
   342         {
       
   343         // buffer for 3D pattern data
       
   344         CBufFlat* buf = pubSub->DataLC();
       
   345                 
       
   346         // readstream to construct the pattern.
       
   347         RBufReadStream readstream( *buf );
       
   348         CleanupClosePushL( readstream );
       
   349                 
       
   350         // create C3DAudioPattern for accessing 3D ringing tone data 
       
   351         delete iParsedPattern;
       
   352         iParsedPattern = NULL;
       
   353         iParsedPattern = C3DAudioPattern::NewL( readstream );
       
   354     
       
   355 	    CleanupStack::PopAndDestroy( &readstream );
       
   356 	    CleanupStack::PopAndDestroy( buf );
       
   357         }
       
   358        
       
   359 	CleanupStack::PopAndDestroy( pubSub );
       
   360 	
       
   361 	if ( patternId == aPatternId )
       
   362 	    {
       
   363 	    return ETrue;
       
   364 	    }
       
   365 	return EFalse;
       
   366 	}
       
   367 
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // C3DAudioXMLParser::WriteToPatternCacheL
       
   371 //
       
   372 // -----------------------------------------------------------------------------
       
   373 //		
       
   374 void C3DAudioXMLParser::WriteToPatternCacheL( TInt aPatternId )
       
   375 	{
       
   376     const TInt KGranularity = 1024;
       
   377 	
       
   378    	C3DPatternPS* pubSub = C3DPatternPS::NewLC( KRingingTone3DAudioEComPluginUID );
       
   379 
       
   380     //
       
   381     // write binary-format (parsed) pattern data into descriptor
       
   382     //
       
   383     CBufFlat* buf = CBufFlat::NewL( KGranularity );
       
   384     CleanupStack::PushL( buf );
       
   385     
       
   386     RBufWriteStream writestream( *buf );
       
   387     CleanupClosePushL( writestream );
       
   388     iParsedPattern->ExternalizeL( writestream );
       
   389    	writestream.CommitL();
       
   390 	CleanupStack::PopAndDestroy( &writestream );
       
   391 
       
   392 #ifdef _DEBUG
       
   393     TInt oldPatternId = pubSub->IntL( C3DPatternPS::EKeyPatternId );
       
   394     FlogPatternsL( oldPatternId, aPatternId );
       
   395 #endif    
       
   396     
       
   397     //
       
   398     // write pattern data and attributes into public and subscribe
       
   399     //
       
   400     pubSub->SetIntL( C3DPatternPS::EKeyPatternId, KErrNotFound );
       
   401 	pubSub->SetIntL( C3DPatternPS::EKeyDopplerUsed, iParsedPattern->DopplerAvailable() );
       
   402 	pubSub->SetIntL( C3DPatternPS::EKeyVelocity, KMotionPatternDefaultVelocity );
       
   403 	pubSub->SetDataL( buf->Ptr( 0 ) );
       
   404 	pubSub->SetIntL( C3DPatternPS::EKeyPatternId, aPatternId );
       
   405 	
       
   406 	CleanupStack::PopAndDestroy( buf );
       
   407 	
       
   408 	CleanupStack::PopAndDestroy( pubSub );
       
   409 	}
       
   410 
       
   411 
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // C3DAudioXMLParser::OnStartDocumentL
       
   415 // Leave if error, otherwise nothing to do.
       
   416 // -----------------------------------------------------------------------------
       
   417 //	
       
   418 void C3DAudioXMLParser::OnStartDocumentL( 
       
   419 	const Xml::RDocumentParameters& /*aDocParam*/, 
       
   420 	TInt aErrorCode )
       
   421 	{
       
   422 	// Leave if error occurred.
       
   423 	User::LeaveIfError( aErrorCode );
       
   424 	}
       
   425 
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // C3DAudioXMLParser::OnEndDocumentL
       
   429 // Leave if error, otherwise nothing to do.
       
   430 // -----------------------------------------------------------------------------
       
   431 //		
       
   432 void C3DAudioXMLParser::OnEndDocumentL( 
       
   433 	TInt aErrorCode )
       
   434 	{
       
   435 	// Leave if error occurred.
       
   436 	User::LeaveIfError( aErrorCode );
       
   437 	}
       
   438 
       
   439 
       
   440 // -----------------------------------------------------------------------------
       
   441 // C3DAudioXMLParser::OnStartElementL
       
   442 // Proceed depending on the element.
       
   443 // -----------------------------------------------------------------------------
       
   444 //		
       
   445 void C3DAudioXMLParser::OnStartElementL( 
       
   446 	const Xml::RTagInfo& aElement, 
       
   447 	const Xml::RAttributeArray& aAttributes, 
       
   448 	TInt aErrorCode )
       
   449 	{
       
   450 	// Leave if error occurred.
       
   451 	User::LeaveIfError( aErrorCode );
       
   452 	
       
   453 	CopyL( iElementName, aElement.LocalName().DesC() );
       
   454 	
       
   455 	// Proceed depending of the element.
       
   456 	if ( iElementName.CompareC( KUpdateElement ) == 0 )
       
   457 		{
       
   458 		ProcessUpdateAttributesL( aAttributes );
       
   459 		iLastTag = EUpdate;
       
   460 		}
       
   461 	else if ( iElementName.CompareC( KPositionElement ) == 0 )
       
   462 		{
       
   463 		// Do not take position in initialization in account.
       
   464 		if ( iLastTag == EUpdate )
       
   465 			{
       
   466 			ProcessPositionAttributesL( aAttributes );
       
   467 			}
       
   468 		}
       
   469 	else if ( iElementName.CompareC( KVelocityElement ) == 0 )
       
   470 		{
       
   471 		// Do not take velocity in initialization in account.
       
   472 		if ( iLastTag == EUpdate )
       
   473 			{
       
   474 			ProcessVelocityAttributesL( aAttributes );	
       
   475 			}
       
   476 		}
       
   477 	else if ( iElementName.CompareC( KInitElement ) == 0 )
       
   478 		{
       
   479 		// pasi
       
   480 		// Create new motion pattern and process the attributes of it.
       
   481 		delete iParsedPattern;
       
   482     	iParsedPattern = NULL;
       
   483 		iParsedPattern = C3DAudioPattern::NewL();
       
   484 		
       
   485 		ProcessInitAttributesL( aAttributes );
       
   486 		iLastTag = EInitialization;
       
   487 		}
       
   488 	else if ( iElementName.CompareC( KLoopElement ) == 0 )
       
   489 		{
       
   490 		ProcessLoopAttributesL( aAttributes );
       
   491 		}
       
   492 	}
       
   493 
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // C3DAudioXMLParser::OnEndElementL
       
   497 // Proceed for elements that need processing.
       
   498 // -----------------------------------------------------------------------------
       
   499 //		
       
   500 void C3DAudioXMLParser::OnEndElementL( const Xml::RTagInfo& aElement, TInt aErrorCode )
       
   501 	{
       
   502 	// Leave if error occurred.
       
   503 	User::LeaveIfError( aErrorCode );
       
   504 	
       
   505 	CopyL( iElementName, aElement.LocalName().DesC() );
       
   506 	
       
   507 	if ( iElementName.CompareC( KUpdateElement ) == 0 )
       
   508 		{
       
   509 		// Update-element ended, add the update to script.
       
   510 		iParsedPattern->AddUpdateL( iCurrentUpdate );
       
   511 		}
       
   512 	else if ( iElementName.CompareC( KLoopElement ) == 0 )
       
   513 		{
       
   514 		// Loop-element ended, end the loop.
       
   515 		iParsedPattern->EndLoop();
       
   516 		}
       
   517 	}
       
   518 
       
   519 
       
   520 // -----------------------------------------------------------------------------
       
   521 // C3DAudioXMLParser::OnContentL
       
   522 // Leave if error, otherwise nothing to do.
       
   523 // -----------------------------------------------------------------------------
       
   524 //		
       
   525 void C3DAudioXMLParser::OnContentL( const TDesC8& /*aBytes*/, TInt aErrorCode )
       
   526 	{
       
   527 	// Leave if error occurred.
       
   528 	User::LeaveIfError( aErrorCode );
       
   529 	}
       
   530 
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // C3DAudioXMLParser::OnStartPrefixMappingL
       
   534 // Leave if error, otherwise nothing to do.
       
   535 // -----------------------------------------------------------------------------
       
   536 //	
       
   537 void C3DAudioXMLParser::OnStartPrefixMappingL( const RString& /*aPrefix*/, 
       
   538 	                                           const RString& /*aUri*/, 
       
   539 	                                           TInt aErrorCode )
       
   540 	{
       
   541 	// Leave if error occurred.
       
   542 	User::LeaveIfError( aErrorCode );
       
   543 	}
       
   544 
       
   545 
       
   546 // -----------------------------------------------------------------------------
       
   547 // C3DAudioXMLParser::OnEndPrefixMappingL
       
   548 // Leave if error, otherwise nothing to do.
       
   549 // -----------------------------------------------------------------------------
       
   550 //		
       
   551 void C3DAudioXMLParser::OnEndPrefixMappingL( const RString& /*aPrefix*/, 
       
   552 	                                         TInt aErrorCode )
       
   553 	{
       
   554 	// Leave if error occurred.
       
   555 	User::LeaveIfError( aErrorCode );
       
   556 	}
       
   557 
       
   558 
       
   559 // -----------------------------------------------------------------------------
       
   560 // C3DAudioXMLParser::OnIgnorableWhiteSpaceL
       
   561 // Leave if error, otherwise nothing to do.
       
   562 // -----------------------------------------------------------------------------
       
   563 //		
       
   564 void C3DAudioXMLParser::OnIgnorableWhiteSpaceL(	const TDesC8& /*aBytes*/, 
       
   565 	                                            TInt aErrorCode )
       
   566 	{
       
   567 	// Leave if error occurred.
       
   568 	User::LeaveIfError( aErrorCode );
       
   569 	}
       
   570 
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // C3DAudioXMLParser::OnSkippedEntityL
       
   574 // Leave if error, otherwise nothing to do.
       
   575 // -----------------------------------------------------------------------------
       
   576 //		
       
   577 void C3DAudioXMLParser::OnSkippedEntityL( const RString& /*aName*/, 
       
   578 	                                      TInt aErrorCode )
       
   579 	{
       
   580 	// Leave if error occurred.
       
   581 	User::LeaveIfError( aErrorCode );
       
   582 	}
       
   583 
       
   584 
       
   585 // -----------------------------------------------------------------------------
       
   586 // C3DAudioXMLParser::OnProcessingInstructionL
       
   587 // Leave if error, otherwise nothing to do.
       
   588 // -----------------------------------------------------------------------------
       
   589 //		
       
   590 void C3DAudioXMLParser::OnProcessingInstructionL( const TDesC8& /*aTarget*/, 
       
   591 	                                              const TDesC8& /*aData*/, 
       
   592 	                                              TInt aErrorCode )
       
   593 	{
       
   594 	// Leave if error occurred.
       
   595 	User::LeaveIfError( aErrorCode );
       
   596 	}
       
   597 
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // C3DAudioXMLParser::OnError
       
   601 // Print error code to debug.
       
   602 // -----------------------------------------------------------------------------
       
   603 //		
       
   604 void C3DAudioXMLParser::OnError( TInt aErrorCode )
       
   605 	{
       
   606 	if ( aErrorCode != KErrNone )
       
   607 	    {
       
   608 	    FLOG( _L("### C3DAudioXMLParser::OnError (%d) ###"), aErrorCode );    
       
   609 	    }
       
   610 	}
       
   611 
       
   612 
       
   613 // -----------------------------------------------------------------------------
       
   614 // C3DAudioXMLParser::GetExtendedInterface
       
   615 // Not implemented
       
   616 // -----------------------------------------------------------------------------
       
   617 //
       
   618 TAny* C3DAudioXMLParser::GetExtendedInterface( const TInt32 /*aUid*/ )
       
   619 	{
       
   620 	return NULL;
       
   621 	}
       
   622 
       
   623 
       
   624 // -----------------------------------------------------------------------------
       
   625 // C3DAudioXMLParser::ProcessInitAttributesL
       
   626 // Process the initialization attributes.
       
   627 // -----------------------------------------------------------------------------
       
   628 //
       
   629 void C3DAudioXMLParser::ProcessInitAttributesL( const Xml::RAttributeArray& aAttributes )
       
   630 	{
       
   631 	// Check each attribute.	
       
   632 	for ( TUint i = 0; i < aAttributes.Count(); ++i )
       
   633 		{
       
   634 		CopyL( iAttributeName, aAttributes[i].Attribute().LocalName().DesC() );
       
   635 		CopyL( iAttributeValue, aAttributes[i].Value().DesC() );
       
   636 		
       
   637 		// Set the name of the pattern.
       
   638 		if ( iAttributeName.CompareC( KPatternName ) == 0 )
       
   639 			{
       
   640 			iParsedPattern->SetNameL( iAttributeValue );
       
   641 			}
       
   642 		else if ( iAttributeName.CompareC( KPatternReverb ) == 0 )
       
   643 			{
       
   644 			TUint selectedReverb = EReverbNotEnabled;
       
   645 
       
   646 			// Determine the reverberation.			
       
   647 			if ( iAttributeValue.CompareC( KReverbPresetOne ) == 0 )
       
   648 				{
       
   649 				selectedReverb = EReverbPresetOne;	
       
   650 				}
       
   651 			else if ( iAttributeValue.CompareC( KReverbPresetTwo ) == 0 )
       
   652 				{
       
   653 				selectedReverb = EReverbPresetTwo;
       
   654 				}
       
   655 			else if ( iAttributeValue.CompareC( KReverbPresetThree ) == 0 )
       
   656 				{
       
   657 				selectedReverb = EReverbPresetThree;
       
   658 				}
       
   659 			else if ( iAttributeValue.CompareC( KReverbPresetFour ) == 0 )
       
   660 				{
       
   661 				selectedReverb = EReverbPresetFour;
       
   662 				}
       
   663 			else if ( iAttributeValue.CompareC( KReverbPresetFive ) == 0 )
       
   664 				{
       
   665 				selectedReverb = EReverbPresetFive;
       
   666 				}
       
   667 			else if ( iAttributeValue.CompareC( KReverbPresetSix ) == 0 )
       
   668 				{
       
   669 				selectedReverb = EReverbPresetSix;
       
   670 				}
       
   671 				
       
   672 			// Set the reverberation to pattern.				
       
   673 			iParsedPattern->SetReverb( selectedReverb );
       
   674 			}
       
   675 		else if ( iAttributeName.CompareC( KPatternDoppler ) == 0)
       
   676 			{
       
   677 			// Set doppler.			
       
   678 			if ( iAttributeValue.CompareC( KBooleanTrue ) == 0 )
       
   679 				{
       
   680 				iParsedPattern->SetDoppler( ETrue );
       
   681 				}
       
   682 			}
       
   683 		}
       
   684 	}
       
   685 
       
   686 
       
   687 // -----------------------------------------------------------------------------
       
   688 // C3DAudioXMLParser::ProcessLoopAttributes
       
   689 // Process the loop-element attributes.
       
   690 // -----------------------------------------------------------------------------
       
   691 //
       
   692 void C3DAudioXMLParser::ProcessLoopAttributesL( const Xml::RAttributeArray& aAttributes )
       
   693 	{
       
   694 	TLex8 lex;
       
   695 			
       
   696 	for ( TUint i = 0; i < aAttributes.Count(); ++i )
       
   697 		{
       
   698 		CopyL( iAttributeName, aAttributes[i].Attribute().LocalName().DesC() );
       
   699 		CopyL( iAttributeValue, aAttributes[i].Value().DesC() );
       
   700 
       
   701 		lex.Assign( iAttributeValue );
       
   702 		
       
   703 		if ( iAttributeName.CompareC( KLoopCount ) == 0 )
       
   704 			{
       
   705 			TUint loopCount;
       
   706 			User::LeaveIfError ( lex.Val( loopCount ) );
       
   707 			
       
   708 			// Start the loop in pattern.
       
   709 			iParsedPattern->StartLoopL( loopCount );
       
   710 			}
       
   711 		}
       
   712 	}
       
   713 
       
   714 
       
   715 // -----------------------------------------------------------------------------
       
   716 // C3DAudioXMLParser::ProcessPositionAttributes
       
   717 // Process the position-element attributes.
       
   718 // -----------------------------------------------------------------------------
       
   719 //
       
   720 void C3DAudioXMLParser::ProcessPositionAttributesL( const Xml::RAttributeArray& aAttributes )
       
   721 	{
       
   722 	TLex8 lex;
       
   723 	T3DPosition position = T3DPosition();
       
   724 		
       
   725     TInt count = aAttributes.Count();
       
   726 	for ( TUint i = 0; i < count; ++i )
       
   727 		{
       
   728 		CopyL( iAttributeName, aAttributes[i].Attribute().LocalName().DesC() );
       
   729 		CopyL( iAttributeValue, aAttributes[i].Value().DesC() );
       
   730 
       
   731 		lex.Assign( iAttributeValue );
       
   732 		
       
   733 		if ( iAttributeName.CompareC( KXCoordinate ) == 0 )
       
   734 			{
       
   735 			User::LeaveIfError( lex.Val( position.iX ) );
       
   736 			}
       
   737 		else if ( iAttributeName.CompareC( KYCoordinate ) == 0 )
       
   738 			{
       
   739 			User::LeaveIfError( lex.Val( position.iY ) );
       
   740 			}
       
   741 		else if ( iAttributeName.CompareC( KZCoordinate ) == 0)
       
   742 			{
       
   743 			User::LeaveIfError( lex.Val( position.iZ ) );
       
   744 			}
       
   745 		}
       
   746 		
       
   747 	// Set position for current update.
       
   748 	iCurrentUpdate.iPosition = position;	
       
   749 	}
       
   750 
       
   751 
       
   752 // -----------------------------------------------------------------------------
       
   753 // C3DAudioXMLParser::ProcessUpdateAttributes
       
   754 // Process the update-element attributes.
       
   755 // -----------------------------------------------------------------------------
       
   756 //
       
   757 void C3DAudioXMLParser::ProcessUpdateAttributesL( const Xml::RAttributeArray& aAttributes )
       
   758 	{
       
   759 	TLex8 lex;
       
   760 	// New update-element.
       
   761 	iCurrentUpdate = T3DScriptUpdate();
       
   762 		
       
   763 	for ( TUint i = 0; i < aAttributes.Count(); ++i )
       
   764 		{
       
   765 		CopyL( iAttributeName, aAttributes[i].Attribute().LocalName().DesC() );
       
   766 		CopyL( iAttributeValue, aAttributes[i].Value().DesC() );
       
   767 
       
   768 		lex.Assign( iAttributeValue );
       
   769 		
       
   770 		if ( iAttributeName.CompareC( KDTime ) == 0 )
       
   771 			{
       
   772 			// Set the dTime for the update.			
       
   773 			User::LeaveIfError( lex.Val( iCurrentUpdate.iDTime ) );
       
   774 			}
       
   775 		}
       
   776 	}
       
   777 
       
   778 
       
   779 // -----------------------------------------------------------------------------
       
   780 // C3DAudioXMLParser::ProcessVelocityAttributes
       
   781 // Process the velocity-element attributes.
       
   782 // -----------------------------------------------------------------------------
       
   783 //
       
   784 void C3DAudioXMLParser::ProcessVelocityAttributesL( const Xml::RAttributeArray& aAttributes )
       
   785 	{
       
   786 	TLex8 lex;
       
   787 	T3DVelocity velocity = T3DVelocity();
       
   788 		
       
   789 	for ( TUint i = 0; i < aAttributes.Count(); ++i )
       
   790 		{
       
   791 		CopyL( iAttributeName, aAttributes[i].Attribute().LocalName().DesC() );
       
   792 		CopyL( iAttributeValue, aAttributes[i].Value().DesC() );
       
   793 
       
   794 		lex.Assign( iAttributeValue );
       
   795 		
       
   796 		if ( iAttributeName.CompareC( KScalarVelocity ) == 0 )
       
   797 			{
       
   798 			velocity.iScalar = ETrue;
       
   799 			User::LeaveIfError( lex.Val( velocity.iScalarVelocity ) );
       
   800 			velocity.iXVector = 0;
       
   801 			velocity.iYVector = 0;
       
   802 			velocity.iZVector = 0;
       
   803 			break;
       
   804 			}
       
   805 		else if ( iAttributeName.CompareC( KXCoordinate ) == 0 )
       
   806 			{
       
   807 			User::LeaveIfError( lex.Val( velocity.iXVector ) );
       
   808 			}
       
   809 		else if ( iAttributeName.CompareC( KYCoordinate ) == 0 )
       
   810 			{
       
   811 			User::LeaveIfError( lex.Val( velocity.iYVector ) );
       
   812 			}
       
   813 		else if ( iAttributeName.CompareC( KZCoordinate ) == 0)
       
   814 			{
       
   815 			User::LeaveIfError( lex.Val( velocity.iZVector ) );
       
   816 			}
       
   817 		}
       
   818 	// Set velocity for current update.	
       
   819 	iCurrentUpdate.iVelocity = velocity;
       
   820 	}
       
   821 
       
   822 
       
   823 // -----------------------------------------------------------------------------
       
   824 // C3DAudioXMLParser::CopyL
       
   825 // 
       
   826 // -----------------------------------------------------------------------------
       
   827 //
       
   828 void C3DAudioXMLParser::CopyL( TDes8& aTarget, const TDesC8& aSource )
       
   829 	{
       
   830 	if ( aSource.Length() > aTarget.MaxLength() )
       
   831 	    {
       
   832 
       
   833 #ifdef _DEBUG			                
       
   834         Panic( KErrArgument );
       
   835 #endif        
       
   836 
       
   837 	    User::Leave( KErrTooBig );
       
   838 	    }
       
   839 	    
       
   840 	aTarget.Copy( aSource );
       
   841 	}
       
   842 
       
   843 
       
   844 // -----------------------------------------------------------------------------
       
   845 // C3DAudioXMLParser::Panic()
       
   846 //
       
   847 // -----------------------------------------------------------------------------
       
   848 //    
       
   849 void C3DAudioXMLParser::Panic(TInt aReason)
       
   850     {
       
   851 	_LIT(KPanicCategory,"RingingTone3DAudioPlugin");
       
   852 	
       
   853 	User::Panic(KPanicCategory, aReason); 
       
   854     }
       
   855     
       
   856 
       
   857 // -------------------------------------------------------------------------------
       
   858 // C3DAudioXMLParser::ReadPatternFileL
       
   859 //
       
   860 // -------------------------------------------------------------------------------
       
   861 //
       
   862 CBufFlat* C3DAudioXMLParser::ReadPatternFileL( const TDesC& aFullName )
       
   863     {
       
   864     const TInt KGranularity = 1024;
       
   865     
       
   866     RFile file;
       
   867 	User::LeaveIfError( file.Open( iFsSession, aFullName, EFileRead ) );
       
   868 	CleanupClosePushL( file );
       
   869 
       
   870   	CBufFlat* buf = CBufFlat::NewL( KGranularity );
       
   871 	CleanupStack::PushL( buf );
       
   872 	
       
   873 	TInt size = 0;
       
   874 	file.Size( size );
       
   875 	buf->ResizeL( size );
       
   876 	
       
   877 	TPtr8 ptr = buf->Ptr( 0 );
       
   878 	User::LeaveIfError( file.Read( ptr ) );
       
   879 
       
   880 	CleanupStack::Pop( buf );
       
   881 	CleanupStack::PopAndDestroy( &file );
       
   882 	
       
   883 	return buf;
       
   884     }
       
   885     
       
   886     
       
   887 // -------------------------------------------------------------------------------
       
   888 // C3DAudioXMLParser::GetPatternFullPathL
       
   889 //
       
   890 // -------------------------------------------------------------------------------
       
   891 //
       
   892 void C3DAudioXMLParser::GetPatternFullPathL(TDes& aText, TInt aPatternId)
       
   893     {
       
   894     _LIT( KFormatString, "%S%S%S\\%S");
       
   895 
       
   896     TBuf<KBufSize32> pattern;
       
   897 
       
   898     // emulator dir  "\epoc32\release\winscw\udeb\Z\resource\3DTones"
       
   899     // hardware dir  "z:\data\Z\resource\3DTones"
       
   900 
       
   901     switch (aPatternId)
       
   902         {
       
   903         case EProfile3DEffectCircle:
       
   904             {
       
   905             pattern = KPatternCircle;
       
   906             break;
       
   907             }
       
   908         case EProfile3DEffectFlyby:
       
   909             {
       
   910             pattern = KPatternFlyBy;
       
   911             break;
       
   912             }
       
   913         case EProfile3DEffectZigZag:
       
   914             {
       
   915             pattern = KPatternZigZag;
       
   916             break;
       
   917             }
       
   918         case EProfile3DEffectRandomWalk:
       
   919             {
       
   920             pattern = KPatternRandomWalk;
       
   921             break;
       
   922             }
       
   923         case EProfile3DEffectChaos:
       
   924             {
       
   925             pattern = KPatternChaos;
       
   926             break;
       
   927             }
       
   928         default:
       
   929             {
       
   930             User::Leave( KErrNotSupported );
       
   931             break;
       
   932             }
       
   933         }
       
   934         
       
   935   	TDriveUnit drive( EDriveZ );
       
   936 	TDriveName driveName = drive.Name();
       
   937 	
       
   938 	aText.Format(KFormatString, &driveName, &KDC_RESOURCE_FILES_DIR, &K3DTonesDir, &pattern);
       
   939     }
       
   940     
       
   941 
       
   942 
       
   943 
       
   944 
       
   945 
       
   946 #ifdef _DEBUG
       
   947 
       
   948 // -----------------------------------------------------------------------------
       
   949 // C3DAudioXMLParser::AssertParseDataL
       
   950 //
       
   951 // -----------------------------------------------------------------------------
       
   952 //
       
   953 void C3DAudioXMLParser::AssertParseDataL( TInt aPatternId )
       
   954 	{
       
   955 	const TInt KGranularity = 1024;
       
   956 	
       
   957    	C3DPatternPS* ps = C3DPatternPS::NewLC( KRingingTone3DAudioEComPluginUID );
       
   958 	   	
       
   959     CBufFlat* buf = CBufFlat::NewL( KGranularity );
       
   960     CleanupStack::PushL( buf );
       
   961     
       
   962     RBufWriteStream writestream( *buf );
       
   963     CleanupClosePushL( writestream );
       
   964     iParsedPattern->ExternalizeL( writestream );
       
   965    	writestream.CommitL();
       
   966 	CleanupStack::PopAndDestroy( &writestream );
       
   967 	
       
   968 	CBufFlat* buf2 = ps->DataLC();
       
   969 
       
   970 
       
   971     TInt id = ps->IntL(C3DPatternPS::EKeyPatternId);
       
   972     if ( id != aPatternId )
       
   973         {
       
   974         Panic( KErrGeneral );
       
   975         }
       
   976     
       
   977     TPtr8 p1 = buf->Ptr( 0 );
       
   978     TPtr8 p2 = buf2->Ptr( 0 );
       
   979     
       
   980     TInt ret = p1.Compare( p2 );
       
   981     if ( ret != 0 )
       
   982         {
       
   983         Panic( KErrGeneral );
       
   984         }
       
   985     TInt doppler = ps->IntL( C3DPatternPS::EKeyDopplerUsed );
       
   986     if ( doppler != iParsedPattern->DopplerAvailable() )
       
   987         {
       
   988         Panic( KErrGeneral );
       
   989         }
       
   990     TInt velocity = ps->IntL( C3DPatternPS::EKeyVelocity );
       
   991     if (velocity != KMotionPatternDefaultVelocity)
       
   992         {
       
   993         Panic( KErrGeneral );
       
   994         }
       
   995     
       
   996     CleanupStack::PopAndDestroy( buf2 );
       
   997     CleanupStack::PopAndDestroy( buf );
       
   998     CleanupStack::PopAndDestroy( ps );
       
   999 	}
       
  1000 
       
  1001 
       
  1002 // -----------------------------------------------------------------------------
       
  1003 // C3DAudioXMLParser::FlogPatternsL()
       
  1004 //
       
  1005 // -----------------------------------------------------------------------------
       
  1006 //    
       
  1007 void C3DAudioXMLParser::FlogPatternsL(TInt aOldPattern, TInt aNewPattern)
       
  1008     {
       
  1009     TBuf<128> buf; TBuf<128> buf2;
       
  1010     
       
  1011     GetPatternString(buf, aOldPattern);
       
  1012     GetPatternString(buf2, aNewPattern);
       
  1013     FLOG( _L("pattern changed from '%S' to '%S'"), &buf, &buf2 );
       
  1014     }
       
  1015 
       
  1016 
       
  1017 // -----------------------------------------------------------------------------
       
  1018 // C3DAudioXMLParser::FlogPatternL()
       
  1019 //
       
  1020 // -----------------------------------------------------------------------------
       
  1021 //    
       
  1022 void C3DAudioXMLParser::FlogPatternL(TInt aPattern)
       
  1023     {
       
  1024     TBuf<128> buf;
       
  1025     
       
  1026     GetPatternString(buf, aPattern);
       
  1027     FLOG( _L("pattern '%S' found in cache"), &buf );
       
  1028     }
       
  1029 
       
  1030 
       
  1031 // -----------------------------------------------------------------------------
       
  1032 // C3DAudioXMLParser::GetPatternString()
       
  1033 //
       
  1034 // -----------------------------------------------------------------------------
       
  1035 //    
       
  1036 void C3DAudioXMLParser::GetPatternString(TDes& aText, TInt aPattern)
       
  1037     {
       
  1038 	switch (aPattern)
       
  1039 		{
       
  1040 		case EProfile3DEffectOff:
       
  1041 			aText = _L("EProfile3DEffectOff");
       
  1042 			break;
       
  1043 		case EProfile3DEffectCircle:
       
  1044 			aText = _L("EProfile3DEffectCircle");
       
  1045 			break;
       
  1046 		case EProfile3DEffectFlyby:
       
  1047 			aText = _L("EProfile3DEffectFlyby");
       
  1048 			break;
       
  1049 		case EProfile3DEffectZigZag:
       
  1050 			aText = _L("EProfile3DEffectZigZag");
       
  1051 			break;
       
  1052 		case EProfile3DEffectRandomWalk:
       
  1053 			aText = _L("EProfile3DEffectRandomWalk");
       
  1054 			break;
       
  1055 		case EProfile3DEffectChaos:
       
  1056 			aText = _L("EProfile3DEffectChaos");
       
  1057 			break;
       
  1058 		case EProfile3DEffectStereoWidening:
       
  1059 			aText = _L("EProfile3DEffectStereoWidening");
       
  1060 			break;
       
  1061 		case KErrNotFound:
       
  1062 			aText = _L("KErrNotFound");
       
  1063 			break;
       
  1064 
       
  1065 		default:
       
  1066 			aText = _L("### unknown pattern ###");
       
  1067 			break;
       
  1068 		}
       
  1069     }
       
  1070 
       
  1071 
       
  1072 // -----------------------------------------------------------------------------
       
  1073 // C3DAudioXMLParser::FlogPubSubL()
       
  1074 //
       
  1075 // -----------------------------------------------------------------------------
       
  1076 //    
       
  1077 void C3DAudioXMLParser::FlogPubSubL(TInt aEcho)
       
  1078     {
       
  1079     FLOG( _L("------ start pubsub data ------") );
       
  1080     
       
  1081     TInt num = 0;
       
  1082     TBuf<128> buf;
       
  1083     
       
  1084     C3DPatternPS* pubSub = C3DPatternPS::NewLC( KRingingTone3DAudioEComPluginUID );
       
  1085 	
       
  1086 	num = pubSub->IntL(C3DPatternPS::EKeyPatternId);
       
  1087     C3DAudioXMLParser::GetPatternString(buf, num);
       
  1088     FLOG( _L("pattern: %S (%d)"), &buf, num );
       
  1089     
       
  1090     GetEchoString(buf, aEcho);
       
  1091     FLOG( _L("echo: %S (%d)"), &buf, aEcho );
       
  1092  
       
  1093     num = pubSub->IntL(C3DPatternPS::EKeyVelocity);
       
  1094     FLOG( _L("velocity: %d"), num );
       
  1095     
       
  1096     num = pubSub->IntL(C3DPatternPS::EKeyDopplerUsed);
       
  1097     FLOG( _L("doppler: %d"), num );
       
  1098     
       
  1099     num = pubSub->IntL(C3DPatternPS::EKeyDataSize);
       
  1100     FLOG( _L("data size: %d"), num );
       
  1101     
       
  1102     CleanupStack::PopAndDestroy( pubSub );
       
  1103     
       
  1104     FLOG( _L("------ end pubsub data ------") );
       
  1105     }
       
  1106 
       
  1107 
       
  1108 // -----------------------------------------------------------------------------
       
  1109 // C3DAudioXMLParser::GetEchoString()
       
  1110 //
       
  1111 // -----------------------------------------------------------------------------
       
  1112 //    
       
  1113 void C3DAudioXMLParser::GetEchoString(TDes& aText, TInt aEcho)
       
  1114     {
       
  1115 	switch (aEcho)
       
  1116 		{
       
  1117 		case EProfile3DEchoOff:
       
  1118 			aText = _L("EProfile3DEchoOff");
       
  1119 			break;
       
  1120 		case EProfile3DEchoLivingRoom:
       
  1121 			aText = _L("EProfile3DEchoLivingRoom");
       
  1122 			break;
       
  1123 		case EProfile3DEchoCave:
       
  1124 			aText = _L("EProfile3DEchoCave");
       
  1125 			break;
       
  1126 		case EProfile3DEchoStoneCorridor:
       
  1127 			aText = _L("EProfile3DEchoStoneCorridor");
       
  1128 			break;
       
  1129 		case EProfile3DEchoForest:
       
  1130 			aText = _L("EProfile3DEchoForest");
       
  1131 			break;
       
  1132 		case EProfile3DEchoSewerPipe:
       
  1133 			aText = _L("EProfile3DEchoSewerPipe");
       
  1134 			break;
       
  1135 		case EProfile3DEchoUnderwater:
       
  1136 			aText = _L("EProfile3DEchoUnderwater");
       
  1137 			break;
       
  1138 		default:
       
  1139 			aText = _L("### unknown echo ###");
       
  1140 			break;
       
  1141 		}
       
  1142     }
       
  1143 
       
  1144 #endif // _DEBUG
       
  1145 
       
  1146 
       
  1147 
       
  1148 
       
  1149 /******************************************************************************
       
  1150  * class C3DPatternPS
       
  1151  ******************************************************************************/
       
  1152 
       
  1153 
       
  1154 
       
  1155 // -----------------------------------------------------------------------------
       
  1156 // C3DPatternPS::NewLC
       
  1157 //
       
  1158 // -----------------------------------------------------------------------------
       
  1159 //		
       
  1160 C3DPatternPS* C3DPatternPS::NewLC( TInt aStoreId )
       
  1161 	{
       
  1162 	C3DPatternPS* self = new ( ELeave ) C3DPatternPS( aStoreId );
       
  1163     CleanupStack::PushL( self );
       
  1164     self->ConstructL();
       
  1165     return self;	
       
  1166 	}
       
  1167 
       
  1168 
       
  1169 // Destructor
       
  1170 C3DPatternPS::~C3DPatternPS()
       
  1171 	{
       
  1172 	iProperty.Close();
       
  1173 	}
       
  1174 
       
  1175 
       
  1176 // -----------------------------------------------------------------------------
       
  1177 // C3DPatternPS::C3DPatternPS
       
  1178 // C++ default constructor can NOT contain any code, that
       
  1179 // might leave.
       
  1180 // -----------------------------------------------------------------------------
       
  1181 //		
       
  1182 C3DPatternPS::C3DPatternPS( TInt aStoreId )
       
  1183 	{
       
  1184 	iStoreUid.iUid = aStoreId;
       
  1185 	}
       
  1186 
       
  1187 
       
  1188 // -----------------------------------------------------------------------------
       
  1189 // C3DPatternPS::ConstructL
       
  1190 //
       
  1191 // -----------------------------------------------------------------------------
       
  1192 //
       
  1193 void C3DPatternPS::ConstructL()
       
  1194     {
       
  1195     TBool ret = DefineKeyL( EKeyPatternId, RProperty::EInt );
       
  1196     if ( ret )
       
  1197         {
       
  1198         // first time initialization
       
  1199         TInt err = iProperty.Set( iStoreUid, EKeyPatternId, KErrNotFound );
       
  1200         User::LeaveIfError( err );
       
  1201         }
       
  1202         
       
  1203     DefineKeyL( EKeyDopplerUsed, RProperty::EInt );
       
  1204     DefineKeyL( EKeyVelocity, RProperty::EInt );
       
  1205     DefineKeyL( EKeyDataSize, RProperty::EInt );
       
  1206     DefineKeyL( EKeyPatternData, RProperty::ELargeText );
       
  1207     }	
       
  1208 
       
  1209 
       
  1210 // -----------------------------------------------------------------------------
       
  1211 // C3DPatternPS::DefineKeyL
       
  1212 //
       
  1213 // -----------------------------------------------------------------------------
       
  1214 //
       
  1215 TBool C3DPatternPS::DefineKeyL( TInt aKeyId, TInt aKeyType )
       
  1216     {
       
  1217     TInt err = iProperty.Define( iStoreUid, aKeyId, aKeyType );
       
  1218 
       
  1219     if ( err != KErrNone && err != KErrAlreadyExists )
       
  1220         {
       
  1221         User::Leave( err );    
       
  1222         }
       
  1223         
       
  1224     if ( err == KErrNone )
       
  1225         {
       
  1226         return ETrue; // key was created
       
  1227         }
       
  1228         
       
  1229     return EFalse;    // key already existed
       
  1230     }
       
  1231 
       
  1232 
       
  1233 
       
  1234 // -----------------------------------------------------------------------------
       
  1235 // C3DPatternPS::IntL
       
  1236 //
       
  1237 // -----------------------------------------------------------------------------
       
  1238 //
       
  1239 TInt C3DPatternPS::IntL( TInt aKey )
       
  1240     {
       
  1241     TInt num = KErrNotFound;
       
  1242     TInt err = iProperty.Get( iStoreUid, aKey, num );
       
  1243     User::LeaveIfError( err );
       
  1244     
       
  1245     return num;
       
  1246     }
       
  1247 
       
  1248 
       
  1249 // -----------------------------------------------------------------------------
       
  1250 // C3DPatternPS::SetIntL
       
  1251 //
       
  1252 // -----------------------------------------------------------------------------
       
  1253 //
       
  1254 void C3DPatternPS::SetIntL( TInt aKey, TInt aValue )
       
  1255     {
       
  1256     TInt err = iProperty.Set( iStoreUid, aKey, aValue );
       
  1257     User::LeaveIfError( err );
       
  1258     }
       
  1259 
       
  1260 
       
  1261 // -----------------------------------------------------------------------------
       
  1262 // C3DPatternPS::SetDataL
       
  1263 //
       
  1264 // -----------------------------------------------------------------------------
       
  1265 //
       
  1266 void C3DPatternPS::SetDataL( const TDesC8& aData )
       
  1267     {
       
  1268     const TInt KMaxSize = 65536;
       
  1269     
       
  1270     if ( aData.Size() > KMaxSize )
       
  1271         {
       
  1272         User::Leave( KErrOverflow );
       
  1273         }
       
  1274 
       
  1275     TInt err = iProperty.Set( iStoreUid, EKeyPatternData, aData );
       
  1276     User::LeaveIfError( err );
       
  1277     
       
  1278     TInt size = aData.Size();
       
  1279     err = iProperty.Set( iStoreUid, EKeyDataSize, size );
       
  1280     User::LeaveIfError( err );
       
  1281     }
       
  1282 
       
  1283 
       
  1284 // -----------------------------------------------------------------------------
       
  1285 // C3DPatternPS::GetDataL
       
  1286 //
       
  1287 // -----------------------------------------------------------------------------
       
  1288 //
       
  1289 void C3DPatternPS::GetDataL( TDes8& aData )
       
  1290     {
       
  1291     TInt err = iProperty.Get( iStoreUid, EKeyPatternData, aData );
       
  1292     User::LeaveIfError( err );
       
  1293     }
       
  1294 
       
  1295 
       
  1296 // -----------------------------------------------------------------------------
       
  1297 // C3DPatternPS::DataLC
       
  1298 //
       
  1299 // -----------------------------------------------------------------------------
       
  1300 //
       
  1301 CBufFlat* C3DPatternPS::DataLC()
       
  1302     {
       
  1303     const TInt KGranularity = 1024;
       
  1304 
       
  1305     CBufFlat* buf = CBufFlat::NewL( KGranularity );
       
  1306     CleanupStack::PushL( buf );
       
  1307 
       
  1308     TInt size = IntL( C3DPatternPS::EKeyDataSize );
       
  1309     buf->ResizeL( size );
       
  1310     TPtr8 ptr8 = buf->Ptr( 0 );
       
  1311     GetDataL( ptr8 );
       
  1312     
       
  1313     return buf;
       
  1314     }
       
  1315 
       
  1316 
       
  1317 
       
  1318 
       
  1319 
       
  1320     
       
  1321 ////////////////////////////////////// START TEST CODE //////////////////////////
       
  1322 
       
  1323 // element names
       
  1324 _LIT(KKInitElement, "initialization");
       
  1325 _LIT(KKUpdateElement, "update");
       
  1326 _LIT(KKPositionElement, "position");
       
  1327 _LIT(KKVelocityElement, "velocity");
       
  1328 
       
  1329 // attribute names
       
  1330 _LIT( KKXCoordinate, "x" );
       
  1331 _LIT( KKYCoordinate, "y" );
       
  1332 _LIT( KKZCoordinate, "z" );
       
  1333 
       
  1334 _LIT( KKPatternName, "name" );
       
  1335 _LIT( KKEchoName, "reverb" );
       
  1336 _LIT( KKDoppler, "doppler" );
       
  1337 _LIT( KKDTime, "dTime" );
       
  1338 
       
  1339 // attribute values
       
  1340 _LIT( KKBooleanTrue, "true" );
       
  1341 
       
  1342 
       
  1343 
       
  1344 
       
  1345 // "Z:\\resource\\10208ADF\\3zigzag.xml"
       
  1346 
       
  1347 
       
  1348 // -----------------------------------------------------------------------------
       
  1349 // C3DPatternParser::NewL
       
  1350 // 
       
  1351 // -----------------------------------------------------------------------------
       
  1352 //
       
  1353 C3DPatternParser* C3DPatternParser::NewL()
       
  1354     {
       
  1355     C3DPatternParser* self = new (ELeave) C3DPatternParser();
       
  1356 	CleanupStack::PushL(self);
       
  1357 	self->ConstructL();
       
  1358 	CleanupStack::Pop(self);
       
  1359 
       
  1360 	return self;
       
  1361     }
       
  1362 
       
  1363 
       
  1364 // -----------------------------------------------------------------------------
       
  1365 // Destructor
       
  1366 // 
       
  1367 // -----------------------------------------------------------------------------
       
  1368 //
       
  1369 C3DPatternParser::~C3DPatternParser()
       
  1370     {
       
  1371     iPositionList.Close();
       
  1372     iVelocityList.Close();
       
  1373    	delete iParser;
       
  1374    	iFsSession.Close();
       
  1375     }
       
  1376 
       
  1377 
       
  1378 // -----------------------------------------------------------------------------
       
  1379 // C3DPatternParser::C3DPatternParser
       
  1380 // 
       
  1381 // -----------------------------------------------------------------------------
       
  1382 //
       
  1383 C3DPatternParser::C3DPatternParser()
       
  1384     {
       
  1385     }
       
  1386 
       
  1387 
       
  1388 // -----------------------------------------------------------------------------
       
  1389 // C3DPatternParser::ConstructL
       
  1390 // 
       
  1391 // -----------------------------------------------------------------------------
       
  1392 //
       
  1393 void C3DPatternParser::ConstructL()
       
  1394     {
       
  1395     _LIT8(KMimeType, "text/xml");
       
  1396     
       
  1397 	iParser = Xml::CParser::NewL( KMimeType, *this );
       
  1398 	
       
  1399 	User::LeaveIfError( iFsSession.Connect() );
       
  1400     }
       
  1401 
       
  1402 
       
  1403 // -----------------------------------------------------------------------------
       
  1404 // C3DPatternParser::ReadFileL
       
  1405 // 
       
  1406 // -----------------------------------------------------------------------------
       
  1407 //
       
  1408 CBufFlat* C3DPatternParser::ReadDocumentL(const TDesC& aFullName)
       
  1409     {
       
  1410     const TInt KGranularity = 1024;
       
  1411     
       
  1412     RFile file;
       
  1413 	User::LeaveIfError( file.Open(iFsSession, aFullName, EFileRead) );
       
  1414 	CleanupClosePushL(file);
       
  1415 
       
  1416   	CBufFlat* buffer = CBufFlat::NewL(KGranularity);
       
  1417 	CleanupStack::PushL(buffer);
       
  1418 	
       
  1419 	TInt size = 0;
       
  1420 	file.Size(size);
       
  1421 	buffer->ResizeL(size);
       
  1422 	
       
  1423 	TPtr8 ptr = buffer->Ptr(0);
       
  1424 	User::LeaveIfError( file.Read(ptr) );
       
  1425 
       
  1426 	CleanupStack::Pop(buffer);
       
  1427 	CleanupStack::PopAndDestroy(&file);
       
  1428 	
       
  1429 	return buffer;
       
  1430     }
       
  1431 
       
  1432 
       
  1433 // -----------------------------------------------------------------------------
       
  1434 // C3DPatternParser::ParseDocumentL
       
  1435 // 
       
  1436 // -----------------------------------------------------------------------------
       
  1437 //
       
  1438 void C3DPatternParser::ParseDocumentL(const TDesC& aFullName)
       
  1439     {
       
  1440     iVelocityUsed = EFalse;
       
  1441     iDopplerUsed = EFalse;
       
  1442     
       
  1443     iPositionList.Reset();
       
  1444     iVelocityList.Reset();
       
  1445 
       
  1446     
       
  1447     CBufFlat* buf = ReadDocumentL(aFullName);
       
  1448     CleanupStack::PushL(buf);
       
  1449     TPtr8 ptr = buf->Ptr(0);
       
  1450     
       
  1451     iParser->ParseL(ptr);
       
  1452     
       
  1453     iParser->ParseEndL();
       
  1454     
       
  1455     ///Print();
       
  1456     
       
  1457     CleanupStack::PopAndDestroy(buf);
       
  1458     }
       
  1459 
       
  1460 
       
  1461 // -----------------------------------------------------------------------------
       
  1462 // C3DPatternParser::ParseDocumentL
       
  1463 // 
       
  1464 // -----------------------------------------------------------------------------
       
  1465 //
       
  1466 void C3DPatternParser::ParseDocumentL(TInt aPatternId)
       
  1467     {
       
  1468     TFileName name;
       
  1469     GetPatternFileNameL(name, aPatternId);
       
  1470     
       
  1471     ParseDocumentL(name);
       
  1472     }
       
  1473 
       
  1474 
       
  1475 // -----------------------------------------------------------------------------
       
  1476 // C3DPatternParser::GetPatternName
       
  1477 // 
       
  1478 // -----------------------------------------------------------------------------
       
  1479 //
       
  1480 void C3DPatternParser::GetPatternName(TDes& aText)
       
  1481     {
       
  1482     StrCopy(aText, iPatternName);
       
  1483     }
       
  1484 
       
  1485 
       
  1486 // -----------------------------------------------------------------------------
       
  1487 // C3DPatternParser::GetEchoName
       
  1488 // 
       
  1489 // -----------------------------------------------------------------------------
       
  1490 //
       
  1491 void C3DPatternParser::GetEchoName(TDes& aText)
       
  1492     {
       
  1493     StrCopy(aText, iEchoName);
       
  1494     }
       
  1495 
       
  1496 
       
  1497 // -----------------------------------------------------------------------------
       
  1498 // C3DPatternParser::GetEchoName
       
  1499 // 
       
  1500 // -----------------------------------------------------------------------------
       
  1501 //
       
  1502 TBool C3DPatternParser::DopplerEnabled()
       
  1503     {
       
  1504     return iDopplerUsed;
       
  1505     }
       
  1506 
       
  1507 
       
  1508 // -----------------------------------------------------------------------------
       
  1509 // C3DPatternParser::PositionCount
       
  1510 // 
       
  1511 // -----------------------------------------------------------------------------
       
  1512 //
       
  1513 TInt C3DPatternParser::PositionCount()
       
  1514     {
       
  1515     return iPositionList.Count();
       
  1516     }
       
  1517 
       
  1518 
       
  1519 // -----------------------------------------------------------------------------
       
  1520 // C3DPatternParser::Position
       
  1521 // 
       
  1522 // -----------------------------------------------------------------------------
       
  1523 //
       
  1524 T3DPatternData& C3DPatternParser::Position(TInt aIndex)
       
  1525     {
       
  1526     if (aIndex < 0 || aIndex >= iPositionList.Count())
       
  1527         {
       
  1528         Panic(KErrArgument);
       
  1529         }
       
  1530         
       
  1531     return iPositionList[aIndex];
       
  1532     }
       
  1533 
       
  1534 
       
  1535 // -----------------------------------------------------------------------------
       
  1536 // C3DPatternParser::Velocity
       
  1537 // 
       
  1538 // -----------------------------------------------------------------------------
       
  1539 //
       
  1540 T3DPatternData& C3DPatternParser::Velocity(TInt aIndex)
       
  1541     {
       
  1542     if (aIndex < 0 || aIndex >= iVelocityList.Count())
       
  1543         {
       
  1544         Panic(KErrArgument);
       
  1545         }
       
  1546         
       
  1547     return iVelocityList[aIndex];
       
  1548     }
       
  1549 
       
  1550 
       
  1551 // -----------------------------------------------------------------------------
       
  1552 // C3DPatternParser::AssertPosition
       
  1553 // 
       
  1554 // -----------------------------------------------------------------------------
       
  1555 //
       
  1556 void C3DPatternParser::AssertPosition(TInt aIndex, TInt aX, TInt aY, TInt aZ)
       
  1557     {
       
  1558     T3DPatternData d = Position(aIndex);
       
  1559     
       
  1560     if (d.iX != aX || d.iY != aY || d.iZ != aZ)
       
  1561         {
       
  1562         Panic(KErrArgument);
       
  1563         }
       
  1564     }
       
  1565 
       
  1566 
       
  1567 // -----------------------------------------------------------------------------
       
  1568 // C3DPatternParser::AssertVelocity
       
  1569 // 
       
  1570 // -----------------------------------------------------------------------------
       
  1571 //
       
  1572 void C3DPatternParser::AssertVelocity(TInt aIndex, TInt aX, TInt aY, TInt aZ)
       
  1573     {
       
  1574     T3DPatternData d = Velocity(aIndex);
       
  1575     
       
  1576     if (d.iX != aX || d.iY != aY || d.iZ != aZ)
       
  1577         {
       
  1578         Panic(KErrArgument);
       
  1579         }
       
  1580     }
       
  1581 
       
  1582 
       
  1583 // -----------------------------------------------------------------------------
       
  1584 // C3DPatternParser::AssertTime
       
  1585 // 
       
  1586 // -----------------------------------------------------------------------------
       
  1587 //
       
  1588 void C3DPatternParser::AssertTime(TInt aIndex, TInt aTime)
       
  1589     {
       
  1590     T3DPatternData d = Position(aIndex);
       
  1591     
       
  1592     if (d.iTime != aTime)
       
  1593         {
       
  1594         Panic(KErrArgument);
       
  1595         }
       
  1596     }
       
  1597 
       
  1598 
       
  1599 // -------------------------------------------------------------------------------
       
  1600 // C3DPatternParser::StrCopy
       
  1601 //
       
  1602 // String copy with lenght check.
       
  1603 // -------------------------------------------------------------------------------
       
  1604 //
       
  1605 void C3DPatternParser::StrCopy(TDes& aTarget, const TDesC8& aSource)
       
  1606     {
       
  1607 	TInt len = aTarget.MaxLength();
       
  1608     if(len < aSource.Length()) 
       
  1609 	    {
       
  1610 		aTarget.Copy(aSource.Left(len));
       
  1611 		return;
       
  1612 	    }
       
  1613 	aTarget.Copy(aSource);
       
  1614     }
       
  1615 
       
  1616 
       
  1617 // -------------------------------------------------------------------------------
       
  1618 // C3DPatternParser::StrCopy
       
  1619 //
       
  1620 // String copy with lenght check.
       
  1621 // -------------------------------------------------------------------------------
       
  1622 //
       
  1623 void C3DPatternParser::StrCopy(TDes& aTarget, const TDesC& aSource)
       
  1624     {
       
  1625 	TInt len = aTarget.MaxLength();
       
  1626     if(len < aSource.Length()) 
       
  1627 	    {
       
  1628 		aTarget.Copy(aSource.Left(len));
       
  1629 		return;
       
  1630 	    }
       
  1631 	aTarget.Copy(aSource);
       
  1632     }
       
  1633 
       
  1634 
       
  1635 // -------------------------------------------------------------------------------
       
  1636 // C3DPatternParser::StrToIntL
       
  1637 //
       
  1638 // -------------------------------------------------------------------------------
       
  1639 //
       
  1640 TInt C3DPatternParser::StrToIntL(const TDesC& aText)
       
  1641 	{
       
  1642 	TInt num = KErrNotFound;
       
  1643 	
       
  1644     TLex lex(aText);
       
  1645 
       
  1646     User::LeaveIfError( lex.Val(num) ); 
       
  1647 	return num;
       
  1648 	}
       
  1649 
       
  1650 // -----------------------------------------------------------------------------
       
  1651 // C3DPatternParser::Panic
       
  1652 //
       
  1653 // -----------------------------------------------------------------------------
       
  1654 //    
       
  1655 void C3DPatternParser::Panic(TInt aReason)
       
  1656     {
       
  1657 	_LIT(KPanicCategory,"C3DPatternParser");
       
  1658 	
       
  1659 	User::Panic(KPanicCategory, aReason); 
       
  1660     }
       
  1661 
       
  1662 
       
  1663 // -------------------------------------------------------------------------------
       
  1664 // C3DPatternParser::GetPatternFileNameL
       
  1665 //
       
  1666 // -------------------------------------------------------------------------------
       
  1667 //
       
  1668 void C3DPatternParser::GetPatternFileNameL(TDes& aText, TInt aPatternId)
       
  1669     {
       
  1670     _LIT( KFormatString, "%S%S%S%S");
       
  1671     _LIT( KPatternDir, "3DTones\\" );
       
  1672 
       
  1673     _LIT( KPatternCircle,     "1circular.xml" );
       
  1674     _LIT( KPatternFlyBy,      "2flyby.xml" );
       
  1675     _LIT( KPatternZigZag,     "3zigzag.xml" );
       
  1676     _LIT( KPatternRandomWalk, "4meander.xml" );
       
  1677     _LIT( KPatternChaos,      "5random.xml" );
       
  1678 
       
  1679     TBuf<KBufSize32> pattern;
       
  1680 
       
  1681     switch (aPatternId)
       
  1682         {
       
  1683         case EProfile3DEffectCircle:
       
  1684             {
       
  1685             pattern = KPatternCircle;
       
  1686             break;
       
  1687             }
       
  1688         case EProfile3DEffectFlyby:
       
  1689             {
       
  1690             pattern = KPatternFlyBy;
       
  1691             break;
       
  1692             }
       
  1693         case EProfile3DEffectZigZag:
       
  1694             {
       
  1695             pattern = KPatternZigZag;
       
  1696             break;
       
  1697             }
       
  1698         case EProfile3DEffectRandomWalk:
       
  1699             {
       
  1700             pattern = KPatternRandomWalk;
       
  1701             break;
       
  1702             }
       
  1703         case EProfile3DEffectChaos:
       
  1704             {
       
  1705             pattern = KPatternChaos;
       
  1706             break;
       
  1707             }
       
  1708         default:
       
  1709             {
       
  1710             User::Leave( KErrNotSupported );
       
  1711             break;
       
  1712             }
       
  1713         }
       
  1714         
       
  1715   	TDriveUnit drive(EDriveZ);
       
  1716 	TDriveName driveName = drive.Name();
       
  1717 	
       
  1718 	aText.Format(KFormatString, &driveName, &KDC_RESOURCE_FILES_DIR, &KPatternDir, &pattern);
       
  1719     }
       
  1720 
       
  1721 
       
  1722 // -------------------------------------------------------------------------------
       
  1723 // C3DPatternParser::ReadPositionAttributesL
       
  1724 //
       
  1725 // -------------------------------------------------------------------------------
       
  1726 //
       
  1727 void C3DPatternParser::ReadPositionAttributesL(const Xml::RAttributeArray& aAttributes)
       
  1728 	{
       
  1729     TInt count = aAttributes.Count();
       
  1730 	
       
  1731 	for (TUint i=0; i<count; ++i)
       
  1732 		{
       
  1733     	StrCopy(iAttributeName, aAttributes[i].Attribute().LocalName().DesC());
       
  1734 		StrCopy(iAttributeValue, aAttributes[i].Value().DesC());
       
  1735 
       
  1736 		if (iAttributeName.CompareC(KKXCoordinate) == 0)
       
  1737 			{
       
  1738 			iCurrentPosition.iX = StrToIntL(iAttributeValue);
       
  1739 			}
       
  1740 		else if (iAttributeName.CompareC(KKYCoordinate) == 0)
       
  1741 			{
       
  1742 			iCurrentPosition.iY = StrToIntL(iAttributeValue);
       
  1743 			}
       
  1744 		else if (iAttributeName.CompareC(KKZCoordinate) == 0)
       
  1745 			{
       
  1746 			iCurrentPosition.iZ = StrToIntL(iAttributeValue);
       
  1747 			}
       
  1748 		}
       
  1749 	}
       
  1750 
       
  1751 
       
  1752 // -------------------------------------------------------------------------------
       
  1753 // C3DPatternParser::ReadVelocityAttributesL
       
  1754 //
       
  1755 // -------------------------------------------------------------------------------
       
  1756 //
       
  1757 void C3DPatternParser::ReadVelocityAttributesL(const Xml::RAttributeArray& aAttributes)
       
  1758 	{
       
  1759     TInt count = aAttributes.Count();
       
  1760 	
       
  1761 	for (TUint i=0; i<count; ++i)
       
  1762 		{
       
  1763 		
       
  1764 		StrCopy(iAttributeName, aAttributes[i].Attribute().LocalName().DesC());
       
  1765 		StrCopy(iAttributeValue, aAttributes[i].Value().DesC());
       
  1766 
       
  1767 		if (iAttributeName.CompareC(KKXCoordinate) == 0)
       
  1768 			{
       
  1769 			iCurrentVelocity.iX = StrToIntL(iAttributeValue);
       
  1770 			}
       
  1771 		else if (iAttributeName.CompareC(KKYCoordinate) == 0)
       
  1772 			{
       
  1773 			iCurrentVelocity.iY = StrToIntL(iAttributeValue);
       
  1774 			}
       
  1775 		else if (iAttributeName.CompareC(KKZCoordinate) == 0)
       
  1776 			{
       
  1777 			iCurrentVelocity.iZ = StrToIntL(iAttributeValue);
       
  1778 			}
       
  1779 		}
       
  1780 		
       
  1781     iVelocityUsed = ETrue;
       
  1782 	}
       
  1783 
       
  1784 
       
  1785 // -------------------------------------------------------------------------------
       
  1786 // C3DPatternParser::ReadInitAttributesL
       
  1787 //
       
  1788 // -------------------------------------------------------------------------------
       
  1789 //
       
  1790 void C3DPatternParser::ReadInitAttributesL(const Xml::RAttributeArray& aAttributes)
       
  1791 	{
       
  1792     TInt count = aAttributes.Count();
       
  1793 	for ( TUint i = 0; i < count; ++i )
       
  1794 		{
       
  1795 		StrCopy(iAttributeName, aAttributes[i].Attribute().LocalName().DesC());
       
  1796 		StrCopy(iAttributeValue, aAttributes[i].Value().DesC());
       
  1797 		
       
  1798 		if (iAttributeName.CompareC(KKPatternName) == 0)
       
  1799 			{
       
  1800 			StrCopy(iPatternName, iAttributeValue);
       
  1801 			}
       
  1802 		else if (iAttributeName.CompareC(KKEchoName) == 0)
       
  1803 			{
       
  1804 			StrCopy(iEchoName, iAttributeValue);
       
  1805 			}
       
  1806 		else if (iAttributeName.CompareC(KKDoppler) == 0)
       
  1807 			{
       
  1808 			if (iAttributeValue.CompareC(KKBooleanTrue) == 0)
       
  1809 				{
       
  1810 				iDopplerUsed = ETrue;
       
  1811 				}
       
  1812 		    else
       
  1813 		        {
       
  1814 		        iDopplerUsed = EFalse;
       
  1815 		        }
       
  1816 			}
       
  1817 		}
       
  1818 	}
       
  1819 
       
  1820 
       
  1821 // -------------------------------------------------------------------------------
       
  1822 // C3DPatternParser::ReadUpdateAttributesL
       
  1823 //
       
  1824 // -------------------------------------------------------------------------------
       
  1825 //
       
  1826 void C3DPatternParser::ReadUpdateAttributesL( const Xml::RAttributeArray& aAttributes )
       
  1827 	{
       
  1828     TInt count = aAttributes.Count();
       
  1829 	for ( TUint i = 0; i < aAttributes.Count(); ++i )
       
  1830 		{
       
  1831 		StrCopy(iAttributeName, aAttributes[i].Attribute().LocalName().DesC());
       
  1832 		StrCopy(iAttributeValue, aAttributes[i].Value().DesC());
       
  1833 
       
  1834     	if (iAttributeName.CompareC(KKDTime) == 0)
       
  1835 			{
       
  1836 			iCurrentPosition.iTime = StrToIntL(iAttributeValue);
       
  1837 			}
       
  1838 		}
       
  1839 	}
       
  1840 
       
  1841 
       
  1842 // -------------------------------------------------------------------------------
       
  1843 // C3DPatternParser::Print
       
  1844 //
       
  1845 // -------------------------------------------------------------------------------
       
  1846 //
       
  1847 void C3DPatternParser::Print()
       
  1848 	{
       
  1849 	FLOG( _L("----- start pattern data -----") );
       
  1850 	
       
  1851 	TBuf<KBufSize128> buf; TBuf<KBufSize128> buf2;
       
  1852 	
       
  1853 	GetPatternName(buf);
       
  1854 	GetEchoName(buf2);
       
  1855 	FLOG( _L("pattern: '%S'  echo: '%S' doppler: %d"), &buf, &buf2, iDopplerUsed);
       
  1856 	
       
  1857 	FLOG( _L("init position and velocity:") );
       
  1858 	PrintCoordinates(iInitPosition, EFalse);
       
  1859 	PrintCoordinates(iInitVelocity, ETrue);
       
  1860 	
       
  1861 	FLOG( _L("positions and velocities:") );
       
  1862 	
       
  1863 	TInt count = PositionCount();
       
  1864 	for (TInt i=0; i<count; i++)
       
  1865 	    {
       
  1866 	    T3DPatternData data = Position(i);
       
  1867 	    PrintCoordinates(data, EFalse);
       
  1868 	    
       
  1869 	    if (iVelocityUsed)
       
  1870 	        {
       
  1871     	    T3DPatternData data = Velocity(i);
       
  1872 	        PrintCoordinates(data, ETrue);
       
  1873 	        }
       
  1874 	    }
       
  1875 	    
       
  1876 	    
       
  1877 	FLOG( _L("----- end pattern data -----") );
       
  1878 	}
       
  1879 
       
  1880 
       
  1881 // -------------------------------------------------------------------------------
       
  1882 // C3DPatternParser::PrintCoordinates
       
  1883 //
       
  1884 // -------------------------------------------------------------------------------
       
  1885 //
       
  1886 void C3DPatternParser::PrintCoordinates(T3DPatternData& aData, TBool aVelocity)
       
  1887 	{
       
  1888 	if (aVelocity)
       
  1889 	    {
       
  1890 	    FLOG( _L("velocity: x=%5d   y=%5d   z=%5d"), aData.iX, aData.iY, aData.iZ);
       
  1891 	    }
       
  1892     else
       
  1893         {
       
  1894         FLOG( _L("position: x=%5d   y=%5d   z=%5d   time=%4d"), aData.iX, aData.iY, aData.iZ, aData.iTime);
       
  1895         }	
       
  1896 	}
       
  1897 
       
  1898 
       
  1899 // -----------------------------------------------------------------------------
       
  1900 // C3DPatternParser::OnStartDocumentL  (from MContentHandler)
       
  1901 // 
       
  1902 // -----------------------------------------------------------------------------
       
  1903 //
       
  1904 void C3DPatternParser::OnStartDocumentL(const Xml::RDocumentParameters& /*aDocParam*/, TInt /*aErrorCode*/)
       
  1905     {
       
  1906     }
       
  1907 
       
  1908 
       
  1909 // -----------------------------------------------------------------------------
       
  1910 // C3DPatternParser::OnEndDocumentL  (from MContentHandler)
       
  1911 // 
       
  1912 // -----------------------------------------------------------------------------
       
  1913 //
       
  1914 void C3DPatternParser::OnEndDocumentL(TInt /*aErrorCode*/)
       
  1915     {
       
  1916     }
       
  1917     
       
  1918     
       
  1919 // -----------------------------------------------------------------------------
       
  1920 // C3DPatternParser::OnStartElementL  (from MContentHandler)
       
  1921 // 
       
  1922 // -----------------------------------------------------------------------------
       
  1923 //
       
  1924 void C3DPatternParser::OnStartElementL(const Xml::RTagInfo& aElement, 
       
  1925                                  const Xml::RAttributeArray& aAttributes, 
       
  1926 							     TInt /*aErrorCode*/)
       
  1927     {
       
  1928     StrCopy(iElementName, aElement.LocalName().DesC());
       
  1929     
       
  1930     if (iElementName.Compare(KKInitElement) == 0)
       
  1931         {
       
  1932         ReadInitAttributesL(aAttributes);
       
  1933         }
       
  1934     else if (iElementName.Compare(KKUpdateElement) == 0)
       
  1935         {
       
  1936         ReadUpdateAttributesL(aAttributes);
       
  1937         }
       
  1938     else if (iElementName.Compare(KKPositionElement) == 0)
       
  1939         {
       
  1940         ReadPositionAttributesL(aAttributes);
       
  1941         }
       
  1942     else if (iElementName.Compare(KKVelocityElement) == 0)
       
  1943         {
       
  1944         ReadVelocityAttributesL(aAttributes);
       
  1945         }
       
  1946     }
       
  1947     
       
  1948     
       
  1949 // -----------------------------------------------------------------------------
       
  1950 // C3DPatternParser::OnEndElementL  (from MContentHandler)
       
  1951 // 
       
  1952 // -----------------------------------------------------------------------------
       
  1953 //
       
  1954 void C3DPatternParser::OnEndElementL(const Xml::RTagInfo& aElement, TInt /*aErrorCode*/)
       
  1955     {
       
  1956     StrCopy(iElementName, aElement.LocalName().DesC());
       
  1957     
       
  1958     if (iElementName.Compare(KKUpdateElement) == 0)
       
  1959         {
       
  1960         iPositionList.AppendL(iCurrentPosition);
       
  1961         if (iVelocityUsed)
       
  1962             {
       
  1963             iVelocityList.AppendL(iCurrentVelocity);
       
  1964             }
       
  1965         }
       
  1966         
       
  1967     if (iElementName.Compare(KKInitElement) == 0)
       
  1968         {
       
  1969         iInitPosition = iCurrentPosition;
       
  1970         if (iVelocityUsed)
       
  1971             {
       
  1972             iInitVelocity = iCurrentVelocity;
       
  1973             }
       
  1974         }
       
  1975     }
       
  1976     
       
  1977     
       
  1978 // -----------------------------------------------------------------------------
       
  1979 // C3DPatternParser::OnContentL  (from MContentHandler)
       
  1980 // 
       
  1981 // -----------------------------------------------------------------------------
       
  1982 //
       
  1983 void C3DPatternParser::OnContentL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/)
       
  1984     {
       
  1985     }
       
  1986     
       
  1987     
       
  1988 // -----------------------------------------------------------------------------
       
  1989 // C3DPatternParser::OnStartPrefixMappingL  (from MContentHandler)
       
  1990 // 
       
  1991 // -----------------------------------------------------------------------------
       
  1992 //
       
  1993 void C3DPatternParser::OnStartPrefixMappingL(const RString& /*aPrefix*/, 
       
  1994                                              const RString& /*aUri*/, 
       
  1995 				     				         TInt /*aErrorCode*/)
       
  1996     {
       
  1997     }
       
  1998     
       
  1999     
       
  2000 // -----------------------------------------------------------------------------
       
  2001 // C3DPatternParser::OnEndPrefixMappingL  (from MContentHandler)
       
  2002 // 
       
  2003 // -----------------------------------------------------------------------------
       
  2004 //
       
  2005 void C3DPatternParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/)
       
  2006     {
       
  2007     }
       
  2008     
       
  2009     
       
  2010 // -----------------------------------------------------------------------------
       
  2011 // C3DPatternParser::OnIgnorableWhiteSpaceL  (from MContentHandler)
       
  2012 // 
       
  2013 // -----------------------------------------------------------------------------
       
  2014 //
       
  2015 void C3DPatternParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/)
       
  2016     {
       
  2017     }
       
  2018     
       
  2019     
       
  2020 // -----------------------------------------------------------------------------
       
  2021 // C3DPatternParser::OnSkippedEntityL  (from MContentHandler)
       
  2022 // 
       
  2023 // -----------------------------------------------------------------------------
       
  2024 //
       
  2025 void C3DPatternParser::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/)
       
  2026     {
       
  2027     }
       
  2028     
       
  2029     
       
  2030 // -----------------------------------------------------------------------------
       
  2031 // C3DPatternParser::OnProcessingInstructionL  (from MContentHandler)
       
  2032 // 
       
  2033 // -----------------------------------------------------------------------------
       
  2034 //
       
  2035 void C3DPatternParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, 
       
  2036                                           const TDesC8& /*aData*/, TInt /*aErrorCode*/)
       
  2037     {
       
  2038     }
       
  2039     
       
  2040     
       
  2041 // -----------------------------------------------------------------------------
       
  2042 // C3DPatternParser::OnError  (from MContentHandler)
       
  2043 // 
       
  2044 // -----------------------------------------------------------------------------
       
  2045 //
       
  2046 void C3DPatternParser::OnError(TInt aErrorCode)
       
  2047     {
       
  2048     if ( aErrorCode != KErrNone )
       
  2049         {
       
  2050         FLOG( _L("### C3DPatternParser::OnError (%d) ###"), aErrorCode);
       
  2051         }
       
  2052     }
       
  2053     
       
  2054 
       
  2055 // -----------------------------------------------------------------------------
       
  2056 // C3DPatternParser::GetExtendedInterface  (from MContentHandler)
       
  2057 // 
       
  2058 // -----------------------------------------------------------------------------
       
  2059 //
       
  2060 TAny* C3DPatternParser::GetExtendedInterface(const TInt32 /*aUid*/)
       
  2061     {
       
  2062     return 0;
       
  2063     }
       
  2064     
       
  2065     
       
  2066 ////////////////////////////////////// END TEST CODE ////////////////////////////
       
  2067 
       
  2068 
       
  2069 
       
  2070 
       
  2071     
       
  2072 
       
  2073 // End of File