cellular/telephonysettings/src/PsetTelephony.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002 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:  ETEL connection and line opening class.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <etelmm.h>
       
    22 #include <e32svr.h>
       
    23 #include <mmtsy_names.h>
       
    24 #include "psetconstants.h" 
       
    25 #include "psettelephony.h" 
       
    26 #include "phonesettingslogger.h" 
       
    27 
       
    28 //  MEMBER FUNCTIONS
       
    29 // ---------------------------------------------------------------------------
       
    30 // 
       
    31 //  First phase constructor
       
    32 // 
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CPsetTelephony* CPsetTelephony::NewL( 
       
    36     RMobilePhone& aPhone, const TDesC* aTsyName )
       
    37     {
       
    38     CPsetTelephony* self = new ( ELeave ) CPsetTelephony( aPhone );
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL( aTsyName );
       
    41     CleanupStack::Pop();
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // 
       
    47 //  Destructor
       
    48 // 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CPsetTelephony::~CPsetTelephony()
       
    52     {
       
    53     if ( iOwnConnection )
       
    54         {
       
    55         if ( iPhone )
       
    56             {
       
    57             iPhone->Close();
       
    58             }
       
    59         
       
    60         /*****************************************************
       
    61         *    Series 60 Customer / ETel
       
    62         *    Series 60  ETel API
       
    63         *****************************************************/
       
    64         /*****************************************************
       
    65         *    Series 60 Customer / TSY
       
    66         *    Needs customer TSY implementation
       
    67         *****************************************************/
       
    68         if ( iTelServer )
       
    69             {
       
    70             iTelServer->UnloadPhoneModule( iTsyName );
       
    71             iTelServer->Close();
       
    72             }
       
    73         delete iTelServer;
       
    74         iTelServer = NULL;
       
    75         delete iPhone;
       
    76         iPhone = NULL;
       
    77         }
       
    78     } 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // 
       
    82 //  Constructor.
       
    83 // 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CPsetTelephony::ConstructL( const TDesC* aTsyName )                   
       
    87     {
       
    88     User::LeaveIfError( ConnectToEtelL( aTsyName ) );
       
    89     iOwnConnection = ETrue;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // 
       
    94 // Connects to ETel server and loads TSY module, then opens phone object
       
    95 // if phone(s) found.
       
    96 // 
       
    97 // ---------------------------------------------------------------------------
       
    98 TInt CPsetTelephony::ConnectToEtelL( const TDesC* aTsyName )
       
    99     {
       
   100     __PHSLOGSTRING("[PHS]--> CPsetTelephony::ConnectToEtelL");
       
   101     if ( aTsyName )
       
   102         {
       
   103         iTsyName= *aTsyName; // use specific tsy name
       
   104         }
       
   105     else
       
   106         {
       
   107         iTsyName = KMmTsyModuleName; // use default tsy name
       
   108         }
       
   109     
       
   110     iTelServer = new ( ELeave ) RTelServer;    
       
   111     iPhone = new ( ELeave ) RMobilePhone;
       
   112     TInt err = KErrNone;
       
   113     
       
   114     for ( TInt a = 0 ; a < KPSetRetryCount ; a++ )
       
   115         {
       
   116         err = iTelServer->Connect();
       
   117         
       
   118         if ( err == KErrNone )
       
   119             {
       
   120             break;
       
   121             }
       
   122         
       
   123         User::After( KPSetRetryTimeout );
       
   124         }
       
   125     
       
   126     User::LeaveIfError( err );
       
   127     
       
   128     /*****************************************************
       
   129     *    Series 60 Customer / ETel
       
   130     *    Series 60  ETel API
       
   131     *****************************************************/
       
   132     /*****************************************************
       
   133     *    Series 60 Customer / TSY
       
   134     *    Needs customer TSY implementation
       
   135     *****************************************************/
       
   136     err = iTelServer->LoadPhoneModule( iTsyName );
       
   137     
       
   138     if ( err == KErrNone )
       
   139         {
       
   140         iTelServer->SetExtendedErrorGranularity( RTelServer::EErrorExtended );
       
   141         
       
   142         RTelServer::TPhoneInfo phoneInfo;
       
   143         err = iTelServer->GetPhoneInfo( 0, phoneInfo );  
       
   144         if ( err == KErrNone )
       
   145             {
       
   146             // open phone subsession
       
   147             err = iPhone->Open( *iTelServer, phoneInfo.iName ); 
       
   148             }
       
   149         }
       
   150 
       
   151     __PHSLOGSTRING("[PHS] <--CPsetTelephony::ConnectToEtelL");
       
   152     return err;
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // 
       
   157 // Checks that correct line for diverting is open. If not, lines
       
   158 // are gone through and when one with correct capabilities is found,
       
   159 // it is opened.
       
   160 // 
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CPsetTelephony::CheckLineModeL( const TServiceGroup aServiceGroup,
       
   164                                     RMobilePhone* aPhone, RMobileLine* aLine)
       
   165     {
       
   166     __PHSLOGSTRING("[PHS]--> CPsetTelephony::CheckLineModeL");
       
   167     if (!aPhone || !aLine)
       
   168         {
       
   169         User::Leave(KErrArgument);
       
   170         }
       
   171     
       
   172     RLine::TCaps lineCaps;    
       
   173     lineCaps.iFlags = 0;
       
   174     TBool oldMode( EFalse ); // if true, another line must be opened    
       
   175     
       
   176     if ( aLine->SubSessionHandle() == 0 )
       
   177         {
       
   178         oldMode = ETrue;
       
   179         }
       
   180     else
       
   181         {
       
   182         User::LeaveIfError( aLine->GetCaps( lineCaps ) );
       
   183         }
       
   184 
       
   185     TUint32 capsFlags( 0 );
       
   186     capsFlags = SetCapFlagsL( aServiceGroup, oldMode, lineCaps );
       
   187     
       
   188     if ( oldMode )
       
   189         { // open line in right mode according to service group        
       
   190         if ( aLine->SubSessionHandle() )
       
   191             {
       
   192             aLine->Close();        
       
   193             }
       
   194         
       
   195         TInt lines = 0;
       
   196         User::LeaveIfError( aPhone->EnumerateLines( lines ) );
       
   197         //lines is no of lines, to check each line, we need to 
       
   198         // check all lines from 0 to lines-1
       
   199         for (lines--; KPSetNoLinesAvailable < lines; lines-- )
       
   200             {
       
   201             RPhone::TLineInfo lineInfo;
       
   202             User::LeaveIfError( aPhone->GetLineInfo( lines, lineInfo ) );            
       
   203             
       
   204             if ( lineInfo.iLineCapsFlags & capsFlags )
       
   205                 {
       
   206                 User::LeaveIfError( aLine->Open( *aPhone, lineInfo.iName ) );
       
   207                 return;
       
   208                 }
       
   209             }        
       
   210         }
       
   211     __PHSLOGSTRING("[PHS] <--CPsetTelephony::CheckLineModeL");
       
   212     }
       
   213 // ---------------------------------------------------------------------------
       
   214 // 
       
   215 // Sets cap flags.
       
   216 // 
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 TUint32 CPsetTelephony::SetCapFlagsL( 
       
   220     const TServiceGroup aServiceGroup, TBool& aMode, RLine::TCaps& aCaps )
       
   221     {
       
   222     __PHSLOGSTRING("[PHS]--> CPsetTelephony::SetCapFlagsL");
       
   223     TUint32 flags(0);
       
   224 
       
   225     switch ( aServiceGroup )
       
   226         {
       
   227         case EServiceGroupVoice:
       
   228             __PHSLOGSTRING("[PHS]    CPsetTelephony::SetCapFlagsL: EServiceGroupVoice");
       
   229             // always open voice line even because it could have been another 
       
   230             // ALS line which was open
       
   231             aMode = ETrue;
       
   232             flags |= RLine::KCapsVoice;
       
   233             break;
       
   234         case EServiceGroupData:
       
   235             __PHSLOGSTRING("[PHS]    CPsetTelephony::SetCapFlagsL: EServiceGroupData");
       
   236             if ( !( aCaps.iFlags & RLine::KCapsData ) )
       
   237                 {
       
   238                 aMode = ETrue;
       
   239                 }
       
   240             flags |= RLine::KCapsData;
       
   241             break;
       
   242         case EServiceGroupFax:
       
   243             __PHSLOGSTRING("[PHS]    CPsetTelephony::SetCapFlagsL: EServiceGroupFax");
       
   244             if ( !( aCaps.iFlags & RLine::KCapsFax ) )
       
   245                 {
       
   246                 aMode = ETrue;
       
   247                 }
       
   248             flags |= RLine::KCapsFax;
       
   249             break;
       
   250         case EServiceGroupAllTeleservices:
       
   251             __PHSLOGSTRING("[PHS]    CPsetTelephony::SetCapFlagsL: EServiceGroupAllTeleservices");
       
   252             aMode = ETrue;
       
   253             flags |= RLine::KCapsData;
       
   254             flags |= RLine::KCapsFax;
       
   255             flags |= RLine::KCapsVoice;
       
   256             break;
       
   257         default:
       
   258             User::Leave( KErrNotSupported );
       
   259         }
       
   260 
       
   261     __PHSLOGSTRING("[PHS] <--CPsetTelephony::SetCapFlagsL");
       
   262     return flags;
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // 
       
   267 // C++ constructor.
       
   268 // 
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 CPsetTelephony::CPsetTelephony
       
   272                 ( RMobilePhone& aPhone ) : iPhone ( &aPhone )
       
   273     {
       
   274     }
       
   275 //End of file