mtpfws/mtpfw/dataproviders/devdp/src/cmtpopensession.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 12 Mar 2010 15:46:41 +0200
branchRCL_3
changeset 11 4843bb5893b6
parent 6 f8e15b44d440
child 14 60a94a45d437
permissions -rw-r--r--
Revision: 201004 Kit: 201008

// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
//

/**
 @file
 @internalComponent
*/

#include <mtp/tmtptyperequest.h>

#include "cmtpopensession.h"
#include "cmtpconnection.h"
#include "cmtpdataprovidercontroller.h"
#include "cmtpdataprovider.h"
#include "mtpdevdppanic.h"
#include "cmtpconnectionmgr.h"
#include "rmtpframework.h"

/**
Verification data for OpenSession request
*/
const TMTPRequestElementInfo KMTPOpenSessionPolicy[] = 
    {
        {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeSessionID, EMTPElementAttrNone, 0, 0, 0}
    };

/**
Two-phase construction method
@param aPlugin    The data provider plugin
@param aFramework    The data provider framework
@param aConnection    The connection from which the request comes
@return a pointer to the created request processor object
*/ 
MMTPRequestProcessor* CMTPOpenSession::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
    {
    CMTPOpenSession* self = new (ELeave) CMTPOpenSession(aFramework, aConnection);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(self);
    return self;
    }

/**
Destructor
*/    
CMTPOpenSession::~CMTPOpenSession()
    {
    iSingletons.Close();
    }

/**
Standard c++ constructor
*/    
CMTPOpenSession::CMTPOpenSession(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
    CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPOpenSessionPolicy)/sizeof(TMTPRequestElementInfo), KMTPOpenSessionPolicy)
    {
    
    }
    
/**
Second phase constructor.
*/
void CMTPOpenSession::ConstructL()
    {
    iSingletons.OpenL();
    }
    
/**
OpenSession request handler.  Adds the session to the connection.
*/    
void CMTPOpenSession::ServiceL()    
    {
    iSingletons.DpController().WaitForEnumerationComplete();
    if(iSingletons.DpController().EnumerateState() < CMTPDataProviderController::EEnumeratingPhaseOneDone)
    	{
    	SendResponseL(EMTPRespCodeDeviceBusy);
    	}
    else
    	{
    	const TUint connectionId = iConnection.ConnectionId();
    	CMTPConnectionMgr& connectionMgr = iSingletons.ConnectionMgr();
    	CMTPConnection& connection = connectionMgr.ConnectionL(connectionId);
    	connection.SessionOpenedL(Request().Uint32(TMTPTypeRequest::ERequestParameter1));
    	SendResponseL(EMTPRespCodeOK);
    	}
    }