phoneengine/PhoneCntFinder/ContactService/inc/cphcntcontactmatchstrategy.h
author Pat Downey <patd@symbian.org>
Wed, 01 Sep 2010 12:30:10 +0100
branchRCL_3
changeset 62 5266b1f337bd
child 81 c26cc2a7c548
permissions -rw-r--r--
Revert incorrect RCL_3 drop: Revision: 201033 Kit: 201035

/*
* Copyright (c) 2006 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:  Contact matching strategy
*
*/


#ifndef CPHCNTCONTACTMATCHSTRATEGY_H
#define CPHCNTCONTACTMATCHSTRATEGY_H

#include <e32base.h>
#include <CVPbkPhoneNumberMatchStrategy.h>

#include "mphcntcontactmatchstrategy.h"
#include "mphcntcontactstoreeventobserver.h"

class CVPbkContactManager;
class MVPbkContactFindObserver;
class CVPbkPhoneNumberMatchStrategy;
class CVPbkContactStoreUriArray;
class CPhCntContactStoreUris;
class CCntRawPhoneNumberExtractor;

/**
 *  Strategy for matcing CS contacts.
 *
 *  @lib PhoneCntFinder.lib
 *  @since S60 v3.1
 */
NONSHARABLE_CLASS( CPhCntContactMatchStrategy ) :
    public CBase,
    public MPhCntContactMatchStrategy,
    private MPhCntContactStoreEventObserver
    {
public:

    /**
     * Static contstructor.
     *
     * @since S60 v3.1
     * @param aContactManager Contact manager.
     * @param aUriArray Array of contact store URI's used.
     * @param aObserver Observer for finding contacts.
     * @param aMatchFlags A bitset of flags for matching strategy. Has zero or
     * more CVPbkPhoneNumberMatchStrategy::TVPbkPhoneNumberMatchFlags flags set.
     */
    static CPhCntContactMatchStrategy* NewL(
        CVPbkContactManager& aContactManager,
        CPhCntContactStoreUris& aContactStoreUris,
        MVPbkContactFindObserver& aObserver,
        TUint32 aMatchFlags );

    /**
     * Destructor.
     *
     * @since S60 v3.1
     */
    virtual ~CPhCntContactMatchStrategy();

// from base class MPhCntContactMatchStrategy

    /**
     * From MPhCntContactMatchStrategy
     *
     * @since S60 v3.1
     * @see MPhCntContactMatchStrategy
     */
    void FindMatchesL( const TDesC& aPhoneNumber );

private:

    /**
     * Creates contact match strategy with given numbers
     * of digits.
     *
     * @since S60 v3.1
     * @return Error code.
     */
    TInt CreateContactMatchStrategy();

// From base class MCenRepNotifyHandlerCallback

    /**
     * From base class MCenRepNotifyHandlerCallback
     * This callback method is used to notify the client about
     * changes for string value keys, i.e. key type is EStringKey.
     *
     * @param aId Id of the key that has changed.
     * @param aNewValue The new value of the key.
     */
    void HandleNotifyString( TUint32 aId, const TDesC16& aNewValue );


// From base class MPhCntContactStoreEventObserver

    /**
     * From MPhCntContactStoreEventObserver
     *
     * @since S60 v3.2
     * @see MPhCntContactStoreEventObserver.
     */
    void ContactStoreAvailabilityChanged();

    /**
     * Method to ease unit testing. Creates the actual instance of iMatchStrategy.
     */
    virtual TInt DoCreateMatchStrategy();
    
    /**
     * Makes the actual matching request using number
     * Declared virtual to ease unit testing.
     */
    virtual void DoMatchL( const TDesC& aNumber );

protected:

    CPhCntContactMatchStrategy(
        CVPbkContactManager& aContactManager,
        CPhCntContactStoreUris& aContactStoreUris,
        MVPbkContactFindObserver& aObserver,
        TUint32 aMatchFlags );

    void ConstructL();

private: // data

    /**
     * Match strategy.
     * Own.
     */
    CVPbkPhoneNumberMatchStrategy* iMatchStrategy;

     /**
      * Contact manager is needed with match strategy.
      * Not own.
      */
    CVPbkContactManager& iContactManager;

    /**
     * Gives active contact store uris.
     * Not own.
     */
    CPhCntContactStoreUris& iContactStoreUris;

     /**
     * Observer of matching.
     * Now own.
     */
    MVPbkContactFindObserver& iObserver;

     /**
      * URI's of the active contact stores, where contacts are
      * looked from.
      * Own.
      */
    CVPbkContactStoreUriArray* iUriArray;

    /**
     * Number extractor.
     * Own.
     */
    CCntRawPhoneNumberExtractor* iNumberExtractor;

protected:  // data

    /**
     * A bitset of matching strategy flags. Changed from
     * CVPbkPhoneNumberMatchStrategy::TVPbkPhoneNumberMatchFlags enum to TUint32
     * in order to support multiple flags, as in
     * CVPbkPhoneNumberMatchStrategy::TConfig.
	 * 
	 * Protected because a unit test class derives from this class.
     */
    TUint32 iMatchFlags;

    };


#endif // CPHCNTCONTACTMATCHSTRATEGY_H