gssettingsuis/Gs/GSPDataAccessPointPlugin/src/GSPDataAccessPointModel.cpp
branchRCL_3
changeset 54 7e0eff37aedb
parent 0 8c5d936e5675
equal deleted inserted replaced
53:8ee96d21d9bf 54:7e0eff37aedb
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Model for GSPDataAccessPointPlugin.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "GSPDataAccessPointModel.h"
       
    21 #include    "GsLogger.h"
       
    22 
       
    23 #include    <commdb.h>
       
    24 #include    <featmgr.h>
       
    25 #include    <commdb.h>
       
    26 #include    <settingsinternalcrkeys.h>
       
    27 
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // CGSPDataAccessPointModel::NewL
       
    36 //
       
    37 // EPOC two-phased constructor
       
    38 // ----------------------------------------------------------------------------
       
    39 //
       
    40 CGSPDataAccessPointModel* CGSPDataAccessPointModel::NewL()
       
    41     {
       
    42     CGSPDataAccessPointModel* self = new( ELeave ) CGSPDataAccessPointModel;
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 
       
    50 // ----------------------------------------------------------------------------
       
    51 // CGSPDataAccessPointModel::CGSPDataAccessPointModel
       
    52 //
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 CGSPDataAccessPointModel::CGSPDataAccessPointModel()
       
    58     {
       
    59     __GSLOGSTRING( "[CGSPDataAccessPointModel] CGSPDataAccessPointModel()" );
       
    60     }
       
    61 
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // CGSPDataAccessPointModel::ConstructL
       
    65 //
       
    66 // EPOC default constructor can leave.
       
    67 // ----------------------------------------------------------------------------
       
    68 //
       
    69 void CGSPDataAccessPointModel::ConstructL()
       
    70     {
       
    71     iCommsDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
    72     iNetworkRepository = 
       
    73         CRepository::NewL( KCRUidNetworkSettings );
       
    74     if( FeatureManager::FeatureSupported( KFeatureIdLoggerGprs ) )
       
    75         {
       
    76         User::LeaveIfError( iTelServer.Connect() );
       
    77         User::LeaveIfError( iPhone.Open( iTelServer, KMmTsyPhoneName ) );
       
    78         User::LeaveIfError( iPktService.Open( iPhone ) );
       
    79         }
       
    80     }
       
    81 
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CGSPDataAccessPointModel::~CGSPDataAccessPointModel
       
    85 //
       
    86 // Destructor
       
    87 // ----------------------------------------------------------------------------
       
    88 //
       
    89 CGSPDataAccessPointModel::~CGSPDataAccessPointModel()
       
    90     {
       
    91     if ( iNetworkRepository )
       
    92         {
       
    93         delete iNetworkRepository;
       
    94         }
       
    95     delete iCommsDb;
       
    96     if( FeatureManager::FeatureSupported( KFeatureIdLoggerGprs ) )
       
    97         {
       
    98         iPktService.Close();
       
    99         iPhone.Close();
       
   100         iTelServer.Close();
       
   101         }
       
   102     __GSLOGSTRING( "[CGSPDataConnectionModel] Handles closed." );
       
   103     }
       
   104 
       
   105 
       
   106 // ----------------------------------------------------------------------------
       
   107 // CGSPDataModel::GetDialupAPNameL
       
   108 //
       
   109 // Gets dial-up acces point name.
       
   110 // ----------------------------------------------------------------------------
       
   111 //
       
   112 TInt CGSPDataAccessPointModel::GetDialupAPNameL( TDes& aName )
       
   113     {
       
   114     CCommsDbTableView* table = iCommsDb->OpenTableLC( TPtrC( DEFAULT_GPRS ) );
       
   115     table->GotoFirstRecord();
       
   116 
       
   117     //If dialup AP name is not initialized, ReadTextL will leave
       
   118     TRAPD( error, table->ReadTextL( TPtrC( GPRS_APN), aName ) );
       
   119     CleanupStack::PopAndDestroy( table );
       
   120     return error;
       
   121     }
       
   122 
       
   123 
       
   124 // ----------------------------------------------------------------------------
       
   125 // CGSPDataModel::SetDialupAPNameL
       
   126 //
       
   127 // Sets dial-up acces point name.
       
   128 // ----------------------------------------------------------------------------
       
   129 //
       
   130 void CGSPDataAccessPointModel::SetDialupAPNameL( const TDesC& aName )
       
   131     {
       
   132     CCommsDbTableView* table = iCommsDb->OpenTableLC( TPtrC( DEFAULT_GPRS ) );
       
   133     table->GotoFirstRecord();
       
   134     User::LeaveIfError( table->UpdateRecord() );
       
   135     table->WriteTextL( TPtrC( GPRS_APN ),aName );
       
   136     User::LeaveIfError( table->PutRecordChanges() );
       
   137     CleanupStack::PopAndDestroy( table );
       
   138 
       
   139     if( FeatureManager::FeatureSupported( KFeatureIdLoggerGprs ) )
       
   140         {
       
   141         TRequestStatus status;
       
   142         RPacketContext::TContextConfigGPRS params;
       
   143         TPckg< RPacketContext::TContextConfigGPRS > paramsBuf( params );
       
   144 
       
   145         if ( aName.Length() <= params.iAccessPointName.MaxLength() )
       
   146             {
       
   147             params.iAccessPointName.Copy( aName );
       
   148             iPktService.SetDefaultContextParams( status, paramsBuf );
       
   149             User::WaitForRequest( status );
       
   150             }
       
   151         }
       
   152     }
       
   153 
       
   154 //  End of File