|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32svr.h> |
|
20 #include "HWRMClient.h" |
|
21 #include "HWRMConfiguration.h" |
|
22 #include "HWRMClientServer.h" |
|
23 #include "HWRMtrace.h" |
|
24 |
|
25 // EXTERNAL DATA STRUCTURES |
|
26 |
|
27 // EXTERNAL FUNCTION PROTOTYPES |
|
28 |
|
29 // CONSTANTS |
|
30 _LIT(KSysBin, "\\sys\\bin\\"); |
|
31 |
|
32 // MACROS |
|
33 |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 |
|
36 // MODULE DATA STRUCTURES |
|
37 |
|
38 // LOCAL FUNCTION PROTOTYPES |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 // ============================= LOCAL FUNCTIONS =============================== |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 /* |
|
47 // ----------------------------------------------------------------------------- |
|
48 // RHWRMClient::RHWRMClient |
|
49 // C++ default constructor can NOT contain any code, that |
|
50 // might leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 RHWRMClient::RHWRMClient() |
|
54 : RSessionBase() |
|
55 { |
|
56 } |
|
57 */ |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // RHWRMClient::Connect |
|
61 // Connects to server |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C TInt RHWRMClient::Connect(THWRMResourceType aType) |
|
65 { |
|
66 COMPONENT_TRACE2(_L( "HWRM Client - RHWRMClient::Connect(0x%x)" ), aType); |
|
67 |
|
68 // Try this twice |
|
69 TInt retry(3); |
|
70 TInt err(KErrNone); |
|
71 |
|
72 while (retry > 0) |
|
73 { |
|
74 // Try to create a HWRM Server session |
|
75 COMPONENT_TRACE2(_L( "HWRM Client - RHWRMClient::Connect - CreateSession retry : %d" ), retry ); |
|
76 err = CreateSession( KServerProcessName, |
|
77 ServerVersion(), |
|
78 KDefaultAsyncSlots ); |
|
79 |
|
80 COMPONENT_TRACE2(_L( "HWRM Client - RHWRMClient::Connect - CreateSession returned: %d" ), err ); |
|
81 |
|
82 if ( err != KErrNotFound && err != KErrServerTerminated ) |
|
83 { |
|
84 // KErrNone or unrecoverable error |
|
85 break; |
|
86 } |
|
87 else |
|
88 { |
|
89 // Return code was KErrNotFound or KErrServerTerminated. |
|
90 // Try to start a new HWRM Server |
|
91 err = StartServer(); |
|
92 |
|
93 COMPONENT_TRACE2(_L( "HWRM Client - RHWRMClient::Connect - StartServer returned: %d" ), err ); |
|
94 |
|
95 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
96 { |
|
97 // Unrecoverable error |
|
98 break; |
|
99 } |
|
100 } |
|
101 |
|
102 retry--; |
|
103 } |
|
104 |
|
105 // Create proper service on server side |
|
106 if ( err == KErrNone ) |
|
107 { |
|
108 switch ( aType ) |
|
109 { |
|
110 case HWRMResourceTypeVibra: |
|
111 err = SendReceive(EHWRMCreateVibraService, TIpcArgs()); |
|
112 break; |
|
113 case HWRMResourceTypeLight: |
|
114 err = SendReceive(EHWRMCreateLightService, TIpcArgs()); |
|
115 break; |
|
116 case HWRMResourceTypePower: |
|
117 err = SendReceive(EHWRMCreatePowerService, TIpcArgs()); |
|
118 break; |
|
119 case HWRMResourceTypeFmTx: |
|
120 err = SendReceive(EHWRMCreateFmTxService, TIpcArgs()); |
|
121 break; |
|
122 default: |
|
123 err = KErrNotSupported; |
|
124 } |
|
125 } |
|
126 |
|
127 COMPONENT_TRACE2( _L( "HWRM Client - RHWRMClient::Connect - return %d" ), err ); |
|
128 return err; |
|
129 } |
|
130 |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // RHWRMClient::ExecuteOperation |
|
134 // Calls SendReceive with given parameters. |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C TInt RHWRMClient::ExecuteOperation(TInt aCommand, const TIpcArgs& aArgs) const |
|
138 { |
|
139 COMPONENT_TRACE2(_L( "HWRM Client - RHWRMClient::ExecuteOperation(0x%x, <aArgs>)" ), aCommand ); |
|
140 |
|
141 TInt retval = SendReceive(aCommand, aArgs); |
|
142 |
|
143 COMPONENT_TRACE2(_L( "HWRM Client - RHWRMClient::ExecuteOperation - return %d" ), retval ); |
|
144 |
|
145 return retval; |
|
146 |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // RHWRMClient::ExecuteAsyncOperation |
|
151 // Calls SendReceive with given parameters. |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 EXPORT_C void RHWRMClient::ExecuteAsyncOperation(TInt aCommand, const TIpcArgs& aArgs, TRequestStatus& aStatus ) const |
|
155 { |
|
156 COMPONENT_TRACE3( _L( "HWRM Client - RHWRMClient::ExecuteAsyncOperation(0x%x, <aArgs>, 0x%x)" ), aCommand, aStatus.Int() ); |
|
157 |
|
158 SendReceive(aCommand, aArgs, aStatus); |
|
159 |
|
160 COMPONENT_TRACE1( _L( "HWRM Client - RHWRMClient::ExecuteAsyncOperation - return" ) ); |
|
161 } |
|
162 // ----------------------------------------------------------------------------- |
|
163 // RHWRMClient::StartServer |
|
164 // Starts server. |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 TInt RHWRMClient::StartServer() const |
|
168 { |
|
169 COMPONENT_TRACE1(_L( "HWRM Client - RHWRMClient::StartServer()" ) ); |
|
170 |
|
171 RProcess server; |
|
172 const TUidType serverUid( KNullUid, KServerUid2, KNullUid ); |
|
173 TInt err = server.Create( ServerLocation(), // HWRMServer.exe |
|
174 KNullDesC, // A descriptor containing data passed as |
|
175 // an argument to the thread function of |
|
176 // the new process's main thread, when it |
|
177 // is first scheduled. |
|
178 serverUid, // HWRM server UID |
|
179 EOwnerProcess ); // Ownership of this process handle |
|
180 |
|
181 // Return error code if we couldn't create a process |
|
182 if ( err == KErrNone ) |
|
183 { |
|
184 // Rendezvous is used to detect server start |
|
185 TRequestStatus stat; |
|
186 server.Rendezvous( stat ); |
|
187 |
|
188 if ( stat != KRequestPending ) |
|
189 { |
|
190 server.Kill( stat.Int() ); // Abort startup |
|
191 } |
|
192 else |
|
193 { |
|
194 server.Resume(); // Logon OK - start the server |
|
195 } |
|
196 |
|
197 COMPONENT_TRACE1(_L( "HWRM Client - RHWRMClient::StartServer - Waiting server startup" ) ); |
|
198 |
|
199 User::WaitForRequest( stat ); // Wait for start or death |
|
200 |
|
201 COMPONENT_TRACE1(_L( "HWRM Client - RHWRMClient::StartServer - Server startup wait finished" ) ); |
|
202 |
|
203 // We can't use the 'exit reason' if the server paniced as this |
|
204 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
205 // from KErrNone |
|
206 err = (server.ExitType() == EExitPanic)? KErrGeneral : stat.Int(); |
|
207 |
|
208 // We can close the handle now |
|
209 server.Close(); |
|
210 } |
|
211 |
|
212 COMPONENT_TRACE2(_L( "HWRM Client - RHWRMClient::StartServer - return %d" ), err ); |
|
213 |
|
214 return err; |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // RHWRMClient::ServerLocation |
|
219 // Returns server location |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 TFullName RHWRMClient::ServerLocation() const |
|
223 { |
|
224 TFullName fullPathAndName( KServerExeDrive ); |
|
225 fullPathAndName.Append( KSysBin ); |
|
226 fullPathAndName.Append( KServerExeName ); |
|
227 |
|
228 COMPONENT_TRACE2(_L( "HWRM Client - RHWRMClient::ServerLocation - return %S" ), &fullPathAndName ); |
|
229 |
|
230 return fullPathAndName; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // RHWRMClient::ServerVersion |
|
235 // Return version of server |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 TVersion RHWRMClient::ServerVersion() const |
|
239 { |
|
240 return TVersion( KServerVersionMajor, KServerVersionMinor, KServerVersionBuild ); |
|
241 } |
|
242 |
|
243 |
|
244 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
245 |
|
246 |
|
247 // End of File |