apengine/apeng/src/ActiveApDbNotifier.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 17 Dec 2009 08:55:21 +0200
changeset 0 5a93021fdf25
child 66 ed07dcc72692
permissions -rw-r--r--
Revision: 200949 Kit: 200951

/*
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Implementation of CActiveApDbNotifier.
*
*/


// INCLUDE FILES

#include "ActiveApDb.h"
#include "ActiveApDbNotifier.h"

// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CActiveApDbNotifier::CActiveApDbNotifier
// ---------------------------------------------------------
//
CActiveApDbNotifier::CActiveApDbNotifier( CActiveApDb& aDb )
: CActive( EPriorityStandard )
    {
    iActiveDb = &aDb;
    CActiveScheduler::Add( this );
    }

// ---------------------------------------------------------
// CActiveApDbNotifier::~CActiveApDbNotifier
// ---------------------------------------------------------
//
CActiveApDbNotifier::~CActiveApDbNotifier()
    {
    Cancel();
    }

// ---------------------------------------------------------
// CActiveApDbNotifier::RunL
// ---------------------------------------------------------
//
void CActiveApDbNotifier::RunL()
    {
    if ( iStatus == KErrCancel )
        {
        // Do nothing.
        }
    else
        {
        // first store status, because re-schedule will be earlier 
        // than notifying clients. Reason:
        // clients can leave but re-schedule MUST happen anyway,
        // to keep the notifier alive even if any client leaves
        TRequestStatus tempstatus( iStatus );

        if ( iStatus == RDbNotifier::EClose )
            {
            // Finish if the database is closed.
            NotifyChange();
            }
        else
            {
            // Reschedule automatically (as long as the database is open).
            NotifyChange();
            }
        // and now let clients handle their stuff...
        TRAP_IGNORE( iActiveDb->HandleDbEventL( tempstatus.Int() ) );
        }
    }


// ---------------------------------------------------------
// CActiveApDbNotifier::DoCancel
// ---------------------------------------------------------
//
void CActiveApDbNotifier::DoCancel()
    {
    Stop();
    }


// ---------------------------------------------------------
// CActiveApDbNotifier::Stop
// ---------------------------------------------------------
//
void CActiveApDbNotifier::Stop()
    {
    iActiveDb->Database()->CancelRequestNotification();
    }

// ---------------------------------------------------------
// CActiveApDbNotifier::Start
// ---------------------------------------------------------
//
void CActiveApDbNotifier::Start()
    {
    NotifyChange();
    }

// ---------------------------------------------------------
// CActiveApDbNotifier::NotifyChange
// ---------------------------------------------------------
//
void CActiveApDbNotifier::NotifyChange()
    {
    if ( !IsActive() )
        {
        iActiveDb->Database()->RequestNotification( iStatus );
        SetActive();
        }
    }

// End of File