telutils/phoneparser/src/CPhoneGsmParser.cpp
changeset 0 ff3b6d0fd310
child 12 ae8abd0db65c
child 43 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     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:  Principal parsing process is defined by the CPhoneGsmParser
       
    15 *                class.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <bldvariant.hrh>
       
    22 
       
    23 #include    "CPhoneGsmParser.h"
       
    24 #include    "CPhoneGsmParserResult.h"
       
    25 #include    "CPhoneGsmParserBase.h"
       
    26 #include    "CPhoneGsmDummyParser.h"
       
    27 #include    "CPhoneGsmOptionContainer.h"
       
    28 #include    "CPhoneParserFeatures.h"
       
    29 #include    "CPhoneGsmOptionContainerBase.h"
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CPhoneGsmParser::NewL
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CPhoneGsmParser* CPhoneGsmParser::NewL( 
       
    41         CPhoneGsmParserBase* aSsProcedure,
       
    42         CPhoneGsmParserBase* aSimControlProcedure,
       
    43         CPhoneGsmParserBase* aPhoneNumber,
       
    44         CPhoneGsmParserBase* aManufacturerSpecific,
       
    45         CPhoneGsmParserBase* aEmergencyNumberParser,
       
    46         CPhoneGsmParserBase* aVoipNumber,
       
    47         CPhoneGsmParserBase* aImeiParser )
       
    48     {
       
    49     // Ownership of these instances is transferred, thus
       
    50     // creation of the instance must not leave. 
       
    51 
       
    52     CPhoneGsmParser* self = 
       
    53         new CPhoneGsmParser(
       
    54             aSsProcedure,
       
    55             aSimControlProcedure,
       
    56             aPhoneNumber,
       
    57             aManufacturerSpecific,
       
    58             aEmergencyNumberParser,
       
    59             aVoipNumber,
       
    60             aImeiParser );
       
    61     
       
    62     if ( !self )
       
    63         {
       
    64         delete aSsProcedure;
       
    65         delete aSimControlProcedure;
       
    66         delete aPhoneNumber;
       
    67         delete aManufacturerSpecific;
       
    68         delete aEmergencyNumberParser;
       
    69         delete aVoipNumber;
       
    70         delete aImeiParser;
       
    71         
       
    72         User::Leave( KErrNoMemory );
       
    73         }
       
    74 
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78 
       
    79     return self;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CPhoneGsmParser::~CPhoneGsmParser
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CPhoneGsmParser::~CPhoneGsmParser()
       
    87     {
       
    88     delete iGsmSsProcedure;
       
    89     delete iGsmSimControlProcedure;
       
    90     delete iGsmPhoneNumber;
       
    91     delete iGsmManufacturerProcedure;
       
    92     delete iGsmEmergencyNumber;
       
    93     delete iVoipNumber;
       
    94     delete iImeiParser;
       
    95     CPhoneParserFeatures::Free();
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CPhoneGsmParser::CPhoneGsmParser
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 CPhoneGsmParser::CPhoneGsmParser( 
       
   103         CPhoneGsmParserBase* aSsProcedure,
       
   104         CPhoneGsmParserBase* aSimControlProcedure,
       
   105         CPhoneGsmParserBase* aPhoneNumber,
       
   106         CPhoneGsmParserBase* aManufacturerSpecific,
       
   107         CPhoneGsmParserBase* aEmergencyNumberParser,
       
   108         CPhoneGsmParserBase* aVoipNumber,
       
   109         CPhoneGsmParserBase* aImeiParser )
       
   110     : iGsmSsProcedure( aSsProcedure ), 
       
   111       iGsmSimControlProcedure( aSimControlProcedure ),
       
   112       iGsmPhoneNumber( aPhoneNumber ),
       
   113       iGsmManufacturerProcedure( aManufacturerSpecific ),
       
   114       iGsmEmergencyNumber( aEmergencyNumberParser ),
       
   115       iVoipNumber( aVoipNumber ),
       
   116       iImeiParser( aImeiParser )
       
   117     {
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CPhoneGsmParser::ConstructL
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CPhoneGsmParser::ConstructL()
       
   125     {
       
   126     // If we didn't receive a parser for something, then create dummy.
       
   127 
       
   128     if ( !iGsmSsProcedure )
       
   129         {
       
   130         iGsmSsProcedure = CPhoneGsmDummyParser::NewL();
       
   131         }
       
   132     if ( !iGsmSimControlProcedure )
       
   133         {
       
   134         iGsmSimControlProcedure = CPhoneGsmDummyParser::NewL();
       
   135         }
       
   136     if ( !iGsmPhoneNumber )
       
   137         {
       
   138         iGsmPhoneNumber = CPhoneGsmDummyParser::NewL();
       
   139         }
       
   140     if ( !iGsmManufacturerProcedure )
       
   141         {
       
   142         iGsmManufacturerProcedure = CPhoneGsmDummyParser::NewL();
       
   143         }
       
   144     if ( !iGsmEmergencyNumber )
       
   145         {
       
   146         iGsmEmergencyNumber = CPhoneGsmDummyParser::NewL();
       
   147         }
       
   148     if ( !iVoipNumber )
       
   149         {
       
   150         iVoipNumber = CPhoneGsmDummyParser::NewL();
       
   151         }
       
   152     if ( !iImeiParser )
       
   153         {
       
   154         iImeiParser = CPhoneGsmDummyParser::NewL();
       
   155         }
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CPhoneGsmParser::ParseL
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TBool CPhoneGsmParser::ParseL( 
       
   163         const TDesC& aString, 
       
   164         CPhoneGsmParserResult& aResult,
       
   165         CPhoneGsmOptionContainerBase& aOptions )
       
   166     {
       
   167     TBool result = EFalse;
       
   168         
       
   169     result = DoParseL(
       
   170             aString,
       
   171             aResult, 
       
   172             static_cast<CPhoneGsmOptionContainer&>( aOptions ) );
       
   173 
       
   174     if ( !result )
       
   175         {
       
   176         aResult.ClearL();
       
   177         }
       
   178 
       
   179     return result;
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CPhoneGsmParser::DoParseL
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 TBool CPhoneGsmParser::DoParseL( 
       
   187         const TDesC& aString,
       
   188         CPhoneGsmParserResult& aResult,
       
   189         CPhoneGsmOptionContainer& aOptions )
       
   190     {
       
   191     TBool result = EFalse;
       
   192     aResult.ClearL();
       
   193 
       
   194     // We do not handle empty strings.
       
   195     if ( !aString.Length() )
       
   196         {
       
   197         return EFalse;
       
   198         }
       
   199 
       
   200     TBool sendOperation = aOptions.FindOptionStatus( KPhoneOptionSend );
       
   201 
       
   202     // Check if it is the only phone control string, show imei.
       
   203     result = iImeiParser->ParseL( aString, aResult, aOptions );
       
   204     
       
   205     // Check if emergency number.
       
   206     if ( !result )
       
   207         {
       
   208         result = iGsmEmergencyNumber->ParseL( aString, aResult, aOptions );
       
   209         }
       
   210     
       
   211     // First check if string is GSM ss procedure supported by MS.
       
   212     if ( !result )
       
   213         {
       
   214         result = iGsmSsProcedure->ParseL( aString, aResult, aOptions );
       
   215         }
       
   216         
       
   217     if ( !result )
       
   218         {
       
   219         // Check if it is sim control procedure.
       
   220         result = iGsmSimControlProcedure->ParseL( aString, aResult, aOptions );
       
   221         }
       
   222 
       
   223     if ( !result )
       
   224         {
       
   225         // Check if it is manufacturer specific procedure.
       
   226         result = 
       
   227             iGsmManufacturerProcedure->ParseL( aString, aResult, aOptions );
       
   228         }
       
   229     if ( !result )
       
   230         {
       
   231         // Check if it voip call.
       
   232         result = iVoipNumber->ParseL( aString, aResult, aOptions );
       
   233         }
       
   234     if ( !result )
       
   235         {
       
   236         result = iGsmPhoneNumber->ParseL( aString, aResult, aOptions );
       
   237         }
       
   238     if ( !result )
       
   239         {
       
   240         result = DefineAsUssdL( aString, aResult, aOptions );
       
   241         } 
       
   242 
       
   243     return result;
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CPhoneGsmParser::DefineAsUssd
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 TBool CPhoneGsmParser::DefineAsUssdL( 
       
   251         const TDesC& aString,
       
   252         CPhoneGsmParserResult& aResult,
       
   253         CPhoneGsmOptionContainer& aOptions )
       
   254     {
       
   255     aResult.ClearL();
       
   256     
       
   257     TBool result = aOptions.FindOptionStatus( KPhoneOptionSend );
       
   258     if ( result )
       
   259         {
       
   260         aResult.SetUid( KPhoneUidUnstructuredService );
       
   261         aResult.AddParameterL( aString );
       
   262         }
       
   263     return result;
       
   264     }
       
   265 
       
   266 //  End of File