profilesservices/RingingTone3DPlugin/inc/C3DAudioXMLParser.h
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 #ifndef C3DAUDIOXMLPARSER_H
       
    20 #define C3DAUDIOXMLPARSER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <eikenv.h>
       
    24 #include "C3DAudioPattern.h"	// C3DAudioPatter, T3DScriptPosition
       
    25 #include <xml/contenthandler.h>	// Xml::MContentHandler
       
    26 #include <xml/parser.h>			// Xml::CParser
       
    27 
       
    28 #include <e32property.h>	    // RProperty
       
    29 
       
    30 
       
    31 //CONSTANTS
       
    32 
       
    33 // Maximum length for names of element and attribute and for value of attribute.
       
    34 const TUint KMaxDataLength = 20;
       
    35 const TUint KBufSize32 = 32;
       
    36 
       
    37 
       
    38 // DATA TYPES
       
    39 
       
    40 // Enumeration to use in determining the last tag.
       
    41 enum TLastTag 
       
    42 	{
       
    43 	EInitialization = 0,
       
    44 	EUpdate
       
    45 	};
       
    46 	
       
    47 	
       
    48 // Identifiers for reverberation presets. Used in mapping.
       
    49 enum TReverbPresets
       
    50 	{
       
    51 	EReverbNotEnabled = 0,
       
    52 	EReverbPresetOne = 14,		// Livingroom
       
    53 	EReverbPresetTwo = 5,		// Cave
       
    54     EReverbPresetThree = 26,	// Stone Corridor
       
    55     EReverbPresetFour = 8,		// Forest
       
    56     EReverbPresetFive = 24,		// Sewerpipe
       
    57     EReverbPresetSix = 28		// Underwater
       
    58 	};
       
    59 	
       
    60 
       
    61 // FORWARD DECLARATIONS
       
    62 
       
    63 class C3DPatternPS;
       
    64 	
       
    65 
       
    66 // CLASS DECLARATION
       
    67 
       
    68 /**
       
    69 * XML-parser used to parse motion patterns.
       
    70 *
       
    71 * @lib RingingTone3DPlugin.dll
       
    72 * @since 5.0
       
    73 */ 	
       
    74 NONSHARABLE_CLASS (C3DAudioXMLParser) : public CBase, public Xml::MContentHandler
       
    75 	{
       
    76     public:
       
    77     
       
    78     enum TPatternAttributeKeys
       
    79         {
       
    80         EKeyPatternId = 1,
       
    81         EKeyDopplerUsed = 2,
       
    82         EKeyVelocity = 3
       
    83         };
       
    84 	
       
    85 	public:
       
    86 		
       
    87 	   /**
       
    88         * Two-phased constructor.
       
    89         */
       
    90 		static C3DAudioXMLParser* NewL();
       
    91 		
       
    92 	   /**
       
    93         * Two-phased constructor.
       
    94         */
       
    95 		static C3DAudioXMLParser* NewLC();
       
    96 		
       
    97 	   /**
       
    98         * Destructor.
       
    99         */
       
   100 		virtual ~C3DAudioXMLParser();
       
   101 		
       
   102 	private:
       
   103 
       
   104        /**
       
   105         * C++ default constructor.
       
   106         */
       
   107         C3DAudioXMLParser();
       
   108         
       
   109        /**
       
   110         * By default Symbian 2nd phase constructor is private.
       
   111         */
       
   112         void ConstructL();
       
   113 		
       
   114 		
       
   115 	public:
       
   116 		
       
   117        /**
       
   118         * Parses the motion pattern from XML-file.
       
   119         * @param aPatternNum Motion pattern to be parsed.
       
   120         */
       
   121 		void ParseL( TInt aPatternId );
       
   122 
       
   123        /**
       
   124         * Parses the motion pattern from XML-file.
       
   125         * @param aPatternNum Motion pattern to be parsed.
       
   126         */
       
   127 		void ParseL( const TDesC& aFileName );
       
   128 		
       
   129 	   /**
       
   130         * Returns single pattern attribute.
       
   131         * @param Pattern attribute key.
       
   132         * @return Pattern attribute value.
       
   133         */
       
   134 		TInt Attribute( TInt aKey );
       
   135 		
       
   136 		const T3DPosition& PositionL( TInt aIndex );
       
   137 		const T3DVelocity& VelocityL( TInt aIndex );
       
   138 		const TInt& TimeL( TInt aIndex );
       
   139 		TInt CountL();
       
   140 		
       
   141     private:
       
   142 	   /**
       
   143         * Reads 3D ringing tone pattern data from cache (PubSub)
       
   144         * @param aPatternId Pattern id.
       
   145         */
       
   146         TBool ReadFromPatternCacheL( TInt aPatternId );
       
   147 
       
   148 	   /**
       
   149         * Writes 3D ringing tone pattern data into cache (PubSub)
       
   150         * @param aPatternId Pattern id.
       
   151         */
       
   152         void WriteToPatternCacheL( TInt aPatternId );
       
   153         
       
   154 #ifdef _DEBUG
       
   155     public:        
       
   156         void AssertParseDataL( TInt aPatternId );
       
   157         static void GetPatternString(TDes& aText, TInt aPattern);
       
   158         static void FlogPatternsL(TInt aOldPattern, TInt aNewPattern);
       
   159         static void FlogPatternL(TInt aPattern);
       
   160         static void FlogPubSubL(TInt aEcho);
       
   161         static void GetEchoString(TDes& aText, TInt aEcho);
       
   162 #endif        
       
   163 
       
   164 
       
   165 	public: // from MContentHandler
       
   166 	
       
   167 	   /**
       
   168         * From MContentHandler This method is a callback to indicate the start of the document. 
       
   169         * @param aDocParam Specifies the various parameters of the document.
       
   170         * @param aErrorCode The error code.
       
   171         */
       
   172 		void OnStartDocumentL( const Xml::RDocumentParameters& aDocParam, TInt aErrorCode );
       
   173 		
       
   174        /**
       
   175         * This method is a callback to indicate the end of the document. 
       
   176         * @param aErrorCode The error code.
       
   177         */
       
   178 		void OnEndDocumentL( TInt aErrorCode );
       
   179 		
       
   180 	   /**
       
   181         * This method is a callback to indicate an element has been parsed. 
       
   182         * @param aElement Handle to the element's details.
       
   183         * @param aAttributes Attributes for the element. 
       
   184         * @param aErrorCode The error code.
       
   185         */
       
   186 		void OnStartElementL( const Xml::RTagInfo& aElement, const Xml::RAttributeArray& aAttributes, TInt aErrorCode );
       
   187 		
       
   188 	   /**
       
   189         * This method is a callback to indicate the end of the element has been reached. 
       
   190         * @param aElement Handle to the element's details.
       
   191         * @param aErrorCode The error code.
       
   192         */
       
   193 		void OnEndElementL( const Xml::RTagInfo& aElement, TInt aErrorCode );
       
   194 		
       
   195        /**
       
   196         * This method is a callback that sends the content of the element.
       
   197         * @param aBytes Raw content data for the element
       
   198         * @param aErrorCode The error code.
       
   199         */
       
   200 		void OnContentL( const TDesC8& aBytes, TInt aErrorCode );
       
   201 	
       
   202 	   /**
       
   203         * This method is a notification of the beginning of the scope of a prefix-URI Namespace mapping.
       
   204         * @param aPrefix Namespace prefix being declared. 
       
   205         * @param aUri Namespace URI the prefix is mapped to. 
       
   206         * @param aErrorCode The error code.
       
   207         */
       
   208 		void OnStartPrefixMappingL( const RString& aPrefix, const RString& aUri, TInt aErrorCode );
       
   209 		
       
   210 	   /**
       
   211         * This method is a notification of the end of the scope of a prefix-URI mapping.
       
   212         * @param aPrefix Namespace prefix that was mapped. 
       
   213         * @param aErrorCode The error code.
       
   214         */
       
   215 		void OnEndPrefixMappingL( const RString& aPrefix, TInt aErrorCode );
       
   216 		
       
   217 	   /**
       
   218         * This method is a notification of ignorable whitespace in element content. 
       
   219         * @since Series ?XX ?SeriesXX_version
       
   220         * @param aBytes Ignored bytes from the document being parsed. 
       
   221         * @param aErrorCode The error code.
       
   222         */
       
   223 		void OnIgnorableWhiteSpaceL( const TDesC8& aBytes, TInt aErrorCode );
       
   224 		
       
   225 	   /**
       
   226         * This method is a notification of a skipped entity.
       
   227         * @param aName Name of the skipped entity.
       
   228         * @param aErrorCode The error code.
       
   229         */
       
   230 		void OnSkippedEntityL( const RString& aName, TInt aErrorCode );
       
   231 		
       
   232        /**
       
   233         * This method is a receive notification of a processing instruction. 
       
   234         * @param aTarget Processing instruction target. 
       
   235         * @param aData Processing instruction data. If empty none was supplied.
       
   236         * @param aErrorCode The error code.
       
   237         */
       
   238 		void OnProcessingInstructionL( const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode );
       
   239 		
       
   240        /**
       
   241         * This method indicates an error has occurred.
       
   242         * @param aErrorCode The error code.
       
   243         */
       
   244 		void OnError( TInt aErrorCode );
       
   245 	
       
   246 	   /**
       
   247         * This method obtains the interface matching the specified uid. 
       
   248         * @param aUid UID identifying the required interface. 
       
   249         */
       
   250 		TAny* GetExtendedInterface( const TInt32 aUid );
       
   251 		
       
   252 		
       
   253 	private:
       
   254 		
       
   255 	   /**
       
   256         * Processes the attributes of initialization-element.
       
   257         * @param aAttributes Array of attributes.
       
   258         */	
       
   259 		void ProcessInitAttributesL( const Xml::RAttributeArray& aAttributes );
       
   260 		
       
   261 	   /**
       
   262 		* Processes the attributes of loop-element.
       
   263         * @param aAttributes Array of attributes.
       
   264         */	
       
   265 		void ProcessLoopAttributesL( const Xml::RAttributeArray& aAttributes );
       
   266 		
       
   267 	   /**
       
   268 		* Processes the attributes of position-element.
       
   269         * @param aAttributes Array of attributes.
       
   270         */
       
   271 		void ProcessPositionAttributesL( const Xml::RAttributeArray& aAttributes );
       
   272 		
       
   273 	   /**
       
   274 		* Processes the attributes of update-element.
       
   275         * @param aAttributes Array of attributes.
       
   276         */
       
   277 		void ProcessUpdateAttributesL( const Xml::RAttributeArray& aAttributes );
       
   278 		
       
   279 	   /**
       
   280 		* Processes the attributes of velocity-element.
       
   281         * @param aAttributes Array of attributes.
       
   282         */
       
   283 		void ProcessVelocityAttributesL( const Xml::RAttributeArray& aAttributes );
       
   284         
       
   285     private:
       
   286 
       
   287 	   /**
       
   288 		* String copy with length check.
       
   289         * @param aTarget.
       
   290         * @param aSource.
       
   291         */
       
   292         void CopyL( TDes8& aTarget, const TDesC8& aSource );
       
   293         
       
   294 	   /**
       
   295         * Panics plugin dll.
       
   296         * @param aReason Panic code.
       
   297         */		        
       
   298         void Panic(TInt aReason);
       
   299         
       
   300         void GetPatternFullPathL(TDes& aText, TInt aPatternId);
       
   301         CBufFlat* ReadPatternFileL( const TDesC& aFullName );
       
   302         CBufFlat* ReadPatternFileL( TInt aPatternId );
       
   303         
       
   304         
       
   305 	private:	// Data
       
   306 	
       
   307 		// Xml::CParser
       
   308 		Xml::CParser* iParser;
       
   309 		
       
   310 		// file server session
       
   311 		RFs iFsSession;
       
   312 		
       
   313 		// Parsed pattern
       
   314 		C3DAudioPattern* iParsedPattern;  
       
   315 		
       
   316 		// element name
       
   317 		TBuf8<KMaxDataLength> iElementName;
       
   318 		
       
   319 		// attribute name
       
   320 		TBuf8<KMaxDataLength> iAttributeName;
       
   321 		
       
   322 		// attribute value
       
   323 		TBuf8<KMaxDataLength> iAttributeValue;
       
   324 			
       
   325 		// Currently parsed pattern update.
       
   326 		T3DScriptUpdate iCurrentUpdate;
       
   327 		
       
   328 		// Last tag occurred.
       
   329 		TLastTag iLastTag;
       
   330 		
       
   331 		// 3DTone file name and path
       
   332 		TFileName iFullPath;
       
   333 		
       
   334 		// Pattern id
       
   335 		TInt iPatternId;
       
   336 	};
       
   337 
       
   338 
       
   339 
       
   340 /**
       
   341 * C3DPatternPS is used for storing 3D pattern data in
       
   342 * Public and Subcribe. Max pattern size is 65536 bytes.
       
   343 *
       
   344 * @lib RingingTone3DPlugin.dll
       
   345 * @since 5.0
       
   346 */ 	
       
   347 NONSHARABLE_CLASS (C3DPatternPS) : public CBase
       
   348 	{
       
   349     public:
       
   350     
       
   351     enum TPatternStoreKeys
       
   352         {
       
   353         EKeyPatternId = 1,
       
   354         EKeyDopplerUsed = 2,
       
   355         EKeyVelocity = 3,
       
   356         EKeyDataSize = 4,
       
   357         EKeyPatternData = 5
       
   358         };
       
   359 	
       
   360 	public:
       
   361 		static C3DPatternPS* NewLC( TInt aStoreId );
       
   362 		virtual ~C3DPatternPS();
       
   363 		
       
   364 	private:
       
   365         C3DPatternPS( TInt aStoreId );
       
   366         void ConstructL();
       
   367 		
       
   368 	public:
       
   369 	    void SetIntL( TInt aKey, TInt aValue );
       
   370 	    TInt IntL( TInt aKey );
       
   371 	    
       
   372 	    CBufFlat* DataLC();
       
   373 		void GetDataL( TDes8& aData );
       
   374 		void SetDataL( const TDesC8& aData );
       
   375 		
       
   376 		void TestL();
       
   377 
       
   378 	private:
       
   379 	    TBool DefineKeyL( TInt aKeyId, TInt aKeyType );
       
   380         
       
   381 	private:
       
   382 	    RProperty iProperty;
       
   383 	    TUid iStoreUid;
       
   384 	};
       
   385 
       
   386 
       
   387 
       
   388 ////////////////////////////////////// START TEST CODE //////////////////////////
       
   389 
       
   390 #include <eikenv.h>
       
   391 
       
   392 const TInt KBufSize128 = 128;
       
   393 const TInt KBufSize64 = 64;
       
   394 
       
   395 
       
   396 class T3DPatternData
       
   397     {
       
   398     public:
       
   399         TInt iTime;
       
   400         TInt iX;
       
   401         TInt iY;
       
   402         TInt iZ;
       
   403     };
       
   404 
       
   405 
       
   406 /**
       
   407 * C3DPatternParser
       
   408 *
       
   409 * Used to parse xml files.
       
   410 */
       
   411 NONSHARABLE_CLASS (C3DPatternParser) : public CBase, public Xml::MContentHandler 
       
   412     {
       
   413     public:
       
   414         static C3DPatternParser* NewL();
       
   415         virtual ~C3DPatternParser();
       
   416 
       
   417     private:
       
   418 	    C3DPatternParser();
       
   419         void ConstructL();
       
   420         
       
   421     public:
       
   422         void ParseDocumentL(const TDesC& aFullName);
       
   423         void ParseDocumentL(TInt aPatternId);
       
   424         TInt PositionCount();
       
   425        	T3DPatternData& Position(TInt aIndex);
       
   426        	T3DPatternData& Velocity(TInt aIndex);
       
   427         void GetPatternName(TDes& aText);
       
   428         void GetEchoName(TDes& aText);
       
   429         TBool DopplerEnabled();
       
   430         
       
   431         void AssertPosition(TInt aIndex, TInt aX, TInt aY, TInt aZ);
       
   432         void AssertVelocity(TInt aIndex, TInt aX, TInt aY, TInt aZ);
       
   433         void AssertTime(TInt aIndex, TInt aTime);
       
   434 
       
   435         
       
   436         
       
   437     private:
       
   438         void Print();
       
   439         void PrintCoordinates(T3DPatternData& aData, TBool aVelocity);
       
   440         
       
   441     
       
   442     private: // from MContentHandler
       
   443     
       
   444         void OnStartDocumentL(const Xml::RDocumentParameters& aDocParam, TInt aErrorCode);
       
   445         void OnEndDocumentL(TInt aErrorCode);
       
   446         void OnStartElementL(const Xml::RTagInfo& aElement, 
       
   447                              const Xml::RAttributeArray& aAttributes, 
       
   448 							 TInt aErrorCode);
       
   449 		void OnEndElementL(const Xml::RTagInfo& aElement, TInt aErrorCode);
       
   450 		void OnContentL(const TDesC8& aBytes, TInt aErrorCode);
       
   451 		void OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, 
       
   452 								   TInt aErrorCode);
       
   453 		void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
       
   454 		void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode);
       
   455 		void OnSkippedEntityL(const RString& aName, TInt aErrorCode);
       
   456 		void OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, 
       
   457 		    						  TInt aErrorCode);
       
   458         void OnError(TInt aErrorCode);
       
   459         TAny* GetExtendedInterface(const TInt32 aUid);
       
   460         
       
   461     private:
       
   462         CBufFlat* ReadDocumentL(const TDesC& aFullName);
       
   463         void ReadPositionAttributesL(const Xml::RAttributeArray& aAttributes);
       
   464         void ReadVelocityAttributesL(const Xml::RAttributeArray& aAttributes);
       
   465         void ReadInitAttributesL(const Xml::RAttributeArray& aAttributes);
       
   466         void ReadUpdateAttributesL(const Xml::RAttributeArray& aAttributes);
       
   467         
       
   468     private:
       
   469         void StrCopy(TDes& aTarget, const TDesC8& aSource);
       
   470         void StrCopy(TDes& aTarget, const TDesC& aSource);
       
   471         TInt StrToIntL(const TDesC& aText);
       
   472         void Panic(TInt aReason);
       
   473         void GetPatternFileNameL(TDes& aText, TInt aPatternId);
       
   474         
       
   475     private:
       
   476         
       
   477 		// Xml parser
       
   478 		Xml::CParser* iParser;
       
   479 		
       
   480 		// file server session
       
   481 		RFs iFsSession;
       
   482 		
       
   483 		TBuf<KBufSize64> iElementName;
       
   484 		TBuf<KBufSize64> iAttributeName;
       
   485 		TBuf<KBufSize64> iAttributeValue;
       
   486 		TBuf<KBufSize64> iEchoName;
       
   487 		TBuf<KBufSize64> iPatternName;
       
   488 		
       
   489 		TBool iDopplerUsed;
       
   490 		TBool iVelocityUsed;
       
   491 		
       
   492 		T3DPatternData iCurrentPosition;
       
   493 		T3DPatternData iCurrentVelocity;
       
   494 		
       
   495 		T3DPatternData iInitPosition;
       
   496 		T3DPatternData iInitVelocity;
       
   497 
       
   498 		
       
   499 		
       
   500 		// list for parsed 3d pattern position coordinates
       
   501 		RArray<T3DPatternData> iPositionList;
       
   502 		
       
   503 		// list for parsed 3d pattern velocity coordinates
       
   504 		RArray<T3DPatternData> iVelocityList;
       
   505     };
       
   506 
       
   507 ////////////////////////////////////// END TEST CODE ////////////////////////////
       
   508 
       
   509 
       
   510 #endif	// C3DAUDIOXMLPARSER_H
       
   511 
       
   512 // End of File