telutils/phoneparser/src/CPhoneGsmParser.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:  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     {
       
    48     // Ownership of these instances is transferred, thus
       
    49     // creation of the instance must not leave. 
       
    50 
       
    51     CPhoneGsmParser* self = 
       
    52         new CPhoneGsmParser(
       
    53             aSsProcedure,
       
    54             aSimControlProcedure,
       
    55             aPhoneNumber,
       
    56             aManufacturerSpecific,
       
    57             aEmergencyNumberParser,
       
    58             aVoipNumber);
       
    59     
       
    60     if ( !self )
       
    61         {
       
    62         delete aSsProcedure;
       
    63         delete aSimControlProcedure;
       
    64         delete aPhoneNumber;
       
    65         delete aManufacturerSpecific;
       
    66         delete aEmergencyNumberParser;
       
    67         delete aVoipNumber;
       
    68         
       
    69         User::Leave( KErrNoMemory );
       
    70         }
       
    71 
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL();
       
    74     CleanupStack::Pop( self );
       
    75 
       
    76     return self;
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CPhoneGsmParser::~CPhoneGsmParser
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CPhoneGsmParser::~CPhoneGsmParser()
       
    84     {
       
    85     delete iGsmSsProcedure;
       
    86     delete iGsmSimControlProcedure;
       
    87     delete iGsmPhoneNumber;
       
    88     delete iGsmManufacturerProcedure;
       
    89     delete iGsmEmergencyNumber;
       
    90     delete iVoipNumber;
       
    91     CPhoneParserFeatures::Free();
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CPhoneGsmParser::CPhoneGsmParser
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CPhoneGsmParser::CPhoneGsmParser( 
       
    99         CPhoneGsmParserBase* aSsProcedure,
       
   100         CPhoneGsmParserBase* aSimControlProcedure,
       
   101         CPhoneGsmParserBase* aPhoneNumber,
       
   102         CPhoneGsmParserBase* aManufacturerSpecific,
       
   103         CPhoneGsmParserBase* aEmergencyNumberParser,
       
   104         CPhoneGsmParserBase* aVoipNumber)
       
   105     : iGsmSsProcedure( aSsProcedure ), 
       
   106       iGsmSimControlProcedure( aSimControlProcedure ),
       
   107       iGsmPhoneNumber( aPhoneNumber ),
       
   108       iGsmManufacturerProcedure( aManufacturerSpecific ),
       
   109       iGsmEmergencyNumber( aEmergencyNumberParser ),
       
   110       iVoipNumber( aVoipNumber )
       
   111     {
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CPhoneGsmParser::ConstructL
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CPhoneGsmParser::ConstructL()
       
   119     {
       
   120     // If we didn't receive a parser for something, then create dummy.
       
   121 
       
   122     if ( !iGsmSsProcedure )
       
   123         {
       
   124         iGsmSsProcedure = CPhoneGsmDummyParser::NewL();
       
   125         }
       
   126     if ( !iGsmSimControlProcedure )
       
   127         {
       
   128         iGsmSimControlProcedure = CPhoneGsmDummyParser::NewL();
       
   129         }
       
   130     if ( !iGsmPhoneNumber )
       
   131         {
       
   132         iGsmPhoneNumber = CPhoneGsmDummyParser::NewL();
       
   133         }
       
   134     if ( !iGsmManufacturerProcedure )
       
   135         {
       
   136         iGsmManufacturerProcedure = CPhoneGsmDummyParser::NewL();
       
   137         }
       
   138     if ( !iGsmEmergencyNumber )
       
   139         {
       
   140         iGsmEmergencyNumber = CPhoneGsmDummyParser::NewL();
       
   141         }
       
   142     if ( !iVoipNumber )
       
   143         {
       
   144         iVoipNumber = CPhoneGsmDummyParser::NewL();
       
   145         }
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CPhoneGsmParser::ParseL
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 TBool CPhoneGsmParser::ParseL( 
       
   153         const TDesC& aString, 
       
   154         CPhoneGsmParserResult& aResult,
       
   155         CPhoneGsmOptionContainerBase& aOptions )
       
   156     {
       
   157     TBool result = EFalse;
       
   158         
       
   159     result = DoParseL(
       
   160             aString,
       
   161             aResult, 
       
   162             static_cast<CPhoneGsmOptionContainer&>( aOptions ) );
       
   163 
       
   164     if ( !result )
       
   165         {
       
   166         aResult.ClearL();
       
   167         }
       
   168 
       
   169     return result;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CPhoneGsmParser::DoParseL
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 TBool CPhoneGsmParser::DoParseL( 
       
   177         const TDesC& aString,
       
   178         CPhoneGsmParserResult& aResult,
       
   179         CPhoneGsmOptionContainer& aOptions )
       
   180     {
       
   181     TBool result = EFalse;
       
   182     aResult.ClearL();
       
   183 
       
   184     // We do not handle empty strings.
       
   185     if ( !aString.Length() )
       
   186         {
       
   187         return EFalse;
       
   188         }
       
   189 
       
   190     TBool sendOperation = aOptions.FindOptionStatus( KPhoneOptionSend );
       
   191     
       
   192     // Check if emergency number.
       
   193     result = iGsmEmergencyNumber->ParseL( aString, aResult, aOptions );
       
   194     
       
   195     // First check if string is GSM ss procedure supported by MS.
       
   196     if ( !result )
       
   197         {
       
   198         result = iGsmSsProcedure->ParseL( aString, aResult, aOptions );
       
   199         }
       
   200         
       
   201     if ( !result )
       
   202         {
       
   203         // Check if it is sim control procedure.
       
   204         result = iGsmSimControlProcedure->ParseL( aString, aResult, aOptions );
       
   205         }
       
   206 
       
   207     if ( !result )
       
   208         {
       
   209         // Check if it is manufacturer specific procedure.
       
   210         result = 
       
   211             iGsmManufacturerProcedure->ParseL( aString, aResult, aOptions );
       
   212         }
       
   213     if ( !result )
       
   214         {
       
   215         // Check if it voip call.
       
   216         result = iVoipNumber->ParseL( aString, aResult, aOptions );
       
   217         }
       
   218     if ( !result )
       
   219         {
       
   220         result = iGsmPhoneNumber->ParseL( aString, aResult, aOptions );
       
   221         }
       
   222     if ( !result )
       
   223         {
       
   224         result = DefineAsUssdL( aString, aResult, aOptions );
       
   225         } 
       
   226 
       
   227     return result;
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CPhoneGsmParser::DefineAsUssd
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TBool CPhoneGsmParser::DefineAsUssdL( 
       
   235         const TDesC& aString,
       
   236         CPhoneGsmParserResult& aResult,
       
   237         CPhoneGsmOptionContainer& aOptions )
       
   238     {
       
   239     aResult.ClearL();
       
   240     
       
   241     TBool result = aOptions.FindOptionStatus( KPhoneOptionSend );
       
   242     if ( result )
       
   243         {
       
   244         aResult.SetUid( KPhoneUidUnstructuredService );
       
   245         aResult.AddParameterL( aString );
       
   246         }
       
   247     return result;
       
   248     }
       
   249 
       
   250 //  End of File