email/imap4mtm/imapservermtm/src/cimapupsresponsewaiter.cpp
changeset 80 8b14b30db193
equal deleted inserted replaced
79:2981cb3aa489 80:8b14b30db193
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 #include <msventry.h>
       
    18 #include <miut_err.h>
       
    19 #include <imapcmds.h>
       
    20 
       
    21 #include "cimapprotocolcontroller.h"
       
    22 #include "cimapupsresponsewaiter.h"
       
    23 #include "cimapsettings.h"
       
    24 
       
    25 /**
       
    26 Construction method
       
    27 @return a new instance of CImapUpsResponseWaiter
       
    28 */
       
    29 CImapUpsResponseWaiter* CImapUpsResponseWaiter::NewL(CMsvServerEntry& aServerEntry, CImapProtocolController& aImapProtocolController)
       
    30 	{
       
    31 	return new(ELeave)CImapUpsResponseWaiter(aServerEntry, aImapProtocolController);
       
    32 	}
       
    33 
       
    34 /**
       
    35 Default constructor.
       
    36 */
       
    37 CImapUpsResponseWaiter::CImapUpsResponseWaiter(CMsvServerEntry& aServerEntry, CImapProtocolController& aImapProtocolController)
       
    38 	:CMsgActive(EPriorityStandard), iServerEntry(aServerEntry), iImapProtocolController(aImapProtocolController)
       
    39 	{
       
    40     iImapSettings = CImapSettings::NewL(iServerEntry);
       
    41     CActiveScheduler::Add(this);
       
    42 	}
       
    43 
       
    44 /**
       
    45 Destructor.
       
    46 */	
       
    47 CImapUpsResponseWaiter::~CImapUpsResponseWaiter()
       
    48 	{
       
    49 	Cancel();
       
    50 	delete iImapSettings;
       
    51 	iUpsSubsession.Close();
       
    52 	iUpsSession.Close(); 
       
    53 	}
       
    54 
       
    55 /**
       
    56 Connect to UPS server and check if the client thread has the capability to check to the 
       
    57 imap server.
       
    58 @param aEntrySelection 	The CMsvEntrySelection containg the imap serviceID.
       
    59 @param aCommand 		The Imap command(KIMAP4MTMConnect OR KIMAP4MTMConnectAndSynchronise).
       
    60 		
       
    61 @param aClientThread	The Rthread of the client application.
       
    62 @param aHasCapability	TBool indicating if the client has passes the server's check on capability.
       
    63 @param aStatus			TRequestStatus of the Active Object.
       
    64 @return void.
       
    65 */
       
    66 void CImapUpsResponseWaiter::AuthoriseAndConnectL(CMsvEntrySelection& aEntrySelection, TInt aCommand, TThreadId aClientThreadId, TBool aHasCapability, TRequestStatus& aStatus)
       
    67 	{
       
    68 	__ASSERT_DEBUG(iState==EIMAP4MTMDisConnected, User::Invariant());
       
    69 	
       
    70 	if(aCommand == KIMAP4MTMConnect)
       
    71 		{
       
    72 		iState = EIMAP4MTMConnect;
       
    73 		}
       
    74 	else if(aCommand == KIMAP4MTMConnectAndSynchronise)	
       
    75 		{
       
    76 		iState = EIMAP4MTMConnectAndSynchronise;
       
    77 		}
       
    78 	
       
    79     iEntrySelection = &aEntrySelection;
       
    80 	
       
    81 	iDecision = EUpsDecNo;
       
    82 	
       
    83 	if( iImapSettings->SettingsLoaded() == EFalse)
       
    84 	    {
       
    85 	    iImapSettings->LoadSettingsL(iServerEntry.Entry().Id());
       
    86 	    }
       
    87 
       
    88 	// Connect to UPS service.....
       
    89 	User::LeaveIfError(iUpsSession.Connect());
       
    90 
       
    91 	RThread clientThread;
       
    92  	User::LeaveIfError(clientThread.Open(aClientThreadId));
       
    93 	CleanupClosePushL(clientThread);
       
    94 
       
    95     User::LeaveIfError(iUpsSubsession.Initialise(iUpsSession, clientThread));
       
    96 	CleanupStack::PopAndDestroy(&clientThread);
       
    97 	
       
    98 	iStatus=KRequestPending;
       
    99 	iUpsSubsession.Authorise(aHasCapability, KUidIMAPService, iImapSettings->ServerAddress(), iDecision, iStatus);
       
   100 
       
   101 	Queue(aStatus);
       
   102 	SetActive();
       
   103     	
       
   104 	}
       
   105 
       
   106 
       
   107 void CImapUpsResponseWaiter::DoRunL()
       
   108 	{
       
   109 	User::LeaveIfError(iStatus.Int());
       
   110 	if(iDecision != EUpsDecYes && iDecision != EUpsDecSessionYes)
       
   111 		{
       
   112 		Complete(KErrPermissionDenied);
       
   113 		return;
       
   114 		}
       
   115 	switch (iState)
       
   116 		{
       
   117 		case EIMAP4MTMConnect:
       
   118 			{
       
   119 			iState = EIMAP4MTMConnected;
       
   120 			iImapProtocolController.ConnectL(iStatus, *iEntrySelection);
       
   121 			SetActive();
       
   122 			}break;
       
   123 		case EIMAP4MTMConnectAndSynchronise:
       
   124 			{
       
   125 			iState = EIMAP4MTMConnected;
       
   126 			iImapProtocolController.ConnectAndSynchroniseL(iStatus, *iEntrySelection);
       
   127 			SetActive();	
       
   128 			}break;
       
   129 		case EIMAP4MTMConnected:
       
   130 			{
       
   131 			Complete(iStatus.Int());
       
   132 			iState=EIMAP4MTMDisConnected;
       
   133 			}break;
       
   134 		default:
       
   135 			{
       
   136 			__ASSERT_DEBUG(iState==EIMAP4MTMDisConnected, User::Invariant());
       
   137 			break;
       
   138 			}	
       
   139 		}
       
   140 	}
       
   141 
       
   142 
       
   143 void CImapUpsResponseWaiter::DoCancel()
       
   144 	{
       
   145 	iUpsSubsession.CancelPrompt();
       
   146 	iImapProtocolController.CancelAndCleanup();
       
   147 	CMsgActive::DoCancel();
       
   148 	}