usbclasses/usbphoneasmodem/classimplementation/mscfileserver/src/mscfilesession.cpp
changeset 34 7858bc6ead78
parent 31 dfdd8240f7c8
child 35 9d8b04ca6939
equal deleted inserted replaced
31:dfdd8240f7c8 34:7858bc6ead78
     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 "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: Implements a Session of a Symbian OS server for the RUsbMassStorage API
       
    14 // 
       
    15 // 
       
    16 
       
    17 #include <e32property.h>
       
    18 #include <coreapplicationuisdomainpskeys.h>
       
    19 #include "mscfilesession.h"
       
    20 #include "mscfilecontroller.h"
       
    21 #include "mscfileserver.h"
       
    22 #include "usbmscfileshared.h"
       
    23 #include "debug.h"
       
    24 
       
    25 /**
       
    26  Construct a Symbian OS session object.
       
    27  
       
    28  @param	aServer		Service the session will be a member of
       
    29  @param	aMessage	The message from the client.
       
    30  @return	A new CMscFileSession object
       
    31  */
       
    32 CMscFileSession* CMscFileSession::NewL(CMscFileServer& aServer)
       
    33 	{
       
    34 	CMscFileSession* r = new (ELeave) CMscFileSession(aServer);
       
    35 	CleanupStack::PushL(r);
       
    36 	r->ConstructL();
       
    37 	CleanupStack::Pop();
       
    38 	return r;
       
    39 	}
       
    40 
       
    41 /**
       
    42  Constructor.
       
    43  
       
    44  @param	aServer	Service the session will be a member of
       
    45  */
       
    46 CMscFileSession::CMscFileSession(CMscFileServer& aServer)
       
    47 	: iMscFileServer( aServer )
       
    48 	{
       
    49     TRACE_FUNC
       
    50 	}
       
    51 
       
    52 
       
    53 /**
       
    54  2nd Phase Construction.
       
    55  */
       
    56 void CMscFileSession::ConstructL()
       
    57 	{
       
    58 	TRACE_FUNC
       
    59 	iMscFileServer.IncrementSessionCount();
       
    60     if ( iMscFileServer.SessionCount() > 1 )
       
    61         {
       
    62         TRACE_ERROR(( _L( "SessionCount: %d" ), iMscFileServer.SessionCount() ))
       
    63         // Only one session is allowed
       
    64         User::Leave( KErrInUse );
       
    65         }        
       
    66  	}
       
    67 
       
    68 
       
    69 /**
       
    70  Destructor.
       
    71  */
       
    72 CMscFileSession::~CMscFileSession()
       
    73 	{
       
    74 	iMscFileServer.DecrementSessionCount();
       
    75 	}
       
    76 
       
    77 /**
       
    78  Called when a message is received from the client.
       
    79  
       
    80  @param	aMessage	Message received from the client
       
    81  */
       
    82 void CMscFileSession::ServiceL( const RMessage2& aMessage )
       
    83 	{
       
    84 	TRAPD( err, DispatchMessageL( aMessage ) );
       
    85 	
       
    86     aMessage.Complete( err );
       
    87 	}
       
    88 
       
    89 void CMscFileSession::DispatchMessageL( const RMessage2& aMessage )
       
    90     {
       
    91     switch (aMessage.Function())
       
    92         {
       
    93         case EMscFileSetupLu:
       
    94             SetupLogicalUnitL( aMessage );
       
    95             break;
       
    96             
       
    97         case EMscFileStart:
       
    98             StartL( aMessage );
       
    99             break;
       
   100             
       
   101         case EMscFileStop:
       
   102             LEAVE_IF_ERROR( Stop() );
       
   103             break;
       
   104             
       
   105         case EMscFileShutdown:
       
   106             LEAVE_IF_ERROR( Shutdown() );
       
   107             break;
       
   108 
       
   109         default:
       
   110             aMessage.Panic( KUsbMsCliPncCat, EUsbMsPanicIllegalIPC );
       
   111             break;
       
   112         }
       
   113 
       
   114     }
       
   115 
       
   116 void CMscFileSession::SetupLogicalUnitL( const RMessage2& aMessage )
       
   117     {
       
   118     TRACE_FUNC_ENTRY
       
   119     TInt protocol;
       
   120     TInt lun;
       
   121     RBuf fullImageFileName;
       
   122     TInt len = aMessage.GetDesLength( 0 );
       
   123     fullImageFileName.CreateL( len );
       
   124     fullImageFileName.CleanupClosePushL();
       
   125     aMessage.ReadL( 0, fullImageFileName );
       
   126     protocol = aMessage.Int1();
       
   127     lun = aMessage.Int2();
       
   128     
       
   129     iMscFileServer.Controller().SetupLogicalUnitL( fullImageFileName, protocol, lun );
       
   130     CleanupStack::PopAndDestroy( &fullImageFileName );
       
   131     TRACE_FUNC_EXIT
       
   132     }
       
   133 /**
       
   134  Client request to start the device.
       
   135  
       
   136  @return	Any error that occurred or KErrNone
       
   137  */
       
   138 void CMscFileSession::StartL( const RMessage2& aMessage )
       
   139 	{
       
   140 	TRACE_FUNC
       
   141 
       
   142     User::LeaveIfError(RProperty::Set(KPSUidCoreApplicationUIs, 
       
   143         KCoreAppUIsUSBFileTransfer, 
       
   144         ECoreAppUIsUSBFileTransferActive));
       
   145 	
       
   146 	TMassStorageConfig msConfig;
       
   147 	GetMsConfigL( aMessage, msConfig );
       
   148 	LEAVE_IF_ERROR( iMscFileServer.Controller().Start( msConfig ) );
       
   149 	}
       
   150 
       
   151 /**
       
   152  Client request to stop the device.
       
   153  
       
   154  @return	Any error that occurred or KErrNone
       
   155  */
       
   156 TInt CMscFileSession::Stop()
       
   157     {
       
   158     TRACE_FUNC
       
   159 
       
   160     RProperty::Set(KPSUidCoreApplicationUIs, 
       
   161         KCoreAppUIsUSBFileTransfer, 
       
   162         ECoreAppUIsUSBFileTransferNotActive);
       
   163 
       
   164 	return iMscFileServer.Controller().Stop();
       
   165 	}
       
   166 
       
   167 /**
       
   168  Client request to shut down the server
       
   169  
       
   170  @return KErrNone
       
   171  */
       
   172 TInt CMscFileSession::Shutdown()
       
   173     {
       
   174     TRACE_FUNC
       
   175     CActiveScheduler::Stop();
       
   176 	return KErrNone;
       
   177 	}
       
   178 
       
   179  /**
       
   180   Get mass storage configuration data from the received message
       
   181   */
       
   182  void CMscFileSession::GetMsConfigL( const RMessage2& aMessage, 
       
   183                                      TMassStorageConfig& aMsStorage )
       
   184  	{
       
   185  	aMessage.ReadL( 0, aMsStorage.iVendorId );
       
   186  	aMessage.ReadL( 1, aMsStorage.iProductId );
       
   187  	aMessage.ReadL( 2, aMsStorage.iProductRev );
       
   188  	}