syncmlfw/common/alertqueue/inc/NSmlAlertQueue.h
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002-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: SyncML alert parser and message handler.   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __NSMLALERTQUEUE_H__
       
    20 #define __NSMLALERTQUEUE_H__
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32std.h>
       
    24 #include <SyncMLDef.h>
       
    25 #include <SyncMLHistory.h>
       
    26 #include <SyncMLAlertInfo.h>
       
    27 #include <utf.h>
       
    28 
       
    29 #include <nsmlunicodeconverter.h>
       
    30 #include "nsmldssettings.h"
       
    31 #include "nsmldmsettings.h"
       
    32 #include "NSmlHistoryArray.h"
       
    33 
       
    34 #include "WBXMLSyncMLParser.h"
       
    35 #include "WBXMLParser.h"
       
    36 #include "WBXMLParserError.h"
       
    37 #include "smlmetinfdtd.h"
       
    38 #include "NSmlURI.h"
       
    39 #include "NSmlAlertQueueDefs.h"
       
    40 
       
    41 
       
    42 
       
    43 //container for profile related alert info
       
    44 class CNSmlAlertInfo : public CBase
       
    45 	{
       
    46 	public:
       
    47 		~CNSmlAlertInfo();
       
    48 		TInt iProfileId;
       
    49 		TInt iMatchCount;
       
    50 		TInt iIAPId;
       
    51 		RPointerArray<TNSmlContentTypeInfo> iTaskInfo;
       
    52 	};
       
    53 	
       
    54 //Base class for server alert parsers
       
    55 class CNSmlMessageParserBase : public CBase
       
    56 	{
       
    57 	public:
       
    58 	
       
    59 		/**
       
    60 		* Constuctor
       
    61         * CNSmlMessageParserBase( CSmlAlertInfo& aAlertInfo,
       
    62         * CSyncMLHistoryPushMsg& aHistoryInfo )
       
    63         * @param aAlertInfo - reference to CSmlAlertInfo : container for hold
       
    64         *                       parsed data
       
    65         * @param aHistoryInfo - reference to CSyncMLHistoryPushMsg : container
       
    66         *                       for hold parsed data
       
    67 		* @return - 
       
    68         */
       
    69 		CNSmlMessageParserBase( CSmlAlertInfo& aAlertInfo, 
       
    70 		    CSyncMLHistoryPushMsg& aHistoryInfo );
       
    71 		
       
    72 		/**
       
    73 		* Destructor
       
    74         * ~CNSmlMessageParserBase()
       
    75         * @param -
       
    76 		* @return - 
       
    77         */
       
    78 		virtual ~CNSmlMessageParserBase();
       
    79 		
       
    80 		/**
       
    81 		* Pure virtual method to implement the parsing
       
    82         * void ParseMessageL()
       
    83         * @param -
       
    84         * @return - 
       
    85         */
       
    86 		virtual void ParseMessageL() = 0;
       
    87 		
       
    88 		/**
       
    89 		* Pure virtual method to target a correct profile
       
    90         * void SearchProfileL(TDesC8& aServerUri)
       
    91         * @param aServerUri - Server Id identifier
       
    92         * @return - 
       
    93         */
       
    94 		virtual void SearchProfileL( TDesC8& aServerUri ) = 0;
       
    95 		
       
    96 		/**
       
    97 		* Method to target correct content type
       
    98         * void MatchContentTypeL( TDesC8& aPath )
       
    99         * @param aPath - Path to local database
       
   100         * @return - 
       
   101         */
       
   102 		virtual void MatchContentTypeL( TDesC8& /*aPath*/ ) {	}
       
   103 		
       
   104 		/**
       
   105 		* Returns a pointer to HBufC8 buffer
       
   106         * TPtr8& Message()
       
   107         * @param -
       
   108         * @return - Reference to HBufC8 buffer 
       
   109         */
       
   110 		TPtr8& Message();
       
   111 		
       
   112 		/**
       
   113 		* Allocates buffer of specified size
       
   114         * void CreateBufferL( TInt aSize )
       
   115         * @param aSize - size of buffer to hold the SAN message
       
   116         * @return -
       
   117         */
       
   118 		void CreateBufferL( TInt aSize );
       
   119 		
       
   120 		/**
       
   121 		* Resolves the profile if more than one match is found
       
   122         * void ResolveProfileL( TInt aContentCount )
       
   123         * @param aContentCount - Number of alerted contents
       
   124         * @return - 
       
   125         */
       
   126 		virtual void ResolveProfileL( TInt /*aContentCount*/ ) { }
       
   127 			
       
   128 		/**
       
   129 		* Leaves with KErrCorrupt if message length < given position
       
   130         * void CheckLengthL(TInt aPos);
       
   131         * @param aPos - Position in message
       
   132         * @return - 
       
   133         */
       
   134 		virtual void CheckLengthL( TInt aPos );
       
   135 		
       
   136 		/**
       
   137 		* Creates a pointer of the message to heap
       
   138         * TPtrC8 DoMessageCopy()
       
   139         * @param -
       
   140         * @return - Pointer to new message instance 
       
   141         */
       
   142 		TPtrC8 DoMessageCopyLC();
       
   143 		
       
   144 	protected:
       
   145 		CSmlAlertInfo& iAlertInfo;
       
   146 		CSyncMLHistoryPushMsg& iHistoryInfo;
       
   147 		RPointerArray<CNSmlAlertInfo> iFoundProfiles;
       
   148 	private:
       
   149 		HBufC8* iMessage;
       
   150 		TPtr8 iMessagePtr;
       
   151 	};
       
   152 
       
   153 //Class for parsing DM server alert notification version 1.1
       
   154 class CNSmlDSAlertParser11 : public CNSmlMessageParserBase, 
       
   155                             public MWBXMLSyncMLCallbacks
       
   156 	{
       
   157 	public:	
       
   158 	
       
   159 		/**
       
   160 		* Constuctor
       
   161         * CNSmlDMAlertParser11( CSmlAlertInfo& aAlertInfo, 
       
   162         * CSyncMLHistoryPushMsg& aHistoryInfo )
       
   163         * @param aAlertInfo - reference to CSmlAlertInfo : container for hold
       
   164         *                       parsed data
       
   165         * @param aHistoryInfo - reference to CSyncMLHistoryPushMsg : container
       
   166         *                       for hold parsed data
       
   167 		* @return - 
       
   168         */
       
   169 		CNSmlDSAlertParser11( CSmlAlertInfo& aAlertInfo, 
       
   170                 CSyncMLHistoryPushMsg& aHistoryInfo );
       
   171 		
       
   172 			/**
       
   173 		* Destructor
       
   174         * ~CNSmlDSAlertParser11();
       
   175         * @param -
       
   176         * @return - 
       
   177         */
       
   178 		virtual ~CNSmlDSAlertParser11();
       
   179 		
       
   180 		/**
       
   181 		* Derived from base class. Implements the parsing.
       
   182         * void ParseMessageL()
       
   183         * @param -
       
   184         * @return -
       
   185         */
       
   186 		virtual void ParseMessageL();
       
   187 		
       
   188 		/**
       
   189 		* Derived from base class. Targets the profile using server id.
       
   190         * void SearchProfileL( TDesC8& aServerUri )
       
   191         * @param aServerUri - Server Id.
       
   192         * @return - 
       
   193         */
       
   194 		virtual void SearchProfileL( TDesC8& aServerUri );		
       
   195 		
       
   196 		/**
       
   197 		* Targets the profile using server id.
       
   198         * TBool SearchProfileURIL( CNSmlURI& aUri )
       
   199         * @param aServerUri - Server Id.
       
   200         * @return - ETrue if profile is found
       
   201         */
       
   202 		TBool SearchProfileURIL( CNSmlURI& aUri );
       
   203 	
       
   204 		
       
   205 		/**
       
   206 		* Converts data in Pcdata structure
       
   207         * 	void PCDATAToUnicodeLC( const SmlPcdata_t& aPcdata, 
       
   208         *                           HBufC*& aUnicodeData ) const;
       
   209         * @param aServerUri - Server Id.
       
   210         * @return - 
       
   211         */
       
   212 		void PCDATAToUnicodeLC( const SmlPcdata_t& aPcdata, 
       
   213 		                        HBufC*& aUnicodeData ) const;
       
   214 		
       
   215 		/**
       
   216 		* Resolves the profile if more than one match is found
       
   217         * void ResolveProfileL( TInt aContentCount )
       
   218         * @param aContentCount - Number of alerted contents
       
   219         * @return - 
       
   220         */
       
   221 		virtual void ResolveProfileL( TInt aContentCount );
       
   222 				
       
   223 		/**
       
   224 		* Derived from base class. Targets content type with 
       
   225 		* remote database path + MimeType.
       
   226         * void MatchContentTypeL( TDesC8& aPath, TInt aContentType, 
       
   227         *                           TInt aSyncType )
       
   228         * @param aPath - Database path.
       
   229         * @param aContentType - Value of content type defined in SAN message
       
   230         * @param aSyncType - Sync type defined in SAN message for the content
       
   231         * @return -
       
   232         */
       
   233 		void MatchContentTypeL( TDesC8& aPath, TDesC8& aContentType, 
       
   234 		                        TSmlSyncType aSyncType, TInt aProfileIndex );
       
   235 		
       
   236 		/**
       
   237 		* Targets content type with mime-type
       
   238         * TBool ConvertContentTypeL( TDesC& aMimeType, 
       
   239         *                            const TInt aDataProviderId )
       
   240         * @param aMimeType - Mime type of the data provider
       
   241         * @param aDataProviderId - Implementation UID of the data provider
       
   242         * @return - ETrue if content type is allowed 
       
   243         */
       
   244 		TBool ConvertContentTypeL( TDesC& aMimeType, 
       
   245 		                            const TInt aDataProviderId );
       
   246 		
       
   247 	private:
       
   248 		
       
   249 		void TrimRightSpaceAndNull (TDes8& aDes ) const;
       
   250 		
       
   251 		Ret_t smlAlertCmdFuncL( SmlAlertPtr_t aContent);          
       
   252 		Ret_t smlGetCmdFuncL( SmlGetPtr_t aContent );                      
       
   253 		Ret_t smlPutCmdFuncL( SmlPutPtr_t aContent );            
       
   254 		Ret_t smlResultsCmdFuncL( SmlResultsPtr_t aContent );   
       
   255 		Ret_t smlStatusCmdFuncL( SmlStatusPtr_t aContent );       
       
   256 		Ret_t smlStartMessageFuncL( SmlSyncHdrPtr_t aSyncHdr);    
       
   257 		Ret_t smlEndMessageFuncL( Boolean_t final );           
       
   258 		Ret_t smlStartSyncFuncL( SmlSyncPtr_t aContent );       
       
   259 		Ret_t smlEndSyncFuncL();                               
       
   260 		Ret_t smlStartAtomicFuncL( SmlAtomicPtr_t aContent );  
       
   261 		Ret_t smlEndAtomicFuncL();                              
       
   262 		Ret_t smlStartSequenceFuncL( SmlSequencePtr_t aContent ); 
       
   263 		Ret_t smlEndSequenceFuncL();                              
       
   264 		Ret_t smlAddCmdFuncL( SmlAddPtr_t aContent );          
       
   265 	   	Ret_t smlCopyCmdFuncL( SmlCopyPtr_t aContent);               
       
   266 		Ret_t smlDeleteCmdFuncL( SmlDeletePtr_t aContent );    
       
   267 		Ret_t smlExecCmdFuncL( SmlExecPtr_t aContent );        
       
   268 		Ret_t smlMapCmdFuncL( SmlMapPtr_t aContent );          
       
   269 		Ret_t smlReplaceCmdFuncL( SmlReplacePtr_t aContent );  
       
   270 		Ret_t smlSearchCmdFuncL( SmlSearchPtr_t aContent );
       
   271 	    Ret_t smlMoveCmdFuncL( SmlMovePtr_t aContent );
       
   272 	  
       
   273 	 private:
       
   274 	 	TInt iContentCount;
       
   275 	 	SmlMetInfMetInf_t* iMetInf;
       
   276 	};
       
   277 	
       
   278 
       
   279 //Class for parsing DM server alert notification version 1.1
       
   280 class CNSmlDMAlertParser11 : public CNSmlMessageParserBase
       
   281 	{
       
   282 	public:	
       
   283 	
       
   284 		/**
       
   285 		* Constuctor
       
   286         * CNSmlDMAlertParser11( CSmlAlertInfo& aAlertInfo, 
       
   287         * CSyncMLHistoryPushMsg& aHistoryInfo )
       
   288         * @param aAlertInfo - reference to CSmlAlertInfo : container for hold
       
   289         *                       parsed data
       
   290         * @param aHistoryInfo - reference to CSyncMLHistoryPushMsg : 
       
   291         *                       container for hold parsed data
       
   292 		* @return - 
       
   293         */
       
   294 		CNSmlDMAlertParser11( CSmlAlertInfo& aAlertInfo, 
       
   295 		                        CSyncMLHistoryPushMsg& aHistoryInfo );
       
   296 		
       
   297 		/**
       
   298 		* Destructor
       
   299         * ~CNSmlDMAlertParser11();
       
   300         * @param -
       
   301         * @return - 
       
   302         */
       
   303 		virtual ~CNSmlDMAlertParser11();
       
   304 		
       
   305 		/**
       
   306 		* Derived from base class. Implements the parsing.
       
   307         * void ParseMessageL()
       
   308         * @param -
       
   309         * @return -
       
   310         */
       
   311 		virtual void ParseMessageL();
       
   312 		
       
   313 		/**
       
   314 		* Derived from base class. Targets the profile using server id.
       
   315         * void SearchProfileL( TDesC8& aServerUri )
       
   316         * @param aServerUri - Server Id.
       
   317         * @return -
       
   318         */
       
   319 		virtual void SearchProfileL( TDesC8& aServerUri );
       
   320 		
       
   321 		/**
       
   322 		* Resolves the profile if more than one match is found
       
   323         * void ResolveProfileL(TInt aContentCount)
       
   324         * @param aContentCount - Number of alerted contents
       
   325         * @return - 
       
   326         */
       
   327 		virtual void ResolveProfileL( TInt aContentCount );		
       
   328 	};
       
   329 	
       
   330 //Class for parsing DS server alert notification version 1.2
       
   331 class CNSmlDSAlertParser12 : public CNSmlMessageParserBase
       
   332 	{
       
   333 	public:	
       
   334 		
       
   335 		/**
       
   336 		* Constuctor
       
   337         * CNSmlDSAlertParser12( CSmlAlertInfo& aAlertInfo, 
       
   338         * CSyncMLHistoryPushMsg& aHistoryInfo )
       
   339         * @param aAlertInfo - reference to CSmlAlertInfo : container for hold
       
   340         *                       parsed data
       
   341         * @param aHistoryInfo - reference to CSyncMLHistoryPushMsg : 
       
   342                                 container for hold parsed data
       
   343 		* @return - 
       
   344         */
       
   345 		CNSmlDSAlertParser12( CSmlAlertInfo& aAlertInfo, 
       
   346 		                        CSyncMLHistoryPushMsg& aHistoryInfo );
       
   347 		
       
   348 		/**
       
   349 		* Destructor
       
   350         * ~CNSmlDSAlertParser12();
       
   351         * @param -
       
   352         * @return - 
       
   353         */
       
   354 		virtual ~CNSmlDSAlertParser12();
       
   355 		
       
   356 		/**
       
   357 		* Derived from base class. Implements the parsing.
       
   358         * void ParseMessageL()
       
   359         * @param -
       
   360         * @return -
       
   361         */
       
   362 		virtual void ParseMessageL();
       
   363 		
       
   364 		/**
       
   365 		* Derived from base class. Targets the profile using server id.
       
   366         * void SearchProfileL( TDesC8& aServerUri )
       
   367         * @param aServerUri - Server Id.
       
   368         * @return - 
       
   369         */
       
   370 		virtual void SearchProfileL( TDesC8& aServerUri );
       
   371 		
       
   372 		/**
       
   373 		* Derived from base class. Targets content type with remote database
       
   374 		* path + MimeType.
       
   375         * void MatchContentTypeL( TDesC8& aPath, TInt aContentType, 
       
   376         *    TSmlSyncType aSyncType, TInt aProfileIndex )
       
   377         * @param aPath - Database path.
       
   378         * @param aContentType - Value of content type defined in SAN message
       
   379         * @param aSyncType - Sync type defined in SAN message for the content
       
   380         * @param aProfileIndex - index of the profile data container
       
   381         * @return -
       
   382         */
       
   383 		virtual void MatchContentTypeL( TDesC8& aPath, TInt aContentType, 
       
   384 		                        TSmlSyncType aSyncType, TInt aProfileIndex );
       
   385 		
       
   386 		/**
       
   387 		* Resolves the profile if more than one match is found
       
   388         * void ResolveProfileL( TInt aContentCount )
       
   389         * @param aContentCount - Number of alerted contents
       
   390         * @return - 
       
   391         */
       
   392         virtual void ResolveProfileL( TInt aContentCount );
       
   393         
       
   394 	private:
       
   395 		
       
   396 		/**
       
   397 		* Derived from base class. Targets content type with mime-type.
       
   398         * TBool ConvertContentTypeLC( const TInt aContentNum, 
       
   399         * const TInt aDataProviderId )
       
   400         * @param aContentNum - Value of content type defined in SAN message
       
   401         * @param aDataProviderId - UID of the content type
       
   402         * @return - ETrue if content type is found
       
   403         */
       
   404 		TBool ConvertContentTypeL( const TInt aContentNum, 
       
   405 		                            const TInt aDataProviderId );
       
   406 		
       
   407 		/**
       
   408 		* Derived from base class. Implements the parsing.
       
   409         * void ValidateSyncType( TInt& aSyncType )
       
   410         * @param aSyncType - received sync type
       
   411         * @return -
       
   412         */
       
   413         void ValidateSyncType( TInt& aSyncType );
       
   414 	};
       
   415 
       
   416 
       
   417 class NSmlParserFactory
       
   418 	{
       
   419 	public:
       
   420 	
       
   421 		/**
       
   422 		* Factory method to create appropriate alert parser
       
   423         * CreateAlertParserL( TSmlUsageType aType, TSmlProtocolVersion aVersion
       
   424         * , CSmlAlertInfo& aAlertInfo, CSyncMLHistoryPushMsg& aHistoryInfo  )
       
   425         * @param aType - Specifies the usage type DM/DS
       
   426         * @param aVersion - Specifies the protocol version
       
   427         * @param aAlertInfo - reference to CSmlAlertInfo instance
       
   428        	* @param aHistoryInfo - reference to CSyncMLHistoryPushMsg instance
       
   429         * @return - instance of CNSmlMessageParserBase derived class
       
   430         */
       
   431 		static CNSmlMessageParserBase* CreateAlertParserL( TSmlUsageType aType,
       
   432 		    TSmlProtocolVersion aVersion, CSmlAlertInfo& aAlertInfo, 
       
   433             CSyncMLHistoryPushMsg& aHistoryInfo  );	
       
   434 	};
       
   435 
       
   436 
       
   437 // container of the alert message. Item of alert message queue
       
   438 class CNSmlMessageItem : public CBase
       
   439 	{
       
   440 	public:
       
   441 	
       
   442 		/**
       
   443 		* Two phase constructor
       
   444         * CNSmlMessageItem* NewL( const TDesC8& aMessage, 
       
   445         * TSmlUsageType aType, TSmlProtocolVersion aVersion, 
       
   446         * TSmlTransportId aBearerType )
       
   447         * @param aMessage - reference to message 
       
   448         * @param aType - Defines if the message is DM or DS
       
   449         * @param aVersion - specifies used DS or DM protocol version
       
   450         * @param aBearerType - specifies used bearer type
       
   451 		* @return - instance of CNSmlMessageItem 
       
   452         */
       
   453 		IMPORT_C static CNSmlMessageItem* NewL( const TDesC8& aMessage,
       
   454 		                TSmlUsageType aType, TSmlProtocolVersion aVersion, 
       
   455 		                TSmlTransportId aBearerType );
       
   456 		
       
   457 		/**
       
   458 		* Destructor
       
   459         * ~CNSmlMessageItem();
       
   460         * @param -
       
   461         * @return -
       
   462         */
       
   463 		~CNSmlMessageItem();
       
   464 		
       
   465 		static const TInt iOffset;
       
   466 		
       
   467 		/**
       
   468 		* returns reference to message
       
   469         * TDesC8& Message()
       
   470         * @param -
       
   471         * @return -
       
   472         */
       
   473 		IMPORT_C TDesC8& Message();
       
   474 				
       
   475 	private:
       
   476 	
       
   477 		/**
       
   478 		* Constructor
       
   479         * CNSmlMessageItem();
       
   480         * @param -
       
   481         * @return -
       
   482         */
       
   483 		CNSmlMessageItem();
       
   484 		
       
   485 		/**
       
   486 		* Second constructor
       
   487         * ConstructL( const TDesC8& aMessage, TSmlUsageType aType, 
       
   488         * TSmlProtocolVersion aVersion, TSmlTransportId aBearerType );
       
   489         * @param aMessage - reference to message 
       
   490         * @param aType - Defines if the message is DM or DS
       
   491         * @param aVersion - specifies used DS or DM protocol version
       
   492         * @param aBearerType - specifies used bearer type
       
   493         * @return -
       
   494         */
       
   495 		void ConstructL( const TDesC8& aMessage, TSmlUsageType aType, 
       
   496                 TSmlProtocolVersion aVersion, TSmlTransportId aBearerType );
       
   497 
       
   498 	private:
       
   499 		TDblQueLink iDlink;
       
   500 		HBufC8* iMessage;
       
   501 		TSmlUsageType iUsageType;
       
   502 		TSmlProtocolVersion iProtocol;
       
   503 		TSmlTransportId iBearerType;
       
   504 		friend class CNSmlMessageQueue;	
       
   505 	};
       
   506 
       
   507 class MNSmlMessageHandler
       
   508 	{
       
   509 	public:
       
   510 	
       
   511 		/**
       
   512 		* Checks if there is message in the queue
       
   513         * void CheckMessage( TBool& aMore, TSmlUsageType& aType, 
       
   514         * TSmlProtocolVersion& aVersion, TSmlTransportId& aBearerType  )
       
   515         * @param aMore - Set to ETrue if there is message in the queue
       
   516         * @param aType - Set to usage type of the message
       
   517         * @param aVersion - Set to used protocol version
       
   518         * @param aBearerType - specifies used bearer type
       
   519         * @return -
       
   520         */
       
   521 		virtual void CheckMessage( TBool& aMore, TSmlUsageType& aType, 
       
   522 		                TSmlProtocolVersion& aVersion, 
       
   523 		                TSmlTransportId& aBearerType ) = 0;
       
   524 		
       
   525 		/**
       
   526 		* Returns the length of the queued SAN message
       
   527         * TInt MessageSize()
       
   528         * @param -
       
   529         * @return TInt - size of the message
       
   530         */
       
   531 		virtual TInt MessageSize() = 0;
       
   532 		
       
   533 		/**
       
   534 		* Makes a copy of the message
       
   535         * void AlertMessage(TDes8& aMessage )
       
   536         * @param aMessage - reference of descriptor the message is copied to
       
   537         * @return -
       
   538         */
       
   539 		virtual void AlertMessage( TDes8& aMessage ) = 0;
       
   540 		
       
   541 		/**
       
   542 		* Creates a job
       
   543         * void CreateJobL( CSmlAlertInfo& aInfo, TBool& aQuit, 
       
   544         * const TPtrC8& aPackage )
       
   545         * @param aInfo - Container of the parsed alert info
       
   546         * @param aQuit - Returns whether there is next is message in queue
       
   547         * @param aPackage - Contains alert package if 1.1 version alert message
       
   548         * @return -
       
   549         */
       
   550 		virtual void CreateJobL( CSmlAlertInfo& aInfo, TBool& aQuit, 
       
   551 		                            const TPtrC8& aPackage  ) = 0;
       
   552 		
       
   553 		/**
       
   554 		* Disconnects local connection.
       
   555 		* void DoDisconnect()
       
   556 		* @param -
       
   557         * @return -        
       
   558 		*/		                            
       
   559 		virtual void DoDisconnect() = 0;
       
   560 	};							 
       
   561 
       
   562 
       
   563 class CNSmlAlertHandler : public CActive
       
   564 	{
       
   565 	public:
       
   566 	
       
   567 		/**
       
   568 		* Two phase constructor
       
   569         * CNSmlAlertHandler* NewL(MNSmlMessageHandler* aMsgHandler)
       
   570         * @param aMsgHandler - Pointer to the alert message handler
       
   571         * @return - new instance of CNSmlAlertHandler
       
   572         */
       
   573 		static CNSmlAlertHandler* NewL( MNSmlMessageHandler* aMsgHandler );
       
   574 		
       
   575 		/**
       
   576 		* Destructor
       
   577         * ~CNSmlAlertHandler()
       
   578         * @param -
       
   579         * @return - 
       
   580         */
       
   581 		~CNSmlAlertHandler();
       
   582 		
       
   583 		/**
       
   584 		* Activates alert handler
       
   585         * void ProcessAlert()
       
   586         * @param -
       
   587         * @return - 
       
   588         */
       
   589 		void ProcessAlert();
       
   590 		
       
   591 		/**
       
   592 		* Method from base class
       
   593         * void DoCancel()
       
   594         * @param -
       
   595         * @return - 
       
   596         */
       
   597 		void DoCancel();
       
   598 		
       
   599 		/**
       
   600 		* Method from base class. Parses the message.
       
   601         * void RunL()
       
   602         * @param -
       
   603         * @return - 
       
   604         */
       
   605 		void RunL();
       
   606 		
       
   607 	private:
       
   608 		
       
   609 		/**
       
   610 		* Fills the alert info before creating job
       
   611         * TBool FinalizeBeforeJobCreationL()
       
   612         * @param -
       
   613         * @return - ETrue if query is accepted
       
   614         */
       
   615 		TBool FinalizeBeforeJobCreationL();
       
   616 				
       
   617 		/**
       
   618 		* Checks whether alert has already been handled
       
   619         * void CheckDigestL(const TInt aProfileId, const TDesC8& aDigest)
       
   620         * @param aProfileId - Id of the profile
       
   621         * @param aDigest - Digest parsed from the SAN message
       
   622         * @return - 
       
   623         */
       
   624 		void CheckDigestL( const TInt aProfileId, const TDesC8& aDigest );
       
   625 		
       
   626 		/**
       
   627 		* Saves the result to profile history log and adds new entry
       
   628         * void SaveAlertInfoL(TBool aNewEntry);
       
   629         * @param aNewEntry - ETrue if new entry
       
   630         * @return - 
       
   631         */
       
   632 		void SaveAlertInfoL();
       
   633 		
       
   634 		/**
       
   635 		* Checks if profile has different version and changes to alert's
       
   636 		* version if different.
       
   637         * void CheckProtocolAndChangeL( TSmlProtocolVersion& aVersion )
       
   638         * @param aVersion - used protocol version
       
   639         * @return - 
       
   640         */
       
   641 		void CheckProtocolAndChangeL( TSmlProtocolVersion& aVersion ) const;
       
   642 		
       
   643 		/**
       
   644 		* Parses the message.
       
   645         * void DoRunL()
       
   646         * @param -
       
   647         * @return - 
       
   648         */
       
   649 		void DoRunL();
       
   650 		
       
   651 	private:
       
   652 		
       
   653 		/**
       
   654 		* Constructor
       
   655         * CNSmlAlertHandler()
       
   656         * @param -
       
   657         * @return - 
       
   658         */
       
   659 		CNSmlAlertHandler();
       
   660 		
       
   661 		/**
       
   662 		* Second phase constructor
       
   663         * void ConstructL( MNSmlMessageHandler* aMsgHandler )
       
   664         * @param aMsgHandler - Pointer to MNSmlMessageHandler observer
       
   665         * @return - 
       
   666         */
       
   667 		void ConstructL( MNSmlMessageHandler* aMsgHandler );
       
   668 		
       
   669 	private:
       
   670 		MNSmlMessageHandler* iMsgHandler;
       
   671 		CSyncMLHistoryPushMsg* iHistoryInfo;
       
   672 		CSmlAlertInfo* iAlertInfo;
       
   673 		CNSmlHistoryArray* iHistoryArray;
       
   674 		CNSmlMessageParserBase* iAlertParser;
       
   675 		TBool iNewEntry;
       
   676 		HBufC* iPackage;
       
   677 	};
       
   678 
       
   679 class CNSmlMessageQueue : public CBase, public MNSmlMessageHandler
       
   680 	{
       
   681 	public:
       
   682 		
       
   683 		enum TNSmlQueueState
       
   684 			{
       
   685 			ENSmlIdle,
       
   686 			ENSmlProcessing,
       
   687 			ENSmlSuspended
       
   688 			};
       
   689 		/**
       
   690 		* Two phase constructor
       
   691         * CNSmlMessageQueue* NewL( MNSmlAlertObserver* aObserver );
       
   692         * @param aMsgHandler - Pointer to the alert message handler
       
   693         * @return - new instance of CNSmlMessageQueue
       
   694         */
       
   695 		IMPORT_C static CNSmlMessageQueue* NewL( MNSmlAlertObserver* aObserver );
       
   696 		
       
   697 		/**
       
   698 		* Destructor
       
   699         * ~CNSmlMessageQueue()
       
   700         * @param -
       
   701         * @return - 
       
   702         */
       
   703 		IMPORT_C virtual ~CNSmlMessageQueue();
       
   704 		
       
   705 		/**
       
   706 		* Inserts new alert message to alert message queue
       
   707         * void AddMessageL( const TDesC8& aMessage, TSmlUsageType aType, 
       
   708         * TSmlProtocolVersion aVersion, TSmlTransportId aBearerType );
       
   709         * @param aMessage - Alert message
       
   710         * @param aType - Usage type of the message
       
   711         * @param aVersion - Protocol version of the message
       
   712         * @param aBearerType - specifies used bearer type
       
   713         * @return - 
       
   714         */
       
   715 		IMPORT_C void AddMessageL( const TDesC8& aMessage, TSmlUsageType aType, 
       
   716 		                       TSmlProtocolVersion aVersion, 
       
   717 		                       TSmlTransportId aBearerType );
       
   718 		
       
   719 		/**
       
   720 		* Check if queue is empty
       
   721         * TBool IsEmpty()
       
   722         * @param -
       
   723         * @return - ETrue if message queue is empty
       
   724         */
       
   725 		IMPORT_C TBool IsEmpty();
       
   726 		
       
   727 		/**
       
   728         * void ServerSuspendedL( TBool aSuspend )
       
   729         * @param aSuspend - ETrue if server goes to suspend mode (back up)
       
   730 		* @return - 
       
   731         */
       
   732 		IMPORT_C void ServerSuspended( TBool aSuspend );
       
   733 		
       
   734 		/**
       
   735 		* Method from the base class
       
   736         * void CheckMessage( TBool& aMore, TSmlUsageType& aType, 
       
   737         * TSmlProtocolVersion& aVersion, TSmlTransportId &aBearerType )
       
   738         * @param aMore - Set to ETrue if there is message in the queue
       
   739         * @param aType - Set to usage type of the message
       
   740         * @param aVersion - Set to used protocol version
       
   741         * @param aBearerType - specifies used bearer type
       
   742         * @return -
       
   743         */
       
   744 		virtual void CheckMessage( TBool& aMore, TSmlUsageType& aType, 
       
   745 		                        TSmlProtocolVersion& aVersion, 
       
   746 		                        TSmlTransportId &aBearerType );
       
   747 		
       
   748 		/**
       
   749 		* Method from the base class
       
   750         * TInt MessageSize()
       
   751         * @param -
       
   752         * @return TInt - size of the message
       
   753         */
       
   754 		virtual TInt MessageSize();
       
   755 		
       
   756 		/**
       
   757 		* Method from the base class
       
   758         * void AlertMessage( TDes8& aMessage )
       
   759         * @param aMessage - reference of descriptor the message is copied to
       
   760         * @return -
       
   761         */
       
   762 		virtual void AlertMessage( TDes8& aMessage );
       
   763 		
       
   764 		/**
       
   765 		* Method from the base class
       
   766         * void CreateJobL( CSmlAlertInfo& aInfo, TSmlUsageType aType, TBool& aQuit, const TPtrC8& aPackage )
       
   767         * @param aInfo - Container of the parsed alert info
       
   768         * @param aQuit - Returns whether there is next is message in queue
       
   769         * @param aPackage - pointer to the message
       
   770         * @return -
       
   771         */
       
   772 		virtual void CreateJobL( CSmlAlertInfo& aInfo, TBool& aQuit, const TPtrC8& aPackage );
       
   773 		
       
   774 		/**
       
   775 		* Disconnects local connection.
       
   776 		* void DoDisconnect()
       
   777 		* @param -
       
   778         * @return -        
       
   779 		*/	
       
   780 		virtual void DoDisconnect();
       
   781 		
       
   782 	private:
       
   783 	
       
   784 		/**
       
   785 		* Constructor
       
   786         * CNSmlMessageQueue(MNSmlAlertObserver* aObserver)
       
   787         * @param aObserver - Pointer to the alert observer
       
   788         * @return - 
       
   789         */
       
   790 		IMPORT_C CNSmlMessageQueue( MNSmlAlertObserver* aObserver );
       
   791 		
       
   792 		/**
       
   793 		* Second phase constructor
       
   794         * void ConstructL()
       
   795         * @param aMsgHandler - Pointer to MNSmlMessageHandler observer
       
   796         * @return - 
       
   797         */
       
   798 		void ConstructL();
       
   799 		
       
   800 		/**
       
   801 		* Clears the queue
       
   802         * void DestroyItems()
       
   803         * @param -
       
   804         * @return - 
       
   805         */
       
   806 		void DestroyItems();
       
   807 		
       
   808 	private:
       
   809 		TDblQue<CNSmlMessageItem> iAlertQueue;
       
   810 		TDblQueIter<CNSmlMessageItem> iAlertIterator;
       
   811 		CNSmlAlertHandler* iAlertHandler;
       
   812 		MNSmlAlertObserver* iAlertObserver; 
       
   813 		TNSmlQueueState iState;		
       
   814 	};
       
   815 
       
   816 #endif