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 <stdio.h>
|
|
23 |
#include <assert.h>
|
|
24 |
#include <rpc/types.h>
|
|
25 |
|
|
26 |
|
|
27 |
/****************************************************************************************
|
|
28 |
*
|
|
29 |
* Local Includes
|
|
30 |
*
|
|
31 |
***************************************************************************************/
|
|
32 |
#include "CCHostexecute.h"
|
|
33 |
|
|
34 |
|
|
35 |
/****************************************************************************************
|
|
36 |
*
|
|
37 |
* Implementation
|
|
38 |
*
|
|
39 |
***************************************************************************************/
|
|
40 |
CCHostexecute::CCHostexecute()
|
|
41 |
{
|
|
42 |
cl = NULL;
|
|
43 |
iLastRPCError.re_status = RPC_SUCCESS;
|
|
44 |
}
|
|
45 |
|
|
46 |
CCHostexecute::~CCHostexecute()
|
|
47 |
{
|
|
48 |
assert( cl == NULL );
|
|
49 |
}
|
|
50 |
|
|
51 |
char *CCHostexecute::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 CCHostexecute::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(), HOSTEXECUTE, HOSTEXECUTE_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 CCHostexecute::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 CCHostexecute::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_3( &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 CCHostexecute::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_3( &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 CCHostexecute::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_3( &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_executecommand
|
|
208 |
*
|
|
209 |
***************************************************************************************/
|
|
210 |
int CCHostexecute::st_executecommand( TExecuteRequest aArgs, TExecuteResult *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_executecommand_3( &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 |
}
|