|
1 /* |
|
2 * Copyright (c) 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: Power save mode client class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32svr.h> |
|
20 #include <data_caging_path_literals.hrh> |
|
21 #include "psmsession.h" |
|
22 #include "psmdefines.h" |
|
23 #include "psmtrace.h" |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // RPsmServer::Connect |
|
27 // Connects to PSM server |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 TInt RPsmServer::Connect() |
|
31 { |
|
32 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::Connect()" ) ) ); |
|
33 |
|
34 // Try this twice |
|
35 TInt retry( KPsmClientTryCount ); |
|
36 TInt err( KErrNone ); |
|
37 |
|
38 while (retry > 0) |
|
39 { |
|
40 // Try to create a PSM Server session |
|
41 err = CreateSession( KPsmProcessName, |
|
42 ServerVersion(), |
|
43 KPsmServerDefaultAsyncSlots ); |
|
44 |
|
45 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::Connect - CreateSession returned: %d" ), err ) ); |
|
46 |
|
47 if ( err != KErrNotFound && err != KErrServerTerminated ) |
|
48 { |
|
49 // KErrNone or unrecoverable error |
|
50 if (err != KErrNone) |
|
51 { |
|
52 ERROR_TRACE( ( _L( "PSM Client - RPsmServer::Connect - ERROR: CreateSession unrecoverable error: %d" ), err ) ); |
|
53 } |
|
54 |
|
55 retry = 0; |
|
56 } |
|
57 else |
|
58 { |
|
59 // Return code was KErrNotFound or KErrServerTerminated. |
|
60 // Try to start a new PSM Server |
|
61 err = StartServer(); |
|
62 |
|
63 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::Connect - StartServer returned: %d" ), err ) ); |
|
64 |
|
65 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
66 { |
|
67 // Unrecoverable error |
|
68 ERROR_TRACE( ( _L( "PSM Client - RPsmServer::Connect - ERROR: StartServer unrecoverable error: %d" ), err ) ); |
|
69 retry = 0; |
|
70 } |
|
71 } |
|
72 |
|
73 retry--; |
|
74 } |
|
75 |
|
76 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::Connect - return %d" ), err ) ); |
|
77 return err; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // RPsmServer::SendReceiveSync |
|
82 // Send message to server |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 TInt RPsmServer::SendReceiveSync( |
|
86 TPsmServerRequest aRequest, const TIpcArgs& aArgs ) const |
|
87 { |
|
88 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::SendReceiveSync()" ) ) ); |
|
89 return SendReceive( aRequest, aArgs ); |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // RPsmServer::SendReceiveSync |
|
94 // Send asynchronous message to server |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void RPsmServer::SendReceiveAsync( |
|
98 TPsmServerRequest aRequest, const TIpcArgs& aArgs, TRequestStatus& aStatus ) const |
|
99 { |
|
100 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::SendReceiveAsync()" ) ) ); |
|
101 SendReceive( aRequest, aArgs, aStatus ); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // RPsmServer::StartServer |
|
106 // Starts server. |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 TInt RPsmServer::StartServer() const |
|
110 { |
|
111 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::StartServer()" ) ) ); |
|
112 |
|
113 RProcess server; |
|
114 const TUidType serverUid( KNullUid, KPsmServerUid2, KNullUid ); |
|
115 TInt err = server.Create( ServerLocation(), // psmserver.exe |
|
116 KNullDesC, // A descriptor containing data passed as |
|
117 // an argument to the thread function of |
|
118 // the new process's main thread, when it |
|
119 // is first scheduled. |
|
120 serverUid, // PSM server UID |
|
121 EOwnerProcess ); // Ownership of this process handle |
|
122 |
|
123 // Return error code if we couldn't create a process |
|
124 if ( err == KErrNone ) |
|
125 { |
|
126 // Rendezvous is used to detect server start |
|
127 TRequestStatus stat; |
|
128 server.Rendezvous( stat ); |
|
129 |
|
130 if ( stat != KRequestPending ) |
|
131 { |
|
132 ERROR_TRACE( ( _L( "PSM Client - RPsmServer::StartServer - ERROR: Rendezvous failure: %d" ), stat.Int() ) ); |
|
133 server.Kill( 0 ); // Abort startup |
|
134 } |
|
135 else |
|
136 { |
|
137 server.Resume(); // Logon OK - start the server |
|
138 } |
|
139 |
|
140 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::StartServer - Waiting server startup" ) ) ); |
|
141 |
|
142 User::WaitForRequest( stat ); // Wait for start or death |
|
143 |
|
144 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::StartServer - Server startup wait finished" ) ) ); |
|
145 |
|
146 // We can't use the 'exit reason' if the server paniced as this |
|
147 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
148 // from KErrNone |
|
149 if ( server.ExitType() == EExitPanic ) |
|
150 { |
|
151 ERROR_TRACE( ( _L( "PSM Client - RPsmServer::StartServer - ERROR: Server paniced at startup" ) ) ); |
|
152 err = KErrGeneral; |
|
153 } |
|
154 else |
|
155 { |
|
156 err = stat.Int(); |
|
157 } |
|
158 |
|
159 // We can close the handle now |
|
160 server.Close(); |
|
161 } |
|
162 |
|
163 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::StartServer - return %d" ), err ) ); |
|
164 |
|
165 return err; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // RPsmServer::ServerLocation |
|
170 // Returns server location |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 TFullName RPsmServer::ServerLocation() const |
|
174 { |
|
175 TFullName fullPathAndName( KPsmExeDrive ); |
|
176 |
|
177 fullPathAndName.Append( KDC_PROGRAMS_DIR ); |
|
178 |
|
179 fullPathAndName.Append( KPsmExeName ); |
|
180 |
|
181 COMPONENT_TRACE( ( _L( "PSM Client - RPsmServer::ServerLocation - return %S" ), &fullPathAndName ) ); |
|
182 |
|
183 return fullPathAndName; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // RPsmServer::ServerVersion |
|
188 // Return version of server |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 TVersion RPsmServer::ServerVersion() const |
|
192 { |
|
193 return TVersion( KPsmVersionMajor, KPsmVersionMinor, KPsmVersionBuild ); |
|
194 } |
|
195 |
|
196 |
|
197 // End of file |