gssettingsuis/Gs/GSPDataConnectionPlugin/src/GSPDataConnectionModel.cpp
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     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 GSPDataConnectionPlugin.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "GSPDataConnectionModel.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 // Default values for some of the settings
       
    31 const   TUint32 KGSDefaultAttachMode = 0;               // when available
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 
       
    36 // ----------------------------------------------------------------------------
       
    37 // CGSPDataConnectionModel::NewL
       
    38 //
       
    39 // EPOC two-phased constructor
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 CGSPDataConnectionModel* CGSPDataConnectionModel::NewL()
       
    43     {
       
    44     CGSPDataConnectionModel* self = new( ELeave ) CGSPDataConnectionModel;
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop( self );
       
    48     return self;
       
    49     }
       
    50 
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CGSPDataConnectionModel::CGSPDataConnectionModel
       
    54 //
       
    55 // C++ default constructor can NOT contain any code, that
       
    56 // might leave.
       
    57 // ----------------------------------------------------------------------------
       
    58 //
       
    59 CGSPDataConnectionModel::CGSPDataConnectionModel()
       
    60     {
       
    61     iIsFeatureIdLoggerGprs = EFalse;
       
    62     __GSLOGSTRING( "[CGSPDataConnectionModel] CGSPDataConnectionModel()" );
       
    63     }
       
    64 
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // CGSPDataConnectionModel::ConstructL
       
    68 //
       
    69 // EPOC default constructor can leave.
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 void CGSPDataConnectionModel::ConstructL()
       
    73     {
       
    74     iCommsDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
    75     if( FeatureManager::FeatureSupported( KFeatureIdLoggerGprs ) )
       
    76         {
       
    77         iIsFeatureIdLoggerGprs = ETrue;
       
    78         User::LeaveIfError( iTelServer.Connect() );
       
    79         User::LeaveIfError( iPhone.Open( iTelServer, KMmTsyPhoneName ) );
       
    80         User::LeaveIfError( iPktService.Open( iPhone ) );
       
    81         }
       
    82     }
       
    83 
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // CGSPDataConnectionModel::~CGSPDataConnectionModel
       
    87 //
       
    88 // Destructor
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 CGSPDataConnectionModel::~CGSPDataConnectionModel()
       
    92     {
       
    93     delete iCommsDb;
       
    94     if( iIsFeatureIdLoggerGprs )
       
    95         {
       
    96         iPktService.Close();
       
    97         iPhone.Close();
       
    98         iTelServer.Close();
       
    99         }
       
   100     __GSLOGSTRING( "[CGSPDataConnectionModel] Handles closed." );
       
   101     }
       
   102 
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // CGSPDataConnectionModel::PDataAttachL
       
   106 //
       
   107 // Returns packet data attach mode.
       
   108 // ----------------------------------------------------------------------------
       
   109 //
       
   110 TInt CGSPDataConnectionModel::PDataAttachL()
       
   111     {
       
   112     TUint32 attachMode = KGSDefaultAttachMode;
       
   113     TRAPD( error, iCommsDb->GetGlobalSettingL( TPtrC( GPRS_ATTACH_MODE ),
       
   114                                                attachMode ) );
       
   115     if ( error == KErrNotFound )
       
   116         {
       
   117         iCommsDb->SetGlobalSettingL( TPtrC( GPRS_ATTACH_MODE ), attachMode );
       
   118         }
       
   119     else if ( error != KErrNone )
       
   120         {
       
   121         User::Leave( error );
       
   122         }
       
   123     return static_cast<TInt> ( attachMode );
       
   124     }
       
   125 
       
   126 // ----------------------------------------------------------------------------
       
   127 // CGSPDataConnectionModel::SetPDataAttachL
       
   128 //
       
   129 // Sets packet data attach mode.
       
   130 // ----------------------------------------------------------------------------
       
   131 //
       
   132 void CGSPDataConnectionModel::SetPDataAttachL( const TInt aAttach )
       
   133     {
       
   134     iCommsDb->SetGlobalSettingL( TPtrC( GPRS_ATTACH_MODE ), aAttach );
       
   135 
       
   136     if( FeatureManager::FeatureSupported( KFeatureIdLoggerGprs ) )
       
   137         {
       
   138         TRequestStatus status;
       
   139         RPacketService::TAttachMode mode(
       
   140             static_cast<RPacketService::TAttachMode> ( aAttach ) );
       
   141         iPktService.SetAttachMode( status, mode );
       
   142         User::WaitForRequest( status );
       
   143         }
       
   144         
       
   145     }  
       
   146 //  End of File