|
1 /* |
|
2 * Copyright (c) 2002-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: This file contains the implementation of RSWInstSilentLauncher |
|
15 * class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <f32file.h> |
|
22 #include <apgcli.h> |
|
23 #include <e32math.h> |
|
24 #include <eikenv.h> |
|
25 |
|
26 #include "SWInstApi.h" |
|
27 #include "SWInstDefs.h" |
|
28 #include "SWInstCommon.h" |
|
29 |
|
30 using namespace SwiUI; |
|
31 |
|
32 const TUint KMaxServerPoll = 100; |
|
33 |
|
34 #ifdef __WINS__ |
|
35 const TUint KServertPollTimeout = 1000000; //1sec. Wins needs more time. |
|
36 #else |
|
37 const TUint KServertPollTimeout = 100000; |
|
38 #endif |
|
39 |
|
40 // ================= MEMBER FUNCTIONS ======================= |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // RSWInstSilentLauncher::RSWInstSilentLauncher |
|
44 // C++ default constructor can NOT contain any code, that |
|
45 // might leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C RSWInstSilentLauncher::RSWInstSilentLauncher() |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // RSWInstSilentLauncher::Connect |
|
54 // Creates connection to the server. |
|
55 // (other items were commented in a header). |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C TInt RSWInstSilentLauncher::Connect() |
|
59 { |
|
60 TInt result( KErrNone ); |
|
61 |
|
62 TUint differentiator = 0; |
|
63 TRAP( result, differentiator = StartServerL( KUidSWInstSvr ) ); |
|
64 if ( result == KErrNone ) |
|
65 { |
|
66 TName serverName; |
|
67 ConstructServerName( serverName, KUidSWInstSvr, differentiator ); |
|
68 TRAP( result, ConnectExistingByNameL( serverName ) ); |
|
69 if ( result == KErrNone ) |
|
70 { |
|
71 iConnected = ETrue; |
|
72 } |
|
73 } |
|
74 // Return the result code |
|
75 return result; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // RSWInstSilentLauncher::ServiceUid |
|
80 // Returns the UID of the service that this session provides an interface for. |
|
81 // (other items were commented in a header). |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 TUid RSWInstSilentLauncher::ServiceUid() const |
|
85 { |
|
86 return TUid::Uid( KSWInstSilentInstallServiceUid ); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // RSWInstSilentLauncher::ServerName |
|
91 // Constructs the name of the server application. |
|
92 // (other items were commented in a header). |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void RSWInstSilentLauncher::ConstructServerName( TName& aServerName, |
|
96 TUid aAppServerUid, |
|
97 TUint aServerDifferentiator ) |
|
98 { |
|
99 _LIT(KServerNameFormat, "%08x_%08x_AppServer"); |
|
100 aServerName.Format( KServerNameFormat, aServerDifferentiator, aAppServerUid ); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // RSWInstSilentLauncher::StartServerL |
|
105 // Starts the server application. |
|
106 // (other items were commented in a header). |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 TUint RSWInstSilentLauncher::StartServerL( TUid aAppUid ) |
|
110 { |
|
111 // Start the server application |
|
112 TName serverName; |
|
113 TUint differentiator( 0 ); |
|
114 while ( ETrue ) |
|
115 { |
|
116 differentiator = Math::Random(); |
|
117 if ( differentiator==0 ) |
|
118 continue; |
|
119 ConstructServerName( serverName, aAppUid, differentiator ); |
|
120 TFindServer find( serverName ); |
|
121 TFullName fullName; |
|
122 if ( find.Next( fullName ) == KErrNone ) |
|
123 continue; |
|
124 break; |
|
125 } |
|
126 |
|
127 TThreadId serverThreadId; |
|
128 LaunchAppL( aAppUid, differentiator, serverThreadId ); |
|
129 |
|
130 // Poll for the server to be started |
|
131 for ( TInt ii = 0; ii < KMaxServerPoll; ii++ ) |
|
132 { |
|
133 // look for the server name |
|
134 TFindServer find( serverName ); |
|
135 TFullName fullName; |
|
136 if ( find.Next( fullName ) == KErrNone ) |
|
137 { |
|
138 return differentiator; // found the server, so return |
|
139 } |
|
140 User::After( KServertPollTimeout ); // wait before trying again |
|
141 } |
|
142 User::Leave( KErrNotFound ); // failed to find the server, bomb out |
|
143 |
|
144 return differentiator; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // RSWInstSilentLauncher::LaunchAppL |
|
149 // Launches the server application. |
|
150 // (other items were commented in a header). |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void RSWInstSilentLauncher::LaunchAppL( TUid aAppUid, TUint aServerDifferentiator, TThreadId& aThreadId ) |
|
154 { |
|
155 RApaLsSession apa; |
|
156 User::LeaveIfError( apa.Connect() ); |
|
157 CleanupClosePushL( apa ); |
|
158 |
|
159 TApaAppInfo info; |
|
160 User::LeaveIfError( apa.GetAppInfo( info, aAppUid ) ); |
|
161 |
|
162 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
163 cmdLine->SetExecutableNameL( info.iFullName ); |
|
164 cmdLine->SetServerRequiredL( aServerDifferentiator ); |
|
165 // Set the command to start the server in background |
|
166 cmdLine->SetCommandL( EApaCommandBackground ); |
|
167 |
|
168 User::LeaveIfError( apa.StartApp( *cmdLine, aThreadId ) ); |
|
169 |
|
170 CleanupStack::PopAndDestroy( 2, &apa ); // cmdLine and apa |
|
171 } |
|
172 |
|
173 |
|
174 // End of File |