os/kernelhwsrv/kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/cusbmassstorageserver.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Implements a Symbian OS server that exposes the RUsbMassStorage API
    15 // 
    16 //
    17 
    18 
    19 
    20 /**
    21  @file
    22  @internalTechnology
    23 */
    24 
    25 #include <e32svr.h>
    26 #include <f32file.h>
    27 #include "usbmsshared.h"
    28 #include "mstypes.h"
    29 #include "msctypes.h"
    30 #include "usbmsclientpanic.h"
    31 #include "cusbmassstorageserver.h"
    32 #include "cusbmassstoragesession.h"
    33 #include "cusbmassstoragecontroller.h"
    34 #include "debug.h"
    35 
    36 #include "usbmsserversecuritypolicy.h"
    37 /**
    38  Constructs a USB mass storage Server
    39 
    40  @return  a pointer to CUsbMassStorageServer object
    41  */
    42 CUsbMassStorageServer* CUsbMassStorageServer::NewLC(CUsbMassStorageController& aController)
    43 	{
    44 	CUsbMassStorageServer* r = new (ELeave) CUsbMassStorageServer(aController);
    45 	CleanupStack::PushL(r);
    46 	r->StartL(KUsbMsServerName);
    47 	return r;
    48 	}
    49 
    50 /**
    51  Destructor
    52  */
    53 CUsbMassStorageServer::~CUsbMassStorageServer()
    54 	{
    55     // Intentionally left blank
    56 	}
    57 
    58 
    59 /**
    60  Constructor
    61 
    62  @param aController a USB mass storage controller reference
    63  */
    64 CUsbMassStorageServer::CUsbMassStorageServer(CUsbMassStorageController& aController)
    65      : CPolicyServer(EPriorityHigh,KUsbMsServerPolicy)
    66     , iController(aController)
    67 	{
    68     __PRINT(_L("CUsbMassStorageServer::CUsbMassStorageServer\n"));
    69 	}
    70 
    71 /**
    72  Create a new session on this server
    73 
    74  @param	&aVersion	Version of client
    75  @return	A pointer to a session object to be used for the client
    76  */
    77 CSession2* CUsbMassStorageServer::NewSessionL(const TVersion &aVersion, const RMessage2& /*aMessage*/) const
    78 	{
    79 	TVersion v(KUsbMsSrvMajorVersionNumber,KUsbMsSrvMinorVersionNumber,KUsbMsSrvBuildVersionNumber);
    80 
    81 	__PRINT(_L("CUsbMassStorageServer::NewSessionL\n"));
    82 	if (!User::QueryVersionSupported(v, aVersion))
    83 		User::Leave(KErrNotSupported);
    84 
    85 	CUsbMassStorageServer* ncThis = const_cast<CUsbMassStorageServer*>(this);
    86 
    87 	CUsbMassStorageSession* sess = CUsbMassStorageSession::NewL(*ncThis);
    88 
    89 	return sess;
    90 	}
    91 
    92 
    93 /**
    94  Inform the client there has been an error.
    95 
    96  @param	aError	The error that has occurred
    97  */
    98 void CUsbMassStorageServer::Error(TInt aError)
    99 	{
   100 	__PRINT1(_L("CUsbMassStorageServer::Error [aError=%d]\n"), aError);
   101 
   102 	Message().Complete(aError);
   103 	ReStart();
   104 	}
   105 
   106 /**
   107  Increment the open session count (iSessionCount) by one.
   108 
   109  @post	the number of open sessions is incremented by one
   110  */
   111 void CUsbMassStorageServer::IncrementSessionCount()
   112 	{
   113 	__PRINT1(_L("CUsbMassStorageServer::IncrementSessionCount %d\n"), iSessionCount);
   114 	__ASSERT_DEBUG(iSessionCount >= 0, User::Panic(KUsbMsClientPanicCat, EUsbMsPanicIllegalIPC));
   115 
   116 	++iSessionCount;
   117 
   118 	__PRINT(_L("CUsbMassStorageServer::IncrementSessionCount\n"));
   119 	}
   120 
   121 /**
   122  Decrement the open session count (iSessionCount) by one.
   123 
   124  @post		the number of open sessions is decremented by one
   125  */
   126 void CUsbMassStorageServer::DecrementSessionCount()
   127 	{
   128 	__PRINT1(_L("CUsbMassStorageServer::DecrementSessionCount %d\n"), iSessionCount);
   129 
   130 	__ASSERT_DEBUG(iSessionCount > 0, User::Panic(KUsbMsClientPanicCat, EUsbMsPanicIllegalIPC));
   131 
   132 	--iSessionCount;
   133 	}