mmappcomponents/mmmtpdataprovider/tsrc/mtpdataprovidertestmodule/src/ctestobjectmanager.cpp
changeset 0 a2952bb97e68
child 48 b7b49303d0c0
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:  Dummy object manager for test module
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32def.h>
       
    20 #include <mtp/mtpprotocolconstants.h>
       
    21 #include <mtp/cmtpobjectmetadata.h>
       
    22 #include <e32debug.h>
       
    23 
       
    24 #include "ctestobjectmanager.h"
       
    25 #include "logging.h"
       
    26 
       
    27 #ifdef LOGGER
       
    28 #undef LOGGER
       
    29 #endif
       
    30 #define LOGGER iLog
       
    31 
       
    32 CTestObjectManager* CTestObjectManager::NewL()
       
    33     {
       
    34     CTestObjectManager* self = new ( ELeave ) CTestObjectManager();
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop();
       
    38     return self;
       
    39     }
       
    40 
       
    41 CTestObjectManager::CTestObjectManager()
       
    42     {
       
    43     // implementation not required
       
    44     }
       
    45 
       
    46 void CTestObjectManager::ConstructL()
       
    47     {
       
    48     TFileName logFileName;
       
    49     logFileName.Copy( KMtpDataProviderTestModuleLogFile );
       
    50     
       
    51     iLog = CStifLogger::NewL( KMtpDataProviderTestModuleLogPath, 
       
    52             logFileName,
       
    53             CStifLogger::ETxt,
       
    54             TRACE_TARGET,
       
    55             ETrue, ETrue, ETrue, EFalse, ETrue );
       
    56     PRINTF0( "CTestObjectManager::ConstructL" );
       
    57     }
       
    58 
       
    59 TUint CTestObjectManager::CountL( const TMTPObjectMgrQueryParams& aParams ) const
       
    60     {
       
    61     PRINTF3( ">CTestObjectManager::CountL storage = 0x%x parent = 0x%x format = 0x%x", aParams.iStorageId, aParams.iParentHandle, aParams.iFormatCode );
       
    62     TUint count = 0;
       
    63     for ( TInt i = 0; i < iMTPObjects.Count(); i++ )
       
    64          {
       
    65          TUint handle = iMTPObjects[i]->Uint( CMTPObjectMetaData::EHandle );
       
    66          TUint formatCode = iMTPObjects[i]->Uint( CMTPObjectMetaData::EFormatCode );
       
    67          TUint storageId = iMTPObjects[i]->Uint( CMTPObjectMetaData::EStorageId );
       
    68          TInt parentId = iMTPObjects[i]->Int( CMTPObjectMetaData::EParentId );
       
    69          if ( ( ( aParams.iStorageId == storageId   ) || ( aParams.iStorageId == KMTPStorageAll ) )
       
    70             &&
       
    71               ( ( aParams.iFormatCode == formatCode ) || ( aParams.iFormatCode == KMTPFormatsAll ) )
       
    72             &&
       
    73               ( ( aParams.iParentHandle == parentId ) || ( aParams.iParentHandle == KMTPHandleNone ) || ( ( aParams.iParentHandle == KMTPHandleNoParent ) && ( parentId == KErrNotFound ) ) ) )
       
    74              {
       
    75              PRINTV1( "Adding handle %d to count", handle );
       
    76              count++;
       
    77              }
       
    78          }
       
    79     PRINTF1( "<CTestObjectManager::CountL, count = %d", count );
       
    80     return count;
       
    81     }
       
    82 
       
    83 void CTestObjectManager::GetObjectHandlesL(
       
    84         const TMTPObjectMgrQueryParams& aParams,
       
    85         RMTPObjectMgrQueryContext& aContext, RArray<TUint>& aHandles ) const
       
    86     {
       
    87     PRINTF3( ">CTestObjectManager::GetObjectHandlesL storage = 0x%x parent = 0x%x format = 0x%x", aParams.iStorageId, aParams.iParentHandle, aParams.iFormatCode );
       
    88     for ( TInt i = 0; i < iMTPObjects.Count(); i++ )
       
    89          {
       
    90          TUint handle = iMTPObjects[i]->Uint( CMTPObjectMetaData::EHandle );
       
    91          TUint formatCode = iMTPObjects[i]->Uint( CMTPObjectMetaData::EFormatCode );
       
    92          TUint storageId = iMTPObjects[i]->Uint( CMTPObjectMetaData::EStorageId );
       
    93          TInt parentId = iMTPObjects[i]->Int( CMTPObjectMetaData::EParentId );
       
    94          if ( ( ( aParams.iStorageId == storageId   ) || ( aParams.iStorageId == KMTPStorageAll ) )
       
    95             &&
       
    96               ( ( aParams.iFormatCode == formatCode ) || ( aParams.iFormatCode == KMTPFormatsAll ) )
       
    97             &&
       
    98             ( ( aParams.iParentHandle == parentId ) || ( aParams.iParentHandle == KMTPHandleNone ) || ( ( aParams.iParentHandle == KMTPHandleNoParent ) && ( parentId == KErrNotFound ) ) ) )
       
    99              {
       
   100              PRINTV1( "Appending handle %d", handle );
       
   101              aHandles.AppendL( handle );
       
   102              }
       
   103          }
       
   104     aContext.Close();
       
   105     PRINTF0( "<CTestObjectManager::GetObjectHandlesL" );
       
   106     }
       
   107       
       
   108 void CTestObjectManager::GetObjectSuidsL( 
       
   109         const TMTPObjectMgrQueryParams& aParams,
       
   110         RMTPObjectMgrQueryContext& aContext, CDesCArray& aSuids ) const
       
   111     {
       
   112     PRINTF3( ">CTestObjectManager::GetObjectSuidsL storage = 0x%x parent = 0x%x format = 0x%x", aParams.iStorageId, aParams.iParentHandle, aParams.iFormatCode );
       
   113     for ( TInt i = 0; i < iMTPObjects.Count(); i++ )
       
   114          {
       
   115          TPtrC suid = iMTPObjects[i]->DesC( CMTPObjectMetaData::ESuid );
       
   116          TUint formatCode = iMTPObjects[i]->Uint( CMTPObjectMetaData::EFormatCode );
       
   117          TUint storageId = iMTPObjects[i]->Uint( CMTPObjectMetaData::EStorageId );
       
   118          TInt parentId = iMTPObjects[i]->Int( CMTPObjectMetaData::EParentId );
       
   119          if ( ( ( aParams.iStorageId == storageId   ) || ( aParams.iStorageId == KMTPStorageAll ) )
       
   120             &&
       
   121               ( ( aParams.iFormatCode == formatCode ) || ( aParams.iFormatCode == KMTPFormatsAll ) )
       
   122             &&
       
   123             ( ( aParams.iParentHandle == parentId ) || ( aParams.iParentHandle == KMTPHandleNone ) || ( ( aParams.iParentHandle == KMTPHandleNoParent ) && ( parentId == KErrNotFound ) ) ) )
       
   124              {
       
   125              PRINTV1( "Appending suid %S", &suid );
       
   126              aSuids.AppendL( suid );
       
   127              }
       
   128          }
       
   129     aContext.Close();
       
   130     PRINTF0( "<CTestObjectManager::GetObjectSuidsL" );
       
   131     }
       
   132       
       
   133 TUint32 CTestObjectManager::HandleL( TInt64 aObjectUid ) const
       
   134     {
       
   135     PRINTF1( "<>CTestObjectManager::HandleL uid = %Ld", aObjectUid );
       
   136     PRINTE0( "NOT IMPLEMENTED" );
       
   137     return NULL;
       
   138     }
       
   139       
       
   140  
       
   141 TUint32 CTestObjectManager::HandleL( const TMTPTypeUint128& aPuid ) const
       
   142     {
       
   143     TUint64 lower = aPuid.LowerValue();
       
   144     TUint64 higher = aPuid.UpperValue();
       
   145     PRINTF2( "<>CTestObjectManager::HandleL puid = %Lu %Lu", lower, higher );
       
   146     PRINTE0( "NOT IMPLEMENTED" );
       
   147     return NULL;    
       
   148     }
       
   149       
       
   150  
       
   151 TUint32 CTestObjectManager::HandleL( const TDesC& aSuid ) const
       
   152     {
       
   153     PRINTF1( ">CTestObjectManager::HandleL suid = %S", &aSuid );
       
   154     TUint handle = 0;
       
   155     for ( TInt i = 0; i < iMTPObjects.Count(); i++ )
       
   156          {
       
   157          if ( ( iMTPObjects[i]->DesC( CMTPObjectMetaData::ESuid ) ).Match( aSuid ) == 0 )
       
   158               {
       
   159               handle = iMTPObjects[i]->Uint( CMTPObjectMetaData::EHandle );
       
   160               break;
       
   161               }
       
   162          }
       
   163     PRINTF1( "<CTestObjectManager::HandleL with handle %d", handle );
       
   164     return handle;
       
   165     }
       
   166 
       
   167 void CTestObjectManager::InsertObjectL( CMTPObjectMetaData& aObject )
       
   168     {
       
   169     TUint handle = aObject.Uint( CMTPObjectMetaData::EHandle );
       
   170     PRINTF1( ">CTestObjectManager::InsertObjectL handle = %d", handle );
       
   171     
       
   172     CMTPObjectMetaData* newObject = CMTPObjectMetaData::NewL(
       
   173             aObject.DesC( CMTPObjectMetaData::ESuid ), 0, 0, 0 );
       
   174     
       
   175     CleanupStack::PushL( newObject );
       
   176     iHandle++;
       
   177     aObject.SetUint( CMTPObjectMetaData::EHandle, iHandle );
       
   178     newObject->SetUint( CMTPObjectMetaData::EHandle, iHandle );
       
   179     CopyObjectMetadataL( aObject, *newObject );
       
   180     CleanupStack::Pop( newObject );
       
   181     
       
   182     iMTPObjects.Append( newObject );
       
   183     PRINTF1( "New object inserted with handle %d", iHandle );
       
   184     }
       
   185 
       
   186 void CTestObjectManager::InsertObjectsL( RPointerArray<CMTPObjectMetaData>& /*aObjects*/ )
       
   187     {
       
   188     PRINTF0( "<>CTestObjectManager::InsertObjectsL" );
       
   189     PRINTE0( "NOT IMPLEMENTED" );
       
   190     }
       
   191 
       
   192 void CTestObjectManager::ModifyObjectL( const CMTPObjectMetaData& aObject )
       
   193     {
       
   194     TUint32 handle = aObject.Uint( CMTPObjectMetaData::EHandle );
       
   195     PRINTF1( ">CTestObjectManager::ModifyObjectL handle = %d", handle );
       
   196     for ( TInt i = 0; i < iMTPObjects.Count(); i++ )
       
   197         {
       
   198         if ( iMTPObjects[i]->Uint( CMTPObjectMetaData::EHandle ) == handle )
       
   199             {
       
   200             PRINTF1( "<CTestObjectManager::ModifyObjectL, index = %d", i );
       
   201             CopyObjectMetadataL( aObject, *iMTPObjects[i] );
       
   202             return;
       
   203             }
       
   204         }
       
   205     PRINTF0( "<CTestObjectManager::ModifyObjectL, object not found" );
       
   206     User::Leave( KErrNotFound );
       
   207     }
       
   208 
       
   209 TBool CTestObjectManager::ObjectL( const TMTPTypeUint32& aHandle, CMTPObjectMetaData& aObject ) const
       
   210     {
       
   211     TUint32 handle = aHandle.Value();
       
   212     PRINTF1( ">CTestObjectManager::ObjectL handle = %d", handle );
       
   213     for ( TInt i = 0; i < iMTPObjects.Count(); i++ )
       
   214         {
       
   215         if ( iMTPObjects[i]->Uint( CMTPObjectMetaData::EHandle ) == handle )
       
   216             {
       
   217             PRINTF1( "<CTestObjectManager::ObjectL, index = %d", i );
       
   218             CopyObjectMetadataL( *iMTPObjects[i], aObject );
       
   219             return ETrue;
       
   220             }
       
   221         }
       
   222     PRINTF0( "<CTestObjectManager::ObjectL, object not found" );
       
   223     return EFalse;
       
   224     }
       
   225 
       
   226 TBool CTestObjectManager::ObjectL( const TDesC& aSuid, CMTPObjectMetaData& aObject ) const
       
   227     {
       
   228     PRINTF1( ">CTestObjectManager::ObjectL suid = %S", &aSuid );
       
   229     for ( TInt i = 0; i < iMTPObjects.Count(); i++ )
       
   230         {
       
   231         if ( ( iMTPObjects[i]->DesC(CMTPObjectMetaData::ESuid ) ).Match( aSuid ) == 0)
       
   232             {
       
   233             PRINTF1( "<CTestObjectManager::ObjectL, index = %d", i );
       
   234             CopyObjectMetadataL( *( iMTPObjects[i] ), aObject );
       
   235             return ETrue;
       
   236             }
       
   237         }
       
   238     PRINTF0( "<CTestObjectManager::ObjectL, object not found" );
       
   239     return EFalse;
       
   240     }
       
   241       
       
   242 TUint CTestObjectManager::ObjectOwnerId( const TMTPTypeUint32& aHandle ) const
       
   243     {
       
   244     TUint32 handle = aHandle.Value();
       
   245     PRINTF1( ">CTestObjectManager::ObjectOwnerId handle = %d", handle );
       
   246     TUint ownerId = KErrNotFound;
       
   247     for ( TInt i = 0; i < iMTPObjects.Count(); i++ )
       
   248         {
       
   249         if ( handle == iMTPObjects[i]->Uint( CMTPObjectMetaData::EHandle ) )
       
   250             {
       
   251             ownerId = iMTPObjects[i]->Uint( CMTPObjectMetaData::EDataProviderId );
       
   252             break;
       
   253             }
       
   254         }
       
   255     if ( ownerId == KErrNotFound )
       
   256         {
       
   257         PRINTE1( "<CTestObjectManager::ObjectOwnerId, object not found: %d", handle );
       
   258         User::Leave( KErrNotFound );
       
   259         }
       
   260     PRINTF1( "<CTestObjectManager::ObjectOwnerId, owner id = %d", ownerId );
       
   261     return ownerId;
       
   262     }
       
   263 
       
   264 TInt64 CTestObjectManager::ObjectUidL( TUint32 aHandle ) const
       
   265     {
       
   266     PRINTF1( "<>CTestObjectManager::ObjectUidL handle = %d", aHandle );
       
   267     return aHandle;  
       
   268     }
       
   269   
       
   270 TInt64 CTestObjectManager::ObjectUidL( const TDesC& aSuid ) const
       
   271     {
       
   272     PRINTF1( ">CTestObjectManager::ObjectUidL suid = %S", &aSuid );
       
   273     TUint handle = 0;
       
   274     for ( TInt i = 0; i < iMTPObjects.Count(); i++ )
       
   275         {
       
   276         if ( ( iMTPObjects[i]->DesC( CMTPObjectMetaData::ESuid ) ).Match( aSuid ) == 0 )
       
   277             {
       
   278             handle = iMTPObjects[i]->Uint( CMTPObjectMetaData::EHandle );
       
   279             break;
       
   280             }
       
   281         }
       
   282     PRINTF1( "<CTestObjectManager::ObjectUidL, handle = %d", handle );
       
   283     return handle;
       
   284     }
       
   285  
       
   286 TInt64 CTestObjectManager::ObjectUidL( TMTPTypeUint128 aPuid ) const
       
   287     {
       
   288     TUint64 lower = aPuid.LowerValue();
       
   289     TUint64 higher = aPuid.UpperValue();
       
   290     PRINTF2( "<>CTestObjectManager::ObjectUidL puid = %Lu %Lu", lower, higher );
       
   291     PRINTE0( "NOT IMPLEMENTED" );
       
   292     return 0;  
       
   293     }
       
   294   
       
   295 TMTPTypeUint128 CTestObjectManager::PuidL( TUint32 aHandle ) const
       
   296     {
       
   297     PRINTF1( ">CTestObjectManager::PuidL handle = %d", aHandle );
       
   298     TMTPTypeUint128 returnValue;
       
   299     for ( TInt i = 0; i < iMTPObjects.Count(); i++)
       
   300          {
       
   301          TUint handle = iMTPObjects[i]->Uint( CMTPObjectMetaData::EHandle );
       
   302          if ( handle == aHandle )
       
   303               {
       
   304               returnValue.Set( handle, handle );
       
   305               break;   
       
   306               }
       
   307          }
       
   308     return returnValue;
       
   309     }
       
   310       
       
   311 TMTPTypeUint128 CTestObjectManager::PuidL( TInt64 aObjectUid ) const
       
   312     {
       
   313     PRINTF1( "<>CTestObjectManager::PuidL uid = %Ld", aObjectUid );
       
   314     TMTPTypeUint128 returnValue;
       
   315     PRINTE0( "NOT IMPLEMENTED" );
       
   316     return returnValue;
       
   317     }
       
   318 
       
   319 TMTPTypeUint128 CTestObjectManager::PuidL( const TDesC& aSuid ) const
       
   320     {
       
   321     PRINTF1( "<>CTestObjectManager::PuidL suid = %S", &aSuid );
       
   322     TMTPTypeUint128 returnValue;
       
   323     PRINTE0( "NOT IMPLEMENTED" );
       
   324     return returnValue;
       
   325     }
       
   326 
       
   327 void CTestObjectManager::RemoveObjectL( const TMTPTypeUint32& aHandle )
       
   328     {
       
   329     TUint handle = aHandle.Value();
       
   330     PRINTF1( "<>CTestObjectManager::RemoveObjectL handle = %d", handle );
       
   331     PRINTE0( "NOT IMPLEMENTED" );
       
   332     }
       
   333       
       
   334 void CTestObjectManager::RemoveObjectL( const TDesC& aSuid )
       
   335     {
       
   336     PRINTF1( "<>CTestObjectManager::RemoveObjectL suid = %S", &aSuid );
       
   337     PRINTE0( "NOT IMPLEMENTED" );
       
   338     }
       
   339 
       
   340 void CTestObjectManager::RemoveObjectsL( const CDesCArray& /*aSuids*/ )
       
   341     {
       
   342     PRINTF0( "<>CTestObjectManager::RemoveObjectsL suid arr" );
       
   343     PRINTE0( "NOT IMPLEMENTED" );
       
   344     }
       
   345 
       
   346 void CTestObjectManager::RemoveObjectsL( TUint aDataProviderId )
       
   347     {
       
   348     PRINTF1( "<>CTestObjectManager::RemoveObjectsL data provider id = %d", aDataProviderId );
       
   349     PRINTE0( "NOT IMPLEMENTED" );
       
   350     }
       
   351    
       
   352 void CTestObjectManager::ReserveObjectHandleL( CMTPObjectMetaData& aObject, TUint64 aSpaceRequired )
       
   353     {
       
   354     TUint handle = aObject.Uint( CMTPObjectMetaData::EHandle );
       
   355     PRINTF2( ">CTestObjectManager::ReserveObjectHandleL handle = %d, space = %Ld", handle, aSpaceRequired );
       
   356     
       
   357     CMTPObjectMetaData* newObject = CMTPObjectMetaData::NewL(
       
   358             aObject.DesC( CMTPObjectMetaData::ESuid ), 0, 0, 0 );
       
   359     
       
   360     CleanupStack::PushL( newObject );
       
   361     iHandle++;
       
   362     aObject.SetUint( CMTPObjectMetaData::EHandle, iHandle );
       
   363     newObject->SetUint( CMTPObjectMetaData::EHandle, iHandle );
       
   364     CopyObjectMetadataL( aObject, *newObject );
       
   365     CleanupStack::Pop( newObject );
       
   366     
       
   367     iMTPObjects.Append( newObject );
       
   368     PRINTF1( "<CTestObjectManager::ReserveObjectHandleL handle = %d", iHandle );
       
   369     }
       
   370 
       
   371 void CTestObjectManager::CommitReservedObjectHandleL( CMTPObjectMetaData& aObject )
       
   372     {
       
   373     TUint handle = aObject.Uint( CMTPObjectMetaData::EHandle );
       
   374     PRINTF1( "<>CTestObjectManager::CommitReservedObjectHandleL handle = %d", handle );
       
   375     }
       
   376 
       
   377 void CTestObjectManager::UnreserveObjectHandleL( const CMTPObjectMetaData& aObject )
       
   378     {
       
   379     TUint reservedHandle = aObject.Uint( CMTPObjectMetaData::EHandle );
       
   380     PRINTF1( ">CTestObjectManager::UnreserveObjectHandleL handle = %d", reservedHandle );
       
   381     
       
   382     for ( TInt i = 0; i < iMTPObjects.Count(); i++)
       
   383          {
       
   384          TUint handle = iMTPObjects[i]->Uint( CMTPObjectMetaData::EHandle );
       
   385          if ( reservedHandle == handle )
       
   386               {
       
   387               CMTPObjectMetaData* object = iMTPObjects[i];
       
   388               iMTPObjects.Remove( i );
       
   389               delete object;
       
   390               break;
       
   391               }
       
   392          }
       
   393     PRINTF0( "<CTestObjectManager::UnreserveObjectHandleL" );
       
   394     }
       
   395 
       
   396 CTestObjectManager::~CTestObjectManager()
       
   397     {
       
   398     PRINTF0( "<>CTestObjectManager::~CTestObjectManager()" );
       
   399     delete iLog;
       
   400     iMTPObjects.ResetAndDestroy();
       
   401     }
       
   402 
       
   403 void CTestObjectManager::CopyObjectMetadataL( 
       
   404         const CMTPObjectMetaData& aSource, CMTPObjectMetaData& aTarget ) const
       
   405     {
       
   406     PRINTF0( ">CTestObjectManager::CopyObjectMetadataL" );
       
   407     for ( TInt i = CMTPObjectMetaData::EDataProviderId;
       
   408             i <= CMTPObjectMetaData::EStorageVolumeId; i++ )
       
   409         {
       
   410         aTarget.SetUint( i, aSource.Uint( i ) );
       
   411         }
       
   412     
       
   413     aTarget.SetDesCL( CMTPObjectMetaData::ESuid, 
       
   414             aSource.DesC( CMTPObjectMetaData::ESuid ) );
       
   415         
       
   416     for ( TInt i = CMTPObjectMetaData::EUserRating;
       
   417             i <= CMTPObjectMetaData::EIdentifier; i++ )
       
   418         {
       
   419         aTarget.SetUint( i, aSource.Uint( i ) );
       
   420         }
       
   421    
       
   422     aTarget.SetInt( CMTPObjectMetaData::EParentId,
       
   423             aSource.Int( CMTPObjectMetaData::EParentId ) );
       
   424     PRINTF0( "<CTestObjectManager::CopyObjectMetadataL" );
       
   425     }