telephonyserverplugins/common_tsy/commontsy/src/mmstorage/cmmonstoretsy.cpp
changeset 0 3553901f7fa8
child 14 7ef16719d8cb
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 //  INCLUDE FILES
       
    19 #include "cmmonstoretsy.h"
       
    20 #include "cmmtsyreqhandlestore.h"
       
    21 #include "CMmPrivateUtility.h"
       
    22 #include "MmTsy_numberOfSlots.h"
       
    23 #include "MmTsy_timeoutdefs.h"
       
    24 #include "cmmmessagemanagerbase.h"
       
    25 #include "cmmpblist.h"
       
    26 #include "cmmphonebookstoretsy.h"
       
    27 #include <ctsy/pluginapi/cmmdatapackage.h>
       
    28 #include <ctsy/serviceapi/mmtsy_ipcdefs.h>
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 CMmONStoreTsy::CMmONStoreTsy()
       
    33     {
       
    34     }
       
    35 
       
    36 void CMmONStoreTsy::ConstructL()
       
    37     {
       
    38 TFLOGSTRING("TSY: CMmONStoreTsy::ConstructL");
       
    39 
       
    40 #ifdef REQHANDLE_TIMER
       
    41     // Create req handle store
       
    42     iTsyReqHandleStore = CMmTsyReqHandleStore::NewL( this, iMmPhone, 
       
    43         EMmTsyNumOfONStoreRequests, iStorageReqHandles );
       
    44 #else // REQHANDLE_TIMER
       
    45     // Create req handle store
       
    46     iTsyReqHandleStore = CMmTsyReqHandleStore::NewL( 
       
    47         EMmTsyNumOfONStoreRequests, iStorageReqHandles );
       
    48 #endif // REQHANDLE_TIMER
       
    49 
       
    50     //get mode of current extension.
       
    51     RMobilePhone::TMobilePhoneNetworkMode currentMode;
       
    52     iMmPhone->GetStaticExtensionMode( &currentMode );
       
    53 
       
    54     // Reset phonebooktype and servicetype
       
    55     ResetVariables();
       
    56 
       
    57     // Create GSM ONStore objects
       
    58     iMmONStoreGsmExt = static_cast<CMmONStoreExtInterface*>(
       
    59         CMmONStoreGsmExt::NewL( this ) );
       
    60     // Set mode GSM
       
    61     iMmONStoreExtInterface = iMmONStoreGsmExt;
       
    62 
       
    63 
       
    64     //if current mode is GSM
       
    65     if ( RMobilePhone::ENetworkModeGsm == currentMode )
       
    66         {
       
    67         // Set phonebook type and servicetype
       
    68         iPhoneBookType = KSimMsisdn;  // MSISDN
       
    69         }
       
    70 
       
    71     // Construct ReadAllList
       
    72     iONStoreListArray = new (ELeave) CArrayFixFlat<TONStoreMsg>(1);
       
    73 
       
    74     // Construct ReadAllArray
       
    75     iONStoreReadAllArray = new (ELeave) CArrayPtrFlat<CListReadAllAttempt>(1);
       
    76 
       
    77     //register ON Store tsy in the message manager
       
    78     iMmPhone->MessageManager()->RegisterTsyObject( 
       
    79         CMmMessageManagerBase::EONStoreTsy, this );
       
    80 
       
    81     // Reset info to fill with ini values
       
    82     SetInfo();
       
    83     }
       
    84 
       
    85 CMmONStoreTsy* CMmONStoreTsy::NewL(
       
    86     CMmPhoneTsy* aMmPhone )
       
    87     {
       
    88     CMmONStoreTsy* aMmONStoreTsy = new( ELeave ) CMmONStoreTsy();
       
    89     CleanupClosePushL( *aMmONStoreTsy );
       
    90 
       
    91     aMmONStoreTsy->iMmPhone = aMmPhone;
       
    92 
       
    93     aMmONStoreTsy->ConstructL();
       
    94     CleanupStack::Pop();
       
    95 
       
    96     return aMmONStoreTsy;
       
    97     }
       
    98 
       
    99 CMmONStoreTsy::~CMmONStoreTsy()
       
   100     {
       
   101 TFLOGSTRING("TSY: CMmONStoreTsy::~CMmONStoreTsy");
       
   102 
       
   103     if (iMmPhone )
       
   104         {
       
   105         // deregister tsy object from message manager
       
   106         iMmPhone->MessageManager()->DeregisterTsyObject(this);
       
   107         }
       
   108 
       
   109     if ( NULL != iTsyReqHandleStore )
       
   110         {
       
   111         delete iTsyReqHandleStore;
       
   112         iTsyReqHandleStore = NULL;
       
   113         }
       
   114 
       
   115     // Delete ONStoreGsmExt
       
   116     delete iMmONStoreGsmExt;
       
   117     iMmONStoreGsmExt = NULL;
       
   118 
       
   119     // Delete TSY's internal ONStore list
       
   120     delete iONStoreListArray;
       
   121     iONStoreListArray = NULL;
       
   122 
       
   123     // Delete ONStoreReadAll array
       
   124     iONStoreReadAllArray->ResetAndDestroy();
       
   125     delete iONStoreReadAllArray;
       
   126     iONStoreReadAllArray = NULL;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CMmONStoreTsy::Init
       
   131 // Initialisation method that is called from ETel Server.
       
   132 // This is an initialization method for the class functionality.
       
   133 // Generally initization method inits e.g. class attributes.
       
   134 // In this case, this method is not needed.
       
   135 // (other items were commented in a header).
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CMmONStoreTsy::Init()
       
   139     {
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CMmONStoreTsy::OpenNewObjectByNameL
       
   144 // This method opens extendable sub-sessions
       
   145 // (other items were commented in a header).
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 CTelObject* CMmONStoreTsy::OpenNewObjectByNameL(
       
   149     const TDesC& )
       
   150     {
       
   151     User::Leave( KErrNotSupported );
       
   152     //lint -e{527} "unreachable code"
       
   153     
       
   154     return NULL;
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CMmONStoreTsy::OpenNewObjectL
       
   159 // This method opens extendable sub-sessions
       
   160 // (other items were commented in a header).
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 CTelObject* CMmONStoreTsy::OpenNewObjectL(
       
   164     TDes& )
       
   165     {
       
   166     User::Leave( KErrNotSupported );
       
   167     //lint -e{527} "unreachable code"
       
   168     
       
   169     return NULL;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CMmONStoreTsy::ReqModeL
       
   174 // To ask what type of flow control is used for the IPC number.
       
   175 // (other items were commented in a header).
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 CTelObject::TReqMode CMmONStoreTsy::ReqModeL(
       
   179     const TInt aIpc )
       
   180     {
       
   181 TFLOGSTRING2("TSY: CMmONStoreTsy::ReqModeL IPC %d", aIpc);
       
   182     CTelObject::TReqMode ret=0;
       
   183     switch ( aIpc )
       
   184         {
       
   185         // Flow Controlled Services
       
   186         case EMobilePhoneStoreRead:
       
   187         case EMobilePhoneStoreWrite:
       
   188         case EMobilePhoneStoreDelete:
       
   189         case EMobilePhoneStoreDeleteAll:
       
   190         case EMobilePhoneStoreReadAllPhase1:
       
   191         case EMobilePhoneStoreReadAllPhase2:
       
   192         case EMobilePhoneStoreGetInfo:
       
   193         case EMobileONStoreStoreAll:
       
   194             ret=KReqModeFlowControlObeyed;
       
   195             break;
       
   196         // Multiple Completion Services with Immediate Server Repost
       
   197         // (Usually Notifications)
       
   198         case EMobilePhoneStoreNotifyStoreEvent:
       
   199             ret=KReqModeMultipleCompletionEnabled | KReqModeRePostImmediately;
       
   200             break;
       
   201         default:
       
   202             User::Leave(KErrNotSupported);
       
   203             break;
       
   204         }
       
   205         
       
   206     return ret;
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CMmONStoreTsy::RegisterNotification
       
   211 // Enables the TSY to "turn on" any regular notification
       
   212 // (other items were commented in a header).
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 TInt CMmONStoreTsy::RegisterNotification(
       
   216     const TInt aIpc )
       
   217     {
       
   218     TInt ret( KErrNone );
       
   219 
       
   220     switch ( aIpc )
       
   221         {
       
   222         case EMobilePhoneStoreNotifyStoreEvent:
       
   223             // KErrNone
       
   224             break;
       
   225         default:
       
   226             // Unknown or invalid IPC
       
   227             ret = KErrNotSupported;
       
   228         }
       
   229 
       
   230     return ret;
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CMmONStoreTsy::DeregisterNotification
       
   235 // Enables the TSY to "turn off" any regular notification
       
   236 // (other items were commented in a header).
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 TInt CMmONStoreTsy::DeregisterNotification(
       
   240     const TInt aIpc )
       
   241     {
       
   242     TInt ret( KErrNone );
       
   243 
       
   244     switch ( aIpc )
       
   245         {
       
   246         case EMobilePhoneStoreNotifyStoreEvent:
       
   247             // KErrNone
       
   248             break;
       
   249         default:
       
   250             // Unknown or invalid IPC
       
   251             ret = KErrNotSupported;
       
   252         }
       
   253 
       
   254     return ret;
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // CMmONStoreTsy::NumberOfSlotsL
       
   259 // To ask the TSY how big buffer it wants
       
   260 // (other items were commented in a header).
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 TInt CMmONStoreTsy::NumberOfSlotsL(
       
   264     const TInt aIpc )
       
   265     {
       
   266     TInt numberOfSlots = 1;
       
   267 
       
   268     switch ( aIpc )
       
   269         {
       
   270         case EMobilePhoneStoreNotifyStoreEvent:
       
   271             numberOfSlots = KMmONStoreNotifyStoreEventSlots;
       
   272             break;
       
   273         default:
       
   274             // Unknown or invalid Phone IPC
       
   275             User::Leave( KErrNotSupported );
       
   276             break;
       
   277         }
       
   278 
       
   279     return numberOfSlots;
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // CMmONStoreTsy::ExtFunc
       
   284 // Handling of extended requests
       
   285 // (other items were commented in a header).
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 TInt CMmONStoreTsy::ExtFunc(
       
   289     const TTsyReqHandle aTsyReqHandle,
       
   290     const TInt aIpc,
       
   291     const TDataPackage& aPackage )
       
   292     {
       
   293 TFLOGSTRING3("TSY: CMmONStoreTsy::ExtFunc - IPC:%d Handle:%d", aIpc, aTsyReqHandle);   
       
   294                
       
   295     TInt ret = KErrNone;
       
   296     TInt trapError = KErrNone;
       
   297 
       
   298     // Reset last tsy request type
       
   299     iReqHandleType = EMultimodeONStoreReqHandleUnknown;
       
   300 
       
   301     TRAP( trapError, ret = DoExtFuncL( aTsyReqHandle, aIpc, aPackage ); );
       
   302 
       
   303     if ( KErrNone != trapError )
       
   304         {
       
   305         ReqCompleted( aTsyReqHandle, trapError );
       
   306         }
       
   307     else if ( KErrNone != ret )
       
   308         {
       
   309         ReqCompleted( aTsyReqHandle, ret );
       
   310         }
       
   311 
       
   312     // Save request handle
       
   313     if ( EMultimodeONStoreReqHandleUnknown != iReqHandleType )
       
   314         {
       
   315 #ifdef REQHANDLE_TIMER
       
   316         SetTypeOfResponse( iReqHandleType, aTsyReqHandle );
       
   317 #else // REQHANDLE_TIMER
       
   318         iTsyReqHandleStore->SetTsyReqHandle( iReqHandleType, aTsyReqHandle );
       
   319 #endif // REQHANDLE_TIMER
       
   320         }
       
   321 
       
   322     return KErrNone;
       
   323     }
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // CMmONStoreTsy::DoExtFuncL
       
   327 // Dispatches extension function requests
       
   328 // (other items were commented in a header).
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 TInt CMmONStoreTsy::DoExtFuncL(
       
   332     const TTsyReqHandle aTsyReqHandle,
       
   333     const TInt aIpc,
       
   334     const TDataPackage& aPackage )
       
   335     {
       
   336 TFLOGSTRING3("TSY: CMmONStoreTsy::DoExtFuncL - IPC:%d Handle:%d", aIpc, aTsyReqHandle);
       
   337 
       
   338     TAny* dataPtr=aPackage.Ptr1();
       
   339     TAny* dataPtr2=aPackage.Ptr2();
       
   340 
       
   341     // Create unique transaction id
       
   342 
       
   343     switch (aIpc)
       
   344         {
       
   345         case EMobilePhoneStoreRead:
       
   346             return ReadL( aPackage.Des1n() );
       
   347 
       
   348         case EMobilePhoneStoreWrite:
       
   349             return WriteL( aTsyReqHandle, aPackage.Des1n() );
       
   350 
       
   351         case EMobilePhoneStoreDelete:
       
   352             return DeleteL( aTsyReqHandle,
       
   353                 REINTERPRET_CAST( TInt*, dataPtr ) );
       
   354 
       
   355         case EMobilePhoneStoreDeleteAll:
       
   356             return DeleteAllL( aTsyReqHandle );
       
   357 
       
   358         case EMobilePhoneStoreGetInfo:
       
   359             return GetInfoL( aTsyReqHandle,
       
   360                 REINTERPRET_CAST( RMobileONStore::TMobileONStoreInfoV1*, 
       
   361                     dataPtr ) );
       
   362 
       
   363         case EMobilePhoneStoreReadAllPhase1:
       
   364             return ReadAllPhase1L( aTsyReqHandle,
       
   365                 REINTERPRET_CAST( RMobilePhone::TClientId*, dataPtr ),
       
   366                 REINTERPRET_CAST( TInt*, dataPtr2 ) );
       
   367 
       
   368         case EMobilePhoneStoreReadAllPhase2:
       
   369             return ReadAllPhase2( aTsyReqHandle,
       
   370                 REINTERPRET_CAST( RMobilePhone::TClientId*, dataPtr ), 
       
   371                 aPackage.Des2n() );
       
   372 
       
   373         case EMobilePhoneStoreNotifyStoreEvent:
       
   374             return NotifyStoreEvent(
       
   375                 REINTERPRET_CAST( RMobilePhoneStore::TMobileStoreEvent*, 
       
   376                 dataPtr ), REINTERPRET_CAST( TInt*, dataPtr2 ) );
       
   377 
       
   378         case EMobileONStoreStoreAll:
       
   379             return StoreAllL( aTsyReqHandle,aPackage.Des1n() );
       
   380 
       
   381         default:
       
   382             return KErrNotSupported;
       
   383         }
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // CMmONStoreTsy::CancelService
       
   388 // To cancel any extension requests
       
   389 // (other items were commented in a header).
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 TInt CMmONStoreTsy::CancelService(
       
   393     const TInt aIpc,
       
   394     const TTsyReqHandle aTsyReqHandle )
       
   395     {
       
   396     switch ( aIpc )
       
   397         {
       
   398         case EMobilePhoneStoreGetInfo:
       
   399             return GetInfoCancel( aTsyReqHandle );
       
   400         case EMobilePhoneStoreRead:
       
   401             return ReadCancel( aTsyReqHandle );
       
   402         case EMobilePhoneStoreWrite:
       
   403             return WriteCancel( aTsyReqHandle );
       
   404         case EMobilePhoneStoreDelete:
       
   405             // There is no change to cancel this request, so only thing to do,
       
   406             // is let the request continue and return KErrNone.
       
   407             return KErrNone;
       
   408         case EMobilePhoneStoreDeleteAll:
       
   409             return DeleteAllCancel( aTsyReqHandle );
       
   410         case EMobilePhoneStoreReadAllPhase1:
       
   411         case EMobilePhoneStoreReadAllPhase2:
       
   412             return ReadAllCancel( aTsyReqHandle );
       
   413         case EMobilePhoneStoreNotifyStoreEvent:
       
   414             return NotifyStoreEventCancel( aTsyReqHandle );
       
   415         case EMobileONStoreStoreAll:
       
   416             return StoreAllCancel( aTsyReqHandle );
       
   417         default:
       
   418             return KErrGeneral;
       
   419         }
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // CMmONStoreTsy::SetActiveONStoreExtension
       
   424 // Sets pointer to active extension
       
   425 // (other items were commented in a header).
       
   426 // ---------------------------------------------------------------------------
       
   427 //
       
   428 TInt CMmONStoreTsy::SetActiveONStoreExtension(
       
   429     CMmONStoreExtInterface* aMmONStoreExt )
       
   430     {
       
   431     TInt ret = KErrGeneral;
       
   432 
       
   433     if ( aMmONStoreExt )
       
   434         {
       
   435         iMmONStoreExtInterface = aMmONStoreExt;
       
   436         ret = KErrNone;
       
   437         }
       
   438 
       
   439     return ret;
       
   440     }
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 // CMmONStoreTsy::Returns a pointer to the active extension
       
   444 // Sets pointer to active extension
       
   445 // (other items were commented in a header).
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 CMmONStoreExtInterface* CMmONStoreTsy::ActiveONExtension()
       
   449     {
       
   450     return iMmONStoreExtInterface;
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // CMmONStoreTsy::ReadL
       
   455 // Read one ON store entry using index
       
   456 // (other items were commented in a header).
       
   457 // ---------------------------------------------------------------------------
       
   458 //
       
   459 TInt CMmONStoreTsy::ReadL( TDes8* aEntry )
       
   460     {
       
   461 TFLOGSTRING("TSY: CMmONStoreTsy::ReadL");
       
   462     // Initialize ret value
       
   463     TInt ret( KErrArgument );
       
   464 
       
   465     if( sizeof( RMobileONStore::TMobileONEntryV1 ) <= aEntry->MaxLength() )
       
   466 	  	{
       
   467 
       
   468         // Unpack entry parameter
       
   469         RMobileONStore::TMobileONEntryV1Pckg* entryPckg =
       
   470             REINTERPRET_CAST
       
   471             ( RMobileONStore::TMobileONEntryV1Pckg*, aEntry );
       
   472         RMobileONStore::TMobileONEntryV1& entry = ( *entryPckg )();
       
   473 
       
   474         // Save entry pointer
       
   475         iReadONStoreEntryPtr = aEntry;
       
   476 
       
   477         // Forward request to GSM Extension
       
   478         ret = iMmONStoreExtInterface->ReadL( EMmTsyONStoreReadIPC, entry.iIndex );
       
   479 
       
   480         if ( KErrNone == ret )
       
   481             {
       
   482             // Save tsy req handle type
       
   483             iReqHandleType = EMultimodeONStoreRead;
       
   484             }
       
   485 	  	}
       
   486 
       
   487     return ret;
       
   488     }
       
   489 
       
   490 // ---------------------------------------------------------------------------
       
   491 // CMmONStoreTsy::CompleteRead
       
   492 // Completes reading a entry from the ONStore
       
   493 // (other items were commented in a header).
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 void CMmONStoreTsy::CompleteRead(
       
   497     TInt aResult,
       
   498     CMmDataPackage* aDataPackage )
       
   499     {
       
   500 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteRead");
       
   501     // Response information
       
   502     TONStoreMsg* ONStoreResp = NULL;
       
   503     // unpack data if exists
       
   504     if ( aDataPackage )
       
   505         {
       
   506         //unpack data
       
   507         aDataPackage->UnPackData( ONStoreResp );
       
   508         }
       
   509     else if ( KErrNone == aResult )
       
   510         {
       
   511 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteRead result is KErrNone and aDataPackage is NULL!");
       
   512         aResult = KErrArgument;
       
   513         }
       
   514 
       
   515     // Reset req handle. Returns the deleted req handle
       
   516     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   517         EMultimodeONStoreRead );
       
   518 
       
   519     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
   520         {
       
   521 
       
   522         if ( KErrNone == aResult )
       
   523             {
       
   524 
       
   525             // Get entry
       
   526             RMobileONStore::TMobileONEntryV1Pckg* entryPckg =
       
   527                 REINTERPRET_CAST( RMobileONStore::TMobileONEntryV1Pckg*,
       
   528                 iReadONStoreEntryPtr );
       
   529             RMobileONStore::TMobileONEntryV1& entry = ( *entryPckg )();
       
   530 
       
   531             // Fill entry
       
   532             // Map iIndex to client world (increase value by one)
       
   533             entry.iIndex = ONStoreResp->iLocation;
       
   534             entry.iText.Copy( ONStoreResp->iName );
       
   535             entry.iNumber.iTelNumber.Copy( ONStoreResp->iTelNumber );
       
   536 
       
   537             // SIM_PN_READ_RESP response
       
   538             entry.iMode = RMobilePhone::ENetworkModeUnknown;
       
   539             /*ENetworkModeUnknown,
       
   540             ENetworkModeUnregistered,
       
   541             ENetworkModeGsm,
       
   542             ENetworkModeAmps,
       
   543             ENetworkModeCdma,
       
   544             ENetworkModeWcdma
       
   545             */
       
   546             entry.iService = RMobilePhone::EServiceUnspecified;
       
   547             /*EServiceUnspecified,
       
   548             EVoiceService,
       
   549             EAuxVoiceService,
       
   550             ECircuitDataService,
       
   551             EPacketDataService,
       
   552             EFaxService,
       
   553             EShortMessageService,
       
   554             EAllServices
       
   555             */
       
   556 
       
   557             // Complete request to success
       
   558             ReqCompleted( reqHandle, KErrNone );
       
   559             }
       
   560         else
       
   561             {
       
   562             // Failure
       
   563             ReqCompleted( reqHandle, aResult );
       
   564             }
       
   565         }
       
   566     }
       
   567 
       
   568 // ---------------------------------------------------------------------------
       
   569 // CMmONStoreTsy::ReadCancel
       
   570 // Cancel read one ON store entry using index
       
   571 // (other items were commented in a header).
       
   572 // ---------------------------------------------------------------------------
       
   573 //
       
   574 TInt CMmONStoreTsy::ReadCancel(
       
   575     const TTsyReqHandle aTsyReqHandle )
       
   576     {
       
   577 TFLOGSTRING("TSY: CMmONStoreTsy::ReadCancel");
       
   578     // Reset req handle. Returns the deleted req handle
       
   579     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   580         EMultimodeONStoreRead );
       
   581 
       
   582     // Check that request handle was valid
       
   583     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
   584         {
       
   585         // Complete with KErrCancel
       
   586         ReqCompleted( aTsyReqHandle, KErrCancel );
       
   587         }
       
   588 
       
   589     return KErrNone;
       
   590     }
       
   591 
       
   592 // ---------------------------------------------------------------------------
       
   593 // CMmONStoreTsy::WriteL
       
   594 // Writes the entry supplied within the entry parameter into the store
       
   595 // (other items were commented in a header).
       
   596 // ---------------------------------------------------------------------------
       
   597 //
       
   598 TInt CMmONStoreTsy::WriteL(
       
   599     const TTsyReqHandle aTsyReqHandle,
       
   600     TDesC8* aEntry )
       
   601     {
       
   602 TFLOGSTRING("TSY: CMmONStoreTsy::WriteL");
       
   603     // Save tsy req handle type
       
   604     iReqHandleType = EMultimodeONStoreWrite;
       
   605 
       
   606     // Unpack entry param to get the location
       
   607     RMobileONStore::TMobileONEntryV1Pckg* entryPckg =
       
   608         REINTERPRET_CAST
       
   609         ( RMobileONStore::TMobileONEntryV1Pckg*, aEntry );
       
   610     RMobileONStore::TMobileONEntryV1& entry = ( *entryPckg )();
       
   611 
       
   612     iWriteONStoreEntryPtr = aEntry;
       
   613     iWriteIndexToReturn = entry.iIndex;
       
   614 
       
   615     // It is not possible to cancel write request anymore...
       
   616     iIsWriteCancellingPossible = EFalse;
       
   617 
       
   618     // Return value
       
   619     TInt ret( KErrNone );
       
   620 
       
   621     ret = iMmONStoreExtInterface->
       
   622         WriteL(
       
   623         EMmTsyONStoreWriteIPC,
       
   624         aEntry );
       
   625 
       
   626     // Check error while processing write
       
   627     if ( KErrNone != ret )
       
   628         {
       
   629         iWriteIndexToReturn = 0;
       
   630         iWriteONStoreEntryPtr = NULL;
       
   631         ReqCompleted( aTsyReqHandle, ret );
       
   632         }
       
   633     else
       
   634         {
       
   635         // Save tsy req handle type
       
   636         iReqHandleType = EMultimodeONStoreWrite;
       
   637         }
       
   638 
       
   639     return KErrNone;
       
   640     }
       
   641 
       
   642 // ---------------------------------------------------------------------------
       
   643 // CMmONStoreTsy::CompleteWrite
       
   644 // Completes writing a entry to the phonebookstore
       
   645 // (other items were commented in a header).
       
   646 // ---------------------------------------------------------------------------
       
   647 //
       
   648 void CMmONStoreTsy::CompleteWrite(
       
   649     TInt aResult,
       
   650     CMmDataPackage* aDataPackage )
       
   651     {
       
   652 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteWrite");   
       
   653     // Reset req handle. Returns the deleted req handle
       
   654     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   655         EMultimodeONStoreWrite );
       
   656 
       
   657     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
   658         {
       
   659         if ( KErrNone == aResult )
       
   660             {
       
   661             TInt location = 0;
       
   662             
       
   663             if ( aDataPackage )
       
   664                 {
       
   665                 aDataPackage->UnPackData( location );
       
   666                 }
       
   667                 
       
   668             // Complete notify store event
       
   669             iMobileONStoreEvent = ( RMobilePhoneStore::KStoreEntryAdded );
       
   670 
       
   671             // Return index within entry.iIndex, if needed
       
   672             if ( -1 == iWriteIndexToReturn )
       
   673                 {
       
   674                 // Unpack entry param
       
   675                 RMobileONStore::TMobileONEntryV1Pckg* entryPckg =
       
   676                     ( RMobileONStore::TMobileONEntryV1Pckg*
       
   677                     )iWriteONStoreEntryPtr;
       
   678                 RMobileONStore::TMobileONEntryV1& entry = ( *entryPckg )();
       
   679 
       
   680                 // Set the correct entry index
       
   681                 entry.iIndex = location;
       
   682                 }
       
   683             
       
   684             CompleteNotifyStoreEvent( location );
       
   685             }
       
   686 
       
   687         // Complete with error
       
   688         ReqCompleted( reqHandle, aResult );
       
   689         }
       
   690 
       
   691     iWriteIndexToReturn = 0;
       
   692     iWriteONStoreEntryPtr = NULL;
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------------------------
       
   696 // CMmONStoreTsy::WriteCancel
       
   697 // Cancels an outstanding Write method
       
   698 // (other items were commented in a header).
       
   699 // ---------------------------------------------------------------------------
       
   700 //
       
   701 TInt CMmONStoreTsy::WriteCancel(
       
   702     const TTsyReqHandle aTsyReqHandle )
       
   703     {
       
   704 TFLOGSTRING("TSY: CMmONStoreTsy::WriteCancel");
       
   705     // Check if cancelling is possible. If not, return KErrNone
       
   706     if ( iIsWriteCancellingPossible )
       
   707         {
       
   708         // Reset req handle. Returns the deleted req handle
       
   709         TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   710             EMultimodeONStoreWrite );
       
   711 
       
   712         if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
   713             {
       
   714             iWriteIndexToReturn = 0;
       
   715             iWriteONStoreEntryPtr = NULL;
       
   716             ReqCompleted( aTsyReqHandle, KErrCancel );
       
   717             }
       
   718         }
       
   719 
       
   720     return KErrNone;
       
   721     }
       
   722 
       
   723 // ---------------------------------------------------------------------------
       
   724 // CMmONStoreTsy::DeleteL
       
   725 // Deletes one ON entry by index supplied as a parameter
       
   726 // (other items were commented in a header).
       
   727 // ---------------------------------------------------------------------------
       
   728 //
       
   729 TInt CMmONStoreTsy::DeleteL(
       
   730     const TTsyReqHandle aTsyReqHandle,
       
   731     TInt* aIndex )
       
   732     {
       
   733 TFLOGSTRING("TSY: CMmONStoreTsy::DeleteL");
       
   734     // Initialize ret value
       
   735     TInt ret( KErrGeneral );
       
   736 
       
   737     // Get index and decrease value (CS uses indexes '0' ->, SOS '1' ->)
       
   738     iDeleteONStoreIndex = *aIndex;
       
   739 
       
   740     // Check that entry index value is greater than zero
       
   741     if ( 0 < iDeleteONStoreIndex )
       
   742         {
       
   743         // Forward Delete request to gsm extension. Use Write function
       
   744         // to "erase" ON store entry
       
   745         ret = iMmONStoreExtInterface->DeleteL( EMmTsyONStoreDeleteIPC, 
       
   746             iDeleteONStoreIndex );
       
   747         }
       
   748 
       
   749     // Message construction failed or phonet sender returned error
       
   750     if ( KErrNone != ret )
       
   751         {
       
   752         ReqCompleted( aTsyReqHandle, ret );
       
   753         }
       
   754     else
       
   755         {
       
   756         // Save tsy request handle type
       
   757         iReqHandleType = EMultimodeONStoreDelete;
       
   758         }
       
   759 
       
   760     return KErrNone;
       
   761     }
       
   762 
       
   763 // ---------------------------------------------------------------------------
       
   764 // CMmONStoreTsy::CompleteDelete
       
   765 // Complete delete one ON entry by index
       
   766 // (other items were commented in a header).
       
   767 // ---------------------------------------------------------------------------
       
   768 //
       
   769 void CMmONStoreTsy::CompleteDelete(
       
   770     TInt aResult )
       
   771     {
       
   772 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteDelete");
       
   773     // Reset req handle. Returns the deleted req handle
       
   774     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   775         EMultimodeONStoreDelete );
       
   776 
       
   777     // Check that request was valid
       
   778     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
   779         {
       
   780         // Complete with CS return value
       
   781         ReqCompleted( reqHandle, aResult );
       
   782 
       
   783         // If deletetion done succesfully, complete notify store event
       
   784         if ( KErrNone == aResult )
       
   785             {
       
   786             // Complete notify store event
       
   787             iMobileONStoreEvent = ( RMobilePhoneStore::KStoreEntryDeleted );
       
   788             CompleteNotifyStoreEvent( iDeleteONStoreIndex );
       
   789             }
       
   790         }
       
   791     }
       
   792 
       
   793 // ---------------------------------------------------------------------------
       
   794 // CMmONStoreTsy::DeleteAllL
       
   795 // Delete all ON store entries
       
   796 // (other items were commented in a header).
       
   797 // ---------------------------------------------------------------------------
       
   798 //
       
   799 TInt CMmONStoreTsy::DeleteAllL (
       
   800     const TTsyReqHandle aTsyReqHandle )
       
   801     {
       
   802 TFLOGSTRING("TSY: CMmONStoreTsy::DeleteAllL");
       
   803     // Init variable for DeleteAllPhase1
       
   804     iDeleteAllContinue = ETrue;
       
   805 
       
   806     // Forwarded extension call
       
   807     TInt ret = iMmONStoreExtInterface->DeleteAllL( 
       
   808         EMmTsyONStoreDeleteAllIPC );
       
   809 
       
   810     // Check is return value valid
       
   811     if ( KErrNone != ret )
       
   812         {
       
   813         // Complete with error
       
   814         ReqCompleted( aTsyReqHandle, ret );
       
   815         }
       
   816     else
       
   817         {
       
   818         // Save TSY request handle type
       
   819         iReqHandleType = EMultimodeONStoreDeleteAll;
       
   820         }
       
   821 
       
   822     return KErrNone;
       
   823     }
       
   824 
       
   825 // ---------------------------------------------------------------------------
       
   826 // CMmONStoreTsy::CompleteDeleteAllPhase1L
       
   827 // Complete delete all ON store entries phase 1
       
   828 // (other items were commented in a header).
       
   829 // ---------------------------------------------------------------------------
       
   830 //
       
   831 void CMmONStoreTsy::CompleteDeleteAllPhase1L(
       
   832     TInt aResult )
       
   833     {
       
   834 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteDeleteAllPhase1L");
       
   835     // Check that DeleteAll was called
       
   836     if ( iDeleteAllContinue )
       
   837         {
       
   838         if ( KErrNone == aResult )
       
   839             {
       
   840             // Empty variables in order to call Write-function
       
   841             TBuf<1> name;
       
   842             TBuf<1> telNumber;
       
   843 
       
   844 #ifdef REQHANDLE_TIMER
       
   845             // Set the new terminate time for deleting new entries from
       
   846             // ONStore. About 300ms/entry => about (15s)/(50entries) ->
       
   847             // x2 -> 30sec.
       
   848             iTsyReqHandleStore->PostponeTimeout( EMultimodeONStoreDeleteAll,
       
   849                 30 );
       
   850 #endif // REQHANDLE_TIMER
       
   851 
       
   852             // Forward Delete request to gsm extension. Use Write function
       
   853             // to start process to erase all ON store entries.
       
   854             // '0' means that first location will be deleted first
       
   855               }
       
   856         // If error from SIM Server
       
   857         else
       
   858             {
       
   859             CompleteDeleteAll( aResult );
       
   860             }
       
   861         }
       
   862     }
       
   863 
       
   864 // ---------------------------------------------------------------------------
       
   865 // CMmONStoreTsy::CompleteDeleteAll
       
   866 // Complete delete all ON store entries
       
   867 // (other items were commented in a header).
       
   868 // ---------------------------------------------------------------------------
       
   869 //
       
   870 void CMmONStoreTsy::CompleteDeleteAll(
       
   871     TInt aResult )
       
   872     {
       
   873     // Reset request handle. Returns the deleted request handle
       
   874     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   875         EMultimodeONStoreDeleteAll );
       
   876 
       
   877     // Check that deleted request handle was valid
       
   878     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
   879         {
       
   880 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteDeleteAll");        
       
   881         // Complete with error
       
   882         ReqCompleted( reqHandle, aResult );
       
   883 
       
   884         // If deletion done succesfully, complete notify store event
       
   885         // Notify will complete if it was requested
       
   886         if ( KErrNone == aResult )
       
   887             {
       
   888             // Set notify reason, whole ON store deleted. Store empty.
       
   889             iMobileONStoreEvent = ( RMobilePhoneStore::KStoreEmpty );
       
   890             // Complete notify store event, with '-1' due that more than one
       
   891             // entries deleted.
       
   892             CompleteNotifyStoreEvent( -1 );
       
   893             }
       
   894         }
       
   895     else if(EMultimodeONStoreReqHandleUnknown !=
       
   896 				 iTsyReqHandleStore->GetTsyReqHandle(EMultimodeONStoreStoreAll ))
       
   897     	{
       
   898 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteDeleteAll requested by StoreAllL.");
       
   899     	TInt ret (aResult);
       
   900 		    	
       
   901     	if(KErrNone == ret)
       
   902     		{
       
   903     		// ON store is now empty. Let's begin with reading store size to actually store all entries.
       
   904     		TInt writeAllIndex = -1; // Store index when writing all entries
       
   905     		TRAPD(err, ret = iMmONStoreExtInterface->ReadL(
       
   906     				EMmTsyONStoreWriteSizeIPC, writeAllIndex ));
       
   907 			if(err != KErrNone)
       
   908 				{
       
   909 				ret = err;
       
   910 				}
       
   911     		}
       
   912         if(KErrNone != ret)
       
   913         	{
       
   914         	CompleteStoreAll( ret );
       
   915         	}
       
   916     	}
       
   917     else
       
   918     	{
       
   919 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteDeleteAll - the request has been cancelled or bad req handle");
       
   920     	}
       
   921     }
       
   922 
       
   923 // ---------------------------------------------------------------------------
       
   924 // CMmONStoreTsy::DeleteAllCancel
       
   925 // This method cancels an outstanding DeleteAll -request
       
   926 // (other items were commented in a header).
       
   927 // ---------------------------------------------------------------------------
       
   928 //
       
   929 TInt CMmONStoreTsy::DeleteAllCancel(
       
   930     const TTsyReqHandle aTsyReqHandle )
       
   931     {
       
   932 TFLOGSTRING("TSY: CMmONStoreTsy::DeleteAllCancel");
       
   933     // Reset req handle. Returns the deleted req handle
       
   934     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   935         EMultimodeONStoreDeleteAll );
       
   936 
       
   937     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
   938         {
       
   939         // Prevent DeleteAllPhase1
       
   940         iDeleteAllContinue = EFalse;
       
   941         // Complete with KErrCancel
       
   942         ReqCompleted( aTsyReqHandle, KErrCancel );
       
   943         }
       
   944 
       
   945     return KErrNone;
       
   946     }
       
   947 
       
   948 // ---------------------------------------------------------------------------
       
   949 // CMmONStoreTsy::GetInfoL
       
   950 // This method returns information about the ONStore
       
   951 // (other items were commented in a header).
       
   952 // ---------------------------------------------------------------------------
       
   953 //
       
   954 TInt CMmONStoreTsy::GetInfoL(
       
   955     const TTsyReqHandle aTsyReqHandle,
       
   956     RMobileONStore::TMobileONStoreInfoV1* aInfo )
       
   957     {
       
   958 TFLOGSTRING("TSY: CMmONStoreTsy::GetInfoL");
       
   959 
       
   960     TInt ret( KErrNone );
       
   961 
       
   962     // if aInfo is not correct type, send KErrArgument to client and return
       
   963     if( RMobilePhoneStore::KETelMobileONStoreV1 != aInfo->ExtensionId() )
       
   964         {
       
   965         ReqCompleted( aTsyReqHandle, KErrArgument );
       
   966         return ret;
       
   967         }
       
   968 
       
   969    	// Don't send request if pb init is still ongoing
       
   970 	// instead send KErrNotReady to client
       
   971 	TBool done ( ETrue );
       
   972 TFLOGSTRING2( "TSY: CMmONStoreTsy::GetInfoL iPBList->GetNumberOfObjects() = %d", iMmPhone->PBList()->GetNumberOfObjects());
       
   973 
       
   974 	for( TInt i = 0; i < iMmPhone->PBList()->GetNumberOfObjects(); i++ )
       
   975 	    {
       
   976 	    CMmPhoneBookStoreTsy* pbStore = iMmPhone->PBList()->
       
   977 	        GetMmPBByIndex( i );
       
   978 TFLOGSTRING2( "TSY: CMmONStoreTsy::GetInfoL index = %d", i);    
       
   979 
       
   980 		if ( !pbStore->IsPBInitDone() 
       
   981 			  && ( pbStore->GetPhonebookType() == KADNPhoneBook
       
   982 		      || pbStore->GetPhonebookType() == KFDNPhoneBook )  )
       
   983 		    {
       
   984 TFLOGSTRING("TSY: CMmONStoreTsy::GetInfoL - ADN or FDN init not done");
       
   985 TFLOGSTRING("TSY: CMmONStoreTsy::GetInfoL - in !pbStore->IsPBInitDone()");
       
   986 			// init still ongoing
       
   987 			done = EFalse;
       
   988 			}
       
   989    		}
       
   990    				
       
   991     // Check if some PB is not initialized, if so send KErrNotReady to client   				
       
   992    	if ( !done )
       
   993 		{
       
   994 TFLOGSTRING("TSY: CMmONStoreTsy::GetInfoL - PBInit not done, return KErrNotReady");
       
   995 		ReqCompleted( aTsyReqHandle, KErrNotReady );
       
   996 		}
       
   997 	            
       
   998 	else
       
   999 		{
       
  1000 TFLOGSTRING("TSY: CMmONStoreTsy::GetInfoL - PBInit done, complete");
       
  1001         // Set get info internal pointer
       
  1002         iONStoreInfoChanged = aInfo;
       
  1003         
       
  1004         // Request to GSM extension, get used entries,
       
  1005         // -1 as a index param-> specified location param not needed
       
  1006         ret = iMmONStoreExtInterface->ReadL( EMmTsyONStoreGetInfoIPC, -1 );
       
  1007 
       
  1008         if ( KErrNone != ret )   // Message sending failed
       
  1009             {
       
  1010             ReqCompleted( aTsyReqHandle, ret );
       
  1011             }
       
  1012         else
       
  1013             {
       
  1014             iIsGetInfoActive = ETrue;
       
  1015             // Save tsy req handle type
       
  1016             iReqHandleType = EMultimodeONStoreGetInfo;
       
  1017             }
       
  1018 		}
       
  1019 
       
  1020     return KErrNone;
       
  1021     }
       
  1022 
       
  1023 // ---------------------------------------------------------------------------
       
  1024 // CMmONStoreTsy::CompleteGetInfo
       
  1025 // Completes GetInfo -request
       
  1026 // (other items were commented in a header).
       
  1027 // ---------------------------------------------------------------------------
       
  1028 //
       
  1029 void CMmONStoreTsy::CompleteGetInfo( 
       
  1030     TInt aResult,
       
  1031     CMmDataPackage* aDataPackage )
       
  1032     {
       
  1033 TFLOGSTRING2("TSY: CMmONStoreTsy::CompleteGetInfo - Result: %d", aResult );
       
  1034 
       
  1035     // The number of used entries
       
  1036     TServiceType serviceType;   
       
  1037     //unpack data
       
  1038     aDataPackage->UnPackData( serviceType );
       
  1039 
       
  1040     // Reset req handle. Returns the deleted req handle
       
  1041     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
  1042         EMultimodeONStoreGetInfo );
       
  1043 
       
  1044     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
  1045         {
       
  1046 
       
  1047         // If request was not cancelled or no error from SIM
       
  1048         // give info to client
       
  1049         if ( KErrNone == aResult )
       
  1050             {
       
  1051             iONStoreInfo.iTotalEntries = serviceType.iNumOfEntries;
       
  1052             iONStoreInfo.iUsedEntries = serviceType.iUsedEntries;
       
  1053             iONStoreInfo.iNumberLen = serviceType.iNumLen;
       
  1054             iONStoreInfo.iTextLen = serviceType.iNameLen;
       
  1055 
       
  1056             *iONStoreInfoChanged = iONStoreInfo;
       
  1057 
       
  1058 TFLOGSTRING3("TSY: CMmONStoreTsy::CompleteGetInfo - Name: %S, Type: %d", &iONStoreInfoChanged->iName, iONStoreInfoChanged->iType );
       
  1059 TFLOGSTRING3("TSY: CMmONStoreTsy::CompleteGetInfo - Total entries: %d, Used entries: %d", iONStoreInfoChanged->iTotalEntries, iONStoreInfoChanged->iUsedEntries );
       
  1060 TFLOGSTRING3("TSY: CMmONStoreTsy::CompleteGetInfo - Max Number length: %d, Max Name length: %d", iONStoreInfoChanged->iNumberLen, iONStoreInfoChanged->iTextLen );
       
  1061             }
       
  1062 
       
  1063         // NULL the pointer to info supplied to TSY from the client
       
  1064         iONStoreInfoChanged = NULL;
       
  1065         iIsGetInfoActive = EFalse;
       
  1066     
       
  1067         // Complete with error
       
  1068         ReqCompleted( reqHandle, aResult );
       
  1069         }
       
  1070     }
       
  1071 
       
  1072 // ---------------------------------------------------------------------------
       
  1073 // CMmONStoreTsy::SetInfo
       
  1074 // This method initializes ONStore internal info parameters
       
  1075 // (other items were commented in a header).
       
  1076 // ---------------------------------------------------------------------------
       
  1077 //
       
  1078 void CMmONStoreTsy::SetInfo()
       
  1079     {
       
  1080 TFLOGSTRING("TSY: CMmONStoreTsy::SetInfo");
       
  1081     // The name of the store
       
  1082     iONStoreInfo.iName = KETelOwnNumberStore;
       
  1083 
       
  1084     // The maximum number of characters for the number in a phonebook entry
       
  1085     iONStoreInfo.iNumberLen = KNoInfoAvail;
       
  1086 
       
  1087     // The maximum number of characters for the text tag in a phonebook entry
       
  1088     iONStoreInfo.iTextLen = KMaxTextLength;
       
  1089 
       
  1090     // The type of entry in the phone-side store
       
  1091     iONStoreInfo.iType = RMobilePhoneStore::EOwnNumberStore;
       
  1092 
       
  1093     // Indicates the capabilities of the store
       
  1094     iONStoreInfo.iCaps = KONStoreCaps;
       
  1095 
       
  1096     // Indicates the current number of entries that may be held in this store
       
  1097     iONStoreInfo.iUsedEntries = KNoInfoAvail;
       
  1098 
       
  1099     // Indicates the total numbetr of entries
       
  1100     iONStoreInfo.iTotalEntries = KNoInfoAvail;
       
  1101     }
       
  1102 
       
  1103 // ---------------------------------------------------------------------------
       
  1104 // CMmONStoreTsy::GetInfoCancel
       
  1105 // This method cancels an outstanding GetInfo -request
       
  1106 // (other items were commented in a header).
       
  1107 // ---------------------------------------------------------------------------
       
  1108 //
       
  1109 TInt CMmONStoreTsy::GetInfoCancel(
       
  1110     const TTsyReqHandle aTsyReqHandle )
       
  1111     {
       
  1112 TFLOGSTRING("TSY: CMmONStoreTsy::GetInfoCancel");
       
  1113 
       
  1114     iTsyReqHandleStore->ResetTsyReqHandle( EMultimodeONStoreGetInfo );
       
  1115 
       
  1116     // Complete with KErrCancel
       
  1117     ReqCompleted( aTsyReqHandle, KErrCancel );
       
  1118 
       
  1119     return KErrNone;
       
  1120     }
       
  1121 
       
  1122 // ---------------------------------------------------------------------------
       
  1123 // CMmONStoreTsy::NotifyStoreEvent
       
  1124 // This method activates notifying of ONStore events
       
  1125 // (other items were commented in a header).
       
  1126 // ---------------------------------------------------------------------------
       
  1127 //
       
  1128 TInt CMmONStoreTsy::NotifyStoreEvent(
       
  1129     RMobilePhoneStore::TMobileStoreEvent* aEvent,
       
  1130     TInt* aIndex )
       
  1131     {
       
  1132 TFLOGSTRING("TSY: CMmONStoreTsy::NotifyStoreEvent");
       
  1133     TTsyReqHandle requestHandle = iTsyReqHandleStore->GetTsyReqHandle( 
       
  1134         EMultimodeONStoreNotifyStoreEvent );
       
  1135 
       
  1136     // If request is not running
       
  1137     if ( 0 == requestHandle )
       
  1138         {
       
  1139         // Set variables to notify
       
  1140         iNotifyONStoreEventPtr = aEvent;
       
  1141         iNotifyONStoreEventIndexPtr = aIndex;
       
  1142 
       
  1143         // Save tsy req handle type
       
  1144         iReqHandleType = EMultimodeONStoreNotifyStoreEvent;
       
  1145         }
       
  1146 
       
  1147     return KErrNone;
       
  1148     }
       
  1149 
       
  1150 // ---------------------------------------------------------------------------
       
  1151 // CMmONStoreTsy::CompleteNotifyStoreEvent
       
  1152 // This method is called when some of ONStore event happens
       
  1153 // (other items were commented in a header).
       
  1154 // ---------------------------------------------------------------------------
       
  1155 //
       
  1156 void CMmONStoreTsy::CompleteNotifyStoreEvent(
       
  1157     TInt aLocation )
       
  1158     {
       
  1159 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteNotifyStoreEvent");
       
  1160     // Reset request handle. Returns the deleted req handle
       
  1161     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
  1162         EMultimodeONStoreNotifyStoreEvent );
       
  1163 
       
  1164     // If request handle is valid
       
  1165     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
  1166         {
       
  1167         RMobilePhoneStore::TMobileStoreEvent* ONStoreEvent =
       
  1168             REINTERPRET_CAST( RMobilePhoneStore::TMobileStoreEvent*,
       
  1169             iNotifyONStoreEventPtr );
       
  1170 
       
  1171         // Fill notify information
       
  1172         *ONStoreEvent = iMobileONStoreEvent;
       
  1173         *iNotifyONStoreEventIndexPtr = aLocation;
       
  1174 
       
  1175         ReqCompleted( reqHandle, KErrNone );
       
  1176         }
       
  1177     }
       
  1178 
       
  1179 // ---------------------------------------------------------------------------
       
  1180 // CMmONStoreTsy::NotifyStoreEventCancel
       
  1181 // This method cancels an outstanding NotifyStoreEvent -request
       
  1182 // (other items were commented in a header).
       
  1183 // ---------------------------------------------------------------------------
       
  1184 //
       
  1185 TInt CMmONStoreTsy::NotifyStoreEventCancel(
       
  1186     const TTsyReqHandle aTsyReqHandle )
       
  1187     {
       
  1188 TFLOGSTRING("TSY: CMmONStoreTsy::NotifyStoreEventCancel");
       
  1189     // Reset req handle. Returns the deleted req handle
       
  1190     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
  1191         EMultimodeONStoreNotifyStoreEvent );
       
  1192 
       
  1193     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
  1194         {
       
  1195         // Reset variables and complete with KErrCancel
       
  1196         iNotifyONStoreEventPtr = NULL;
       
  1197         iNotifyONStoreEventIndexPtr = NULL;
       
  1198         ReqCompleted( aTsyReqHandle, KErrCancel );
       
  1199         }
       
  1200 
       
  1201     return KErrNone;
       
  1202     }
       
  1203 
       
  1204 // ---------------------------------------------------------------------------
       
  1205 // CMmONStoreTsy::ReadAllPhase1L
       
  1206 // This method starts the two-phased ReadAll -request
       
  1207 // (other items were commented in a header).
       
  1208 // ---------------------------------------------------------------------------
       
  1209 //
       
  1210 TInt CMmONStoreTsy::ReadAllPhase1L(
       
  1211     const TTsyReqHandle aReqHandle,
       
  1212     const RMobilePhone::TClientId* aId, 
       
  1213     TInt* aBufSize )
       
  1214     {
       
  1215 TFLOGSTRING("TSY: CMmONStoreTsy::ReadAllPhase1L");
       
  1216     // Init return value
       
  1217     TInt ret( KErrNone );
       
  1218     
       
  1219     // Store index when reading all entries
       
  1220     TInt readAllIndex = -1; 
       
  1221     
       
  1222     iReadAllBufSizePtr = aBufSize;
       
  1223     iReadAllId = *aId;
       
  1224     
       
  1225     iReadAllONStoreIndex = 0;
       
  1226     ret = iMmONStoreExtInterface->
       
  1227         ReadL( EMmTsyONStoreReadSizeIPC, readAllIndex );
       
  1228 
       
  1229     // Increase PhoneBookStoreIndex by 1.
       
  1230     iReadAllONStoreIndex++;
       
  1231 
       
  1232     // Unsuccess request for read entry
       
  1233     if ( KErrNone != ret )
       
  1234         {
       
  1235         // Complete with error from Phonet Sender
       
  1236         ReqCompleted( aReqHandle, ret );
       
  1237         }
       
  1238     else
       
  1239         {
       
  1240         // Save tsy req handle type
       
  1241         iReqHandleType = EMultimodeONStoreReadAll;
       
  1242         }
       
  1243 
       
  1244     return KErrNone;
       
  1245     }
       
  1246     
       
  1247 // ---------------------------------------------------------------------------
       
  1248 // CMmONStoreTsy::InternalRetrieveONListReadSizeL
       
  1249 // This method is part of ReadAll -request, purposed to get
       
  1250 // the ONStore size and continue request with reading the whole ONStore
       
  1251 // (other items were commented in a header).
       
  1252 // ---------------------------------------------------------------------------
       
  1253 //
       
  1254 void CMmONStoreTsy::InternalRetrieveONListReadSizeL(
       
  1255     TInt aError,
       
  1256     CMmDataPackage* aDataPackage )
       
  1257     {
       
  1258 TFLOGSTRING("TSY: CMmONStoreTsy::InternalRetrieveONListReadSizeL");
       
  1259     if ( KErrNone == aError )
       
  1260         {
       
  1261         TInt size;
       
  1262         aDataPackage->UnPackData( size );
       
  1263 TFLOGSTRING2("TSY: CMmONStoreTsy::InternalRetrieveONListReadSizeL size=%d",size);
       
  1264         if( 0 < size )
       
  1265             {
       
  1266             *iReadAllBufSizePtr = size;
       
  1267             iReadAllONStoreSize = size;
       
  1268             MakeInternalRetrieveONListReadReqL();
       
  1269             }
       
  1270         else
       
  1271             {
       
  1272 TFLOGSTRING2("TSY: CMmONStoreTsy::InternalRetrieveONListReadSizeL size is %d", size);
       
  1273             CompleteReadAllPhase1Req( KErrNotFound );
       
  1274             }
       
  1275         }
       
  1276     else
       
  1277         {
       
  1278         CompleteReadAllPhase1Req( aError );
       
  1279         }
       
  1280 
       
  1281     } 
       
  1282 
       
  1283 // ---------------------------------------------------------------------------
       
  1284 // CMmONStoreTsy::MakeInternalRetrieveONListReadReqL
       
  1285 // This method is part of ReadAll -request, purposed to read
       
  1286 // entries from ONStore and handle the ONStoreTSY's internal read all -index.
       
  1287 // (other items were commented in a header).
       
  1288 // ---------------------------------------------------------------------------
       
  1289 //
       
  1290 void CMmONStoreTsy::MakeInternalRetrieveONListReadReqL()
       
  1291     {
       
  1292 TFLOGSTRING("TSY: CMmONStoreTsy::MakeInternalRetrieveONListReadReqL");
       
  1293     // Read one entry from the PhoneBook.
       
  1294     TInt ret = iMmONStoreExtInterface->
       
  1295         ReadL( EMmTsyONStoreReadEntryIPC,iReadAllONStoreIndex );
       
  1296 
       
  1297 	// Increase PhoneBookStoreIndex by 1.
       
  1298     iReadAllONStoreIndex++;
       
  1299 
       
  1300     // Unsuccess request for read entry
       
  1301     if ( KErrNone != ret )
       
  1302         {
       
  1303         // Complete with error from Phonet Sender
       
  1304         CompleteReadAllPhase1Req( ret );
       
  1305         }
       
  1306     }
       
  1307     
       
  1308 // ---------------------------------------------------------------------------
       
  1309 // CMmONStoreTsy::InternalRetrieveONListReadEntryL
       
  1310 // This method is part of ReadAll -request, purposed to get the read response 
       
  1311 // and complete ReadAllPhase1 -request, if all the entries have been read.
       
  1312 // (other items were commented in a header).
       
  1313 // ---------------------------------------------------------------------------
       
  1314 //
       
  1315 void CMmONStoreTsy::InternalRetrieveONListReadEntryL(
       
  1316     TInt aError,
       
  1317     CMmDataPackage* aDataPackage)
       
  1318     {
       
  1319 TFLOGSTRING("TSY: CMmONStoreTsy::InternalRetrieveONListReadEntryL");
       
  1320     if ( KErrNone == aError )
       
  1321         {
       
  1322         // Check if there is data to save
       
  1323         if ( aDataPackage )
       
  1324             {
       
  1325             TONStoreMsg onStoreMsg;
       
  1326             aDataPackage->UnPackData( onStoreMsg );
       
  1327             // Add entry to the TSY's internal storage array
       
  1328             iONStoreListArray->AppendL( onStoreMsg );
       
  1329             }
       
  1330         // Check if all entries read, complete if so
       
  1331         if ( iReadAllONStoreIndex > iReadAllONStoreSize )
       
  1332             {
       
  1333             TInt leaveCode( KErrNone );
       
  1334 
       
  1335             TRAP( leaveCode, CompleteReadAllPhase1L(); );
       
  1336             // Memory allocation failed
       
  1337             // TRAP is used here, because if memory allocation
       
  1338             // failed, list array elements must be destroyed
       
  1339             if ( leaveCode != KErrNone )
       
  1340                 {
       
  1341                 DeleteONStoreListArrayElements();
       
  1342                 CompleteReadAllPhase1Req( leaveCode );
       
  1343                 }
       
  1344             }
       
  1345         // There is more entries to read
       
  1346         else
       
  1347             {
       
  1348             MakeInternalRetrieveONListReadReqL();
       
  1349             }
       
  1350         }
       
  1351     else
       
  1352         {
       
  1353         CompleteReadAllPhase1Req( aError );
       
  1354         }
       
  1355     }
       
  1356   
       
  1357 // ---------------------------------------------------------------------------
       
  1358 // CMmONStoreTsy::CompleteReadAllPhase1L
       
  1359 // Completes internal retrieving entries from the ONStore
       
  1360 // (other items were commented in a header).
       
  1361 // ---------------------------------------------------------------------------
       
  1362 //
       
  1363 TInt CMmONStoreTsy::CompleteReadAllPhase1L()
       
  1364     {
       
  1365 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteReadAllPhase1L");
       
  1366     // Reset req handle. Returns the deleted req handle
       
  1367     TTsyReqHandle reqHandle = iTsyReqHandleStore->GetTsyReqHandle(
       
  1368         EMultimodeONStoreReadAll );
       
  1369 
       
  1370     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
  1371         {
       
  1372         // Check that ONStoreList array contains ONStore entries
       
  1373         if( 0 < iONStoreListArray->Count() )
       
  1374             {
       
  1375             // read the list, store its content and then return size of this
       
  1376             // buffer to client
       
  1377             CMobilePhoneONList* list = CMobilePhoneONList::NewL();
       
  1378             CleanupStack::PushL( list );
       
  1379 
       
  1380             RMobileONStore::TMobileONEntryV1 entry;
       
  1381 
       
  1382             // Loop until TSY's internal ONStorage is empty 
       
  1383             while( !iONStoreListArray->Count() == 0 )     
       
  1384                 {
       
  1385                 TONStoreMsg& ONStoreMsg = iONStoreListArray->At(0);
       
  1386  
       
  1387                 // Fill TMobileONEntryV1 information
       
  1388                 entry.iMode = RMobilePhone::ENetworkModeUnknown;
       
  1389                 entry.iService = RMobilePhone::EServiceUnspecified;
       
  1390                 entry.iIndex = ( ONStoreMsg.iLocation );
       
  1391                                                              // from SIM
       
  1392                 entry.iNumber.iTypeOfNumber = RMobilePhone::EUnknownNumber;
       
  1393                 entry.iNumber.iNumberPlan = 
       
  1394                     RMobilePhone::EUnknownNumberingPlan;
       
  1395                 entry.iNumber.iTelNumber.Copy( ONStoreMsg.iTelNumber );
       
  1396                 entry.iText.Copy( ONStoreMsg.iName );
       
  1397          
       
  1398                 // Add to PhoneBook list
       
  1399                 list->AddEntryL( entry );
       
  1400 
       
  1401                 // Delete list member
       
  1402                 iONStoreListArray->Delete(0);
       
  1403                 iONStoreListArray->Compress();
       
  1404                 }
       
  1405 
       
  1406             // Store the streamed list and the client ID
       
  1407             CListReadAllAttempt* read = CListReadAllAttempt::NewL(
       
  1408                 &iReadAllId );
       
  1409             CleanupStack::PushL( read );
       
  1410 
       
  1411             read->iListBuf = list->StoreLC();
       
  1412             CleanupStack::Pop(); // Pop the CBufFlat allocated by StoreLC
       
  1413 
       
  1414             iONStoreReadAllArray->AppendL( read );
       
  1415             CleanupStack::Pop(); // Pop the CListReadAllAttempt
       
  1416             
       
  1417             // Return the CBufFlat’s size to client
       
  1418             *iReadAllBufSizePtr = ( read->iListBuf )->Size();
       
  1419  
       
  1420             // Complete first phase of list retrieval
       
  1421             CompleteReadAllPhase1Req( KErrNone );
       
  1422             CleanupStack::PopAndDestroy(); // Pop&destroy list
       
  1423 
       
  1424             return KErrNone;
       
  1425             }
       
  1426         else    // Store was empty
       
  1427             {
       
  1428             CompleteReadAllPhase1Req( KErrNotFound );
       
  1429             }
       
  1430         }
       
  1431 
       
  1432     return KErrNone;
       
  1433     }
       
  1434 
       
  1435 // ---------------------------------------------------------------------------
       
  1436 // CMmONStoreTsy::CompleteReadAllPhase1Req
       
  1437 // Completes ReadAll phase1 -request
       
  1438 // (other items were commented in a header).
       
  1439 // ---------------------------------------------------------------------------
       
  1440 //
       
  1441 void CMmONStoreTsy::CompleteReadAllPhase1Req(
       
  1442     TInt aResult )
       
  1443     {
       
  1444 TFLOGSTRING("TSY: CMmONStoreTsy::CompleteReadAllPhase1Req");
       
  1445     // Reset req handle. Returns the deleted req handle
       
  1446     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
  1447         EMultimodeONStoreReadAll );
       
  1448 
       
  1449     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
  1450         {
       
  1451         // If this request is completed with error,
       
  1452         // delete ReadAll -arrays
       
  1453         if ( KErrNone != aResult )
       
  1454             {
       
  1455             // Delete ONStore array
       
  1456             iONStoreReadAllArray->ResetAndDestroy();
       
  1457             // Delete ONStoreList array
       
  1458             DeleteONStoreListArrayElements();
       
  1459             }
       
  1460 
       
  1461         ReqCompleted( reqHandle, aResult );
       
  1462         }
       
  1463     }
       
  1464 
       
  1465 // ---------------------------------------------------------------------------
       
  1466 // CMmONStoreTsy::DeleteONStoreListArrayElements
       
  1467 // Deletes ONStore elements that are stored to an array
       
  1468 // (other items were commented in a header).
       
  1469 // ---------------------------------------------------------------------------
       
  1470 //
       
  1471 void CMmONStoreTsy::DeleteONStoreListArrayElements()
       
  1472     {
       
  1473 TFLOGSTRING("TSY: CMmONStoreTsy::DeleteONStoreListArrayElements");
       
  1474     while( 0 == !iONStoreListArray->Count() )
       
  1475         {
       
  1476         // Delete list member
       
  1477         iONStoreListArray->Delete(0);
       
  1478         iONStoreListArray->Compress();
       
  1479         }
       
  1480 
       
  1481     // Delete pointers to elements from array
       
  1482     iONStoreListArray->Reset();
       
  1483     }
       
  1484 
       
  1485 // ---------------------------------------------------------------------------
       
  1486 // CMmONStoreTsy::ReadAllPhase2
       
  1487 // Read all ONStore entries, second phase
       
  1488 // (other items were commented in a header).
       
  1489 // ---------------------------------------------------------------------------
       
  1490 //
       
  1491 TInt CMmONStoreTsy::ReadAllPhase2(
       
  1492     TTsyReqHandle aTsyReqHandle,
       
  1493     const RMobilePhone::TClientId* aId,
       
  1494     TDes8* aBuffer )
       
  1495     {
       
  1496 TFLOGSTRING("TSY: CMmONStoreTsy::ReadAllPhase2");
       
  1497     // Initialize ret value
       
  1498     TInt ret( KErrCorrupt );
       
  1499 
       
  1500     // Set read pointer to NULL
       
  1501     CListReadAllAttempt* read = NULL;
       
  1502 
       
  1503     // Find the read attempt from this client
       
  1504     for ( TInt i=0; ( i<iONStoreReadAllArray->Count() ) &&
       
  1505         ( KErrCorrupt == ret ); ++i )
       
  1506         {
       
  1507         // Get and set item from array
       
  1508         // This is not deleted later on within this function if session
       
  1509         // handle and subsession handle does not match.
       
  1510         // Someone else 'owns' this data.
       
  1511         read = iONStoreReadAllArray->At( i );
       
  1512 
       
  1513         // Check that session and client are rigth ones
       
  1514         if ( ( read->iClient.iSessionHandle == aId->iSessionHandle ) &&
       
  1515             ( read->iClient.iSubSessionHandle == aId->iSubSessionHandle ) )
       
  1516             {
       
  1517             // Set pointer to list buffer
       
  1518             TPtr8 bufPtr( ( read->iListBuf )->Ptr( 0 ) );
       
  1519             // Copy the streamed list to the client
       
  1520             aBuffer->Copy( bufPtr );
       
  1521 
       
  1522             // Delete read and item from internal array
       
  1523             delete read;
       
  1524             iONStoreReadAllArray->Delete( i );
       
  1525 
       
  1526             // Complete request
       
  1527             ReqCompleted( aTsyReqHandle, KErrNone );
       
  1528             // Set ret to KErrNone so that loop can exit
       
  1529             ret = KErrNone;
       
  1530             }
       
  1531         }
       
  1532 
       
  1533     // Check ret value
       
  1534     if ( KErrCorrupt == ret )
       
  1535         {
       
  1536         // Doesn't found the matching client from read all phase 1
       
  1537         iONStoreReadAllArray->ResetAndDestroy();
       
  1538         ReqCompleted( aTsyReqHandle, KErrCorrupt);
       
  1539         }
       
  1540 
       
  1541     return KErrNone;
       
  1542     }
       
  1543 
       
  1544 // ---------------------------------------------------------------------------
       
  1545 // CMmONStoreTsy::ReadAllCancel
       
  1546 // Cancels an outstanding ReadAll -request
       
  1547 // (other items were commented in a header).
       
  1548 // ---------------------------------------------------------------------------
       
  1549 //
       
  1550 TInt CMmONStoreTsy::ReadAllCancel(
       
  1551     const TTsyReqHandle aTsyReqHandle )
       
  1552     {
       
  1553 TFLOGSTRING("TSY: CMmONStoreTsy::ReadAllCancel");
       
  1554     // Reset req handle. Returns the deleted req handle
       
  1555     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
  1556         EMultimodeONStoreReadAll );
       
  1557 
       
  1558     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
  1559         {
       
  1560         // Delete ONStore array
       
  1561         iONStoreReadAllArray->ResetAndDestroy();
       
  1562         // Delete ONStoreList elements
       
  1563         DeleteONStoreListArrayElements();
       
  1564         // Complete with KErrCancel
       
  1565         ReqCompleted( aTsyReqHandle, KErrCancel );
       
  1566         }
       
  1567 
       
  1568     return KErrNone;
       
  1569     }
       
  1570 
       
  1571 // ---------------------------------------------------------------------------
       
  1572 // CMmONStoreTsy::StoreAllL
       
  1573 // This method stores the whole ONStore in one go
       
  1574 // (other items were commented in a header).
       
  1575 // ---------------------------------------------------------------------------
       
  1576 //
       
  1577 TInt CMmONStoreTsy::StoreAllL(
       
  1578     const TTsyReqHandle aTsyReqHandle,
       
  1579     TDes8* aBuffer )
       
  1580     {
       
  1581 TFLOGSTRING("TSY: CMmONStoreTsy::StoreAllL");
       
  1582     // Init return value
       
  1583     TInt ret( KErrNone );
       
  1584     
       
  1585     // Set pointer to descrptor
       
  1586     iStoreAllBuffer = aBuffer;
       
  1587 
       
  1588     // Create ONList and push it to cleanup stack
       
  1589     CMobilePhoneONList* aONList=CMobilePhoneONList::NewL();
       
  1590     CleanupStack::PushL(aONList);
       
  1591     aONList->RestoreL(*aBuffer);
       
  1592     
       
  1593     // Get the size of ONList
       
  1594     // Note: If this list does not contain any data, all the entries
       
  1595     // will be deleted from ONStore!!
       
  1596     iStoreAllONListSize = aONList->Enumerate();
       
  1597     
       
  1598     // StoreAll overwrites ON phone store. So, first delete all store.
       
  1599     ret = iMmONStoreExtInterface->DeleteAllL( 
       
  1600         EMmTsyONStoreDeleteAllIPC );
       
  1601 TFLOGSTRING2("CMmONStoreTsy::StoreAllL - DeleteAllL() ret: %d", ret);
       
  1602     
       
  1603     // Message construction failed or phonet sender returned error
       
  1604     if ( KErrNone != ret )
       
  1605         {
       
  1606         ReqCompleted( aTsyReqHandle, ret );
       
  1607         }
       
  1608     else
       
  1609         {
       
  1610         // Save tsy req handle type
       
  1611         iReqHandleType = EMultimodeONStoreStoreAll;
       
  1612         }
       
  1613 
       
  1614     CleanupStack::PopAndDestroy(); // aONList
       
  1615    
       
  1616     return KErrNone;
       
  1617     }
       
  1618 
       
  1619 // ---------------------------------------------------------------------------
       
  1620 // CMmONStoreTsy::InternalStoreAllGetSizeL
       
  1621 // This method is part of StoreAll -request, purposed to get
       
  1622 // the ONStore size and continue request with writing the whole ONStore
       
  1623 // (other items were commented in a header).
       
  1624 // ---------------------------------------------------------------------------
       
  1625 //
       
  1626 void CMmONStoreTsy::InternalStoreAllGetSizeL(
       
  1627     TInt aError,
       
  1628     CMmDataPackage* aDataPackage )
       
  1629     {
       
  1630 TFLOGSTRING2("CMmONStoreTsy::InternalStoreAllGetSizeL %d",aError);
       
  1631     if ( KErrNone == aError )
       
  1632         {
       
  1633         TInt size;
       
  1634         aDataPackage->UnPackData( size );
       
  1635 
       
  1636 TFLOGSTRING2("CMmONStoreTsy::InternalStoreAllGetSizeL size %d", size);
       
  1637         // Check the size of ONStore and the ONList size from Client
       
  1638         // Client's ONList size should not be greater than ONStore size
       
  1639         if ( size > 0 && size >= iStoreAllONListSize )
       
  1640             {
       
  1641             TTsyReqHandle storeAllRequestHandle = 
       
  1642                 iTsyReqHandleStore->GetTsyReqHandle(
       
  1643                 EMultimodeONStoreStoreAll );
       
  1644             // Check if request has been cancelled or bad req. handle
       
  1645             if ( EMultimodeONStoreReqHandleUnknown != storeAllRequestHandle )
       
  1646                 {
       
  1647                 // Ok, set the class attribute iReadAllPhoneBookStoreIndex 
       
  1648                 // with the size of the ONStore
       
  1649                 iStoreAllONStoreSize = 
       
  1650                 size;
       
  1651                 iStoreAllONStoreIndex = 0;
       
  1652                 MakeInternalStoreAllWriteReqL();
       
  1653                 }
       
  1654             }
       
  1655         // Error occurs, when the size of the ONStore is not > 0
       
  1656         // or ONList size is greater that ONStore
       
  1657         else
       
  1658             {
       
  1659             CompleteStoreAll( KErrTooBig );
       
  1660             }
       
  1661         }
       
  1662     // Error from SIM Server
       
  1663     else
       
  1664         {
       
  1665         CompleteStoreAll( aError );
       
  1666         }
       
  1667     }
       
  1668 
       
  1669 // ---------------------------------------------------------------------------
       
  1670 // CMmONStoreTsy::MakeInternalStoreAllWriteReqL
       
  1671 // This method is part of StoreAll -request, purposed to make
       
  1672 // a write request by storeall index and an entry from ONList
       
  1673 // (other items were commented in a header).
       
  1674 // ---------------------------------------------------------------------------
       
  1675 //
       
  1676 void CMmONStoreTsy::MakeInternalStoreAllWriteReqL()
       
  1677     {
       
  1678 TFLOGSTRING("CMmONStoreTsy::MakeInternalStoreAllWriteReqL ");
       
  1679     // Create ONList and push it to cleanup stack
       
  1680     CMobilePhoneONList* aONList=CMobilePhoneONList::NewL();
       
  1681     CleanupStack::PushL(aONList);
       
  1682 
       
  1683     // Check the existance of buffered ONlist
       
  1684     if ( iStoreAllBuffer )
       
  1685         {
       
  1686         aONList->RestoreL(*iStoreAllBuffer);
       
  1687 
       
  1688         // Initialize ONStore entry
       
  1689         RMobileONStore::TMobileONEntryV1 entry;
       
  1690         TInt ret( KErrNone );
       
  1691 
       
  1692         // Loop until all entriest written
       
  1693         if( iStoreAllONStoreIndex < iStoreAllONStoreSize )
       
  1694             {
       
  1695             // Get entry from ONList from clinet, if list contains
       
  1696             // entries
       
  1697             if ( iStoreAllONStoreIndex < iStoreAllONListSize )
       
  1698                 {
       
  1699                 // Get entry from ONStore list
       
  1700                 entry = aONList->GetEntryL( iStoreAllONStoreIndex );
       
  1701                 }
       
  1702             // List does not contain entries anymore!!
       
  1703             // Destroy rest of the entries by overwriting Nam&Num with zero
       
  1704             else
       
  1705                 {
       
  1706                 entry.iText.Zero();
       
  1707                 entry.iNumber.iTelNumber.Zero();
       
  1708                 }
       
  1709 
       
  1710 #ifdef REQHANDLE_TIMER
       
  1711             // Set 10 sec. terminate time for writing a new entry
       
  1712             iTsyReqHandleStore->PostponeTimeout( 
       
  1713                 EMultimodeONStoreStoreAll, 10 );
       
  1714 #endif // REQHANDLE_TIMER
       
  1715             CMmDataPackage dataPckg;
       
  1716             dataPckg.PackData( &entry );
       
  1717             // Forward request to GSM Extension
       
  1718             ret = iMmONStoreExtInterface->WriteAllL(    
       
  1719                 EMmTsyONStoreWriteEntryIPC, &dataPckg );
       
  1720 
       
  1721             if ( KErrNone != ret )
       
  1722                 {
       
  1723                 CompleteStoreAll( ret );
       
  1724                 }
       
  1725             iStoreAllONStoreIndex++;
       
  1726             }
       
  1727         // All entries written; complete with KErrNone
       
  1728         else
       
  1729             {
       
  1730             CompleteStoreAll( KErrNone );
       
  1731             }
       
  1732         }
       
  1733     // List not found
       
  1734     else
       
  1735         {
       
  1736         CompleteStoreAll( KErrCorrupt );
       
  1737         }
       
  1738 
       
  1739     CleanupStack::PopAndDestroy(); // aONList
       
  1740     }
       
  1741 
       
  1742 // ---------------------------------------------------------------------------
       
  1743 // CMmONStoreTsy::InternalStoreAllWriteEntryL
       
  1744 // This function is part of StoreAll -request purposed to get
       
  1745 // the error value from write one ONStore entry -request. This method 
       
  1746 // continues StoreAll -request if the error is KErrNone supplied as 
       
  1747 // a parameter.
       
  1748 // (other items were commented in a header).
       
  1749 // ---------------------------------------------------------------------------
       
  1750 //
       
  1751 void CMmONStoreTsy::InternalStoreAllWriteEntryL(
       
  1752     TInt aResult )
       
  1753     {
       
  1754 TFLOGSTRING2("CMmONStoreTsy::InternalStoreAllWriteEntryL %d",aResult);
       
  1755 
       
  1756 	TTsyReqHandle storeAllRequestHandle = 
       
  1757 		iTsyReqHandleStore->GetTsyReqHandle(
       
  1758 				EMultimodeONStoreStoreAll );
       
  1759 	
       
  1760 	if ( EMultimodeONStoreReqHandleUnknown == storeAllRequestHandle )
       
  1761 		{
       
  1762 		// The request has been cancelled or bad req handle
       
  1763 TFLOGSTRING("The ON store request has been cancelled or bad req handle");
       
  1764 		return;
       
  1765 		}
       
  1766 
       
  1767     if ( KErrNone == aResult )
       
  1768         {
       
  1769         MakeInternalStoreAllWriteReqL();
       
  1770         }
       
  1771     // Error from SIM Server, complete with an error
       
  1772     else
       
  1773         {
       
  1774         CompleteStoreAll( aResult );
       
  1775         }
       
  1776     }
       
  1777 
       
  1778 // ---------------------------------------------------------------------------
       
  1779 // CMmONStoreTsy::CompleteStoreAll
       
  1780 // This method completes StoreAll -request
       
  1781 // (other items were commented in a header).
       
  1782 // ---------------------------------------------------------------------------
       
  1783 //
       
  1784 void CMmONStoreTsy::CompleteStoreAll(
       
  1785     TInt aResult )
       
  1786     {
       
  1787 TFLOGSTRING2("CMmONStoreTsy::CompleteStoreAll %d",aResult);
       
  1788     // Reset req handle. Returns the deleted req handle
       
  1789     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
  1790         EMultimodeONStoreStoreAll );
       
  1791 
       
  1792     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
  1793         {
       
  1794 
       
  1795         if ( KErrNone == aResult )
       
  1796             {
       
  1797             // Set notify reason, whole ON store stored. Do refresh.
       
  1798             iMobileONStoreEvent = ( RMobilePhoneStore::KStoreDoRefresh );
       
  1799 
       
  1800             // Complete notify store event, with '-1' due that whole
       
  1801             // store has been changed
       
  1802             CompleteNotifyStoreEvent( -1 );
       
  1803             }
       
  1804 
       
  1805         // Reset class attributes
       
  1806         iStoreAllBuffer = NULL;
       
  1807         iStoreAllONStoreSize = 0;
       
  1808         iStoreAllONStoreIndex = 0;
       
  1809         iStoreAllONListSize = 0;
       
  1810 
       
  1811         // Complete request
       
  1812         ReqCompleted( reqHandle, aResult );
       
  1813         }
       
  1814     }
       
  1815 
       
  1816 // ---------------------------------------------------------------------------
       
  1817 // CMmONStoreTsy::StoreAllCancel
       
  1818 // This method cancels an outstanding StoreAll -request
       
  1819 // (other items were commented in a header).
       
  1820 // ---------------------------------------------------------------------------
       
  1821 //
       
  1822 TInt CMmONStoreTsy::StoreAllCancel(
       
  1823     TTsyReqHandle aTsyReqHandle )
       
  1824     {
       
  1825 TFLOGSTRING("CMmONStoreTsy::StoreAllCancel");
       
  1826     // Reset req handle. Returns the deleted req handle
       
  1827     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
  1828         EMultimodeONStoreStoreAll );
       
  1829 
       
  1830     if ( EMultimodeONStoreReqHandleUnknown != reqHandle )
       
  1831         {
       
  1832         // Reset class attributes
       
  1833         iStoreAllBuffer = NULL;
       
  1834         iStoreAllONStoreSize = 0;
       
  1835         iStoreAllONStoreIndex = 0;
       
  1836         iStoreAllONListSize = 0;
       
  1837 
       
  1838         // Complete with KErrCancel
       
  1839         ReqCompleted( aTsyReqHandle, KErrCancel );
       
  1840         }
       
  1841 
       
  1842     return KErrNone;
       
  1843     }
       
  1844 
       
  1845 // ---------------------------------------------------------------------------
       
  1846 // CMmONStoreTsy::ResetVariables
       
  1847 // Reset all used variables
       
  1848 // (other items were commented in a header).
       
  1849 // ---------------------------------------------------------------------------
       
  1850 //
       
  1851 void CMmONStoreTsy::ResetVariables()
       
  1852     {
       
  1853     iPhoneBookType = KSimNoServiceType;
       
  1854     iServiceType.iNumOfEntries = KNoInfoAvail;
       
  1855     iServiceType.iNameLen = KNoInfoAvail;
       
  1856     iServiceType.iNumLen = KNoInfoAvail;
       
  1857     }
       
  1858 
       
  1859 // ---------------------------------------------------------------------------
       
  1860 // CMmONStoreTsy::Phone
       
  1861 // Returns CMmPhoneTsy object
       
  1862 // (other items were commented in a header).
       
  1863 // ---------------------------------------------------------------------------
       
  1864 //
       
  1865 CMmPhoneTsy* CMmONStoreTsy::Phone()
       
  1866     {
       
  1867     return iMmPhone;
       
  1868     }
       
  1869 
       
  1870 #ifdef TF_LOGGING_ENABLED
       
  1871 // ---------------------------------------------------------------------------
       
  1872 // CMmONStoreTsy::ReqCompleted
       
  1873 // Overrides CTelObject::ReqCompleted for test logging purposes.
       
  1874 // It prints the aTsyReqHandle and aError variable in the log file and then
       
  1875 // calls CTelObject::ReqCompleted.
       
  1876 // ---------------------------------------------------------------------------
       
  1877 //
       
  1878 void CMmONStoreTsy::ReqCompleted(
       
  1879     const TTsyReqHandle aTsyReqHandle, 
       
  1880     const TInt aError )
       
  1881     {
       
  1882 TFLOGSTRING3("TSY: CMmONStoreTsy::ReqCompleted Completed - Handle:%d Error:%d", aTsyReqHandle, aError);
       
  1883 
       
  1884     CTelObject::ReqCompleted( aTsyReqHandle, aError );
       
  1885     }
       
  1886 
       
  1887 #endif // TF_LOGGING_ENABLED
       
  1888 
       
  1889 #ifdef REQHANDLE_TIMER
       
  1890 // ---------------------------------------------------------------------------
       
  1891 // CMmONStoreTsy::SetTypeOfResponse
       
  1892 // Sets the type of response for a given Handle
       
  1893 // (other items were commented in a header).
       
  1894 // ---------------------------------------------------------------------------
       
  1895 //
       
  1896 void CMmONStoreTsy::SetTypeOfResponse(
       
  1897     const TInt aReqHandleType,
       
  1898     const TTsyReqHandle aTsyReqHandle )
       
  1899     {
       
  1900     TInt timeOut( 0 );
       
  1901 
       
  1902     //example switch
       
  1903     switch ( aReqHandleType )
       
  1904         {
       
  1905 
       
  1906         case EMultimodeONStoreRead:
       
  1907             timeOut = KMmONStoreReadTimeOut;
       
  1908             break;
       
  1909         case EMultimodeONStoreWrite:
       
  1910             // Set time for writing first empty location
       
  1911             if ( iIsWriteCancellingPossible )
       
  1912                 {
       
  1913                 timeOut = KMmONStoreWriteToFirstEmptyLocTimeOut;
       
  1914                 }
       
  1915             // Set time for normal write request
       
  1916             else
       
  1917                 {
       
  1918                 timeOut = KMmONStoreWriteTimeOut;
       
  1919                 }
       
  1920             break;
       
  1921         case EMultimodeONStoreDelete:
       
  1922             timeOut = KMmONDeleteTimeOut;
       
  1923             break;
       
  1924         case EMultimodeONStoreDeleteAll:
       
  1925             timeOut = KMmONDeleteAllTimeOut;
       
  1926             break;
       
  1927         case EMultimodeONStoreGetInfo:
       
  1928             timeOut = KMmONGetInfoTimeOut;
       
  1929             break;
       
  1930            case EMultimodeONStoreReadAll:
       
  1931         case EMultimodeONStoreStoreAll:
       
  1932             timeOut = KMmONStoreAllTimeOut;
       
  1933             break;
       
  1934 
       
  1935         //Must not use timer:
       
  1936         // - all notifications
       
  1937             //case EMultimodePhoneStoreNotifyStoreEvent:
       
  1938         // - 2nd phase methods (when two phase lists are used)
       
  1939             //case EMultimodeONStoreReadAll:
       
  1940 
       
  1941         default:
       
  1942             //does not use timer
       
  1943             iTsyReqHandleStore->SetTsyReqHandle(
       
  1944                 aReqHandleType,
       
  1945                 aTsyReqHandle );
       
  1946             break;
       
  1947         }
       
  1948 
       
  1949     if ( 0 < timeOut )
       
  1950         {
       
  1951         //the timeout parameter is given in seconds.
       
  1952         iTsyReqHandleStore->SetTsyReqHandle(
       
  1953             aReqHandleType,
       
  1954             aTsyReqHandle,
       
  1955             timeOut );
       
  1956         }
       
  1957     }
       
  1958 
       
  1959 // ---------------------------------------------------------------------------
       
  1960 // CMmONStoreTsy::Complete
       
  1961 // Completes the request due timer expiration
       
  1962 // (other items were commented in a header).
       
  1963 // ---------------------------------------------------------------------------
       
  1964 //
       
  1965 void CMmONStoreTsy::Complete(
       
  1966     TInt aReqHandleType,
       
  1967     TInt aError )
       
  1968     {
       
  1969 TFLOGSTRING3( "TSY: CMmONStoreTsy::Complete - ReqHandleType: %d Error: %d", aReqHandleType, aError );    
       
  1970     //All possible TSY req handle types are listed in the
       
  1971     //switch case below.
       
  1972     switch( aReqHandleType )
       
  1973         {
       
  1974         case EMultimodeONStoreRead:
       
  1975             CompleteRead( aError, NULL );
       
  1976             break;
       
  1977         case EMultimodeONStoreWrite:
       
  1978             CompleteWrite( aError, NULL );
       
  1979             break;
       
  1980         case EMultimodeONStoreDelete:
       
  1981             CompleteDelete( aError );
       
  1982             break;
       
  1983         case EMultimodeONStoreDeleteAll:
       
  1984             CompleteDeleteAll( aError );
       
  1985             break;
       
  1986         case EMultimodeONStoreGetInfo:
       
  1987             CompleteGetInfo( aError, 0 );
       
  1988             break;
       
  1989         case EMultimodeONStoreStoreAll:
       
  1990             CompleteStoreAll( aError );
       
  1991             break;
       
  1992 
       
  1993         //Can't use timer:
       
  1994         // - all notifications
       
  1995             //case EMultimodeONStoreNotifyStoreEvent:
       
  1996         // - 2nd phase methods (when two phase lists are used)
       
  1997             //case EMultimodeONStoreReadAll:
       
  1998 
       
  1999         default:
       
  2000             ReqCompleted( iTsyReqHandleStore->ResetTsyReqHandle(
       
  2001                 aReqHandleType ), aError );
       
  2002             break;
       
  2003         }
       
  2004     }
       
  2005 
       
  2006 #endif
       
  2007 
       
  2008 //  End of File