voipplugins/sipconnectionprovider/src/scpimhandler.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2009 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: SCP IM Handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "scpimhandler.h"
       
    20 #include "scpsubservice.h"
       
    21 #include "scplogger.h"
       
    22 #include "scpprofilehandler.h"
       
    23 #include "csipclientresolverutils.h"
       
    24 
       
    25 // Implementation UID of IM Resolver plugin
       
    26 const TUid KResolver = { 0x2002133D };
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CScpImHandler::CCScpImHandler
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CScpImHandler::CScpImHandler( CScpSubService& aSubService ) :
       
    36     CScpServiceHandlerBase( aSubService )
       
    37     {
       
    38     SCPLOGSTRING2( "CScpImHandler[0x%x]::CScpImHandler", this )
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CScpImHandler::ConstructL
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 void CScpImHandler::ConstructL()
       
    46     {
       
    47     SCPLOGSTRING2( "CScpImHandler[0x%x]::ConstructL", this )
       
    48     BaseConstructL();
       
    49     iSipClientResolver = CSipClientResolverUtils::NewL();
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CScpPresenceHandler::NewL
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CScpImHandler* CScpImHandler::NewL( CScpSubService& aSubService )
       
    57     {
       
    58     SCPLOGSTRING( "CScpImHandler::NewL" )
       
    59     CScpImHandler* self = new ( ELeave ) CScpImHandler( aSubService );
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CScpImHandler::~CScpImHandler
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CScpImHandler::~CScpImHandler()
       
    71     {
       
    72     SCPLOGSTRING2( "CScpImHandler[0x%x]::~CScpImHandler", this )
       
    73     delete iSipClientResolver;
       
    74     SCPLOGSTRING( "CScpImHandler[0x%x]::~CScpImHandler - Out" )
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // From class CScpServiceHandlerBase
       
    79 // CScpImHandler::EnableSubServiceL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void CScpImHandler::EnableSubServiceL()
       
    83     {
       
    84     SCPLOGSTRING4( "CScpImHandler[0x%x]::EnableSubServiceL: 0x%x type: %i", 
       
    85                    this, &iSubService, iSubService.SubServiceType() )
       
    86     
       
    87     __ASSERT_DEBUG( ECCHIMSub == iSubService.SubServiceType(), User::Panic(
       
    88         KNullDesC, KErrGeneral ) );
       
    89     
       
    90     CScpServiceHandlerBase::RegisterProfileL();
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // From class CScpServiceHandlerBase
       
    95 // CScpImHandler::DisableSubService
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 TInt CScpImHandler::DisableSubService()
       
    99     {
       
   100     SCPLOGSTRING4( "CScpImHandler[0x%x]::DisableSubService: 0x%x type: %i", 
       
   101                    this, &iSubService, iSubService.SubServiceType() )
       
   102     __ASSERT_DEBUG( ECCHIMSub == iSubService.SubServiceType(), User::Panic(
       
   103         KNullDesC, KErrGeneral ) );
       
   104     
       
   105     TInt result( KErrNone );
       
   106 
       
   107     TCCHSubserviceState subServiceState = iSubService.State();
       
   108 
       
   109     if( ECCHDisabled != subServiceState )
       
   110         {
       
   111         TRAP( result, DeregisterContactHeaderL() );      
       
   112 
       
   113         DeregisterProfile();
       
   114         }
       
   115     else
       
   116         {
       
   117         result = KErrNotSupported;
       
   118         }
       
   119 
       
   120     return result;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // From class CScpServiceHandlerBase
       
   125 // CScpImHandler::SubServiceType
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TCCHSubserviceType CScpImHandler::SubServiceType() const
       
   129     {
       
   130     SCPLOGSTRING2( "CScpImHandler[0x%x]::SubServiceType", this )
       
   131     return ECCHIMSub;
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // From class CScpServiceHandlerBase
       
   136 // CScpImHandler::HandleSipConnectionEvent
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CScpImHandler::HandleSipConnectionEvent( TUint32 aProfileId,
       
   140     TScpConnectionEvent aEvent )
       
   141     {
       
   142     SCPLOGSTRING2( "CScpImHandler[0x%x]::HandleSipConnectionEvent", this )
       
   143     TRAP_IGNORE( HandleSipConnectionEventL( aProfileId, aEvent ) )
       
   144     SCPLOGSTRING( "CScpImHandler::HandleSipConnectionEvent - Out" )
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // Handle SIP connection event
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CScpImHandler::HandleSipConnectionEventL( const TUint32 aProfileId,
       
   152     TScpConnectionEvent aEvent )
       
   153     {
       
   154     SCPLOGSTRING4(
       
   155     "CScpImHandler[0x%x]::HandleSipConnectionEventL, profileID: %d event: %d",
       
   156         this, aProfileId, aEvent )
       
   157     
       
   158     if ( iSubService.SipProfileId() == aProfileId &&
       
   159         CScpSubService::EScpNoRequest != iSubService.EnableRequestedState() )
       
   160         {
       
   161         if ( EScpRegistered == aEvent && CScpSubService::EScpEnabled ==
       
   162             iSubService.EnableRequestedState() )
       
   163             {
       
   164             RBuf8 contactHeaderUser;
       
   165             contactHeaderUser.CleanupClosePushL();
       
   166             GetSipProfileContactHeaderUserL( contactHeaderUser );
       
   167             
       
   168             TInt32 uniqueId = iSubService.SipProfileId();
       
   169             TUid uniqueUid;
       
   170             uniqueUid.iUid = uniqueId;
       
   171             
       
   172             iSipClientResolver->RegisterClientWithUserL(
       
   173                 uniqueUid, contactHeaderUser, KResolver );
       
   174             
       
   175             CleanupStack::PopAndDestroy( &contactHeaderUser );
       
   176             }
       
   177         
       
   178         iSubService.HandleConnectionEvent( aEvent );
       
   179         }
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // Get SIP profile contact header user
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CScpImHandler::GetSipProfileContactHeaderUserL(
       
   187     RBuf8& aContactHeaderUser ) const
       
   188     {
       
   189     SCPLOGSTRING2( "CScpImHandler[0x%x]::GetSipProfileContactHeaderUserL",
       
   190         this )
       
   191     
       
   192     TUint32 sipProfileId = iSubService.SipProfileId();
       
   193     CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
       
   194     CScpSipConnection* sipConnection = profileHandler.CreateSipConnectionL(
       
   195         sipProfileId );
       
   196     CleanupStack::PushL( sipConnection );
       
   197     
       
   198     if( sipConnection )
       
   199         {
       
   200         User::LeaveIfError( sipConnection->GetContactHeaderUser(
       
   201             aContactHeaderUser ) );
       
   202         __ASSERT_DEBUG( aContactHeaderUser.Length() > 0, User::Panic(
       
   203             KNullDesC, KErrGeneral ) );
       
   204         }
       
   205     else
       
   206         {
       
   207         User::Leave( KErrNotFound );
       
   208         }
       
   209     
       
   210     CleanupStack::PopAndDestroy( sipConnection );
       
   211     
       
   212     SCPLOGSTRING( "CScpImHandler::GetSipProfileContactHeaderUserL - Out" )
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // Deregister contact header
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CScpImHandler::DeregisterContactHeaderL()
       
   220     {
       
   221     SCPLOGSTRING2( "CScpImHandler[0x%x]::DeregisterContactHeaderL", this )
       
   222 
       
   223     RBuf8 contactHeaderUser;
       
   224     contactHeaderUser.CleanupClosePushL();
       
   225 
       
   226     GetSipProfileContactHeaderUserL( contactHeaderUser );
       
   227     
       
   228     TInt32 uniqueId = iSubService.SipProfileId();
       
   229     TUid uniqueUid;
       
   230     uniqueUid.iUid = uniqueId;
       
   231     
       
   232     iSipClientResolver->UnRegisterClientWithUserL( 
       
   233         uniqueUid,
       
   234         contactHeaderUser );
       
   235     
       
   236     CleanupStack::PopAndDestroy( &contactHeaderUser );
       
   237     
       
   238     SCPLOGSTRING( "CScpImHandler::DeregisterContactHeaderL - Out" )
       
   239     }