|
1 /* |
|
2 * Copyright (c) 2009-2010 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: |
|
15 * Launches the Connection Method Manager Server. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "cmmclistatic.h" |
|
21 |
|
22 /** |
|
23 * LaunchServer |
|
24 * |
|
25 * Launches the CmManager server. |
|
26 * |
|
27 * Return KErrNone if CmManager server is launched successfully, |
|
28 * otherwise one of the system wide error codes. |
|
29 */ |
|
30 TInt TCmManagerLauncher::LaunchServer( |
|
31 const TDesC& aServerName, |
|
32 const TDesC& aServerFileName, |
|
33 const TUid& aServerUid3, |
|
34 const TUint aWinsMinHeapSize, |
|
35 const TUint aWinsMaxHeapSize, |
|
36 const TUint aWinsStackSize ) |
|
37 { |
|
38 RMutex mutex; |
|
39 TInt err( KErrNone ); |
|
40 const TUidType serverUid( KNullUid, KNullUid, aServerUid3 ); |
|
41 |
|
42 // |
|
43 // EPOC and EKA2 is easy, we just create a new server process. Simultaneous |
|
44 // launching of two such processes should be detected when the second one |
|
45 // attempts to create the server object, failing with KErrAlreadyExists. |
|
46 // |
|
47 |
|
48 // Try obtaining a lock. If that fails, server has already been started. |
|
49 // If something fails with obtaining the lock, propagate the error to user. |
|
50 if ( !ServerStartupLock( mutex, err ) ) |
|
51 { |
|
52 ServerStartupUnlock( mutex ); |
|
53 return err; |
|
54 } |
|
55 |
|
56 RProcess server; |
|
57 err = server.Create( aServerFileName, KNullDesC, serverUid ); |
|
58 (void)aServerName; |
|
59 (void)aWinsMinHeapSize; |
|
60 (void)aWinsMaxHeapSize; |
|
61 (void)aWinsStackSize; |
|
62 |
|
63 if ( err != KErrNone ) |
|
64 { |
|
65 ServerStartupUnlock( mutex ); |
|
66 return err; |
|
67 } |
|
68 |
|
69 TRequestStatus stat; |
|
70 server.Rendezvous( stat ); |
|
71 if ( stat != KRequestPending ) |
|
72 { |
|
73 server.Kill( 0 ); // Abort startup. |
|
74 } |
|
75 else |
|
76 { |
|
77 server.Resume(); // Logon OK - start the server. |
|
78 } |
|
79 User::WaitForRequest( stat ); // Wait for start or death. |
|
80 // We can't use the 'exit reason' if the server panicked as this |
|
81 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
82 // from KErrNone. |
|
83 err = ( server.ExitType() == EExitPanic ) ? KErrGeneral : stat.Int(); |
|
84 server.Close(); |
|
85 |
|
86 ServerStartupUnlock( mutex ); |
|
87 return err; |
|
88 } |
|
89 |
|
90 /** |
|
91 * ServerStartupLock |
|
92 * |
|
93 * Returns true if obtains the lock without waiting. That is, the |
|
94 * mutex is not created before this call. |
|
95 * |
|
96 * Return false if mutex is created. |
|
97 */ |
|
98 TBool TCmManagerLauncher::ServerStartupLock( RMutex& mutex, TInt& err ) |
|
99 { |
|
100 TInt retval( ETrue ); |
|
101 |
|
102 // Create handle to mutex. |
|
103 err = mutex.CreateGlobal( KCmManagerStartupMutex ); |
|
104 if ( err != KErrNone ) |
|
105 { |
|
106 // Mutex already created, wait until done. |
|
107 retval = EFalse; |
|
108 err = mutex.OpenGlobal( KCmManagerStartupMutex ); |
|
109 if ( err == KErrNone ) |
|
110 { |
|
111 // Wait for completion |
|
112 mutex.Wait(); |
|
113 // Server already running, return. |
|
114 return EFalse; |
|
115 } |
|
116 // Else opening failed, err will be propagated to user. |
|
117 } |
|
118 // Else Obtained lock without waiting (retval is ETrue). |
|
119 // The next call completes instantly. |
|
120 mutex.Wait(); |
|
121 return retval; |
|
122 } |
|
123 |
|
124 /** |
|
125 * ServerStartupUnlock |
|
126 * |
|
127 * Frees and closes the mutex. |
|
128 */ |
|
129 void TCmManagerLauncher::ServerStartupUnlock( RMutex& mutex ) |
|
130 { |
|
131 // Let others run |
|
132 mutex.Signal(); |
|
133 // Destroy handle |
|
134 mutex.Close(); |
|
135 } |
|
136 |
|
137 // End of file |