mtpfws/mtpfw/dataproviders/proxydp/src/cmtpdeleteobjectproplist.cpp
changeset 0 d0791faffa3f
child 15 f85613f12947
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 
       
    17 #include <mtp/mtpprotocolconstants.h>
       
    18 #include <mtp/cmtptypedeleteobjectproplist.h>
       
    19 #include <mtp/tmtptypedatapair.h>
       
    20 #include <mtp/mmtpdataproviderframework.h>
       
    21 
       
    22 #include "cmtpdeleteobjectproplist.h"
       
    23 #include "mtpproxydppanic.h"
       
    24 #include "cmtpdataprovidercontroller.h"
       
    25 #include "cmtpobjectmgr.h"
       
    26 #include "cmtpdataprovider.h"
       
    27 
       
    28 
       
    29 // Class constants.
       
    30 __FLOG_STMT(_LIT8(KComponent,"DeleteObjectPropList");)
       
    31 
       
    32 
       
    33 /**
       
    34 Verification data for the DeleteObjectPropList request
       
    35 */
       
    36 const TMTPRequestElementInfo KMTPDeleteObjectPropListPolicy[] = 
       
    37     {
       
    38         { TMTPTypeRequest::ERequestParameter1, EMTPElementTypeObjectHandle, (EMTPElementAttrDir | EMTPElementAttrWrite), 1, KMTPHandleAll, 0 }
       
    39     };
       
    40 
       
    41 /**
       
    42 Two-phase construction method
       
    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 MMTPRequestProcessor* CMTPDeleteObjectPropList::NewL( MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection )
       
    48     {
       
    49     CMTPDeleteObjectPropList* self = new (ELeave) CMTPDeleteObjectPropList( aFramework, aConnection );
       
    50     CleanupStack::PushL(self);
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop(self);
       
    53     return self;
       
    54     }
       
    55 
       
    56 /**
       
    57 Destructor
       
    58 */ 
       
    59 CMTPDeleteObjectPropList::~CMTPDeleteObjectPropList()
       
    60     {
       
    61     __FLOG(_L8("~CMTPDeleteObjectPropList - Entry"));
       
    62     
       
    63     delete iDeleteObjectPropList;
       
    64     iSingletons.Close();
       
    65     iTargetDps.Close();
       
    66     iSubDatasets.ResetAndDestroy();
       
    67     
       
    68     __FLOG(_L8("~CMTPDeleteObjectPropList - Exit"));
       
    69     __FLOG_CLOSE;
       
    70     }
       
    71 
       
    72 CMTPDeleteObjectPropList::CMTPDeleteObjectPropList(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection):
       
    73 CMTPRequestProcessor( aFramework, aConnection, (sizeof(KMTPDeleteObjectPropListPolicy) / sizeof(TMTPRequestElementInfo)), KMTPDeleteObjectPropListPolicy )
       
    74     {
       
    75     
       
    76     }
       
    77 
       
    78 void CMTPDeleteObjectPropList::ConstructL()
       
    79     {
       
    80     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    81     __FLOG(_L8("ConstructL - Entry"));
       
    82     
       
    83     iSingletons.OpenL();
       
    84     
       
    85     __FLOG(_L8("ConstructL - Exit"));
       
    86     }
       
    87 
       
    88 void CMTPDeleteObjectPropList::ServiceL()
       
    89     {
       
    90     __FLOG(_L8("ServiceL - Entry"));
       
    91     
       
    92     delete iDeleteObjectPropList;
       
    93     iTargetDps.Reset();
       
    94     iSubDatasets.Reset();
       
    95     
       
    96 
       
    97     iDeleteObjectPropList = CMTPTypeDeleteObjectPropList::NewL();
       
    98     ReceiveDataL(*iDeleteObjectPropList);
       
    99 
       
   100     __FLOG(_L8("ServiceL - Exit"));
       
   101     }
       
   102 
       
   103 TBool CMTPDeleteObjectPropList::DoHandleResponsePhaseL()
       
   104     {
       
   105     __FLOG(_L8("DoHandleResponsePhaseL - Entry"));
       
   106       
       
   107     //if the ObjectHandle is 0x00000000, 
       
   108     //discard the received data and return Invalid_ObjectHandle error code
       
   109     if ( Request().Uint32(TMTPTypeRequest::ERequestParameter1) == KMTPHandleNone )
       
   110      {  
       
   111      TRAP_IGNORE(SendResponseL(EMTPRespCodeInvalidObjectHandle));
       
   112      }
       
   113     else
       
   114      {
       
   115      BuildSubRequestsL();
       
   116      
       
   117      if(iTargetDps.Count() == 0)
       
   118     	 {
       
   119     	 TRAP_IGNORE(SendResponseL(EMTPRespCodeInvalidDataset));
       
   120     	 }
       
   121      else
       
   122     	 {
       
   123 	     iCurrentTarget = 0;
       
   124 	     
       
   125 	     Schedule(KErrNone);
       
   126     	 }
       
   127      }
       
   128     
       
   129     __FLOG(_L8("DoHandleResponsePhaseL - Exit"));
       
   130     
       
   131     return EFalse;
       
   132     }
       
   133 
       
   134 void CMTPDeleteObjectPropList::BuildSubRequestsL()
       
   135     {
       
   136     __FLOG(_L8("BuildSubRequests - Entry"));
       
   137 
       
   138     TInt count(iDeleteObjectPropList->NumberOfElements());
       
   139     TInt dpid(0);
       
   140     TInt index(-1);
       
   141     TInt tmpDpid(-1);
       
   142     for( TUint i(0); i < count; i++)
       
   143         {
       
   144         TMTPTypeDataPair& temp(iDeleteObjectPropList->ElementL(i));
       
   145         TMTPTypeDataPair* element = new (ELeave) TMTPTypeDataPair();
       
   146         CleanupStack::PushL(element);
       
   147         MMTPType::CopyL( temp, *element );
       
   148         dpid = iSingletons.ObjectMgr().ObjectOwnerId( temp.Uint32(TMTPTypeDataPair::EOwnerHandle) );
       
   149         if ( tmpDpid != dpid )
       
   150             {
       
   151             iTargetDps.Append(dpid);
       
   152             CMTPTypeDeleteObjectPropList* dataset = CMTPTypeDeleteObjectPropList::NewLC();
       
   153             iSubDatasets.AppendL( dataset );
       
   154             dataset->AppendL( element);
       
   155             CleanupStack::Pop(dataset);
       
   156             
       
   157             tmpDpid = dpid;
       
   158             ++index;
       
   159             }
       
   160         else
       
   161             {          
       
   162             iSubDatasets[index]->AppendL( element );
       
   163             }
       
   164         
       
   165         CleanupStack::Pop(element);
       
   166         }
       
   167     
       
   168     __FLOG(_L8("BuildSubRequests - Exit"));
       
   169     }
       
   170 
       
   171 TBool CMTPDeleteObjectPropList::HasDataphase() const
       
   172     {
       
   173     __FLOG(_L8("HasDataphase - Entry"));
       
   174         
       
   175     
       
   176         
       
   177     __FLOG(_L8("HasDataphase - Exit"));
       
   178     
       
   179     return ETrue;
       
   180     }
       
   181 
       
   182 
       
   183 #ifdef _DEBUG
       
   184 void CMTPDeleteObjectPropList::ProxyReceiveDataL(MMTPType& aData, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus)
       
   185 #else
       
   186 void CMTPDeleteObjectPropList::ProxyReceiveDataL(MMTPType& aData, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus)
       
   187 #endif
       
   188     {
       
   189     __ASSERT_DEBUG(iRequest == &aRequest && &iConnection == &aConnection, Panic(EMTPNotSameRequestProxy));
       
   190 
       
   191     MMTPType::CopyL( *iSubDatasets[iCurrentTarget], aData);
       
   192     TRequestStatus* status = &aStatus;
       
   193     User::RequestComplete(status, KErrNone);
       
   194     }
       
   195 
       
   196 
       
   197 void CMTPDeleteObjectPropList::ProxySendDataL(const MMTPType& /*aData*/, const TMTPTypeRequest&  /*aRequest*/, MMTPConnection& /* aConnection */, TRequestStatus& /*aStatus*/)
       
   198     {
       
   199     __FLOG(_L8("ProxySendDataL - Entry"));
       
   200         
       
   201     Panic(EMTPWrongRequestPhase);
       
   202         
       
   203     __FLOG(_L8("ProxySendDataL - Exit"));
       
   204     }
       
   205 
       
   206 /**
       
   207   Send the corresponding response for the request is routed by Proxy DP
       
   208   ProxySendResponseL will complete the request of framework's AO, then switch the transaction phase to TranscationComplete
       
   209   so ProxyTransactionCompleteL will be called later.
       
   210   @param aResponse      The response which is sent by some DP
       
   211   @param aRequest       The corresponding request 
       
   212   @param aConnection    The corresponding connection
       
   213   @param aStatus        The status of framework AO 
       
   214  */
       
   215 #ifdef _DEBUG    
       
   216 void CMTPDeleteObjectPropList::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus)
       
   217 #else
       
   218 void CMTPDeleteObjectPropList::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus)
       
   219 #endif
       
   220     {
       
   221     __FLOG(_L8("ProxySendResponseL - Entry"));
       
   222     
       
   223     __ASSERT_DEBUG(((iRequest == &aRequest) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy));
       
   224     MMTPType::CopyL(aResponse, iResponse);
       
   225     TRequestStatus* status = &aStatus;
       
   226     User::RequestComplete(status, KErrNone);
       
   227     
       
   228     __FLOG(_L8("ProxySendResponseL - Exit"));
       
   229     }
       
   230 
       
   231 
       
   232 /**
       
   233   Complete the transaction phase for the request is routed by Proxy DP
       
   234   Drive its AO to route other requests or send the response.
       
   235   @param aRequest       The corresponding request 
       
   236   @param aConnection    The corresponding connection
       
   237  */
       
   238 #ifdef _DEBUG
       
   239 void CMTPDeleteObjectPropList::ProxyTransactionCompleteL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
       
   240 #else
       
   241 void CMTPDeleteObjectPropList::ProxyTransactionCompleteL(const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/)
       
   242 #endif
       
   243     {
       
   244     __FLOG(_L8("ProxyTransactionCompleteL - Entry"));
       
   245         
       
   246     __ASSERT_DEBUG(((iRequest == &aRequest) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy));
       
   247     const TUint16 KResponseCode(iResponse.Uint16(TMTPTypeResponse::EResponseCode)); 
       
   248     TInt err((KResponseCode == EMTPRespCodeOK) ? KErrNone : KErrGeneral);    
       
   249     if (err == KErrNone)
       
   250        {
       
   251        ++iCurrentTarget;
       
   252        }
       
   253     else
       
   254         {
       
   255         //when error, calculate the zero-based index of the first failed property
       
   256         TUint index = iResponse.Uint32(TMTPTypeResponse::EResponseParameter1);
       
   257         for(TInt i = 0 ; i < iCurrentTarget; i++ )
       
   258             {
       
   259             index  += iSubDatasets[i]->NumberOfElements();
       
   260             }
       
   261         iResponse.SetUint32(TMTPTypeResponse::EResponseParameter1, index );
       
   262         
       
   263         if(KResponseCode == EMTPRespCodeOperationNotSupported)
       
   264             {
       
   265             iResponse.SetUint16(TMTPTypeResponse::EResponseCode, EMTPRespCodeInvalidObjectHandle );
       
   266             }
       
   267         }
       
   268 
       
   269     Schedule(err);
       
   270         
       
   271     __FLOG(_L8("ProxyTransactionCompleteL - Exit"));
       
   272     }
       
   273 
       
   274 
       
   275     
       
   276 void CMTPDeleteObjectPropList::SendResponseL(TUint16 aCode)
       
   277     {
       
   278     __FLOG(_L8("SendResponseL - Entry"));
       
   279         
       
   280     const TMTPTypeRequest& req(Request());
       
   281     iResponse.SetUint16(TMTPTypeResponse::EResponseCode, aCode);
       
   282     iResponse.SetUint32(TMTPTypeResponse::EResponseSessionID, req.Uint32(TMTPTypeRequest::ERequestSessionID));
       
   283     iResponse.SetUint32(TMTPTypeResponse::EResponseTransactionID, req.Uint32(TMTPTypeRequest::ERequestTransactionID));
       
   284     iFramework.SendResponseL(iResponse, req, Connection());
       
   285         
       
   286     __FLOG(_L8("SendResponseL - Exit"));
       
   287     }
       
   288 
       
   289 void CMTPDeleteObjectPropList::RunL()
       
   290     {
       
   291     __FLOG(_L8("RunL - Entry"));
       
   292     
       
   293     if ( (iStatus == KErrNone) && (iCurrentTarget < iTargetDps.Count()) )    
       
   294         {
       
   295         TUint id(iTargetDps[iCurrentTarget]);
       
   296         
       
   297         if(iSingletons.DpController().IsDataProviderLoaded(id))
       
   298         	{
       
   299         	iSingletons.DpController().DataProviderL(id).ExecuteProxyRequestL( *iRequest, Connection(), *this );
       
   300         	}
       
   301         else
       
   302         	{
       
   303         	 TUint index(0);
       
   304 	         for(TInt i = 0 ; i < iCurrentTarget; i++ )
       
   305 	            {
       
   306 	            index  += iSubDatasets[i]->NumberOfElements();
       
   307 	            }
       
   308 	         iResponse.SetUint32(TMTPTypeResponse::EResponseParameter1, index );
       
   309         	 TRAP_IGNORE(SendResponseL(EMTPRespCodeInvalidObjectHandle));
       
   310         	}
       
   311         }
       
   312     else        
       
   313         {
       
   314         //Any error will stop the process, and send the corresponding response.
       
   315         SendResponseL(iResponse.Uint16(TMTPTypeResponse::EResponseCode));
       
   316         }  
       
   317     
       
   318     __FLOG(_L8("RunL - Exit"));
       
   319     }
       
   320         
       
   321 TInt CMTPDeleteObjectPropList::RunError(TInt /*aError*/)
       
   322     {
       
   323     __FLOG(_L8("RunError - Entry"));
       
   324     
       
   325     TRAP_IGNORE(SendResponseL(EMTPRespCodeGeneralError));
       
   326     
       
   327     __FLOG(_L8("RunError - Exit"));
       
   328     return KErrNone;
       
   329     }
       
   330             
       
   331 /**
       
   332 Completes the current asynchronous request with the specified 
       
   333 completion code.
       
   334 @param aError The asynchronous request completion request.
       
   335 */
       
   336 void CMTPDeleteObjectPropList::Schedule(TInt aError)
       
   337     {
       
   338     __FLOG(_L8("Schedule - Entry"));
       
   339     
       
   340     TRequestStatus* status = &iStatus;
       
   341     User::RequestComplete(status, aError);
       
   342     SetActive();
       
   343     
       
   344     __FLOG(_L8("Schedule - Exit"));
       
   345     }
       
   346 
       
   347