kerneltest/f32test/shostmassstorage/msman/server/cusbotgserver.cpp
author hgs
Tue, 26 Oct 2010 12:49:20 +0100
changeset 297 b2826f67641f
parent 0 a41df078684a
permissions -rw-r--r--
201043_03

// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the License "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:
// Implements a Symbian OS server that exposes the RUsbMassStorage API
//
//



/**
 @file
 @internalTechnology
*/

#include <e32svr.h>
#include <f32file.h>

#include <d32usbdi_hubdriver.h>
#include <d32otgdi.h>

#include "usbtypes.h"
#include "cusbotg.h"

#include "msmanclientserver.h"
#include "cusbotgserver.h"
#include "cusbotgsession.h"

CUsbOtgServer* CUsbOtgServer::NewLC()
    {
    CUsbOtgServer* r = new (ELeave) CUsbOtgServer();
    CleanupStack::PushL(r);
    r->ConstructL();
    return r;
    }


CUsbOtgServer::CUsbOtgServer()
:   CServer2(EPriorityLow)
    {
    }


void CUsbOtgServer::ConstructL()
    {
    iUsbOtg = CUsbOtg::NewL();
    StartL(KUsbOtgServerName);
    }


CUsbOtgServer::~CUsbOtgServer()
    {
    delete iUsbOtg;
    }


CSession2* CUsbOtgServer::NewSessionL(const TVersion &aVersion, const RMessage2& /*aMessage*/) const
    {
    TVersion v(KUsbOtgSrvMajorVersionNumber, KUsbOtgSrvMinorVersionNumber, KUsbOtgSrvBuildVersionNumber);

    if (!User::QueryVersionSupported(v, aVersion))
        User::Leave(KErrNotSupported);

    CUsbOtgSession* session = CUsbOtgSession::NewL();

    return session;
    }



TInt CUsbOtgServer::RunError(TInt aError)
    {
    Message().Complete(aError);
    ReStart();
    return KErrNone;
    }


void CUsbOtgServer::AddSession()
    {
    ++iSessionCount;
    }

void CUsbOtgServer::RemoveSession()
    {
    if (--iSessionCount == 0)
        {
        User::After(1000000);
        CActiveScheduler::Stop();
        }
    }