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.
     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 Session of a Symbian OS server for the RUsbMassStorage API
    15 // 
    16 //
    17 
    18 
    19 
    20 /**
    21  @file
    22  @internalTechnology
    23 */
    24 
    25 #include <e32base.h>
    26 #include <f32file.h>
    27 
    28 #include "usbmsshared.h"
    29 #include "mstypes.h"
    30 #include "msctypes.h"
    31 #include "cusbmassstoragesession.h"
    32 #include "cusbmassstoragecontroller.h"
    33 #include "cusbmassstorageserver.h"
    34 
    35 #include "debug.h"
    36 #include "msdebug.h"
    37 
    38 /**
    39  Construct a Symbian OS session object.
    40 
    41  @param	aServer		Service the session will be a member of
    42  @param	aMessage	The message from the client.
    43  @return	A new CUsbMassStorageSession object
    44  */
    45 CUsbMassStorageSession* CUsbMassStorageSession::NewL(CUsbMassStorageServer& aServer)
    46 	{
    47     __MSFNSLOG
    48 	CUsbMassStorageSession* r = new (ELeave) CUsbMassStorageSession(aServer);
    49 	CleanupStack::PushL(r);
    50 	r->ConstructL();
    51 	CleanupStack::Pop();
    52 	return r;
    53 	}
    54 
    55 /**
    56  Constructor.
    57 
    58  @param	aServer	Service the session will be a member of
    59  */
    60 CUsbMassStorageSession::CUsbMassStorageSession(CUsbMassStorageServer& aServer)
    61 	: iUsbMsServer(aServer)
    62 	{
    63     __MSFNLOG
    64 	}
    65 
    66 
    67 /**
    68  2nd Phase Construction.
    69  */
    70 void CUsbMassStorageSession::ConstructL()
    71 	{
    72     __MSFNLOG
    73 	iUsbMsServer.IncrementSessionCount();
    74     if (iUsbMsServer.SessionCount() > 1)
    75         {
    76         __PRINT1(_L("\tiSessionCount: %d\n"), iUsbMsServer.SessionCount());
    77         // Only one session is allowed
    78         User::Leave(KErrInUse);
    79         }
    80  	}
    81 
    82 
    83 /**
    84  Destructor.
    85  */
    86 CUsbMassStorageSession::~CUsbMassStorageSession()
    87 	{
    88     __MSFNLOG
    89 	iUsbMsServer.DecrementSessionCount();
    90 	}
    91 
    92 /**
    93  Called when a message is received from the client.
    94 
    95  @param	aMessage	Message received from the client
    96  */
    97 void CUsbMassStorageSession::ServiceL(const RMessage2& aMessage)
    98 	{
    99     __MSFNLOG
   100 	DispatchMessageL(aMessage);
   101 	}
   102 
   103 /**
   104  Handles the request (in the form of a the message) received from the client
   105 
   106  @internalTechnology
   107  @param	aMessage	The received message
   108  */
   109 void CUsbMassStorageSession::DispatchMessageL(const RMessage2& aMessage)
   110 	{
   111     __MSFNLOG
   112 	TInt ret = KErrNone;
   113 
   114 	switch (aMessage.Function())
   115 		{
   116 	case EUsbMsStart:
   117 		ret = Start(aMessage);
   118 		break;
   119 	case EUsbMsStop:
   120 		ret = Stop();
   121 		break;
   122 	case EUsbMsShutdown:
   123 		ret = Shutdown();
   124 		break;
   125 
   126 	default:
   127 		aMessage.Panic(KUsbMsCliPncCat, EUsbMsPanicIllegalIPC);
   128 		break;
   129 		}
   130 
   131 	aMessage.Complete(ret);
   132 	}
   133 
   134 /**
   135  Client request to start the device.
   136 
   137  @return	Any error that occurred or KErrNone
   138  */
   139 TInt CUsbMassStorageSession::Start(const RMessage2& aMessage)
   140 	{
   141     __MSFNLOG
   142 	__PRINT(_L("CUsbMassStorageSession::Start\n"));
   143 
   144 	TMassStorageConfig msConfig;
   145 	TRAPD(err, GetMsConfigL(aMessage, msConfig));
   146 	if (err != KErrNone)
   147 		{
   148 		__PRINT(_L("Failed to get mass storage configuration data\n"));
   149 		return err;
   150 		}
   151 
   152 	return iUsbMsServer.Controller().Start(msConfig);
   153 	}
   154 
   155 /**
   156  Client request to stop the device.
   157 
   158  @return	Any error that occurred or KErrNone
   159  */
   160 TInt CUsbMassStorageSession::Stop()
   161     {
   162     __MSFNLOG
   163     TInt err = iUsbMsServer.Controller().Stop();
   164 	return err;
   165 	}
   166 
   167 /**
   168  Client request to shut down the server
   169 
   170  @return KErrNone
   171  */
   172 TInt CUsbMassStorageSession::Shutdown()
   173     {
   174     __MSFNLOG
   175     CActiveScheduler::Stop();
   176 	return KErrNone;
   177 	}
   178 
   179  /**
   180   Get mass storage configuration data from the received message
   181   */
   182  void CUsbMassStorageSession::GetMsConfigL(const RMessage2& aMessage, TMassStorageConfig& aMsStorage)
   183  	{
   184     __MSFNLOG
   185  	aMessage.ReadL(0,aMsStorage.iVendorId);
   186  	aMessage.ReadL(1,aMsStorage.iProductId);
   187  	aMessage.ReadL(2,aMsStorage.iProductRev);
   188  	}