camerauis/cameraapp/generic/src/CamObserverHandler.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 14 Sep 2010 20:46:07 +0300
branchRCL_3
changeset 57 2c87b2808fd7
parent 0 1ddebce53859
child 67 756ad29ed18e
permissions -rw-r--r--
Revision: 201033 Kit: 201035

/*
* Copyright (c) 2007-2010 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:  Generic handler to be used by Observables
*
*/



// INCLUDE FILES
#include "CamObservable.h"
#include "CamObserver.h"
#include "CamObserverHandler.h"
#include "camlogging.h"

// ---------------------------------------------------------
// CCamObserverHandler::CCamObserverHandler
// C++ constructor
// ---------------------------------------------------------
//
CCamObserverHandler::CCamObserverHandler()
    {
    }
    
// ---------------------------------------------------------
// CCamObserverHandler::~CCamObserverHandler
// C++ Destructor
// ---------------------------------------------------------
//
CCamObserverHandler::~CCamObserverHandler()
  {
  PRINT( _L("Camera => ~CCamObserverHandler") );
  iObservers.Reset();
  PRINT( _L("Camera <= ~CCamObserverHandler") );
  }
    
// ---------------------------------------------------------
// CCamObserverHandler::NewL
// Symbian 2-phase constructor
// ---------------------------------------------------------
//
CCamObserverHandler* CCamObserverHandler::NewL()
    {
    CCamObserverHandler* self = new( ELeave ) CCamObserverHandler();
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop( self );
    return self;
    }
    
// ---------------------------------------------------------
// CCamObserverHandler::ConstructL
// Second phase constructor
// ---------------------------------------------------------
//
void CCamObserverHandler::ConstructL()
    {
    }

// ---------------------------------------------------------
// CCamObserverHandler::RegisterObserverL
// Registers observer if not previously registered
// ---------------------------------------------------------
//
void CCamObserverHandler::RegisterObserverL(MCamObserver* aObserver)
    {
    if ( aObserver )
        {
        if ( KErrNotFound == iObservers.Find( aObserver ))
            {
            User::LeaveIfError(iObservers.Append(aObserver));
            }
        }
    }
    
// ---------------------------------------------------------
// CCamObserverHandler::DeregisterObserver
// Removes observer
// ---------------------------------------------------------
//
void CCamObserverHandler::DeregisterObserver(MCamObserver* aObserver)
    {
    if ( aObserver )
        {
        TInt index = iObservers.Find( aObserver );
        if ( KErrNotFound != index )
            {
            iObservers.Remove(index);
            }
        }
    }
    
// ---------------------------------------------------------
// CCamObserverHandler::BroadcastEvent
// Broadcasts an event code to all observers
// ---------------------------------------------------------
//
void CCamObserverHandler::BroadcastEvent( TCamObserverEvent aEvent )
    {
    TInt count = iObservers.Count();
    TInt i;
    for ( i = 0; i < count; i++ )
        {
        // Checked to be non-NULL when added to array.
        iObservers[i]->HandleObservedEvent( aEvent );
        }
    }
    
// End of File