usbclasses/usbphoneasmodem/classimplementation/mscfileserver/src/mscfilecontroller.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  @file
       
    19  CMscFileController implementation.
       
    20 */
       
    21 
       
    22 #include "mscfilecontroller.h"
       
    23 #include "scsiprot.h"
       
    24 #include "bulkonlytransport.h"
       
    25 #include "debug.h"
       
    26 
       
    27 CMscFileController* CMscFileController::NewL()
       
    28     {
       
    29     TRACE_FUNC
       
    30     CMscFileController* self = new (ELeave) CMscFileController;
       
    31     CleanupStack::PushL( self );
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36 /**
       
    37 Destructor
       
    38 */
       
    39 CMscFileController::~CMscFileController()
       
    40 	{
       
    41 	delete iProtocol;
       
    42 	delete iTransport;
       
    43 	delete iFsImage;
       
    44 	}
       
    45 
       
    46 CMscFileController::CMscFileController()
       
    47     {
       
    48     }
       
    49 /**
       
    50 Creates the drive manager, transport, protocol and server
       
    51 
       
    52 @param aMaxDrives Maximum number of Mass Storage drives supported.
       
    53 */
       
    54 void CMscFileController::ConstructL()
       
    55 	{
       
    56 	TRACE_FUNC_ENTRY
       
    57 	iMaxDrives = 1; 
       
    58     TRACE_INFO(( _L( "Creating transport" ) ))
       
    59     iTransport = CBulkOnlyTransport::NewL(iMaxDrives, *this);
       
    60 	TRACE_FUNC_EXIT
       
    61 	}
       
    62 
       
    63 void CMscFileController::SetupLogicalUnitL( const TDesC& aFileName, 
       
    64                                             const TInt /*aProtocol*/, 
       
    65                                             const TInt aLun )
       
    66     {
       
    67     TRACE_FUNC_ENTRY
       
    68     if ( aLun != 0 )
       
    69         {
       
    70         // More than one logical unit is not supported in this version
       
    71         LEAVE( KErrArgument );
       
    72         }
       
    73     if(iFsImage)
       
    74         {
       
    75         delete iFsImage;
       
    76         iFsImage = NULL;
       
    77         }
       
    78     iFsImage = CFileSystemImage::NewL( aFileName );
       
    79 
       
    80     TRACE_INFO(( _L( "Creating protocol" ) ))
       
    81     //create protocol according to aProtocol
       
    82     if(iProtocol)
       
    83         {
       
    84         delete iProtocol;
       
    85         iProtocol = NULL;
       
    86         }
       
    87     iProtocol = CScsiProtocol::NewL( *this );
       
    88     iTransport->RegisterProtocol( *iProtocol );
       
    89     iProtocol->RegisterTransport( iTransport );
       
    90     TRACE_FUNC_EXIT
       
    91     }
       
    92 
       
    93 /**
       
    94 Starts the transport and initializes the protocol.
       
    95 
       
    96 @param aConfig Reference to Mass Storage configuration data
       
    97 */
       
    98 TInt CMscFileController::Start( TMassStorageConfig& aConfig )
       
    99 	{
       
   100 	TRACE_FUNC_ENTRY
       
   101 	//Save this value for use in the Reset method.
       
   102 	iConfig = aConfig;
       
   103 	TInt err = KErrNotReady;
       
   104 	if ( iProtocol && iTransport )
       
   105 		{
       
   106 		TRACE_INFO(( _L( "Starting" ) ))
       
   107 		((CScsiProtocol*)iProtocol)->SetScsiParameters(aConfig);
       
   108 		err = iTransport->Start();
       
   109 		}
       
   110 
       
   111 	TRACE_FUNC_EXIT
       
   112 	return err;
       
   113 	}
       
   114 
       
   115 /**
       
   116 Stops the transport.
       
   117 */
       
   118 TInt CMscFileController::Stop()
       
   119 	{
       
   120 	TRACE_FUNC_ENTRY
       
   121 	TInt err = KErrNotReady;
       
   122 	if ( iTransport )
       
   123 		{
       
   124 		TRACE_INFO(( _L( "Stopping" ) ))
       
   125 		err = iTransport->Stop();
       
   126 		}
       
   127 	TRACE_FUNC_EXIT
       
   128 	return err;
       
   129 	}
       
   130 
       
   131 /**
       
   132 Delete the transport and protocol and start new ones.
       
   133 */
       
   134 void CMscFileController::Reset()
       
   135 	{
       
   136 	TRACE_FUNC
       
   137 	delete iProtocol;
       
   138 	iProtocol = NULL;
       
   139 
       
   140 	//Create transport and protocol and initialize them
       
   141 	TRACE_INFO(_L("Creating  protocol"));
       
   142 
       
   143 	TRAPD(err,iProtocol = CScsiProtocol::NewL(*this));
       
   144 	err = err;
       
   145 	__ASSERT_DEBUG(err==KErrNone, User::Invariant());
       
   146 	iTransport->RegisterProtocol(*iProtocol);
       
   147 	iProtocol->RegisterTransport(iTransport);
       
   148 	}
       
   149 
       
   150 CFileSystemImage* CMscFileController::FsImage( TInt aLun )
       
   151     {
       
   152     // Only 1 LUN supported in this version
       
   153     if ( aLun == 0 )
       
   154         {
       
   155         return iFsImage;
       
   156         }
       
   157     else
       
   158         {
       
   159         return NULL;
       
   160         }
       
   161     }
       
   162 
       
   163