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: Implements a Symbian OS server that exposes the RUsbMassStorage API
|
|
14 |
//
|
|
15 |
//
|
|
16 |
|
|
17 |
#include <e32svr.h>
|
|
18 |
#include "usbmscfileshared.h"
|
|
19 |
#include "mscfileserver.h"
|
|
20 |
#include "mscfilesession.h"
|
|
21 |
#include "mscfileserversecuritypolicy.h"
|
|
22 |
#include "mscfilecontroller.h"
|
|
23 |
#include "debug.h"
|
|
24 |
|
|
25 |
/**
|
|
26 |
Constructs a USB mass storage Server
|
|
27 |
|
|
28 |
@return a pointer to CMscFileServer object
|
|
29 |
*/
|
|
30 |
CMscFileServer* CMscFileServer::NewLC()
|
|
31 |
{
|
|
32 |
CMscFileServer* r = new (ELeave) CMscFileServer();
|
|
33 |
CleanupStack::PushL(r);
|
|
34 |
r->ConstructL();
|
|
35 |
return r;
|
|
36 |
}
|
|
37 |
|
|
38 |
/**
|
|
39 |
Destructor
|
|
40 |
*/
|
|
41 |
CMscFileServer::~CMscFileServer()
|
|
42 |
{
|
|
43 |
TRACE_FUNC
|
|
44 |
|
|
45 |
delete iController;
|
|
46 |
}
|
|
47 |
|
|
48 |
/**
|
|
49 |
Constructor
|
|
50 |
|
|
51 |
@param aController a USB mass storage controller reference
|
|
52 |
*/
|
|
53 |
CMscFileServer::CMscFileServer()
|
|
54 |
: CPolicyServer(EPriorityHigh, KMscFileServerPolicy)
|
|
55 |
{
|
|
56 |
}
|
|
57 |
|
|
58 |
void CMscFileServer::ConstructL()
|
|
59 |
{
|
|
60 |
TRACE_FUNC
|
|
61 |
|
|
62 |
StartL( KMscFileServerName );
|
|
63 |
|
|
64 |
iController = CMscFileController::NewL();
|
|
65 |
}
|
|
66 |
/**
|
|
67 |
Create a new session on this server
|
|
68 |
|
|
69 |
@param &aVersion Version of client
|
|
70 |
@return A pointer to a session object to be used for the client
|
|
71 |
*/
|
|
72 |
CSession2* CMscFileServer::NewSessionL(const TVersion &aVersion, const RMessage2& /*aMessage*/) const
|
|
73 |
{
|
|
74 |
TRACE_FUNC
|
|
75 |
TVersion v( KUsbMsSrvMajorVersionNumber,
|
|
76 |
KUsbMsSrvMinorVersionNumber,
|
|
77 |
KUsbMsSrvBuildVersionNumber );
|
|
78 |
|
|
79 |
if ( !User::QueryVersionSupported( v, aVersion ) )
|
|
80 |
{
|
|
81 |
User::Leave( KErrNotSupported );
|
|
82 |
}
|
|
83 |
|
|
84 |
CMscFileServer* ncThis = const_cast<CMscFileServer*>(this);
|
|
85 |
CMscFileSession* sess = CMscFileSession::NewL(*ncThis);
|
|
86 |
return sess;
|
|
87 |
}
|
|
88 |
|
|
89 |
|
|
90 |
/**
|
|
91 |
Inform the client there has been an error.
|
|
92 |
|
|
93 |
@param aError The error that has occurred
|
|
94 |
*/
|
|
95 |
void CMscFileServer::Error(TInt aError)
|
|
96 |
{
|
|
97 |
TRACE_STATE(( _L("!! CMscFileServer::Error( %d )"), aError ))
|
|
98 |
|
|
99 |
Message().Complete(aError);
|
|
100 |
ReStart();
|
|
101 |
}
|
|
102 |
|
|
103 |
/**
|
|
104 |
Increment the open session count (iSessionCount) by one.
|
|
105 |
|
|
106 |
@post the number of open sessions is incremented by one
|
|
107 |
*/
|
|
108 |
void CMscFileServer::IncrementSessionCount()
|
|
109 |
{
|
|
110 |
TRACE_STATE(( _L(">< CMscFileServer::IncrementSessionCount( %d )"), iSessionCount ))
|
|
111 |
__ASSERT_DEBUG(iSessionCount >= 0, User::Panic(KUsbMsSvrPncCat, EUsbMsPanicIllegalIPC));
|
|
112 |
|
|
113 |
++iSessionCount;
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
Decrement the open session count (iSessionCount) by one.
|
|
118 |
|
|
119 |
@post the number of open sessions is decremented by one
|
|
120 |
*/
|
|
121 |
void CMscFileServer::DecrementSessionCount()
|
|
122 |
{
|
|
123 |
TRACE_STATE(( _L(">< CMscFileServer::DecrementSessionCount( %d )"), iSessionCount ))
|
|
124 |
__ASSERT_DEBUG(iSessionCount > 0, User::Panic(KUsbMsSvrPncCat, EUsbMsPanicIllegalIPC));
|
|
125 |
|
|
126 |
--iSessionCount;
|
|
127 |
}
|
|
128 |
|
|
129 |
void CMscFileServer::ThreadFunctionL()
|
|
130 |
{
|
|
131 |
TRACE_FUNC_ENTRY
|
|
132 |
|
|
133 |
// Naming the server thread after the server helps to debug panics
|
|
134 |
User::LeaveIfError( User::RenameThread( KMscFileServerName ) );
|
|
135 |
|
|
136 |
// Construct active scheduler
|
|
137 |
CActiveScheduler* activeScheduler = new ( ELeave ) CActiveScheduler;
|
|
138 |
CleanupStack::PushL( activeScheduler ) ;
|
|
139 |
|
|
140 |
// Install active scheduler
|
|
141 |
// We don't need to check whether an active scheduler is already installed
|
|
142 |
// as this is a new thread, so there won't be one
|
|
143 |
CActiveScheduler::Install( activeScheduler );
|
|
144 |
|
|
145 |
// Construct our server
|
|
146 |
CMscFileServer::NewLC(); // Anonymous
|
|
147 |
|
|
148 |
RProcess::Rendezvous( KErrNone );
|
|
149 |
|
|
150 |
// Start handling requests
|
|
151 |
CActiveScheduler::Start();
|
|
152 |
|
|
153 |
//===== thread stopped =====
|
|
154 |
TRACE_INFO(( _L( " MscFileServer thread stopped" ) ))
|
|
155 |
CleanupStack::PopAndDestroy( 2, activeScheduler ); // Anonymous CMscFileServer
|
|
156 |
|
|
157 |
TRACE_FUNC_EXIT
|
|
158 |
}
|
|
159 |
|
|
160 |
|
|
161 |
TInt CMscFileServer::ThreadFunction( TAny* /*aNone*/ )
|
|
162 |
{
|
|
163 |
TRACE_FUNC_ENTRY
|
|
164 |
CTrapCleanup* cleanupStack = CTrapCleanup::New();
|
|
165 |
if ( !cleanupStack )
|
|
166 |
{
|
|
167 |
RThread::Rendezvous( KErrNoMemory );
|
|
168 |
}
|
|
169 |
|
|
170 |
TRAPD( err, ThreadFunctionL() )
|
|
171 |
if ( err != KErrNone )
|
|
172 |
{
|
|
173 |
TRACE_ERROR(( _L( "*** Error! Thread leaves w/ %d ***" ), err ))
|
|
174 |
RThread::Rendezvous( KErrNoMemory );
|
|
175 |
}
|
|
176 |
|
|
177 |
delete cleanupStack;
|
|
178 |
cleanupStack = NULL;
|
|
179 |
|
|
180 |
TRACE_FUNC_EXIT
|
|
181 |
return KErrNone;
|
|
182 |
}
|
|
183 |
|
|
184 |
|
|
185 |
TInt E32Main()
|
|
186 |
{
|
|
187 |
return CMscFileServer::ThreadFunction( NULL );
|
|
188 |
}
|
|
189 |
|
|
190 |
|