convergedconnectionhandler/cchclientapi/cchuinotif/src/cchuinotifconnectionhandler.cpp
changeset 0 a4daefaec16c
child 15 43658d24f35d
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2008-2008 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:  Provider access to SNAPs
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <cmmanagerdef.h>
       
    20 #include <cmpluginwlandef.h> // bearer type
       
    21 #include <cmdestinationext.h>
       
    22 #include <cmconnectionmethoddef.h>
       
    23 #include <cmconnectionmethodext.h>
       
    24 #include <cmpluginpacketdatadef.h>
       
    25 
       
    26 #include "cchuilogger.h"
       
    27 #include "cchuinotifconnectionhandler.h"
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 CCchUiNotifConnectionHandler::CCchUiNotifConnectionHandler()
       
    32     {
       
    33     }
       
    34 
       
    35 void CCchUiNotifConnectionHandler::ConstructL()
       
    36     {
       
    37     iCmManagerExt.OpenL();
       
    38     }
       
    39 
       
    40 CCchUiNotifConnectionHandler* CCchUiNotifConnectionHandler::NewL()
       
    41     {
       
    42     CCchUiNotifConnectionHandler* self = NewLC();
       
    43     CleanupStack::Pop(self);
       
    44     return self;
       
    45     }
       
    46 
       
    47 CCchUiNotifConnectionHandler* CCchUiNotifConnectionHandler::NewLC()
       
    48     {
       
    49     CCchUiNotifConnectionHandler* self =
       
    50         new (ELeave) CCchUiNotifConnectionHandler();
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL();
       
    53     return self;
       
    54     }
       
    55 
       
    56 CCchUiNotifConnectionHandler::~CCchUiNotifConnectionHandler()
       
    57     {
       
    58     iCmManagerExt.Close();
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Gets GPRS access points from Internet SNAP
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 TUint32 CCchUiNotifConnectionHandler::GetGprsAccessPointsL( 
       
    66     CDesCArray& aIaps, RArray<TUint32>& aIapIds )
       
    67     {    
       
    68     CCHUIDEBUG( "CCchUiNotifConnectionHandler::GetGprsAccessPointsL - IN" );
       
    69     
       
    70     TUint32 internetSnapId = KErrNone;
       
    71     RArray<TUint32> destIds = RArray<TUint32>( 1 );
       
    72     CleanupClosePushL( destIds );
       
    73     iCmManagerExt.AllDestinationsL( destIds );
       
    74     
       
    75     for ( TInt index = 0 ; index < destIds.Count() ; index++ )
       
    76         {
       
    77         RCmDestinationExt refDestination = 
       
    78             iCmManagerExt.DestinationL( destIds[index] );
       
    79         CleanupClosePushL( refDestination );    
       
    80         
       
    81         if ( refDestination.MetadataL( CMManager::ESnapMetadataInternet ) )
       
    82             {
       
    83             // Get all GPRS access point from this destination
       
    84             GetGprsAccessPointsFromSnapL( aIaps, aIapIds, refDestination );
       
    85             internetSnapId = refDestination.Id();
       
    86             }
       
    87         CleanupStack::PopAndDestroy( &refDestination );
       
    88         }
       
    89     CleanupStack::PopAndDestroy( &destIds );
       
    90     
       
    91     CCHUIDEBUG( "CCchUiNotifConnectionHandler::GetGprsAccessPointsL - OUT" );
       
    92     
       
    93     return internetSnapId;
       
    94     } 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Gets connection name.
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CCchUiNotifConnectionHandler::ConnectionNameL( 
       
   101     TUint aIapId, TDesC& aServiceName, RBuf& aIapName )
       
   102     {    
       
   103     CCHUIDEBUG( "CCchUiNotifConnectionHandler::ConnectionNameL - IN" );
       
   104     
       
   105     if ( aIapId )
       
   106         {
       
   107         RCmConnectionMethodExt connMethod = 
       
   108         iCmManagerExt.ConnectionMethodL( aIapId );
       
   109         CleanupClosePushL( connMethod );
       
   110         
       
   111         HBufC* connName = connMethod.GetStringAttributeL( 
       
   112             CMManager::ECmName );
       
   113         CleanupStack::PushL( connName );
       
   114                     
       
   115         aIapName.CreateL( connName->Des().Length() );
       
   116         aIapName.Copy( connName->Des() );
       
   117                     
       
   118         CleanupStack::PopAndDestroy( connName );              
       
   119         CleanupStack::PopAndDestroy( &connMethod );
       
   120         }
       
   121     else
       
   122         {
       
   123         RArray<TUint32> destinationIds;
       
   124         CleanupClosePushL( destinationIds );
       
   125         iCmManagerExt.AllDestinationsL( destinationIds );
       
   126         
       
   127         for ( TInt i( 0 ) ; i < destinationIds.Count() ; i++ )
       
   128             {
       
   129             RCmDestinationExt dest = 
       
   130                 iCmManagerExt.DestinationL( destinationIds[ i ] );
       
   131             CleanupClosePushL( dest );
       
   132 
       
   133             HBufC* destName = dest.NameLC();
       
   134             if ( destName->Des().Compare( aServiceName ) == 0  )
       
   135                 {
       
   136                 // Get highest priority connecton method from snap
       
   137                 RCmConnectionMethodExt cm = dest.ConnectionMethodL( 0 );
       
   138                 CleanupClosePushL( cm );
       
   139                 
       
   140                 HBufC* cmName = NULL;
       
   141                 cmName = cm.GetStringAttributeL( CMManager::ECmName );
       
   142                 
       
   143                 if ( cmName )
       
   144                     {
       
   145                     CleanupStack::PushL( cmName );
       
   146                     aIapName.CreateL( cmName->Des().Length() );
       
   147                     aIapName.Copy( cmName->Des() );
       
   148                     CleanupStack::PopAndDestroy( cmName );
       
   149                     }
       
   150                 
       
   151                 CleanupStack::PopAndDestroy( &cm );
       
   152                 }
       
   153             
       
   154             CleanupStack::PopAndDestroy( destName );
       
   155             CleanupStack::PopAndDestroy( &dest );
       
   156             }
       
   157         
       
   158         CleanupStack::PopAndDestroy( &destinationIds );
       
   159         }
       
   160     
       
   161     CCHUIDEBUG2( "ConnectionNameL - NAME=%S", &aIapName );
       
   162         
       
   163     CCHUIDEBUG( 
       
   164             "CCchUiNotifConnectionHandler::ConnectionNameL - OUT" );
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // Gets all but specified service´s destinations.
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CCchUiNotifConnectionHandler::GetDestinationsL( 
       
   172     TDesC& aServiceName, RArray<TUint32>& aDestinationIds )
       
   173     {  
       
   174     CCHUIDEBUG( "CCchUiNotifConnectionHandler::GetDestinationsL - IN" );
       
   175     
       
   176     iCmManagerExt.AllDestinationsL( aDestinationIds );
       
   177     
       
   178     // Remove our services destination from destination ids.
       
   179     for ( TInt i( 0 ) ; i < aDestinationIds.Count() ; i++ )
       
   180         {
       
   181         RCmDestinationExt refDestination = 
       
   182         iCmManagerExt.DestinationL( aDestinationIds[ i ] );
       
   183         CleanupClosePushL( refDestination );
       
   184                
       
   185         HBufC* destName = refDestination.NameLC();
       
   186                
       
   187         if ( destName->Des().Compare( aServiceName ) == 0 )
       
   188             {
       
   189             CCHUIDEBUG( 
       
   190                 "GetDestinationsL - remove current service´s destination" );
       
   191             
       
   192             aDestinationIds.Remove( i );
       
   193             aDestinationIds.Compress();
       
   194             }
       
   195                
       
   196         CleanupStack::PopAndDestroy( destName );      
       
   197         CleanupStack::PopAndDestroy( &refDestination );
       
   198         }
       
   199     
       
   200     CCHUIDEBUG( "CCchUiNotifConnectionHandler::GetDestinationsL - OUT" );
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // Gets all access point ids from SNAP.
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CCchUiNotifConnectionHandler::GetAccessPointsFromSnapL( 
       
   208     RArray<TUint32>& aIapIds, TUint32 aDestinationId )
       
   209     {    
       
   210     CCHUIDEBUG( 
       
   211         "CCchUiNotifConnectionHandler::GetAccessPointsFromSnapL - IN" );
       
   212 
       
   213     RCmDestinationExt destination = 
       
   214                 iCmManagerExt.DestinationL( aDestinationId );
       
   215     CleanupClosePushL( destination );
       
   216     
       
   217     for ( TInt index = 0 ; 
       
   218         index < destination.ConnectionMethodCount() ; index++ )
       
   219         {
       
   220         RCmConnectionMethodExt connMethod = 
       
   221             destination.ConnectionMethodL( index );
       
   222         CleanupClosePushL( connMethod );      
       
   223         TUint32 iapId = connMethod.GetIntAttributeL( CMManager::ECmIapId );
       
   224         aIapIds.AppendL( iapId );
       
   225         CleanupStack::PopAndDestroy( &connMethod );
       
   226         }
       
   227 
       
   228     CleanupStack::PopAndDestroy( &destination );
       
   229     
       
   230     CCHUIDEBUG( 
       
   231         "CCchUiNotifConnectionHandler::GetAccessPointsFromSnapL - OUT" );
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // Gets GPRS access points from Internet SNAP
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 void CCchUiNotifConnectionHandler::GetGprsAccessPointsFromSnapL( 
       
   239     CDesCArray& aIaps, 
       
   240     RArray<TUint32>& aIapIds, 
       
   241     RCmDestinationExt& aDestination )
       
   242     {    
       
   243     CCHUIDEBUG( 
       
   244         "CCchUiNotifConnectionHandler::GetGprsAccessPointsFromSnapL - IN" );
       
   245 
       
   246     __ASSERT_ALWAYS( aDestination.ConnectionMethodCount(), 
       
   247         User::Leave( KErrNotFound ) );
       
   248 
       
   249     for ( TInt index = 0 ; 
       
   250         index < aDestination.ConnectionMethodCount() ; index++ )
       
   251         {
       
   252         RCmConnectionMethodExt connMethod = 
       
   253             aDestination.ConnectionMethodL( index );
       
   254         CleanupClosePushL( connMethod );
       
   255         
       
   256         if ( KUidPacketDataBearerType == connMethod.GetIntAttributeL( 
       
   257                 CMManager::ECmBearerType ) )
       
   258             {
       
   259             HBufC* connName = 
       
   260                 connMethod.GetStringAttributeL( CMManager::ECmName );
       
   261             CleanupStack::PushL( connName );
       
   262             
       
   263             CCHUIDEBUG( "GetGprsAccessPointsFromSnapL - iap name ok" );
       
   264             
       
   265             aIaps.AppendL( *connName );
       
   266             CleanupStack::PopAndDestroy( connName );    
       
   267             TUint32 iapId = connMethod.GetIntAttributeL( CMManager::ECmIapId );
       
   268             aIapIds.AppendL( iapId );
       
   269             
       
   270             CCHUIDEBUG2( "GetGprsAccessPointsFromSnapL - iap id: %d", iapId );
       
   271             }
       
   272         CleanupStack::PopAndDestroy( &connMethod );
       
   273         }
       
   274 
       
   275     CCHUIDEBUG( 
       
   276         "CCchUiNotifConnectionHandler::GetGprsAccessPointsFromSnapL - OUT" );
       
   277     }