contentpublishingsrv/contentpublishingserver/cpserver/inc/cpserverdatamanager.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 11 May 2010 16:30:05 +0300
branchRCL_3
changeset 19 edd621764147
parent 14 15e4dd19031c
permissions -rw-r--r--
Revision: 201017 Kit: 201019

/*
* Copyright (c) 2008 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:  Used by sessions for handling data related requests
 *
*/


#ifndef C_CPDATA_MANAGER_H
#define C_CPDATA_MANAGER_H

#include <e32base.h>
#include "cpstorage.h"
#include "cpactiondatacache.h"

// FORWARD DECLARATIONS
#ifdef CONTENT_PUBLISHER_DEBUG
class CCPDebug;
#endif
class CLiwMap;
class CCPLiwMap;
class CCpStorage;
class CCPServerSession;
class CCPNotificationHandler;
class TLiwVariant;

/**
 *  Content publisher data manager.
 *
 *  Used to add, modify and remove data and actions.
 *  @since S60 v5.0
 */
class CCPDataManager : public CBase, MCPChangeNotifier
    {
public:
    // exported

    /**
     * C++ destructor
     */
    ~CCPDataManager();

    /**
     * Two-phased constructor.
     */
    static CCPDataManager* NewL(TLiwVariant& aDataMapCache, TBool aTBool =
            EFalse);

    /**
     * Two-phased constructor.
     */
    static CCPDataManager* NewLC(TLiwVariant& aDataMapCache, TBool aTBool =
            EFalse);

    /**
     * Add a new data to database
     *
     * @param aData Data to be added.
     * @return Id of a newly created data item
     */
    TUint AddDataL( CCPLiwMap& aMap );

    /**
     * Data is not added to database. Only notification is send to observers.
     *
     * @param aData Data to be added.
     * @return Id of a newly created data item
     */
    void AddNonPersistentDataL( const CCPLiwMap* aMap );

    /**
     * Fetches data from database
     * @param aInParamList filter and sorting criteria
     * @param aOutParamList results
     */
    void GetListL( const CCPLiwMap& aMa, CLiwGenericParamList& aOutParamList );
    /**
     * Fetches action from database
     * @param aInParamList filter and sorting criteria
     * @param aEnableCache flag indicating if action data should be cached
     * @param aOutParamList results
     * @param aNotificationList change info list (for notifications)
     * @return KErrNotFound if data was not found
     */
    TInt GetActionsL( const CCPLiwMap& aMap,
        TBool aEnableCache,
        CLiwGenericParamList& aOutParamList,
        CLiwDefaultList* aNotificationList = NULL );

    /**
     * Fetches all activated publishers 
     * @param aInParamList filter and sorting criteria
     * @param aOutParamList results
     */
    void GetActivePublishersL( CLiwGenericParamList* aResultList );

    /**
     * Removes data from database
     * @param aInParamList filter criteria
     */
    void RemoveDataL( const CCPLiwMap& aMa );

    /**
     * Adds observer to database
     * @param new observer
     */
    void AddObserverL( CCPNotificationHandler* aNotificationHandler );

    /**
     * Removes observer from database
     * @param aNotificationHandler observer to remove
     */
    void RemoveObserver( CCPNotificationHandler* aNotificationHandler );

    // from MCPChangeNotifier
    /**
     * @param Map containing change information
     * @return 
     */
    void HandleChangeL( CLiwDefaultList* aListOfMaps );

    /**
     * Close database 
     * @return 
     */
    void CloseDatabase();
    /**
     * Open database 
     * @return 
     */
    void OpenDatabaseL(TLiwVariant& aDataMapCache);

private:
    // methods

    /**
     * Standard C++ constructor.
     */
    CCPDataManager();

    /**
     * Standard 2nd phase constructor.
     */
    void ConstructL( TLiwVariant& aDataMapCache, TBool aTBool );

    /**
     * Fetches action bound to provided trigger.
     *
     * @param aOutParamList of all actions
     * @param aMap for found action
     * @param aTrigger
     */
    void ExtractTriggerL( CLiwGenericParamList& aOutParamList,
        const CLiwDefaultMap* aMap, const TDesC8& aTrigger );
    /**
     * Sends notifications to observers stored in iNotificationsArray
     *
     * @param List of change information
     * @param index od data item
     */
    void SendNotificationL( CLiwDefaultList* aListOfMaps, TInt aIndex );

    /**
     * Exctracts action from input parameters
     *
     * @param aParam for data
     * @param aAction for action
     */
    void ExtractActionL( const TLiwGenericParam* aParam, RBuf8& aAction );
    
    /**
     * Fills aOutParamList with parameters for action.
     *
     * @param aOutParamList parsed list of items
     * @param aActionMap action map from the database
     * @param aActionTrigger action trigger
     */
    void FillActionParamListL(
    		CLiwGenericParamList & aOutParamList, 
            const CLiwDefaultMap* aActionMap,
    		const CLiwDefaultList* aActionTriggers);

     /**
     * Creates map for GetList request - publisher, content_type
     * and content_id are copied from aMap to returned map
     * @param aMap - input map
     * @return input map for GetList request
     */
    CCPLiwMap* CreateMapForGetlistLC( const CCPLiwMap& aMap );


     /**
     * Gets Flag for specified item from DB and returns activate
     * info
     * @param aMap - input map
     * @return activate flag
     */
    TBool GetActivateInfoL( const CCPLiwMap* aMap );
    
    /**
    * Builds change info list based on query result to database
    * @param aMap - map containing parameters needed to build change info list
    * @param aParam - param from getlist result     
    * @param aActionMap - action map from a database 
    * @param aChangeInfoList - output list containing change info list sent
    * as notification
    */
    void BuildChangeInfoL( 
    		const CCPLiwMap* aMap, 
    		const CLiwDefaultList* aActionTriggers,
    		const TLiwGenericParam* aParam,	
    		const CLiwDefaultMap* aActionMap,
    		CLiwDefaultList* aChangeInfoList );
  
    /**
    * Builds change info list when query to database returned nothing
    * @param aMap - map containing parameters needed to build change info list
    * @param aChangeInfoList - output list containing change info list sent
    * as notification
    */
    void BuildDefaultChangeInfoL( 
    		const CCPLiwMap* aMap, 
    		const CLiwDefaultList* aActionTriggers,
    		CLiwDefaultList* aChangeInfoList );
    /**
    * Builds change info list when query to database returned nothing
    * @param aMap - map containing parameters needed to build change info list
    * @param aChangeInfoList - output list containing change info list sent
    * as notification
    */
    void BuildChangeInfoForAddL(
            const CCPLiwMap* aMap,
            CLiwDefaultList* aChangeInfoList );

    /**
    * Copies variant from in to out map if entry with provided key exists
    * @param aKey a key
    * @param aInMap input map
    * @param aOutMap output map
    */    
    void CopyVariantL(const TDesC8& aKey, const CLiwMap* aInMap, 
    		CLiwDefaultMap* aOutMap );

    /**
    * Copies variant from in map for key KActionTrigger to out map with key KActionTrigger16 
    * and formated type(from TDesC8 to TDesC) 
    * @param aInMap input map
    * @param aOutMap output map
    */    
    void CopyActionTrigger16L( const CLiwMap* aInMap, 
    		CLiwDefaultMap* aOutMap );

    /**
    * Converts variant type from TDesC8 to TDesC
    * @param aVariant variant to convert
    */     
    void CopyActionTrigger16L( const TLiwVariant& aVariant, 
            CLiwDefaultMap* aOutMap );

private:
    // data

    /*
     * Storage database
     * Own.
     */
    CCpStorage* iStorage;

    /*
     * Array of registered notification handlers.
     * Own.
     */
    RPointerArray<CCPNotificationHandler> iNotificationsArray;

    /*
     * Action data cache
     * Own.
     */
    CCPActionDataCache* iActionDataCache;
    
#ifdef CONTENT_PUBLISHER_DEBUG
    CCPDebug* iDebug;
#endif
    };

#endif // C_CPDATA_MANAGER_H
// end of file