telephonyserverplugins/common_tsy/commontsy/src/mmcustomtsy/CMmSIMTsy.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 "CMmSIMTsy.h"
       
    20 #include <ctsy/pluginapi/cmmdatapackage.h>
       
    21 #include <ctsy/tflogger.h>
       
    22 
       
    23 // ======== MEMBER FUNCTIONS ========
       
    24 
       
    25 CMmSIMTsy::CMmSIMTsy()
       
    26     {
       
    27     }
       
    28 
       
    29 void CMmSIMTsy::ConstructL(
       
    30     CMmCustomTsy* aMmCustomTsy )
       
    31     {
       
    32 TFLOGSTRING("TSY: CMmSIMTsy::ConstructL");         
       
    33     iMmCustomTsy = aMmCustomTsy;
       
    34 
       
    35     // Create req handle store
       
    36 #ifdef REQHANDLE_TIMER
       
    37     iTsyReqHandleStore = CMmTsyReqHandleStore::NewL( iMmCustomTsy,
       
    38         iMmCustomTsy->iMmPhoneTsy, ESIMRequestTypeMaxNumOfRequests,
       
    39         iSIMReqHandles );
       
    40 #else
       
    41    iTsyReqHandleStore = CMmTsyReqHandleStore::NewL(
       
    42         ESIMRequestTypeMaxNumOfRequests, iSIMReqHandles );
       
    43 #endif // REQHANDLE_TIMER
       
    44 
       
    45     // By default VIAG parameters are not requested. This means that
       
    46     // when "SIM ready" indication is received, TSY will not check
       
    47     // if it needs to read VIAG parameters or not.
       
    48     iViagParamsReadRequested = EFalse;
       
    49 
       
    50     // Initialize pointer to NULL.
       
    51     iCurrentlyRetrievedCache = NULL;
       
    52 
       
    53     // create the o2 HomeZone dynamic cache
       
    54     // IGNORE if this fails due to Out-of-Memory problem
       
    55     TInt leaveCode;
       
    56     TRAP( leaveCode, iViagDynamicCache = new ( ELeave )
       
    57         CArrayFixFlat<RMmCustomAPI::TViagCacheRecordContent>( 
       
    58         ( KPhEngMaxViagHomeZones * KPhEngMaxCacheId ) ); );
       
    59     if ( leaveCode )
       
    60         {
       
    61 TFLOGSTRING2("TSY: CMmSIMTsy::ConstructL: Could not construct o2 HomeZone dynamic cache, error=%d", leaveCode);
       
    62         iViagDynamicCache = NULL;
       
    63         }
       
    64     else
       
    65         {
       
    66         // initialise
       
    67         RMmCustomAPI::TViagCacheRecordContent zero;
       
    68         zero.iLac = 0xFFFF;
       
    69         zero.iCellId = 0xFFFF;
       
    70         iViagDynamicCache->AppendL( zero, ( KPhEngMaxViagHomeZones * 
       
    71             KPhEngMaxCacheId ) );
       
    72         iViagHomeZoneCacheReady = EFalse;
       
    73 TFLOGSTRING("TSY: CMmSIMTsy::ConstructL: o2 HomeZone dynamic cache array created.");
       
    74         }
       
    75     }
       
    76 
       
    77 CMmSIMTsy* CMmSIMTsy::NewL(
       
    78     CMmCustomTsy* aMmCustomTsy )
       
    79     {
       
    80 TFLOGSTRING("TSY: CMmSIMTsy::NewL");    
       
    81     CMmSIMTsy* self = new (ELeave) CMmSIMTsy();
       
    82 
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL( aMmCustomTsy );
       
    85     CleanupStack::Pop( self );
       
    86 
       
    87     return self;
       
    88     }
       
    89 
       
    90 CMmSIMTsy::~CMmSIMTsy()
       
    91     {
       
    92 TFLOGSTRING("TSY: CMmSIMTsy::~CMmSIMTsy()");         
       
    93     // delete all CB ID related
       
    94     ResetAndDestroySimCbTopics();
       
    95 
       
    96     delete iTsyReqHandleStore;
       
    97     delete iViagDynamicCache; 
       
    98     delete iCurrentlyRetrievedCache; 
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CMmSIMTsy::Init
       
   103 // Initialisation method that is called from ETel Server.
       
   104 // (other items were commented in a header).
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CMmSIMTsy::Init()
       
   108     {
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CMmSIMTsy::SupportingIPC
       
   113 // Tells whether the object supports given IPC.
       
   114 // (other items were commented in a header).
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 TBool CMmSIMTsy::SupportingIPC(
       
   118     TInt  aIpc )
       
   119     {
       
   120     TInt ret( EFalse );
       
   121 
       
   122     switch ( aIpc )
       
   123         {
       
   124         case EReadViagHomeZoneParamsIPC:
       
   125         case EReadViagHomeZoneCacheIPC:
       
   126         case EWriteViagHomeZoneCacheIPC:
       
   127         case EWriteViagHomeZoneUHZIUESettingsIPC:
       
   128         case ECustomStartSimCbTopicBrowsingIPC:
       
   129         case ECustomGetNextSimCbTopicIPC:
       
   130         case ECustomDeleteSimCbTopicIPC:
       
   131             ret = ETrue;
       
   132             break;
       
   133         default:
       
   134             ret = EFalse;
       
   135             break;
       
   136         }
       
   137 
       
   138     return ret;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CMmSIMTsy::DoExtFuncL
       
   143 // Dispatches extension function requests.
       
   144 // (other items were commented in a header).
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 TInt CMmSIMTsy::DoExtFuncL(
       
   148     const TTsyReqHandle aTsyReqHandle, 
       
   149     const TInt aIpc, 
       
   150     const TDataPackage& aPackage )
       
   151     {
       
   152 TFLOGSTRING3("TSY: CMmSIMTsy::DoExtFuncL - IPC:%d Handle:%d", aIpc, aTsyReqHandle);
       
   153     TInt ret( KErrGeneral );
       
   154 
       
   155     // reset last tsy request type
       
   156     iReqHandleType = ESIMTsyReqHandleUnknown;
       
   157 
       
   158     switch ( aIpc )
       
   159         {
       
   160         case EReadViagHomeZoneParamsIPC:
       
   161             ret = ReadViagHomeZoneParamsL(
       
   162                 REINTERPRET_CAST( RMmCustomAPI::TViagParams*, aPackage.Ptr1() 
       
   163                 ), REINTERPRET_CAST( RMmCustomAPI::TViagElement*,
       
   164                 aPackage.Ptr2() ) );
       
   165             break;
       
   166         case EReadViagHomeZoneCacheIPC:
       
   167             ret = ReadDynamicViagHomeZoneCacheL( aTsyReqHandle, 
       
   168                 REINTERPRET_CAST( RMmCustomAPI::TViagCacheRecordId*, 
       
   169                 aPackage.Ptr1() ), REINTERPRET_CAST(
       
   170                 RMmCustomAPI::TViagCacheRecordContent*, aPackage.Ptr2() ) );
       
   171             break;
       
   172         case EWriteViagHomeZoneCacheIPC:
       
   173             ret = WriteViagHomeZoneCacheL(
       
   174                 REINTERPRET_CAST( RMmCustomAPI::TViagCacheRecordId*, 
       
   175                     aPackage.Ptr1() ), REINTERPRET_CAST( 
       
   176                     RMmCustomAPI::TViagCacheRecordContent*, aPackage.Ptr2() )
       
   177                     );
       
   178             break;
       
   179         case ECustomStartSimCbTopicBrowsingIPC:
       
   180             ret = StartSimCbTopicBrowsingL( aTsyReqHandle );
       
   181             break;
       
   182         case ECustomGetNextSimCbTopicIPC:
       
   183             ret = GetNextSimCbTopic( aTsyReqHandle, REINTERPRET_CAST( 
       
   184                   RMmCustomAPI::TSimCbTopic*, aPackage.Ptr1()) );
       
   185             break;
       
   186         case ECustomDeleteSimCbTopicIPC:
       
   187             ret = DeleteSimCbTopicL( aTsyReqHandle, REINTERPRET_CAST(TUint*, 
       
   188                 aPackage.Ptr1() ) );
       
   189             break;
       
   190         case EWriteViagHomeZoneUHZIUESettingsIPC:
       
   191             ret = WriteViagHomeZoneUHZIUESettingsL( REINTERPRET_CAST(
       
   192                 RMmCustomAPI::TViagUHZIUESettings*, aPackage.Ptr1() ) );
       
   193             break;
       
   194         default:
       
   195             ret = KErrNotSupported;
       
   196             break;
       
   197         }
       
   198 
       
   199     // save request handle
       
   200     if ( ESIMTsyReqHandleUnknown != iReqHandleType )
       
   201         {
       
   202 #ifdef REQHANDLE_TIMER
       
   203         SetTypeOfResponse( iReqHandleType, aTsyReqHandle );
       
   204 #else
       
   205         iTsyReqHandleStore->SetTsyReqHandle( iReqHandleType, aTsyReqHandle );
       
   206 #endif // REQHANDLE_TIMER
       
   207         }
       
   208 
       
   209     return ret;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CMmSIMTsy::ReqModeL
       
   214 // Returns request mode for given IPC. Leaves with error code KErrNotSupported
       
   215 // if the IPC number does not belong to some of the SIM API functions.
       
   216 // (other items were commented in a header).
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 CTelObject::TReqMode CMmSIMTsy::ReqModeL(
       
   220     const TInt aIpc )
       
   221     {
       
   222     CTelObject::TReqMode ret = 0;
       
   223 
       
   224     switch ( aIpc )
       
   225         {
       
   226         case EReadViagHomeZoneParamsIPC:
       
   227         case EReadViagHomeZoneCacheIPC:
       
   228         case EWriteViagHomeZoneCacheIPC:
       
   229         case EWriteViagHomeZoneUHZIUESettingsIPC:
       
   230         case ECustomStartSimCbTopicBrowsingIPC:
       
   231         case ECustomGetNextSimCbTopicIPC:
       
   232         case ECustomDeleteSimCbTopicIPC:
       
   233             ret = 0;    // flow control in tsy
       
   234             break;
       
   235         default:
       
   236             User::Leave( KErrNotSupported );
       
   237             break;
       
   238         }
       
   239 
       
   240     return ret;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // CMmSIMTsy::NumberOfSlotsL
       
   245 // Returns number of slots to be used for given IPC. Leaves with error code
       
   246 // KErrNotSupported if the IPC number does not belong to some of the SIM
       
   247 // API functions.
       
   248 // (other items were commented in a header).
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 TInt CMmSIMTsy::NumberOfSlotsL(
       
   252     const TInt aIpc )
       
   253     {
       
   254     TInt numberOfSlots( KMmCustomDefaultSlots );
       
   255 
       
   256     switch ( aIpc )
       
   257         {
       
   258         case EReadViagHomeZoneParamsIPC:
       
   259         case EReadViagHomeZoneCacheIPC:
       
   260         case EWriteViagHomeZoneCacheIPC:
       
   261         case EWriteViagHomeZoneUHZIUESettingsIPC:
       
   262         case ECustomStartSimCbTopicBrowsingIPC:
       
   263         case ECustomGetNextSimCbTopicIPC:
       
   264         case ECustomDeleteSimCbTopicIPC:
       
   265            numberOfSlots = KMmCustomDefaultSlots;
       
   266            break;
       
   267         default:
       
   268             // Unknown or invalid IPC
       
   269             User::Leave( KErrNotSupported );
       
   270             break;
       
   271         }
       
   272 
       
   273     return numberOfSlots;
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CMmSIMTsy::CancelService
       
   278 // When the clients close their sub-sessions (eg. by calling RPhone::Close),
       
   279 // they may not have cancelled all their outstanding asynchronous requests
       
   280 // before closing. It is up to the ETel server to clean up in this situation,
       
   281 // so the server will find the list of outstanding requests related to that
       
   282 // sub-session object and pass these outstanding IPC request numbers, one at
       
   283 // a time, to the CancelService function in the TSY.
       
   284 // (other items were commented in a header).
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 TInt CMmSIMTsy::CancelService(
       
   288     const TInt aIpc, 
       
   289     const TTsyReqHandle aTsyReqHandle)
       
   290     {
       
   291     TInt ret( KErrGeneral );
       
   292 
       
   293     switch ( aIpc )
       
   294         {
       
   295         case EReadViagHomeZoneParamsIPC:
       
   296             ret = ReadViagHomeZoneParamsCancel();
       
   297             break;
       
   298         case EReadViagHomeZoneCacheIPC:
       
   299             ret = ReadViagHomeZoneCacheCancel( aTsyReqHandle );
       
   300             break;
       
   301         case EWriteViagHomeZoneCacheIPC:
       
   302             ret = WriteViagHomeZoneCacheCancel();
       
   303             break;
       
   304         case EWriteViagHomeZoneUHZIUESettingsIPC:
       
   305             ret = WriteViagHomeZoneUHZIUESettingsCancel();
       
   306             break;
       
   307         case ECustomGetNextSimCbTopicIPC:
       
   308         case ECustomDeleteSimCbTopicIPC:
       
   309             // operation cannot be cancelled on DOS side
       
   310             ret = KErrNone;
       
   311             break;
       
   312         default:
       
   313             ret = KErrGeneral;
       
   314             break;
       
   315         }
       
   316 
       
   317     return ret;
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // CMmSIMTsy::RegisterNotification
       
   322 // Called when the server recognises this notification being posted for
       
   323 // the first time on this sub-session object. It enables the TSY to "turn on"
       
   324 // any regular notification messages that it may receive from DOS.
       
   325 // (other items were commented in a header).
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 TInt CMmSIMTsy::RegisterNotification(
       
   329     const TInt )
       
   330     {
       
   331     // No supported notifications in CMmSimTsy
       
   332     return KErrNotSupported;
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // CMmSIMTsy::DeregisterNotification
       
   337 // Called when the server recognises that this notification will not be posted
       
   338 // again because the last client to have a handle on this sub-session object
       
   339 // has just closed the handle. It enables the TSY to "turn off" any regular
       
   340 // notification messages that it may receive from DOS.
       
   341 // (other items were commented in a header).
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 TInt CMmSIMTsy::DeregisterNotification(
       
   345     const TInt )
       
   346     {
       
   347     // No supported notifications in CMmSimTsy
       
   348     return KErrNotSupported;
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CMmSIMTsy::ReadViagHomeZoneParamsL
       
   353 // Reads VIAG Home Zone Parameters.
       
   354 // If it has been requested before SIM is ready, the request is saved and will
       
   355 // be done later. See methods CheckViagHomezoneParams and
       
   356 // CMmPhoneTsy::CompleteNotifySimStatusReady.
       
   357 // (other items were commented in a header).
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 TInt CMmSIMTsy::ReadViagHomeZoneParamsL(
       
   361     RMmCustomAPI::TViagParams* aViagParameters, 
       
   362     RMmCustomAPI::TViagElement* aViagElements )
       
   363     {
       
   364 TFLOGSTRING("TSY: CMmSIMTsy::ReadViagHomeZoneParamsL");
       
   365     TInt ret( KErrNone);
       
   366 
       
   367     if ( ESIMTsyReqHandleUnknown != iTsyReqHandleStore->GetTsyReqHandle(
       
   368         ESIMRequestTypeReadParams ) )
       
   369         {
       
   370         return KErrServerBusy;
       
   371         }
       
   372 
       
   373     // Count is already checked in CustomAPI
       
   374     iViagParams = aViagParameters;
       
   375     iViagElems = aViagElements;
       
   376 
       
   377     // If SIM is ready, then request VIAG homezone parameters.
       
   378     // If not ready, store pointers and send request when the
       
   379     // "SIM ready" indication is received.
       
   380     if ( iMmCustomTsy->Phone()->NosBootState()->iSIMReady )
       
   381         {
       
   382         // send request to DOS (no parameters)
       
   383         ret = iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
   384             EReadViagHomeZoneParamsIPC );
       
   385         }
       
   386     else
       
   387         {
       
   388         // SIM is not yet ready. TSY should send read request when SIM has
       
   389         // indicated that it is ready. See CheckViagHomezoneParams and
       
   390         // CMmPhoneTsy::CompleteNotifySimStatusReady.
       
   391         iViagParamsReadRequested = ETrue;
       
   392         }
       
   393 
       
   394     // If message is sent or we are waiting for adaptation indication SIM 
       
   395     // being ready. Then store handle.
       
   396     if ( KErrNone == ret )
       
   397         {
       
   398         iReqHandleType = ESIMRequestTypeReadParams;
       
   399         }
       
   400 
       
   401     return ret;
       
   402     }
       
   403 
       
   404 // ---------------------------------------------------------------------------
       
   405 // CMmSIMTsy::CheckViagHomezoneParamsL
       
   406 // Reads VIAG Home Zone Parameters when it has been requested before
       
   407 // SIM is ready.
       
   408 // (other items were commented in a header).
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 void CMmSIMTsy::CheckViagHomezoneParamsL()
       
   412     {
       
   413 TFLOGSTRING("TSY: CMmSIMTsy::CheckViagHomezoneParamsL");
       
   414     // Check if the request is pending
       
   415     if ( ESIMTsyReqHandleUnknown != iTsyReqHandleStore->GetTsyReqHandle(
       
   416         ESIMRequestTypeReadParams )  && iViagParamsReadRequested )
       
   417         {
       
   418         // Ensure that we wont flood SIM with mupltiple VIAG params
       
   419         // read requests, set flag to EFalse.
       
   420         iViagParamsReadRequested = EFalse;
       
   421 
       
   422 TFLOGSTRING("TSY: CMmSIMTsy::CheckViagHomezoneParamsL - Sending request" );
       
   423         // send request to DOS (no parameters)
       
   424         // Void return value, there is nothing to be done if request fails.
       
   425         (void) iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
   426             EReadViagHomeZoneParamsIPC );
       
   427         }
       
   428     else
       
   429         {
       
   430 TFLOGSTRING("TSY: CMmSIMTsy::CheckViagHomezoneParamsL - VIAG homezone params not requested");
       
   431         }
       
   432 
       
   433     StartDynamicCachingL();
       
   434     }
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // CMmSIMTsy::CompleteReadViagHomeZoneParamsResp
       
   438 // Completes a ReadViagHomeZoneParams request (which was issued either by
       
   439 // ReadViagHomeZoneParams or by CheckViagHomezoneParams).
       
   440 // (other items were commented in a header).
       
   441 // ---------------------------------------------------------------------------
       
   442 //
       
   443 void CMmSIMTsy::CompleteReadViagHomeZoneParamsResp(
       
   444     RMmCustomAPI::TViagParams* aParams, 
       
   445     RMmCustomAPI::TViagElements* aElems, 
       
   446     TInt aError )
       
   447     {
       
   448 TFLOGSTRING2("TSY: CMmSIMTsy::CompleteReadViagHomeZoneParamsResp - aError: %d", aError );
       
   449     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   450         ESIMRequestTypeReadParams );
       
   451     if ( ESIMTsyReqHandleUnknown != reqHandle )
       
   452         {
       
   453         if ( aError == KErrNone && iViagParams && iViagElems )
       
   454             {
       
   455             *iViagParams = *aParams;
       
   456 TFLOGSTRING2("TSY: CMmSIMTsy::CompleteReadViagHomeZoneParamsResp - iSmsC: %S", &iViagParams->iSmsC );
       
   457 TFLOGSTRING2("TSY: CMmSIMTsy::CompleteReadViagHomeZoneParamsResp - iScp: %S",  &iViagParams->iScp );
       
   458 TFLOGSTRING2("TSY: CMmSIMTsy::CompleteReadViagHomeZoneParamsResp - iSubscribedZoneAndVersion: %d", iViagParams->iSubscribedZoneAndVersion );
       
   459 
       
   460             for ( TUint8 i = 0; i < RMmCustomAPI::KViagElementCount; i++ )
       
   461                 {
       
   462                 iViagElems[ i ].iCoordinates.iX = aElems->At(i).iCoordinates.iX;
       
   463 TFLOGSTRING3("TSY: CMmSIMTsy::CompleteReadViagHomeZoneParamsResp - Element: %d, iX: %d", i, aElems->At(i).iCoordinates.iX );
       
   464 
       
   465                 iViagElems[ i ].iCoordinates.iY = aElems->At(i).iCoordinates.iY;
       
   466 TFLOGSTRING3("TSY: CMmSIMTsy::CompleteReadViagHomeZoneParamsResp - Element: %d, iY: %d", i, aElems->At(i).iCoordinates.iY );
       
   467 
       
   468                 iViagElems[ i ].iCoordinates.iR2 = aElems->
       
   469                     At(i).iCoordinates.iR2;
       
   470 TFLOGSTRING3("TSY: CMmSIMTsy::CompleteReadViagHomeZoneParamsResp - Element: %d, iR2: %d", i, aElems->At(i).iCoordinates.iR2 );
       
   471 
       
   472                 iViagElems[ i ].iCoordinates.iZoneId = aElems->
       
   473                     At(i).iCoordinates.iZoneId;
       
   474 TFLOGSTRING3("TSY: CMmSIMTsy::CompleteReadViagHomeZoneParamsResp - Element: %d, iZoneId: %d", i, aElems->At(i).iCoordinates.iZoneId );
       
   475 
       
   476                 iViagElems[ i ].iName.Copy( aElems->At(i).iName );
       
   477                 iViagElems[ i ].iActiveFlag = aElems->At(i).iActiveFlag;
       
   478 TFLOGSTRING3("TSY: CMmSIMTsy::CompleteReadViagHomeZoneParamsResp - Element: %d, iActiveFlag: %d", i, aElems->At(i).iActiveFlag );
       
   479                 }
       
   480             }
       
   481         iMmCustomTsy->ReqCompleted( reqHandle, aError );
       
   482         }
       
   483     }
       
   484 
       
   485 // ---------------------------------------------------------------------------
       
   486 // CMmSIMTsy::ReadViagHomeZoneParamsCancel
       
   487 // Cancels reading VIAG Home Zone parameters.
       
   488 // (other items were commented in a header).
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 TInt CMmSIMTsy::ReadViagHomeZoneParamsCancel()
       
   492     {
       
   493 TFLOGSTRING("TSY: CMmSIMTsy::ReadViagHomeZoneParamsCancel");
       
   494     // reset the pointer to client space
       
   495     iViagParams = NULL;
       
   496     iViagElems = NULL;
       
   497 
       
   498     // reset the req handle
       
   499     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   500         ESIMRequestTypeReadParams );
       
   501 
       
   502     if ( ESIMTsyReqHandleUnknown != reqHandle )
       
   503     	{
       
   504     	// complete with cancel
       
   505     	iMmCustomTsy->ReqCompleted( reqHandle, KErrCancel );
       
   506     	}
       
   507 
       
   508     return KErrNone;
       
   509     }
       
   510 
       
   511 // ---------------------------------------------------------------------------
       
   512 // CMmSIMTsy::ReadViagHomeZoneCacheL
       
   513 // Reads VIAG Home Zone Cache.
       
   514 // (other items were commented in a header).
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 TInt CMmSIMTsy::ReadViagHomeZoneCacheL(
       
   518     RMmCustomAPI::TViagCacheRecordId* aViagRecordId,
       
   519     RMmCustomAPI::TViagCacheRecordContent* aViagRecordContent )
       
   520     {
       
   521 TFLOGSTRING("TSY: CMmSIMTsy::ReadViagHomeZoneCacheL");
       
   522     TInt ret( KErrGeneral );
       
   523 
       
   524     if ( ESIMTsyReqHandleUnknown != iTsyReqHandleStore->GetTsyReqHandle(
       
   525         ESIMRequestTypeReadCache ) )
       
   526         {
       
   527         return KErrServerBusy;
       
   528         }
       
   529 
       
   530     iViagReadCacheRecord = aViagRecordContent;
       
   531 
       
   532     // send request to DOS
       
   533     // packed parameter: RMmCustomAPI::TViagCacheRecordId
       
   534     CMmDataPackage dataPackage;
       
   535     dataPackage.PackData( aViagRecordId );
       
   536     ret = iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
   537         EReadViagHomeZoneCacheIPC, &dataPackage );
       
   538 
       
   539     if ( KErrNone == ret )
       
   540         {
       
   541         // Store the request handle
       
   542         iReqHandleType = ESIMRequestTypeReadCache;
       
   543         }
       
   544 
       
   545     return ret;
       
   546     }
       
   547 
       
   548 // ---------------------------------------------------------------------------
       
   549 // CMmSIMTsy::CompleteReadViagHomeZoneCacheRespL
       
   550 // Completes reading VIAG Home Zone Cache.
       
   551 // (other items were commented in a header).
       
   552 // ---------------------------------------------------------------------------
       
   553 //
       
   554 void CMmSIMTsy::CompleteReadViagHomeZoneCacheRespL(
       
   555     RMmCustomAPI::TViagCacheRecordContent* aViagRecord,
       
   556     TInt aError )
       
   557     {
       
   558 TFLOGSTRING("TSY: CMmSIMTsy::CompleteReadViagHomeZoneCacheRespL");
       
   559     if (iCurrentlyRetrievedCache == NULL)
       
   560         {
       
   561         // Got an unexpected update... ignore!
       
   562         return;
       
   563         }
       
   564     if ( KErrNone == aError )
       
   565         {
       
   566         // response OK
       
   567         if ( iViagDynamicCache )
       
   568             {
       
   569             // save in dynamic cache
       
   570             // some arithmetics:
       
   571             //     cache ids range 1..4
       
   572             //     record ids range 0..20
       
   573             //     array indexes range 0..83
       
   574             // ==> A[c][r] = A[((c-1)*rMax)+r]
       
   575             TInt arrayIndex =
       
   576                 ( ( iCurrentlyRetrievedCache->iCacheId - 1 ) * 21 ) +
       
   577                 iCurrentlyRetrievedCache->iRecordId;
       
   578             iViagDynamicCache->At( arrayIndex ) = *aViagRecord;
       
   579 TFLOGSTRING3("TSY: CMmSIMTsy::CompleteReadViagHomeZoneCacheRespL:Entry at cacheId=%d, recordId=%d read.", iCurrentlyRetrievedCache->iCacheId,iCurrentlyRetrievedCache->iRecordId);
       
   580 
       
   581             TRAP_IGNORE(
       
   582                 // loop. loop four caches times 21 entries!
       
   583             if ( 20 > iCurrentlyRetrievedCache->iRecordId )
       
   584                 {
       
   585                 iCurrentlyRetrievedCache->iRecordId++;
       
   586                 // send request to DOS
       
   587                 // packed parameter: RMmCustomAPI::TViagCacheRecordId
       
   588                 CMmDataPackage dataPackage;
       
   589                 dataPackage.PackData( iCurrentlyRetrievedCache );
       
   590                 iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
   591                     EReadViagHomeZoneCacheIPC, &dataPackage );
       
   592                 }
       
   593             else if ( 4 > iCurrentlyRetrievedCache->iCacheId )
       
   594                 {
       
   595                 // next cache
       
   596                 iCurrentlyRetrievedCache->iCacheId++;
       
   597                 iCurrentlyRetrievedCache->iRecordId = 0;
       
   598                 // send request to DOS
       
   599                 // packed parameter: RMmCustomAPI::TViagCacheRecordId
       
   600                 CMmDataPackage dataPackage;
       
   601                 dataPackage.PackData( iCurrentlyRetrievedCache );
       
   602                 iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
   603                     EReadViagHomeZoneCacheIPC, &dataPackage );
       
   604                 }
       
   605             else
       
   606                 {
       
   607                 // caching done
       
   608                 delete iCurrentlyRetrievedCache;
       
   609                 iCurrentlyRetrievedCache = NULL;
       
   610                 iViagHomeZoneCacheReady = ETrue;
       
   611 TFLOGSTRING("TSY: CMmSIMTsy::CompleteReadViagHomeZoneCacheRespL:Caching completed successfully!");
       
   612 
       
   613                 if( 0 < iReadViagHomeZoneCacheRequests.Count() )
       
   614                     {
       
   615                     
       
   616                     for ( TInt i=0; i <iReadViagHomeZoneCacheRequests.Count() ; i++ )
       
   617                         {
       
   618 TFLOGSTRING2("TSY: CMmSIMTsy::CompleteReadDynamicViagHomeZoneCacheRespL: for i:%d", i);
       
   619                         TReadViagHomeZoneCacheRequest* req = 
       
   620 		  			    iReadViagHomeZoneCacheRequests[ i ];
       
   621 		  			    
       
   622                         // copy data from dynamic cache to client
       
   623                         // some arithmetics:
       
   624                         //     cache ids range 1..4
       
   625                         //     record ids range 0..20
       
   626                         //     array indexes range 0..83
       
   627                         // ==> A[c][r] = A[((c-1)*rMax)+r]
       
   628                         TInt arrayIndex = ( ( req->iViagRecordId->iCacheId - 1 ) * 21 ) +
       
   629                         req->iViagRecordId->iRecordId;//iCacheId;  
       
   630                         
       
   631                         //set value in client side
       
   632 		                *(req->iViagRecordContent) =iViagDynamicCache->At( arrayIndex );
       
   633 			            //reset the return pointer
       
   634 		                iMmCustomTsy->ReqCompleted( req->iReqHandle, KErrNone );
       
   635                         }
       
   636                     iReadViagHomeZoneCacheRequests.ResetAndDestroy();
       
   637                         
       
   638                     }
       
   639                 }
       
   640             );
       
   641             }
       
   642         }
       
   643         else
       
   644             {
       
   645             // caching aborted
       
   646             delete iCurrentlyRetrievedCache;
       
   647             iCurrentlyRetrievedCache = NULL;
       
   648 TFLOGSTRING2("TSY: CMmSIMTsy::CompleteReadViagHomeZoneCacheRespL:There was a problem reading cache values from SIM, error=%d", aError);
       
   649             }
       
   650     }
       
   651 
       
   652 // ---------------------------------------------------------------------------
       
   653 // CMmSIMTsy::ReadViagHomeZoneCacheCancel
       
   654 // Cancels reading VIAG Home Zone cache.
       
   655 // (other items were commented in a header).
       
   656 // ---------------------------------------------------------------------------
       
   657 //
       
   658 TInt CMmSIMTsy::ReadViagHomeZoneCacheCancel(
       
   659     const TTsyReqHandle aTsyReqHandle )
       
   660     {
       
   661 TFLOGSTRING("TSY: CMmSIMTsy::ReadViagHomeZoneCacheCancel");
       
   662 TFLOGSTRING2("TSY: CMmSIMTsy::ReadViagHomeZoneCacheCancel - Handle:%d",aTsyReqHandle);
       
   663     // Reset the pointer to client space
       
   664     iViagReadCacheRecord = NULL;
       
   665 
       
   666     // Check if request handle already exists
       
   667     TTsyReqHandle reqHandle = iTsyReqHandleStore->GetTsyReqHandle(
       
   668         ESIMRequestTypeReadCache );
       
   669 
       
   670 	if (aTsyReqHandle == reqHandle ) 
       
   671 		{
       
   672 	    // Reset the request handle. Returns the deleted req handle
       
   673         reqHandle = iTsyReqHandleStore->ResetTsyReqHandle( 
       
   674             ESIMRequestTypeReadCache );
       
   675         if ( ESIMTsyReqHandleUnknown != reqHandle )
       
   676         	{
       
   677 TFLOGSTRING2("TSY: CMmSIMTsy::ReadViagHomeZoneCacheCancel - Completed with Cancel Handle:%d",reqHandle);	
       
   678 			// Complete request with cancel
       
   679 			iMmCustomTsy->ReqCompleted( reqHandle, KErrCancel );
       
   680         	}
       
   681         }
       
   682 	else
       
   683 	    {		
       
   684         if( 0 < iReadViagHomeZoneCacheRequests.Count() )
       
   685             {
       
   686             // Search the request handle in the array
       
   687             for ( TInt i=0; i < iReadViagHomeZoneCacheRequests.Count(); i++ )
       
   688                 {
       
   689                 TReadViagHomeZoneCacheRequest* req = 
       
   690                 iReadViagHomeZoneCacheRequests[ i ];
       
   691                 
       
   692                 if (aTsyReqHandle == req->iReqHandle)
       
   693                 	{
       
   694                 	// Complete the request if the request handle is found
       
   695 TFLOGSTRING3("TSY: CMmSIMTsy::ReadViagHomeZoneCacheCancel - Complete with Cancel from array Handle:%d Id=%d ", req->iReqHandle,i);
       
   696                     iMmCustomTsy->ReqCompleted( req->iReqHandle, KErrCancel );
       
   697 	                delete iReadViagHomeZoneCacheRequests[ i ];
       
   698 	                iReadViagHomeZoneCacheRequests.Remove(i);
       
   699                     break;                 	
       
   700                     }
       
   701                 }
       
   702             }
       
   703         }
       
   704     return KErrNone;
       
   705     }
       
   706 
       
   707 // ---------------------------------------------------------------------------
       
   708 // CMmSIMTsy::ReadDynamicViagHomeZoneCacheL
       
   709 // Reads Dynamic VIAG Home Zone cache.
       
   710 // (other items were commented in a header).
       
   711 // ---------------------------------------------------------------------------
       
   712 //
       
   713 TInt CMmSIMTsy::ReadDynamicViagHomeZoneCacheL(
       
   714     const TTsyReqHandle aTsyReqHandle,
       
   715     RMmCustomAPI::TViagCacheRecordId* aViagRecordId,
       
   716     RMmCustomAPI::TViagCacheRecordContent* aViagRecordContent )
       
   717     {
       
   718 TFLOGSTRING2("TSY: CMmSIMTsy::ReadDynamicViagHomeZoneCache:Is ViagHomeZoneCache Ready =%d", iViagHomeZoneCacheReady);
       
   719 TFLOGSTRING3("TSY: CMmSIMTsy::ReadDynamicViagHomeZoneCache iCacheId %d iRecordId %d",aViagRecordId->iCacheId,aViagRecordId->iRecordId );
       
   720     TInt err = KErrNone;
       
   721 	//  KPhEngMaxViagHomeZones(4) * KPhEngMaxCacheId(21)
       
   722 	if ( 1 > aViagRecordId->iCacheId || 4 < aViagRecordId->iCacheId || 
       
   723 		 0 > aViagRecordId->iRecordId || 20 < aViagRecordId->iRecordId )
       
   724 		{
       
   725 		err = KErrArgument;	
       
   726 		}
       
   727     else if ( iViagDynamicCache && iViagHomeZoneCacheReady )
       
   728         {
       
   729 TFLOGSTRING("TSY: CMmSIMTsy::ReadDynamicViagHomeZoneCache: else if : Cache is ready, Reading cache possible");
       
   730         // copy data from dynamic cache to client
       
   731         // some arithmetics:
       
   732         //     cache ids range 1..4
       
   733         //     record ids range 0..20
       
   734         //     array indexes range 0..83
       
   735         // ==> A[c][r] = A[((c-1)*rMax)+r]
       
   736         TInt arrayIndex = ( ( aViagRecordId->iCacheId - 1 ) * 21 ) +
       
   737             aViagRecordId->iRecordId;
       
   738         *aViagRecordContent = iViagDynamicCache->At( arrayIndex );
       
   739         }
       
   740     else if ( !iViagHomeZoneCacheReady )
       
   741         {
       
   742  TFLOGSTRING("TSY: CMmSIMTsy::ReadDynamicViagHomeZoneCache: else if : Cache is NOT ready, Reading cache NOT possible");
       
   743         //The request is already in processing because of previous request
       
   744         //Complete request with status value informing the client about
       
   745 		TReadViagHomeZoneCacheRequest* req = 
       
   746                               new (ELeave) TReadViagHomeZoneCacheRequest();
       
   747 		req->iReqHandle = aTsyReqHandle;
       
   748 		req->iViagRecordId = aViagRecordId;
       
   749 		req->iViagRecordContent = aViagRecordContent;
       
   750 		iReadViagHomeZoneCacheRequests.AppendL( req );
       
   751         }
       
   752 
       
   753     // complete to client
       
   754     if ( iViagHomeZoneCacheReady )
       
   755         {
       
   756         iMmCustomTsy->ReqCompleted( aTsyReqHandle, err );
       
   757         return KErrNone;
       
   758         }
       
   759     return err;
       
   760     }
       
   761 
       
   762 // ---------------------------------------------------------------------------
       
   763 // CMmSIMTsy::WriteViagHomeZoneCacheL
       
   764 // Writes VIAG Home Zone Cache.
       
   765 // (other items were commented in a header).
       
   766 // ---------------------------------------------------------------------------
       
   767 //
       
   768 TInt CMmSIMTsy::WriteViagHomeZoneCacheL(
       
   769     RMmCustomAPI::TViagCacheRecordId* aViagRecordId,
       
   770     RMmCustomAPI::TViagCacheRecordContent* aViagRecordContent )
       
   771     {
       
   772 TFLOGSTRING3("TSY: CCMmSIMTsy::WriteViagHomeZoneCacheL iCacheId %d iRecordId %d",aViagRecordId->iCacheId,aViagRecordId->iRecordId );
       
   773     TInt ret( KErrGeneral );
       
   774 
       
   775     if ( ESIMTsyReqHandleUnknown != iTsyReqHandleStore->GetTsyReqHandle(
       
   776         ESIMRequestTypeWriteCache ) )
       
   777         {
       
   778         return KErrServerBusy;
       
   779         }
       
   780 	if ( 1 > aViagRecordId->iCacheId || 4 < aViagRecordId->iCacheId || 
       
   781 		 0 > aViagRecordId->iRecordId || 20 < aViagRecordId->iRecordId )
       
   782 		{
       
   783 		return KErrArgument;	
       
   784 		}
       
   785     else if ( iViagDynamicCache )
       
   786         {
       
   787         // copy data from client to dynamic cache
       
   788         // some arithmetics:
       
   789         //     cache ids range 1..4
       
   790         //     record ids range 0..20
       
   791         //     array indexes range 0..83
       
   792         // ==> A[c][r] = A[((c-1)*rMax)+r]
       
   793         TInt arrayIndex = ( ( aViagRecordId->iCacheId - 1 ) * 21 ) +
       
   794             aViagRecordId->iRecordId;
       
   795         iViagDynamicCache->At( arrayIndex ) = *aViagRecordContent;
       
   796         }
       
   797 
       
   798     // send request to DOS
       
   799     // packed parameters: RMmCustomAPI::TViagCacheRecordId and
       
   800     // RMmCustomAPI::TViagCacheRecordContent
       
   801     CMmDataPackage dataPackage;
       
   802     dataPackage.PackData( aViagRecordId, aViagRecordContent );
       
   803     ret = iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
   804         EWriteViagHomeZoneCacheIPC, &dataPackage );
       
   805 
       
   806     if( KErrNone == ret )
       
   807         {
       
   808         // Store the request handle
       
   809         iReqHandleType = ESIMRequestTypeWriteCache;
       
   810         }
       
   811 
       
   812     return ret;
       
   813     }
       
   814 
       
   815 // ---------------------------------------------------------------------------
       
   816 // CMmSIMTsy::CompleteWriteViagHomeZoneCacheResp
       
   817 // Completes writing VIAG Home Zone Cache.
       
   818 // (other items were commented in a header).
       
   819 // ---------------------------------------------------------------------------
       
   820 //
       
   821 void CMmSIMTsy::CompleteWriteViagHomeZoneCacheResp(
       
   822     TInt aError )
       
   823     {
       
   824 TFLOGSTRING("TSY: CMmSIMTsy::CompleteWriteViagHomeZoneCacheResp");
       
   825     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   826         ESIMRequestTypeWriteCache );
       
   827 
       
   828     if ( ESIMTsyReqHandleUnknown != reqHandle )
       
   829         {
       
   830         iMmCustomTsy->ReqCompleted( reqHandle, aError );
       
   831         }
       
   832         
       
   833     return;
       
   834     }
       
   835 
       
   836 // ----------------------------------------------------------------------------
       
   837 // CMmSIMTsy::CompleteWriteViagHomeZoneUHZIUESettingsResp
       
   838 // This method copletes the VIAG Home Zone UHZIUE settings write request.
       
   839 // (other items were commented in a header).
       
   840 // ----------------------------------------------------------------------------
       
   841 //
       
   842 void CMmSIMTsy::CompleteWriteViagHomeZoneUHZIUESettingsResp(
       
   843     TInt aError )
       
   844     {
       
   845 TFLOGSTRING2("TSY: CMmSIMTsy::CompleteWriteViagHomeZoneUHZIUESettingsResp error = %d",aError);
       
   846     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   847         ESIMRequestTypeWriteSettings );
       
   848 
       
   849     if ( ESIMTsyReqHandleUnknown != reqHandle )
       
   850         {
       
   851         iMmCustomTsy->ReqCompleted( reqHandle, aError );
       
   852         }
       
   853     }
       
   854 
       
   855 // ---------------------------------------------------------------------------
       
   856 // CMmSIMTsy::WriteViagHomeZoneCacheCancel
       
   857 // Cancels writing VIAG Home Zone cache.
       
   858 // (other items were commented in a header).
       
   859 // ---------------------------------------------------------------------------
       
   860 //
       
   861 TInt CMmSIMTsy::WriteViagHomeZoneCacheCancel()
       
   862     {
       
   863     // reset the req handle
       
   864     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   865         ESIMRequestTypeWriteCache );
       
   866 
       
   867     if ( ESIMTsyReqHandleUnknown != reqHandle )
       
   868     	{
       
   869     	// complete with cancel
       
   870     	iMmCustomTsy->ReqCompleted( reqHandle, KErrCancel );
       
   871     	}
       
   872 
       
   873     return KErrNone;
       
   874     }
       
   875 
       
   876 // ---------------------------------------------------------------------------
       
   877 // CMmSIMTsy::StartDynamicCachingL
       
   878 // Start dynamic caching
       
   879 // (other items were commented in a header).
       
   880 // ---------------------------------------------------------------------------
       
   881 //
       
   882 void CMmSIMTsy::StartDynamicCachingL()
       
   883     {
       
   884 TFLOGSTRING("TSY: CMmSIMTsy::StartDynamicCachingL");
       
   885 
       
   886 	// Make sure there are no ongoing dynamic caching requests.. 
       
   887 	if( iCurrentlyRetrievedCache ) 
       
   888 		{ 
       
   889 TFLOGSTRING("TSY: CMmSIMTsy::StartDynamicCachingL - iCurrentlyRetrievedCache already exists - no new request done");       
       
   890 		return; 
       
   891 		} 
       
   892 
       
   893     TInt trapError;
       
   894     TRAP( trapError, iCurrentlyRetrievedCache = new (ELeave) 
       
   895         RMmCustomAPI::TViagCacheRecordId(); );
       
   896     if ( trapError )
       
   897         {
       
   898 TFLOGSTRING2("TSY: CMmSIMTsy::StartDynamicCachingL:Could not start caching, error=%d", trapError);
       
   899         return;
       
   900     }
       
   901 TFLOGSTRING("TSY: CMmSIMTsy::StartDynamicCachingL:Starting caching now.");
       
   902     iCurrentlyRetrievedCache->iCacheId = 1;  // caches range from 1 to 4
       
   903     iCurrentlyRetrievedCache->iRecordId = 0; // records range from 0 to 20
       
   904     // send request to DOS
       
   905     // packed parameter: RMmCustomAPI::TViagCacheRecordId
       
   906     CMmDataPackage dataPackage;
       
   907     dataPackage.PackData( iCurrentlyRetrievedCache );
       
   908     iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
   909         EReadViagHomeZoneCacheIPC, &dataPackage );
       
   910 
       
   911     }
       
   912 
       
   913 // ----------------------------------------------------------------------------
       
   914 // CMmSIMTsy::ReadViagHomeZoneUHZIUESettingsL
       
   915 // This method writes specified VIAG Home Zone UHZIUE settings to SIM.
       
   916 // (other items were commented in a header).
       
   917 // ----------------------------------------------------------------------------
       
   918 //
       
   919 TInt CMmSIMTsy::WriteViagHomeZoneUHZIUESettingsL(
       
   920     RMmCustomAPI::TViagUHZIUESettings* aSettings )
       
   921     {
       
   922 TFLOGSTRING("TSY: CMmSIMTsy::WriteViagHomeZoneUHZIUESettingsL");
       
   923     TInt ret( KErrGeneral );
       
   924 
       
   925     if ( ESIMTsyReqHandleUnknown != iTsyReqHandleStore->GetTsyReqHandle(
       
   926         ESIMRequestTypeWriteSettings ) )
       
   927         {
       
   928         return KErrServerBusy;
       
   929         }
       
   930 
       
   931     CMmDataPackage dataPackage;
       
   932     dataPackage.PackData( aSettings );
       
   933     ret = iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
   934         EWriteViagHomeZoneUHZIUESettingsIPC, &dataPackage );
       
   935 
       
   936     if( KErrNone == ret )
       
   937         {
       
   938         // Store the request handle
       
   939         iReqHandleType = ESIMRequestTypeWriteSettings;
       
   940         }
       
   941 
       
   942     return ret;
       
   943     }
       
   944 
       
   945 // ---------------------------------------------------------------------------
       
   946 // CMmSIMTsy::WriteViagHomeZoneUHZIUESettingsCancel
       
   947 // Cancels writing request of VIAG Home Zone UHZIUE settings.
       
   948 // (other items were commented in a header).
       
   949 // ---------------------------------------------------------------------------
       
   950 //
       
   951 TInt CMmSIMTsy::WriteViagHomeZoneUHZIUESettingsCancel()
       
   952     {
       
   953 TFLOGSTRING("TSY: CMmSIMTsy::WriteViagHomeZoneUHZIUESettingsCancel");
       
   954     // check if handle is not in use.
       
   955     TTsyReqHandle scFileHandle = 
       
   956         iTsyReqHandleStore->GetTsyReqHandle( ESIMRequestTypeWriteSettings );
       
   957 
       
   958     if( ESIMTsyReqHandleUnknown != scFileHandle )
       
   959         {
       
   960         // reset the req handle
       
   961         TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
   962             ESIMRequestTypeWriteSettings );
       
   963 
       
   964         if ( ESIMTsyReqHandleUnknown != reqHandle )
       
   965         	{
       
   966         	// complete with cancel
       
   967         	iMmCustomTsy->ReqCompleted( reqHandle, KErrCancel );
       
   968         	}
       
   969         }
       
   970 
       
   971     return KErrNone;
       
   972     }
       
   973 
       
   974 // ---------------------------------------------------------------------------
       
   975 // CMmSIMTsy::StartSimCbTopicBrowsingL
       
   976 // This method reads Cell Broadcast messages from SIM, and caches them in
       
   977 // iSimCbTopics. No data will be copied to client, this is done via
       
   978 // GetNextSimCbTopic.
       
   979 // (other items were commented in a header).
       
   980 // ---------------------------------------------------------------------------
       
   981 //
       
   982 TInt CMmSIMTsy::StartSimCbTopicBrowsingL(
       
   983     const TTsyReqHandle /*aTsyReqHandle */)
       
   984     {
       
   985 TFLOGSTRING("TSY: CMmSIMTsy::StartSimCbTopicBrowsingL");
       
   986     // reset variables
       
   987     ResetAndDestroySimCbTopics();
       
   988     iGetNextSimCbTopicIndex = KNoCbIds;
       
   989     TInt ret( KErrNone );
       
   990 
       
   991     if ( ESIMTsyReqHandleUnknown != iTsyReqHandleStore->GetTsyReqHandle(
       
   992          ESIMRequestTypeStartSimCbTopicBrowsing ) ||
       
   993          ESIMTsyReqHandleUnknown != iTsyReqHandleStore->GetTsyReqHandle(
       
   994          ESIMRequestTypeDeleteSimCbTopic ) )
       
   995         {
       
   996         // this request cannot be processed if either reading or deleting
       
   997         // CB topics is currently pending
       
   998         ret = KErrServerBusy;
       
   999         }
       
  1000     else
       
  1001         {
       
  1002         // send request to DOS (no packed parameters).
       
  1003         ret = iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
  1004             ECustomStartSimCbTopicBrowsingIPC );
       
  1005         if ( KErrNone == ret )
       
  1006             {
       
  1007             // store the request handle
       
  1008             iReqHandleType = ESIMRequestTypeStartSimCbTopicBrowsing;
       
  1009             }
       
  1010         }
       
  1011         
       
  1012     return ret;
       
  1013     }
       
  1014 
       
  1015 // ---------------------------------------------------------------------------
       
  1016 // CMmSIMTsy::CompleteStartSimCbTopicBrowsing
       
  1017 // This method completes the StartSimCbTopicBrowsing request. No data will be
       
  1018 // copied to client, this is done via GetNextSimCbTopic.
       
  1019 // (other items were commented in a header).
       
  1020 // ---------------------------------------------------------------------------
       
  1021 //
       
  1022 void CMmSIMTsy::CompleteStartSimCbTopicBrowsing(
       
  1023     CArrayFixFlat<RMmCustomAPI::TSimCbTopic>* aTopics, 
       
  1024     TInt aError )
       
  1025     {
       
  1026 TFLOGSTRING("TSY: CMmSIMTsy::CompleteStartSimCbTopicBrowsing");
       
  1027     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
  1028         ESIMRequestTypeStartSimCbTopicBrowsing );
       
  1029 
       
  1030     if ( ESIMTsyReqHandleUnknown != reqHandle )
       
  1031         {
       
  1032         if ( KErrNone == aError && aTopics )
       
  1033             {
       
  1034             // Request succeeded. Replace old CB topic array by the new one.
       
  1035             ResetAndDestroySimCbTopics();
       
  1036             iGetNextSimCbTopicIndex = 0;
       
  1037             TRAP_IGNORE( iSimCbTopics = new ( ELeave ) 
       
  1038                 CArrayFixFlat<RMmCustomAPI::TSimCbTopic>( aTopics->Count() );
       
  1039             // copy entries
       
  1040             for ( int i = 0; i < aTopics->Count(); i++ )
       
  1041                 {
       
  1042                 iSimCbTopics->AppendL( aTopics->At( i ) );
       
  1043                 }
       
  1044                 );
       
  1045             }
       
  1046         else
       
  1047             {
       
  1048             // Request failed. Destroy CB topics array
       
  1049             ResetAndDestroySimCbTopics();
       
  1050             iGetNextSimCbTopicIndex = KNoCbIds;
       
  1051             }
       
  1052 
       
  1053         // complete request
       
  1054         iMmCustomTsy->ReqCompleted( reqHandle, aError );
       
  1055         }
       
  1056     }
       
  1057 
       
  1058 // ---------------------------------------------------------------------------
       
  1059 // CMmSIMTsy::GetNextSimCbTopic
       
  1060 // This method get's the next id from local array and put's it to aSimCbTopic
       
  1061 // which is a pointer to client side structure.
       
  1062 // (other items were commented in a header).
       
  1063 // ---------------------------------------------------------------------------
       
  1064 //
       
  1065 TInt CMmSIMTsy::GetNextSimCbTopic(
       
  1066     TTsyReqHandle aTsyReqHandle, 
       
  1067     RMmCustomAPI::TSimCbTopic *aSimCbTopic )
       
  1068     {
       
  1069 TFLOGSTRING("TSY: CMmSIMTsy::GetNextSimCbTopic");
       
  1070     // initialize ret with KErrNotFound
       
  1071     TInt ret ( KErrNotFound );
       
  1072 
       
  1073     if( ( iGetNextSimCbTopicIndex >= 0 ) && iSimCbTopics )
       
  1074         {
       
  1075         if( iSimCbTopics->Count() > iGetNextSimCbTopicIndex )
       
  1076             {
       
  1077             // read the next id and put it to client side pointer
       
  1078             *aSimCbTopic = ( iSimCbTopics->At( iGetNextSimCbTopicIndex ) );
       
  1079             iGetNextSimCbTopicIndex++;
       
  1080             ret = KErrNone;
       
  1081             }
       
  1082         else
       
  1083             {
       
  1084             // set index to -1
       
  1085             iGetNextSimCbTopicIndex = KNoCbIds;
       
  1086             }
       
  1087         }
       
  1088 
       
  1089     // complete request
       
  1090     iMmCustomTsy->ReqCompleted( aTsyReqHandle, ret );
       
  1091 
       
  1092     return KErrNone;
       
  1093     }
       
  1094 
       
  1095 // ---------------------------------------------------------------------------
       
  1096 // CMmSIMTsy::DeleteSimCbTopicL
       
  1097 // Delete a CB topic stored on SIM.
       
  1098 // (other items were commented in a header).
       
  1099 // ---------------------------------------------------------------------------
       
  1100 //
       
  1101 TInt CMmSIMTsy::DeleteSimCbTopicL(
       
  1102     const TTsyReqHandle /*aTsyReqHandle */, 
       
  1103     TUint* aSimCbTopicNumber )
       
  1104     {
       
  1105 TFLOGSTRING("TSY: CMmSIMTsy::DeleteSimCbTopicL");
       
  1106     TInt ret( KErrNone );
       
  1107     TBool topicInSimMemoryDelete ( EFalse );
       
  1108 
       
  1109     // Check that neither browsing nor deleting request is pending
       
  1110     if ( ESIMTsyReqHandleUnknown != iTsyReqHandleStore->GetTsyReqHandle(
       
  1111          ESIMRequestTypeDeleteSimCbTopic ) ||
       
  1112          ESIMTsyReqHandleUnknown != iTsyReqHandleStore->GetTsyReqHandle(
       
  1113          ESIMRequestTypeStartSimCbTopicBrowsing ) )
       
  1114         {
       
  1115         ret = KErrServerBusy;
       
  1116         }
       
  1117 
       
  1118     // Find the topic id in cached list
       
  1119     if ( ( KErrNone == ret ) && iSimCbTopics )
       
  1120     	{
       
  1121     	iSimCbTopicIndexToBeDeleted = KErrNotFound;
       
  1122         for ( int i = 0; i < iSimCbTopics->Count(); i++ )
       
  1123             {
       
  1124             if ( iSimCbTopics->At( i ).iNumber == *aSimCbTopicNumber )
       
  1125                 {
       
  1126                 // Store index of entry to be deleted
       
  1127                 iSimCbTopicIndexToBeDeleted = i;
       
  1128                 ret = KErrNone;
       
  1129                 topicInSimMemoryDelete = ETrue;
       
  1130                 break;
       
  1131                 }
       
  1132             }
       
  1133         }
       
  1134 
       
  1135     // Send delete request to DOS
       
  1136     if ( KErrNone == ret )
       
  1137         {
       
  1138         // Send delete request to DOS
       
  1139         // Packed parameter: TUint with topic id
       
  1140         CMmDataPackage dataPackage;
       
  1141         dataPackage.PackData( aSimCbTopicNumber, &topicInSimMemoryDelete );
       
  1142         ret = iMmCustomTsy->Phone()->MessageManager()->HandleRequestL(
       
  1143             ECustomDeleteSimCbTopicIPC, &dataPackage );
       
  1144         }
       
  1145 
       
  1146     if ( KErrNone == ret )
       
  1147         {
       
  1148         // Store the request handle
       
  1149         iReqHandleType = ESIMRequestTypeDeleteSimCbTopic;
       
  1150         }
       
  1151 
       
  1152     return ret;
       
  1153     }
       
  1154 
       
  1155 // ---------------------------------------------------------------------------
       
  1156 // CMmSIMTsy::CompleteDeleteSimCbTopic
       
  1157 // Completes DeleteSimCbTopic request.
       
  1158 // (other items were commented in a header).
       
  1159 // ---------------------------------------------------------------------------
       
  1160 //
       
  1161 void CMmSIMTsy::CompleteDeleteSimCbTopic(
       
  1162     TInt aError )
       
  1163     {
       
  1164 TFLOGSTRING2("TSY: CMmSIMTsy::CompleteDeleteSimCbTopic- aError: %d", aError);
       
  1165     TTsyReqHandle reqHandle = iTsyReqHandleStore->ResetTsyReqHandle(
       
  1166         ESIMRequestTypeDeleteSimCbTopic );
       
  1167 
       
  1168     if ( ESIMTsyReqHandleUnknown != reqHandle )
       
  1169         {
       
  1170 
       
  1171     // if delete was successful, the cached array has to be updated
       
  1172     if ( KErrNone == aError )
       
  1173         {
       
  1174         // Delete entry from array
       
  1175         if ( iSimCbTopics && ( iSimCbTopicIndexToBeDeleted != KErrNotFound ) )
       
  1176         	{
       
  1177         	iSimCbTopics->Delete( iSimCbTopicIndexToBeDeleted );
       
  1178         	iSimCbTopics->Compress();
       
  1179         	}
       
  1180 
       
  1181         // Reset index, it could go crazy otherwise
       
  1182         iGetNextSimCbTopicIndex = 0;
       
  1183 
       
  1184         // Reset index of topic to be deleted
       
  1185         iSimCbTopicIndexToBeDeleted = KErrNotFound;
       
  1186         }
       
  1187 
       
  1188         iMmCustomTsy->ReqCompleted( reqHandle, aError );
       
  1189         }
       
  1190     }
       
  1191 
       
  1192 
       
  1193 // ---------------------------------------------------------------------------
       
  1194 // CMmSIMTsy::ResetAndDestroySimCbTopics
       
  1195 // Destroys the CB message id array
       
  1196 // (other items were commented in a header).
       
  1197 // ---------------------------------------------------------------------------
       
  1198 //
       
  1199 void CMmSIMTsy::ResetAndDestroySimCbTopics()
       
  1200     {
       
  1201     if( iSimCbTopics )
       
  1202         {
       
  1203         iSimCbTopics->Reset();
       
  1204         delete iSimCbTopics;
       
  1205         iSimCbTopics = NULL;
       
  1206         }
       
  1207     }
       
  1208 
       
  1209 #ifdef REQHANDLE_TIMER
       
  1210 // ---------------------------------------------------------------------------
       
  1211 // CMmSIMTsy::SetTypeOfResponse
       
  1212 // Sets the type of response for a given handle. Automatic mode includes an
       
  1213 // automatic response in case of non response from the DOS in a specified time.
       
  1214 // (other items were commented in a header).
       
  1215 // ---------------------------------------------------------------------------
       
  1216 //
       
  1217 void CMmSIMTsy::SetTypeOfResponse(
       
  1218     const TInt aReqHandleType, 
       
  1219     const TTsyReqHandle aTsyReqHandle )
       
  1220     {
       
  1221     TInt timeOut( 0 );
       
  1222     TInt ipc( 0 );
       
  1223 
       
  1224     switch ( aReqHandleType )
       
  1225         {
       
  1226         case ESIMRequestTypeReadParams:
       
  1227             timeOut = KMmViagHomeZoneReadParamsTimeOut;
       
  1228             ipc = EReadViagHomeZoneParamsIPC;
       
  1229             break;
       
  1230         case ESIMRequestTypeReadCache:
       
  1231             timeOut = KMmViagHomeZoneReadCacheTimeOut;
       
  1232             ipc = EReadViagHomeZoneCacheIPC;
       
  1233             break;
       
  1234         case ESIMRequestTypeWriteCache:
       
  1235             timeOut = KMmViagHomeZoneWriteCacheTimeOut;
       
  1236             ipc = EWriteViagHomeZoneCacheIPC;
       
  1237             break;
       
  1238         case ESIMRequestTypeWriteSettings:
       
  1239             timeOut = KMmViagHomeZoneWriteSettingsTimeOut;
       
  1240             ipc = EWriteViagHomeZoneUHZIUESettingsIPC;
       
  1241             break;
       
  1242         case ESIMRequestTypeStartSimCbTopicBrowsing:
       
  1243             timeOut = KMmStartSimCbTopicBrowsingTimeOut;
       
  1244             ipc = ECustomStartSimCbTopicBrowsingIPC;
       
  1245             break;
       
  1246         case ESIMRequestTypeDeleteSimCbTopic:
       
  1247         	timeOut = KMmDeleteSimCbTopicTimeOut;
       
  1248         	ipc = ECustomDeleteSimCbTopicIPC;
       
  1249         	break;
       
  1250         default:
       
  1251             // Does not use timer
       
  1252             iTsyReqHandleStore->SetTsyReqHandle(
       
  1253                 aReqHandleType, aTsyReqHandle );
       
  1254             break;
       
  1255         }
       
  1256 
       
  1257     if ( 0 < timeOut )
       
  1258         {
       
  1259         // The timeout parameter is given in seconds.
       
  1260         iTsyReqHandleStore->SetTsyReqHandle( aReqHandleType, aTsyReqHandle,
       
  1261             timeOut, ipc );
       
  1262         }
       
  1263     }
       
  1264 
       
  1265 // ---------------------------------------------------------------------------
       
  1266 // CMmSIMTsy::Complete
       
  1267 // Completes the request due the timer expiration.
       
  1268 // (other items were commented in a header).
       
  1269 // ---------------------------------------------------------------------------
       
  1270 void CMmSIMTsy::Complete(
       
  1271     TInt aReqHandleType, 
       
  1272     TInt aError )
       
  1273     {
       
  1274 TFLOGSTRING3( "CustomTSY: CMmSIMTsy::Complete.\n\t ReqHandleType:%d \n\t Error:%d\n", aReqHandleType, aError );
       
  1275 
       
  1276     // All possible TSY req handle types are listed in the
       
  1277     // switch case below.
       
  1278     switch ( aReqHandleType )
       
  1279         {
       
  1280         case ESIMRequestTypeReadParams:
       
  1281             CompleteReadViagHomeZoneParamsResp( NULL, NULL, aError );
       
  1282             break;
       
  1283         case ESIMRequestTypeReadCache:
       
  1284             TRAP_IGNORE( 
       
  1285             	CompleteReadViagHomeZoneCacheRespL( NULL, aError ););
       
  1286             break;
       
  1287         case ESIMRequestTypeWriteCache:
       
  1288             CompleteWriteViagHomeZoneCacheResp( aError );
       
  1289             break;
       
  1290         case ESIMRequestTypeWriteSettings:
       
  1291             CompleteWriteViagHomeZoneUHZIUESettingsResp( aError );
       
  1292             break;
       
  1293         case ESIMRequestTypeStartSimCbTopicBrowsing:
       
  1294             CompleteStartSimCbTopicBrowsing( NULL, aError );
       
  1295             break;
       
  1296         default:
       
  1297             iMmCustomTsy->ReqCompleted( iTsyReqHandleStore->ResetTsyReqHandle(
       
  1298                 aReqHandleType ), aError );
       
  1299             break;
       
  1300         }
       
  1301     }
       
  1302 #endif // REQHANDLE_TIMER
       
  1303 
       
  1304 //  End of File