phoneclientserver/EnPolicy/Src/SosEnPolicy/CSosEnPolicyENListHandler.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2004-2005 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:  Shared Data Monitor
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "csosenpolicyenlisthandler.h" 
       
    21 #include <e32property.h>
       
    22 #include <centralrepository.h>
       
    23 #include <telservicesinternalcrkeys.h>
       
    24 #include <defaultemergencynumberscrkeys.h>
       
    25 
       
    26 // FUNCTIONS
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CSosEnPolicyENListHandler::NewL
       
    30 // Two-phased constructor.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CSosEnPolicyENListHandler* CSosEnPolicyENListHandler::NewL( 
       
    34      )
       
    35     {
       
    36     CSosEnPolicyENListHandler* self = new ( ELeave ) 
       
    37         CSosEnPolicyENListHandler();
       
    38 
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop();
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CSosEnPolicyENListHandler::~CSosEnPolicyENListHandler()
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CSosEnPolicyENListHandler::~CSosEnPolicyENListHandler()
       
    50     {
       
    51     if ( iListener )
       
    52         {
       
    53         iListener->StopListening();
       
    54         delete iListener;
       
    55         }
       
    56     delete iRepository;
       
    57     
       
    58     iProductSpecificList.Zero();
       
    59     iCurrentList.Zero();
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CSosEnPolicyENListHandler::CSosEnPolicyENListHandler
       
    64 // C++ constructor can NOT contain any code, that
       
    65 // might leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CSosEnPolicyENListHandler::CSosEnPolicyENListHandler( 
       
    69     )
       
    70     {
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CSosEnPolicyENListHandler::ConstructL
       
    75 // Construction, 2nd phase.
       
    76 // -----------------------------------------------------------------------------
       
    77 //        
       
    78 void CSosEnPolicyENListHandler::ConstructL()
       
    79     {
       
    80     ClearCurrentList();
       
    81     iRepository = CRepository::NewL( KCRUidDefaultEmergencyNumbers );
       
    82     iListener = CCenRepNotifyHandler::NewL( 
       
    83         *this, 
       
    84         *iRepository, 
       
    85         CCenRepNotifyHandler::EStringKey, 
       
    86         KDefaultEmergencyNumbersList);
       
    87     
       
    88     iListener->StartListeningL();
       
    89     }
       
    90 
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CSosEnPolicyENListHandler::AddToList
       
    94 // 
       
    95 // Adds number to list with separator.
       
    96 // If numbers are set to permanent, also list start index is updated. 
       
    97 // Permanent numbers must be in the beginning of the list,
       
    98 // so SIM numbers are removed before writing!
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CSosEnPolicyENListHandler::AddToList( 
       
   102     const TDesC& aNumber, 
       
   103     TBool aPermanent ) 
       
   104     {
       
   105     TInt length = aNumber.Length();
       
   106     if ( length > 0 ) // for null string do nothing
       
   107         {
       
   108         // Remove non permanent numbers
       
   109         if ( aPermanent )
       
   110             {
       
   111             ClearCurrentList();
       
   112             }
       
   113         // Write new ones
       
   114     
       
   115         for ( TInt i = 0; i < length; i++ )
       
   116             {
       
   117             iCurrentList[ iCurrentListPlace ] = aNumber[i];
       
   118             iCurrentListPlace++;
       
   119             }
       
   120         iCurrentListPlace++;
       
   121         // Update starting point
       
   122         if ( aPermanent )
       
   123             {
       
   124             iCurrentListStart = iCurrentListPlace;
       
   125             }
       
   126         }
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CSosEnPolicyENListHandler::ClearCurrentList
       
   131 // 
       
   132 // Clears list to be written to Central Repository.
       
   133 // Does not clear permanent numbers, from the begining of list
       
   134 // There is always 112 or 911 (WCDMA) and optionally product specific numbers.
       
   135 // Basically only deleted numbers are SIM emergency numbers.
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CSosEnPolicyENListHandler::ClearCurrentList()
       
   139     {
       
   140     iCurrentList.SetLength( KEnPolicySDEmergencyNumberListLength );
       
   141     iCurrentListPlace = iCurrentListStart;
       
   142     for ( TInt i = iCurrentListStart; 
       
   143           i < KEnPolicySDEmergencyNumberListLength; 
       
   144           i++ )
       
   145         {
       
   146         iCurrentList[i] = KEnPolicySDNumberSeparator;
       
   147         }
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CSosEnPolicyENListHandler::IsInListByAdvancedMode
       
   152 // 
       
   153 // Checks if the number is in list by advanced mode check.
       
   154 //
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TBool CSosEnPolicyENListHandler::IsInListByAdvancedMode ( TDes& aNumber )
       
   158     {    
       
   159     TLex list( iCurrentList );
       
   160     TLexMark mark;
       
   161     TPtrC token_candidate( KNullDesC() ); 
       
   162     
       
   163     for ( TInt i = 0; i < KEnPolicySDEmergencyNumberListLength; i++ )
       
   164         {
       
   165         list.Mark( mark );
       
   166         list.SkipCharacters();
       
   167         TPtrC token;
       
   168         token.Set( list.MarkedToken( mark ) );
       
   169         if ( token.Length() && ( token == aNumber.Right( token.Length() ) ) )
       
   170             {
       
   171             // _DDPRINT( 4, "ENPolicy.SDM.IsInListAdvanced.ok.", place );
       
   172             if( token_candidate == KNullDesC )
       
   173                 { 
       
   174                 token_candidate.Set( token ); 
       
   175                 } 
       
   176             else 
       
   177                 { 
       
   178                 if( token.Length() > token_candidate.Length() ) 
       
   179                     { 
       
   180                     token_candidate.Set( token );     
       
   181                     } 
       
   182                 } 
       
   183             } 
       
   184         list.Inc(); 
       
   185         } 
       
   186 
       
   187     if( token_candidate != KNullDesC ) 
       
   188         { 
       
   189         aNumber = token_candidate; 
       
   190         return ETrue; 
       
   191         }    
       
   192     return EFalse;
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CSosEnPolicyENListHandler::IsInListByNormalMode
       
   197 // 
       
   198 // Checks if the number is in list by normal mode check.
       
   199 //
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 TBool CSosEnPolicyENListHandler::IsInListByNormalMode( 
       
   203     const TDesC& aNumber )
       
   204     {
       
   205     TInt length = aNumber.Length();
       
   206     TInt place = iCurrentList.Find( aNumber ); // first number of aNumber
       
   207 
       
   208     // _DDPRINT( 4, "ENPolicy.SDM.IsInListNormal.ok.", place );  // debug print
       
   209 
       
   210     if ( place < 0 )
       
   211         {
       
   212         // negative value is an error, not found!
       
   213         // return immediately
       
   214         return EFalse;
       
   215         }
       
   216 
       
   217     TInt endOfMatch = place + length; // end of number + 1
       
   218 
       
   219     // we check the begining
       
   220     if ( place > 0 )
       
   221         {
       
   222         // we are not in the begining of buffer, so we have to check
       
   223         // char before that
       
   224         if ( iCurrentList[ place -1 ] != KEnPolicySDNumberSeparator )
       
   225             {
       
   226             // this was just a substring numbers before that
       
   227             return EFalse;
       
   228             }
       
   229         }
       
   230 
       
   231     // beginning was ok, so we can continue
       
   232     
       
   233     // now checking the end
       
   234     // there must be atleast one empty space in the end that
       
   235     // we do the checking of number end.
       
   236     if ( endOfMatch < ( iCurrentList.Length() - 2 ) )
       
   237         {
       
   238         if ( iCurrentList[ endOfMatch ] != KEnPolicySDNumberSeparator )
       
   239             {
       
   240             return EFalse;
       
   241             }
       
   242         }
       
   243 
       
   244     // if we get so far, its ok.
       
   245     return ETrue;
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CSosEnPolicyENListHandler::ReadProductSpecificNumbers
       
   250 // 
       
   251 // Reads product specific values from Central Repository.
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 const TDesC& CSosEnPolicyENListHandler::ReadProductSpecificNumbers()
       
   255     {
       
   256     // This is done only once in bootup phase.
       
   257     iProductSpecificList.Zero();
       
   258 
       
   259     TInt err = KErrNone;
       
   260     err = iRepository->Get( KDefaultEmergencyNumbersList, 
       
   261                             iProductSpecificList );
       
   262 
       
   263     if ( err != KErrNone )
       
   264         {
       
   265         iProductSpecificList.Zero();
       
   266         }
       
   267 
       
   268     // _DDPRINT( 4, "ENPolicy.SDM.ReadPSN.list", iProductSpecificList );
       
   269 
       
   270     return iProductSpecificList;
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CDosEmergencyNumberPolicy::HandleNotifyString
       
   275 // 
       
   276 // Inherited from MCenRepNotifyHandlerCallback.
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 void CSosEnPolicyENListHandler::HandleNotifyString( 
       
   280     TUint32 aId, const TDesC16& aNewValue )
       
   281     {
       
   282     if( aId == KDefaultEmergencyNumbersList )
       
   283         {
       
   284         iProductSpecificList.Zero();
       
   285         iProductSpecificList.Copy( aNewValue );
       
   286         
       
   287         ClearCurrentList();
       
   288         AddToList( iProductSpecificList );
       
   289         }
       
   290     }
       
   291 
       
   292 //  End of File