mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetobjectpropvalue.cpp
changeset 0 a2952bb97e68
child 9 bee149131e4b
child 25 d881023c13eb
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:  Implement the operation: GetObjectPropValue
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mtp/cmtptypestring.h>
       
    20 #include <mtp/cmtptypearray.h>
       
    21 #include <mtp/mmtpdataproviderframework.h>
       
    22 #include <mtp/mmtpobjectmgr.h>
       
    23 #include <mtp/cmtpobjectmetadata.h>
       
    24 #include <f32file.h>
       
    25 
       
    26 #include "cgetobjectpropvalue.h"
       
    27 #include "mmmtpdputility.h"
       
    28 #include "cmmmtpdpmetadataaccesswrapper.h"
       
    29 #include "mmmtpdplogger.h"
       
    30 #include "mmmtpdpconfig.h"
       
    31 
       
    32 _LIT( KMtpDateTimeFormat, "%F%Y%M%DT%H%T%S" );
       
    33 const TInt KMtpMaxDateTimeStringLength = 15;
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // Verification data for the GetObjectPropValue request
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 const TMTPRequestElementInfo KMTPGetObjectPropValuePolicy[] =
       
    40     {
       
    41         {
       
    42         TMTPTypeRequest::ERequestParameter1,
       
    43         EMTPElementTypeObjectHandle,
       
    44         EMTPElementAttrNone,
       
    45         0,
       
    46         0,
       
    47         0
       
    48         },
       
    49     };
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CGetObjectPropValue::~CGetObjectPropValue
       
    53 // Destructor
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CGetObjectPropValue::~CGetObjectPropValue()
       
    57     {
       
    58     delete iMTPTypeString;
       
    59     delete iMTPTypeArray;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CGetObjectPropValue::CGetObjectPropValue
       
    64 // Standard c++ constructor
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CGetObjectPropValue::CGetObjectPropValue( MMTPDataProviderFramework& aFramework,
       
    68     MMTPConnection& aConnection,
       
    69     MMmMtpDpConfig& aDpConfig ) :
       
    70     CRequestProcessor( aFramework,
       
    71         aConnection,
       
    72         sizeof ( KMTPGetObjectPropValuePolicy ) / sizeof ( TMTPRequestElementInfo ),
       
    73         KMTPGetObjectPropValuePolicy ),
       
    74     iDpConfig( aDpConfig )
       
    75     {
       
    76     SetPSStatus();
       
    77     PRINT( _L( "Operation: GetObjectPropValue(0x9803)" ) );
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CGetObjectPropValue::CheckRequestL
       
    82 // Verify the reqeust
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C TMTPResponseCode CGetObjectPropValue::CheckRequestL()
       
    86     {
       
    87     PRINT( _L( "MM MTP => CGetObjectPropValue::CheckRequestL" ) );
       
    88     TMTPResponseCode result = CRequestProcessor::CheckRequestL();
       
    89 
       
    90     //Now check to see if we support the property
       
    91     if ( result == EMTPRespCodeOK )
       
    92         {
       
    93         TUint32 objectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
       
    94         CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( objectHandle );
       
    95 
       
    96         if (!objectInfo)
       
    97             {
       
    98             PRINT(_L("MM MTP <> CGetObjectPropValue::CheckRequestL, objectInfo is NULL"));
       
    99             return EMTPRespCodeInvalidObjectHandle;
       
   100             }
       
   101 
       
   102         TFileName fileName = objectInfo->DesC( CMTPObjectMetaData::ESuid );
       
   103         TUint32 formatCode = objectInfo->Uint( CMTPObjectMetaData::EFormatCode );
       
   104 
       
   105         PRINT3( _L( "MM MTP <> CGetObjectPropValue::CheckRequestL, handle = 0x%x, filename = %S, formatCode = 0x%x" ), objectHandle, &fileName, formatCode);
       
   106         const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( formatCode );
       
   107         TInt count = properties->Count();
       
   108 
       
   109         TUint32 propCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
       
   110         PRINT1( _L( "MM MTP <> CGetObjectPropValue::CheckRequestL propCode = 0x%x" ), propCode );
       
   111 
       
   112         result = EMTPRespCodeInvalidObjectPropCode;
       
   113 
       
   114         for ( TInt i = 0; i < count; i++ )
       
   115             {
       
   116             if ( (*properties)[i] == propCode )
       
   117                 {
       
   118                 result = EMTPRespCodeOK;
       
   119                 break;
       
   120                 }
       
   121             }
       
   122         }
       
   123 
       
   124     PRINT1( _L( "MM MTP <= CGetObjectPropValue::CheckRequestL result = 0x%x" ), result );
       
   125     return result;
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CGetObjectPropValue::ServiceL
       
   130 // GetObjectPropValue request handler
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C void CGetObjectPropValue::ServiceL()
       
   134     {
       
   135     PRINT( _L( "MM MTP => CGetObjectPropValue::ServiceL" ) );
       
   136 
       
   137     //Get the request information
       
   138     TUint32 objectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
       
   139     TUint32 propCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
       
   140     PRINT2( _L( "MM MTP <> CGetObjectPropValue::ServiceL objectHandle = 0x%x, propCode = 0x%x" ),
       
   141             objectHandle, propCode );
       
   142 
       
   143     // don't have the ownship of the object
       
   144     iObjectInfo = iRequestChecker->GetObjectInfo( objectHandle );
       
   145     TPtrC suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
   146     PRINT1( _L( "MM MTP <> CGetObjectPropValue::ServiceL object file name is %S" ), &suid );
       
   147     TParsePtrC parse( suid );
       
   148 
       
   149     iDpConfig.GetWrapperL().SetStorageRootL( parse.Drive() );
       
   150 
       
   151     if ( iMTPTypeString != NULL )
       
   152         {
       
   153         delete iMTPTypeString;
       
   154         iMTPTypeString = NULL;
       
   155         }
       
   156 
       
   157     switch ( propCode )
       
   158         {
       
   159         // Storage ID
       
   160         case EMTPObjectPropCodeStorageID:
       
   161             {
       
   162             iMTPTypeUint32.Set( 0 );
       
   163             iMTPTypeUint32 = iObjectInfo->Uint( CMTPObjectMetaData::EStorageId );
       
   164             SendDataL( iMTPTypeUint32 );
       
   165             }
       
   166             break;
       
   167 
       
   168         // Format Code
       
   169         case EMTPObjectPropCodeObjectFormat:
       
   170             {
       
   171             iMTPTypeUint16.Set( 0 );
       
   172             iMTPTypeUint16 = iObjectInfo->Uint( CMTPObjectMetaData::EFormatCode );
       
   173             PRINT1( _L( "MM MTP <> CGetObjectPropValue::ServiceL ObjectFormat = 0x%x" ),
       
   174                 iMTPTypeUint16.Value() );
       
   175 
       
   176             SendDataL( iMTPTypeUint16 );
       
   177             }
       
   178             break;
       
   179 
       
   180         // ProtectionStatus
       
   181         case EMTPObjectPropCodeProtectionStatus:
       
   182             {
       
   183             iMTPTypeUint16.Set( 0 );
       
   184             iMTPTypeUint16 = MmMtpDpUtility::GetProtectionStatusL( iFramework.Fs(),
       
   185                     iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
   186             SendDataL( iMTPTypeUint16 );
       
   187             }
       
   188             break;
       
   189 
       
   190         // Object Size
       
   191         case EMTPObjectPropCodeObjectSize:
       
   192             {
       
   193             iMTPTypeUint64.Set( 0 );
       
   194             iMTPTypeUint64 = MmMtpDpUtility::GetObjectSizeL( iFramework.Fs(),
       
   195                     iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
   196             SendDataL( iMTPTypeUint64 );
       
   197             }
       
   198             break;
       
   199 
       
   200         // Filename
       
   201         case EMTPObjectPropCodeObjectFileName:
       
   202             {
       
   203             const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
   204             PRINT1( _L( "MM MTP <> CGetObjectPropValue::ServiceL SUID = %S" ), &suid );
       
   205 
       
   206             TPtrC path( suid.Ptr(), suid.Length() );
       
   207             TParsePtrC parse( path );
       
   208             iMTPTypeString = CMTPTypeString::NewL( parse.NameAndExt() );
       
   209             SendDataL( *iMTPTypeString );
       
   210             }
       
   211             break;
       
   212 
       
   213         // Parent
       
   214         case EMTPObjectPropCodeParentObject:
       
   215             {
       
   216             iMTPTypeUint32.Set( 0 );
       
   217             iMTPTypeUint32 = iObjectInfo->Uint( CMTPObjectMetaData::EParentHandle );
       
   218             SendDataL( iMTPTypeUint32 );
       
   219             }
       
   220             break;
       
   221 
       
   222         // Persistent Unique Object Identifier
       
   223         case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
       
   224             {
       
   225             iMTPTypeUint128.Set( 0, 0 );
       
   226             iMTPTypeUint128 = iFramework.ObjectMgr().PuidL( objectHandle );
       
   227             SendDataL( iMTPTypeUint128 );
       
   228             }
       
   229             break;
       
   230 
       
   231         // Name and DataAdded (audio only) fall under the same branch while dateadded(video)/modified/created fall under another
       
   232         case EMTPObjectPropCodeName: // 0xDC44
       
   233         case EMTPObjectPropCodeDateAdded: // 0xDC4E
       
   234             {
       
   235             if ( ( propCode == EMTPObjectPropCodeName)
       
   236                 || ( ( !MmMtpDpUtility::IsVideoL(iObjectInfo->DesC( CMTPObjectMetaData::ESuid ), iFramework ) )
       
   237                         && ( propCode == EMTPObjectPropCodeDateAdded ) ) )
       
   238                 {
       
   239                 iMTPTypeString = CMTPTypeString::NewL();
       
   240                 ServiceMetaDataFromWrapperL( propCode, *iMTPTypeString, *iObjectInfo );
       
   241                 break;
       
   242                 }
       
   243             }
       
   244         //lint -fallthrough
       
   245         case EMTPObjectPropCodeDateCreated:
       
   246         case EMTPObjectPropCodeDateModified:
       
   247             {
       
   248             TTime dataModified;
       
   249             dataModified = MmMtpDpUtility::GetObjectDateModifiedL( iFramework.Fs(),
       
   250                 iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
   251 
       
   252             TBuf<KMtpMaxDateTimeStringLength> timeStr;
       
   253             dataModified.FormatL( timeStr, KMtpDateTimeFormat );
       
   254             PRINT1( _L( "MM MTP <> CGetObjectPropValue::ServiceL Date time %S" ), &timeStr );
       
   255             iMTPTypeString = CMTPTypeString::NewL( timeStr );
       
   256             SendDataL( *iMTPTypeString );
       
   257             }
       
   258             break;
       
   259 
       
   260         // Consumable
       
   261         case EMTPObjectPropCodeNonConsumable:
       
   262             {
       
   263             iMTPTypeUint8.Set( 0 );
       
   264             SendDataL( iMTPTypeUint8 );
       
   265             }
       
   266             break;
       
   267 
       
   268         default:
       
   269             {
       
   270             ServiceSpecificObjectPropertyL( propCode );
       
   271             }
       
   272             break;
       
   273         }
       
   274     PRINT( _L( "MM MTP <= CGetObjectPropValue::ServiceL" ) );
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CGetObjectPropValue::ServiceMetaDataFromWrapperL
       
   279 // Get MetaData from CMetadataAccessWrapper and send data
       
   280 // or response to initiator
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 EXPORT_C void CGetObjectPropValue::ServiceMetaDataFromWrapperL( const TUint16 aPropCode,
       
   284     MMTPType& aNewData,
       
   285     const CMTPObjectMetaData& aObjectMetaData )
       
   286     {
       
   287     TRAPD( err, iDpConfig.GetWrapperL().GetObjectMetadataValueL( aPropCode,
       
   288         aNewData,
       
   289         aObjectMetaData ) );
       
   290 
       
   291     PRINT1( _L( "MM MTP <> CGetObjectPropValue::ServiceMetaDataFromWrapperL err = %d" ), err );
       
   292 
       
   293     if ( err == KErrNone )
       
   294         {
       
   295         SendDataL( aNewData );
       
   296         }
       
   297     // according to the codes of S60
       
   298     else if ( err == KErrTooBig )
       
   299         {
       
   300         SendResponseL( EMTPRespCodeInvalidDataset );
       
   301         }
       
   302     else if( err == KErrPermissionDenied )
       
   303         {
       
   304         SendResponseL( EMTPRespCodeAccessDenied );
       
   305         }
       
   306     else if ( err == KErrNotFound )
       
   307         {
       
   308         if( MmMtpDpUtility::HasMetadata( aObjectMetaData.Uint( CMTPObjectMetaData::EFormatCode ) ) )
       
   309             SendResponseL( EMTPRespCodeAccessDenied );
       
   310         else
       
   311             SendDataL( aNewData );
       
   312         }
       
   313     // PTP/MTP error code, according to the codes of S60
       
   314     else if ( err > KErrNone )
       
   315         {
       
   316         SendResponseL( static_cast<TMTPResponseCode>( err ) );
       
   317         }
       
   318     else
       
   319         {
       
   320         SendResponseL( EMTPRespCodeGeneralError );
       
   321         }
       
   322     }
       
   323 
       
   324 // end of file