|
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 <stdio.h> |
|
23 #include <assert.h> |
|
24 #include <rpc/types.h> |
|
25 |
|
26 |
|
27 /**************************************************************************************** |
|
28 * |
|
29 * Local Includes |
|
30 * |
|
31 ***************************************************************************************/ |
|
32 #include "CCGenericstub.h" |
|
33 |
|
34 |
|
35 /**************************************************************************************** |
|
36 * |
|
37 * Implementation |
|
38 * |
|
39 ***************************************************************************************/ |
|
40 CCGenericstub::CCGenericstub( const int anIID, const int aVersion ) |
|
41 : iIID(anIID), iVersion(aVersion) |
|
42 { |
|
43 cl = NULL; |
|
44 iLastRPCError.re_status = RPC_SUCCESS; |
|
45 } |
|
46 |
|
47 CCGenericstub::~CCGenericstub() |
|
48 { |
|
49 assert( cl == NULL ); |
|
50 } |
|
51 |
|
52 char *CCGenericstub::GetLastRPCError( int *aIntErr ) |
|
53 { |
|
54 struct rpc_err rpcerr; |
|
55 |
|
56 // check that the handle is valid |
|
57 if( cl == NULL ) { |
|
58 return NULL; |
|
59 } |
|
60 |
|
61 // pass the aIntErr |
|
62 if( aIntErr != NULL ) { |
|
63 clnt_geterr( cl, &rpcerr ); |
|
64 *aIntErr = rpcerr.re_status; |
|
65 } |
|
66 |
|
67 // return the errorstring |
|
68 return clnt_sperror( cl, NULL ); |
|
69 } |
|
70 |
|
71 int CCGenericstub::Connect( string aRemoteHost ) |
|
72 { |
|
73 int res = ERR_NONE; |
|
74 // check that we are not already connected |
|
75 if( cl != NULL ) |
|
76 { |
|
77 res = ERR_STUB_ALREADY_CONNECTED; |
|
78 } |
|
79 |
|
80 if( res == ERR_NONE ) |
|
81 { |
|
82 // start the rpc library |
|
83 res = rpc_nt_init(); |
|
84 if( res == ERR_NONE ) |
|
85 { |
|
86 // connect to the service |
|
87 cl = clnt_create( aRemoteHost.c_str(), iIID, iVersion, "tcp" ); |
|
88 if( cl == NULL ) |
|
89 { |
|
90 rpc_nt_exit(); |
|
91 res = ERR_FAILED_TO_CONNECT; |
|
92 } |
|
93 } |
|
94 else |
|
95 { |
|
96 res = ERR_RPC_ERROR; |
|
97 } |
|
98 } |
|
99 |
|
100 // done |
|
101 return res; |
|
102 } |
|
103 |
|
104 int CCGenericstub::Disconnect( ) |
|
105 { |
|
106 // check that we are connected |
|
107 if( cl == NULL ) { |
|
108 return ERR_STUB_NOT_CONNECTED; |
|
109 } |
|
110 |
|
111 // cleanup the client handle |
|
112 clnt_destroy( cl ); |
|
113 cl = NULL; |
|
114 rpc_nt_exit(); |
|
115 |
|
116 // done |
|
117 return ERR_NONE; |
|
118 } |
|
119 |
|
120 |
|
121 /**************************************************************************************** |
|
122 * |
|
123 * PUBLIC FUNCTION: ss_startuprpcservice |
|
124 * |
|
125 ***************************************************************************************/ |
|
126 int CCGenericstub::ss_startuprpcservice( TStartupInfo aArgs, int *rv ) |
|
127 { |
|
128 struct rpc_err rerr; |
|
129 |
|
130 // check the rv pointer |
|
131 if( rv == NULL ) { |
|
132 return ERR_INVALID_RV_POINTER; |
|
133 } |
|
134 |
|
135 // check that we have a connection |
|
136 if( cl == NULL ) { |
|
137 return ERR_STUB_NOT_CONNECTED; |
|
138 } |
|
139 |
|
140 // do the call |
|
141 *rv = *ss_startuprpcservice_11( &aArgs, cl ); |
|
142 |
|
143 // check for rpc errors and return the result |
|
144 clnt_geterr( cl, &rerr ); |
|
145 if( rerr.re_status != RPC_SUCCESS ) { |
|
146 iLastRPCError = rerr; |
|
147 return ERR_RPC_ERROR; |
|
148 } |
|
149 return ERR_NONE; |
|
150 } |
|
151 |
|
152 |
|
153 /**************************************************************************************** |
|
154 * |
|
155 * PUBLIC FUNCTION: sc_shutdownrpcservice |
|
156 * |
|
157 ***************************************************************************************/ |
|
158 int CCGenericstub::sc_shutdownrpcservice( int aArgs, int *rv ) |
|
159 { |
|
160 struct rpc_err rerr; |
|
161 |
|
162 // check the rv pointer |
|
163 if( rv == NULL ) { |
|
164 return ERR_INVALID_RV_POINTER; |
|
165 } |
|
166 |
|
167 // check that we have a connection |
|
168 if( cl == NULL ) { |
|
169 return ERR_STUB_NOT_CONNECTED; |
|
170 } |
|
171 |
|
172 // do the call |
|
173 *rv = *sc_shutdownrpcservice_11( &aArgs, cl ); |
|
174 |
|
175 // check for rpc errors and return the result |
|
176 clnt_geterr( cl, &rerr ); |
|
177 if( rerr.re_status != RPC_SUCCESS ) { |
|
178 iLastRPCError = rerr; |
|
179 return ERR_RPC_ERROR; |
|
180 } |
|
181 return ERR_NONE; |
|
182 } |
|
183 |
|
184 |
|
185 /**************************************************************************************** |
|
186 * |
|
187 * PUBLIC FUNCTION: list_connections |
|
188 * |
|
189 ***************************************************************************************/ |
|
190 int CCGenericstub::list_connections( TComponentList *rv ) |
|
191 { |
|
192 struct rpc_err rerr; |
|
193 int aArgs = 0; |
|
194 |
|
195 // check the rv pointer |
|
196 if( rv == NULL ) { |
|
197 return ERR_INVALID_RV_POINTER; |
|
198 } |
|
199 |
|
200 // check that we have a connection |
|
201 if( cl == NULL ) { |
|
202 return ERR_STUB_NOT_CONNECTED; |
|
203 } |
|
204 |
|
205 // do the call |
|
206 *rv = *list_connections_11( &aArgs, cl ); |
|
207 |
|
208 // check for rpc errors and return the result |
|
209 clnt_geterr( cl, &rerr ); |
|
210 if( rerr.re_status != RPC_SUCCESS ) { |
|
211 iLastRPCError = rerr; |
|
212 return ERR_RPC_ERROR; |
|
213 } |
|
214 return ERR_NONE; |
|
215 } |
|
216 |
|
217 |
|
218 /**************************************************************************************** |
|
219 * |
|
220 * PUBLIC FUNCTION: cstr_startprocess |
|
221 * |
|
222 ***************************************************************************************/ |
|
223 int CCGenericstub::cstr_startprocess( char *aArgs, int *rv ) |
|
224 { |
|
225 struct rpc_err rerr; |
|
226 |
|
227 // check the rv pointer |
|
228 if( rv == NULL ) { |
|
229 return ERR_INVALID_RV_POINTER; |
|
230 } |
|
231 |
|
232 // check that we have a connection |
|
233 if( cl == NULL ) { |
|
234 return ERR_STUB_NOT_CONNECTED; |
|
235 } |
|
236 |
|
237 // do the call |
|
238 *rv = *cstr_startprocess_11( &aArgs, cl ); |
|
239 |
|
240 // check for rpc errors and return the result |
|
241 clnt_geterr( cl, &rerr ); |
|
242 if( rerr.re_status != RPC_SUCCESS ) { |
|
243 iLastRPCError = rerr; |
|
244 return ERR_RPC_ERROR; |
|
245 } |
|
246 return ERR_NONE; |
|
247 } |
|
248 |
|
249 |
|
250 /**************************************************************************************** |
|
251 * |
|
252 * PUBLIC FUNCTION: dstr_removeprocess |
|
253 * |
|
254 ***************************************************************************************/ |
|
255 int CCGenericstub::dstr_removeprocess( int aArgs, int *rv ) |
|
256 { |
|
257 struct rpc_err rerr; |
|
258 |
|
259 // check the rv pointer |
|
260 if( rv == NULL ) { |
|
261 return ERR_INVALID_RV_POINTER; |
|
262 } |
|
263 |
|
264 // check that we have a connection |
|
265 if( cl == NULL ) { |
|
266 return ERR_STUB_NOT_CONNECTED; |
|
267 } |
|
268 |
|
269 // do the call |
|
270 *rv = *dstr_removeprocess_11( &aArgs, cl ); |
|
271 |
|
272 // check for rpc errors and return the result |
|
273 clnt_geterr( cl, &rerr ); |
|
274 if( rerr.re_status != RPC_SUCCESS ) { |
|
275 iLastRPCError = rerr; |
|
276 return ERR_RPC_ERROR; |
|
277 } |
|
278 return ERR_NONE; |
|
279 } |
|
280 |
|
281 |
|
282 /**************************************************************************************** |
|
283 * |
|
284 * PUBLIC FUNCTION: run_command |
|
285 * |
|
286 ***************************************************************************************/ |
|
287 int CCGenericstub::run_command( TCall aArgs, int *rv ) |
|
288 { |
|
289 struct rpc_err rerr; |
|
290 |
|
291 // check the rv pointer |
|
292 if( rv == NULL ) { |
|
293 return ERR_INVALID_RV_POINTER; |
|
294 } |
|
295 |
|
296 // check that we have a connection |
|
297 if( cl == NULL ) { |
|
298 return ERR_STUB_NOT_CONNECTED; |
|
299 } |
|
300 |
|
301 // do the call |
|
302 *rv = *run_command_11( &aArgs, cl ); |
|
303 |
|
304 // check for rpc errors and return the result |
|
305 clnt_geterr( cl, &rerr ); |
|
306 if( rerr.re_status != RPC_SUCCESS ) { |
|
307 iLastRPCError = rerr; |
|
308 return ERR_RPC_ERROR; |
|
309 } |
|
310 return ERR_NONE; |
|
311 } |