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 |
* CGenericStub.cpp
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
#include <assert.h>
|
|
23 |
|
|
24 |
#include "CGenericStub.h"
|
|
25 |
#include "CCGenericStub.h"
|
|
26 |
#include "GenericStub.h"
|
|
27 |
|
|
28 |
#define CALL_ID "CallID"
|
|
29 |
|
|
30 |
CGenericStub::CGenericStub( char* aIniFile, char* aServiceName )
|
|
31 |
: iIniFile(NULL)
|
|
32 |
{
|
|
33 |
// Open the interface ini file
|
|
34 |
iIniFile = new CUCCIniFile( aIniFile );
|
|
35 |
assert( iIniFile != NULL );
|
|
36 |
|
|
37 |
// Retrieve the IID and version
|
|
38 |
int IID;
|
|
39 |
bool ret = iIniFile->KeyValue("ServiceIID", aServiceName, IID);
|
|
40 |
assert( ret == true );
|
|
41 |
assert( IID != 0 );
|
|
42 |
int version;
|
|
43 |
ret = iIniFile->KeyValue("Version", aServiceName, version);
|
|
44 |
assert( ret == true );
|
|
45 |
assert( version != 0 );
|
|
46 |
iGenericStub = new CCGenericstub( IID, version );
|
|
47 |
}
|
|
48 |
|
|
49 |
CGenericStub::~CGenericStub()
|
|
50 |
{
|
|
51 |
delete iGenericStub;
|
|
52 |
delete iIniFile;
|
|
53 |
}
|
|
54 |
|
|
55 |
int CGenericStub::StartUccsService( char *aHostName, int *aErrorCode, int *aUnused )
|
|
56 |
{
|
|
57 |
int client_stub_error;
|
|
58 |
|
|
59 |
*aErrorCode = 0;
|
|
60 |
|
|
61 |
// connect to the remote service
|
|
62 |
client_stub_error = iGenericStub->Connect( aHostName );
|
|
63 |
|
|
64 |
// return the result
|
|
65 |
return client_stub_error;
|
|
66 |
}
|
|
67 |
|
|
68 |
int CGenericStub::StopUccsService( int *aErrorCode, int *aUnused )
|
|
69 |
{
|
|
70 |
int client_stub_error;
|
|
71 |
*aErrorCode = 0;
|
|
72 |
|
|
73 |
// shutdown the stub -- force it to close
|
|
74 |
client_stub_error = iGenericStub->Disconnect();
|
|
75 |
|
|
76 |
// done
|
|
77 |
return client_stub_error;
|
|
78 |
}
|
|
79 |
|
|
80 |
CDataRecord* CGenericStub::IssueCommand( CDataRecord* aRequest )
|
|
81 |
{
|
|
82 |
int call_result, err, client_stub_error, method_id = -1;
|
|
83 |
|
|
84 |
CDataRecord *request_reply;
|
|
85 |
|
|
86 |
int rv_integer, sarg_integer;
|
|
87 |
|
|
88 |
// create a standard reply
|
|
89 |
request_reply = CreateBaseReply( aRequest );
|
|
90 |
|
|
91 |
// get and check the method_id
|
|
92 |
err = request_reply->GetFieldAsInt( "METHODID", &method_id );
|
|
93 |
if( method_id == -1 )
|
|
94 |
{
|
|
95 |
UpdateCompletionCode( request_reply, ERR_INVALID_METHOD );
|
|
96 |
return request_reply;
|
|
97 |
}
|
|
98 |
|
|
99 |
// now dispatch and call the appropriate method
|
|
100 |
switch( method_id )
|
|
101 |
{
|
|
102 |
// ss_startuprpcservice
|
|
103 |
case 1:
|
|
104 |
{
|
|
105 |
// extract the parameters
|
|
106 |
TStartupInfo sarg_startup_info;
|
|
107 |
sarg_startup_info.iEmpty = 0;
|
|
108 |
|
|
109 |
// make the call and update the return value
|
|
110 |
client_stub_error = iGenericStub->ss_startuprpcservice( sarg_startup_info, &rv_integer );
|
|
111 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
112 |
if( client_stub_error != ERR_NONE )
|
|
113 |
{
|
|
114 |
break;
|
|
115 |
}
|
|
116 |
// set any return information
|
|
117 |
request_reply->NewField( "RESULT", rv_integer );
|
|
118 |
}
|
|
119 |
break;
|
|
120 |
|
|
121 |
// sc_shutdownrpcservice
|
|
122 |
case 2:
|
|
123 |
{
|
|
124 |
// extract the parameters
|
|
125 |
GETINTEGERARGUMENT( "FORCE", &sarg_integer, 1, 1, aRequest, request_reply );
|
|
126 |
|
|
127 |
// make the call and update the return value
|
|
128 |
client_stub_error = iGenericStub->sc_shutdownrpcservice( sarg_integer, &rv_integer );
|
|
129 |
UpdateCompletionCode( request_reply, client_stub_error );
|
|
130 |
if( client_stub_error != ERR_NONE )
|
|
131 |
{
|
|
132 |
break;
|
|
133 |
}
|
|
134 |
// set the return values
|
|
135 |
request_reply->NewField( "RESULT", rv_integer );
|
|
136 |
}
|
|
137 |
break;
|
|
138 |
|
|
139 |
// RunCommand
|
|
140 |
case 10:
|
|
141 |
{
|
|
142 |
// Extract the call name first
|
|
143 |
char* callName = NULL;
|
|
144 |
GETSTRINGARGUMENT( "CALL", &callName, 1, 0, aRequest, request_reply );
|
|
145 |
|
|
146 |
if( callName == NULL )
|
|
147 |
{
|
|
148 |
UpdateCompletionCode( request_reply, ERR_INVALID_CALL );
|
|
149 |
return request_reply;
|
|
150 |
}
|
|
151 |
|
|
152 |
// Lookup the parameters for this call from the ini file
|
|
153 |
// Compare that they are all provided if required
|
|
154 |
vector<string> parameters = iIniFile->SectionParameters(callName);
|
|
155 |
|
|
156 |
// Retrieve the callID from the section by using the call name.
|
|
157 |
// NOTE: Every call section must have a callID
|
|
158 |
TCall call;
|
|
159 |
bool ret = iIniFile->KeyValue(CALL_ID, callName, call.iCallID);
|
|
160 |
if( !ret )
|
|
161 |
{
|
|
162 |
UpdateCompletionCode( request_reply, ERR_INVALID_CALL );
|
|
163 |
return request_reply;
|
|
164 |
}
|
|
165 |
|
|
166 |
call.iParams.iParams_len = parameters.size()-1; // Don't count the CallID
|
|
167 |
call.iParams.iParams_val = new TParam[parameters.size()-1];
|
|
168 |
|
|
169 |
// Package up the call to be sent to the service
|
|
170 |
int paramNum = 2; // Start at 2 as the "CALL" is 1.
|
|
171 |
int callParamCount = 0;
|
|
172 |
for( int i=0 ; i<parameters.size() ; i++ )
|
|
173 |
{
|
|
174 |
if( parameters[i] != CALL_ID )
|
|
175 |
{
|
|
176 |
int required;
|
|
177 |
ret = iIniFile->KeyValue(parameters[i], callName, required);
|
|
178 |
if( !ret )
|
|
179 |
{
|
|
180 |
delete[] call.iParams.iParams_val;
|
|
181 |
UpdateCompletionCode( request_reply, ERR_MISSING_PARAMETER );
|
|
182 |
return request_reply;
|
|
183 |
}
|
|
184 |
|
|
185 |
char* paramValue = NULL;
|
|
186 |
|
|
187 |
// Retrieve the parameter from the i/p stream (eg. script, console, serial comms, ip comms, etc)
|
|
188 |
if (GetStringArgument((char *) parameters[i].c_str(), ¶mValue, paramNum, true, aRequest, request_reply))
|
|
189 |
break;
|
|
190 |
|
|
191 |
// Check to see if some data is present for the parameter
|
|
192 |
if( paramValue==NULL )
|
|
193 |
{
|
|
194 |
// If the parameter was required then retun an error
|
|
195 |
if( required==1 )
|
|
196 |
{
|
|
197 |
delete[] call.iParams.iParams_val;
|
|
198 |
UpdateCompletionCode( request_reply, ERR_MISSING_PARAMETER );
|
|
199 |
return request_reply;
|
|
200 |
}
|
|
201 |
// Else just decrement the number of parameters being sent to the service
|
|
202 |
call.iParams.iParams_len--;
|
|
203 |
}
|
|
204 |
else
|
|
205 |
{
|
|
206 |
// Update the parameter name within the call
|
|
207 |
if( parameters[i].size() > 0 && parameters[i].size() <= MAXPARAMNAMELENGTH )
|
|
208 |
{
|
|
209 |
strcpy( call.iParams.iParams_val[callParamCount].iName,
|
|
210 |
parameters[i].c_str() );
|
|
211 |
|
|
212 |
}
|
|
213 |
// Update the parameter value within the call
|
|
214 |
if( strlen(paramValue) <= MAXPARAMVALUELENGTH )
|
|
215 |
{
|
|
216 |
strcpy( call.iParams.iParams_val[callParamCount].iValue,
|
|
217 |
paramValue );
|
|
218 |
}
|
|
219 |
|
|
220 |
// Increment the call parameter to update next
|
|
221 |
callParamCount++;
|
|
222 |
}
|
|
223 |
// Increment the script parameter number to retrieve next
|
|
224 |
paramNum++;
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
// Make the call and update the return values
|
|
229 |
call_result = iGenericStub->run_command( call, &rv_integer );
|
|
230 |
|
|
231 |
// Cleanup the parameters now
|
|
232 |
delete[] call.iParams.iParams_val;
|
|
233 |
|
|
234 |
UpdateCompletionCode( request_reply, call_result );
|
|
235 |
if( call_result != ERR_NONE )
|
|
236 |
{
|
|
237 |
break;
|
|
238 |
}
|
|
239 |
// set the return values
|
|
240 |
request_reply->NewField( "RESULT", rv_integer );
|
|
241 |
}
|
|
242 |
break;
|
|
243 |
|
|
244 |
// Any other method id results in an invalid method id result
|
|
245 |
default:
|
|
246 |
{
|
|
247 |
UpdateCompletionCode( request_reply, ERR_INVALID_METHOD );
|
|
248 |
}
|
|
249 |
break;
|
|
250 |
}
|
|
251 |
|
|
252 |
// everything should be handled above
|
|
253 |
return request_reply;
|
|
254 |
}
|
|
255 |
|
|
256 |
int CGenericStub::GetStatus()
|
|
257 |
{
|
|
258 |
return -1;
|
|
259 |
}
|
|
260 |
|
|
261 |
char *CGenericStub::GetLastRPCError( int *aIntError )
|
|
262 |
{
|
|
263 |
return iGenericStub->GetLastRPCError( aIntError );
|
|
264 |
}
|