email/imap4mtm/imapservermtm/src/cimapupsresponsewaiter.cpp
changeset 0 72b543305e3a
child 21 c6838af47512
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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 	CActiveScheduler::Add(this);
       
    41 	}
       
    42 
       
    43 /**
       
    44 Destructor.
       
    45 */	
       
    46 CImapUpsResponseWaiter::~CImapUpsResponseWaiter()
       
    47 	{
       
    48 	Cancel();
       
    49 	iUpsSubsession.Close();
       
    50 	iUpsSession.Close(); 
       
    51 	}
       
    52 
       
    53 /**
       
    54 Connect to UPS server and check if the client thread has the capability to check to the 
       
    55 imap server.
       
    56 @param aEntrySelection 	The CMsvEntrySelection containg the imap serviceID.
       
    57 @param aCommand 		The Imap command(KIMAP4MTMConnect OR KIMAP4MTMConnectAndSynchronise).
       
    58 		
       
    59 @param aClientThread	The Rthread of the client application.
       
    60 @param aHasCapability	TBool indicating if the client has passes the server's check on capability.
       
    61 @param aStatus			TRequestStatus of the Active Object.
       
    62 @return void.
       
    63 */
       
    64 void CImapUpsResponseWaiter::AuthoriseAndConnectL(CMsvEntrySelection& aEntrySelection, TInt aCommand, TThreadId aClientThreadId, TBool aHasCapability, TRequestStatus& aStatus)
       
    65 	{
       
    66 	__ASSERT_DEBUG(iState==EIMAP4MTMDisConnected, User::Invariant());
       
    67 	
       
    68 	if(aCommand == KIMAP4MTMConnect)
       
    69 		{
       
    70 		iState = EIMAP4MTMConnect;
       
    71 		}
       
    72 	else if(aCommand == KIMAP4MTMConnectAndSynchronise)	
       
    73 		{
       
    74 		iState = EIMAP4MTMConnectAndSynchronise;
       
    75 		}
       
    76 	iEntrySelection = &aEntrySelection;
       
    77 	
       
    78 	iDecision = EUpsDecNo;
       
    79 	
       
    80 	CImapSettings* imapSettings = CImapSettings::NewL(iServerEntry);
       
    81 	CleanupStack::PushL(imapSettings);
       
    82 	imapSettings->LoadSettingsL(iServerEntry.Entry().Id());
       
    83 
       
    84 	// Connect to UPS service.....
       
    85 	User::LeaveIfError(iUpsSession.Connect());
       
    86 	RThread clientThread;
       
    87  	User::LeaveIfError(clientThread.Open(aClientThreadId));
       
    88 	CleanupClosePushL(clientThread);
       
    89  	User::LeaveIfError(iUpsSubsession.Initialise(iUpsSession, clientThread));
       
    90 	CleanupStack::PopAndDestroy(&clientThread);
       
    91 	
       
    92 	
       
    93 	iStatus=KRequestPending;
       
    94 	iUpsSubsession.Authorise(aHasCapability, KUidIMAPService, imapSettings->ServerAddress(), iDecision, iStatus);
       
    95 	Queue(aStatus);
       
    96 	SetActive();
       
    97 	CleanupStack::PopAndDestroy();// imapSettings
       
    98 	}
       
    99 
       
   100 
       
   101 void CImapUpsResponseWaiter::DoRunL()
       
   102 	{
       
   103 	User::LeaveIfError(iStatus.Int());
       
   104 	if(iDecision != EUpsDecYes && iDecision != EUpsDecSessionYes)
       
   105 		{
       
   106 		Complete(KErrPermissionDenied);
       
   107 		return;
       
   108 		}
       
   109 	switch (iState)
       
   110 		{
       
   111 		case EIMAP4MTMConnect:
       
   112 			{
       
   113 			iState = EIMAP4MTMConnected;
       
   114 			iImapProtocolController.ConnectL(iStatus, *iEntrySelection);
       
   115 			SetActive();
       
   116 			}break;
       
   117 		case EIMAP4MTMConnectAndSynchronise:
       
   118 			{
       
   119 			iState = EIMAP4MTMConnected;
       
   120 			iImapProtocolController.ConnectAndSynchroniseL(iStatus, *iEntrySelection);
       
   121 			SetActive();	
       
   122 			}break;
       
   123 		case EIMAP4MTMConnected:
       
   124 			{
       
   125 			Complete(iStatus.Int());
       
   126 			iState=EIMAP4MTMDisConnected;
       
   127 			}break;
       
   128 		default:
       
   129 			{
       
   130 			__ASSERT_DEBUG(iState==EIMAP4MTMDisConnected, User::Invariant());
       
   131 			break;
       
   132 			}	
       
   133 		}
       
   134 	}
       
   135 
       
   136 
       
   137 void CImapUpsResponseWaiter::DoCancel()
       
   138 	{
       
   139 	iUpsSubsession.CancelPrompt();
       
   140 	iImapProtocolController.CancelAndCleanup();
       
   141 	}