mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetobject.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: GetObject
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mtp/mmtpdataproviderframework.h>
       
    20 #include <mtp/cmtpobjectmetadata.h>
       
    21 #include <mtp/cmtptypefile.h>
       
    22 
       
    23 #include "cgetobject.h"
       
    24 #include "mmmtpdplogger.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // Verification data for the GetNumObjects request
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 const TMTPRequestElementInfo KMTPGetObjectPolicy[] =
       
    31     {
       
    32         {
       
    33         TMTPTypeRequest::ERequestParameter1,
       
    34         EMTPElementTypeObjectHandle,
       
    35         EMTPElementAttrFile,
       
    36         0,
       
    37         0,
       
    38         0
       
    39         }
       
    40     };
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CGetObject::NewL
       
    44 // Two-phase construction method
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 EXPORT_C MMmRequestProcessor* CGetObject::NewL( MMTPDataProviderFramework& aFramework,
       
    48     MMTPConnection& aConnection,
       
    49     MMmMtpDpConfig& /*aDpConfig*/ )
       
    50     {
       
    51     CGetObject* self = new ( ELeave ) CGetObject( aFramework, aConnection );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CGetObject::ConstructL
       
    60 // Two-phase construction method
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CGetObject::ConstructL()
       
    64     {
       
    65     SetPSStatus();
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CGetObject::~CGetObject
       
    70 // Destructor
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C CGetObject::~CGetObject()
       
    74     {
       
    75     PRINT( _L( "MM MTP => CGetObject::~CGetObject" ) );
       
    76     delete iFileObject;
       
    77     PRINT( _L( "MM MTP <= CGetObject::~CGetObject" ) );
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CGetObject::CGetObject
       
    82 // Standard c++ constructor
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CGetObject::CGetObject( MMTPDataProviderFramework& aFramework,
       
    86     MMTPConnection& aConnection ) :
       
    87     CRequestProcessor( aFramework,
       
    88         aConnection,
       
    89         sizeof( KMTPGetObjectPolicy ) / sizeof( TMTPRequestElementInfo ),
       
    90         KMTPGetObjectPolicy ),
       
    91     iFs( iFramework.Fs() ),
       
    92     iError( EMTPRespCodeOK )
       
    93     {
       
    94     PRINT( _L( "Operation: GetObject(0x1009)" ) );
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CGetObject::ServiceL
       
    99 // GetObject request handler
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CGetObject::ServiceL()
       
   103     {
       
   104     PRINT( _L( "MM MTP => CGetObject::ServiceL" ) );
       
   105 
       
   106     // Get the objectinfo
       
   107     TUint32 objectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
       
   108     PRINT1( _L( "MM MTP <> CGetObject::ServiceL objectHandle = 0x%x" ), objectHandle );
       
   109 
       
   110     // NOTE: shouldn't be deleted in destructor, don't have the ownership
       
   111     iObjectInfo = iRequestChecker->GetObjectInfo( objectHandle );
       
   112 
       
   113     if ( iObjectInfo != NULL )
       
   114         {
       
   115         // Get the file
       
   116         GetObjectL( iObjectInfo->DesC( CMTPObjectMetaData::ESuid  ) );
       
   117 
       
   118         // Send the data (file)
       
   119         SendDataL( *iFileObject );
       
   120         }
       
   121     else
       
   122         {
       
   123         // The object handle has already been checked, so an invalid handle can
       
   124         // only occur if it was invalidated during a context switch between
       
   125         // the validation time and now.
       
   126         iError = EMTPRespCodeInvalidObjectHandle;
       
   127         }
       
   128 
       
   129     PRINT1( _L( "MM MTP <= CGetObject::ServiceL iError = 0x%x" ), iError );
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CGetObject::GetObjectL
       
   134 //
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CGetObject::GetObjectL( const TDesC& aFileName )
       
   138     {
       
   139     PRINT( _L( "MM MTP => CGetObject::GetObjectL" ) );
       
   140 
       
   141     // Create the file object
       
   142     delete iFileObject;
       
   143     iFileObject = NULL;
       
   144     iFileObject = CMTPTypeFile::NewL( iFs, aFileName, EFileRead  );
       
   145 
       
   146     PRINT( _L( "MM MTP <= CGetObject::GetObjectL" ) );
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CGetObject::DoHandleResponsePhaseL
       
   151 // Handle the response phase of the current request
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TBool CGetObject::DoHandleResponsePhaseL()
       
   155     {
       
   156     PRINT( _L( "MM MTP => CGetObject::DoHandleResponsePhaseL" ) )
       
   157 
       
   158     TMTPResponseCode responseCode = ( iCancelled ? EMTPRespCodeIncompleteTransfer : iError );
       
   159     SendResponseL( responseCode );
       
   160 
       
   161     PRINT1( _L( "MM MTP <= CGetObject::DoHandleResponsePhaseL responseCode = 0x%x" ),  responseCode );
       
   162 
       
   163     return EFalse;
       
   164     }
       
   165 
       
   166 // end of file