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