os/kernelhwsrv/kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/cusbmassstoragesession.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Implements a Session of a Symbian OS server for the RUsbMassStorage API
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
 @internalTechnology
sl@0
    23
*/
sl@0
    24
sl@0
    25
#include <e32base.h>
sl@0
    26
#include <f32file.h>
sl@0
    27
sl@0
    28
#include "usbmsshared.h"
sl@0
    29
#include "mstypes.h"
sl@0
    30
#include "msctypes.h"
sl@0
    31
#include "cusbmassstoragesession.h"
sl@0
    32
#include "cusbmassstoragecontroller.h"
sl@0
    33
#include "cusbmassstorageserver.h"
sl@0
    34
sl@0
    35
#include "debug.h"
sl@0
    36
#include "msdebug.h"
sl@0
    37
sl@0
    38
/**
sl@0
    39
 Construct a Symbian OS session object.
sl@0
    40
sl@0
    41
 @param	aServer		Service the session will be a member of
sl@0
    42
 @param	aMessage	The message from the client.
sl@0
    43
 @return	A new CUsbMassStorageSession object
sl@0
    44
 */
sl@0
    45
CUsbMassStorageSession* CUsbMassStorageSession::NewL(CUsbMassStorageServer& aServer)
sl@0
    46
	{
sl@0
    47
    __MSFNSLOG
sl@0
    48
	CUsbMassStorageSession* r = new (ELeave) CUsbMassStorageSession(aServer);
sl@0
    49
	CleanupStack::PushL(r);
sl@0
    50
	r->ConstructL();
sl@0
    51
	CleanupStack::Pop();
sl@0
    52
	return r;
sl@0
    53
	}
sl@0
    54
sl@0
    55
/**
sl@0
    56
 Constructor.
sl@0
    57
sl@0
    58
 @param	aServer	Service the session will be a member of
sl@0
    59
 */
sl@0
    60
CUsbMassStorageSession::CUsbMassStorageSession(CUsbMassStorageServer& aServer)
sl@0
    61
	: iUsbMsServer(aServer)
sl@0
    62
	{
sl@0
    63
    __MSFNLOG
sl@0
    64
	}
sl@0
    65
sl@0
    66
sl@0
    67
/**
sl@0
    68
 2nd Phase Construction.
sl@0
    69
 */
sl@0
    70
void CUsbMassStorageSession::ConstructL()
sl@0
    71
	{
sl@0
    72
    __MSFNLOG
sl@0
    73
	iUsbMsServer.IncrementSessionCount();
sl@0
    74
    if (iUsbMsServer.SessionCount() > 1)
sl@0
    75
        {
sl@0
    76
        __PRINT1(_L("\tiSessionCount: %d\n"), iUsbMsServer.SessionCount());
sl@0
    77
        // Only one session is allowed
sl@0
    78
        User::Leave(KErrInUse);
sl@0
    79
        }
sl@0
    80
 	}
sl@0
    81
sl@0
    82
sl@0
    83
/**
sl@0
    84
 Destructor.
sl@0
    85
 */
sl@0
    86
CUsbMassStorageSession::~CUsbMassStorageSession()
sl@0
    87
	{
sl@0
    88
    __MSFNLOG
sl@0
    89
	iUsbMsServer.DecrementSessionCount();
sl@0
    90
	}
sl@0
    91
sl@0
    92
/**
sl@0
    93
 Called when a message is received from the client.
sl@0
    94
sl@0
    95
 @param	aMessage	Message received from the client
sl@0
    96
 */
sl@0
    97
void CUsbMassStorageSession::ServiceL(const RMessage2& aMessage)
sl@0
    98
	{
sl@0
    99
    __MSFNLOG
sl@0
   100
	DispatchMessageL(aMessage);
sl@0
   101
	}
sl@0
   102
sl@0
   103
/**
sl@0
   104
 Handles the request (in the form of a the message) received from the client
sl@0
   105
sl@0
   106
 @internalTechnology
sl@0
   107
 @param	aMessage	The received message
sl@0
   108
 */
sl@0
   109
void CUsbMassStorageSession::DispatchMessageL(const RMessage2& aMessage)
sl@0
   110
	{
sl@0
   111
    __MSFNLOG
sl@0
   112
	TInt ret = KErrNone;
sl@0
   113
sl@0
   114
	switch (aMessage.Function())
sl@0
   115
		{
sl@0
   116
	case EUsbMsStart:
sl@0
   117
		ret = Start(aMessage);
sl@0
   118
		break;
sl@0
   119
	case EUsbMsStop:
sl@0
   120
		ret = Stop();
sl@0
   121
		break;
sl@0
   122
	case EUsbMsShutdown:
sl@0
   123
		ret = Shutdown();
sl@0
   124
		break;
sl@0
   125
sl@0
   126
	default:
sl@0
   127
		aMessage.Panic(KUsbMsCliPncCat, EUsbMsPanicIllegalIPC);
sl@0
   128
		break;
sl@0
   129
		}
sl@0
   130
sl@0
   131
	aMessage.Complete(ret);
sl@0
   132
	}
sl@0
   133
sl@0
   134
/**
sl@0
   135
 Client request to start the device.
sl@0
   136
sl@0
   137
 @return	Any error that occurred or KErrNone
sl@0
   138
 */
sl@0
   139
TInt CUsbMassStorageSession::Start(const RMessage2& aMessage)
sl@0
   140
	{
sl@0
   141
    __MSFNLOG
sl@0
   142
	__PRINT(_L("CUsbMassStorageSession::Start\n"));
sl@0
   143
sl@0
   144
	TMassStorageConfig msConfig;
sl@0
   145
	TRAPD(err, GetMsConfigL(aMessage, msConfig));
sl@0
   146
	if (err != KErrNone)
sl@0
   147
		{
sl@0
   148
		__PRINT(_L("Failed to get mass storage configuration data\n"));
sl@0
   149
		return err;
sl@0
   150
		}
sl@0
   151
sl@0
   152
	return iUsbMsServer.Controller().Start(msConfig);
sl@0
   153
	}
sl@0
   154
sl@0
   155
/**
sl@0
   156
 Client request to stop the device.
sl@0
   157
sl@0
   158
 @return	Any error that occurred or KErrNone
sl@0
   159
 */
sl@0
   160
TInt CUsbMassStorageSession::Stop()
sl@0
   161
    {
sl@0
   162
    __MSFNLOG
sl@0
   163
    TInt err = iUsbMsServer.Controller().Stop();
sl@0
   164
	return err;
sl@0
   165
	}
sl@0
   166
sl@0
   167
/**
sl@0
   168
 Client request to shut down the server
sl@0
   169
sl@0
   170
 @return KErrNone
sl@0
   171
 */
sl@0
   172
TInt CUsbMassStorageSession::Shutdown()
sl@0
   173
    {
sl@0
   174
    __MSFNLOG
sl@0
   175
    CActiveScheduler::Stop();
sl@0
   176
	return KErrNone;
sl@0
   177
	}
sl@0
   178
sl@0
   179
 /**
sl@0
   180
  Get mass storage configuration data from the received message
sl@0
   181
  */
sl@0
   182
 void CUsbMassStorageSession::GetMsConfigL(const RMessage2& aMessage, TMassStorageConfig& aMsStorage)
sl@0
   183
 	{
sl@0
   184
    __MSFNLOG
sl@0
   185
 	aMessage.ReadL(0,aMsStorage.iVendorId);
sl@0
   186
 	aMessage.ReadL(1,aMsStorage.iProductId);
sl@0
   187
 	aMessage.ReadL(2,aMsStorage.iProductRev);
sl@0
   188
 	}