mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/csetobjectproplist.cpp
branchRCL_3
changeset 9 bee149131e4b
parent 0 a2952bb97e68
child 14 05b0d2323768
equal deleted inserted replaced
4:d45095c2f4f3 9:bee149131e4b
    25 #include "csetobjectproplist.h"
    25 #include "csetobjectproplist.h"
    26 #include "cmmmtpdpmetadataaccesswrapper.h"
    26 #include "cmmmtpdpmetadataaccesswrapper.h"
    27 #include "mmmtpdputility.h"
    27 #include "mmmtpdputility.h"
    28 #include "mmmtpdplogger.h"
    28 #include "mmmtpdplogger.h"
    29 #include "mmmtpdpconfig.h"
    29 #include "mmmtpdpconfig.h"
    30 
    30 #include "cpropertysettingutility.h"
    31 // -----------------------------------------------------------------------------
    31 
    32 // CSetObjectPropList::NewL
    32 // -----------------------------------------------------------------------------
       
    33 // CSendObject::NewL
    33 // Two-phase construction method
    34 // Two-phase construction method
    34 // -----------------------------------------------------------------------------
    35 // -----------------------------------------------------------------------------
    35 //
    36 //
    36 //EXPORT_C MMmRequestProcessor* CSetObjectPropList::NewL( MMTPDataProviderFramework& aFramework,
    37 EXPORT_C MMmRequestProcessor* CSetObjectPropList::NewL( MMTPDataProviderFramework& aFramework,
    37 //    MMTPConnection& aConnection,
    38     MMTPConnection& aConnection,
    38 //    CMmMtpDpMetadataAccessWrapper& aWrapper )
    39     MMmMtpDpConfig& aDpConfig )
    39 //    {
    40     {
    40 //    CSetObjectPropList* self = new ( ELeave ) CSetObjectPropList( aFramework,
    41     CSetObjectPropList* self = new ( ELeave ) CSetObjectPropList( aFramework, aConnection, aDpConfig );
    41 //        aConnection,
    42 
    42 //        aWrapper );
    43     CleanupStack::PushL(self);
    43 //    CleanupStack::PushL( self );
    44     self->ConstructL();
    44 //    self->ConstructL();
    45     CleanupStack::Pop(self);
    45 //    CleanupStack::Pop( self );
    46 
    46 //    return self;
    47     return self;
    47 //    }
    48     }
    48 
    49 
    49 // -----------------------------------------------------------------------------
    50 // -----------------------------------------------------------------------------
    50 // CSetObjectPropList::CSetObjectPropList
    51 // CSetObjectPropList::CSetObjectPropList
    51 // Standard c++ constructor
    52 // Standard c++ constructor
    52 // -----------------------------------------------------------------------------
    53 // -----------------------------------------------------------------------------
    53 //
    54 //
    54 EXPORT_C CSetObjectPropList::CSetObjectPropList( MMTPDataProviderFramework& aFramework,
    55 CSetObjectPropList::CSetObjectPropList( MMTPDataProviderFramework& aFramework,
    55     MMTPConnection& aConnection,
    56     MMTPConnection& aConnection,
    56     MMmMtpDpConfig& aDpConfig ) :
    57     MMmMtpDpConfig& aDpConfig ) :
    57     CRequestProcessor( aFramework, aConnection, 0, NULL),
    58         CRequestProcessor( aFramework, aConnection, 0, NULL),
    58     iObjectMgr( aFramework.ObjectMgr() ),
    59         iObjectMgr( aFramework.ObjectMgr() ),
    59     iFs( aFramework.Fs() ),
    60         iFs( aFramework.Fs() ),
    60     iDpConfig( aDpConfig ),
    61         iDpConfig( aDpConfig ),
    61     iUnprocessedIndex ( 0 )
    62         iUnprocessedIndex ( 0 )
    62     {
    63     {
    63     PRINT( _L( "Operation: SetObjectPropList(0x9806)" ) );
    64     PRINT( _L( "Operation: SetObjectPropList(0x9806)" ) );
    64     }
    65     }
    65 
    66 
    66 // -----------------------------------------------------------------------------
    67 // -----------------------------------------------------------------------------
    67 // CSetObjectPropList::ConstructL
    68 // CSetObjectPropList::ConstructL
    68 // 2nd Phase Constructor
    69 // 2nd Phase Constructor
    69 // -----------------------------------------------------------------------------
    70 // -----------------------------------------------------------------------------
    70 //
    71 //
    71 EXPORT_C void CSetObjectPropList::ConstructL()
    72 void CSetObjectPropList::ConstructL()
    72     {
    73     {
    73     CActiveScheduler::Add( this );
    74     CActiveScheduler::Add( this );
    74 
    75 
    75     iPropertyList = CMTPTypeObjectPropList::NewL();
    76     iPropertyList = CMTPTypeObjectPropList::NewL();
    76     SetPSStatus();
    77     SetPSStatus();
    83 //
    84 //
    84 EXPORT_C CSetObjectPropList::~CSetObjectPropList()
    85 EXPORT_C CSetObjectPropList::~CSetObjectPropList()
    85     {
    86     {
    86     Cancel();
    87     Cancel();
    87     delete iPropertyList;
    88     delete iPropertyList;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CSetObjectPropList::CheckRequestL
       
    93 //
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C TMTPResponseCode CSetObjectPropList::CheckRequestL()
       
    97     {
       
    98     PRINT( _L( "MM MTP => CSetObjectPropList::CheckRequestL" ) );
       
    99 
       
   100     TMTPResponseCode result = CRequestProcessor::CheckRequestL();
       
   101     if ( result == EMTPRespCodeObjectWriteProtected )
       
   102         {
       
   103         // Return AccessDenied for P4S pass rate, instead of EMTPRespCodeObjectWriteProtected
       
   104         result = EMTPRespCodeAccessDenied;
       
   105         }
       
   106 
       
   107     PRINT( _L( "MM MTP <= CSetObjectPropList::CheckRequestL" ) );
       
   108     return result;
    88     }
   109     }
    89 
   110 
    90 // -----------------------------------------------------------------------------
   111 // -----------------------------------------------------------------------------
    91 // CSetObjectPropList::ServiceL
   112 // CSetObjectPropList::ServiceL
    92 // SetObjectPropList request handler
   113 // SetObjectPropList request handler
   130 // -----------------------------------------------------------------------------
   151 // -----------------------------------------------------------------------------
   131 // CSetObjectPropList::SetObjectPropListL
   152 // CSetObjectPropList::SetObjectPropListL
   132 // Set object proplist
   153 // Set object proplist
   133 // -----------------------------------------------------------------------------
   154 // -----------------------------------------------------------------------------
   134 //
   155 //
   135 TMTPResponseCode CSetObjectPropList::SetObjectPropListL(
   156 TMTPResponseCode CSetObjectPropList::SetObjectPropListL( const CMTPTypeObjectPropListElement& aPropListElement )
   136         const CMTPTypeObjectPropListElement& aPropListElement )
       
   137     {
   157     {
   138     PRINT( _L( "MM MTP => CSetObjectPropList::SetObjectPropListL" ) );
   158     PRINT( _L( "MM MTP => CSetObjectPropList::SetObjectPropListL" ) );
   139 
   159 
   140     TMTPTypeUint16 protectionStatus( EMTPProtectionNoProtection );
       
   141     TMTPResponseCode responseCode( EMTPRespCodeOK );
   160     TMTPResponseCode responseCode( EMTPRespCodeOK );
   142 
   161 
   143     TUint32 handle = aPropListElement.Uint32L( CMTPTypeObjectPropListElement::EObjectHandle );
   162     TUint32 handle = aPropListElement.Uint32L( CMTPTypeObjectPropListElement::EObjectHandle );
   144     TUint16 propertyCode = aPropListElement.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode );
   163     TUint16 propertyCode = aPropListElement.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode );
   145     TUint16 dataType = aPropListElement.Uint16L( CMTPTypeObjectPropListElement::EDatatype );
   164     TUint16 dataType = aPropListElement.Uint16L( CMTPTypeObjectPropListElement::EDatatype );
   146     PRINT3( _L( "MM MTP <> handle = 0x%x, propertyCode = 0x%x, dataType = 0x%x" ),
   165     PRINT3( _L( "MM MTP <> handle = 0x%x, propertyCode = 0x%x, dataType = 0x%x" ),
   147         handle, propertyCode, dataType );
   166         handle,
       
   167         propertyCode,
       
   168         dataType );
   148 
   169 
   149     responseCode = MmMtpDpUtility::CheckPropType( propertyCode, dataType );
   170     responseCode = MmMtpDpUtility::CheckPropType( propertyCode, dataType );
   150     PRINT1( _L( "MM MTP <> CheckPropType response code is 0x%x" ), responseCode );
   171     PRINT1( _L( "MM MTP <> CheckPropType response code is 0x%x" ), responseCode );
       
   172 
   151     if( responseCode != EMTPRespCodeOK )
   173     if( responseCode != EMTPRespCodeOK )
   152         return responseCode;
   174         return responseCode;
   153 
   175 
   154     if ( iFramework.ObjectMgr().ObjectOwnerId( handle )
   176     if ( iFramework.ObjectMgr().ObjectOwnerId( handle )
   155         == iFramework.DataProviderId() )
   177         == iFramework.DataProviderId() )
   156         {
   178         {
   157         PRINT( _L( "MM MTP => CSetObjectPropList::SetObjectPropListL enter" ) );
   179         PRINT( _L( "MM MTP => CSetObjectPropList::SetObjectPropListL enter" ) );
       
   180 
   158         CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC(); // + object
   181         CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC(); // + object
   159         iFramework.ObjectMgr().ObjectL( handle, *object );
   182         iFramework.ObjectMgr().ObjectL( handle, *object );
   160 
   183 
   161         if ( protectionStatus.Value() != EMTPProtectionNoProtection )
   184         // Check the file attribution first. If it is Read-Only, nothing should be set into db which is inlined with P4S cases.
       
   185         TUint16 protectionStatus = EMTPProtectionNoProtection;
       
   186         protectionStatus = MmMtpDpUtility::GetProtectionStatusL( iFs, object->DesC( CMTPObjectMetaData::ESuid ) );
       
   187         if ( protectionStatus != EMTPProtectionNoProtection )
   162             {
   188             {
   163             //for some reason, P4S expects Access Denied response instead of write protected
   189             // NOTE: P4S expects AccessDenied response instead of ObjectWriteProtected
   164             return EMTPRespCodeAccessDenied; // EMTPRespCodeObjectWriteProtected;
   190             return EMTPRespCodeAccessDenied; // EMTPRespCodeObjectWriteProtected;
   165             }
   191             }
   166 
   192 
   167         switch ( propertyCode )
   193         switch ( propertyCode )
   168             {
   194             {
   170             case EMTPObjectPropCodeObjectFormat:
   196             case EMTPObjectPropCodeObjectFormat:
   171             case EMTPObjectPropCodeProtectionStatus:
   197             case EMTPObjectPropCodeProtectionStatus:
   172             case EMTPObjectPropCodeObjectSize:
   198             case EMTPObjectPropCodeObjectSize:
   173             case EMTPObjectPropCodeParentObject:
   199             case EMTPObjectPropCodeParentObject:
   174             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
   200             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
   175             case EMTPObjectPropCodeNonConsumable:
       
   176             case EMTPObjectPropCodeDateAdded:
   201             case EMTPObjectPropCodeDateAdded:
   177             case EMTPObjectPropCodeDateCreated:
   202             case EMTPObjectPropCodeDateCreated:
   178             case EMTPObjectPropCodeDateModified:
   203             case EMTPObjectPropCodeDateModified:
   179                 {
   204                 {
   180                 responseCode = EMTPRespCodeAccessDenied;
   205                 responseCode = EMTPRespCodeAccessDenied;
   181                 }
   206                 }
   182                 break;
   207                 break;
   183 
   208 
       
   209             case EMTPObjectPropCodeNonConsumable:
       
   210                 object->SetUint( CMTPObjectMetaData::ENonConsumable,
       
   211                     aPropListElement.Uint8L( CMTPTypeObjectPropListElement::EValue ) );
       
   212                 // TODO: need to reconsider,
       
   213                 // if propList comprise both non-consumable and objectFileName,
       
   214                 // ModifyObjectL would be called twice, need to investigate if it won't affect
       
   215                 // performance
       
   216                 iFramework.ObjectMgr().ModifyObjectL( *object );
       
   217                 break;
       
   218 
   184             case EMTPObjectPropCodeObjectFileName:
   219             case EMTPObjectPropCodeObjectFileName:
   185                 {
   220                 {
   186                 TPtrC suid( object->DesC( CMTPObjectMetaData::ESuid ) );
   221                 TPtrC suid( object->DesC( CMTPObjectMetaData::ESuid ) );
   187                 TBuf<KMaxFileName> newSuid( aPropListElement.StringL(
   222                 TBuf<KMaxFileName> newSuid( aPropListElement.StringL(
   188                     CMTPTypeObjectPropListElement::EValue ) );
   223                     CMTPTypeObjectPropListElement::EValue ) );
   189                 TInt err = KErrNone;
   224                 TInt err = MmMtpDpUtility::UpdateObjectFileName( iFramework.Fs(), suid, newSuid );
   190                 err = MmMtpDpUtility::UpdateObjectFileName( iFramework.Fs(), suid, newSuid );
       
   191                 PRINT1( _L( "MM MTP <> Update object file name err = %d" ), err );
   225                 PRINT1( _L( "MM MTP <> Update object file name err = %d" ), err );
   192                 if ( KErrOverflow == err ) // full path name is too long
   226                 if ( KErrOverflow == err ) // full path name is too long
   193                     {
   227                     {
   194                     responseCode = EMTPRespCodeInvalidDataset;
   228                     responseCode = EMTPRespCodeInvalidDataset;
   195                     }
   229                     }
   198                     TRAP( err, iDpConfig.GetWrapperL().RenameObjectL( suid, newSuid ) ); //Update MPX DB
   232                     TRAP( err, iDpConfig.GetWrapperL().RenameObjectL( suid, newSuid ) ); //Update MPX DB
   199                     PRINT1( _L( "MM MTP <> Rename Object err = %d" ), err );
   233                     PRINT1( _L( "MM MTP <> Rename Object err = %d" ), err );
   200                     // it is ok if file is not found in DB, following S60 solution
   234                     // it is ok if file is not found in DB, following S60 solution
   201                     if ( KErrNotFound == err )
   235                     if ( KErrNotFound == err )
   202                         {
   236                         {
   203                         TRAP( err, iDpConfig.GetWrapperL().AddObjectL( newSuid ) );
   237                         TUint formatCode = object->Uint( CMTPObjectMetaData::EFormatCode );
       
   238                         TUint subFormatCode = object->Uint( CMTPObjectMetaData::EFormatSubCode );
       
   239                         TRAP( err, iDpConfig.GetWrapperL().AddObjectL( newSuid, formatCode, subFormatCode ) );
   204                         PRINT1( _L( "MM MTP <> Add Object err = %d" ), err );
   240                         PRINT1( _L( "MM MTP <> Add Object err = %d" ), err );
   205                         }
   241                         }
   206 
   242 
   207                     if ( KErrNone == err )
   243                     if ( KErrNone == err )
   208                         {
   244                         {
   218                 break;
   254                 break;
   219 
   255 
   220             case EMTPObjectPropCodeName:
   256             case EMTPObjectPropCodeName:
   221                 {
   257                 {
   222                 CMTPTypeString* stringData = CMTPTypeString::NewLC(
   258                 CMTPTypeString* stringData = CMTPTypeString::NewLC(
   223                     aPropListElement.StringL(
   259                     aPropListElement.StringL( CMTPTypeObjectPropListElement::EValue ) );// + stringData
   224                         CMTPTypeObjectPropListElement::EValue ) );// + stringData
   260 
   225 
   261                 responseCode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapperL( iDpConfig,
   226                 responseCode = ServiceMetaDataToWrapperL( propertyCode,
   262                     propertyCode,
   227                     *stringData, *object );
   263                     *stringData,
       
   264                     *object );
   228 
   265 
   229                 CleanupStack::PopAndDestroy( stringData );// - stringData
   266                 CleanupStack::PopAndDestroy( stringData );// - stringData
   230                 }
   267                 }
   231                 break;
   268                 break;
   232 
   269 
   233             default:
   270             default:
   234                 {
   271                 {
   235                 /*// trap and handle with response code here, so correct fail index should report
   272                 responseCode = iDpConfig.PropSettingUtility()->SetSpecificObjectPropertyL( iDpConfig,
   236                 TRAPD( err, responseCode = ServiceSpecificObjectPropertyL( propertyCode, *object, aPropListElement ) );
   273                     propertyCode,
   237                 PRINT1( _L("MM MTP <> CSetObjectPropList::SetObjectPropListL, ServiceSpecificObjectPropertyL, err = %d"), err );
   274                     *object,
   238 
       
   239                 if ( err == KErrNotSupported )
       
   240                     {
       
   241                     responseCode = EMTPRespCodeAccessDenied;
       
   242                     }*/
       
   243                 responseCode = ServiceSpecificObjectPropertyL( propertyCode, *object,
       
   244                     aPropListElement );
   275                     aPropListElement );
   245                 }
   276                 }
   246                 break;
   277                 break;
   247             }
   278             }
   248 
   279 
   259 // -----------------------------------------------------------------------------
   290 // -----------------------------------------------------------------------------
   260 //
   291 //
   261 EXPORT_C TBool CSetObjectPropList::HasDataphase() const
   292 EXPORT_C TBool CSetObjectPropList::HasDataphase() const
   262     {
   293     {
   263     return ETrue;
   294     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     }
   295     }
   315 
   296 
   316 // -----------------------------------------------------------------------------
   297 // -----------------------------------------------------------------------------
   317 // CSetObjectPropList::RunL
   298 // CSetObjectPropList::RunL
   318 //
   299 //
   349 //
   330 //
   350 // -----------------------------------------------------------------------------
   331 // -----------------------------------------------------------------------------
   351 //
   332 //
   352 EXPORT_C TInt CSetObjectPropList::RunError( TInt aError )
   333 EXPORT_C TInt CSetObjectPropList::RunError( TInt aError )
   353     {
   334     {
   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 );
   335     PRINT1( _L( "MM MTP <> CGetObjectPropList::RunError aError = %d" ), aError );
       
   336 
   363     TRAP_IGNORE( SendResponseL( EMTPRespCodeGeneralError ) );
   337     TRAP_IGNORE( SendResponseL( EMTPRespCodeGeneralError ) );
   364 
   338 
   365     return KErrNone;
   339     return KErrNone;
   366     }
   340     }
   367 
   341 
   370 // Cancel the process
   344 // Cancel the process
   371 // -----------------------------------------------------------------------------
   345 // -----------------------------------------------------------------------------
   372 //
   346 //
   373 EXPORT_C void CSetObjectPropList::DoCancel()
   347 EXPORT_C void CSetObjectPropList::DoCancel()
   374     {
   348     {
   375 
       
   376     }
   349     }
   377 
   350 
   378 // end of file
   351 // end of file