vmbx/vmbxengine/src/vmbxpbkstore.cpp
branchRCL_3
changeset 19 7d48bed6ce0c
equal deleted inserted replaced
18:594d59766373 19:7d48bed6ce0c
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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:  Implementation of the CVmbxPbkStore class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <commonphoneparser.h>
       
    21 #include <mpbutil.h>
       
    22 #include <cvoicemailboxentry.h>
       
    23 
       
    24 #include "vmbxutilities.h"
       
    25 #include "vmbxetelconnection.h"
       
    26 #include "vmbxlogger.h"
       
    27 #include "vmbxpbkstore.h"
       
    28 
       
    29 #include <e32property.h>
       
    30 #include <simutils.h>
       
    31 #include <startupdomainpskeys.h>
       
    32 //CONSTANTS
       
    33 // Amount of retries to be performed.
       
    34 const TInt KVmbxPhonebookBufferSize( 150 );
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS =============================
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CVmbxPbkStore::CVmbxPbkStore
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CVmbxPbkStore::CVmbxPbkStore(): CActive(EPriorityStandard ),
       
    45                                 iAsynType( EVmbxSimDefault )
       
    46     {
       
    47     VMBLOGSTRING( "VMBX: CVmbxPbkStore::CVmbxPbkStore =>" );
       
    48     CActiveScheduler::Add( this );
       
    49     VMBLOGSTRING( "VMBX: CVmbxPbkStore::CVmbxPbkStore <=" );
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CVmbxPbkStore::~CVmbxPbkStore
       
    54 // destructor
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CVmbxPbkStore:: ~CVmbxPbkStore()
       
    58     {
       
    59     VMBLOGSTRING( "VMBX: CVmbxPbkStore::~CVmbxPbkStore =>" );
       
    60     Cancel();
       
    61     iPhoneBook.Close();
       
    62     delete iWait;
       
    63     delete iETelConnection;
       
    64     VMBLOGSTRING( "VMBX: CVmbxPbkStore::~CVmbxPbkStore <=" );
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CVmbxPbkStore::NewL
       
    69 // two phase constructor
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CVmbxPbkStore* CVmbxPbkStore::NewL()
       
    73     {
       
    74     VMBLOGSTRING( "VMBX: CVmbxPbkStore::NewL =>" );
       
    75     CVmbxPbkStore* self = new( ELeave ) CVmbxPbkStore();
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     CleanupStack::Pop( self );
       
    79     VMBLOGSTRING( "VMBX: CVmbxPbkStore::NewL <=" );
       
    80     return self;
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CVmbxPbkStore::ConstructL
       
    85 // two phase constructor
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CVmbxPbkStore::ConstructL()
       
    89     {
       
    90     VMBLOGSTRING( "VMBX: CVmbxPbkStore::ConstructL =>" );
       
    91     TInt value( 0 );
       
    92     TInt res = RProperty::Get( KPSUidStartup, KPSSimStatus, value );
       
    93     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::ConstructL res = %d", res );
       
    94     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::ConstructL value = %d", value );
       
    95     if ( (ESimUsable != value && ESimReadable != value ) || KErrNone != res )
       
    96         {
       
    97         // Sim card not ready to use
       
    98         User::Leave( KErrNotReady );
       
    99         }
       
   100     // Open tel server and phone
       
   101     iETelConnection = CVmbxETelConnection::NewL();
       
   102 
       
   103     iWait = new( ELeave ) CActiveSchedulerWait; 
       
   104     TVmbxAlsLineType alsLine = VmbxUtilities::AlsLine();
       
   105 
       
   106     // Supported ALS line,ALS line on
       
   107     if ( EVmbxAlsLineDefault != alsLine )
       
   108         {
       
   109         // open 6f17 file ,if not found the file, leave
       
   110         User::LeaveIfError( OpenVmbxPhonebook() );
       
   111         }
       
   112     // Not supported ALS line,ALS line off
       
   113     else
       
   114         {
       
   115         // Open 6fc7 file, if not found, open 6f17 file
       
   116         TInt result = OpenMbdnPhonebook();
       
   117         if ( KErrPathNotFound == result )
       
   118             {
       
   119             //close 6fc7 and open 6f17 file
       
   120             iPhoneBook.Close();
       
   121             // open 6f17 file ,if not found the file, leave
       
   122             User::LeaveIfError( OpenVmbxPhonebook() );
       
   123             }
       
   124         else
       
   125             {
       
   126             User::LeaveIfError( result );
       
   127             }
       
   128         }
       
   129     VMBLOGSTRING( "VMBX: CVmbxPbkStore::ConstructL <=" );
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CVmbxPbkStore::GetVmbxInfo
       
   134 // Activates phonebook info query
       
   135 // ---------------------------------------------------------------------------
       
   136 TInt CVmbxPbkStore::GetVmbxInfo( 
       
   137         RMobilePhoneBookStore::TMobilePhoneBookInfoV1& aInfo )
       
   138     {
       
   139     VMBLOGSTRING( "VMBX: CVmbxPbkStore::GetVmbxInfo =>" );
       
   140     TInt result( KErrInUse );
       
   141     RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg
       
   142                                             InfoPckg( aInfo );
       
   143     // get Info from phonebook
       
   144     if( !IsActive() && !iWait->IsStarted() )
       
   145         {
       
   146         iPhoneBook.GetInfo( iStatus, InfoPckg );
       
   147         iAsynType = EVmbxSimGetInfo;
       
   148         SetActive();
       
   149         iWait->Start();
       
   150 
       
   151         result = iStatus.Int();
       
   152         VMBLOGSTRING2( "VMBX: CVmbxPbkStore::PhonebookInfo: \
       
   153                 SIM Phonebook info read, status: %I", result );
       
   154         }
       
   155     VMBLOGSTRING( "VMBX: CVmbxPbkStore::GetVmbxInfo <=" );
       
   156     return result;
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CVmbxPbkStore::IsWritable
       
   161 // Sim write support
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 TBool CVmbxPbkStore::IsWritable()
       
   165     {
       
   166     VMBLOGSTRING( "VMBX: CVmbxPbkStore::IsWritable =>" );
       
   167     TBool result( EFalse );
       
   168     if ( IsWriteAccess() )
       
   169         {
       
   170         // Get current sim entry, then write the same entry 
       
   171         // to sim if read successufully
       
   172         CVoiceMailboxEntry* simEntry(NULL);
       
   173         TRAPD( newErr, simEntry = CVoiceMailboxEntry::NewL() );
       
   174         VMBLOGSTRING2( "VMBX: CVmbxPbkStore::IsWritable newErr = %d ",
       
   175             newErr );
       
   176         if ( KErrNone == newErr )
       
   177             {
       
   178             // get als line info
       
   179             TVmbxAlsLineType alsLine = VmbxUtilities::AlsLine();
       
   180             simEntry->SetVmbxAlsLineType( alsLine );
       
   181             // ALS line off
       
   182             if ( IsSimFileExisting(EMBDNPhoneBook) && (EVmbxAlsLineDefault == alsLine) )
       
   183                 {
       
   184                 // ALS line on and 6f17 exist 
       
   185                 // just check 6f17 file write access
       
   186                 iPhoneBookType = EMBDNPhoneBook;
       
   187                 }
       
   188             else
       
   189                 {
       
   190                 // ALS line on, only should write to 6fc7; ALS off, 6f17 file inexist
       
   191                 //  check 6fc7 file write access
       
   192                 iPhoneBookType = EVMBXPhoneBook;
       
   193                 }
       
   194             simEntry->SetVoiceMailboxType( EVmbxVoice );
       
   195             simEntry->SetServiceId( KVmbxServiceVoice );
       
   196             TRAPD( err, SimReadL( *simEntry ) );
       
   197             VMBLOGSTRING2( "VMBX: CVmbxPbkStore:: IsWritable read %I <=", err );
       
   198             if ( KErrNotFound == err )
       
   199                 {
       
   200                 simEntry->SetVmbxNumber( KNullDesC );
       
   201                 }
       
   202             if ( KErrNone == err || KErrNotFound == err )
       
   203                 {
       
   204                 err = Write( *simEntry );
       
   205                 VMBLOGSTRING2( "VMBX: CVmbxPbkStore:: IsWritable write %I <=",
       
   206                     err );
       
   207                 // If write successfully, means writable
       
   208                 if ( KErrNone == err )
       
   209                     {
       
   210                     result = ETrue;
       
   211                     }
       
   212                 }
       
   213             }
       
   214         delete simEntry;
       
   215         simEntry = NULL;
       
   216         }
       
   217     VMBLOGSTRING2( "VMBX: CVmbxPbkStore:: IsWritable result %I <=", result );
       
   218     return result;
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CVmbxPbkStore::PhoneBookType
       
   223 // PhoneBookType
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 TVmbxSimPhonebookType CVmbxPbkStore::PhoneBookType()
       
   227     {
       
   228     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::PhoneBookType type %I", 
       
   229                          iPhoneBookType );
       
   230     return iPhoneBookType;
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CVmbxPbkStore::Write
       
   235 // Write to SIM
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 TInt CVmbxPbkStore::Write( const CVoiceMailboxEntry& aEntry )
       
   239     {
       
   240     VMBLOGSTRING( "VMBX: CVmbxPbkStore::Write =>" );
       
   241     TInt result( KErrInUse );
       
   242     TBuf8<KVmbxPhonebookBufferSize> pbData;
       
   243 
       
   244     CPhoneBookBuffer* pbkBuffer = new CPhoneBookBuffer();
       
   245     
       
   246     if ( !pbkBuffer )
       
   247         {
       
   248         VMBLOGSTRING( "VMBX: CVmbxPbkStore::Write: \
       
   249         Phonebook creation error" );
       
   250         result = KErrNoMemory;
       
   251         }
       
   252     else
       
   253         {
       
   254         pbkBuffer->Set( &pbData );
       
   255         TInt activeAlsLine = aEntry.VmbxAlsLineType();
       
   256         // Add index, const value for vmbx write.
       
   257         int entryIndex = 1;
       
   258         // New entry
       
   259         result = pbkBuffer->AddNewEntryTag();
       
   260         if ( KErrNone == result )
       
   261             {
       
   262             // Type of index is TUint16 in Multimode ETel and TInt in old ETel.
       
   263             result = pbkBuffer->PutTagAndValue( 
       
   264             RMobilePhoneBookStore::ETagPBAdnIndex, (TUint16)entryIndex );
       
   265             VMBLOGSTRING2( "VMBX: CVmbxPbkStore::Write: ETagPBAdnIndex \
       
   266                     result=%I",  result );
       
   267             // Add name, Type of ETagPBText is TDes16
       
   268             TPtrC vmbxName( KNullDesC );
       
   269             aEntry.GetVmbxName( vmbxName );
       
   270             result = pbkBuffer->PutTagAndValue( 
       
   271             RMobilePhoneBookStore::ETagPBText, vmbxName );
       
   272             VMBLOGSTRING2( "VMBX: CVmbxPbkStore::Write: ETagPBText\
       
   273                     result=%I",  result );
       
   274             // Add number, Type of ETagPBNumber is TDes16
       
   275             TPtrC vmbxNumber( KNullDesC );
       
   276             aEntry.GetVmbxNumber( vmbxNumber );
       
   277             result = pbkBuffer->PutTagAndValue( 
       
   278             RMobilePhoneBookStore::ETagPBNumber, vmbxNumber );
       
   279             VMBLOGSTRING2( "VMBX: CVmbxPbkStore::Write: ETagPBNumber\
       
   280                     result=%I",  result );
       
   281             }
       
   282 
       
   283         if ( KErrNone == result )
       
   284             {
       
   285             if ( iPhoneBookType == EMBDNPhoneBook )
       
   286                 {
       
   287                 RMobilePhone::TMobilePhoneVoicemailIdsV3 mbdnInfo;
       
   288                 result = GetMbdnInfo( mbdnInfo );
       
   289 
       
   290                 if ( KErrNone == result )
       
   291                     {
       
   292                     TInt index = mbdnInfo.iVoice;
       
   293                     if( !IsActive() && !iWait->IsStarted() )
       
   294                         {
       
   295                         // write vmbx number to 6fc7 file
       
   296                         iPhoneBook.Write( iStatus, pbData, index );
       
   297                         // Wait for asynchronous call to finish
       
   298                         iAsynType = EVmbxSimEntryWrite;
       
   299                         SetActive();
       
   300                         iWait->Start();
       
   301                         result = iStatus.Int();
       
   302                         }
       
   303                     }
       
   304                 VMBLOGSTRING( "Mbdn writing" );
       
   305                 }
       
   306             else
       
   307                 {
       
   308                 if( !IsActive() && !iWait->IsStarted() )
       
   309                     {
       
   310                     // write vmbx number to 6f17 file
       
   311                     iPhoneBook.Write( iStatus, pbData, entryIndex );
       
   312                     iAsynType = EVmbxSimEntryWrite;
       
   313                     // Wait for asynchronous call to finish
       
   314                     SetActive();
       
   315                     iWait->Start();
       
   316                     result = iStatus.Int();
       
   317                     }
       
   318                 VMBLOGSTRING( "CVmbxPbkStore::Write 6f17 writing" );
       
   319                 }
       
   320             }
       
   321         }
       
   322     delete pbkBuffer;
       
   323     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::Write: result=%I<=",  result );
       
   324     return result;
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CVmbxPbkStore::PhonebookStore
       
   329 // Return RMobilePhoneBookStore
       
   330 // ---------------------------------------------------------------------------
       
   331 RMobilePhoneBookStore& CVmbxPbkStore::PhonebookStore()
       
   332     {
       
   333     VMBLOGSTRING( "VMBX: CVmbxPbkStore::PhonebookStore <=>" );
       
   334     return iPhoneBook;
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // CVmbxPbkStore::GetMbdnInfo
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 TInt CVmbxPbkStore::GetMbdnInfo( RMobilePhone::TMobilePhoneVoicemailIdsV3& aInfo )
       
   342     {
       
   343     VMBLOGSTRING( "VMBX: CVmbxPbkStore::GetMbdnInfo =>" );
       
   344     TInt result( KErrInUse );
       
   345     // Get identifiers
       
   346     if ( !IsActive() && !iWait->IsStarted() )
       
   347         {
       
   348         VMBLOGSTRING( "VMBX: CVmbxPbkStore::GetMbdnInfo: GetMailboxNumbers" );
       
   349         VMBLOGSTRING2( "VMBX: CVmbxPbkStore::GetMbdnInfo: iStatus %I",
       
   350                                                              iStatus.Int() );
       
   351         RMobilePhone::TMobilePhoneVoicemailIdsV3Pckg infoPckg( aInfo );
       
   352         iETelConnection->Phone().GetMailboxNumbers( iStatus, infoPckg );
       
   353         VMBLOGSTRING2( "VMBX: CVmbxPbkStore::GetMbdnInfo :iStatus %I",
       
   354                                                              iStatus.Int() );
       
   355         iAsynType = EVmbxSimMbdnInfo;
       
   356         // Wait for asynchronous call to finish
       
   357         SetActive();
       
   358         iWait->Start();
       
   359 
       
   360         VMBLOGSTRING2( "VMBX: CVmbxPbkStore::GetMbdnInfo: iVoice original value %I",
       
   361                                                              aInfo.iVoice );
       
   362         if ( iStatus.Int() == KErrNotFound )
       
   363             {
       
   364             result = KErrNone;
       
   365             VMBLOGSTRING( "VMBX: CVmbxPbkStore::GetMbdnInfo: KErrNotFound,\
       
   366              but igorned and change to KErrNone" );
       
   367             }
       
   368         else
       
   369             {
       
   370             result = iStatus.Int();
       
   371             }
       
   372         TVmbxAlsLineType alsLine = VmbxUtilities::AlsLine();
       
   373         if ( EVmbxAlsLineDefault == alsLine )
       
   374             {
       
   375             aInfo.iVoice =  EVmbxAlsLine1;
       
   376             }
       
   377         VMBLOGSTRING2( "VMBX: CVmbxPbkStore::GetMbdnInfo: iVoice last value %I",
       
   378             aInfo.iVoice );
       
   379         }
       
   380     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::GetMbdnInfo: result %I<=",
       
   381          result );
       
   382     return result;
       
   383     }
       
   384 
       
   385 // ---------------------------------------------------------------------------
       
   386 // CVmbxPbkStore::OpenMbdnPhonebook
       
   387 // opening mbdn-type phonebook
       
   388 // ---------------------------------------------------------------------------
       
   389 //   
       
   390 TInt CVmbxPbkStore::OpenMbdnPhonebook()
       
   391     {
       
   392     VMBLOGSTRING( "VMBX: CVmbxPbkStore::OpenMbdnPhonebook =>" );
       
   393     //Open mbdn-type phonebook , Currently the file not exist, thr return
       
   394     // value also KErrNone
       
   395     TInt result = iPhoneBook.Open( iETelConnection->Phone(),
       
   396                                          KETelIccMbdnPhoneBook );
       
   397     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::OpenMbdnPhonebook :\
       
   398         MBDN opening result = %d", result );
       
   399 
       
   400     TBool res = IsSimFileExisting( EMBDNPhoneBook );
       
   401     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::OpenMbdnPhonebook :\
       
   402         MBDN reading res = %d", res );
       
   403     if ( !res )
       
   404         {
       
   405         result = KErrPathNotFound;
       
   406         }
       
   407     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::OpenMbdnPhonebook res = %d<=", result );
       
   408     return result;
       
   409     }
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // CVmbxPbkStore::OpenVmbxPhonebook
       
   413 // opening vmbx-type phonebook
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 TInt CVmbxPbkStore::OpenVmbxPhonebook()
       
   417     {
       
   418     VMBLOGSTRING( "VMBX: CVmbxPbkStore::OpenVmbxPhonebook =>" );
       
   419     //Open vmbx-type phonebook , Currently the file not exist, thr return
       
   420     // value also KErrNone
       
   421     TInt result = iPhoneBook.Open( iETelConnection->Phone(),
       
   422                                                  KETelIccVoiceMailBox );
       
   423     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::OpenVmbxPhonebook :\
       
   424         Vmbx opening result = %d", result );
       
   425     TBool res = IsSimFileExisting( EVMBXPhoneBook );
       
   426     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::OpenVmbxPhonebook :\
       
   427         Vmbx reading res = %d", res );
       
   428     if ( !res )
       
   429         {
       
   430         result = KErrPathNotFound;
       
   431         }
       
   432     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::OpenVmbxPhonebook result=%d <=", result );
       
   433     return result;
       
   434     }
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // CVmbxPbkStore::GetL
       
   438 // Fetches mailbox number from Sim
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 void CVmbxPbkStore::GetL( CVoiceMailboxEntry& aEntry )
       
   442     {
       
   443     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::GetL: iPhoneBookType %d=>",
       
   444                          iPhoneBookType );
       
   445 
       
   446     if ( EMBDNPhoneBook == iPhoneBookType )
       
   447         {
       
   448         TRAPD( err, SimReadL( aEntry ) );
       
   449 
       
   450         TPtrC vmbxNumber( KNullDesC );
       
   451         if ( KErrNone == err )
       
   452             {
       
   453             err = aEntry.GetVmbxNumber( vmbxNumber );
       
   454             }
       
   455 
       
   456         // 6fc7 file empty
       
   457         if ( ( KErrNone != err ) || ( !vmbxNumber.Length() ) )
       
   458             {
       
   459             VMBLOGSTRING2( "VMBX: CVmbxPbkStore::GetL: \
       
   460             no vmbx number in 6fc7 file then read from 6f17 file err%I", err );
       
   461             // close 6fc7 and open 6f17 file
       
   462             iPhoneBook.Close();
       
   463             User::LeaveIfError( OpenVmbxPhonebook() );
       
   464             // read vmbx number from 6f17 file
       
   465             SimReadL( aEntry );
       
   466             }
       
   467         }
       
   468     else
       
   469         {
       
   470         SimReadL( aEntry );
       
   471         }
       
   472 
       
   473     VMBLOGSTRING( "VMBX: CVmbxPbkStore::GetL <=" );
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------------------------
       
   477 // CVmbxPbkStore::SimReadL
       
   478 // read vmbx number from sim
       
   479 // ---------------------------------------------------------------------------
       
   480 //
       
   481 void CVmbxPbkStore::SimReadL( CVoiceMailboxEntry& aEntry )
       
   482     {
       
   483     VMBLOGSTRING( "VMBX: CVmbxPbkStore::SimReadL =>" );
       
   484 
       
   485     TInt numEntries( 1 );
       
   486     TBuf8<KVmbxPhonebookBufferSize> pbData;
       
   487 
       
   488     TInt result( KErrInUse );
       
   489     if ( iPhoneBookType == EMBDNPhoneBook )
       
   490         {
       
   491         RMobilePhone::TMobilePhoneVoicemailIdsV3 mbdnInfo;
       
   492         result = GetMbdnInfo( mbdnInfo );
       
   493         if ( KErrNone == result )
       
   494             {
       
   495             VMBLOGSTRING( "start MBDN PhoneBook read" );
       
   496             if( !IsActive() && !iWait->IsStarted() )
       
   497                 {
       
   498                 // read vmbx number from 6fc7 file
       
   499                 iPhoneBook.Read( 
       
   500                 iStatus, mbdnInfo.iVoice, numEntries, pbData );
       
   501                 iAsynType = EVmbxSimEntryRead;
       
   502                 // Wait for asynchronous call to finish
       
   503                 SetActive();
       
   504                 iWait->Start();
       
   505                 }
       
   506             }
       
   507         }
       
   508     else
       
   509         {
       
   510         // Record#1 in sim is for line1 number and Record#2 in sim is for
       
   511         // line2 number so line is used to fetch
       
   512         VMBLOGSTRING( "start VMBX PhoneBook read" );
       
   513         TInt activeAlsLine = aEntry.VmbxAlsLineType();
       
   514         if ( EVmbxAlsLineDefault == activeAlsLine )
       
   515             {
       
   516             activeAlsLine = EVmbxAlsLine1;
       
   517             }
       
   518         if( !IsActive() && !iWait->IsStarted() )
       
   519             {
       
   520             result = KErrNone;
       
   521             // read vmbx number from 6f17 file
       
   522             VMBLOGSTRING2( "VMBX: CVmbxPbkStore::SimReadLactiveAlsLine = %I",
       
   523                  activeAlsLine );
       
   524             iPhoneBook.Read( iStatus, activeAlsLine, numEntries, pbData );
       
   525             iAsynType = EVmbxSimEntryRead;
       
   526             // Wait for asynchronous call to finish
       
   527             SetActive();
       
   528             iWait->Start();
       
   529             }
       
   530         }
       
   531 
       
   532     User::LeaveIfError( result );
       
   533     // asynchronous call finished
       
   534     VMBLOGSTRING2( "PhoneBook read iStatus = %I", iStatus.Int() );
       
   535 
       
   536     if( iStatus.Int() == KErrNone )
       
   537         {
       
   538         ParseDataL( aEntry, pbData );
       
   539         }
       
   540     else
       
   541         {
       
   542         User::Leave( iStatus.Int() );
       
   543         }
       
   544 
       
   545     VMBLOGSTRING( "VMBX: CVmbxPbkStore::SimReadL <=" );
       
   546     }
       
   547 
       
   548 // ---------------------------------------------------------------------------
       
   549 // CVmbxPbkStore::ParseDataL
       
   550 // 
       
   551 // ---------------------------------------------------------------------------
       
   552 //
       
   553 void CVmbxPbkStore::ParseDataL( CVoiceMailboxEntry& aEntry, TDes8& aPbData )
       
   554     {
       
   555     VMBLOGSTRING( "VMBX: CVmbxPbkStore::ParseDataL =>" );
       
   556     TInt result( KErrNotFound );
       
   557 
       
   558     VMBLOGSTRING2( "CVmbxPbkStore::ParseDataL Lengh = %d", aPbData.Length() );
       
   559 
       
   560     if ( aPbData.Length() )
       
   561         {
       
   562         // -> Search Tags "ETagPBNumber" and "ETagPBText"
       
   563         // and read (decode) them
       
   564         // create buffer
       
   565         CPhoneBookBuffer* pbkBuffer = new( ELeave ) CPhoneBookBuffer();
       
   566         CleanupStack::PushL( pbkBuffer );
       
   567 
       
   568         // start read
       
   569         pbkBuffer->Set( &aPbData );
       
   570         pbkBuffer->StartRead();
       
   571 
       
   572         result = ReadNewEntryTag( pbkBuffer );
       
   573         // Read first "new-entry-tag"
       
   574         if ( KErrNone == result )
       
   575             {
       
   576             ReadPbkDataL( pbkBuffer, aEntry );
       
   577             }
       
   578         CleanupStack::PopAndDestroy( pbkBuffer );
       
   579         }
       
   580     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::ParseDataL: result %I", result );
       
   581     User::LeaveIfError( result );
       
   582     VMBLOGSTRING( "VMBX: CVmbxPbkStore::ParseDataL <=" );
       
   583     }
       
   584 
       
   585 
       
   586 // ---------------------------------------------------------------------------
       
   587 // CVmbxPbkStore::ReadNewEntryTag
       
   588 // Reads "new-entry-tag" from phonebook data from Sim
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 TInt CVmbxPbkStore::ReadNewEntryTag( CPhoneBookBuffer* aPbkBuffer )
       
   592     {
       
   593     VMBLOGSTRING( "VMBX: CVmbxPbkStore::ReadNewEntryTag =>" );
       
   594     TInt result( KErrNone );
       
   595     TUint8 tagValue( 0 );
       
   596     CPhoneBookBuffer::TPhBkTagType dataType(
       
   597                                CPhoneBookBuffer::EPhBkTypeNoData );
       
   598 
       
   599     result = aPbkBuffer->GetTagAndType( tagValue, dataType );
       
   600     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::ReadNewEntryTag result = %d",
       
   601      result );
       
   602 
       
   603     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::ReadNewEntryTag tagValue = %X",
       
   604      tagValue );
       
   605     if ( tagValue != RMobilePhoneBookStore::ETagPBNewEntry )
       
   606         {
       
   607         VMBLOGSTRING( "VMBX: CVmbxPbkStore::ParseDataL: Unknown result" );
       
   608         result = KErrArgument;  // Something wrong in TLV
       
   609         }
       
   610     VMBLOGSTRING( "VMBX: CVmbxPbkStore::ReadNewEntryTag <=" );
       
   611     return result;
       
   612     }
       
   613 
       
   614 // ---------------------------------------------------------------------------
       
   615 // CVmbxPbkStore::ReadPbkData
       
   616 // Reads tags from buffer retrieved from sim
       
   617 // ---------------------------------------------------------------------------
       
   618 //
       
   619 void CVmbxPbkStore::ReadPbkDataL( CPhoneBookBuffer* aPbkBuffer,
       
   620                                          CVoiceMailboxEntry& aEntry )
       
   621     {
       
   622     VMBLOGSTRING( "VMBX: CVmbxPbkStore::ReadPbkDataL =>" );
       
   623 
       
   624     TInt result( KErrNone );
       
   625     TInt next( KErrNone );
       
   626     TBool found( EFalse );
       
   627     TUint8 tagValue( 0 );
       
   628     CPhoneBookBuffer::TPhBkTagType dataType(
       
   629                                           CPhoneBookBuffer::EPhBkTypeNoData );
       
   630 
       
   631     result = aPbkBuffer->GetTagAndType( tagValue, dataType );
       
   632 
       
   633     // loop through data to find a number and an possible alpha string
       
   634     while ( next == KErrNone && result == KErrNone )
       
   635         {
       
   636         VMBLOGSTRING2("VMBX: CVmbxPbkStore::ReadPbkDataL: tagValue: %d",
       
   637          tagValue );
       
   638         VMBLOGSTRING2("VMBX: CVmbxPbkStore::ReadPbkDataL: dataType: %d",
       
   639          dataType );
       
   640 
       
   641         // Check for text field
       
   642         if ( tagValue == RMobilePhoneBookStore::ETagPBText )
       
   643             {
       
   644             VMBLOGSTRING("VMBX: CVmbxPbkStore::ReadPbkDataL: \
       
   645                           ETagPBText found Alpha ID" );
       
   646             found = ETrue;
       
   647             // Alpha string field found from TLV entry,
       
   648             // assuming 16bit data
       
   649             TPtrC16 alphaPtrC;
       
   650             result = aPbkBuffer->GetValue( alphaPtrC );
       
   651             
       
   652             if ( KErrNone == result )
       
   653                 {
       
   654                 // set name to vmbx entry
       
   655                 result = aEntry.SetVmbxName( alphaPtrC );
       
   656                 }
       
   657             }
       
   658 
       
   659         // Check for number field
       
   660         else if ( tagValue == RMobilePhoneBookStore::ETagPBNumber )
       
   661             {
       
   662             VMBLOGSTRING("VMBX: CVmbxPbkStore::ReadPbkDataL: \
       
   663                           ETagPBNumber found Number" );
       
   664             found = ETrue;
       
   665             // Number field found from TLV entry, assuming 16bit data
       
   666             TPtrC16 numberPtrC;
       
   667             result = aPbkBuffer->GetValue( numberPtrC );
       
   668 
       
   669             if ( KErrNone == result )
       
   670                 {
       
   671                 // set number to vmbx entry
       
   672                 result = aEntry.SetVmbxNumber( numberPtrC );
       
   673                 }
       
   674             }
       
   675         else
       
   676             {
       
   677             // skip field
       
   678             aPbkBuffer->SkipValue( dataType );
       
   679             VMBLOGSTRING( "VMBX: CVmbxPbkStore::ReadPbkDataL: SkipValue" );
       
   680             }
       
   681         // read next if no errors
       
   682         if ( KErrNone == result )
       
   683             {
       
   684             // Read next field type
       
   685             next = aPbkBuffer->GetTagAndType( tagValue, dataType );
       
   686             VMBLOGSTRING2( "VMBX: CVmbxPbkStore::ReadPbkDataL: \
       
   687                                     next GetTagAndType = %I", result );
       
   688             }
       
   689         }
       
   690 
       
   691     // Neither alpha string Nor number is found
       
   692     if( KErrNone == result && !found )
       
   693         {
       
   694         result = KErrNotFound;
       
   695         }
       
   696     
       
   697     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::ReadPbkDataL result=%I", result );
       
   698     User::LeaveIfError( result );
       
   699     VMBLOGSTRING( "VMBX: CVmbxPbkStore::ReadPbkDataL <=" );
       
   700     }
       
   701 
       
   702 // ---------------------------------------------------------------------------
       
   703 // CVmbxPbkStore::RunL
       
   704 // 
       
   705 // ---------------------------------------------------------------------------
       
   706 //
       
   707 void CVmbxPbkStore::RunL()
       
   708     {
       
   709     VMBLOGSTRING( "VMBX: CVmbxPbkStore::RunL =>" );
       
   710     if ( iWait->IsStarted() )
       
   711         {
       
   712         // stop blocking
       
   713         iWait->AsyncStop();
       
   714         VMBLOGSTRING( "VMBX: CVmbxSimHandler::RunL: AsyncStop" );
       
   715         }
       
   716     iAsynType = EVmbxSimDefault;
       
   717     VMBLOGSTRING( "VMBX: CVmbxPbkStore::RunL <=" );
       
   718     }
       
   719 
       
   720 // ---------------------------------------------------------------------------
       
   721 // CVmbxPbkStore::DoCancel
       
   722 // 
       
   723 // ---------------------------------------------------------------------------
       
   724 //
       
   725 void CVmbxPbkStore::DoCancel()
       
   726     {
       
   727     VMBLOGSTRING( "VMBX: CVmbxPbkStore::DoCancel =>" );
       
   728     if ( iWait->IsStarted() )
       
   729         {
       
   730         // stop blocking
       
   731         iWait->AsyncStop();
       
   732         VMBLOGSTRING( "VMBX: CVmbxPbkStore::DoCancel: AsyncStop" );
       
   733         }
       
   734     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::DoCancel: iAsynType %I",iAsynType );
       
   735     switch ( iAsynType )    
       
   736         {
       
   737         // only for USIM
       
   738         case EVmbxSimMbdnInfo:
       
   739             {
       
   740             VMBLOGSTRING( "VMBX: CVmbxPbkStore::DoCancel : \
       
   741                                         EVmbxSimMbdnInfo" );
       
   742             iETelConnection->Phone().CancelAsyncRequest( 
       
   743                                               EMobilePhoneGetMailboxNumbers );
       
   744             break;
       
   745             }
       
   746         case EVmbxSimGetInfo:
       
   747             {
       
   748             VMBLOGSTRING( "VMBX: CVmbxPbkStore::DoCancel : \
       
   749                                               EVmbxSimGetInfo" );
       
   750             iETelConnection->Phone().CancelAsyncRequest( 
       
   751                                                EMobilePhoneStoreGetInfo );
       
   752             break;
       
   753             }            
       
   754         case EVmbxSimEntryRead:
       
   755             {
       
   756             VMBLOGSTRING( "VMBX: CVmbxPbkStore::DoCancel : EVmbxSimEntryRead" );
       
   757             iETelConnection->Phone().CancelAsyncRequest( 
       
   758                                                EMobilePhoneStoreRead );
       
   759             break;
       
   760             }
       
   761         case EVmbxSimEntryWrite:
       
   762             {
       
   763             VMBLOGSTRING( "VMBX: CVmbxPbkStore::DoCancel : EVmbxSimEntryWrite" );
       
   764             iETelConnection->Phone().CancelAsyncRequest( 
       
   765                                                EMobilePhoneStoreWrite );
       
   766             break;
       
   767             }
       
   768         default:
       
   769             break;
       
   770         }
       
   771     
       
   772     VMBLOGSTRING( "VMBX: CVmbxPbkStore::DoCancel <=" );
       
   773     }
       
   774 
       
   775 // ---------------------------------------------------------------------------
       
   776 // CVmbxPbkStore::RunError
       
   777 // 
       
   778 // ---------------------------------------------------------------------------
       
   779 //
       
   780 TInt CVmbxPbkStore::RunError(TInt aError)
       
   781     {
       
   782     // Avoid warning
       
   783     aError = aError;
       
   784     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::RunError: %I", aError );
       
   785     return KErrNone;
       
   786     }
       
   787 
       
   788 // ---------------------------------------------------------------------------
       
   789 // CVmbxPbkStore::IsSimFileExisting
       
   790 // check sim file existing or not
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 TBool CVmbxPbkStore::IsSimFileExisting( const TVmbxSimPhonebookType aType )
       
   794     {
       
   795     VMBLOGSTRING( "VMBX: CVmbxPbkStore::IsSimFileExisting =>" );
       
   796     iPhoneBookType = aType;
       
   797     TBool result( ETrue );
       
   798     CVoiceMailboxEntry* entry(NULL);
       
   799     TRAPD( err, entry = CVoiceMailboxEntry::NewL() );
       
   800     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::IsSimFileExisting err = %d ",
       
   801      err );
       
   802     if ( KErrNone != err )
       
   803         {
       
   804         result = EFalse;
       
   805         }
       
   806     else
       
   807         {
       
   808         entry->SetVoiceMailboxType( EVmbxVoice );
       
   809         TRAPD( err, SimReadL( *entry ) );
       
   810         // KErrPathNotFound means when current file path not found.
       
   811         if ( KErrPathNotFound == err )
       
   812             {
       
   813             result = EFalse;
       
   814             }
       
   815         }
       
   816     delete entry;
       
   817     entry = NULL;
       
   818     VMBLOGSTRING2( "VMBX: CVmbxPbkStore::IsSimFileExisting result = %d <= ",
       
   819          result );
       
   820     return result;
       
   821     }
       
   822 
       
   823 // ---------------------------------------------------------------------------
       
   824 // CVmbxPbkStore::IsWriteAccess
       
   825 // Sim write access support
       
   826 // ---------------------------------------------------------------------------
       
   827 //
       
   828 TBool CVmbxPbkStore::IsWriteAccess()
       
   829     {
       
   830     VMBLOGSTRING( "VMBX: CVmbxPbkStore::IsWriteAccess =>" );
       
   831     TBool result( EFalse );
       
   832     RMobilePhoneBookStore::TMobilePhoneBookInfoV1 info;
       
   833     TInt temp = GetVmbxInfo( info );
       
   834     if( KErrNone == temp )
       
   835         {
       
   836         result = ( info.iCaps &
       
   837                 RMobilePhoneBookStore::KCapsWriteAccess ? ETrue : EFalse );
       
   838         
       
   839         }
       
   840     VMBLOGSTRING2( "VMBX: CVmbxPbkStore:: IsWriteAccess: info.iCaps %X",
       
   841                      info.iCaps );
       
   842     VMBLOGSTRING2( "VMBX: CVmbxPbkStore:: IsWriteAccess result %I <=", result );
       
   843     return result;
       
   844     }
       
   845 
       
   846 //End of file