00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <mtp/mtpprotocolconstants.h>
00031 #include <mtp/tmtptyperequest.h>
00032 #include <mtp/mmtpdataproviderframework.h>
00033 #include <mtp/tmtptypeevent.h>
00034 #include <mtp/mmtpconnection.h>
00035 #include <mtp/mmtpobjectmgr.h>
00036
00037 #include "cmtpexampledprequestprocessor.h"
00038
00039
00048 CMTPExampleDpRequestProcessor::CMTPExampleDpRequestProcessor(
00049 MMTPDataProviderFramework& aFramework,
00050 MMTPConnection& aConnection,
00051 TInt aElementCount,
00052 const TMTPRequestElementInfo* aElements)
00053 :iFramework(aFramework),
00054 iConnection(aConnection),
00055 iElementCount(aElementCount),
00056 iElements(aElements)
00057 {
00058
00059 }
00060
00064 CMTPExampleDpRequestProcessor::~CMTPExampleDpRequestProcessor()
00065 {
00066 }
00070 void CMTPExampleDpRequestProcessor::Release()
00071 {
00072 delete this;
00073 }
00074
00075
00082 void CMTPExampleDpRequestProcessor::SendResponseL(TMTPResponseCode aResponseCode, TInt aParameterCount, TUint32* aParams)
00083 {
00084 iResponse.SetUint16(TMTPTypeResponse::EResponseCode, aResponseCode);
00085
00086 iResponse.SetUint32(TMTPTypeResponse::EResponseSessionID, iSessionId);
00087
00088 iResponse.SetUint32(TMTPTypeResponse::EResponseTransactionID, iTransactionCode);
00089
00090 TInt i = 0;
00091 for(i = 0; i < aParameterCount; i++)
00092 {
00093 iResponse.SetUint32(TMTPTypeResponse::EResponseParameter1 + i, aParams[i]);
00094 }
00095
00096 i += TMTPTypeResponse::EResponseParameter1;
00097 while(i <= TMTPTypeResponse::EResponseParameter5)
00098 {
00099 iResponse.SetUint32(i, KMTPNotSpecified32);
00100 i++;
00101 }
00102 iFramework.SendResponseL(iResponse, *iRequest, iConnection);
00103 }
00108 const TMTPTypeRequest& CMTPExampleDpRequestProcessor::Request() const
00109 {
00110 return *iRequest;
00111 }
00112
00113
00114
00118 void CMTPExampleDpRequestProcessor::CompleteRequestL()
00119 {
00120 iFramework.TransactionCompleteL(*iRequest, iConnection);
00121 }
00122
00123
00130 TBool CMTPExampleDpRequestProcessor::HandleRequestL(const TMTPTypeRequest& aRequest, TMTPTransactionPhase aPhase)
00131 {
00132 iRequest = &aRequest;
00133 TBool result = EFalse;
00134 switch(aPhase)
00135 {
00136 case ERequestPhase:
00137 ExtractSessionTransactionId();
00138 ServiceL();
00139 break;
00140
00141 case EResponsePhase:
00142 result = DoHandleResponsePhaseL();
00143 break;
00144
00145 case ECompletingPhase:
00146 result = DoHandleCompletingPhaseL();
00147 break;
00148 }
00149 return result;
00150 }
00151
00152
00157 MMTPConnection& CMTPExampleDpRequestProcessor::Connection() const
00158 {
00159 return iConnection;
00160 }
00161
00166 TUint32 CMTPExampleDpRequestProcessor::SessionId()
00167 {
00168 return iSessionId;
00169 }
00170
00175 TBool CMTPExampleDpRequestProcessor::DoHandleResponsePhaseL()
00176 {
00177 TMTPResponseCode responseCode = (iCancelled ? EMTPRespCodeIncompleteTransfer : EMTPRespCodeOK);
00178 SendResponseL(responseCode);
00179 return EFalse;
00180 }
00181
00186 TBool CMTPExampleDpRequestProcessor::DoHandleCompletingPhaseL()
00187 {
00188 CompleteRequestL();
00189 return ETrue;
00190 }
00191
00195 void CMTPExampleDpRequestProcessor::ExtractSessionTransactionId()
00196 {
00197 iSessionId = iRequest->Uint32(TMTPTypeRequest::ERequestSessionID);
00198 iTransactionCode = iRequest->Uint32(TMTPTypeRequest::ERequestTransactionID);
00199 }
00200
00201
00208 TBool CMTPExampleDpRequestProcessor::Match(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection) const
00209 {
00210
00211 TUint32 eventSessionId = aEvent.Uint32(TMTPTypeEvent::EEventSessionID);
00212 TUint32 eventTransactionCode = aEvent.Uint32(TMTPTypeEvent::EEventTransactionID);
00213
00214 TBool result = EFalse;
00215 if(iSessionId == eventSessionId &&
00216 iTransactionCode == eventTransactionCode &&
00217 &iConnection == &aConnection)
00218 {
00219 result = ETrue;
00220 }
00221 return result;
00222 }
00223
00230 TBool CMTPExampleDpRequestProcessor::Match(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) const
00231 {
00232 TBool result = ((&aRequest == iRequest) && (&iConnection == &aConnection));
00233 return result;
00234 }
00235
00240 void CMTPExampleDpRequestProcessor::HandleEventL(const TMTPTypeEvent& aEvent)
00241 {
00242 TUint16 eventCode = aEvent.Uint16(TMTPTypeEvent::EEventCode);
00243 iCancelled = (eventCode == EMTPEventCodeCancelTransaction);
00244 }
00245
00246
00247
00248