examples/RemoteConn/MtpDataProviderExample/src/cmtpexampledprequestprocessor.cpp

00001 /*
00002 Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description: 
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 

Generated by  doxygen 1.6.2