photosgallery/collectionframework/datasource/manager/inc/glxdatasource.h
changeset 0 4e91876724a2
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    data source header file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef _C_GLXDATASOURCE_H_
       
    22 #define _C_GLXDATASOURCE_H_
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32base.h>
       
    26 #include <e32cmn.h>
       
    27 #include <mpxattribute.h>
       
    28 #include <mpxcollectionpath.h>
       
    29 
       
    30 #include <ecom/ecom.h>
       
    31 #include "mglxdatasource.h"
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 class CGlxRequest;
       
    35 class CGlxDataSourceTask;
       
    36 class CGlxDataSource;
       
    37 // CONSTANTS
       
    38 
       
    39 // CLASS DECLARATION
       
    40 
       
    41 /**
       
    42  * CDataSourceArrayOwner
       
    43  * A singleton that owns a pointer array of datasources
       
    44  */
       
    45 NONSHARABLE_CLASS(CDataSourceArrayOwner) : public CBase
       
    46     {
       
    47 public:
       
    48 	/**
       
    49 	 * Returns the CDataSourceArrayOwner singleton
       
    50 	 * @return the CDataSourceArrayOwner singleton
       
    51 	 */
       
    52     static CDataSourceArrayOwner* InstanceL();
       
    53     
       
    54     /**
       
    55      * Closes the singleton
       
    56      */
       
    57     void Close();
       
    58   
       
    59     /**
       
    60      * Retuns a reference to the array owned by this object
       
    61      * @return a reference to the array owned by this object
       
    62      */
       
    63     RPointerArray<CGlxDataSource>& Array();
       
    64     
       
    65 private:
       
    66 	/**
       
    67 	 * Constructor (private so that only
       
    68 	 * the singleton store can use it)
       
    69 	 */
       
    70     static CDataSourceArrayOwner* NewL();    
       
    71     /**
       
    72      * Destructor
       
    73      */
       
    74     ~CDataSourceArrayOwner();
       
    75     
       
    76 private:
       
    77       /**
       
    78        * Array of datasource
       
    79        * (owned)
       
    80        * (array contents not owned)
       
    81        */
       
    82       RPointerArray<CGlxDataSource> iDataSources;
       
    83       };
       
    84       
       
    85 /**
       
    86  *  CGlxDataSource class 
       
    87  *
       
    88  *  Data Source is the Data Source base class.
       
    89  *	@ingroup collection_component_design
       
    90  *  @internal reviewed 11/07/2007 by Dave Schofield
       
    91  */
       
    92 class CGlxDataSource : public CActive,
       
    93 					   public MGlxDataSource
       
    94 	{
       
    95 	
       
    96 public:
       
    97 	IMPORT_C CGlxDataSource();
       
    98     IMPORT_C virtual ~CGlxDataSource();
       
    99 	
       
   100 public: // from MGlxDataSource
       
   101 	/**
       
   102 	 * Asynchronous call to retrieve 
       
   103 	 * 
       
   104 	 * @param aListId list for this query relates to
       
   105 	 * @return error code
       
   106 	 */
       
   107 	IMPORT_C void DataSourceRequestL(CGlxRequest* aRequest, MGlxDataSourceRequestObserver& aObserver);
       
   108 	/**
       
   109 	 * Cancel asynchronous request call
       
   110 	 * as each requestor can only have one active request the observer is sufficient to cancel the request.
       
   111 	 * 
       
   112 	 */
       
   113 	IMPORT_C void CancelRequest(MGlxDataSourceRequestObserver& aObserver);
       
   114 	/**
       
   115 	 * Decrements the reference count of the data source. Deletes the 
       
   116 	 * data source if there are no more references.
       
   117 	 */
       
   118 	IMPORT_C void Close(MGlxDataSourceUpdateObserver& aObserver);
       
   119 
       
   120 
       
   121 public:
       
   122     IMPORT_C void HandleTaskComplete(CGlxDataSourceTask* aRequest);
       
   123 
       
   124 public:
       
   125 	inline const TUid& Uid() const
       
   126 		{
       
   127 		return iUid;
       
   128 		};
       
   129 	inline void SetUid(const TUid& aUid)
       
   130 		{
       
   131 		iUid = aUid;
       
   132 		};
       
   133 	inline const TInt Count() 
       
   134 		{
       
   135 		return iDataSourceObservers.Count();
       
   136 		};
       
   137 	inline void SetDtorKey(const TUid& aDtorKey)
       
   138 		{
       
   139 		iDtorKey = aDtorKey;
       
   140 		};
       
   141 	inline void SetEComSession(REComSession& aEComSession)
       
   142 		{
       
   143 		iEComSession = aEComSession;
       
   144 		};
       
   145 	
       
   146 	/**
       
   147 	 * Set the datasource array owner
       
   148 	 * Should be called after object construction
       
   149 	 * @param aDataSourceArrayOwner the datasource array owner
       
   150 	 */
       
   151 	inline void SetDataSourceArrayOwner(CDataSourceArrayOwner* aDataSourceArrayOwner)
       
   152 		{
       
   153 		iDataSourceArrayOwner = aDataSourceArrayOwner;
       
   154 		};
       
   155 		
       
   156 public:
       
   157 	void AddObserverL(MGlxDataSourceUpdateObserver& aObserver);
       
   158 
       
   159 public: // from CActive
       
   160     IMPORT_C void RunL();
       
   161     IMPORT_C void DoCancel();
       
   162     IMPORT_C TInt RunError(TInt aError);
       
   163 
       
   164 public:
       
   165 	enum TItemType
       
   166 		{
       
   167 		EItemTypeNotAnItem = 0,
       
   168 		EItemTypeImage,
       
   169 		EItemTypeVideo
       
   170 		};
       
   171 		
       
   172 	enum TContainerType
       
   173 		{
       
   174 		EContainerTypeNotAContainer = 0,
       
   175 		EContainerTypeAlbum,
       
   176 		EContainerTypeTag,
       
   177 		EContainerTypeMonth
       
   178 		};
       
   179 		
       
   180 private:
       
   181     enum TAction
       
   182     {
       
   183         EExecuteOnly = 1,
       
   184         ECleanupAndExecute
       
   185     };
       
   186     
       
   187 private:
       
   188 	virtual CGlxDataSourceTask* CreateTaskL(CGlxRequest* aRequest, MGlxDataSourceRequestObserver& aObserver) = 0;
       
   189 	
       
   190 	void CompleteSelf(TAction aAction);
       
   191 	
       
   192 	virtual void TaskStartedL() = 0;
       
   193 	virtual void TaskCompletedL()= 0;
       
   194 	
       
   195 protected:
       
   196 	IMPORT_C void BroadcastMessage(CMPXMessage& aMessage);
       
   197 	IMPORT_C void TryStartTask(TBool aFirstStart = EFalse);
       
   198 	
       
   199 protected:
       
   200 	RPointerArray< MGlxDataSourceUpdateObserver > iDataSourceObservers;
       
   201 	RPointerArray< CGlxDataSourceTask > iTasks;
       
   202 	TInt iDataSourceId; // session specific id count from DSM, used to mask the item ids.
       
   203 	TInt iCount;
       
   204 	TUid iUid;
       
   205 	TUid iDtorKey;
       
   206 	REComSession iEComSession;
       
   207 	TBool iDataSourceReady;
       
   208 
       
   209 	/**
       
   210 	 * Singleton, reference counted
       
   211 	 * Close() should be called when in order
       
   212 	 * when object is no longer required.
       
   213 	 */
       
   214 	CDataSourceArrayOwner* iDataSourceArrayOwner;
       
   215 	};
       
   216 
       
   217 
       
   218 
       
   219 
       
   220 #endif //_C_GLXDATASOURCE_H_