mtpfws/mtpfw/dataproviders/proxydp/src/cmtpgetobjectpropssupported.cpp
changeset 0 d0791faffa3f
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/tmtptyperequest.h>
       
    17 #include <mtp/mmtpdataproviderframework.h>
       
    18 #include <mtp/mtpprotocolconstants.h>
       
    19 #include <mtp/cmtpdataproviderplugin.h>
       
    20 #include <mtp/cmtptypearray.h>
       
    21 
       
    22 #include "rmtpframework.h"
       
    23 #include "cmtpdataprovidercontroller.h"
       
    24 #include "cmtpparserrouter.h"
       
    25 #include "cmtpdataprovider.h"
       
    26 #include "cmtpgetobjectpropssupported.h"
       
    27 #include "mtpproxydppanic.h"
       
    28    
       
    29 /**
       
    30 Factory method.
       
    31 @param aFramework	The data provider framework
       
    32 @param aConnection	The connection from which the request comes
       
    33 @return a pointer to the created request processor object.
       
    34 */ 
       
    35 MMTPRequestProcessor* CMTPGetObjectPropsSupported::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
       
    36 	{
       
    37 	CMTPGetObjectPropsSupported* self = new (ELeave) CMTPGetObjectPropsSupported(aFramework, aConnection);
       
    38     CleanupStack::PushL(self);
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 /**
       
    45 Destructor.
       
    46 */	
       
    47 CMTPGetObjectPropsSupported::~CMTPGetObjectPropsSupported()
       
    48 	{
       
    49 	iObjectPropsSupported.Reset();
       
    50 	delete iDataset;
       
    51     iTargetDps.Close();
       
    52 	iSingletons.Close();
       
    53 	}
       
    54 
       
    55 /**
       
    56 GetObjectPropsSupported request handler. Obtains a list of all the data providers
       
    57 that support the request, then starts an active object to send it to them all.
       
    58 */	
       
    59 void CMTPGetObjectPropsSupported::ServiceL()
       
    60 	{
       
    61 	iObjectPropsSupported.Reset();
       
    62 	iTargetDps.Reset();
       
    63 	
       
    64 	CMTPParserRouter& router(iSingletons.Router());
       
    65     CMTPParserRouter::TRoutingParameters params(*iRequest, iConnection);
       
    66     router.ParseOperationRequestL(params);
       
    67     router.RouteOperationRequestL(params, iTargetDps);
       
    68 	iCurrentTarget = 0;	
       
    69 	Schedule(KErrNone);
       
    70 	}
       
    71 
       
    72 void CMTPGetObjectPropsSupported::ProxyReceiveDataL(MMTPType& /*aData*/, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& /*aStatus*/)
       
    73 	{	
       
    74 	Panic(EMTPWrongRequestPhase);
       
    75 	}
       
    76 
       
    77 #ifdef _DEBUG	
       
    78 void CMTPGetObjectPropsSupported::ProxySendDataL(const MMTPType& aData, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus)
       
    79 #else
       
    80 void CMTPGetObjectPropsSupported::ProxySendDataL(const MMTPType& aData, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus)
       
    81 #endif
       
    82 	{
       
    83 	__ASSERT_DEBUG(((iRequest == &aRequest) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy));
       
    84 	__ASSERT_DEBUG(aData.Type() == EMTPTypeAUINT16, Panic(EMTPInvalidDataType));
       
    85 	const CMTPTypeArray& KProperties(static_cast<const CMTPTypeArray&>(aData));
       
    86 	const TInt KCountProperties(KProperties.NumElements());
       
    87 	for (TUint i(0); (i < KCountProperties); i++)
       
    88 		{
       
    89 		const TInt KErr(iObjectPropsSupported.InsertInOrder(KProperties.ElementUint(i)));
       
    90 		if ((KErr != KErrNone) &&
       
    91 		    (KErr != KErrAlreadyExists))
       
    92 		    {
       
    93 		    User::Leave(KErr);
       
    94 		    }
       
    95 		}
       
    96 	TRequestStatus* status(&aStatus);
       
    97 	User::RequestComplete(status, KErrNone);	
       
    98 	}
       
    99 
       
   100 #ifdef _DEBUG	
       
   101 void CMTPGetObjectPropsSupported::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus)
       
   102 #else
       
   103 void CMTPGetObjectPropsSupported::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus)
       
   104 #endif
       
   105 	{
       
   106 	__ASSERT_DEBUG(((iRequest == &aRequest) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy));
       
   107 	MMTPType::CopyL(aResponse, iResponse);
       
   108 	TRequestStatus* status(&aStatus);
       
   109 	User::RequestComplete(status, KErrNone);
       
   110 	}
       
   111 
       
   112 #ifdef _DEBUG		
       
   113 void CMTPGetObjectPropsSupported::ProxyTransactionCompleteL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
       
   114 #else
       
   115 void CMTPGetObjectPropsSupported::ProxyTransactionCompleteL(const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/)
       
   116 #endif
       
   117 	{
       
   118 	__ASSERT_DEBUG(((iRequest == &aRequest) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy));
       
   119     TInt err((iResponse.Uint16(TMTPTypeResponse::EResponseCode) == EMTPRespCodeOK) ? KErrNone : KErrGeneral);    
       
   120     if (err == KErrNone)
       
   121         {
       
   122         iCurrentTarget++;
       
   123         }
       
   124     Schedule(err);
       
   125 	}	
       
   126 
       
   127 /**
       
   128 Sends the request to all the data providers that expressed an interest,
       
   129 one each iteration of the active object.
       
   130 */
       
   131 void CMTPGetObjectPropsSupported::RunL()
       
   132 	{
       
   133 	// We cannot use assertion here, because it might be completed with KErrGeneral. See ProxyTransactionCompleteL()
       
   134     if (iStatus == KErrNone)
       
   135         {
       
   136         if (iCurrentTarget < iTargetDps.Count())   
       
   137             {
       
   138             const TUint KTarget(iTargetDps[iCurrentTarget]);
       
   139             iSingletons.DpController().DataProviderL(KTarget).ExecuteProxyRequestL(*iRequest, Connection(), *this);
       
   140             }
       
   141         else
       
   142     		{
       
   143     		delete iDataset;
       
   144     		iDataset = NULL;
       
   145     		iDataset = CMTPTypeArray::NewL(EMTPTypeAUINT16, iObjectPropsSupported);
       
   146 			SendDataL(*iDataset);
       
   147 			}
       
   148 		}
       
   149     else
       
   150         {
       
   151         SendResponseL(iResponse.Uint16(TMTPTypeResponse::EResponseCode));
       
   152         } 	
       
   153 	}
       
   154 
       
   155 /**
       
   156 Constructor.
       
   157 */	
       
   158 CMTPGetObjectPropsSupported::CMTPGetObjectPropsSupported(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
       
   159     CMTPRequestProcessor(aFramework, aConnection, 0, NULL)
       
   160 	{
       
   161 	
       
   162 	}
       
   163     
       
   164 /**
       
   165 Second phase constructor.
       
   166 */
       
   167 void CMTPGetObjectPropsSupported::ConstructL()
       
   168     {
       
   169     iSingletons.OpenL();
       
   170     }
       
   171 
       
   172 /**
       
   173 Completes the current asynchronous request with the specified 
       
   174 completion code.
       
   175 @param aError The asynchronous request completion request.
       
   176 */
       
   177 void CMTPGetObjectPropsSupported::Schedule(TInt aError)
       
   178 	{
       
   179 	TRequestStatus* status(&iStatus);
       
   180 	User::RequestComplete(status, aError);
       
   181 	SetActive();
       
   182 	}
       
   183 
       
   184 /**
       
   185 Sends a response to the initiator.
       
   186 @param aCode MTP response code
       
   187 */
       
   188 void CMTPGetObjectPropsSupported::SendResponseL(TUint16 aCode)
       
   189     {
       
   190     const TMTPTypeRequest& req(Request());
       
   191     iResponse.SetUint16(TMTPTypeResponse::EResponseCode, aCode);
       
   192     iResponse.SetUint32(TMTPTypeResponse::EResponseSessionID, req.Uint32(TMTPTypeRequest::ERequestSessionID));
       
   193     iResponse.SetUint32(TMTPTypeResponse::EResponseTransactionID, req.Uint32(TMTPTypeRequest::ERequestTransactionID));
       
   194     iFramework.SendResponseL(iResponse, req, Connection());
       
   195     }