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 |
#include <e32uid.h>
|
|
22 |
#include <string.h>
|
|
23 |
#include <stdlib.h>
|
|
24 |
|
|
25 |
|
|
26 |
/**********************************************************************************
|
|
27 |
*
|
|
28 |
* Local Includes
|
|
29 |
*
|
|
30 |
*********************************************************************************/
|
|
31 |
#include "assert.h"
|
|
32 |
#include "CUCCSDeviceControl.h"
|
|
33 |
|
|
34 |
// Error Codes
|
|
35 |
#include "CProtocolTypes.h"
|
|
36 |
#include "UCCS_ErrorCodes.h"
|
|
37 |
|
|
38 |
|
|
39 |
/**********************************************************************************
|
|
40 |
*
|
|
41 |
* Dll Entry point
|
|
42 |
*
|
|
43 |
*********************************************************************************/
|
|
44 |
/**********************************************************************************
|
|
45 |
*
|
|
46 |
* Construction / Destruction
|
|
47 |
*
|
|
48 |
*********************************************************************************/
|
|
49 |
EXPORT_C CUCCSDeviceControl* CUCCSDeviceControl::New()
|
|
50 |
{
|
|
51 |
CUCCSDeviceControl* self = new CUCCSDeviceControl();
|
|
52 |
CleanupStack::PushL(self);
|
|
53 |
self->ConstructL();
|
|
54 |
CleanupStack::Pop();
|
|
55 |
return self;
|
|
56 |
}
|
|
57 |
|
|
58 |
|
|
59 |
CUCCSDeviceControl::CUCCSDeviceControl()
|
|
60 |
{
|
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
void CUCCSDeviceControl::ConstructL()
|
|
65 |
{
|
|
66 |
iProtocol = new (ELeave) CUCCSDeviceProtocol();
|
|
67 |
assert( iProtocol != NULL );
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
EXPORT_C CUCCSDeviceControl::~CUCCSDeviceControl()
|
|
72 |
{
|
|
73 |
int ret;
|
|
74 |
ret = iProtocol->disconnect();
|
|
75 |
assert (ret == TDC_SUCCESS);
|
|
76 |
assert( iProtocol != NULL );
|
|
77 |
delete iProtocol;
|
|
78 |
iProtocol = NULL;
|
|
79 |
}
|
|
80 |
|
|
81 |
|
|
82 |
EXPORT_C TUint CUCCSDeviceControl::connectL( TDesC *aRemoteHost, TDPTransport aTransportType )
|
|
83 |
{
|
|
84 |
int ret = iProtocol->initialise(*aRemoteHost,aTransportType);
|
|
85 |
if (ret != TDP_SUCCESS)
|
|
86 |
return TDC_ERRINTIALISING;
|
|
87 |
return TDC_SUCCESS;
|
|
88 |
}
|
|
89 |
|
|
90 |
|
|
91 |
/**********************************************************************************
|
|
92 |
*
|
|
93 |
* startUseCase
|
|
94 |
*
|
|
95 |
*********************************************************************************/
|
|
96 |
EXPORT_C TUint CUCCSDeviceControl::startUseCase ( TUint aData, int *aErrorCode )
|
|
97 |
{
|
|
98 |
int ret, datalen;
|
|
99 |
TStartUsecaseRequest req;
|
|
100 |
TStartUsecaseReply rep;
|
|
101 |
TPCommand cmdID;
|
|
102 |
|
|
103 |
// Send the request
|
|
104 |
cmdID = CMD_REQ_STARTUSECASEID;
|
|
105 |
req.iUsecaseID = aData;
|
|
106 |
datalen = sizeof(req);
|
|
107 |
|
|
108 |
ret = iProtocol->sendMessage( cmdID, datalen, &req);
|
|
109 |
*aErrorCode = ret;
|
|
110 |
if ( ret != TDP_SUCCESS )
|
|
111 |
return TDC_ERRSENDING;
|
|
112 |
|
|
113 |
// Get the reply
|
|
114 |
datalen = sizeof(rep);
|
|
115 |
ret = iProtocol->receiveMessage ( &cmdID, &datalen, &rep);
|
|
116 |
*aErrorCode = ret;
|
|
117 |
if ( ret != TDP_SUCCESS )
|
|
118 |
return TDC_ERRRECV;
|
|
119 |
|
|
120 |
// Check that the reply cmdID is what we expect it to be
|
|
121 |
if ( cmdID != CMD_REP_STARTUSECASEID )
|
|
122 |
return TDC_INVALIDREPLY;
|
|
123 |
|
|
124 |
// Then return the result
|
|
125 |
return rep.iResult;
|
|
126 |
}
|
|
127 |
|
|
128 |
/**********************************************************************************
|
|
129 |
*
|
|
130 |
* signal
|
|
131 |
*
|
|
132 |
*********************************************************************************/
|
|
133 |
EXPORT_C TUint CUCCSDeviceControl::signal( TUint aData, int *aErrorCode )
|
|
134 |
{
|
|
135 |
int ret, datalen;
|
|
136 |
TSignalRequest req;
|
|
137 |
TSignalReply rep;
|
|
138 |
TPCommand cmdID;
|
|
139 |
|
|
140 |
// Send the request
|
|
141 |
cmdID = CMD_REQ_SIGNALID;
|
|
142 |
req.iUsecaseID = aData;
|
|
143 |
datalen = sizeof(req);
|
|
144 |
|
|
145 |
ret = iProtocol->sendMessage( cmdID, datalen, &req);
|
|
146 |
*aErrorCode = ret;
|
|
147 |
if ( ret != TDP_SUCCESS )
|
|
148 |
return TDC_ERRSENDING;
|
|
149 |
|
|
150 |
// Get the reply
|
|
151 |
datalen = sizeof(rep);
|
|
152 |
ret = iProtocol->receiveMessage ( &cmdID, &datalen, &rep);
|
|
153 |
*aErrorCode = ret;
|
|
154 |
if ( ret != TDP_SUCCESS )
|
|
155 |
return TDC_ERRRECV;
|
|
156 |
|
|
157 |
// Check that the reply cmdID is what we expect it to be
|
|
158 |
if ( cmdID != CMD_REP_SIGNALID )
|
|
159 |
return TDC_INVALIDREPLY;
|
|
160 |
|
|
161 |
// Then return the result
|
|
162 |
return rep.iResult;
|
|
163 |
}
|
|
164 |
|
|
165 |
/**********************************************************************************
|
|
166 |
*
|
|
167 |
* waitfor
|
|
168 |
*
|
|
169 |
*********************************************************************************/
|
|
170 |
EXPORT_C TUint CUCCSDeviceControl::waitfor( TUint aData, int *aErrorCode )
|
|
171 |
{
|
|
172 |
int ret, datalen;
|
|
173 |
TWaitRequest req;
|
|
174 |
TWaitReply rep;
|
|
175 |
TPCommand cmdID;
|
|
176 |
|
|
177 |
// Send the request
|
|
178 |
cmdID = CMD_REQ_WAITID;
|
|
179 |
req.iUsecaseID = aData;
|
|
180 |
datalen = sizeof(req);
|
|
181 |
|
|
182 |
ret = iProtocol->sendMessage( cmdID, datalen, &req);
|
|
183 |
*aErrorCode = ret;
|
|
184 |
if ( ret != TDP_SUCCESS )
|
|
185 |
return TDC_ERRSENDING;
|
|
186 |
|
|
187 |
// Get the reply
|
|
188 |
datalen = sizeof(rep);
|
|
189 |
ret = iProtocol->receiveMessage ( &cmdID, &datalen, &rep);
|
|
190 |
*aErrorCode = ret;
|
|
191 |
if ( ret != TDP_SUCCESS )
|
|
192 |
return TDC_ERRRECV;
|
|
193 |
|
|
194 |
// Check that the reply cmdID is what we expect it to be
|
|
195 |
if ( cmdID != CMD_REP_WAITID )
|
|
196 |
return TDC_INVALIDREPLY;
|
|
197 |
|
|
198 |
// Then return the result
|
|
199 |
return rep.iResult;
|
|
200 |
}
|
|
201 |
|
|
202 |
/**********************************************************************************
|
|
203 |
*
|
|
204 |
* rendezvous
|
|
205 |
*
|
|
206 |
*********************************************************************************/
|
|
207 |
EXPORT_C TUint CUCCSDeviceControl::rendezvous( TUint aData, int *aErrorCode )
|
|
208 |
{
|
|
209 |
int ret, datalen;
|
|
210 |
TRendezvousRequest req;
|
|
211 |
TRendezvousReply rep;
|
|
212 |
TPCommand cmdID;
|
|
213 |
|
|
214 |
// Send the request
|
|
215 |
cmdID = CMD_REQ_RENDEZVOUSID;
|
|
216 |
req.iUsecaseID = aData;
|
|
217 |
datalen = sizeof(req);
|
|
218 |
|
|
219 |
ret = iProtocol->sendMessage( cmdID, datalen, &req);
|
|
220 |
*aErrorCode = ret;
|
|
221 |
if ( ret != TDP_SUCCESS )
|
|
222 |
return TDC_ERRSENDING;
|
|
223 |
|
|
224 |
// Get the reply
|
|
225 |
datalen = sizeof(rep);
|
|
226 |
ret = iProtocol->receiveMessage ( &cmdID, &datalen, &rep);
|
|
227 |
*aErrorCode = ret;
|
|
228 |
if ( ret != TDP_SUCCESS )
|
|
229 |
return TDC_ERRRECV;
|
|
230 |
|
|
231 |
// Check that the reply cmdID is what we expect it to be
|
|
232 |
if ( cmdID != CMD_REP_RENDEZVOUSID )
|
|
233 |
return TDC_INVALIDREPLY;
|
|
234 |
|
|
235 |
// Then return the result
|
|
236 |
return rep.iResult;
|
|
237 |
}
|
|
238 |
|
|
239 |
/**********************************************************************************
|
|
240 |
*
|
|
241 |
* endUseCase
|
|
242 |
*
|
|
243 |
*********************************************************************************/
|
|
244 |
EXPORT_C TUint CUCCSDeviceControl::endUseCase (TUint aUseCaseID, TUint aResult, int *aErrorCode )
|
|
245 |
{
|
|
246 |
int ret, datalen;
|
|
247 |
TEndUsecaseRequest req;
|
|
248 |
TEndUsecaseReply rep;
|
|
249 |
TPCommand cmdID;
|
|
250 |
|
|
251 |
// Send the request
|
|
252 |
cmdID = CMD_REQ_ENDUSECASEID;
|
|
253 |
req.iUsecaseID = aUseCaseID;
|
|
254 |
req.iResult = aResult;
|
|
255 |
datalen = sizeof(req);
|
|
256 |
|
|
257 |
ret = iProtocol->sendMessage( cmdID, datalen, &req);
|
|
258 |
*aErrorCode = ret;
|
|
259 |
if ( ret != TDP_SUCCESS )
|
|
260 |
return TDC_ERRSENDING;
|
|
261 |
|
|
262 |
// Get the reply
|
|
263 |
datalen = sizeof(rep);
|
|
264 |
ret = iProtocol->receiveMessage ( &cmdID, &datalen, &rep);
|
|
265 |
*aErrorCode = ret;
|
|
266 |
if ( ret != TDP_SUCCESS )
|
|
267 |
return TDC_ERRRECV;
|
|
268 |
|
|
269 |
// Check that the reply cmdID is what we expect it to be
|
|
270 |
if ( cmdID != CMD_REP_ENDUSECASEID )
|
|
271 |
return TDC_INVALIDREPLY;
|
|
272 |
|
|
273 |
// Then return the result
|
|
274 |
return rep.iCommandResult;
|
|
275 |
}
|
|
276 |
|
|
277 |
/**********************************************************************************
|
|
278 |
*
|
|
279 |
* getVariableName
|
|
280 |
*
|
|
281 |
*********************************************************************************/
|
|
282 |
EXPORT_C TUint CUCCSDeviceControl::getVariableName( char* aVariableName, char* aOutputBuffer, int aOutputBufferSize, int *aErrorCode )
|
|
283 |
{
|
|
284 |
int ret, len, recDatalen;
|
|
285 |
TGetVariableNameRequest var_req;
|
|
286 |
TGetVariableNameReply var_rep;
|
|
287 |
TPCommand cmd;
|
|
288 |
|
|
289 |
// Check params
|
|
290 |
assert ( aVariableName != NULL );
|
|
291 |
assert ( aOutputBuffer != NULL );
|
|
292 |
assert ( aOutputBufferSize >= 0);
|
|
293 |
|
|
294 |
// Check if aVariableName can be copied into our structure
|
|
295 |
len = strlen(aVariableName) + 1;
|
|
296 |
if ( len > MAXVARNAMELEN )
|
|
297 |
return TDC_VARNAMETOOLONG;
|
|
298 |
|
|
299 |
// Then copy into our buffer
|
|
300 |
memcpy ( var_req.iVariableName, aVariableName, len);
|
|
301 |
|
|
302 |
// Send the request
|
|
303 |
cmd = CMD_REQ_GETVARIABLENAMEID;
|
|
304 |
ret = iProtocol->sendMessage( cmd, sizeof(var_req), &var_req);
|
|
305 |
*aErrorCode = ret;
|
|
306 |
if ( ret != TDP_SUCCESS )
|
|
307 |
return TDC_ERRSENDING;
|
|
308 |
|
|
309 |
// Get the reply
|
|
310 |
recDatalen = sizeof(var_rep);
|
|
311 |
ret = iProtocol->receiveMessage( &cmd, &recDatalen, &var_rep);
|
|
312 |
*aErrorCode = ret;
|
|
313 |
if ( ret != TDP_SUCCESS )
|
|
314 |
return TDC_ERRRECV;
|
|
315 |
|
|
316 |
// Check whether we successfully retrieved the value we want
|
|
317 |
if ( cmd != CMD_REP_GETVARIABLENAMEID)
|
|
318 |
return TDC_INVALIDREPLY; // Not what we are expecting
|
|
319 |
|
|
320 |
// Only copy the data if everything went ok at the UCCS end - UCCS_OK
|
|
321 |
if ( var_rep.iResult == UCCS_OK )
|
|
322 |
{
|
|
323 |
// Return the data
|
|
324 |
// Check that the data received will fit into the return buffer
|
|
325 |
len = strlen (var_rep.iVariableValue) + 1;
|
|
326 |
if ( len > aOutputBufferSize )
|
|
327 |
return TDC_VARVALTOOLONG;
|
|
328 |
|
|
329 |
// Else copy the data into the return buffer
|
|
330 |
memcpy ( aOutputBuffer, var_rep.iVariableValue, len);
|
|
331 |
}
|
|
332 |
|
|
333 |
return var_rep.iResult;
|
|
334 |
}
|
|
335 |
|
|
336 |
/**********************************************************************************
|
|
337 |
*
|
|
338 |
* runCommand
|
|
339 |
*
|
|
340 |
*********************************************************************************/
|
|
341 |
EXPORT_C TUint CUCCSDeviceControl::runCommandL( char* aCommandLine, int *aErrorCode )
|
|
342 |
{
|
|
343 |
int ret, len, recDatalen;
|
|
344 |
TRunCommandRequest* run_req = new (ELeave) (TRunCommandRequest);
|
|
345 |
TRunCommandReply run_rep;
|
|
346 |
TPCommand cmd;
|
|
347 |
|
|
348 |
// Check params
|
|
349 |
assert ( aCommandLine != NULL );
|
|
350 |
|
|
351 |
// Check if aCommandLine can be copied into our structure
|
|
352 |
len = strlen( aCommandLine )+1;
|
|
353 |
if ( len > MAXCOMMANDLINELEN )
|
|
354 |
return TDC_COMMANDLINETOOLONG;
|
|
355 |
|
|
356 |
// Then copy into our buffer
|
|
357 |
memset( run_req->iCommandLine, 0x00, sizeof(run_req->iCommandLine) );
|
|
358 |
memcpy( run_req->iCommandLine, aCommandLine, len);
|
|
359 |
|
|
360 |
// Send the request
|
|
361 |
cmd = CMD_REQ_RUNCOMMAND;
|
|
362 |
ret = iProtocol->sendMessage( cmd, sizeof(*run_req), run_req);
|
|
363 |
*aErrorCode = ret;
|
|
364 |
if ( ret != TDP_SUCCESS )
|
|
365 |
return TDC_ERRSENDING;
|
|
366 |
|
|
367 |
// Get the reply
|
|
368 |
recDatalen = sizeof(run_rep);
|
|
369 |
ret = iProtocol->receiveMessage( &cmd, &recDatalen, &run_rep);
|
|
370 |
*aErrorCode = ret;
|
|
371 |
if ( ret != TDP_SUCCESS )
|
|
372 |
return TDC_ERRRECV;
|
|
373 |
|
|
374 |
// Check whether we successfully retrieved the value we want
|
|
375 |
if ( cmd != CMD_REP_RUNCOMMAND)
|
|
376 |
return TDC_INVALIDREPLY; // Not what we are expecting
|
|
377 |
|
|
378 |
return run_rep.iResult;
|
|
379 |
}
|
|
380 |
|