PECengine/PresenceManager2/SrcSearch/CPEngSearchSessionHandler.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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: this class handles the search session
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CPEngSearchSessionHandler.h"
       
    20 #include "CPEngNWSessionSlot2.h"
       
    21 #include "PEngWVSearchPanics.h"
       
    22 #include <CIMPSSAPSettings.h>
       
    23 #include <impserrors.h>
       
    24 
       
    25 //MACROS
       
    26 
       
    27 #define RETURN_IF_NOT_PENDING( aId ) \
       
    28         {                                \
       
    29         if( !IsRequestPending( aId ) )   \
       
    30             {                            \
       
    31             return;                      \
       
    32             }                            \
       
    33         }                                \
       
    34      
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CPEngSearchSessionHandler::NewL()
       
    40 // -----------------------------------------------------------------------------
       
    41 CPEngSearchSessionHandler* CPEngSearchSessionHandler::NewL(
       
    42     TInt aPriority,
       
    43     const CPEngNWSessionSlotID2& aNWSessionSlotID )
       
    44     {
       
    45     CPEngSearchSessionHandler* self = new ( ELeave ) CPEngSearchSessionHandler();
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL( aPriority, aNWSessionSlotID );
       
    48     CleanupStack::Pop( self );
       
    49 
       
    50     return self;
       
    51     }
       
    52 
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CPEngSearchSessionHandler::CPEngSearchSessionHandler()
       
    56 // -----------------------------------------------------------------------------
       
    57 CPEngSearchSessionHandler::CPEngSearchSessionHandler()
       
    58         : iOperation( EPEngAccOp_Idle )
       
    59     {
       
    60     }
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CPEngSearchSessionHandler::~CPEngSearchSessionHandler()
       
    65 // -----------------------------------------------------------------------------
       
    66 CPEngSearchSessionHandler::~CPEngSearchSessionHandler()
       
    67     {
       
    68     iImpsAccClient.Unregister();
       
    69     iImpsEng.Close();
       
    70 
       
    71     delete iImpsSap;
       
    72 
       
    73     if ( iRequest )
       
    74         {
       
    75         User::RequestComplete( iRequest, KErrCancel );
       
    76         }
       
    77     }
       
    78 
       
    79 
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CPEngSearchSessionHandler::ConstructL()
       
    83 // -----------------------------------------------------------------------------
       
    84 void CPEngSearchSessionHandler::ConstructL( TInt aPriority,
       
    85                                             const CPEngNWSessionSlotID2& aNWSessionSlotID )
       
    86     {
       
    87     iImpsSap = CIMPSSAPSettings::NewL();
       
    88 
       
    89 
       
    90     //Load SAP data
       
    91     CPEngNWSessionSlot2* slot = CPEngNWSessionSlot2::NewLC( aNWSessionSlotID, aPriority );
       
    92     User::LeaveIfError( slot->OpenNWPresenceSessionOwnership() );
       
    93     User::LeaveIfError( slot->GetNWPresenceSessionSap( *iImpsSap ) );
       
    94     CleanupStack::PopAndDestroy( slot );
       
    95 
       
    96 
       
    97     User::LeaveIfError( iImpsEng.Connect() );
       
    98     iImpsAccClient.RegisterL( iImpsEng, this, aPriority );
       
    99     iImpsAccClient.RegisterErrorObserverL( *this );
       
   100     }
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CPEngSearchSessionHandler::OpenCspSessionL()
       
   105 // -----------------------------------------------------------------------------
       
   106 void CPEngSearchSessionHandler::OpenCspSessionL( TRequestStatus& aStatus )
       
   107     {
       
   108     __ASSERT_ALWAYS( !iRequest, User::Leave( KErrAlreadyExists ) );
       
   109     __ASSERT_ALWAYS( iImpsSap, SearchPanicOrLeaveL( EPEngNoSapContainerLoaded, KErrNotReady ) );
       
   110 
       
   111 
       
   112     TImpsCspIdentifier sessIndentifier;
       
   113     sessIndentifier.SetUserIdL( iImpsSap->SAPUserId() );
       
   114     sessIndentifier.SetSapL( iImpsSap->SAPAddress() );
       
   115 
       
   116     iOpId = iImpsAccClient.LoginL( sessIndentifier,
       
   117                                    iImpsSap->SAPUserPassword(),
       
   118                                    iImpsSap->ClientId(),
       
   119                                    iImpsSap->AccessPoint(),
       
   120                                    &( iImpsSap->ServerAuthenticationName() ),
       
   121                                    &( iImpsSap->ServerAuthenticationPassword() ) );
       
   122 
       
   123 
       
   124 
       
   125 
       
   126 
       
   127     iRequest = &aStatus;
       
   128     *iRequest = KRequestPending;
       
   129     iOperation = EPEngAccOp_LogIn;
       
   130     }
       
   131 
       
   132 
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CPEngSearchSessionHandler::CloseCspSessionL()
       
   136 // -----------------------------------------------------------------------------
       
   137 void CPEngSearchSessionHandler::CloseCspSessionL( TRequestStatus& aStatus )
       
   138     {
       
   139     __ASSERT_ALWAYS( !iRequest, User::Leave( KErrAlreadyExists ) );
       
   140 
       
   141     iOpId = iImpsAccClient.LogoutL();
       
   142     iRequest = &aStatus;
       
   143     *iRequest = KRequestPending;
       
   144     iOperation = EPEngAccOp_LogOut;
       
   145     }
       
   146 
       
   147 
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CPEngSearchSessionHandler::ImpsEngine()
       
   151 // -----------------------------------------------------------------------------
       
   152 RImpsEng& CPEngSearchSessionHandler::ImpsEngine()
       
   153     {
       
   154     return iImpsEng;
       
   155     }
       
   156 
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CPEngSearchSessionHandler::IsRequestPending()
       
   160 // -----------------------------------------------------------------------------
       
   161 TBool CPEngSearchSessionHandler::IsRequestPending( TInt aId )
       
   162     {
       
   163     if ( ( aId == iOpId ) && iRequest )
       
   164         {
       
   165         return ETrue;
       
   166         }
       
   167 
       
   168     return EFalse;
       
   169     }
       
   170 
       
   171 
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CPEngSearchSessionHandler::HandleLoginL()
       
   175 // From MImpsAccessHandler2
       
   176 // -----------------------------------------------------------------------------
       
   177 void CPEngSearchSessionHandler::HandleLoginL( TInt aId,
       
   178                                               TImpsCspIdentifier& /*aCspId*/ )
       
   179     {
       
   180     RETURN_IF_NOT_PENDING( aId );
       
   181     User::RequestComplete( iRequest, KErrNone );
       
   182     }
       
   183 
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CPEngSearchSessionHandler::HandleLoginL()
       
   187 // From MImpsAccessHandler2
       
   188 // -----------------------------------------------------------------------------
       
   189 void CPEngSearchSessionHandler::HandleLogoutL( TInt aId,
       
   190                                                TImpsCspIdentifier& /*aCspId*/ )
       
   191     {
       
   192     RETURN_IF_NOT_PENDING( aId );
       
   193     User::RequestComplete( iRequest, KErrNone );
       
   194     }
       
   195 
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CPEngSearchSessionHandler::HandleLoginL()
       
   199 // From MImpsAccessHandler2
       
   200 // -----------------------------------------------------------------------------
       
   201 void CPEngSearchSessionHandler::HandleLoginCancelL( TInt aCancelledOpId,
       
   202                                                     TImpsCspIdentifier& /*aCspId*/ )
       
   203     {
       
   204     RETURN_IF_NOT_PENDING( aCancelledOpId );
       
   205     User::RequestComplete( iRequest, KErrCancel );
       
   206     }
       
   207 
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CPEngSearchSessionHandler::HandleLoginL()
       
   211 // From MImpsAccessHandler2
       
   212 // -----------------------------------------------------------------------------
       
   213 void CPEngSearchSessionHandler::HandleNbrSessionsL( TInt /*aId*/,
       
   214                                                     TInt /*aNbr*/,
       
   215                                                     TImpsCspIdentifier& /*aCspId*/ )
       
   216     {
       
   217     }
       
   218 
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CPEngSearchSessionHandler::HandleErrorL()
       
   222 // From MImpsErrorHandler2
       
   223 // -----------------------------------------------------------------------------
       
   224 void CPEngSearchSessionHandler::HandleErrorL( TInt aStatus,
       
   225                                               TInt aOpId,
       
   226                                               const TDesC* /*aDescription*/,
       
   227                                               const CImpsDetailed* /*aDetailedRes*/,
       
   228                                               TImpsCspIdentifier& /*aCspId*/ )
       
   229     {
       
   230     RETURN_IF_NOT_PENDING( aOpId );
       
   231 
       
   232     //Map ignorable errors to KErrNone
       
   233     switch ( iOperation )
       
   234         {
       
   235         case EPEngAccOp_LogOut:
       
   236             {
       
   237             if ( ( aStatus == KImpsErrorNotLogged ) ||
       
   238                  ( aStatus == KImpsErrorOthersLogged ) ||
       
   239                  ( aStatus == KImpsErrorShuttingDown ) ||
       
   240                  ( aStatus == KImpsErrorBearerSuspended ) )
       
   241                 {
       
   242                 aStatus = KErrNone;
       
   243                 }
       
   244             break;
       
   245             }
       
   246 
       
   247         default:
       
   248             {
       
   249             //Nothing to do
       
   250             break;
       
   251             }
       
   252         }
       
   253 
       
   254     User::RequestComplete( iRequest, aStatus );
       
   255     }
       
   256 
       
   257 
       
   258 // End of file