satengine/SatServer/SatClient/src/CSatAllowRefreshMonitor.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:  Active object for waiting the refresh query,
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CSatAllowRefreshMonitor.h"
       
    22 #include    "msatrefreshobserver.h"
       
    23 #include    "rsatrefresh.h"
       
    24 #include    "SatLog.h"
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CSatAllowRefreshMonitor::CSatAllowRefreshMonitor
       
    30 // C++ default constructor can NOT contain any code, that
       
    31 // might leave.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CSatAllowRefreshMonitor::CSatAllowRefreshMonitor(
       
    35     MSatRefreshObserver& aObserver,
       
    36     RSatRefresh& aRefresh ) :
       
    37     CActive( CActive::EPriorityStandard ),
       
    38     iObserver( aObserver ),
       
    39     iRefresh( aRefresh ),
       
    40     iChangingFiles(),
       
    41     iChangingFilesPckg( iChangingFiles ),
       
    42     iObservedFiles(),
       
    43     iType( ERefreshTypeNotSet ),
       
    44     iTypePckg( iType )
       
    45     {
       
    46     LOG( SIMPLE,
       
    47         "SATCLIENT: CSatAllowRefreshMonitor::CSatAllowRefreshMonitor calling" )
       
    48 
       
    49     CActiveScheduler::Add( this );
       
    50     iObservedFiles.Zero();
       
    51 
       
    52     LOG( SIMPLE,
       
    53         "SATCLIENT: CSatAllowRefreshMonitor::CSatAllowRefreshMonitor exiting" )
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CSatAllowRefreshMonitor::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CSatAllowRefreshMonitor* CSatAllowRefreshMonitor::NewL(
       
    62     MSatRefreshObserver& aObserver,
       
    63     RSatRefresh& aRefresh )
       
    64     {
       
    65     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::NewL calling" )
       
    66 
       
    67     CSatAllowRefreshMonitor* self =
       
    68         new ( ELeave ) CSatAllowRefreshMonitor( aObserver, aRefresh );
       
    69 
       
    70     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::NewL exiting" )
       
    71     return self;
       
    72     }
       
    73 
       
    74 // Destructor
       
    75 CSatAllowRefreshMonitor::~CSatAllowRefreshMonitor()
       
    76     {
       
    77     LOG( SIMPLE,
       
    78         "SATCLIENT: CSatAllowRefreshMonitor::~CSatAllowRefreshMonitor calling" )
       
    79 
       
    80     Cancel();
       
    81     iObservedFiles.Zero();
       
    82 
       
    83     LOG( SIMPLE,
       
    84         "SATCLIENT: CSatAllowRefreshMonitor::~CSatAllowRefreshMonitor exiting" )
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSatAllowRefreshMonitor::ObserveFiles
       
    89 // Set files to be observed.
       
    90 // (other items were commented in a header).
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CSatAllowRefreshMonitor::ObserveFiles(
       
    94     const TSatRefreshFiles& aObservedFiles )
       
    95     {
       
    96     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::ObserveFiles calling" )
       
    97 
       
    98     iObservedFiles.Zero();
       
    99 
       
   100     // Add list of observed files if given.
       
   101     TInt observeFileCount( aObservedFiles.Length() );
       
   102     LOG2( SIMPLE, 
       
   103     "SATCLIENT: CSatAllowRefreshMonitor::ObserveFiles observeFileCount: %d",
       
   104     observeFileCount )
       
   105     for ( TInt fileIndex = 0; fileIndex < observeFileCount; fileIndex++ )
       
   106         {
       
   107         iObservedFiles.Append( aObservedFiles[ fileIndex ] );
       
   108         }
       
   109 
       
   110     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::ObserveFiles exiting" )
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CSatAllowRefreshMonitor::Start
       
   115 // Starts the waiting of notification.
       
   116 // (other items were commented in a header).
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CSatAllowRefreshMonitor::Start()
       
   120     {
       
   121     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::Start calling" )
       
   122 
       
   123     if ( !IsActive() )
       
   124         {
       
   125         LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::Start not Active" )
       
   126         iChangingFiles.Zero();
       
   127 
       
   128         // Add list of observed files if given.
       
   129         TInt observeFileCount( iObservedFiles.Length() );
       
   130         LOG2( SIMPLE, 
       
   131         "SATCLIENT: CSatAllowRefreshMonitor::Start observeFileCount: %d",
       
   132         observeFileCount )
       
   133         for ( TInt fileIndex = 0; fileIndex < observeFileCount; fileIndex++ )
       
   134             {
       
   135             iChangingFiles.Append( iObservedFiles[ fileIndex ] );
       
   136             }
       
   137 
       
   138         iRefresh.NotifyAllowRefresh( iTypePckg, iChangingFilesPckg, iStatus );
       
   139         SetActive();
       
   140         }
       
   141 
       
   142     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::Start exiting" )
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CSatAllowRefreshMonitor::RunL
       
   147 // Notifies the observer for the refresh query.
       
   148 // (other items were commented in a header).
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CSatAllowRefreshMonitor::RunL()
       
   152     {
       
   153     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::RunL calling" )
       
   154     const TInt err( iStatus.Int() );
       
   155     
       
   156     LOG2( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::RunL, error: %i", err )
       
   157 
       
   158     if ( KErrNone == err )
       
   159         {
       
   160         const TBool response = iObserver.AllowRefresh( iType, iChangingFiles );
       
   161         iRefresh.AllowRefreshL( response );
       
   162         Start();
       
   163         }
       
   164     else if ( KErrInUse != err && 
       
   165               KErrServerTerminated != err && 
       
   166               KErrCancel != err )
       
   167         {
       
   168         Start();
       
   169         }
       
   170 
       
   171     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::RunL exiting" )
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CSatAllowRefreshMonitor::RunError
       
   176 // Handles refresh monitor error.
       
   177 // (other items were commented in a header).
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 TInt CSatAllowRefreshMonitor::RunError( TInt aError )
       
   181     {
       
   182     LOG2( SIMPLE,
       
   183           "SATCLIENT: CSatAllowRefreshMonitor::RunError calling, error: %i",
       
   184           aError )
       
   185 
       
   186     iRefresh.CancelNotifyAllowRefresh( aError );
       
   187 
       
   188     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::RunError exiting" )
       
   189     return KErrNone;
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CSatAllowRefreshMonitor::DoCancels
       
   194 // Cancels the notfication.
       
   195 // (other items were commented in a header).
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CSatAllowRefreshMonitor::DoCancel()
       
   199     {
       
   200     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::DoCancel calling" )
       
   201 
       
   202     iRefresh.CancelNotifyAllowRefresh();
       
   203 
       
   204     LOG( SIMPLE, "SATCLIENT: CSatAllowRefreshMonitor::DoCancel exiting" )
       
   205     }
       
   206 
       
   207 //  End of File