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