mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/csetobjectproplist.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: SetObjectPropList
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mtp/mmtpdataproviderframework.h>
       
    20 #include <mtp/cmtptypeobjectproplist.h>
       
    21 #include <mtp/mmtpobjectmgr.h>
       
    22 #include <mtp/cmtptypestring.h>
       
    23 #include <mtp/cmtptypearray.h>
       
    24 
       
    25 #include "csetobjectproplist.h"
       
    26 #include "cmmmtpdpmetadataaccesswrapper.h"
       
    27 #include "mmmtpdputility.h"
       
    28 #include "mmmtpdplogger.h"
       
    29 #include "mmmtpdpconfig.h"
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CSetObjectPropList::NewL
       
    33 // Two-phase construction method
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 //EXPORT_C MMmRequestProcessor* CSetObjectPropList::NewL( MMTPDataProviderFramework& aFramework,
       
    37 //    MMTPConnection& aConnection,
       
    38 //    CMmMtpDpMetadataAccessWrapper& aWrapper )
       
    39 //    {
       
    40 //    CSetObjectPropList* self = new ( ELeave ) CSetObjectPropList( aFramework,
       
    41 //        aConnection,
       
    42 //        aWrapper );
       
    43 //    CleanupStack::PushL( self );
       
    44 //    self->ConstructL();
       
    45 //    CleanupStack::Pop( self );
       
    46 //    return self;
       
    47 //    }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CSetObjectPropList::CSetObjectPropList
       
    51 // Standard c++ constructor
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C CSetObjectPropList::CSetObjectPropList( MMTPDataProviderFramework& aFramework,
       
    55     MMTPConnection& aConnection,
       
    56     MMmMtpDpConfig& aDpConfig ) :
       
    57     CRequestProcessor( aFramework, aConnection, 0, NULL),
       
    58     iObjectMgr( aFramework.ObjectMgr() ),
       
    59     iFs( aFramework.Fs() ),
       
    60     iDpConfig( aDpConfig ),
       
    61     iUnprocessedIndex ( 0 )
       
    62     {
       
    63     PRINT( _L( "Operation: SetObjectPropList(0x9806)" ) );
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CSetObjectPropList::ConstructL
       
    68 // 2nd Phase Constructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C void CSetObjectPropList::ConstructL()
       
    72     {
       
    73     CActiveScheduler::Add( this );
       
    74 
       
    75     iPropertyList = CMTPTypeObjectPropList::NewL();
       
    76     SetPSStatus();
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CSetObjectPropList::~CSetObjectPropList
       
    81 // Destructor
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C CSetObjectPropList::~CSetObjectPropList()
       
    85     {
       
    86     Cancel();
       
    87     delete iPropertyList;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CSetObjectPropList::ServiceL
       
    92 // SetObjectPropList request handler
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C void CSetObjectPropList::ServiceL()
       
    96     {
       
    97     PRINT( _L( "MM MTP => CSetObjectPropList::ServiceL" ) );
       
    98     // Recieve the data from the property list
       
    99     ReceiveDataL( *iPropertyList );
       
   100     PRINT( _L( "MM MTP <= CSetObjectPropList::ServiceL" ) );
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CSetObjectPropList::DoHandleResponsePhaseL
       
   105 // Completing phase for the request handler
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 EXPORT_C TBool CSetObjectPropList::DoHandleResponsePhaseL()
       
   109     {
       
   110     PRINT( _L( "MM MTP => CSetObjectPropList::DoHandleResponsePhaseL" ) );
       
   111 
       
   112     iElementCount = iPropertyList->NumberOfElements();
       
   113     iPropertyList->ResetCursor();
       
   114     if( iElementCount > 0 )
       
   115         {
       
   116         iUnprocessedIndex = 0;
       
   117         TRequestStatus* status = &iStatus;
       
   118         User::RequestComplete( status, iStatus.Int() );
       
   119         SetActive();
       
   120         }
       
   121     else
       
   122         {
       
   123         SendResponseL( EMTPRespCodeOK );
       
   124         }
       
   125 
       
   126     PRINT( _L( "MM MTP <= CSetObjectPropList::DoHandleResponsePhaseL" ) );
       
   127     return EFalse;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CSetObjectPropList::SetObjectPropListL
       
   132 // Set object proplist
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 TMTPResponseCode CSetObjectPropList::SetObjectPropListL(
       
   136         const CMTPTypeObjectPropListElement& aPropListElement )
       
   137     {
       
   138     PRINT( _L( "MM MTP => CSetObjectPropList::SetObjectPropListL" ) );
       
   139 
       
   140     TMTPTypeUint16 protectionStatus( EMTPProtectionNoProtection );
       
   141     TMTPResponseCode responseCode( EMTPRespCodeOK );
       
   142 
       
   143     TUint32 handle = aPropListElement.Uint32L( CMTPTypeObjectPropListElement::EObjectHandle );
       
   144     TUint16 propertyCode = aPropListElement.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode );
       
   145     TUint16 dataType = aPropListElement.Uint16L( CMTPTypeObjectPropListElement::EDatatype );
       
   146     PRINT3( _L( "MM MTP <> handle = 0x%x, propertyCode = 0x%x, dataType = 0x%x" ),
       
   147         handle, propertyCode, dataType );
       
   148 
       
   149     responseCode = MmMtpDpUtility::CheckPropType( propertyCode, dataType );
       
   150     PRINT1( _L( "MM MTP <> CheckPropType response code is 0x%x" ), responseCode );
       
   151     if( responseCode != EMTPRespCodeOK )
       
   152         return responseCode;
       
   153 
       
   154     if ( iFramework.ObjectMgr().ObjectOwnerId( handle )
       
   155         == iFramework.DataProviderId() )
       
   156         {
       
   157         PRINT( _L( "MM MTP => CSetObjectPropList::SetObjectPropListL enter" ) );
       
   158         CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC(); // + object
       
   159         iFramework.ObjectMgr().ObjectL( handle, *object );
       
   160 
       
   161         if ( protectionStatus.Value() != EMTPProtectionNoProtection )
       
   162             {
       
   163             //for some reason, P4S expects Access Denied response instead of write protected
       
   164             return EMTPRespCodeAccessDenied; // EMTPRespCodeObjectWriteProtected;
       
   165             }
       
   166 
       
   167         switch ( propertyCode )
       
   168             {
       
   169             case EMTPObjectPropCodeStorageID:
       
   170             case EMTPObjectPropCodeObjectFormat:
       
   171             case EMTPObjectPropCodeProtectionStatus:
       
   172             case EMTPObjectPropCodeObjectSize:
       
   173             case EMTPObjectPropCodeParentObject:
       
   174             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
       
   175             case EMTPObjectPropCodeNonConsumable:
       
   176             case EMTPObjectPropCodeDateAdded:
       
   177             case EMTPObjectPropCodeDateCreated:
       
   178             case EMTPObjectPropCodeDateModified:
       
   179                 {
       
   180                 responseCode = EMTPRespCodeAccessDenied;
       
   181                 }
       
   182                 break;
       
   183 
       
   184             case EMTPObjectPropCodeObjectFileName:
       
   185                 {
       
   186                 TPtrC suid( object->DesC( CMTPObjectMetaData::ESuid ) );
       
   187                 TBuf<KMaxFileName> newSuid( aPropListElement.StringL(
       
   188                     CMTPTypeObjectPropListElement::EValue ) );
       
   189                 TInt err = KErrNone;
       
   190                 err = MmMtpDpUtility::UpdateObjectFileName( iFramework.Fs(), suid, newSuid );
       
   191                 PRINT1( _L( "MM MTP <> Update object file name err = %d" ), err );
       
   192                 if ( KErrOverflow == err ) // full path name is too long
       
   193                     {
       
   194                     responseCode = EMTPRespCodeInvalidDataset;
       
   195                     }
       
   196                 else if ( ( KErrNone == err ) || ( KErrAlreadyExists == err ) )
       
   197                     {
       
   198                     TRAP( err, iDpConfig.GetWrapperL().RenameObjectL( suid, newSuid ) ); //Update MPX DB
       
   199                     PRINT1( _L( "MM MTP <> Rename Object err = %d" ), err );
       
   200                     // it is ok if file is not found in DB, following S60 solution
       
   201                     if ( KErrNotFound == err )
       
   202                         {
       
   203                         TRAP( err, iDpConfig.GetWrapperL().AddObjectL( newSuid ) );
       
   204                         PRINT1( _L( "MM MTP <> Add Object err = %d" ), err );
       
   205                         }
       
   206 
       
   207                     if ( KErrNone == err )
       
   208                         {
       
   209                         object->SetDesCL( CMTPObjectMetaData::ESuid, newSuid );
       
   210                         iFramework.ObjectMgr().ModifyObjectL( *object );
       
   211                         }
       
   212                     else
       
   213                         {
       
   214                         responseCode = EMTPRespCodeGeneralError;
       
   215                         }
       
   216                     }
       
   217                 }
       
   218                 break;
       
   219 
       
   220             case EMTPObjectPropCodeName:
       
   221                 {
       
   222                 CMTPTypeString* stringData = CMTPTypeString::NewLC(
       
   223                     aPropListElement.StringL(
       
   224                         CMTPTypeObjectPropListElement::EValue ) );// + stringData
       
   225 
       
   226                 responseCode = ServiceMetaDataToWrapperL( propertyCode,
       
   227                     *stringData, *object );
       
   228 
       
   229                 CleanupStack::PopAndDestroy( stringData );// - stringData
       
   230                 }
       
   231                 break;
       
   232 
       
   233             default:
       
   234                 {
       
   235                 /*// trap and handle with response code here, so correct fail index should report
       
   236                 TRAPD( err, responseCode = ServiceSpecificObjectPropertyL( propertyCode, *object, aPropListElement ) );
       
   237                 PRINT1( _L("MM MTP <> CSetObjectPropList::SetObjectPropListL, ServiceSpecificObjectPropertyL, err = %d"), err );
       
   238 
       
   239                 if ( err == KErrNotSupported )
       
   240                     {
       
   241                     responseCode = EMTPRespCodeAccessDenied;
       
   242                     }*/
       
   243                 responseCode = ServiceSpecificObjectPropertyL( propertyCode, *object,
       
   244                     aPropListElement );
       
   245                 }
       
   246                 break;
       
   247             }
       
   248 
       
   249         CleanupStack::PopAndDestroy( object ); // - object
       
   250         }
       
   251 
       
   252     PRINT1( _L( "MM MTP <= CSetObjectPropList::SetObjectPropListL responseCode = 0x%x" ), responseCode );
       
   253     return responseCode;
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CSetObjectPropList::HasDataphase
       
   258 // Decide if has data phase
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 EXPORT_C TBool CSetObjectPropList::HasDataphase() const
       
   262     {
       
   263     return ETrue;
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CSetObjectPropList::ServiceMetaDataToWrapperL
       
   268 //
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 EXPORT_C TMTPResponseCode CSetObjectPropList::ServiceMetaDataToWrapperL(
       
   272     const TUint16 aPropCode,
       
   273     MMTPType& aNewData,
       
   274     const CMTPObjectMetaData& aObjectMetaData )
       
   275     {
       
   276     TMTPResponseCode resCode = EMTPRespCodeOK;
       
   277 
       
   278     TRAPD( err, iDpConfig.GetWrapperL().SetObjectMetadataValueL( aPropCode,
       
   279         aNewData,
       
   280         aObjectMetaData ) );
       
   281 
       
   282     PRINT1( _L("MM MTP <> CSetObjectPropList::ServiceMetaDataToWrapperL err = %d"), err);
       
   283 
       
   284     if ( err == KErrNone )
       
   285         {
       
   286         resCode = EMTPRespCodeOK;
       
   287         }
       
   288     else if ( err == KErrTooBig )
       
   289         // according to the codes of S60
       
   290         {
       
   291         resCode = EMTPRespCodeInvalidDataset;
       
   292         }
       
   293     else if ( err == KErrPermissionDenied )
       
   294         {
       
   295         resCode = EMTPRespCodeAccessDenied;
       
   296         }
       
   297     else if ( err == KErrNotFound )
       
   298         {
       
   299         if( MmMtpDpUtility::HasMetadata( aObjectMetaData.Uint( CMTPObjectMetaData::EFormatCode ) ) )
       
   300             SendResponseL( EMTPRespCodeAccessDenied );
       
   301         }
       
   302     else
       
   303         {
       
   304         // add new virtual call to see if the above condition can be handle probably
       
   305         err = HandleSpecificWrapperError( err, aObjectMetaData );
       
   306 
       
   307         if ( err != KErrNone )
       
   308             resCode = EMTPRespCodeGeneralError;
       
   309         }
       
   310 
       
   311     PRINT1( _L( "MM MTP <= CSetObjectPropList::ServiceMetaDataToWrapperL resCode = 0x%x" ), resCode );
       
   312 
       
   313     return resCode;
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CSetObjectPropList::RunL
       
   318 //
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 EXPORT_C void CSetObjectPropList::RunL()
       
   322     {
       
   323     if ( iUnprocessedIndex <  iElementCount )
       
   324         {
       
   325         TMTPResponseCode responseCode = SetObjectPropListL( iPropertyList->GetNextElementL());
       
   326 
       
   327         if ( responseCode != EMTPRespCodeOK )
       
   328             {
       
   329             SendResponseL( responseCode, 1, &iUnprocessedIndex );
       
   330             }
       
   331         else
       
   332             {
       
   333             // Complete ourselves with current TRequestStatus
       
   334             // Increase index to process next handle on next round
       
   335             iUnprocessedIndex++;
       
   336             TRequestStatus* status = &iStatus;
       
   337             User::RequestComplete( status, iStatus.Int() );
       
   338             SetActive();
       
   339             }
       
   340         }
       
   341     else // all handles processed, can send data
       
   342         {
       
   343         SendResponseL( EMTPRespCodeOK );
       
   344         }
       
   345     }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CSetObjectPropList::RunError
       
   349 //
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 EXPORT_C TInt CSetObjectPropList::RunError( TInt aError )
       
   353     {
       
   354     PRINT1( _L( "MM MTP <> CSetObjectPropList::RunError with error %d" ), aError );
       
   355 
       
   356     // Reschedule ourselves
       
   357     // TODO: go to next index or increase?
       
   358     // iUnprocessedIndex++
       
   359 //    TRequestStatus* status = &iStatus;
       
   360 //    User::RequestComplete( status, aError );
       
   361 //    SetActive();
       
   362     PRINT1( _L( "MM MTP <> CGetObjectPropList::RunError aError = %d" ), aError );
       
   363     TRAP_IGNORE( SendResponseL( EMTPRespCodeGeneralError ) );
       
   364 
       
   365     return KErrNone;
       
   366     }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CSetObjectPropList::DoCancel()
       
   370 // Cancel the process
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 EXPORT_C void CSetObjectPropList::DoCancel()
       
   374     {
       
   375 
       
   376     }
       
   377 
       
   378 // end of file