mtpfws/mtpfw/dataproviders/devdp/src/cmtpopensession.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 02 Feb 2010 01:11:40 +0200
changeset 0 d0791faffa3f
child 1 f8e15b44d440
permissions -rw-r--r--
Revision: 201003 Kit: 201005

// 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::EEnumerated)
    	{
    	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);
    	}
    }