os/kernelhwsrv/kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/cusbmassstoragesession.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/cusbmassstoragesession.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,188 @@
     1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Implements a Session of a Symbian OS server for the RUsbMassStorage API
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @internalTechnology
    1.26 +*/
    1.27 +
    1.28 +#include <e32base.h>
    1.29 +#include <f32file.h>
    1.30 +
    1.31 +#include "usbmsshared.h"
    1.32 +#include "mstypes.h"
    1.33 +#include "msctypes.h"
    1.34 +#include "cusbmassstoragesession.h"
    1.35 +#include "cusbmassstoragecontroller.h"
    1.36 +#include "cusbmassstorageserver.h"
    1.37 +
    1.38 +#include "debug.h"
    1.39 +#include "msdebug.h"
    1.40 +
    1.41 +/**
    1.42 + Construct a Symbian OS session object.
    1.43 +
    1.44 + @param	aServer		Service the session will be a member of
    1.45 + @param	aMessage	The message from the client.
    1.46 + @return	A new CUsbMassStorageSession object
    1.47 + */
    1.48 +CUsbMassStorageSession* CUsbMassStorageSession::NewL(CUsbMassStorageServer& aServer)
    1.49 +	{
    1.50 +    __MSFNSLOG
    1.51 +	CUsbMassStorageSession* r = new (ELeave) CUsbMassStorageSession(aServer);
    1.52 +	CleanupStack::PushL(r);
    1.53 +	r->ConstructL();
    1.54 +	CleanupStack::Pop();
    1.55 +	return r;
    1.56 +	}
    1.57 +
    1.58 +/**
    1.59 + Constructor.
    1.60 +
    1.61 + @param	aServer	Service the session will be a member of
    1.62 + */
    1.63 +CUsbMassStorageSession::CUsbMassStorageSession(CUsbMassStorageServer& aServer)
    1.64 +	: iUsbMsServer(aServer)
    1.65 +	{
    1.66 +    __MSFNLOG
    1.67 +	}
    1.68 +
    1.69 +
    1.70 +/**
    1.71 + 2nd Phase Construction.
    1.72 + */
    1.73 +void CUsbMassStorageSession::ConstructL()
    1.74 +	{
    1.75 +    __MSFNLOG
    1.76 +	iUsbMsServer.IncrementSessionCount();
    1.77 +    if (iUsbMsServer.SessionCount() > 1)
    1.78 +        {
    1.79 +        __PRINT1(_L("\tiSessionCount: %d\n"), iUsbMsServer.SessionCount());
    1.80 +        // Only one session is allowed
    1.81 +        User::Leave(KErrInUse);
    1.82 +        }
    1.83 + 	}
    1.84 +
    1.85 +
    1.86 +/**
    1.87 + Destructor.
    1.88 + */
    1.89 +CUsbMassStorageSession::~CUsbMassStorageSession()
    1.90 +	{
    1.91 +    __MSFNLOG
    1.92 +	iUsbMsServer.DecrementSessionCount();
    1.93 +	}
    1.94 +
    1.95 +/**
    1.96 + Called when a message is received from the client.
    1.97 +
    1.98 + @param	aMessage	Message received from the client
    1.99 + */
   1.100 +void CUsbMassStorageSession::ServiceL(const RMessage2& aMessage)
   1.101 +	{
   1.102 +    __MSFNLOG
   1.103 +	DispatchMessageL(aMessage);
   1.104 +	}
   1.105 +
   1.106 +/**
   1.107 + Handles the request (in the form of a the message) received from the client
   1.108 +
   1.109 + @internalTechnology
   1.110 + @param	aMessage	The received message
   1.111 + */
   1.112 +void CUsbMassStorageSession::DispatchMessageL(const RMessage2& aMessage)
   1.113 +	{
   1.114 +    __MSFNLOG
   1.115 +	TInt ret = KErrNone;
   1.116 +
   1.117 +	switch (aMessage.Function())
   1.118 +		{
   1.119 +	case EUsbMsStart:
   1.120 +		ret = Start(aMessage);
   1.121 +		break;
   1.122 +	case EUsbMsStop:
   1.123 +		ret = Stop();
   1.124 +		break;
   1.125 +	case EUsbMsShutdown:
   1.126 +		ret = Shutdown();
   1.127 +		break;
   1.128 +
   1.129 +	default:
   1.130 +		aMessage.Panic(KUsbMsCliPncCat, EUsbMsPanicIllegalIPC);
   1.131 +		break;
   1.132 +		}
   1.133 +
   1.134 +	aMessage.Complete(ret);
   1.135 +	}
   1.136 +
   1.137 +/**
   1.138 + Client request to start the device.
   1.139 +
   1.140 + @return	Any error that occurred or KErrNone
   1.141 + */
   1.142 +TInt CUsbMassStorageSession::Start(const RMessage2& aMessage)
   1.143 +	{
   1.144 +    __MSFNLOG
   1.145 +	__PRINT(_L("CUsbMassStorageSession::Start\n"));
   1.146 +
   1.147 +	TMassStorageConfig msConfig;
   1.148 +	TRAPD(err, GetMsConfigL(aMessage, msConfig));
   1.149 +	if (err != KErrNone)
   1.150 +		{
   1.151 +		__PRINT(_L("Failed to get mass storage configuration data\n"));
   1.152 +		return err;
   1.153 +		}
   1.154 +
   1.155 +	return iUsbMsServer.Controller().Start(msConfig);
   1.156 +	}
   1.157 +
   1.158 +/**
   1.159 + Client request to stop the device.
   1.160 +
   1.161 + @return	Any error that occurred or KErrNone
   1.162 + */
   1.163 +TInt CUsbMassStorageSession::Stop()
   1.164 +    {
   1.165 +    __MSFNLOG
   1.166 +    TInt err = iUsbMsServer.Controller().Stop();
   1.167 +	return err;
   1.168 +	}
   1.169 +
   1.170 +/**
   1.171 + Client request to shut down the server
   1.172 +
   1.173 + @return KErrNone
   1.174 + */
   1.175 +TInt CUsbMassStorageSession::Shutdown()
   1.176 +    {
   1.177 +    __MSFNLOG
   1.178 +    CActiveScheduler::Stop();
   1.179 +	return KErrNone;
   1.180 +	}
   1.181 +
   1.182 + /**
   1.183 +  Get mass storage configuration data from the received message
   1.184 +  */
   1.185 + void CUsbMassStorageSession::GetMsConfigL(const RMessage2& aMessage, TMassStorageConfig& aMsStorage)
   1.186 + 	{
   1.187 +    __MSFNLOG
   1.188 + 	aMessage.ReadL(0,aMsStorage.iVendorId);
   1.189 + 	aMessage.ReadL(1,aMsStorage.iProductId);
   1.190 + 	aMessage.ReadL(2,aMsStorage.iProductRev);
   1.191 + 	}