diff -r 0efa10d348c0 -r a5a39a295112 contentpublishingsrv/contentpublishingserver/cpserver/inc/cpserverdatamanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contentpublishingsrv/contentpublishingserver/cpserver/inc/cpserverdatamanager.h Wed Sep 01 12:22:09 2010 +0100 @@ -0,0 +1,297 @@ +/* +* 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 +#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 iNotificationsArray; + + /* + * Action data cache + * Own. + */ + CCPActionDataCache* iActionDataCache; + +#ifdef CONTENT_PUBLISHER_DEBUG + CCPDebug* iDebug; +#endif + }; + +#endif // C_CPDATA_MANAGER_H +// end of file