os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/cusbmassstorageserver.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2004-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 Symbian OS server that exposes the RUsbMassStorage API
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology
sl@0
    21
*/
sl@0
    22
sl@0
    23
#include <e32svr.h>
sl@0
    24
#include "usbmsshared.h"
sl@0
    25
#include "cusbmassstorageserver.h"
sl@0
    26
#include "cusbmassstoragesession.h"
sl@0
    27
#include "cusbmassstoragecontroller.h"
sl@0
    28
#include "massstoragedebug.h"
sl@0
    29
sl@0
    30
#include "usbmsserversecuritypolicy.h"
sl@0
    31
/**
sl@0
    32
 Constructs a USB mass storage Server
sl@0
    33
 
sl@0
    34
 @return  a pointer to CUsbMassStorageServer object
sl@0
    35
 */
sl@0
    36
CUsbMassStorageServer* CUsbMassStorageServer::NewLC(CUsbMassStorageController& aController)
sl@0
    37
	{
sl@0
    38
	CUsbMassStorageServer* r = new (ELeave) CUsbMassStorageServer(aController);
sl@0
    39
	CleanupStack::PushL(r);
sl@0
    40
	r->StartL(KUsbMsServerName);
sl@0
    41
	return r;
sl@0
    42
	}
sl@0
    43
sl@0
    44
/**
sl@0
    45
 Destructor
sl@0
    46
 */
sl@0
    47
CUsbMassStorageServer::~CUsbMassStorageServer()
sl@0
    48
	{
sl@0
    49
    // Intentionally left blank
sl@0
    50
	}
sl@0
    51
sl@0
    52
sl@0
    53
/**
sl@0
    54
 Constructor
sl@0
    55
sl@0
    56
 @param aController a USB mass storage controller reference
sl@0
    57
 */
sl@0
    58
CUsbMassStorageServer::CUsbMassStorageServer(CUsbMassStorageController& aController)
sl@0
    59
     : CPolicyServer(EPriorityHigh,KUsbMsServerPolicy) 
sl@0
    60
    , iController(aController)
sl@0
    61
	{
sl@0
    62
    __PRINT(_L("CUsbMassStorageServer::CUsbMassStorageServer\n"));   
sl@0
    63
	}
sl@0
    64
sl@0
    65
/**
sl@0
    66
 Create a new session on this server
sl@0
    67
 
sl@0
    68
 @param	&aVersion	Version of client
sl@0
    69
 @return	A pointer to a session object to be used for the client
sl@0
    70
 */
sl@0
    71
CSession2* CUsbMassStorageServer::NewSessionL(const TVersion &aVersion, const RMessage2& /*aMessage*/) const
sl@0
    72
	{
sl@0
    73
	TVersion v(KUsbMsSrvMajorVersionNumber,KUsbMsSrvMinorVersionNumber,KUsbMsSrvBuildVersionNumber);
sl@0
    74
sl@0
    75
	__PRINT(_L("CUsbMassStorageServer::NewSessionL\n"));
sl@0
    76
	if (!User::QueryVersionSupported(v, aVersion))
sl@0
    77
		User::Leave(KErrNotSupported);
sl@0
    78
sl@0
    79
	CUsbMassStorageServer* ncThis = const_cast<CUsbMassStorageServer*>(this);
sl@0
    80
	
sl@0
    81
	CUsbMassStorageSession* sess = CUsbMassStorageSession::NewL(*ncThis);
sl@0
    82
		
sl@0
    83
	return sess;
sl@0
    84
	}
sl@0
    85
sl@0
    86
sl@0
    87
/**
sl@0
    88
 Inform the client there has been an error.
sl@0
    89
 
sl@0
    90
 @param	aError	The error that has occurred
sl@0
    91
 */
sl@0
    92
void CUsbMassStorageServer::Error(TInt aError)
sl@0
    93
	{
sl@0
    94
	__PRINT1(_L("CUsbMassStorageServer::Error [aError=%d]\n"), aError);
sl@0
    95
sl@0
    96
	Message().Complete(aError);
sl@0
    97
	ReStart();
sl@0
    98
	}
sl@0
    99
sl@0
   100
/**
sl@0
   101
 Increment the open session count (iSessionCount) by one.
sl@0
   102
 
sl@0
   103
 @post	the number of open sessions is incremented by one
sl@0
   104
 */
sl@0
   105
void CUsbMassStorageServer::IncrementSessionCount()
sl@0
   106
	{
sl@0
   107
	__PRINT1(_L("CUsbMassStorageServer::IncrementSessionCount %d\n"), iSessionCount);
sl@0
   108
	__ASSERT_DEBUG(iSessionCount >= 0, User::Panic(KUsbMsSvrPncCat, EUsbMsPanicIllegalIPC));
sl@0
   109
	
sl@0
   110
	++iSessionCount;
sl@0
   111
sl@0
   112
	__PRINT(_L("CUsbMassStorageServer::IncrementSessionCount\n"));
sl@0
   113
	}
sl@0
   114
sl@0
   115
/**
sl@0
   116
 Decrement the open session count (iSessionCount) by one.
sl@0
   117
 
sl@0
   118
 @post		the number of open sessions is decremented by one
sl@0
   119
 */
sl@0
   120
void CUsbMassStorageServer::DecrementSessionCount()
sl@0
   121
	{
sl@0
   122
	__PRINT1(_L("CUsbMassStorageServer::DecrementSessionCount %d\n"), iSessionCount);
sl@0
   123
sl@0
   124
	__ASSERT_DEBUG(iSessionCount > 0, User::Panic(KUsbMsSvrPncCat, EUsbMsPanicIllegalIPC));
sl@0
   125
sl@0
   126
	--iSessionCount;
sl@0
   127
	}
sl@0
   128