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