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