mds_plat/harvester_framework_api/inc/harvesterclient.h
changeset 58 fe894bb075c2
parent 51 87e65c44ff3a
child 60 79f826a55db2
equal deleted inserted replaced
51:87e65c44ff3a 58:fe894bb075c2
     1 /*
       
     2 * Copyright (c) 2006-2009 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:  Harvester client header
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __HARVESTER_CLIENT_H__
       
    20 #define __HARVESTER_CLIENT_H__
       
    21 
       
    22 #include <e32base.h>
       
    23 
       
    24 #include <mdccommon.h>
       
    25 #include <mdeconstants.h>
       
    26 #include <harvestereventenum.h>
       
    27 
       
    28 // forward declarations
       
    29 class CHarvesterClientAO;
       
    30 class CHarvesterSessionAsyncHandler;
       
    31 class CHarvesterEventObserverAO;
       
    32 class MHarvesterEventObserver;
       
    33 class CHarvesterRequestActive;
       
    34 class CHarvesterRequestQueue;
       
    35 class MHarvesterSessionObserver;
       
    36 class CHarvesterSessionWatcher;
       
    37 
       
    38 // default event interval for MHarvesterEventObserver
       
    39 const TInt KHarvesterEventInterval = 20;
       
    40 
       
    41 /**
       
    42  * Observer interface to inform when fast harvesting is completed
       
    43  * with the HarvestingComplete callback.
       
    44  *
       
    45  * Example of MHarvestObserver and RHarvesterClient::HarvestFile usage:
       
    46  *
       
    47  * Client application (like Camera) which wants to observe the completion of 
       
    48  * harvesting requests (issued with RHarvesterClient::Harvestile method) needs
       
    49  * implement the interface MHarvestObserver::HarvestingComplete. Callback 
       
    50  * HarvestingComplete provides the name of the harvested file (aURI) and also possible 
       
    51  * error code (aError).
       
    52  *
       
    53  * class CHarvestingObserver : public MHarvestObserver
       
    54  *     {
       
    55  *     void HarvestingComplete( TDesC& aURI, TInt aError ); // from MHarvestObserver
       
    56  *     void IssueHarvestingRequests();
       
    57  * 
       
    58  *     RHarvesterClient iHClient;	
       
    59  *     }
       
    60  *
       
    61  * void CHarvestObserver::ConstructL()
       
    62  *     {
       
    63  *     // connecting to Harvester server
       
    64  *	   iHClient.Connect();
       
    65  *     }
       
    66  * 
       
    67  * void CHarvestObserver::IssueHarvestingRequests()
       
    68  *     {
       
    69  *     // new harvesting request data
       
    70  * 	   _LIT( KNewFile, "C:\\Data\\ThisIsANewFile1.jpg" );
       
    71  *     RArray<TItemId> defaultPhotoAlbums;
       
    72  *	   defaultPhotoAlbums.Append( 123 );
       
    73  *     defaultPhotoAlbums.Append( 456 );
       
    74  *     defaultPhotoAlbums.Append( 789 );
       
    75  *
       
    76  *     // setting this class as the observer for the fast harvesting calls
       
    77  *      iHClient.SetObserver(this);
       
    78  *        
       
    79  *     // issué new harvesting request and requesting location data to be harvested
       
    80  *     iHClient.HarvestFile( KNewFile, defaultPhotoAlbums, ETrue );   
       
    81  *     }
       
    82  *
       
    83  * void CHarvestObserver::HarvestingComplete( TDesC& aURI, TInt aError )
       
    84  *     {
       
    85  *     _LIT( KExpectedFile, "C:\\Data\\ThisIsANewFile1.jpg" );
       
    86  *
       
    87  *     // Checking if an error occurred and if this was the expected file
       
    88  *     if ((aError == KErrNone) && (aURI.CompareC(KExpectedFile) == 0))
       
    89  *         {
       
    90  *         // do something
       
    91  *         }
       
    92  *     }
       
    93  *
       
    94  */
       
    95 class MHarvestObserver
       
    96 	{
       
    97 public:
       
    98     /**
       
    99      * Callback to inform when fast harvesting of a file is complete.
       
   100      * 
       
   101      * @param aURI    URI of the harvested file.
       
   102      * @param aError  Error code of the fast harvesting. <code>KErrNone</code> is
       
   103      *                expected if fast harvesting succeeded. Otherwise some
       
   104      *                system wide error code. 
       
   105      *
       
   106      */
       
   107 	virtual void HarvestingComplete( TDesC& aURI, TInt aError ) = 0;
       
   108 	};
       
   109 
       
   110 /**
       
   111  * Observer interface to inform about events that happen inside the observer framework
       
   112  *
       
   113  * Example of MHarvesterEventObserver, RHarvesterClient::AddHarvesterEventObserver and
       
   114  * RHarvesterClient::RemoveHarvesterEventObserver usage:
       
   115  *
       
   116  * void CHarvestObserver::ConstructL()
       
   117  *     {
       
   118  *     // iHClient is instance of RHarvesterClient
       
   119  *	   iHClient.Connect();
       
   120  *
       
   121  *     // Listen to placeholder changes to "full" metadata objects - request notification
       
   122  *     // after 100 items have changed.
       
   123  *     TInt err = iHClient.AddHarvesterEventObserver( *this, EHEObserverTypePlaceholder, 100 );
       
   124  *     if (err == KErrNone)
       
   125  *         {
       
   126  *         // do something now that event observer is setup
       
   127  *         }
       
   128  *     }
       
   129  *
       
   130  * void CHarvestObserver::HarvestingUpdated( HarvesterEventObserverType aHEObserverType, 
       
   131  *			HarvesterEventState aHarvesterEventState, TInt aItemsLeft )
       
   132  *     {
       
   133  *     // Check the observer notification type
       
   134  *     if (aHEObserverType == EHEObserverTypePlaceholder)
       
   135  *         {
       
   136  *         // Checking if there are more than 1000 items left to process 
       
   137  *         if (aItemsLeft > 1000)
       
   138  *             {
       
   139  *             // do something since there are some many items still placeholders
       
   140  *             }
       
   141  *         if (aItemsLeft == 0)
       
   142  *             {
       
   143 	           // all placeholders changed to "full" objects - do something...
       
   144  *             }
       
   145  *         }   
       
   146  *     }
       
   147  *
       
   148  * CHarvestObserver::~CHarvestObserver()
       
   149  *     {
       
   150  *     // Removing the observer in destructor
       
   151  *     iHClient.RemoveHarvesterEventObserver( *this );   
       
   152  *     }
       
   153  */
       
   154 
       
   155 
       
   156 class MHarvesterEventObserver
       
   157 	{
       
   158 public:
       
   159     /**
       
   160      * Callback interface which informs about harvesting changes based on the observers
       
   161      * that the end user has setup/registered.
       
   162      * 
       
   163      * @param aHEObserverType       Defines the observer type to which this events is related 
       
   164      * @param aHarvesterEventState  Event that occurred
       
   165      * @param aItemsLeft            Number of items left regarding the harvesting procedure (defined
       
   166      *                              by aHEObserverType)
       
   167      * @see RHarvesterClient::AddHarvesterEventObserver
       
   168      * @see RHarvesterClient::RemoveHarvesterEventObserver
       
   169      */
       
   170 	virtual void HarvestingUpdated( 
       
   171 			HarvesterEventObserverType aHEObserverType, 
       
   172 			HarvesterEventState aHarvesterEventState,
       
   173 			TInt aItemsLeft ) = 0;
       
   174 	};
       
   175 
       
   176 class MHarvesterSessionObserver
       
   177     {
       
   178 public:
       
   179 
       
   180     /**
       
   181      * Called to notify the observer that harvester server has been terminated,
       
   182      * thus harvester server sessions created are now invalid and new connection
       
   183      * needs to be established
       
   184      * NOTE! Cliens still have to call Close() on the session to release client side
       
   185      * resources.
       
   186      */
       
   187     virtual void HarvesterServerTerminated() = 0;
       
   188     };
       
   189 
       
   190 /**
       
   191  * Harvester client session class which provides also means to:
       
   192  * - Pause/resume the Harvesting framework
       
   193  * - Fast harvest files and observe when they have been harvested
       
   194  * - Setup observers to observe the harvesting progress
       
   195  */
       
   196 NONSHARABLE_CLASS( RHarvesterClient ) : public RSessionBase
       
   197 	{
       
   198 	friend class CHarvesterSessionAsyncHandler;
       
   199 	friend class CHarvesterEventObserverAO;
       
   200 
       
   201 	public:
       
   202 		
       
   203         /**
       
   204          * Constructor
       
   205          */
       
   206         IMPORT_C RHarvesterClient();
       
   207 
       
   208         /**
       
   209          * Public method to connect Harvester server.
       
   210          * 
       
   211          * @return Symbian OS error code.
       
   212          */
       
   213         IMPORT_C TInt Connect();
       
   214          
       
   215         /**
       
   216          * Public method to pause the operation
       
   217          * of the Harvester framework.
       
   218          *
       
   219          * @return  Symbian OS error code.
       
   220          */
       
   221         IMPORT_C TInt Pause();
       
   222 
       
   223         /**
       
   224          * Public method to resume the operation
       
   225          * of the Harvester framework.
       
   226          *
       
   227          * @return  Symbian OS error code.
       
   228          */    
       
   229         IMPORT_C TInt Resume();
       
   230 
       
   231         /**
       
   232          * Public method to close session to Harvester server.
       
   233          */
       
   234         IMPORT_C void Close();
       
   235             
       
   236         /**
       
   237          * Public method to set observer for fast harvesting.
       
   238          * Only one observer is currently supported.
       
   239          *
       
   240          * @param aObserver  Pointer to the observer
       
   241          */     
       
   242         IMPORT_C void SetObserver( MHarvestObserver* aObserver);
       
   243 
       
   244         /**
       
   245          * Public method to remove observer for fast harvesting.
       
   246          *
       
   247          * @param aObserver  Pointer to the observer
       
   248          */     
       
   249         IMPORT_C void RemoveObserver( MHarvestObserver* aObserver);
       
   250         
       
   251         /**
       
   252          * Public method for doing fast harvesting. These files
       
   253          * are handled first before the ones that are in the harvesting 
       
   254          * queue inside the Harvesting framework.
       
   255          *
       
   256          * @param aURI          Uri of the file to be harvested
       
   257          * @param aAlbumIds     Array of album id's that the harvested file 
       
   258          *                      will be included in
       
   259          * @param aAddLocation  Should location information be added to item
       
   260          */ 
       
   261     	IMPORT_C void HarvestFile( const TDesC& aURI, RArray<TItemId> &aAlbumIds, TBool aAddLocation );
       
   262         
       
   263         /**
       
   264          * Method for adding observer for harvester framework events
       
   265          *
       
   266          * @param aHarvesterEventObserver  class to implement MHarvesterEventObserver interface
       
   267          * @param aHEObserverType          Harvester event observer type (EPlaceholderState, 
       
   268          *                                 EMMCState, EOverallState)
       
   269          * @param aEventInterval           Interval of harvester events as item amount
       
   270          * 
       
   271          * @return  Symbian OS wide error code.
       
   272          */
       
   273         IMPORT_C TInt AddHarvesterEventObserver( 
       
   274         		MHarvesterEventObserver& aHarvesterEventObserver, 
       
   275         		TInt aHEObserverType,
       
   276         		TInt aEventInterval = KHarvesterEventInterval );
       
   277         
       
   278         /**
       
   279          * Method for removing observer for harvester framework events. Please note that
       
   280          * removing any of the event observers will remove all observers which are registered
       
   281          * by the given parameter aHarvesterEventObserver (= observer class).
       
   282          *
       
   283          * @param aHarvesterEventObserver class to implement MHarvesterEventObserver interface
       
   284          *
       
   285          * @return  Symbian OS wide error code.
       
   286          */
       
   287         IMPORT_C TInt RemoveHarvesterEventObserver( MHarvesterEventObserver& aHarvesterEventObserver );
       
   288         
       
   289 		/**
       
   290          * Public method for doing fast harvesting. These files
       
   291          * are handled first before the ones that are in the harvesting 
       
   292          * queue. 
       
   293          *
       
   294          * @param aURI          Uri of the file to be harvested
       
   295          * @param aAlbumIds     Array of album id's that the harvested file will be included in
       
   296          * @param aAddLocation  Should location information be added to image
       
   297 		 * @param aUid          Uid of the originating application for the object
       
   298          */ 
       
   299     	IMPORT_C void HarvestFileWithUID( const TDesC& aURI, 
       
   300 		                                  RArray<TItemId> &aAlbumIds, 
       
   301 										  TBool aAddLocation,
       
   302 										  TUid aUid );
       
   303 
       
   304         /**
       
   305          * Public method to set observer for notifications about harvester server termination.
       
   306          * Only one observer at a time is currently supported.
       
   307          *
       
   308          * @param aObserver  Pointer to the observer
       
   309          */     
       
   310     	IMPORT_C void AddSessionObserverL( MHarvesterSessionObserver& aObserver  );
       
   311 
       
   312         /**
       
   313          * Public method to remove harvester session observer
       
   314          */     
       
   315         IMPORT_C void RemoveSessionObserver();
       
   316     	
       
   317         /**
       
   318          * Requests a harvest complete event from harvester server.
       
   319 		 * On return, aURI is the URI of the harvested file.
       
   320          *
       
   321          * @param aURI  Harvested image uri what server
       
   322          * @param aStatus    Reference to a request indicator
       
   323          */ 
       
   324         void RegisterHarvestComplete( TDes& aURI, TRequestStatus& aStatus );
       
   325         
       
   326         /**
       
   327          * Cancels the harvest complete notification request.
       
   328          */ 
       
   329         void UnregisterHarvestComplete( );
       
   330         
       
   331         /**
       
   332          * Private method for doing fast harvesting. These files
       
   333          * are handled first before the ones that are in the harvesting 
       
   334          * queue.
       
   335          * 
       
   336          * @param aService  Service request which to execute on server side
       
   337          * @param aArgs     Parameters for harvesting
       
   338          * @param aStatus   Status of the asunchronous call
       
   339          */ 
       
   340         void HarvestFile( TInt& aService, TIpcArgs& aArgs, TRequestStatus& aStatus  );
       
   341 
       
   342         /**
       
   343          * Restricted method for doing fast harvesting. These files
       
   344          * are handled first before the ones that are in the harvesting 
       
   345          * queue. This version forces the file to be harvested immidiately.
       
   346          * 
       
   347          * @param aService  Service request which to execute on server side
       
   348          * @param aArgs     Parameters for harvesting
       
   349          */ 
       
   350         void ForceHarvestFile( TInt& aService, TIpcArgs& aArgs );
       
   351         
       
   352 	private: 
       
   353 
       
   354 	    /**
       
   355 	     * Observer of the class
       
   356 	     */ 
       
   357 	     MHarvestObserver* iObserver;
       
   358 	
       
   359         /**
       
   360          * Private method for version.
       
   361          */      
       
   362         TVersion Version() const;
       
   363 
       
   364         /**
       
   365          * Harvester client active object.
       
   366          */    
       
   367         CHarvesterClientAO* iHarvesterClientAO;
       
   368         
       
   369         /** 
       
   370          * Pointer to Harvester event observer active object.
       
   371          */
       
   372         CHarvesterEventObserverAO* iHEO;
       
   373         
       
   374         /**
       
   375          * Request queue processor.
       
   376          */
       
   377         CHarvesterRequestQueue* iRequestQueue;
       
   378         
       
   379         /**
       
   380          * Harvester session observer AO.
       
   381          */
       
   382         CHarvesterSessionWatcher* iSessionWatcher;
       
   383     	};
       
   384 
       
   385 #endif // __HARVESTER_CLIENT_H__