mmappcomponents/mmmtpdataprovider/tsrc/mtpdataprovidertestmodule/inc/ctestobserver.h
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 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:  Test observer to act as dummy mtp framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CTESTOBSERVER_H
       
    20 #define CTESTOBSERVER_H
       
    21 
       
    22 #include <stiflogger.h>
       
    23 #include <mtp/mmtpdataproviderframework.h> 
       
    24 #include <mtp/mmtpdataproviderconfig.h>
       
    25 #include <mtp/tmtptyperesponse.h>
       
    26 #include <f32file.h>
       
    27 #include <mpxmedia.h>
       
    28 #include <mpxharvesterutilityobserver.h>
       
    29 #include "ctestobjectmanager.h"
       
    30 #include "cteststoragemgr.h"
       
    31 
       
    32 #if defined(_UNICODE)
       
    33 #define CASTING(a) ((TText)L ## a)
       
    34 #else
       
    35 #define CASTING(a) ((TText)(a))
       
    36 #endif
       
    37 
       
    38 class CMmMtpDataProviderTestModule;
       
    39 
       
    40 class CTestObserver : public MMTPDataProviderFramework, public MMTPDataProviderConfig,
       
    41         public MMPXHarvesterUtilityObserver, public CBase
       
    42     {
       
    43 public:
       
    44     enum TAsyncOperation
       
    45         {
       
    46         EIdleOperation,
       
    47         EStorageEnumeration,
       
    48         EObjectEnumeration,
       
    49         EHarvesterAddObject,
       
    50         EHarvesterDeleteObject,
       
    51         EHarvesterImportAbstractMedia,
       
    52         ECopyObject,
       
    53         EMoveObject,
       
    54         EDeleteObject,
       
    55         EGetObjectPropList,
       
    56         ESetObjectPropList
       
    57         };
       
    58     
       
    59     /**
       
    60        * C++ default constructor.
       
    61        */
       
    62     CTestObserver( CMmMtpDataProviderTestModule* aTestModule );
       
    63     
       
    64     /**
       
    65         * Destructor.
       
    66         */
       
    67         ~CTestObserver();
       
    68         
       
    69      static CTestObserver* NewL( CMmMtpDataProviderTestModule* aTestModule );
       
    70      static CTestObserver* NewLC( CMmMtpDataProviderTestModule* aTestModule );   
       
    71         
       
    72         
       
    73   // from MMTPDataProviderFramework
       
    74    
       
    75     /**
       
    76      Provides the unique identifier of the calling data provider.
       
    77      @return The data provider identifier.
       
    78      */
       
    79      TUint DataProviderId() const;
       
    80 
       
    81      /**
       
    82      Provides the current MTP operational mode.
       
    83      @return The current MTP operational mode.
       
    84      */
       
    85      TMTPOperationalMode Mode() const;
       
    86    
       
    87     /**
       
    88     Initiates a data object receive sequence in the MTP data provider framework
       
    89     layer. This method should only be invoked when processing the ERequestPhase
       
    90     of an MTP transaction (@see CMTPDataProviderPlugin::ProcessRequestPhaseL),
       
    91     and causes the MTP session transaction state to transition to the
       
    92     @see EDataIToRPhase. The data object receive sequence is completed when the 
       
    93     MTP data provider framework layer initiates the @see EResponsePhase of the 
       
    94     MTP transaction (@see CMTPDataProviderPlugin::ProcessRequestPhaseL).
       
    95     @param aData The MTP data object sink buffer.
       
    96     @param aRequest The MTP request dataset of the active MTP transaction.
       
    97     @param aConnection The handle of the MTP connection on which the transaction
       
    98     is being processed.
       
    99     @see CMTPDataProviderPlugin::ProcessRequestPhaseL
       
   100     @leave KErrNotReady, if invoked when the current MTP transaction phase is
       
   101     not ERequestPhase.
       
   102     */
       
   103     void ReceiveDataL(MMTPType& aData, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection);
       
   104 
       
   105     /**
       
   106     Initiates a data object send sequence in the MTP data provider framework
       
   107     layer. This method should only be invoked when processing the ERequestPhase
       
   108     of an MTP transaction (@see CMTPDataProviderPlugin::ProcessRequestPhaseL),
       
   109     and causes the MTP session transaction state to transition to the
       
   110     @see EDataRToIPhase. The data object send sequence is completed when the 
       
   111     MTP data provider framework layer initiates the @see EResponsePhase of the 
       
   112     MTP transaction (@see CMTPDataProviderPlugin::ProcessRequestPhaseL).
       
   113     @param aData The MTP data object source buffer.
       
   114     @param aRequest The MTP request dataset of the active MTP transaction.
       
   115     @param aConnection The handle of the MTP connection on which the transaction
       
   116     is being processed.
       
   117     @see CMTPDataProviderPlugin::ProcessRequestPhaseL
       
   118     @leave KErrNotReady, if invoked when the current MTP transaction phase is
       
   119     not ERequestPhase.
       
   120     */
       
   121     void SendDataL(const MMTPType& aData, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection);
       
   122 
       
   123     /**
       
   124     Signals the MTP data provider framework layer to send an asynchronous event
       
   125     dataset on the specified MTP connection.
       
   126     @param aEvent The MTP event dataset source buffer.
       
   127     @param aConnection The handle of the MTP connection on which the event is
       
   128     to be sent.
       
   129     @leave KErrArgument, if the event data is not valid.
       
   130     */
       
   131     void SendEventL(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection);
       
   132 
       
   133     /**
       
   134     Signals the MTP data provider framework layer to send an asynchronous event
       
   135     dataset on all active MTP connections.
       
   136     @param aEvent The MTP event dataset source, this should always target all
       
   137     open sessions, i.e. SessionID should be set to KMTPAllSessions.
       
   138     @leave KErrArgument, if the event data is invalid.
       
   139     */
       
   140     void SendEventL(const TMTPTypeEvent& aEvent);
       
   141 
       
   142     /**
       
   143     Initiates an MTP response dataset send sequence in the MTP data provider
       
   144     framework layer. This method should only be invoked when processing either
       
   145     the @see ERequestPhase or @see EResponsePhase of an MTP transaction, (@see
       
   146     CMTPDataProviderPlugin::ProcessRequestPhaseL) and causes the MTP session
       
   147     transaction state to transition to the @see ECompletingPhase. The MTP 
       
   148     response dataset send sequence is completed when the MTP data provider 
       
   149     framework layer initiates the @see ECompletingPhase of the MTP transaction 
       
   150     (@see CMTPDataProviderPlugin::ProcessRequestPhaseL).
       
   151     @param aResponse The MTP aResponse dataset source buffer.
       
   152     @param aConnection The handle of the MTP connection on which the transaction
       
   153     is being processed.
       
   154     @see CMTPDataProviderPlugin::ProcessRequestPhaseL
       
   155     @leave KErrNotReady, if invoked when the current MTP transaction phase is
       
   156     not ERequestPhase or EResponsePhase.
       
   157     */
       
   158     void SendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection);
       
   159 
       
   160     /**
       
   161     Signals to the MTP data provider framework layer that all processing
       
   162     related to the current transaction has been completed. This method should
       
   163     only be invoked when processing the @see ECompletingPhase of the MTP 
       
   164     transaction (@see CMTPDataProviderPlugin::ProcessRequestPhaseL), and causes 
       
   165     the MTP session transaction state to transition to the @see EIdle state.
       
   166     @param aRequest The MTP request dataset that initiated the transaction.
       
   167     @param aRequest The MTP request dataset of the active MTP transaction.
       
   168     @param aConnection The handle of the MTP connection on which the transaction
       
   169     is being processed.
       
   170     @see CMTPDataProviderPlugin::ProcessRequestPhaseL
       
   171     @leave KErrNotReady If invoked when the current MTP transaction phase is
       
   172     invalid.
       
   173     */
       
   174     void TransactionCompleteL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection);
       
   175 
       
   176     /**
       
   177     Registers the calling data provider to receive one or more occurrences of 
       
   178     the specified request dataset that are received on the specified 
       
   179     connection. This method should be used to register the calling data 
       
   180     provider to receive the following request types:
       
   181     
       
   182         1.  Follow-on requests of an MTP operation that can span multiple 
       
   183             transaction cycles. The following request types are recognised
       
   184             by the framework as follow-on requests:
       
   185             
       
   186             i)  SendObject (preceded by SendObjectInfo or SendObjectPropList). 
       
   187             ii) TerminateOpenCapture (preceded by InitiateOpenCapture).
       
   188             
       
   189         2.  MTP vendor extension requests.
       
   190         
       
   191     Note that:
       
   192 
       
   193         1.  The request dataset being registered must minimally specify the
       
   194             Operation Code of the expected operation and the SessionID on which 
       
   195             the operation request is expected to be received. 
       
   196             
       
   197             Follow-on request registrations MUST specify a specific SessionID. 
       
   198             Registrations of non follow-on requests may optionally specify a 
       
   199             SessionID of @see KMTPSessionAll to receive matching requests from
       
   200             any active MTP session.
       
   201            
       
   202         2.  With the exception of the TransactionID element, registered request
       
   203             datasets must exactly match all data elements of the expected request 
       
   204             dataset in order to be successfully routed.
       
   205            
       
   206         3.  Duplicate RouteRequestRegisterL registrations are not permitted. A request 
       
   207             dataset that matches that of a previous registration by this or 
       
   208             any other data provider on the same MTP session will result in the 
       
   209             previous registration being superceded.
       
   210            
       
   211         4.  Pending RouteRequestRegisterL registrations can be withdrawn at any time
       
   212             using the @see RouteRequestUnregisterL method. 
       
   213            
       
   214         5.  RouteRequestRegisterL registrations of MTP request types which ARE 
       
   215             recognised by the framework as MTP follow-on requests (SendObject, 
       
   216             TerminateOpenCapture) will result in at most one matching request 
       
   217             occurence being routed to the data provider. To receive another 
       
   218             request dataset of the same type, a new @see RouteRequestRegisterL 
       
   219             registration must be made.
       
   220             
       
   221         6   RouteRequestRegisterL registrations of MTP request types which ARE
       
   222             NOT recognised by the framework as MTP follow-on requests will 
       
   223             result in all matching requests which are subsequently received 
       
   224             being routed to the data provider. This will continue until such 
       
   225             time as the RouteRequestRegisterL registration is withdrawn using 
       
   226             the @see RouteRequestUnregisterL method.
       
   227             
       
   228         7.  RouteRequestRegisterL registrations request datasets which specify 
       
   229             an SessionID value of @see KMTPSessionAll, will result in matching 
       
   230             requests which are subsequently received on any active MTP session
       
   231             being routed to the data provider.
       
   232 
       
   233     @param aRequest The operation request dataset being registered.
       
   234     @param aConnection The handle of the MTP connection on which the operation
       
   235     request is expected to be received.
       
   236     @leave KErrArgument, if the request dataset does meet the minimal
       
   237     registration requirements specified above.
       
   238     @leave One of the system wide error codes, if a general processing error
       
   239     occurs.
       
   240     @see RouteRequestUnregisterL
       
   241     */
       
   242     void RouteRequestRegisterL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection);
       
   243 
       
   244     /**
       
   245     Cancels a pending RouteRequestRegisterL registration.
       
   246     @param aRequest The registered operation request dataset.
       
   247     @param aConnection The handle of the MTP connection for which the operation
       
   248     request was registered.
       
   249     @leave One of the system wide error codes, if a general processing error
       
   250     occurs.
       
   251     @see RouteRequestRegisterL
       
   252     */
       
   253     void RouteRequestUnregisterL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection);
       
   254 
       
   255     /**
       
   256     Signals the completion of the data provider's object store enumeration
       
   257     sequence that was previously initiated by a StartObjectEnumerationL signal
       
   258     made to the MTP data provider interface.
       
   259     @param aStorageId The MTP StorageID of the enumerated storage. This should 
       
   260     match the value specified in the preceding StartObjectEnumerationL.
       
   261     @see MMTPDataProvider::StartObjectEnumerationL
       
   262     */
       
   263     void ObjectEnumerationCompleteL(TUint32 aStorageId);
       
   264 
       
   265     /**
       
   266     Signals the completion of the data provider's storage enumeration sequence
       
   267     that was previously initiated by a StartStorageEnumerationL signal
       
   268     made to the MTP data provider interface.
       
   269     @see MMTPDataProvider::StartStorageEnumerationL
       
   270     */
       
   271     void StorageEnumerationCompleteL();
       
   272 
       
   273     /**
       
   274     Provides a handle to the configurability data specified in the data 
       
   275     provider's configuration file. 
       
   276     @return Handle to the data provider's configurability data.
       
   277     */
       
   278     const MMTPDataProviderConfig& DataProviderConfig() const;
       
   279 
       
   280     /**
       
   281     Provides a handle to the data provider framework configurability parameter 
       
   282     data. 
       
   283     @return Handle to the data provider framework configurability data.
       
   284     */
       
   285     const MMTPFrameworkConfig& FrameworkConfig() const;
       
   286 
       
   287     /**
       
   288     Provides a handle to the MTP object manager, which manages the assignment
       
   289     of MTP object handles and their mapping to actual data objects on behalf
       
   290     of the data provider.
       
   291     @return Handle to the MTP data provider framework object manager.
       
   292     */
       
   293     MMTPObjectMgr& ObjectMgr() const;
       
   294 
       
   295     /**
       
   296     Provides a handle to the MTP object reference manager, to which data
       
   297     providers can delegate the handling of the MTP persistent, abstract
       
   298     object referencing mechanism.
       
   299     @return Handle to the MTP data provider framework object reference manager.
       
   300     */
       
   301     MMTPReferenceMgr& ReferenceMgr() const;
       
   302 
       
   303     /**
       
   304     Provides a handle to the MTP storage manager, which manages the assignment 
       
   305     of MTP storage identifiers on behalf of the data provider.
       
   306     @return Handle to the MTP data provider framework storage manager.
       
   307     */
       
   308     MMTPStorageMgr& StorageMgr() const;
       
   309     
       
   310     /**
       
   311     Provides a handle to the MTP data provider framework RFs session.
       
   312     @return Handle to the MTP data provider framework RFs session.
       
   313     */
       
   314     RFs& Fs() const;   
       
   315     
       
   316     TBool ObjectEnumerationComplete() const;
       
   317     TInt ObjectEnumerationError() const;
       
   318     
       
   319     TBool StorageEnumerationComplete() const;
       
   320 
       
   321     TMTPTransactionPhase SetPhaseL( TMTPTransactionPhase aPhase );
       
   322     
       
   323     void SetPendingOperation( TAsyncOperation aOperation );
       
   324     TInt WaitForPendingOperation();
       
   325     TInt GetPendingResult();
       
   326 public: // From MMTPDataProviderConfig
       
   327 
       
   328     TUint UintValue( TParameter aParam ) const;
       
   329     TBool BoolValue( TParameter aParam ) const;
       
   330     const TDesC& DesCValue( TParameter aParam ) const;
       
   331     const TDesC8& DesC8Value( TParameter aParam ) const;
       
   332     void GetArrayValue( TParameter aParam, RArray<TUint>& aArray ) const;
       
   333         
       
   334 public: // From MMPXHarvesterUtilityObserver
       
   335     void HandleAbstractMediaExportCompletedL( CMPXMedia* aMedia, TInt aErr );
       
   336     void HandleAbstractMediaImportCompletedL( CMPXMedia* aMedia, TInt aErr );
       
   337     void HandleFileAddCompletedL( CMPXMedia* aMedia, TInt aErr );
       
   338     void HandleDeleteCompletedL( TInt aErr );
       
   339     void HandleFileImportCompletedL( CMPXMedia* aMedia, TInt aErr  );
       
   340     void HandleFileGetMediaCompletedL( CMPXMedia* aMedia, TInt aErr );
       
   341 
       
   342 protected:
       
   343     void ConstructL();
       
   344 
       
   345 public:
       
   346     TMTPTransactionPhase iPhase;
       
   347     TMTPTypeResponse iResponse;
       
   348     TUint16 iResponseCode;
       
   349     const MMTPType* iMMTPTypeData;
       
   350     CMTPTypeArray* iObjectPropsSupported;
       
   351     
       
   352 private:
       
   353     CStifLogger* iLog;
       
   354     
       
   355     CTestObjectManager* iTestObjManager;
       
   356     RFs iFsSession;
       
   357     TBool iObjectEnumerationComplete;
       
   358     TInt iObjectEnumerationError;
       
   359     TBool iStorageEnumerationComplete;
       
   360     CTestStorageMgr* iStorageManager;
       
   361     CMmMtpDataProviderTestModule *iTestModule;
       
   362     TAsyncOperation iPendingOperation;
       
   363     TInt iAsyncResult;
       
   364     CActiveSchedulerWait* iActiveSchedulerWait;
       
   365     TUint32 iResourceId;
       
   366     };
       
   367 
       
   368 #endif // CTESTOBSERVER_H