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