satengine/SatServer/Engine/src/CSatSRefreshSubSession.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Handles the refresh sub-session IPC.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    <e32base.h>
       
    20 #include    "MSatUtils.h"
       
    21 #include    "CSatSRefreshSubSession.h"
       
    22 #include    "SatSOpcodes.h"
       
    23 #include    "CSatSSession.h"
       
    24 #include    "EnginePanic.h"
       
    25 #include    "CSatSServer.h"
       
    26 #include    "SatLog.h"
       
    27 
       
    28 const TInt KClientQueryDelay = 1000000; // 1 second.
       
    29 const TInt KClientNotifyDelay = 60000000; // 1 minute.
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CSatSRefreshSubSession::CSatSRefreshSubSession
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CSatSRefreshSubSession::CSatSRefreshSubSession(
       
    40     CSatSSession& aSession,
       
    41     TSatEventMediator& aEventMediator ) :
       
    42     CSatSSubSession( aSession ),
       
    43     iEventMediator( aEventMediator ),
       
    44     iClientQueryPending( EFalse ),
       
    45     iClientNotifyPending( EFalse ),
       
    46     iClientWaitingRefresh( EFalse )
       
    47     {
       
    48     LOG( SIMPLE,
       
    49         "SATENGINE: CSatSRefreshSubSession::CSatSRefreshSubSession \
       
    50         calling - exiting" )
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CSatSRefreshSubSession::ConstructL
       
    55 // Symbian 2nd phase constructor can leave.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CSatSRefreshSubSession::ConstructL()
       
    59     {
       
    60     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::ConstructL calling" )
       
    61 
       
    62     CSatSServer* server =
       
    63         const_cast<CSatSServer*>(
       
    64             static_cast<const CSatSServer*>( iSession.Server() ) );
       
    65     server->AddL( this );
       
    66 
       
    67     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::ConstructL exiting" )
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CSatSRefreshSubSession::NewL
       
    72 // Two-phased constructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CSatSRefreshSubSession* CSatSRefreshSubSession::NewL(
       
    76     CSatSSession& aSession,
       
    77     TSatEventMediator& aEventMediator )
       
    78     {
       
    79     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NewL calling" )
       
    80 
       
    81     CSatSRefreshSubSession* self =
       
    82         new( ELeave ) CSatSRefreshSubSession( aSession, aEventMediator );
       
    83 
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     CleanupStack::Pop( self );
       
    87 
       
    88     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NewL exiting" )
       
    89     return self;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CSatSRefreshSubSession::~CSatSRefreshSubSession()
       
    94 // Destructor.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CSatSRefreshSubSession::~CSatSRefreshSubSession()
       
    98     {
       
    99     LOG( SIMPLE,
       
   100         "SATENGINE: CSatSRefreshSubSession::~CSatSRefreshSubSession calling" )
       
   101 
       
   102     CSatSServer* server =
       
   103         const_cast<CSatSServer*>(
       
   104             static_cast<const CSatSServer*>( iSession.Server() ) );
       
   105     server->Remove( this );
       
   106 
       
   107     // Remove Client Query timer.
       
   108     if ( iQueryTimer )
       
   109         {
       
   110         iQueryTimer->Cancel();
       
   111         delete iQueryTimer;
       
   112         iQueryTimer = NULL;
       
   113         }
       
   114 
       
   115     // Remove Client Notify timer.
       
   116     if ( iNotifyTimer )
       
   117         {
       
   118         iNotifyTimer->Cancel();
       
   119         delete iNotifyTimer;
       
   120         iNotifyTimer = NULL;
       
   121         }
       
   122 
       
   123     LOG( SIMPLE,
       
   124         "SATENGINE: CSatSRefreshSubSession::~CSatSRefreshSubSession exiting" )
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CSatSRefreshSubSession::HandleCommandL
       
   129 // Handles the refresh sub-session requests.
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CSatSRefreshSubSession::HandleCommandL( const RMessage2& aMessage )
       
   133     {
       
   134     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::HandleCommandL calling" )
       
   135 
       
   136     switch ( aMessage.Function() )
       
   137         {
       
   138         case ESatSRefreshAllowed:
       
   139             {
       
   140             LOG( NORMAL, "SATENGINE:   Command: ESatSRefreshAllowed" )
       
   141             // Client's response to refresh query.
       
   142             RefreshAllowed( aMessage );
       
   143             break;
       
   144             }
       
   145 
       
   146         case ESatSNotifyAllowRefresh:
       
   147             {
       
   148             LOG( NORMAL, "SATENGINE:   Command: ESatSNotifyAllowRefresh" )
       
   149             // Client is ready for refresh query.
       
   150             NotifyRefreshAllowed( aMessage );
       
   151             break;
       
   152             }
       
   153 
       
   154         case ESatSNotityAllowRefreshCancel:
       
   155             {
       
   156             LOG( NORMAL, "SATENGINE:   Command: ESatSNotityAllowRefreshCancel" )
       
   157             // Client cancels the refresh query.
       
   158             CancelNotifyAllowRefresh( aMessage );
       
   159             break;
       
   160             }
       
   161 
       
   162         case ESatSNotifyRefresh:
       
   163             {
       
   164             LOG( NORMAL, "SATENGINE:   Command: ESatSNotifyRefresh" )
       
   165             // Client is ready for refresh.
       
   166             NotifyRefresh( aMessage );
       
   167             break;
       
   168             }
       
   169 
       
   170         case ESatSCancelNotifyRefresh:
       
   171             {
       
   172             LOG( NORMAL, "SATENGINE:   Command: ESatSCancelNotifyRefresh" )
       
   173             // Client cancels the refresh.
       
   174             CancelNotifyRefresh( aMessage );
       
   175             break;
       
   176             }
       
   177 
       
   178         case ESatSRefreshEFRead:
       
   179             {
       
   180             LOG( NORMAL, "SATENGINE:   Command: ESatSRefreshEFRead" )
       
   181             // Client has completed refresh.
       
   182             CompleteRefresh( aMessage );
       
   183             break;
       
   184             }
       
   185 
       
   186         default:
       
   187             {
       
   188             LOG( NORMAL, "SATENGINE:   Unexpected command: ggg" )
       
   189             // A wrong message was sent.
       
   190             iSession.PanicClient( aMessage, ESatSBadDescriptor );
       
   191             }
       
   192         }
       
   193 
       
   194     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::HandleCommandL exiting" )
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CSatSRefreshSubSession::RefreshAllowed
       
   199 // Sends the client's response of refresh query to SatServer.
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CSatSRefreshSubSession::RefreshAllowed( const RMessage2& aMessage )
       
   203     {
       
   204     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::RefreshAllowed calling" )
       
   205 
       
   206     // Handle reply only when we are waiting for it.
       
   207     // It is possible, that query has timed out and we got a late response.
       
   208     if ( iClientQueryPending )
       
   209         {
       
   210         LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::RefreshAllowed \
       
   211         iClientQueryPending true" )
       
   212         iClientQueryPending = EFalse;
       
   213 
       
   214         // Stop timer, client replied.
       
   215         if ( iQueryTimer )
       
   216             {
       
   217             LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::RefreshAllowed \
       
   218             iQueryTimer true" )
       
   219             iQueryTimer->Cancel();
       
   220             }
       
   221 
       
   222         TBool allow( EFalse );
       
   223         TPckg<TBool> allowPckg( allow );
       
   224         TRAPD( err, aMessage.ReadL( 0, allowPckg ) );
       
   225         LOG2( SIMPLE, "SATENGINE: CSatSRefreshSubSession::RefreshAllowed \
       
   226               err: %i", err )
       
   227         if ( KErrNone == err )
       
   228             {
       
   229             //lint -e{774} Allow updated through allowPckg in ReadL.
       
   230             if ( allow )
       
   231                 {
       
   232                 LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::\
       
   233                      RefreshAllowed allow refresh" )
       
   234                 iEventMediator.Notify( MSatUtils::ERefreshAllowed );
       
   235                 iClientWaitingRefresh = ETrue;
       
   236                 }
       
   237             else
       
   238                 {
       
   239                 LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::\
       
   240                      RefreshAllowed don't allow refresh" )
       
   241                 iEventMediator.Notify( MSatUtils::ERefreshNotAllowed );
       
   242                 }
       
   243             }
       
   244         else
       
   245             {
       
   246             iSession.PanicClient( aMessage, ESatSBadDescriptor );
       
   247             }
       
   248         }
       
   249 
       
   250     aMessage.Complete( KErrNone );
       
   251 
       
   252     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::RefreshAllowed exiting" )
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CSatSRefreshSubSession::NotifyRefresh
       
   257 // Stores the NotifyRefresh request information for later completion.
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CSatSRefreshSubSession::NotifyRefresh( const RMessage2& aMessage )
       
   261     {
       
   262     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NotifyRefresh calling" )
       
   263 
       
   264     if ( !iNotifyRefreshPending )
       
   265         {
       
   266         iNotifyRefreshPending = ETrue;
       
   267         iNotifyRefreshMessage = aMessage;
       
   268         }
       
   269     else
       
   270         {
       
   271         LOG( SIMPLE, "SATENGINE:   Request already received" )
       
   272         aMessage.Complete( KErrInUse );
       
   273         }
       
   274 
       
   275     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NotifyRefresh exiting" )
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CSatSRefreshSubSession::CancelNotifyRefresh
       
   280 // Cancels the refresh notification
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CSatSRefreshSubSession::CancelNotifyRefresh( const RMessage2& aMessage )
       
   284     {
       
   285     LOG( SIMPLE,
       
   286         "SATENGINE: CSatSRefreshSubSession::CancelNotifyRefresh calling" )
       
   287 
       
   288     if ( iNotifyRefreshPending )
       
   289         {
       
   290         LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::CancelNotifyRefresh\
       
   291         iNotifyRefreshPending true" )
       
   292         iNotifyRefreshPending = EFalse;
       
   293         iNotifyRefreshMessage.Complete( KErrCancel );
       
   294         }
       
   295 
       
   296     aMessage.Complete( KErrNone );
       
   297 
       
   298     LOG( SIMPLE,
       
   299         "SATENGINE: CSatSRefreshSubSession::CancelNotifyRefresh exiting" )
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CSatSRefreshSubSession::NotifyRefreshAllowed
       
   304 // Storest the refresh notification for later completion
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CSatSRefreshSubSession::NotifyRefreshAllowed( const RMessage2& aMessage )
       
   308     {
       
   309     LOG( SIMPLE,
       
   310         "SATENGINE: CSatSRefreshSubSession::NotifyRefreshAllowed calling" )
       
   311 
       
   312     if ( !iRefreshAllowPending )
       
   313         {
       
   314         iRefreshAllowPending = ETrue;
       
   315         iRefreshAllowMessage = aMessage;
       
   316         }
       
   317     else
       
   318         {
       
   319         LOG( SIMPLE, "SATENGINE:   Request already received" )
       
   320         aMessage.Complete( KErrInUse );
       
   321         }
       
   322 
       
   323     LOG( SIMPLE,
       
   324         "SATENGINE: CSatSRefreshSubSession::NotifyRefreshAllowed exiting" )
       
   325     }
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // CSatSRefreshSubSession::CancelNotifyAllowRefresh
       
   329 // Cancels the refresh notification.
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 void CSatSRefreshSubSession::CancelNotifyAllowRefresh(
       
   333     const RMessage2& aMessage )
       
   334     {
       
   335     LOG( SIMPLE,
       
   336         "SATENGINE: CSatSRefreshSubSession::CancelNotifyAllowRefresh calling" )
       
   337 
       
   338     if ( iRefreshAllowPending )
       
   339         {
       
   340         LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::\
       
   341         CancelNotifyAllowRefresh iRefreshAllowPending true" )
       
   342         iRefreshAllowPending = EFalse;
       
   343         iRefreshAllowMessage.Complete( KErrCancel );
       
   344         }
       
   345 
       
   346     aMessage.Complete( KErrNone );
       
   347 
       
   348     LOG( SIMPLE,
       
   349         "SATENGINE: CSatSRefreshSubSession::CancelNotifyAllowRefresh exiting" )
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // CSatSRefreshSubSession::CompleteRefresh
       
   354 // Sends the client's completion to SatServer.
       
   355 // -----------------------------------------------------------------------------
       
   356 //
       
   357 void CSatSRefreshSubSession::CompleteRefresh( const RMessage2& aMessage )
       
   358     {
       
   359     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::CompleteRefresh calling" )
       
   360 
       
   361     // Handle completion only when we are waiting for it.
       
   362     // It is possible, that it has timed out and we got a late response.
       
   363     if ( iClientNotifyPending )
       
   364         {
       
   365         LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::CompleteRefresh \
       
   366         iClientNotifyPending true" )
       
   367         iClientNotifyPending = EFalse;
       
   368 
       
   369         // Stop timer, client replied.
       
   370         if ( iNotifyTimer )
       
   371             {
       
   372             LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::CompleteRefresh \
       
   373             iNotifyTimer true" )
       
   374             iNotifyTimer->Cancel();
       
   375             }
       
   376 
       
   377         TBool additionEFRead( EFalse );
       
   378         TPckg<TBool> additionEFReadPckg( additionEFRead );
       
   379         TRAPD( err, aMessage.ReadL( 0, additionEFReadPckg ) );
       
   380         if ( KErrNone == err )
       
   381             {
       
   382             //lint -e{774} additionEFRead updated through additionEFReadPckg.
       
   383             if ( additionEFRead )
       
   384                 {
       
   385                 LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::\
       
   386                      CompleteRefresh additionEFRead true" )
       
   387                 iEventMediator.Notify( MSatUtils::ERefreshAdditionalEFRead );
       
   388                 }
       
   389             else
       
   390                 {
       
   391                 LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::\
       
   392                      CompleteRefresh additionEFRead false" )
       
   393                 iEventMediator.Notify( MSatUtils::ERefreshEFRead );
       
   394                 }
       
   395             }
       
   396         else
       
   397             {
       
   398             LOG( SIMPLE, "SATENGINE:   Bad descriptor" )
       
   399             iEventMediator.Notify( MSatUtils::ERefreshEFRead );
       
   400             }
       
   401         }
       
   402 
       
   403     aMessage.Complete( KErrNone );
       
   404 
       
   405     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::CompleteRefresh exiting" )
       
   406     }
       
   407 
       
   408 // -----------------------------------------------------------------------------
       
   409 // CSatSRefreshSubSession::QueryClient
       
   410 // Notifies the client that response for refresh query has to be made.
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 void CSatSRefreshSubSession::QueryClient(
       
   414     const RSat::TRefreshV2& aRefresh )
       
   415     {
       
   416     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::QueryClient calling" )
       
   417     TBool allowRefreshNow( ETrue );
       
   418 
       
   419     if ( iRefreshAllowPending )
       
   420         {
       
   421         if ( VerifyObservedFiles( aRefresh ) )
       
   422             {
       
   423             // Write the refresh information to client.
       
   424             TPckg<RSat::TRefreshFileList> fileListPckg( aRefresh.iFileList );
       
   425             TPckg<RSat::TRefreshType> typePckg( aRefresh.iType );
       
   426 
       
   427             TRAPD(
       
   428                 err,
       
   429                 iRefreshAllowMessage.WriteL( 0, fileListPckg );
       
   430                 iRefreshAllowMessage.WriteL( 1, typePckg ); )
       
   431 
       
   432             if ( KErrNone == err )
       
   433                 {
       
   434                 LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::QueryClient \
       
   435                 KErrNone == err" )
       
   436                 iRefreshAllowPending = EFalse;
       
   437                 iRefreshAllowMessage.Complete( err );
       
   438                 iClientQueryPending = ETrue;
       
   439                 allowRefreshNow = EFalse;
       
   440 
       
   441                 // Start timer to prevent jam, when client will not reply.
       
   442                 if ( iQueryTimer )
       
   443                     {
       
   444                     LOG( SIMPLE, "CSatSRefreshSubSession::QueryClient \
       
   445                          iQueryTimer true" )
       
   446                     iQueryTimer->Cancel();
       
   447                     }
       
   448                 else
       
   449                     {
       
   450                     // Create Client Query timer when first time used.
       
   451                     TRAP(
       
   452                         err,
       
   453                         iQueryTimer =
       
   454                             CPeriodic::NewL( CActive::EPriorityStandard ); )
       
   455                     }
       
   456 
       
   457                 if ( ( KErrNone == err ) && iQueryTimer )
       
   458                     {
       
   459                     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::\
       
   460                     QueryClient start iQueryTimer" )
       
   461                     TCallBack callback( TimerQueryCallback, this );
       
   462                     iQueryTimer->Start(
       
   463                         KClientQueryDelay,
       
   464                         KClientQueryDelay,
       
   465                         callback );
       
   466                     }
       
   467                 }
       
   468             else
       
   469                 {
       
   470                 LOG2( SIMPLE, "SATENGINE:   QueryClient error: %i", err )
       
   471                 }
       
   472             }
       
   473         }
       
   474 
       
   475     if ( allowRefreshNow )
       
   476         {
       
   477         LOG( SIMPLE, "CSatSRefreshSubSession::QueryClient \
       
   478         allowRefreshNow true" )
       
   479         iEventMediator.Notify( MSatUtils::ERefreshAllowed );
       
   480         }
       
   481 
       
   482     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::QueryClient exiting" )
       
   483     }
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CSatSRefreshSubSession::NotifyClient
       
   487 // Notifies the client that refresh has happened.
       
   488 // -----------------------------------------------------------------------------
       
   489 //
       
   490 void CSatSRefreshSubSession::NotifyClient(
       
   491     const RSat::TRefreshV2& aRefresh )
       
   492     {
       
   493     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NotifyClient calling" )
       
   494     TBool completeRefreshNow( ETrue );
       
   495 
       
   496     if ( iNotifyRefreshPending && iClientWaitingRefresh )
       
   497         {
       
   498         TPckg<RSat::TRefreshFileList> fileListPckg( aRefresh.iFileList );
       
   499 
       
   500         #ifdef ENABLE_SAT_LOGGING
       
   501         TInt fileCount ( aRefresh.iFileList.Length() );
       
   502         LOG2( NORMAL, "SATENGINE:   Refresh file count: %d", fileCount )
       
   503         for ( TInt fileIndex = 0; fileIndex < fileCount; fileIndex++ )
       
   504             {
       
   505             LOG2( NORMAL, "SATENGINE:     Refresh file : %x",
       
   506                 aRefresh.iFileList[ fileIndex ] )
       
   507             }
       
   508         #endif
       
   509 
       
   510         TPckg<RSat::TRefreshType> typePckg( aRefresh.iType );
       
   511 
       
   512         TRAPD(
       
   513             err,
       
   514             iNotifyRefreshMessage.WriteL( 0, fileListPckg );
       
   515             iNotifyRefreshMessage.WriteL( 1, typePckg ); )
       
   516 
       
   517         LOG2( SIMPLE, "SATENGINE:   NotifyClient error: %i", err )
       
   518         if ( KErrNone == err )
       
   519             {
       
   520             // ESimReset confirmation will not be waited.
       
   521             if ( RSat::ESimReset != aRefresh.iType )
       
   522                 {
       
   523                 LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NotifyClient\
       
   524                 RSat::ESimReset != aRefresh.iType" )
       
   525                 iClientNotifyPending = ETrue; // Waiting client
       
   526                 completeRefreshNow = EFalse; // Client must complete this
       
   527 
       
   528                 // Start timer to prevent jam, when client will not restart.
       
   529                 if ( iNotifyTimer )
       
   530                     {
       
   531                     LOG( SIMPLE, "CSatSRefreshSubSession::NotifyClient \
       
   532                          iNotifyTimer true" )
       
   533                     iNotifyTimer->Cancel();
       
   534                     }
       
   535                 else
       
   536                     {
       
   537                     // Create Client Notify timer when first time used.
       
   538                     TRAP(
       
   539                         err,
       
   540                         iNotifyTimer =
       
   541                             CPeriodic::NewL( CActive::EPriorityStandard ); )
       
   542                     }
       
   543 
       
   544                 if ( ( KErrNone == err ) && iNotifyTimer )
       
   545                     {
       
   546                     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::\
       
   547                     NotifyClient start iNotifyTimer" )
       
   548                     TCallBack callback( TimerNotifyCallback, this );
       
   549                     iNotifyTimer->Start(
       
   550                         KClientNotifyDelay,
       
   551                         KClientNotifyDelay,
       
   552                         callback );
       
   553                     }
       
   554                 }
       
   555             }
       
   556 
       
   557         iNotifyRefreshPending = EFalse;
       
   558         iClientWaitingRefresh = EFalse;
       
   559         iNotifyRefreshMessage.Complete( err );
       
   560         }
       
   561 
       
   562     if ( completeRefreshNow )
       
   563         {
       
   564         LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NotifyClient \
       
   565         completeRefreshNow true" )
       
   566         iEventMediator.Notify( MSatUtils::ERefreshEFRead );
       
   567         }
       
   568 
       
   569     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NotifyClient exiting" )
       
   570     }
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CSatSRefreshSubSession::NotifyClientCancel
       
   574 // Notifies the client that refresh has been cancelled.
       
   575 // -----------------------------------------------------------------------------
       
   576 //
       
   577 void CSatSRefreshSubSession::NotifyClientCancel()
       
   578     {
       
   579     LOG( SIMPLE,
       
   580         "SATENGINE: CSatSRefreshSubSession::NotifyClientCancel calling" )
       
   581 
       
   582     // Notify only clients having accepted Refresh and waiting it.
       
   583     if ( iNotifyRefreshPending && iClientWaitingRefresh )
       
   584         {
       
   585         LOG( SIMPLE,
       
   586         "SATENGINE: CSatSRefreshSubSession::NotifyClientCancel wait refresh" )
       
   587         RSat::TRefreshFileList fileList;
       
   588         fileList.Zero();
       
   589         TPckg<RSat::TRefreshFileList> fileListPckg( fileList );
       
   590         TPckg<RSat::TRefreshType> typePckg( RSat::ERefreshTypeNotSet );
       
   591         iNotifyRefreshPending = EFalse;
       
   592         iClientWaitingRefresh = EFalse;
       
   593 
       
   594         TRAPD(
       
   595             err,
       
   596             iNotifyRefreshMessage.WriteL( 0, fileListPckg );
       
   597             iNotifyRefreshMessage.WriteL( 1, typePckg ) );
       
   598         
       
   599         LOG2( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NotifyClientCancel error: %i", err )
       
   600 
       
   601         iNotifyRefreshMessage.Complete( err );
       
   602         }
       
   603 
       
   604     LOG( SIMPLE,
       
   605         "SATENGINE: CSatSRefreshSubSession::NotifyClientCancel exiting" )
       
   606     }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CSatSRefreshSubSession::VerifyObservedFiles
       
   610 // Checks whether current client is interested about this refresh.
       
   611 // -----------------------------------------------------------------------------
       
   612 //
       
   613 TBool CSatSRefreshSubSession::VerifyObservedFiles(
       
   614     const RSat::TRefreshV2& aRefresh ) const
       
   615     {
       
   616     LOG( SIMPLE,
       
   617         "SATENGINE: CSatSRefreshSubSession::VerifyObservedFiles calling" )
       
   618     TBool isObserved( ETrue );
       
   619 
       
   620     // Only pure file refresh is checked.
       
   621     if ( RSat::EFileChangeNotification == aRefresh.iType )
       
   622         {
       
   623         // Fetch observed files from clients message.
       
   624         RSat::TRefreshFileList observedFiles;
       
   625         observedFiles.Zero();
       
   626         TPckg<RSat::TRefreshFileList> observedPckg( observedFiles );
       
   627         TRAPD( err, iRefreshAllowMessage.ReadL( 0, observedPckg ) );
       
   628         LOG2( SIMPLE, "SATENGINE:   ReadL failed: %i", err )
       
   629         if ( KErrNone == err )
       
   630             {
       
   631             TInt observeFileCount( observedFiles.Length() );
       
   632             LOG2( SIMPLE, "SATENGINE: CSatSRefreshSubSession::\
       
   633                   VerifyObservedFiles observeFileCount: %i", observeFileCount )
       
   634             if ( observeFileCount > 0 )
       
   635                 {
       
   636                 LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::\
       
   637                 VerifyObservedFiles observeFileCount > 0" )
       
   638                 // Observed files found, check whether any of them has been
       
   639                 // updated.
       
   640                 isObserved = EFalse;
       
   641                 for ( TInt fileIndex = 0;
       
   642                       ( fileIndex < observeFileCount ) && !isObserved;
       
   643                       fileIndex++ )
       
   644                     {
       
   645                     if ( KErrNotFound !=
       
   646                          aRefresh.iFileList.Locate(
       
   647                             observedFiles[ fileIndex ] ) )
       
   648                         {
       
   649                         isObserved = ETrue;
       
   650                         LOG( SIMPLE, "SATENGINE:   Observed file found" )
       
   651                         }
       
   652                     }
       
   653                 }
       
   654             }
       
   655         }
       
   656 
       
   657     LOG( SIMPLE,
       
   658         "SATENGINE: CSatSRefreshSubSession::VerifyObservedFiles exiting" )
       
   659     return isObserved;
       
   660     }
       
   661 
       
   662 // -----------------------------------------------------------------------------
       
   663 // CSatSRefreshSubSession::TimerQueryCallback
       
   664 // (other items were commented in a header).
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 TInt CSatSRefreshSubSession::TimerQueryCallback(
       
   668     TAny* aRefreshSubSession )
       
   669     {
       
   670     LOG( SIMPLE,
       
   671         "SATENGINE: CSatSRefreshSubSession::TimerQueryCallback calling" )
       
   672 
       
   673     CSatSRefreshSubSession* handler =
       
   674         static_cast<CSatSRefreshSubSession*>( aRefreshSubSession );
       
   675 
       
   676     if ( handler )
       
   677         {
       
   678         LOG( SIMPLE,
       
   679         "SATENGINE: CSatSRefreshSubSession::TimerQueryCallback handler true" )
       
   680         handler->QueryTimeout();
       
   681         }
       
   682 
       
   683     LOG( SIMPLE,
       
   684         "SATENGINE: CSatSRefreshSubSession::TimerQueryCallback exiting" )
       
   685     return KErrNone;
       
   686     }
       
   687 
       
   688 // -----------------------------------------------------------------------------
       
   689 // CSatSRefreshSubSession::QueryTimeout
       
   690 // Timeout handler for the client's response of refresh query.
       
   691 // -----------------------------------------------------------------------------
       
   692 //
       
   693 void CSatSRefreshSubSession::QueryTimeout()
       
   694     {
       
   695     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::QueryTimeout calling" )
       
   696 
       
   697     if ( iQueryTimer )
       
   698         {
       
   699         LOG( SIMPLE,
       
   700         "SATENGINE: CSatSRefreshSubSession::QueryTimeout iQueryTimer true" )
       
   701         iQueryTimer->Cancel();
       
   702         }
       
   703 
       
   704     // Handle reply timeout only when we are waiting for it.
       
   705     if ( iClientQueryPending )
       
   706         {
       
   707         LOG( SIMPLE,
       
   708         "SATENGINE: CSatSRefreshSubSession::QueryTimeout \
       
   709         iClientQueryPending true" )
       
   710         iClientQueryPending = EFalse;
       
   711         iEventMediator.Notify( MSatUtils::ERefreshAllowed );
       
   712         }
       
   713 
       
   714     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::QueryTimeout exiting" )
       
   715     }
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // CSatSRefreshSubSession::TimerNotifyCallback
       
   719 // (other items were commented in a header).
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 TInt CSatSRefreshSubSession::TimerNotifyCallback(
       
   723     TAny* aRefreshSubSession )
       
   724     {
       
   725     LOG( SIMPLE,
       
   726         "SATENGINE: CSatSRefreshSubSession::TimerNotifyCallback calling" )
       
   727 
       
   728     CSatSRefreshSubSession* handler =
       
   729         static_cast<CSatSRefreshSubSession*>( aRefreshSubSession );
       
   730 
       
   731     if ( handler )
       
   732         {
       
   733         LOG( SIMPLE,
       
   734         "SATENGINE: CSatSRefreshSubSession::TimerNotifyCallback handler" )
       
   735         handler->NotifyTimeout();
       
   736         }
       
   737 
       
   738     LOG( SIMPLE,
       
   739         "SATENGINE: CSatSRefreshSubSession::TimerNotifyCallback exiting" )
       
   740     return KErrNone;
       
   741     }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // CSatSRefreshSubSession::NotifyTimeout
       
   745 // Timeout handler for the client's response of refresh query.
       
   746 // -----------------------------------------------------------------------------
       
   747 //
       
   748 void CSatSRefreshSubSession::NotifyTimeout()
       
   749     {
       
   750     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NotifyTimeout calling" )
       
   751 
       
   752     if ( iNotifyTimer )
       
   753         {
       
   754         LOG( SIMPLE, 
       
   755         "SATENGINE: CSatSRefreshSubSession::NotifyTimeout iNotifyTimer true" )
       
   756         iNotifyTimer->Cancel();
       
   757         }
       
   758 
       
   759     // Handle reply timeout only when we are waiting for it.
       
   760     if ( iClientNotifyPending )
       
   761         {
       
   762         LOG( SIMPLE, 
       
   763         "SATENGINE: CSatSRefreshSubSession::NotifyTimeout \
       
   764         iClientNotifyPending" )
       
   765         iClientNotifyPending = EFalse;
       
   766         // On timeout we should assume no EFs read, as most typical for S60.
       
   767         iEventMediator.Notify( MSatUtils::ERefreshEFRead );
       
   768         }
       
   769 
       
   770     LOG( SIMPLE, "SATENGINE: CSatSRefreshSubSession::NotifyTimeout exiting" )
       
   771     }