mtpfws/mtpfw/dataproviders/dputility/src/cmtpgetpartialobject.cpp
changeset 0 d0791faffa3f
child 2 4843bb5893b6
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <f32file.h>
       
    17 
       
    18 #include <mtp/cmtptypefile.h>
       
    19 #include <mtp/cmtpobjectmetadata.h>
       
    20 #include <mtp/mmtpdataproviderframework.h>
       
    21 #include <mtp/mmtpobjectmgr.h>
       
    22 #include <mtp/mmtpstoragemgr.h>
       
    23 #include <mtp/mtpprotocolconstants.h>
       
    24 #include <mtp/tmtptyperequest.h>
       
    25 
       
    26 #include "cmtpgetpartialobject.h"
       
    27 #include "mtpdppanic.h"
       
    28 
       
    29 // Class constants.
       
    30 __FLOG_STMT(_LIT8(KComponent,"GetObject");)
       
    31 
       
    32 /**
       
    33 Verification data for the GetNumObjects request
       
    34 */
       
    35 const TMTPRequestElementInfo KMTPGetPartialObjectPolicy[] = 
       
    36     {
       
    37         {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeObjectHandle, EMTPElementAttrFile, 0, 0, 0}
       
    38     };
       
    39 
       
    40 /**
       
    41 Two-phase construction method
       
    42 @param aPlugin	The data provider plugin
       
    43 @param aFramework	The data provider framework
       
    44 @param aConnection	The connection from which the request comes
       
    45 @return a pointer to the created request processor object
       
    46 */     
       
    47 EXPORT_C MMTPRequestProcessor* CMTPGetPartialObject::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
       
    48 	{
       
    49 	CMTPGetPartialObject* self = new (ELeave) CMTPGetPartialObject(aFramework, aConnection);
       
    50 	CleanupStack::PushL(self);
       
    51 	self->ConstructL();
       
    52 	CleanupStack::Pop(self);
       
    53 	return self;
       
    54 	}
       
    55 
       
    56 /**
       
    57 Destructor
       
    58 */	
       
    59 EXPORT_C CMTPGetPartialObject::~CMTPGetPartialObject()
       
    60 	{	
       
    61     __FLOG(_L8("~CMTPGetPartialObject - Entry"));
       
    62 	delete iFileObject;
       
    63     __FLOG(_L8("~CMTPGetPartialObject - Exit"));
       
    64     __FLOG_CLOSE;
       
    65 	}
       
    66 	
       
    67 /**
       
    68 Standard c++ constructor
       
    69 */	
       
    70 CMTPGetPartialObject::CMTPGetPartialObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : 
       
    71     CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPGetPartialObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPGetPartialObjectPolicy)
       
    72 	{
       
    73 	
       
    74 	}
       
    75 
       
    76 /**
       
    77 Second-phase constructor.
       
    78 */        
       
    79 void CMTPGetPartialObject::ConstructL()
       
    80     {
       
    81     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    82     __FLOG(_L8("ConstructL - Entry"));
       
    83     __FLOG(_L8("ConstructL - Exit"));
       
    84     }
       
    85 
       
    86 /**
       
    87 Check the GetPartialObject reqeust
       
    88 @return EMTPRespCodeOK if the request is good, otherwise, one of the error response codes
       
    89 */  
       
    90 TMTPResponseCode CMTPGetPartialObject::CheckRequestL()
       
    91     {
       
    92     __FLOG(_L8("CheckRequestL - Entry"));
       
    93     TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL();
       
    94     if(result == EMTPRespCodeOK)
       
    95         {
       
    96         TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    97         iOffset = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
       
    98         iLength = Request().Uint32(TMTPTypeRequest::ERequestParameter3);
       
    99         
       
   100         //does not take ownership
       
   101         iObjectInfo = iRequestChecker->GetObjectInfo(objectHandle);
       
   102         if (!iObjectInfo)
       
   103             {
       
   104             // The object handle has already been checked, so an invalid handle can
       
   105             // only occur if it was invalidated during a context switch between
       
   106             // the validation time and now.
       
   107             result = EMTPRespCodeInvalidObjectHandle;
       
   108             }
       
   109         else
       
   110             {
       
   111             TEntry fileEntry;
       
   112             User::LeaveIfError(iFramework.Fs().Entry(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), fileEntry));
       
   113 
       
   114             if((iOffset >= fileEntry.iSize)) 
       
   115                 {
       
   116                 result = EMTPRespCodeInvalidParameter;
       
   117                 }
       
   118             }
       
   119         }
       
   120 
       
   121     __FLOG(_L8("CheckRequestL - Exit"));
       
   122     return result;  
       
   123     }
       
   124 
       
   125 /**
       
   126 GetObject request handler
       
   127 */		
       
   128 void CMTPGetPartialObject::ServiceL()
       
   129 	{
       
   130     __FLOG(_L8("ServiceL - Entry"));
       
   131     
       
   132 	if (!iObjectInfo)
       
   133 	    {
       
   134 	    SendResponseL(EMTPRespCodeInvalidObjectHandle);
       
   135 	    }
       
   136     else
       
   137         {
       
   138         delete iFileObject;
       
   139         iFileObject = CMTPTypeFile::NewL(iFramework.Fs(), iObjectInfo->DesC(CMTPObjectMetaData::ESuid), EFileRead, iLength, iOffset);
       
   140     	SendDataL(*iFileObject);
       
   141         }
       
   142 	
       
   143     __FLOG(_L8("ServiceL - Exit"));
       
   144 	}
       
   145 
       
   146 /**
       
   147 Handle the response phase of the current request
       
   148 @return EFalse
       
   149 */		
       
   150 TBool CMTPGetPartialObject::DoHandleResponsePhaseL()
       
   151 	{
       
   152     __FLOG(_L8("DoHandleResponsePhaseL - Entry"));
       
   153     __ASSERT_DEBUG(iFileObject, Panic(EMTPDpObjectNull));
       
   154 
       
   155     TUint32 dataLength = iFileObject->GetByteSent();
       
   156 	SendResponseL(EMTPRespCodeOK, 1, &dataLength);
       
   157 	
       
   158     __FLOG(_L8("DoHandleResponsePhaseL - Exit"));
       
   159 	return EFalse;
       
   160 	}
       
   161 
       
   162