apengine/apeng/src/ActiveApDbNotifier.cpp
changeset 61 8b0c979bbe8c
parent 59 2709c04a4af5
child 70 ac5daea24fb0
equal deleted inserted replaced
59:2709c04a4af5 61:8b0c979bbe8c
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of CActiveApDbNotifier.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "ActiveApDb.h"
       
    22 #include "ActiveApDbNotifier.h"
       
    23 
       
    24 // ================= MEMBER FUNCTIONS =======================
       
    25 
       
    26 // ---------------------------------------------------------
       
    27 // CActiveApDbNotifier::CActiveApDbNotifier
       
    28 // ---------------------------------------------------------
       
    29 //
       
    30 CActiveApDbNotifier::CActiveApDbNotifier( CActiveApDb& aDb )
       
    31 : CActive( EPriorityStandard )
       
    32     {
       
    33     iActiveDb = &aDb;
       
    34     CActiveScheduler::Add( this );
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // CActiveApDbNotifier::~CActiveApDbNotifier
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 CActiveApDbNotifier::~CActiveApDbNotifier()
       
    42     {
       
    43     Cancel();
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CActiveApDbNotifier::RunL
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 void CActiveApDbNotifier::RunL()
       
    51     {
       
    52     if ( iStatus == KErrCancel )
       
    53         {
       
    54         // Do nothing.
       
    55         }
       
    56     else
       
    57         {
       
    58         // first store status, because re-schedule will be earlier 
       
    59         // than notifying clients. Reason:
       
    60         // clients can leave but re-schedule MUST happen anyway,
       
    61         // to keep the notifier alive even if any client leaves
       
    62         TRequestStatus tempstatus( iStatus );
       
    63 
       
    64         if ( iStatus == RDbNotifier::EClose )
       
    65             {
       
    66             // Finish if the database is closed.
       
    67             NotifyChange();
       
    68             }
       
    69         else
       
    70             {
       
    71             // Reschedule automatically (as long as the database is open).
       
    72             NotifyChange();
       
    73             }
       
    74         // and now let clients handle their stuff...
       
    75         TRAP_IGNORE( iActiveDb->HandleDbEventL( tempstatus.Int() ) );
       
    76         }
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CActiveApDbNotifier::DoCancel
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 void CActiveApDbNotifier::DoCancel()
       
    85     {
       
    86     Stop();
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CActiveApDbNotifier::Stop
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 void CActiveApDbNotifier::Stop()
       
    95     {
       
    96     iActiveDb->Database()->CancelRequestNotification();
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // CActiveApDbNotifier::Start
       
   101 // ---------------------------------------------------------
       
   102 //
       
   103 void CActiveApDbNotifier::Start()
       
   104     {
       
   105     NotifyChange();
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // CActiveApDbNotifier::NotifyChange
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 void CActiveApDbNotifier::NotifyChange()
       
   113     {
       
   114     if ( !IsActive() )
       
   115         {
       
   116         iActiveDb->Database()->RequestNotification( iStatus );
       
   117         SetActive();
       
   118         }
       
   119     }
       
   120 
       
   121 // End of File