29
|
1 |
/*
|
|
2 |
* Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: DUN server
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32property.h>
|
|
20 |
#include "DunServer.h"
|
|
21 |
#include "DunServerUtils.h"
|
|
22 |
#include "DunSession.h"
|
|
23 |
#include "DunDebug.h"
|
|
24 |
#include "DunServerSecurityPolicy.h"
|
|
25 |
#include "dundomainpskeys.h"
|
|
26 |
#include "DunTransporter.h"
|
|
27 |
|
|
28 |
// PubSub security settings constants
|
|
29 |
_LIT_SECURITY_POLICY_PASS( KConnStatusReadPolicy );
|
|
30 |
_LIT_SECURITY_POLICY_C2( KConnStatusWritePolicy,
|
|
31 |
ECapabilityLocalServices,
|
|
32 |
ECapabilityWriteDeviceData );
|
|
33 |
|
|
34 |
// ======== LOCAL FUNCTIONS ========
|
|
35 |
|
|
36 |
// ---------------------------------------------------------------------------
|
|
37 |
// StartServerL Create Active Scheduler and CDunServer.
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
static void StartServerL()
|
|
41 |
{
|
|
42 |
FTRACE(FPrint( _L("CDunServer::StartServerL()") ));
|
|
43 |
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
|
|
44 |
CleanupStack::PushL( scheduler );
|
|
45 |
CActiveScheduler::Install( scheduler );
|
|
46 |
|
|
47 |
CDunServer* server = CDunServer::NewL();
|
|
48 |
CleanupStack::PushL( server );
|
|
49 |
|
|
50 |
User::RenameThread( KDialupServerName );
|
|
51 |
RProcess::Rendezvous( KErrNone );
|
|
52 |
FTRACE(FPrint( _L("CDunServer::StartServerL() Initialization done. Server is running.") ));
|
|
53 |
|
|
54 |
CActiveScheduler::Start(); // run the server
|
|
55 |
|
|
56 |
CleanupStack::PopAndDestroy( server );
|
|
57 |
CleanupStack::PopAndDestroy( scheduler );
|
|
58 |
FTRACE(FPrint( _L("CDunServer::StartServerL() complete") ));
|
|
59 |
}
|
|
60 |
|
|
61 |
// ======== MEMBER FUNCTIONS ========
|
|
62 |
|
|
63 |
// ---------------------------------------------------------------------------
|
|
64 |
// Two-phased constructor.
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
CDunServer* CDunServer::NewL()
|
|
68 |
{
|
|
69 |
CDunServer* self = new (ELeave) CDunServer( EPriorityStandard );
|
|
70 |
CleanupStack::PushL( self );
|
|
71 |
self->ConstructL();
|
|
72 |
CleanupStack::Pop( self );
|
|
73 |
return self;
|
|
74 |
}
|
|
75 |
|
|
76 |
// ---------------------------------------------------------------------------
|
|
77 |
// Destructor.
|
|
78 |
// ---------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
CDunServer::~CDunServer()
|
|
81 |
{
|
|
82 |
FTRACE(FPrint(_L("CDunServer::~CDunServer()")));
|
|
83 |
// Destroy iConnData
|
|
84 |
TInt i;
|
|
85 |
for ( i=iConnData.Count()-1; i>=0; i-- )
|
|
86 |
{
|
|
87 |
if ( iUtility )
|
|
88 |
{
|
|
89 |
iUtility->TryClosePlugin( i, EFalse, EFalse, EFalse );
|
|
90 |
}
|
|
91 |
}
|
|
92 |
if ( iConnData.Count() == 0 )
|
|
93 |
{
|
|
94 |
iConnData.Close();
|
|
95 |
}
|
|
96 |
else
|
|
97 |
{
|
|
98 |
FTRACE(FPrint(_L("CDunServer::~CDunServer() (ERROR) complete")));
|
|
99 |
}
|
|
100 |
// Destroy iPluginQueue
|
|
101 |
iPluginQueue.Close();
|
|
102 |
// Destroy iClosedQueue
|
|
103 |
iClosedQueue.Close();
|
|
104 |
// Destroy transporter
|
|
105 |
delete iTransporter;
|
|
106 |
iTransporter = NULL;
|
|
107 |
// Destroy utility
|
|
108 |
CDunServerUtils* utility = static_cast<CDunServerUtils*>( iUtility );
|
|
109 |
delete utility;
|
|
110 |
iUtility = NULL;
|
|
111 |
// Destroy close waiter
|
|
112 |
delete iCloseWait;
|
|
113 |
iCloseWait = NULL;
|
|
114 |
// Remove key
|
|
115 |
RProperty::Delete( KPSUidDialupConnStatus, KDialupConnStatus );
|
|
116 |
FTRACE(FPrint(_L("CDunServer::~CDunServer() complete")));
|
|
117 |
}
|
|
118 |
|
|
119 |
// ---------------------------------------------------------------------------
|
|
120 |
// Notification to manage local media On request
|
|
121 |
// This comes from client
|
|
122 |
// ---------------------------------------------------------------------------
|
|
123 |
//
|
|
124 |
TInt CDunServer::NotifyMediaOpenRequest( TUid aPluginUid )
|
|
125 |
{
|
|
126 |
FTRACE(FPrint(_L("CDunServer::NotifyMediaOpenRequest()")));
|
|
127 |
iUtility->ClearQueuedUIDs( aPluginUid, ETrue, ETrue );
|
|
128 |
iUtility->RemoveZombiePlugins();
|
|
129 |
TInt retVal = OpenMediaByUid( aPluginUid, ETrue );
|
|
130 |
FTRACE(FPrint(_L("CDunServer::NotifyMediaOpenRequest() complete (%d)"), retVal));
|
|
131 |
return retVal;
|
|
132 |
}
|
|
133 |
|
|
134 |
// ---------------------------------------------------------------------------
|
|
135 |
// Notification to manage local media Off request
|
|
136 |
// This comes from client
|
|
137 |
// ---------------------------------------------------------------------------
|
|
138 |
//
|
|
139 |
TInt CDunServer::NotifyMediaCloseRequest( TUid aPluginUid )
|
|
140 |
{
|
|
141 |
FTRACE(FPrint(_L("CDunServer::NotifyMediaCloseRequest()")));
|
|
142 |
// If plugin can be found with iEnqueue or iClosed marked ETrue,
|
|
143 |
// Close also them in the same way (no special processing needed)
|
|
144 |
TInt retVal = CloseMediaByUid( aPluginUid, ETrue, ETrue, ETrue );
|
|
145 |
FTRACE(FPrint(_L("CDunServer::NotifyMediaCloseRequest() complete (%d)"), retVal));
|
|
146 |
return retVal;
|
|
147 |
}
|
|
148 |
|
|
149 |
// ---------------------------------------------------------------------------
|
|
150 |
// Current active connection
|
|
151 |
// This comes from client
|
|
152 |
// ---------------------------------------------------------------------------
|
|
153 |
//
|
|
154 |
TConnId CDunServer::ActiveConnection()
|
|
155 |
{
|
|
156 |
FTRACE(FPrint(_L("CDunServer::ActiveConnection()")));
|
|
157 |
if ( iConnData.Count()<1 || iConnData.Count()>1 )
|
|
158 |
{
|
|
159 |
FTRACE(FPrint(_L("CDunServer::ActiveConnection() (unknown plugin amount) complete")));
|
|
160 |
return NULL;
|
|
161 |
}
|
|
162 |
TDunConnectionData& plugin = iConnData[0];
|
|
163 |
if ( !plugin.iLocalModulePtr )
|
|
164 |
{
|
|
165 |
FTRACE(FPrint(_L("CDunServer::ActiveConnection() (no instance) complete")));
|
|
166 |
return NULL;
|
|
167 |
}
|
|
168 |
TConnId connId = plugin.iLocalModulePtr->ActiveConnection();
|
|
169 |
FTRACE(FPrint(_L("CDunServer::ActiveConnection() complete")));
|
|
170 |
return connId;
|
|
171 |
}
|
|
172 |
|
|
173 |
// ---------------------------------------------------------------------------
|
|
174 |
// Increases reference count made by sessions
|
|
175 |
// This comes from client
|
|
176 |
// ---------------------------------------------------------------------------
|
|
177 |
//
|
|
178 |
void CDunServer::IncRefCount()
|
|
179 |
{
|
|
180 |
FTRACE(FPrint(_L("CDunServer::IncRefCount()")));
|
|
181 |
iRefCount++;
|
|
182 |
FTRACE(FPrint(_L("CDunServer::IncRefCount() complete")));
|
|
183 |
}
|
|
184 |
|
|
185 |
// ---------------------------------------------------------------------------
|
|
186 |
// Decreases reference count made by sessions
|
|
187 |
// This comes from client
|
|
188 |
// ---------------------------------------------------------------------------
|
|
189 |
//
|
|
190 |
void CDunServer::DecRefCount()
|
|
191 |
{
|
|
192 |
FTRACE(FPrint(_L("CDunServer::DecRefCount()")));
|
|
193 |
if ( iRefCount > 0 )
|
|
194 |
{
|
|
195 |
iRefCount--;
|
|
196 |
FTRACE(FPrint(_L("CDunServer::DecRefCount() reference count decreased")));
|
|
197 |
if ( iRefCount == 0 )
|
|
198 |
{
|
|
199 |
FTRACE(FPrint(_L("CDunServer::DecRefCount() stopping activescheduler...")));
|
|
200 |
CActiveScheduler::Stop();
|
|
201 |
}
|
|
202 |
}
|
|
203 |
FTRACE(FPrint(_L("CDunServer::DecRefCount() complete")));
|
|
204 |
}
|
|
205 |
|
|
206 |
// ---------------------------------------------------------------------------
|
|
207 |
// From class CServer2 (CPolicyServer -> CServer2).
|
|
208 |
// Creates a server-side client session object.
|
|
209 |
// ---------------------------------------------------------------------------
|
|
210 |
//
|
|
211 |
CSession2* CDunServer::NewSessionL( const TVersion& aVersion,
|
|
212 |
const RMessage2& /*aMessage*/ ) const
|
|
213 |
{
|
|
214 |
FTRACE(FPrint(_L("CDunServer::NewSessionL()")));
|
|
215 |
TVersion version(KDunServerMajorVersionNumber,
|
|
216 |
KDunServerMinorVersionNumber,
|
|
217 |
KDunServerBuildVersionNumber );
|
|
218 |
TBool supported = User::QueryVersionSupported( version, aVersion );
|
|
219 |
if ( !supported )
|
|
220 |
{
|
|
221 |
FTRACE(FPrint(_L("CDunServer::NewSessionL() (not supported) complete")));
|
|
222 |
User::Leave( KErrNotSupported );
|
|
223 |
}
|
|
224 |
CDunSession* session = new (ELeave) CDunSession(const_cast<CDunServer*>( this ));
|
|
225 |
FTRACE(FPrint(_L("CDunServer::NewSessionL() complete")));
|
|
226 |
return session;
|
|
227 |
}
|
|
228 |
|
|
229 |
// ---------------------------------------------------------------------------
|
|
230 |
// CDunServer::CDunServer
|
|
231 |
// ---------------------------------------------------------------------------
|
|
232 |
//
|
|
233 |
CDunServer::CDunServer( TInt aPriority ) :
|
|
234 |
// aPriority: priority of AO
|
|
235 |
// KDunServerPolicy: TPolicy structure of DUN
|
|
236 |
CPolicyServer( aPriority, KDunServerPolicy ),
|
|
237 |
iTransporter( NULL ),
|
|
238 |
iConnStatus( EDialupUndefined ),
|
|
239 |
iRefCount( 0 )
|
|
240 |
{
|
|
241 |
FTRACE( FPrint( _L( "CDunServer::CDunServer()" )));
|
|
242 |
}
|
|
243 |
|
|
244 |
// ---------------------------------------------------------------------------
|
|
245 |
// CDunServer::ConstructL
|
|
246 |
// ---------------------------------------------------------------------------
|
|
247 |
//
|
|
248 |
void CDunServer::ConstructL()
|
|
249 |
{
|
|
250 |
FTRACE( FPrint( _L( "CDunServer::ConstructL()" )));
|
|
251 |
StartL( KDialupServerName );
|
|
252 |
// Initialize pubsub key properties
|
|
253 |
User::LeaveIfError(
|
|
254 |
RProperty::Define( KPSUidDialupConnStatus,
|
|
255 |
KDialupConnStatus,
|
|
256 |
RProperty::EInt,
|
|
257 |
KConnStatusReadPolicy,
|
|
258 |
KConnStatusWritePolicy) );
|
|
259 |
// Set key to initial value
|
|
260 |
RProperty::Set( KPSUidDialupConnStatus,
|
|
261 |
KDialupConnStatus,
|
|
262 |
EDialupInactive );
|
|
263 |
// Create waiter for closing self-destruct plugins
|
|
264 |
CDunCloseWait* closeWait = CDunCloseWait::NewL( this );
|
|
265 |
CleanupStack::PushL( closeWait );
|
|
266 |
// Create transporter
|
|
267 |
CDunTransporter* transporter = CDunTransporter::NewL( this );
|
|
268 |
CleanupStack::PushL( transporter );
|
|
269 |
// Create utility
|
|
270 |
CDunServerUtils* utility = CDunServerUtils::NewL( *this );
|
|
271 |
iUtility = static_cast<MDunServerUtility*>( utility );
|
|
272 |
iTransporter = transporter;
|
|
273 |
iCloseWait = closeWait;
|
|
274 |
CleanupStack::Pop( transporter );
|
|
275 |
CleanupStack::Pop( closeWait );
|
|
276 |
FTRACE( FPrint( _L( "CDunServer::ConstructL() complete")));
|
|
277 |
}
|
|
278 |
|
|
279 |
// ---------------------------------------------------------------------------
|
|
280 |
// Opens local media plugin by UID
|
|
281 |
// ---------------------------------------------------------------------------
|
|
282 |
//
|
|
283 |
TInt CDunServer::OpenMediaByUid( TUid aPluginUid, TBool aDequeue )
|
|
284 |
{
|
|
285 |
FTRACE(FPrint(_L("CDunServer::OpenMediaByUid()")));
|
|
286 |
TInt i;
|
|
287 |
TInt count = iConnData.Count();
|
|
288 |
for ( i=0; i<count; i++ )
|
|
289 |
{
|
|
290 |
if ( iConnData[i].iLocalModuleUid == aPluginUid )
|
|
291 |
{
|
|
292 |
FTRACE(FPrint(_L("CDunServer::OpenMediaByUid() (already exists) complete")));
|
|
293 |
return KErrAlreadyExists;
|
|
294 |
}
|
|
295 |
}
|
|
296 |
FTRACE(FPrint(_L("CDunServer::OpenMediaByUid() creating new plugin 0x%08X"), aPluginUid.iUid));
|
|
297 |
TInt retTemp = iUtility->CreateNewPlugin( aPluginUid );
|
|
298 |
if ( retTemp != KErrNone )
|
|
299 |
{
|
|
300 |
FTRACE(FPrint(_L("CDunServer::OpenMediaByUid() (ERROR) complete")));
|
|
301 |
return retTemp;
|
|
302 |
}
|
|
303 |
TInt pluginIndex = iConnData.Count() - 1;
|
|
304 |
FTRACE(FPrint(_L("CDunServer::OpenMediaByUid() trying listen at index %d"), pluginIndex));
|
|
305 |
retTemp = iUtility->TryListening( pluginIndex );
|
|
306 |
if ( retTemp != KErrNone )
|
|
307 |
{
|
|
308 |
FTRACE(FPrint(_L("CDunServer::OpenMediaByUid() trying close at index %d"), pluginIndex));
|
|
309 |
iUtility->TryClosePlugin( pluginIndex, aDequeue, EFalse, EFalse );
|
|
310 |
// Ignore error(s), TryClosePlugin()'s TryUninitialize already sets to Zombie if error(s)
|
|
311 |
FTRACE(FPrint(_L("CDunServer::OpenMediaByUid() (ERROR) complete")));
|
|
312 |
return retTemp;
|
|
313 |
}
|
|
314 |
// Clear queued also from queued plugin UIDs, just to be safe
|
|
315 |
iUtility->ClearQueuedUIDs( aPluginUid, ETrue, ETrue );
|
|
316 |
FTRACE(FPrint(_L("CDunServer::OpenMediaByUid() complete")));
|
|
317 |
return KErrNone;
|
|
318 |
}
|
|
319 |
|
|
320 |
// ---------------------------------------------------------------------------
|
|
321 |
// Closes local media plugin by UID
|
|
322 |
// ---------------------------------------------------------------------------
|
|
323 |
//
|
|
324 |
TInt CDunServer::CloseMediaByUid( TUid aPluginUid,
|
|
325 |
TBool aClearQueued,
|
|
326 |
TBool aClientClose,
|
|
327 |
TBool aSelfDelete )
|
|
328 |
{
|
|
329 |
FTRACE(FPrint(_L("CDunServer::CloseMediaByUid()")));
|
|
330 |
TInt i;
|
|
331 |
TBool cleared = EFalse;
|
|
332 |
if ( aClearQueued )
|
|
333 |
{
|
|
334 |
cleared = iUtility->ClearQueuedUIDs( aPluginUid, ETrue, ETrue );
|
|
335 |
}
|
|
336 |
TInt count = iConnData.Count();
|
|
337 |
for ( i=0; i<count; i++ )
|
|
338 |
{
|
|
339 |
if ( iConnData[i].iLocalModuleUid == aPluginUid )
|
|
340 |
{
|
|
341 |
break;
|
|
342 |
}
|
|
343 |
}
|
|
344 |
if ( i >= count )
|
|
345 |
{
|
|
346 |
FTRACE(FPrint(_L("CDunServer::CloseMediaByUid() (not found) complete")));
|
|
347 |
return KErrNotFound;
|
|
348 |
}
|
|
349 |
FTRACE(FPrint(_L("CDunServer::CloseMediaByUid() trying close at index %d"), i));
|
|
350 |
// Plugin found from main list, now close
|
|
351 |
TInt retTemp = iUtility->TryClosePlugin( i,
|
|
352 |
ETrue,
|
|
353 |
aClientClose,
|
|
354 |
aSelfDelete );
|
|
355 |
if ( retTemp!=KErrNone && !cleared )
|
|
356 |
{
|
|
357 |
FTRACE(FPrint(_L("CDunServer::CloseMediaByUid() (ERROR) complete")));
|
|
358 |
return retTemp;
|
|
359 |
}
|
|
360 |
FTRACE(FPrint(_L("CDunServer::CloseMediaByUid() complete")));
|
|
361 |
return KErrNone;
|
|
362 |
}
|
|
363 |
|
|
364 |
// ---------------------------------------------------------------------------
|
|
365 |
// Reopens plugins from plugin queue
|
|
366 |
// ---------------------------------------------------------------------------
|
|
367 |
//
|
|
368 |
TInt CDunServer::ReopenQueuedPlugins()
|
|
369 |
{
|
|
370 |
FTRACE(FPrint(_L("CDunServer::ReopenQueuedPlugins() (%d)"), iPluginQueue.Count()));
|
|
371 |
TInt i = iPluginQueue.Count() - 1;
|
|
372 |
while ( i >= 0 )
|
|
373 |
{
|
|
374 |
TInt retTemp = OpenMediaByUid( iPluginQueue[i], EFalse );
|
|
375 |
if ( retTemp == KErrNone )
|
|
376 |
{
|
|
377 |
// Open succeeded so plugin UID was removed by ClearQueuedUIDs().
|
|
378 |
// Recalculate i because this method can remove more than one
|
|
379 |
// match.
|
|
380 |
i = iPluginQueue.Count() - 1;
|
|
381 |
}
|
|
382 |
else
|
|
383 |
{
|
|
384 |
// Open failed so the plugin UID was not removed from queue.
|
|
385 |
// Just decrease index (avoid forever loop).
|
|
386 |
i--;
|
|
387 |
}
|
|
388 |
}
|
|
389 |
FTRACE(FPrint(_L("CDunServer::ReopenQueuedPlugin()")));
|
|
390 |
return KErrNone;
|
|
391 |
}
|
|
392 |
|
|
393 |
// ---------------------------------------------------------------------------
|
|
394 |
// From class MDunServerCallback.
|
|
395 |
// Searches for plugin in connection data and returns its state
|
|
396 |
// ---------------------------------------------------------------------------
|
|
397 |
//
|
|
398 |
TDunPluginState CDunServer::GetPluginStateByUid( TUid aPluginUid )
|
|
399 |
{
|
|
400 |
FTRACE(FPrint(_L("CDunServer::GetPluginStateByUid()")));
|
|
401 |
TInt i;
|
|
402 |
TInt count = iConnData.Count();
|
|
403 |
for ( i=0; i<count; i++ )
|
|
404 |
{
|
|
405 |
if ( iConnData[i].iLocalModuleUid == aPluginUid )
|
|
406 |
{
|
|
407 |
break;
|
|
408 |
}
|
|
409 |
}
|
|
410 |
if ( i >= count )
|
|
411 |
{
|
|
412 |
FTRACE(FPrint(_L("CDunServer::GetPluginStateByUid() (not found) complete")));
|
|
413 |
return EDunStateNone;
|
|
414 |
}
|
|
415 |
FTRACE(FPrint(_L("CDunServer::GetPluginStateByUid() state at index %d is %d"), i, iConnData[i].iPluginState));
|
|
416 |
FTRACE(FPrint(_L("CDunServer::GetPluginStateByUid() complete")));
|
|
417 |
return iConnData[i].iPluginState;
|
|
418 |
}
|
|
419 |
|
|
420 |
// ---------------------------------------------------------------------------
|
|
421 |
// From class MDunServerCallback.
|
|
422 |
// Notification about request to change plugin state up by one level
|
|
423 |
// ---------------------------------------------------------------------------
|
|
424 |
//
|
|
425 |
TInt CDunServer::NotifyPluginStateChangeUp( TDunPluginState aPluginState,
|
|
426 |
TUid aPluginUid )
|
|
427 |
{
|
|
428 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeUp()")));
|
|
429 |
TInt i;
|
|
430 |
TInt count = iConnData.Count();
|
|
431 |
for ( i=0; i<count; i++ )
|
|
432 |
{
|
|
433 |
if ( iConnData[i].iLocalModuleUid == aPluginUid )
|
|
434 |
{
|
|
435 |
break;
|
|
436 |
}
|
|
437 |
}
|
|
438 |
if ( i >= count )
|
|
439 |
{
|
|
440 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeUp() (not found) complete")));
|
|
441 |
return KErrNotFound;
|
|
442 |
}
|
|
443 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeUp() found at index %d"), i));
|
|
444 |
TDunPluginState pluginState = iConnData[i].iPluginState;
|
|
445 |
if ( pluginState<EDunStateTryUninitialize || aPluginState-pluginState!=1 )
|
|
446 |
{
|
|
447 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeUp() (unknown state) complete (%d/%d)"), pluginState, aPluginState));
|
|
448 |
return KErrNotSupported;
|
|
449 |
}
|
|
450 |
iConnData[i].iPluginState = aPluginState;
|
|
451 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeUp() state changed to %d(%d)"), aPluginState, pluginState));
|
|
452 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeUp() complete")));
|
|
453 |
return KErrNone;
|
|
454 |
}
|
|
455 |
|
|
456 |
// ---------------------------------------------------------------------------
|
|
457 |
// From class MDunServerCallback.
|
|
458 |
// Notification about request to change plugin state down by one level
|
|
459 |
// ---------------------------------------------------------------------------
|
|
460 |
//
|
|
461 |
TInt CDunServer::NotifyPluginStateChangeDown( TDunPluginState aPluginState,
|
|
462 |
TUid aPluginUid)
|
|
463 |
{
|
|
464 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeDown()")));
|
|
465 |
TInt i;
|
|
466 |
TInt count = iConnData.Count();
|
|
467 |
for ( i=0; i<count; i++ )
|
|
468 |
{
|
|
469 |
if ( iConnData[i].iLocalModuleUid == aPluginUid )
|
|
470 |
{
|
|
471 |
break;
|
|
472 |
}
|
|
473 |
}
|
|
474 |
if ( i >= count )
|
|
475 |
{
|
|
476 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeDown() (not found) complete")));
|
|
477 |
return KErrNotFound;
|
|
478 |
}
|
|
479 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeDown() found at index %d"), i));
|
|
480 |
TDunPluginState pluginState = iConnData[i].iPluginState;
|
|
481 |
if ( aPluginState >= pluginState )
|
|
482 |
{
|
|
483 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeDown() (unknown state) complete (%d/%d)"), pluginState, aPluginState));
|
|
484 |
return KErrNotSupported;
|
|
485 |
}
|
|
486 |
// Next catch the cases where state is not "try"
|
|
487 |
if ( aPluginState != EDunStateTryUninitialize &&
|
|
488 |
aPluginState != EDunStateTryLoad &&
|
|
489 |
aPluginState != EDunStateTryListen &&
|
|
490 |
aPluginState != EDunStateTryChannel )
|
|
491 |
{
|
|
492 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeDown() (unknown state) complete (%d/%d)"), pluginState, aPluginState));
|
|
493 |
return KErrNotSupported;
|
|
494 |
}
|
|
495 |
iConnData[i].iPluginState = aPluginState;
|
|
496 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeDown() state changed to %d(%d)"), aPluginState, pluginState));
|
|
497 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginStateChangeDown() complete")));
|
|
498 |
return KErrNone;
|
|
499 |
}
|
|
500 |
|
|
501 |
// ---------------------------------------------------------------------------
|
|
502 |
// From class MDunServerCallback.
|
|
503 |
// Notification about plugin restart request
|
|
504 |
// ---------------------------------------------------------------------------
|
|
505 |
//
|
|
506 |
TInt CDunServer::NotifyPluginRestart( TUid aPluginUid )
|
|
507 |
{
|
|
508 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginRestart()")));
|
|
509 |
TInt retTemp = iUtility->TryInitializeToListening( aPluginUid );
|
|
510 |
if ( retTemp != KErrNone )
|
|
511 |
{
|
|
512 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginRestart() (ERROR) initialize failed")));
|
|
513 |
return retTemp;
|
|
514 |
}
|
|
515 |
// Restarting may have freed channel(s),
|
|
516 |
// try to reopen queued plugins (ignore error(s))
|
|
517 |
ReopenQueuedPlugins();
|
|
518 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginRestart() complete")));
|
|
519 |
return KErrNone;
|
|
520 |
}
|
|
521 |
|
|
522 |
// ---------------------------------------------------------------------------
|
|
523 |
// From class MDunServerCallback.
|
|
524 |
// Notification about plugin restart request
|
|
525 |
// ---------------------------------------------------------------------------
|
|
526 |
//
|
|
527 |
TInt CDunServer::NotifyPluginReopenRequest()
|
|
528 |
{
|
|
529 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginReopenRequest()")));
|
|
530 |
TInt retVal = ReopenQueuedPlugins();
|
|
531 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginReopenRequest() complete")));
|
|
532 |
return retVal;
|
|
533 |
}
|
|
534 |
|
|
535 |
// ---------------------------------------------------------------------------
|
|
536 |
// From class MDunPluginManager (MDunServerCallback->MDunPluginManager).
|
|
537 |
// Notification about request to enqueue a plugin to plugin queue
|
|
538 |
// ---------------------------------------------------------------------------
|
|
539 |
//
|
|
540 |
TInt CDunServer::NotifyPluginEnqueueRequest( TUid aPluginUid )
|
|
541 |
{
|
|
542 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginEnqueueRequest()")));
|
|
543 |
TInt i;
|
|
544 |
TInt count = iConnData.Count();
|
|
545 |
for ( i=0; i<count; i++ )
|
|
546 |
{
|
|
547 |
if ( iConnData[i].iLocalModuleUid == aPluginUid )
|
|
548 |
{
|
|
549 |
break;
|
|
550 |
}
|
|
551 |
}
|
|
552 |
if ( i >= count )
|
|
553 |
{
|
|
554 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginEnqueueRequest() (not found) complete")));
|
|
555 |
return KErrNotFound;
|
|
556 |
}
|
|
557 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginEnqueueRequest() found at index %d"), i));
|
|
558 |
// Plugin exists, now try to find it from plugin queue
|
|
559 |
count = iPluginQueue.Count();
|
|
560 |
for ( i=0; i<count; i++ )
|
|
561 |
{
|
|
562 |
if ( iPluginQueue[i] == aPluginUid )
|
|
563 |
{
|
|
564 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginEnqueueRequest() (already exists) complete")));
|
|
565 |
return KErrAlreadyExists;
|
|
566 |
}
|
|
567 |
}
|
|
568 |
// New plugin found, queue
|
|
569 |
TInt retTemp = CloseMediaByUid( aPluginUid, EFalse, EFalse, ETrue );
|
|
570 |
if ( retTemp != KErrNone )
|
|
571 |
{
|
|
572 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginEnqueueRequest() (close failed) complete")));
|
|
573 |
return KErrGeneral;
|
|
574 |
}
|
|
575 |
retTemp = iPluginQueue.Append( aPluginUid );
|
|
576 |
if ( retTemp != KErrNone )
|
|
577 |
{
|
|
578 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginEnqueueRequest() (append failed!) complete")));
|
|
579 |
return retTemp;
|
|
580 |
}
|
|
581 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginEnqueueRequest() appended to index %d"), iPluginQueue.Count()-1));
|
|
582 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginEnqueueRequest() complete")));
|
|
583 |
return KErrNone;
|
|
584 |
}
|
|
585 |
|
|
586 |
// ---------------------------------------------------------------------------
|
|
587 |
// From class MDunPluginManager (MDunServerCallback->MDunPluginManager).
|
|
588 |
// Notification about request to dequeue a plugin from plugin queue
|
|
589 |
// ---------------------------------------------------------------------------
|
|
590 |
//
|
|
591 |
TInt CDunServer::NotifyPluginDequeueRequest( TUid aPluginUid )
|
|
592 |
{
|
|
593 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginDequeueRequest()")));
|
|
594 |
TBool cleared = iUtility->ClearQueuedUIDs( aPluginUid, ETrue, ETrue );
|
|
595 |
if ( !cleared )
|
|
596 |
{
|
|
597 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginDequeueRequest() (not found) complete")));
|
|
598 |
return KErrNotFound;
|
|
599 |
}
|
|
600 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginDequeueRequest() complete")));
|
|
601 |
return KErrNone;
|
|
602 |
}
|
|
603 |
|
|
604 |
// ---------------------------------------------------------------------------
|
|
605 |
// From class MDunPluginManager (MDunServerCallback->MDunPluginManager).
|
|
606 |
// Notification about request to close a plugin
|
|
607 |
// ---------------------------------------------------------------------------
|
|
608 |
//
|
|
609 |
TInt CDunServer::NotifyPluginCloseRequest( TUid aPluginUid, TBool aSelfClose )
|
|
610 |
{
|
|
611 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginCloseRequest()")));
|
|
612 |
TInt retTemp = CloseMediaByUid( aPluginUid, ETrue, EFalse, aSelfClose );
|
|
613 |
if ( retTemp != KErrNone )
|
|
614 |
{
|
|
615 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginCloseRequest() (ERROR) complete")));
|
|
616 |
return retTemp;
|
|
617 |
}
|
|
618 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginCloseRequest() complete")));
|
|
619 |
return KErrNone;
|
|
620 |
}
|
|
621 |
|
|
622 |
// ---------------------------------------------------------------------------
|
|
623 |
// From MDunCloseWait.
|
|
624 |
// Notification about request to close a plugin after wait
|
|
625 |
// ---------------------------------------------------------------------------
|
|
626 |
//
|
|
627 |
void CDunServer::NotifyPluginCloseAfterWait(
|
|
628 |
RPointerArray<MDunLocalMediaPlugin>& aPluginsToClose )
|
|
629 |
{
|
|
630 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginCloseAfterWait()")));
|
|
631 |
TInt i;
|
|
632 |
TInt j;
|
|
633 |
TInt closeCount = aPluginsToClose.Count();
|
|
634 |
for ( i=0; i<closeCount; i++ )
|
|
635 |
{
|
|
636 |
// keep iConnData.Count() on the line below as it changes!
|
|
637 |
for ( j=0; j<iConnData.Count(); j++ )
|
|
638 |
{
|
|
639 |
if ( iConnData[j].iLocalModulePtr == aPluginsToClose[i] )
|
|
640 |
{
|
|
641 |
iUtility->DoClosePlugin( j, ETrue, EFalse );
|
|
642 |
}
|
|
643 |
}
|
|
644 |
}
|
|
645 |
FTRACE(FPrint(_L("CDunServer::NotifyPluginCloseAfterWait() complete")));
|
|
646 |
}
|
|
647 |
|
|
648 |
// ======== GLOBAL FUNCTIONS ========
|
|
649 |
|
|
650 |
// ---------------------------------------------------------------------------
|
|
651 |
// WinsMain/E32Main implements main function for DUN
|
|
652 |
// exe.
|
|
653 |
// Create Cleanup Stack, initialise server and start Active
|
|
654 |
// Scheduler.
|
|
655 |
// Returns: Error value: General error value
|
|
656 |
// ---------------------------------------------------------------------------
|
|
657 |
//
|
|
658 |
TInt E32Main()
|
|
659 |
{
|
|
660 |
FTRACE(FPrint( _L("CDunServer::Main() Process started.") ));
|
|
661 |
__UHEAP_MARK;
|
|
662 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
663 |
TInt retVal = KErrNoMemory;
|
|
664 |
|
|
665 |
if ( cleanup )
|
|
666 |
{
|
|
667 |
TRAP( retVal, StartServerL() ); // perform all other initialisation
|
|
668 |
delete cleanup;
|
|
669 |
}
|
|
670 |
__UHEAP_MARKEND;
|
|
671 |
|
|
672 |
FTRACE(FPrint( _L("CDunServer::Main() Process exit code = %d"), retVal));
|
|
673 |
return retVal;
|
|
674 |
}
|