syncmlfw/common/syncagent/inc/NSmlAgentBase.h
changeset 0 b497e44ab2fc
child 25 b183ec05bd8c
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     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:  Base class in Commmon Agent
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __NSMLAGENTBASE_H__
       
    20 #define __NSMLAGENTBASE_H__
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <SyncMLDef.h>
       
    24 #include "WBXMLSyncMLParser.h"
       
    25 #include "nsmlerror.h"
       
    26 #include "nsmlagenttestdefines.h"
       
    27 
       
    28 //Rnd_AutoRestart
       
    29 #include <ApEngineConsts.h>
       
    30 //Rnd_AutoRestart
       
    31 //DATA TYPES
       
    32 enum TNSmlSyncInitiation    
       
    33 	{		
       
    34 	EClientInitiated = 1,
       
    35 	EServerAlerted
       
    36 	};
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 class CSyncMLHistoryJob;
       
    40 class CNSmlStatusContainer;
       
    41 class CNSmlResponseController;
       
    42 class CNSmlTransport;
       
    43 class CNSmlCmdsBase;
       
    44 class CNSmlURI;
       
    45 class CNSmlFutureReservation;
       
    46 
       
    47 // CLASS DECLARATION
       
    48 
       
    49 /**
       
    50 *  CNSmlAgentBase implements common parts (both for DS and DM)   
       
    51 *  
       
    52 */
       
    53 class CNSmlAgentBase:public CActive, public MWBXMLSyncMLCallbacks
       
    54 	{
       
    55 	public: // enumerations 
       
    56 	enum TAuthenticationType
       
    57 		{
       
    58 		ENoAuth,
       
    59 		EBasic,
       
    60 		EMD5
       
    61 		};
       
    62 
       
    63     public:  // Constructors and destructor
       
    64     IMPORT_C CNSmlAgentBase();            
       
    65     IMPORT_C virtual ~CNSmlAgentBase();
       
    66 
       
    67     public: 
       
    68 	// New functions
       
    69 	virtual TAuthenticationType AuthTypeL() const = 0;
       
    70 	virtual void Interrupt( TInt aErrorCode, TBool aImmediatelyInterruption, TBool aStatusError ) = 0;
       
    71 	virtual void InterruptL( TInt appIndex, TInt aErrorCode, TBool aImmediatelyInterruption, TBool aStatusError ) = 0;
       
    72 	virtual void WriteWarningL( TNSmlError::TNSmlAgentErrorCode aWarningCode ) = 0;  
       
    73 	virtual void WriteWarningL( TInt appIndex, TNSmlError::TNSmlAgentErrorCode aWarningCode ) = 0;
       
    74 	virtual void WriteWarningL( TInt appIndex, TNSmlError::TNSmlSyncMLStatusCode aWarningCode ) = 0;
       
    75 	virtual void CheckServerStatusCodeL( TInt aEntryID ) = 0;
       
    76 	virtual TBool Interrupted() = 0;
       
    77 	TBool AlreadyAuthenticated() const;  
       
    78 	HBufC8* BasicCredentialL() const;
       
    79 	HBufC8* Md5CredentialL( TBool aServerAuth = EFalse ) const;
       
    80 	IMPORT_C virtual HBufC* ServerNonceAllocL() const;
       
    81 	IMPORT_C virtual void SetServerNonceL( const TDesC& aNonce ) const;
       
    82 	IMPORT_C void SetEndOfDataAlertRequest();
       
    83     IMPORT_C CSyncMLHistoryJob* SyncLog();
       
    84 	IMPORT_C TBool CallbackCalled() const;
       
    85 	IMPORT_C void SetOffCallbackCalled();
       
    86 	IMPORT_C virtual void DoOutsideCancel();
       
    87 	//Rnd_AutoRestart
       
    88 	IMPORT_C virtual void LaunchAutoRestartL(TInt aError);
       
    89 	IMPORT_C TApBearerType CheckAPBearerTypeL( const TUint32 aIAPId );
       
    90 	void ReadAcessPointL();
       
    91 	//Rnd_AutoRestart
       
    92 	
       
    93 	//
       
    94 	// Profile ID getter
       
    95 	//
       
    96 	IMPORT_C TInt ProfileId() const;
       
    97 
       
    98 	IMPORT_C TRequestStatus& StatusReference();
       
    99     
       
   100 	public:
       
   101 	// Functions from base classes
       
   102 	IMPORT_C void RunL();										   // from CActive       
       
   103 	IMPORT_C void DoCancel();									   // from CActive 
       
   104     IMPORT_C Ret_t smlAddCmdFuncL( SmlAddPtr_t aContent );          // from MWBXMLSyncMLCallbacks
       
   105    	IMPORT_C Ret_t smlCopyCmdFuncL( SmlCopyPtr_t aContent);         // from MWBXMLSyncMLCallbacks      
       
   106 	IMPORT_C Ret_t smlDeleteCmdFuncL( SmlDeletePtr_t aContent );    // from MWBXMLSyncMLCallbacks
       
   107 	IMPORT_C Ret_t smlExecCmdFuncL( SmlExecPtr_t aContent );        // from MWBXMLSyncMLCallbacks
       
   108 	IMPORT_C Ret_t smlMapCmdFuncL( SmlMapPtr_t aContent );          // from MWBXMLSyncMLCallbacks
       
   109 	IMPORT_C Ret_t smlReplaceCmdFuncL( SmlReplacePtr_t aContent );  // from MWBXMLSyncMLCallbacks
       
   110 	IMPORT_C Ret_t smlSearchCmdFuncL( SmlSearchPtr_t aContent );    // from MWBXMLSyncMLCallbacks
       
   111 	IMPORT_C Ret_t smlMoveCmdFuncL( SmlMovePtr_t aContent );		// from MWBXMLSyncMLCallbacks (1.2 changes)
       
   112 
       
   113     protected: // enumerations
       
   114 	//
       
   115     // State coding enumerations
       
   116 	//
       
   117 	//main level state coding
       
   118 	enum TMainState
       
   119 		{
       
   120 		EBeginning,			
       
   121 		EClientInitialisation,
       
   122 		EServerInitialisation,
       
   123 // <MAPINFO_RESEND_MOD_BEGIN>
       
   124 		EClientResendMapInfo,
       
   125 // <MAPINFO_RESEND_MOD_END>
       
   126 		EClientModifications,
       
   127 		EResultAlert,
       
   128 		EServerModifications,
       
   129 		EDataUpdateStatus,
       
   130 		EMapAcknowledge,
       
   131 		EFinishing,
       
   132 		EClientAlertNext,
       
   133 		EServerAlertNext,
       
   134 		ESending,
       
   135 		EReceiving,
       
   136 		EAlert,
       
   137 		EBusy
       
   138 		};
       
   139 		
       
   140 	//beginning level state coding
       
   141 	enum TBeginningState
       
   142 		{
       
   143 		EBegin,
       
   144 		EBeginConnectingToServer
       
   145 		};
       
   146 
       
   147 	//client initialisation level state coding
       
   148 	enum TClientInitState
       
   149 		{
       
   150 		EInitStartingMessage,
       
   151 		EInitMakingStatus,
       
   152 		EInitAlerting,
       
   153 		EInitDeviceInfo,
       
   154 		EInitAskingDeviceInfo,
       
   155 		EInitEndingMessage
       
   156 		};
       
   157 
       
   158 			
       
   159 	//server modifications level state coding
       
   160 	enum TServerModificationsState
       
   161 		{
       
   162 		EServerModWaitingStartMessage,
       
   163 		EServerModWaitingCommands,
       
   164 		EServerModWaitingUpdateCommands,
       
   165 		EServerModMessageReceived,
       
   166 		EServerModPackageReceived
       
   167 		};
       
   168 
       
   169 	//data update status level state coding
       
   170 	enum TDataUpdateStatusState
       
   171 		{
       
   172 		EStatusStartingMessage,
       
   173 		EStatusMakingAlert,
       
   174 		EStatusMakingStatus,
       
   175 		EStatusMakingMap,
       
   176 		EStatusMakingResults,
       
   177 		EStatusEndingMessage
       
   178 		};
       
   179 
       
   180 	//result alert from client level state coding
       
   181 	enum TResultAlertState
       
   182 		{
       
   183 		EResultAlertStartingMessage,
       
   184 		EResultAlertMakingAlert,
       
   185 		EResultAlertEndingMessage
       
   186 		};
       
   187 
       
   188 	// client alerting for next state coding	
       
   189 	enum TClientAlertNextState
       
   190 		{
       
   191 		EClientAlertNextStartingMessage,
       
   192 		EClientAlertNextMakingAlert,
       
   193 		EClientAlertNextMakingStatus,
       
   194 		EClientAlertNextMakingMap,
       
   195 		EClientAlertNextEndingMessage
       
   196 		};
       
   197 	// server alerting for next state coding	
       
   198 	enum TServerAlertNextState
       
   199 		{
       
   200 		EServerAlertNextWaitingStartMessage,
       
   201 		EServerAlertNextWaitingCommands,
       
   202 		EServerAlertNextMessageReceived
       
   203 		};
       
   204 		
       
   205 	protected:   //new functions
       
   206 	//
       
   207 	// Pure virtual state functions
       
   208 	//
       
   209 	virtual void NavigateMainStateL() = 0;
       
   210 	virtual void NextMainStateL() = 0;
       
   211 	virtual void InitialiseSubStates() = 0; 
       
   212     virtual void BeginStateL() = 0;
       
   213 	virtual void InitStartingMessageStateL() = 0; 
       
   214 	virtual void InitAlertingStateL() = 0;
       
   215 	virtual void InitDeviceInfoStateL() = 0;
       
   216 	virtual void ServerModUpdatesStateL( const TDesC8& aCmd, SmlGenericCmd_t* aContent ) =0;
       
   217 	virtual void DataUpdateStatusStartingMessageStateL() = 0;
       
   218 	//
       
   219 	// Pure virtual Nonce read/update functions
       
   220 	//
       
   221 	virtual HBufC* NonceL() const = 0;
       
   222 	virtual void SetNonceL( const TDesC& aNonce ) const = 0;
       
   223 	//
       
   224 	// Pure virtual Sync Log functions
       
   225 	//
       
   226 	virtual void FinalizeSyncLog() = 0;
       
   227 	//
       
   228 	virtual void CheckCommandsAreReceivedL() = 0;
       
   229 	//
       
   230 	// Pure virtual authentication type update
       
   231 	//
       
   232 	virtual void SetAuthTypeL( TAuthenticationType aAuthType ) const = 0;
       
   233 	//
       
   234 	// Pure virtual Resource Freeing 
       
   235 	//
       
   236 	virtual void FreeResources() = 0;
       
   237 	//
       
   238 	// Pure virtual Error Handling functions
       
   239 	//
       
   240 	virtual void FinaliseWhenErrorL() = 0;
       
   241 	//
       
   242 	//
       
   243 	IMPORT_C void ConstructL();
       
   244 	//
       
   245 	// Beginning state functions 
       
   246 	//
       
   247 	IMPORT_C void BeginningStateL();
       
   248 	//			
       
   249 	// Client Initialisation state functions 
       
   250 	//
       
   251 	IMPORT_C void ClientInitialisationStateL();
       
   252 	IMPORT_C void InitStartingMessageStateBaseL();
       
   253 	IMPORT_C virtual void InitAskingDeviceInfoStateL();
       
   254 	//
       
   255 	// Server Modifications state functions 
       
   256 	//
       
   257 	IMPORT_C void ServerModStartMessageStateL( SmlSyncHdr_t* aSyncHdr );
       
   258 	IMPORT_C void ServerModStatusCmdStateL( SmlStatus_t* aStatus );
       
   259 	IMPORT_C void ServerModAlertCmdStateL( SmlAlert_t* aAlert );
       
   260 	IMPORT_C void ServerModEndMessageStateL( TBool aFinal );
       
   261 	//
       
   262 	// Data Update Status state functions
       
   263 	//
       
   264 	IMPORT_C void DataUpdateStatusStateL();
       
   265 	IMPORT_C void DataUpdateStatusStartingMessageStateBaseL();
       
   266 	IMPORT_C virtual void DataUpdateStatusMakingMapStateL();
       
   267 	IMPORT_C virtual void DataUpdateStatusMakingResultsStateL();
       
   268 	//
       
   269 	// Result Alert state functions 
       
   270 	//
       
   271 	IMPORT_C void ResultAlertStateL();
       
   272 	//
       
   273 	// Client Alert For Next state functions 
       
   274 	//
       
   275 	IMPORT_C void ClientAlertNextStateL();
       
   276 	IMPORT_C virtual void ClientAlertNextMakingMapStateL();
       
   277 	//
       
   278 	// Server Alert For Next state functions 
       
   279 	//
       
   280 	IMPORT_C void ServerAlertNextStateL();
       
   281 	IMPORT_C void ServerAlertNextStartMessageStateL( SmlSyncHdr_t* aSyncHdr );
       
   282 	IMPORT_C void ServerAlertNextStatusCmdStateL( SmlStatus_t* aStatus );
       
   283 	IMPORT_C void ServerAlertNextAlertCmdStateL( SmlAlert_t* aAlert );
       
   284 	IMPORT_C void ServerAlertNextEndMessageStateL( TBool aFinal );
       
   285 	//
       
   286 	// Sending state functions 
       
   287 	//
       
   288 	IMPORT_C void SendingStateL();
       
   289 	//
       
   290 	// Receiving state functions 
       
   291 	//
       
   292 	IMPORT_C  void ReceivingStateL();
       
   293 	//
       
   294 	// Status code check				
       
   295 	//
       
   296 	IMPORT_C TBool CheckStatusCodesAreReceivedL( TBool aFinal = ETrue );
       
   297 	//
       
   298 	// Authentication functions
       
   299 	//
       
   300 	IMPORT_C void SaveIfNonceL( const CNSmlResponseController& aResponseController, TInt aEntryID ) const;
       
   301 	IMPORT_C TBool AuthenticationRequirementL( const CNSmlResponseController& aResponseController, TInt aEntryID );
       
   302 	IMPORT_C virtual TPtrC ServerUserName() const;
       
   303 	IMPORT_C virtual TPtrC ServerPassword() const;
       
   304 
       
   305 	//
       
   306 	// Free resources
       
   307 	//
       
   308 	IMPORT_C void FreeBaseResources();
       
   309 	
       
   310 	//
       
   311 	private: //functions
       
   312 		
       
   313 	CNSmlAgentBase( const CNSmlAgentBase& aOther );
       
   314 	CNSmlAgentBase& operator=( const CNSmlAgentBase& aOther );
       
   315     //
       
   316 	// Beginning state functions 
       
   317 	//
       
   318 	void BeginConnectingStateL();  
       
   319     //			
       
   320 	// Client Initialisation state functions 
       
   321 	//
       
   322     void InitMakingStatusStateL(); 
       
   323 	void InitEndingMessageStateL(); 
       
   324     //
       
   325 	// Data Update Status state functions
       
   326 	//
       
   327 	void DataUpdateStatusMakingAlertStateL();  
       
   328 	void DataUpdateStatusMakingStatusStateL(); 
       
   329 	void DataUpdateStatusEndingMessageStateL(); 
       
   330 	//
       
   331 	// Result Alert state functions 
       
   332 	//
       
   333 	void ResultAlertStartingMessageStateL();  
       
   334 	void ResultAlertAlertingStateL();          
       
   335 	void ResultAlertEndingMessageStateL();      
       
   336 	//
       
   337 	// Client Alert For Next state functions 
       
   338 	//
       
   339 	void ClientAlertNextStartingMessageStateL();  
       
   340 	void ClientAlertNextAlertingStateL();         
       
   341 	void ClientAlertNextMakingStatusStateL();     
       
   342 	void ClientAlertNextEndingMessageStateL();    
       
   343 	//
       
   344 	// Transport functions
       
   345 	//
       
   346 	void ConnectIssueL();		
       
   347 	void ConnectDoneL();		
       
   348 	void SendDataIssueL();
       
   349 	void SendDataDoneL();
       
   350 	void ReceiveDataIssueL();
       
   351 	void ReceiveDataDoneL();
       
   352 	void Disconnect();
       
   353 	//
       
   354 	// Error Handling functions
       
   355 	//
       
   356 	void ErrorHandling( TInt aErrorCode );  
       
   357 	
       
   358 	public:     // Data
       
   359 	
       
   360 	//Rnd_AutoRestart
       
   361 	TBool iPacketDataUnAvailable;
       
   362 	TUint32 iNetmonAPId;
       
   363 	TApBearerType iNetmonAPBearerType;
       
   364 	//Rnd_AutoRestart
       
   365 	
       
   366     protected:    // Data	
       
   367 		
       
   368 	//
       
   369     // State codes
       
   370 	//
       
   371 	TMainState iCurrMainState;
       
   372 	TMainState iPrevSyncState;
       
   373 	TBeginningState iCurrBeginningState;
       
   374 	TClientInitState iCurrClientInitState;
       
   375 	TServerModificationsState iCurrServerModState;
       
   376 	TDataUpdateStatusState iCurrDataUpdateStatusState;
       
   377 	TResultAlertState iCurrResultAlertState;
       
   378 	TClientAlertNextState iCurrClientAlertNextState;
       
   379 	TServerAlertNextState iCurrServerAlertNextState;
       
   380 	//
       
   381 	TRequestStatus* iCallerStatus;
       
   382 	//	
       
   383 	// IMEI code
       
   384 	HBufC* iImeiCode;
       
   385 	// Switch for autenthication
       
   386 	TBool iAlreadyAuthenticated;
       
   387 	// Switch for challenge request 
       
   388 	TBool iChallengeRequest;
       
   389 	// Switch for MD5 challenge request 
       
   390 	TBool iMD5AlreadyRequested;
       
   391 	// switch for asynchronous issues
       
   392 	TBool iCommandIssued;
       
   393 	// switch for checking SyncML version
       
   394 	TBool iVersionIsChecked;
       
   395 	// MaxMsgSize in a server 
       
   396 	TInt iMaxMsgSizeInServer;
       
   397 	// switch for Busy Status
       
   398 	TBool iBusyStatusReceived;
       
   399 	// switch for Result Alert
       
   400 	TBool iResultAlertIssued;
       
   401 	// switch for full workspace buffer
       
   402 	TBool iBufferFull;
       
   403 	// switch for final
       
   404 	TBool iFinalMessageFromClient;
       
   405 	// switch for Data Update Status package;
       
   406 	TBool iStatusPackage;
       
   407 	// switchs for end 
       
   408 	TBool iEnd;
       
   409 	TBool iCancelForced;
       
   410 	
       
   411 	// Common settings data
       
   412 	TSmlProfileId iProfileID;
       
   413 	HBufC* iSyncMLUserName;
       
   414 	HBufC* iSyncMLPassword;
       
   415 
       
   416 	HBufC* iSyncHTTPAuthUserName;	
       
   417 	HBufC* iSyncHTTPAuthPassword;	
       
   418 	TInt iSyncHTTPAuthUsed;			
       
   419 
       
   420 	CNSmlURI* iSyncServer;
       
   421 	TUid iMediumType;
       
   422 	TInt iIAPId;
       
   423     CArrayFixFlat<TUint32>* iIAPIdArray;
       
   424 
       
   425 	// Sync Initiation 
       
   426 	TNSmlSyncInitiation iSyncInitiation;
       
   427 	// SyncML MIME type;
       
   428 	HBufC8* iSyncMLMIMEType;
       
   429 	// Result Alert code
       
   430 	HBufC8* iResultAlertCode;
       
   431 	// End of Data Alert code
       
   432 	HBufC8* iEndOfDataAlertCode;
       
   433     // Session Abort Alert code (DM Only)
       
   434 	HBufC8* iSessionAbortAlertCode;
       
   435 	// Next Message Alert code
       
   436 	HBufC8* iNextMessageCode;
       
   437 	// Switch for end of data alert
       
   438 	TBool iEndOfDataAlertRequest;
       
   439 	// Switch for session abort alert (DM Only)
       
   440 	TBool iSessionAbortAlertRequest; 
       
   441 	// Counter for nested Atomics
       
   442 	TInt iNestedAtomicsCount;
       
   443     // 
       
   444 	TBool iCallbackCalled;
       
   445 	//
       
   446 	// Used classes
       
   447 	//
       
   448 	CSyncMLHistoryJob* iSyncLog;
       
   449 	//
       
   450 	// Owned classes
       
   451 	//
       
   452 	CNSmlCmdsBase* iSyncMLCmds;
       
   453 	TNSmlError* iError;
       
   454 	//
       
   455 	// Owned classes
       
   456 	//
       
   457 	CNSmlTransport* iTransport; 
       
   458 
       
   459 	private:    // Data
       
   460 	// Reserved to maintain binary compability
       
   461 	CNSmlFutureReservation* iReserved;
       
   462 
       
   463 	TPtr8 iBufferArea;
       
   464 	
       
   465 	TInt iSendRetries;
       
   466 	// for module test
       
   467 #ifdef __NOTRANSPORT
       
   468 	TInt iTestCounter;
       
   469 #endif
       
   470 	};
       
   471 
       
   472 #endif // __NSMLAGENTBASE_H__
       
   473             
       
   474 // End of File