mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/csetobjectreferences.cpp
changeset 0 a2952bb97e68
child 14 05b0d2323768
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: SetObjectReferences
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mtp/cmtptypearray.h>
       
    20 #include <mtp/mmtpobjectmgr.h>
       
    21 #include <mtp/mmtpdataproviderframework.h>
       
    22 #include <mtp/mmtpreferencemgr.h>
       
    23 
       
    24 #include "csetobjectreferences.h"
       
    25 #include "tmmmtpdppanic.h"
       
    26 #include "mmmtpdplogger.h"
       
    27 #include "cmmmtpdpmetadataaccesswrapper.h"
       
    28 #include "mmmtpdputility.h"
       
    29 #include "mmmtpdpconfig.h"
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // Verification data for the SetReferences request
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 const TMTPRequestElementInfo KMTPSetObjectReferencesPolicy[] =
       
    36     {
       
    37         {
       
    38         TMTPTypeRequest::ERequestParameter1,
       
    39         EMTPElementTypeObjectHandle,
       
    40         EMTPElementAttrNone,
       
    41         0,
       
    42         0,
       
    43         0
       
    44         }
       
    45     };
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CSetObjectReferences::NewL
       
    49 // Two-phase construction method
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C MMmRequestProcessor* CSetObjectReferences::NewL( MMTPDataProviderFramework& aFramework,
       
    53     MMTPConnection& aConnection,
       
    54     MMmMtpDpConfig& aDpConfig )
       
    55     {
       
    56     CSetObjectReferences* self = new ( ELeave ) CSetObjectReferences( aFramework,
       
    57         aConnection,
       
    58         aDpConfig );
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CSetObjectReferences::ConstructL
       
    67 // Two-phase construction method
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CSetObjectReferences::ConstructL()
       
    71     {
       
    72     SetPSStatus();
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CSetObjectReferences::~CSetObjectReferences
       
    77 // Destructor
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 EXPORT_C CSetObjectReferences::~CSetObjectReferences()
       
    81     {
       
    82     delete iReferences;
       
    83     delete iReferenceSuids;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CSetObjectReferences::CSetObjectReferences
       
    88 // Standard c++ constructor
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 EXPORT_C CSetObjectReferences::CSetObjectReferences(
       
    92     MMTPDataProviderFramework& aFramework,
       
    93     MMTPConnection& aConnection,
       
    94     MMmMtpDpConfig& aDpConfig ) :
       
    95     CRequestProcessor(
       
    96         aFramework,
       
    97         aConnection,
       
    98         sizeof( KMTPSetObjectReferencesPolicy )/sizeof( TMTPRequestElementInfo ),
       
    99         KMTPSetObjectReferencesPolicy ),
       
   100     iDpConfig( aDpConfig )
       
   101     {
       
   102     PRINT( _L( "Operation: SetObjectReferences(0x9811)" ) );
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CSetObjectReferences::DoSetObjectReferencesL
       
   107 // set references to DB
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void CSetObjectReferences::DoSetObjectReferencesL( CMmMtpDpMetadataAccessWrapper& aWrapper,
       
   111     TUint16 aObjectFormat,
       
   112     const TDesC& aSrcFileName,
       
   113     CDesCArray& aRefFileArray )
       
   114     {
       
   115     // do nothing, do special thing by inheriting
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CSetObjectReferences::ServiceL
       
   120 // SetReferences request handler
       
   121 // start receiving reference data from the initiator
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C void CSetObjectReferences::ServiceL()
       
   125     {
       
   126     PRINT( _L( "MM MTP => CSetObjectReferences::ServiceL" ) );
       
   127     delete iReferences;
       
   128     iReferences = NULL;
       
   129     iReferences = CMTPTypeArray::NewL( EMTPTypeAUINT32 );
       
   130     ReceiveDataL( *iReferences );
       
   131     PRINT( _L( "MM MTP <= CSetObjectReferences::ServiceL" ) );
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CSetObjectReferences::DoHandleResponsePhaseL
       
   136 // Apply the references to the specified object
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 EXPORT_C TBool CSetObjectReferences::DoHandleResponsePhaseL()
       
   140     {
       
   141     PRINT( _L("MM MTP => CSetObjectReferences::DoHandleResponsePhaseL" ) );
       
   142 
       
   143     delete iReferenceSuids;
       
   144     iReferenceSuids = NULL;
       
   145     iReferenceSuids = new ( ELeave ) CDesCArrayFlat( 3 );
       
   146 
       
   147     if ( !VerifyReferenceHandlesL() )
       
   148         {
       
   149         SendResponseL( EMTPRespCodeInvalidObjectReference );
       
   150         }
       
   151     else
       
   152         {
       
   153         MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr();
       
   154         TUint32 objectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
       
   155         PRINT1( _L( "MM MTP <>CSetObjectReferences::DoHandleResponsePhaseL objectHandle = 0x%x" ), objectHandle );
       
   156         referenceMgr.SetReferencesL( TMTPTypeUint32( objectHandle ),
       
   157             *iReferences );
       
   158 
       
   159         CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC(); // + object
       
   160         iFramework.ObjectMgr().ObjectL( objectHandle, *object );
       
   161         PRINT1( _L( "MM MTP <> object file name is %S" ), &(object->DesC( CMTPObjectMetaData::ESuid ) ) );
       
   162         DoSetObjectReferencesL( iDpConfig.GetWrapperL(),
       
   163             object->Uint( CMTPObjectMetaData::EFormatCode ),
       
   164             object->DesC( CMTPObjectMetaData::ESuid ),
       
   165             *iReferenceSuids );
       
   166 
       
   167         CleanupStack::PopAndDestroy( object ); // - object
       
   168 
       
   169         SendResponseL( EMTPRespCodeOK );
       
   170         }
       
   171     PRINT( _L("MM MTP <= CSetObjectReferences::DoHandleResponsePhaseL" ) );
       
   172     return EFalse;
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CSetObjectReferences::VerifyReferenceHandlesL
       
   177 // Verify if the references are valid handles to objects
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 TBool CSetObjectReferences::VerifyReferenceHandlesL() const
       
   181     {
       
   182     PRINT( _L( "MM MTP => CSetObjectReferences::VerifyReferenceHandlesL" ) );
       
   183     __ASSERT_DEBUG( iReferences, Panic( EMmMTPDpReferencesNull ) );
       
   184     TBool result = ETrue;
       
   185     TInt count = iReferences->NumElements();
       
   186     PRINT1( _L( "MM MTP <> CSetObjectReferences::VerifyReferenceHandlesL count = %d" ), count );
       
   187     CMTPObjectMetaData* object( CMTPObjectMetaData::NewLC() ); // + object
       
   188     MMTPObjectMgr& objectMgr = iFramework.ObjectMgr();
       
   189 
       
   190     for ( TInt i = 0; i < count; i++ )
       
   191         {
       
   192         TMTPTypeUint32 handle;
       
   193         iReferences->ElementL( i, handle );
       
   194         if ( !objectMgr.ObjectL( handle, *object ) )
       
   195             {
       
   196             result = EFalse;
       
   197             break;
       
   198             }
       
   199 
       
   200         iReferenceSuids->AppendL( object->DesC( CMTPObjectMetaData::ESuid ) );
       
   201         }
       
   202     CleanupStack::PopAndDestroy( object ); // - object
       
   203     PRINT( _L( "MM MTP <= CSetObjectReferences::VerifyReferenceHandlesL" ) );
       
   204     return result;
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CSetObjectReferences::HasDataphase
       
   209 // Derived from CRequestProcessor, can not be neglected
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 EXPORT_C TBool CSetObjectReferences::HasDataphase() const
       
   213     {
       
   214     return ETrue;
       
   215     }
       
   216 
       
   217 // end of file