mtpfws/mtpfw/dataproviders/proxydp/src/cmtpsetobjectproplist.cpp
changeset 0 d0791faffa3f
child 6 ef55b168cedb
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 <mtp/cmtpobjectmetadata.h>
       
    17 #include <mtp/cmtptypeobjectinfo.h>
       
    18 #include <mtp/cmtptypeobjectproplist.h>
       
    19 #include <mtp/mmtpdataproviderframework.h>
       
    20 #include <mtp/mtpprotocolconstants.h>
       
    21 #include <mtp/tmtptyperequest.h>
       
    22 
       
    23 #include "cmtpdataprovider.h"
       
    24 #include "cmtpdataprovidercontroller.h"
       
    25 #include "cmtpobjectmgr.h"
       
    26 #include "cmtpparserrouter.h"
       
    27 #include "cmtpsetobjectproplist.h"
       
    28 #include "mtpproxydppanic.h"
       
    29 #include "rmtpframework.h"
       
    30 
       
    31 /**
       
    32 Two-phase construction method
       
    33 @param aFramework    The data provider framework
       
    34 @param aConnection    The connection from which the request comes
       
    35 @return a pointer to the created request processor object
       
    36 */ 
       
    37 MMTPRequestProcessor* CMTPSetObjectPropList::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
       
    38     {
       
    39     CMTPSetObjectPropList* self = new (ELeave) CMTPSetObjectPropList(aFramework, aConnection);
       
    40     CleanupStack::PushL(self);
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop(self);
       
    43     return self;
       
    44     }
       
    45 
       
    46 /**
       
    47 Destructor
       
    48 */    
       
    49 CMTPSetObjectPropList::~CMTPSetObjectPropList()
       
    50     {
       
    51     delete iObjectPropList;
       
    52     iDpList.Close();
       
    53     iSingletons.Close();
       
    54     }
       
    55 
       
    56 /**
       
    57 Standard c++ constructor
       
    58 */    
       
    59 CMTPSetObjectPropList::CMTPSetObjectPropList(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
       
    60     CMTPRequestProcessor(aFramework, aConnection, 0, NULL)
       
    61     {
       
    62     
       
    63     }
       
    64     
       
    65 /**
       
    66 Second phase constructor.
       
    67 */
       
    68 void CMTPSetObjectPropList::ConstructL()
       
    69     {
       
    70     iSingletons.OpenL();
       
    71     }
       
    72 
       
    73 /**
       
    74 SetObjectPropList request handler
       
    75 */    
       
    76 void CMTPSetObjectPropList::ServiceL()
       
    77     {
       
    78     delete iObjectPropList;
       
    79     iObjectPropList = NULL;
       
    80     iObjectPropList = CMTPTypeObjectPropList::NewL();
       
    81     ReceiveDataL(*iObjectPropList);    
       
    82     }
       
    83 
       
    84 /**
       
    85 Override to handle the response phase of SetObjectPropList requests
       
    86 @return EFalse
       
    87 */
       
    88 TBool CMTPSetObjectPropList::DoHandleResponsePhaseL()
       
    89     {
       
    90     iDpIdx = 0;
       
    91     iPropertyIdx = 0;
       
    92     iDpListCreated = EFalse;
       
    93     iPropertyIdx = 0;
       
    94     iDpList.Reset();
       
    95     iObjectPropList->ResetCursor();             
       
    96     Reschedule(KErrNone);
       
    97     return EFalse;
       
    98     }
       
    99 
       
   100 #ifdef _DEBUG
       
   101 void CMTPSetObjectPropList::ProxyReceiveDataL(MMTPType& aData, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus)
       
   102 #else
       
   103 void CMTPSetObjectPropList::ProxyReceiveDataL(MMTPType& aData, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus)
       
   104 #endif
       
   105     {
       
   106     __ASSERT_DEBUG(iRequest == &aRequest && &iConnection == &aConnection, Panic(EMTPNotSameRequestProxy));
       
   107     __ASSERT_DEBUG(aData.Type() == EMTPTypeObjectPropListDataset, Panic(EMTPInvalidDataType));
       
   108     
       
   109 
       
   110 	CMTPTypeObjectPropList* targetObjectPropList = static_cast<CMTPTypeObjectPropList*>(&aData); 
       
   111 	targetObjectPropList->AppendObjectPropListL(*iObjectPropList);
       
   112 
       
   113     TRequestStatus* status = &aStatus;
       
   114     User::RequestComplete(status, KErrNone);
       
   115     }
       
   116     
       
   117 void CMTPSetObjectPropList::ProxySendDataL(const MMTPType& /*aData*/, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& /*aStatus*/)
       
   118     {
       
   119     Panic(EMTPWrongRequestPhase);
       
   120     }
       
   121     
       
   122 #ifdef _DEBUG    
       
   123 void CMTPSetObjectPropList::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus)
       
   124 #else
       
   125 void CMTPSetObjectPropList::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus)
       
   126 #endif
       
   127     {
       
   128     __ASSERT_DEBUG(iRequest == &aRequest && &iConnection == &aConnection, Panic(EMTPNotSameRequestProxy));
       
   129     iResponseCode = static_cast<TMTPResponseCode>(aResponse.Uint16(TMTPTypeResponse::EResponseCode));
       
   130     iPropertyIdx = aResponse.Uint32(TMTPTypeResponse::EResponseParameter1);
       
   131     TRequestStatus* status = &aStatus;
       
   132     User::RequestComplete(status, KErrNone);
       
   133     }
       
   134 
       
   135 #ifdef _DEBUG    
       
   136 void CMTPSetObjectPropList::ProxyTransactionCompleteL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
       
   137 #else
       
   138 void CMTPSetObjectPropList::ProxyTransactionCompleteL(const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/)
       
   139 #endif
       
   140     {
       
   141     __ASSERT_DEBUG(iRequest == &aRequest && &iConnection == &aConnection, Panic(EMTPNotSameRequestProxy));
       
   142     const TInt KErr(iResponseCode == EMTPRespCodeOK ? KErrNone : KErrGeneral);    
       
   143     if (KErr == KErrNone)
       
   144         {
       
   145         ++iDpIdx;
       
   146         }
       
   147     Reschedule(KErr);
       
   148     }
       
   149 
       
   150 void CMTPSetObjectPropList::RunL()
       
   151     {    
       
   152     if (iStatus == KErrNone) // send request to the next dp
       
   153         {
       
   154         if (!iDpListCreated)
       
   155             {    
       
   156             // Data provider list under construction.
       
   157             iResponseCode = EMTPRespCodeOK;
       
   158             const TUint KElementCount(iObjectPropList->NumberOfElements());
       
   159             const TUint KRunLength(32);
       
   160 		
       
   161             for (TUint i(0); ((i < KRunLength) && (iPropertyIdx < KElementCount) && (iResponseCode == EMTPRespCodeOK)); ++i)
       
   162                 {
       
   163 				iPropertyIdx++;
       
   164 				CMTPTypeObjectPropListElement& element=iObjectPropList->GetNextElementL();			
       
   165                 const TUint32 KHandle(element.Uint32L(CMTPTypeObjectPropListElement::EObjectHandle));
       
   166                 const TUint16 KPropCode(element.Uint16L(CMTPTypeObjectPropListElement::EPropertyCode));
       
   167                 CMTPParserRouter::TRoutingParameters params(*iRequest, iConnection);
       
   168                 params.SetParam(CMTPParserRouter::TRoutingParameters::EParamObjectHandle, KHandle);
       
   169                 params.SetParam(CMTPParserRouter::TRoutingParameters::EParamObjectPropCode, KPropCode);
       
   170                                 
       
   171                 CMTPObjectMetaData* meta(CMTPObjectMetaData::NewLC());
       
   172                 if (!iSingletons.ObjectMgr().ObjectL(KHandle, *meta))
       
   173                     {
       
   174                     // Invalid object handle.
       
   175                     iResponseCode = EMTPRespCodeInvalidObjectHandle;
       
   176                     }
       
   177                 else
       
   178                     {
       
   179                     RArray<TUint> targets;
       
   180                     CleanupClosePushL(targets);
       
   181                     iSingletons.Router().RouteOperationRequestL(params, targets);
       
   182                     __ASSERT_DEBUG((targets.Count() <= 1), User::Invariant());
       
   183                     if (targets.Count() == 1)
       
   184                         {
       
   185                         iDpList.InsertInOrder(targets[0]);
       
   186                         }
       
   187                     else
       
   188                         {
       
   189                         // Unsupported object propertycode.
       
   190                         iResponseCode = EMTPRespCodeObjectPropNotSupported;
       
   191                         }
       
   192                     CleanupStack::PopAndDestroy(&targets);
       
   193                     }
       
   194                 CleanupStack::PopAndDestroy(meta);
       
   195                 
       
   196                 if (iResponseCode != EMTPRespCodeOK)
       
   197                     {
       
   198                     // If an error occurs at this point then no properties have been updated.
       
   199                     iPropertyIdx = 0;
       
   200                     iDpList.Reset();
       
   201                     }
       
   202                 }	                
       
   203             if ((iPropertyIdx < KElementCount) && (iResponseCode == EMTPRespCodeOK))
       
   204                 {
       
   205                 Reschedule(KErrNone);
       
   206                 }
       
   207             else
       
   208                 {
       
   209                 iDpListCreated = ETrue;
       
   210                 }
       
   211             }
       
   212             
       
   213         if (iDpListCreated)
       
   214             {
       
   215             if (iDpIdx < iDpList.Count())
       
   216                 {
       
   217                 iSingletons.DpController().DataProviderL(iDpList[iDpIdx]).ExecuteProxyRequestL(Request(), Connection(), *this);
       
   218                 }
       
   219             else
       
   220                 {
       
   221                 SendResponseL(iResponseCode, 1, &iPropertyIdx);                
       
   222                 }
       
   223             }
       
   224         }
       
   225     else
       
   226         {
       
   227         if (!iDpListCreated)
       
   228             {
       
   229             /* 
       
   230             If an error occurs prior to starting the proxy transaction cycles 
       
   231             then no properties have been updated.
       
   232             */
       
   233             iPropertyIdx = 0;
       
   234             }
       
   235             
       
   236         if (iResponseCode == EMTPRespCodeOK)
       
   237             {
       
   238             iResponseCode = EMTPRespCodeGeneralError;
       
   239             }
       
   240         SendResponseL(iResponseCode, 1, &iPropertyIdx);
       
   241         }    
       
   242     }
       
   243 
       
   244 /**
       
   245 Reschedules the active object with the specified completion code.
       
   246 @param aError The asynchronous request completion code.
       
   247 */
       
   248 void CMTPSetObjectPropList::Reschedule(TInt aError)
       
   249     {
       
   250     SetActive();
       
   251     TRequestStatus* status = &iStatus;
       
   252     User::RequestComplete(status, aError);
       
   253     }