0
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 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 |
* System Includes
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
#include <assert.h>
|
|
23 |
|
|
24 |
|
|
25 |
/*******************************************************************************
|
|
26 |
*
|
|
27 |
* Local Includes
|
|
28 |
*
|
|
29 |
******************************************************************************/
|
|
30 |
#include "CHostExecuteAsyncStub.h"
|
|
31 |
#include "CCHostexecuteasync.h"
|
|
32 |
#include "../../Core/UCCS_ServiceValues.h"
|
|
33 |
#include "../../Core/UCCS_ErrorCodes.h"
|
|
34 |
|
|
35 |
|
|
36 |
/*******************************************************************************
|
|
37 |
*
|
|
38 |
* Constructor / Destructor
|
|
39 |
*
|
|
40 |
******************************************************************************/
|
|
41 |
CHostExecuteAsyncStub::CHostExecuteAsyncStub()
|
|
42 |
{
|
|
43 |
iClientHostExecuteClient = new CCHostexecuteasync();
|
|
44 |
assert( iClientHostExecuteClient != NULL );
|
|
45 |
}
|
|
46 |
|
|
47 |
|
|
48 |
CHostExecuteAsyncStub::~CHostExecuteAsyncStub()
|
|
49 |
{
|
|
50 |
delete iClientHostExecuteClient;
|
|
51 |
}
|
|
52 |
|
|
53 |
|
|
54 |
/*******************************************************************************
|
|
55 |
*
|
|
56 |
* Startup / Shutdown
|
|
57 |
*
|
|
58 |
******************************************************************************/
|
|
59 |
int CHostExecuteAsyncStub::StartUccsService( char *aHostName, int *aErrorCode, int *aUnused )
|
|
60 |
{
|
|
61 |
int client_stub_error;
|
|
62 |
|
|
63 |
// check params
|
|
64 |
assert( aHostName != NULL );
|
|
65 |
assert( aErrorCode != NULL );
|
|
66 |
*aErrorCode = 0;
|
|
67 |
|
|
68 |
// connect to the remote service
|
|
69 |
client_stub_error = iClientHostExecuteClient->Connect( aHostName );
|
|
70 |
|
|
71 |
// return the result
|
|
72 |
return client_stub_error;
|
|
73 |
}
|
|
74 |
|
|
75 |
|
|
76 |
int CHostExecuteAsyncStub::StopUccsService( int *aErrorCode, int *aUnused )
|
|
77 |
{
|
|
78 |
int client_stub_error;
|
|
79 |
|
|
80 |
// check params
|
|
81 |
assert( aErrorCode != NULL );
|
|
82 |
*aErrorCode = 0;
|
|
83 |
|
|
84 |
// shutdown the stub -- force it to close
|
|
85 |
client_stub_error = iClientHostExecuteClient->Disconnect();
|
|
86 |
|
|
87 |
// done
|
|
88 |
return client_stub_error;
|
|
89 |
}
|
|
90 |
|
|
91 |
|
|
92 |
/*******************************************************************************
|
|
93 |
*
|
|
94 |
* IssueCommand
|
|
95 |
*
|
|
96 |
******************************************************************************/
|
|
97 |
CDataRecord* CHostExecuteAsyncStub::IssueCommand( CDataRecord *aRequest )
|
|
98 |
{
|
|
99 |
int i, err, client_stub_error, method_id = -1, length_to_output;
|
|
100 |
char *tmp_string;
|
|
101 |
CDataRecord *request_reply;
|
|
102 |
|
|
103 |
TStartupInfo arg_startup_info;
|
|
104 |
int sarg_integer;
|
|
105 |
|
|
106 |
int rv_integer;
|
|
107 |
THostExecuteAsyncProcessInfo rv_proc_info;
|
|
108 |
TComponentList rv_component_list;
|
|
109 |
TResult rv_result;
|
|
110 |
TVarData rv_vardata;
|
|
111 |
|
|
112 |
// check params
|
|
113 |
assert( aRequest != NULL );
|
|
114 |
|
|
115 |
// create a standard reply
|
|
116 |
request_reply = CreateBaseReply( aRequest );
|
|
117 |
assert( request_reply != NULL );
|
|
118 |
|
|
119 |
// get and check the method_id
|
|
120 |
err = request_reply->GetFieldAsInt( "METHODID", &method_id );
|
|
121 |
if( method_id == -1 ) {
|
|
122 |
UpdateCompletionCode( request_reply, ERR_INVALID_METHOD );
|
|
123 |
return request_reply;
|
|
124 |
}
|
|
125 |
|
|
126 |
// now dispatch and call the appropriate method
|
|
127 |
switch( method_id ) {
|
|
128 |
|
|
129 |
// ss_startuprpcservice
|
|
130 |
case 1:
|
|
131 |
|
|
132 |
// extract the parameters
|
|
133 |
arg_startup_info.iDummy = 0;
|
|
134 |
|
|
135 |
// make the call and update the return value
|
|
136 |
client_stub_error = iClientHostExecuteClient->ss_startuprpcservice( arg_startup_info, &rv_integer );
|
|
137 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
138 |
if( client_stub_error != ERR_NONE ) {
|
|
139 |
break;
|
|
140 |
}
|
|
141 |
|
|
142 |
// set any return information
|
|
143 |
request_reply->NewField( "RESULT", rv_integer );
|
|
144 |
break;
|
|
145 |
|
|
146 |
// sc_shutdownrpcservice
|
|
147 |
case 2:
|
|
148 |
|
|
149 |
// extract the parameters
|
|
150 |
GETINTEGERARGUMENT( "FORCE", &sarg_integer, 1, 1, aRequest, request_reply );
|
|
151 |
|
|
152 |
// make the call and update the return value
|
|
153 |
client_stub_error = iClientHostExecuteClient->sc_shutdownrpcservice( sarg_integer, &rv_integer );
|
|
154 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
155 |
if( client_stub_error != ERR_NONE ) {
|
|
156 |
break;
|
|
157 |
}
|
|
158 |
|
|
159 |
// set the return values
|
|
160 |
request_reply->NewField( "RESULT", rv_integer );
|
|
161 |
break;
|
|
162 |
|
|
163 |
|
|
164 |
// list_devices
|
|
165 |
case 30:
|
|
166 |
|
|
167 |
// make the call and update the return value
|
|
168 |
client_stub_error = iClientHostExecuteClient->list_devices( &rv_component_list );
|
|
169 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
170 |
if( client_stub_error != ERR_NONE ) {
|
|
171 |
break;
|
|
172 |
}
|
|
173 |
|
|
174 |
// set the return values
|
|
175 |
request_reply->NewField( "PROCESSCOUNT", rv_component_list.TComponentList_len );
|
|
176 |
for( i = 0; i < rv_component_list.TComponentList_len; i++ ) {
|
|
177 |
AddIteratedIntegerFieldName( "PID", i, (rv_component_list.TComponentList_val)[i], request_reply );
|
|
178 |
}
|
|
179 |
break;
|
|
180 |
|
|
181 |
|
|
182 |
// cstr_startprocess
|
|
183 |
case 31:
|
|
184 |
|
|
185 |
// extract the parameters
|
|
186 |
GETSTRINGARGUMENT( "CMD", &tmp_string, 1, 0, aRequest, request_reply );
|
|
187 |
|
|
188 |
// make the call and update the return value
|
|
189 |
client_stub_error = iClientHostExecuteClient->cstr_startprocess( tmp_string, &rv_result );
|
|
190 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
191 |
if( client_stub_error != ERR_NONE ) {
|
|
192 |
break;
|
|
193 |
}
|
|
194 |
|
|
195 |
// set the return values
|
|
196 |
request_reply->NewField( "RESULT", rv_result.iStandardResult );
|
|
197 |
request_reply->NewField( "RESULT_DETAIL", rv_result.iExtendedCode );
|
|
198 |
request_reply->NewField( "RESULT_SYSTEM_ERROR", rv_result.iSystemError );
|
|
199 |
break;
|
|
200 |
|
|
201 |
|
|
202 |
// dstr_removeprocess
|
|
203 |
case 32:
|
|
204 |
|
|
205 |
// extract the parameters
|
|
206 |
GETINTEGERARGUMENT( "PID", &sarg_integer, 1, 0, aRequest, request_reply );
|
|
207 |
|
|
208 |
// make the call and update the return value
|
|
209 |
client_stub_error = iClientHostExecuteClient->dstr_removeprocess( sarg_integer, &rv_result );
|
|
210 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
211 |
if( client_stub_error != ERR_NONE ) {
|
|
212 |
break;
|
|
213 |
}
|
|
214 |
|
|
215 |
// set the return values
|
|
216 |
request_reply->NewField( "RESULT", rv_result.iStandardResult );
|
|
217 |
request_reply->NewField( "RESULT_DETAIL", rv_result.iExtendedCode );
|
|
218 |
request_reply->NewField( "RESULT_SYSTEM_ERROR", rv_result.iSystemError );
|
|
219 |
break;
|
|
220 |
|
|
221 |
|
|
222 |
// killprocess
|
|
223 |
case 5:
|
|
224 |
|
|
225 |
// extract the parameters
|
|
226 |
GETINTEGERARGUMENT( "PID", &sarg_integer, 1, 0, aRequest, request_reply );
|
|
227 |
|
|
228 |
// make the call and update the return value
|
|
229 |
client_stub_error = iClientHostExecuteClient->killprocess( sarg_integer, &rv_result );
|
|
230 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
231 |
if( client_stub_error != ERR_NONE ) {
|
|
232 |
break;
|
|
233 |
}
|
|
234 |
|
|
235 |
// set the return values
|
|
236 |
request_reply->NewField( "RESULT", rv_result.iStandardResult );
|
|
237 |
request_reply->NewField( "RESULT_DETAIL", rv_result.iExtendedCode );
|
|
238 |
request_reply->NewField( "RESULT_SYSTEM_ERROR", rv_result.iSystemError );
|
|
239 |
break;
|
|
240 |
|
|
241 |
|
|
242 |
// stopprocess
|
|
243 |
case 6:
|
|
244 |
|
|
245 |
// extract the parameters
|
|
246 |
GETINTEGERARGUMENT( "PID", &sarg_integer, 1, 0, aRequest, request_reply );
|
|
247 |
|
|
248 |
// make the call and update the return value
|
|
249 |
client_stub_error = iClientHostExecuteClient->stopprocess( sarg_integer, &rv_result );
|
|
250 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
251 |
if( client_stub_error != ERR_NONE ) {
|
|
252 |
break;
|
|
253 |
}
|
|
254 |
|
|
255 |
// set the return values
|
|
256 |
request_reply->NewField( "RESULT", rv_result.iStandardResult );
|
|
257 |
request_reply->NewField( "RESULT_DETAIL", rv_result.iExtendedCode );
|
|
258 |
request_reply->NewField( "RESULT_SYSTEM_ERROR", rv_result.iSystemError );
|
|
259 |
break;
|
|
260 |
|
|
261 |
|
|
262 |
// getprocessinfo
|
|
263 |
case 7:
|
|
264 |
|
|
265 |
// extract the parameters
|
|
266 |
GETINTEGERARGUMENT( "PID", &sarg_integer, 1, 0, aRequest, request_reply );
|
|
267 |
|
|
268 |
// make the call and update the return value
|
|
269 |
client_stub_error = iClientHostExecuteClient->getprocessinfo( sarg_integer, &rv_proc_info );
|
|
270 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
271 |
if( client_stub_error != ERR_NONE ) {
|
|
272 |
break;
|
|
273 |
}
|
|
274 |
|
|
275 |
// set the return values
|
|
276 |
request_reply->NewField( "RESULT", rv_proc_info.iErrorCode );
|
|
277 |
request_reply->NewField( "RESULT_DETAIL", rv_proc_info.iErrorDetail );
|
|
278 |
request_reply->NewField( "PROCESS_COMMAND", rv_proc_info.iCommandLine );
|
|
279 |
request_reply->NewField( "PROCESS_STATUS", rv_proc_info.iProcessStatus );
|
|
280 |
request_reply->NewField( "PROCESS_EXIT_REASON", rv_proc_info.iProcessExitReason );
|
|
281 |
request_reply->NewField( "PROCESS_EXIT_CODE", rv_proc_info.iExitCode );
|
|
282 |
break;
|
|
283 |
|
|
284 |
|
|
285 |
// getstandardoutput
|
|
286 |
case 8:
|
|
287 |
|
|
288 |
// extract the parameters
|
|
289 |
GETINTEGERARGUMENT( "PID", &sarg_integer, 1, 0, aRequest, request_reply );
|
|
290 |
|
|
291 |
// make the call and update the return value
|
|
292 |
client_stub_error = iClientHostExecuteClient->getstandardoutput( sarg_integer, &rv_vardata );
|
|
293 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
294 |
if( client_stub_error != ERR_NONE ) {
|
|
295 |
break;
|
|
296 |
}
|
|
297 |
|
|
298 |
// set the return values
|
|
299 |
length_to_output = ((rv_vardata.TVarData_len > 0) ? (rv_vardata.TVarData_len - 1) : rv_vardata.TVarData_len);
|
|
300 |
request_reply->NewField( "STDOUT", (char*)(rv_vardata.TVarData_val) );
|
|
301 |
request_reply->NewField( "LENGTH", length_to_output );
|
|
302 |
|
|
303 |
// free the memory (if any was allocated)
|
|
304 |
if( rv_vardata.TVarData_len > 0 ) {
|
|
305 |
XdrFree( (char**)&(rv_vardata.TVarData_val), (int*)&(rv_vardata.TVarData_len) );
|
|
306 |
}
|
|
307 |
break;
|
|
308 |
|
|
309 |
|
|
310 |
// getstandarderror
|
|
311 |
case 9:
|
|
312 |
|
|
313 |
// extract the parameters
|
|
314 |
GETINTEGERARGUMENT( "PID", &sarg_integer, 1, 0, aRequest, request_reply );
|
|
315 |
|
|
316 |
// make the call and update the return value
|
|
317 |
client_stub_error = iClientHostExecuteClient->getstandarderror( sarg_integer, &rv_vardata );
|
|
318 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
319 |
if( client_stub_error != ERR_NONE ) {
|
|
320 |
break;
|
|
321 |
}
|
|
322 |
|
|
323 |
// set the return values
|
|
324 |
length_to_output = ((rv_vardata.TVarData_len > 0) ? (rv_vardata.TVarData_len - 1) : rv_vardata.TVarData_len);
|
|
325 |
request_reply->NewField( "STDERR", (char*)(rv_vardata.TVarData_val) );
|
|
326 |
request_reply->NewField( "LENGTH", length_to_output );
|
|
327 |
|
|
328 |
// free the memory (if any was allocated)
|
|
329 |
if( rv_vardata.TVarData_len > 0 ) {
|
|
330 |
XdrFree( (char**)&(rv_vardata.TVarData_val), (int*)&(rv_vardata.TVarData_len) );
|
|
331 |
}
|
|
332 |
break;
|
|
333 |
|
|
334 |
// Any other method id results in an invalid method id result
|
|
335 |
default:
|
|
336 |
UpdateCompletionCode( request_reply, ERR_INVALID_METHOD );
|
|
337 |
break;
|
|
338 |
}
|
|
339 |
|
|
340 |
// everything should be handled above
|
|
341 |
return request_reply;
|
|
342 |
}
|
|
343 |
|
|
344 |
|
|
345 |
/*******************************************************************************
|
|
346 |
*
|
|
347 |
* GetStatus()
|
|
348 |
*
|
|
349 |
******************************************************************************/
|
|
350 |
int CHostExecuteAsyncStub::GetStatus()
|
|
351 |
{
|
|
352 |
assert( !"GetStatus() - is not implemented" );
|
|
353 |
return -1;
|
|
354 |
}
|
|
355 |
|
|
356 |
|
|
357 |
/*******************************************************************************
|
|
358 |
*
|
|
359 |
* GetLastRPCError()
|
|
360 |
*
|
|
361 |
******************************************************************************/
|
|
362 |
char *CHostExecuteAsyncStub::GetLastRPCError( int *aIntError )
|
|
363 |
{
|
|
364 |
return iClientHostExecuteClient->GetLastRPCError( aIntError );
|
|
365 |
}
|
|
366 |
|