realtimenetprots/sipfw/ProfileAgent/ApnManager/src/sipapnmanager.cpp
branchRCL_3
changeset 2 1e1cc61f56c3
child 13 822e1f077722
equal deleted inserted replaced
1:dd3853b8dc3f 2:1e1cc61f56c3
       
     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 // Name        : sipapnmanager.cpp
       
    15 // Part of     : SIP Profile Server
       
    16 // implementation
       
    17 // Version     : 1.0
       
    18 //
       
    19 
       
    20 #include <commsdattypesv1_1.h>
       
    21 #include <commsdat.h>
       
    22 #include <commdb.h>
       
    23 #include <f32file.h>
       
    24 #include "sipapnmanager.h"
       
    25 #include "SipProfileLog.h"
       
    26 #include "sipapnconfigurationhandler.h"
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ==============================
       
    29 
       
    30 // ----------------------------------------------------------------------------
       
    31 // CSIPApnManager::NewL
       
    32 // ----------------------------------------------------------------------------
       
    33 //
       
    34 CSIPApnManager* CSIPApnManager::NewL( 
       
    35     MSIPApnChangeObserver& aObserver )
       
    36     {
       
    37     CSIPApnManager* self = new (ELeave) CSIPApnManager( aObserver );
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ----------------------------------------------------------------------------
       
    45 // CSIPApnManager::~CSIPApnManager
       
    46 // ----------------------------------------------------------------------------
       
    47 //
       
    48 CSIPApnManager::~CSIPApnManager()
       
    49     {
       
    50     iHandlers.ResetAndDestroy();
       
    51     }
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CSIPApnManager::UpdateApnL
       
    55 // ----------------------------------------------------------------------------
       
    56 //	
       
    57 void CSIPApnManager::UpdateApnL( TUint32 aIapId, TBool aIsPrimaryApn, const TDesC8& aApn )
       
    58 	{
       
    59     CSIPApnConfigurationHandler* handler = FindIapIdHandler( aIapId );
       
    60     if (!handler)
       
    61         {
       
    62         CreateHandlerL(aIapId);
       
    63         handler = FindIapIdHandler(aIapId);
       
    64         }
       
    65     
       
    66         PROFILE_DEBUG1("CSIPApnManager::UpdateApnL(), handler exists")
       
    67         handler->UpdateApnL( aIsPrimaryApn, aApn);
       
    68 	}
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // CSIPApnManager::IsFailed
       
    72 // ----------------------------------------------------------------------------
       
    73 //    
       
    74 TBool CSIPApnManager::IsFailed( TUint32 aIapId )
       
    75     {
       
    76     CSIPApnConfigurationHandler* handler = FindIapIdHandler( aIapId );
       
    77     return (handler && handler->IsFailed());
       
    78     }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // CSIPApnManager::SetFailed
       
    82 // Setting back to "not-failed" state is allowed only if fatal failure has not
       
    83 // occured.
       
    84 // ----------------------------------------------------------------------------
       
    85 // 
       
    86 void CSIPApnManager::SetFailed( TUint32 aIapId ,TBool aIsFailed, TBool aIsFatalFailure )
       
    87     {
       
    88     CSIPApnConfigurationHandler* handler = FindIapIdHandler( aIapId );
       
    89     if(handler)
       
    90         {
       
    91         handler->SetFailed( aIsFailed, aIsFatalFailure );
       
    92         }
       
    93     }
       
    94 
       
    95 // ----------------------------------------------------------------------------
       
    96 // CSIPApnManager::IsPrimaryApnInUse
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 TBool CSIPApnManager::IsPrimaryApnInUse( TUint32 aIapId )
       
   100     {
       
   101     CSIPApnConfigurationHandler* handler = FindIapIdHandler( aIapId );
       
   102     return ( handler && handler->IsPrimaryApnUsed() );
       
   103     }
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // CSIPApnManager::WriteApnL
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 void CSIPApnManager::WriteApnL( TUint32 aIapId, TBool aIsPrimaryApn, const TDesC8* aApn )
       
   110 	{
       
   111 	PROFILE_DEBUG3( "CSIPApnManager::WriteApnL isPrimary", aIsPrimaryApn )
       
   112 	TBool useSecureAuth = aIsPrimaryApn ? EFalse : ETrue;
       
   113 
       
   114 	CSIPApnConfigurationHandler* handler = FindIapIdHandler( aIapId );
       
   115 	    if (!handler)
       
   116 	        {
       
   117 	        CreateHandlerL(aIapId);
       
   118 	        handler = FindIapIdHandler(aIapId);
       
   119 	        }
       
   120 	    
       
   121 	    handler->SetApnL( *aApn, useSecureAuth, ETrue);
       
   122 	}
       
   123 
       
   124 // ----------------------------------------------------------------------------
       
   125 // CSIPApnManager::HasPendingTasks
       
   126 // ----------------------------------------------------------------------------
       
   127 //
       
   128 TBool CSIPApnManager::HasPendingTasks() const
       
   129     {    
       
   130     TInt count = iHandlers.Count();
       
   131     PROFILE_DEBUG3( 
       
   132             "CSIPApnManager::HasPendingTasks handler count", count )
       
   133 
       
   134     for ( TInt i = 0; i < count; ++i )
       
   135         {
       
   136         if ( iHandlers[ i ]->HasPendingTasks() )
       
   137             {
       
   138             PROFILE_DEBUG1( 
       
   139                     "CSIPApnManager::HasPendingTasks return ETrue" )
       
   140             return ETrue;
       
   141             }
       
   142         }
       
   143     PROFILE_DEBUG1( 
       
   144             "CSIPApnManager::HasPendingTasks return EFalse" )
       
   145     return EFalse;
       
   146     }
       
   147 // ----------------------------------------------------------------------------
       
   148 // CSIPApnManager::CSIPApnManager
       
   149 // ----------------------------------------------------------------------------
       
   150 //
       
   151 CSIPApnManager::CSIPApnManager( MSIPApnChangeObserver& aObserver ) :
       
   152     iObserver( aObserver )
       
   153     {
       
   154     }
       
   155     
       
   156 // ----------------------------------------------------------------------------
       
   157 // CSIPApnManager::ConstructL
       
   158 // Read APNs from settings file but don't write to CommsDat yet. If IMS profile
       
   159 // has APNs, use them instead. APN is written to CommsDat when the operation
       
   160 // (register, deregister, update..) that caused IMS agent to be loaded, starts
       
   161 // (CSIPIMSProfileAgent::SelectInitialApnL).
       
   162 // ----------------------------------------------------------------------------
       
   163 //    
       
   164 void CSIPApnManager::ConstructL()
       
   165     {
       
   166     PROFILE_DEBUG1("CSIPApnManager::ConstructL()" )  
       
   167     }
       
   168 
       
   169 // ----------------------------------------------------------------------------
       
   170 // CSIPApnManager::FindIapIdHandler
       
   171 // ----------------------------------------------------------------------------
       
   172 //
       
   173 CSIPApnConfigurationHandler* CSIPApnManager::FindIapIdHandler( TUint32 aIapId )
       
   174     {
       
   175     CSIPApnConfigurationHandler* handler = NULL;
       
   176     TBool found(EFalse);
       
   177     
       
   178     for(TInt i =0; i<iHandlers.Count() && !found ; i++)
       
   179         {
       
   180         if (iHandlers[i]->HandlerIapId()== aIapId)
       
   181             {
       
   182             PROFILE_DEBUG3("CSIPApnManager::FindIapIdHandler, found handler for aIapId", aIapId )
       
   183             found = ETrue;
       
   184             handler = iHandlers[ i ];
       
   185             }
       
   186         }
       
   187     
       
   188     return handler;
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CSIPApnManager::CreateHandlerL
       
   193 // ----------------------------------------------------------------------------
       
   194 //
       
   195 void CSIPApnManager::CreateHandlerL( TUint32 aIapId )
       
   196 	{
       
   197     PROFILE_DEBUG1( 
       
   198             "CSIPApnManager::CreateHandlerL , enter" )
       
   199     PROFILE_DEBUG3( 
       
   200         "CSIPApnManager::CreateHandlerL for IapId", aIapId )
       
   201 
       
   202     CSIPApnConfigurationHandler* Handler = 
       
   203         CSIPApnConfigurationHandler::NewL( iObserver, aIapId);
       
   204     CleanupStack::PushL( Handler );
       
   205     iHandlers.AppendL( Handler );
       
   206     CleanupStack::Pop( Handler );
       
   207     PROFILE_DEBUG1( 
       
   208               "CSIPApnManager::CreateHandlerL, exit" )
       
   209 	}
       
   210 
       
   211 // ----------------------------------------------------------------------------
       
   212 // CSIPApnManager::IsIapGPRSL
       
   213 // ----------------------------------------------------------------------------
       
   214 //
       
   215 TBool CSIPApnManager::IsIapGPRSL( TUint32 aIapId )
       
   216     {
       
   217     TBool isIapGPRS(EFalse);          
       
   218     using namespace CommsDat;        
       
   219     CMDBSession* db = CMDBSession::NewL( CMDBSession::LatestVersion() );
       
   220     CleanupStack::PushL( db );
       
   221     // Set any attributes if any
       
   222     db->SetAttributeMask( ECDHidden );    
       
   223     // Create an iap record
       
   224     CCDIAPRecord* iapRecord = 
       
   225             static_cast<CCDIAPRecord*>(
       
   226                     CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) );
       
   227     CleanupStack::PushL( iapRecord );        
       
   228     iapRecord->SetRecordId( aIapId );
       
   229     iapRecord->LoadL( *db );  
       
   230     TPtrC bearerType(iapRecord->iBearerType);
       
   231     if(bearerType.CompareF(TPtrC(KCDTypeNameModemBearer)) == 0)
       
   232         {
       
   233         isIapGPRS = ETrue;
       
   234         }
       
   235     
       
   236     db->ClearAttributeMask( ECDHidden );
       
   237     
       
   238     CleanupStack::PopAndDestroy( iapRecord );
       
   239     CleanupStack::PopAndDestroy( db );
       
   240     PROFILE_DEBUG3(
       
   241                     "CSIPApnConfigurationHandler::IsIapGPRSL(),isIapGPRS", isIapGPRS )
       
   242     return isIapGPRS;
       
   243     }
       
   244 // End of File