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