|
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: Client API implementation for the Mediator Server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <e32std.h> |
|
22 #include <s32mem.h> |
|
23 #include "MediatorServerClient.h" |
|
24 #include "MediatorCommon.h" |
|
25 #include "Debug.h" |
|
26 |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KServerRetries = 2; |
|
30 |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 RMediatorServer::RMediatorServer() |
|
35 { |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // RMediatorServer::Connect |
|
40 // Creates a new client-server -session with MediatorServer. Starts it up if not |
|
41 // started already. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 TInt RMediatorServer::Connect() |
|
45 { |
|
46 // Check that there's no connection existing already |
|
47 if ( Handle() ) |
|
48 { |
|
49 return KErrAlreadyExists; |
|
50 } |
|
51 |
|
52 TInt tryLoop = 0; |
|
53 TInt error = 0; |
|
54 // Try to create session to server. If server is not started, try to start it. |
|
55 for ( tryLoop = 0; tryLoop < KServerRetries; tryLoop++ ) |
|
56 { |
|
57 error = CreateSession( KMediatorServerName, Version() ); |
|
58 |
|
59 TRACE(Print(_L("[Mediator Server]\t Session created with status %d\n"), error)); |
|
60 |
|
61 if ( error != KErrNotFound && error != KErrServerTerminated ) |
|
62 { |
|
63 if ( error != KErrNone ) |
|
64 { |
|
65 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::Connect(ln%d): error=%d\n"), __LINE__, error ) ); |
|
66 } |
|
67 |
|
68 return error; |
|
69 } |
|
70 |
|
71 error = StartServer(); |
|
72 |
|
73 if ( error != KErrNone && error != KErrAlreadyExists ) |
|
74 { |
|
75 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::Connect(ln%d): error=%d\n"), __LINE__, error ) ); |
|
76 return error; |
|
77 } |
|
78 |
|
79 } |
|
80 return error; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // StartServer |
|
85 // Creates a new process for the server and starts it up. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 TInt RMediatorServer::StartServer() |
|
89 { |
|
90 TInt result( KErrNone ); |
|
91 // create server - if one of this name does not already exist |
|
92 TFindProcess findServerProcess( KMediatorServerProcessName ); |
|
93 TFullName name; |
|
94 if ( findServerProcess.Next( name ) != KErrNone ) // we don't exist already |
|
95 { |
|
96 TRequestStatus status( KRequestPending ); |
|
97 RProcess server; |
|
98 // Create the server process |
|
99 result = server.Create( KMediatorServerExe, KNullDesC ); |
|
100 if( result != KErrNone ) |
|
101 { |
|
102 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::StartServer: result=%d\n"), result ) ); |
|
103 return result; |
|
104 } |
|
105 |
|
106 // Process created successfully |
|
107 server.Rendezvous( status ); |
|
108 server.Resume(); // start it going |
|
109 |
|
110 // Wait until the completion of the server creation |
|
111 // server signals us when it's up |
|
112 User::WaitForRequest( status ); |
|
113 if( status != KErrNone ) |
|
114 { |
|
115 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::StartServer: status=%d\n"), status.Int() ) ); |
|
116 server.Close(); |
|
117 return status.Int(); |
|
118 } |
|
119 |
|
120 // Server created successfully |
|
121 server.Close(); // we can close the handle to server process now |
|
122 } |
|
123 return result; |
|
124 } |
|
125 |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // RMediatorServer::Close |
|
129 // |
|
130 // (other items were commented in a header). |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void RMediatorServer::Close() |
|
134 { |
|
135 // Base call |
|
136 RSessionBase::Close(); |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // RMediatorServer::Version |
|
141 // |
|
142 // (other items were commented in a header). |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TVersion RMediatorServer::Version(void) const |
|
146 { |
|
147 return( TVersion( KMediatorServerMajor, |
|
148 KMediatorServerMinor, |
|
149 KMediatorServerBuild )); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // RMediatorServer::Cancel |
|
154 // Cancels ongoing command in Mediator |
|
155 // (other items were commented in a header). |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void RMediatorServer::Cancel( ) |
|
159 { |
|
160 LOG(_L("[Mediator Server]\t RMediatorServer::Cancel\n")); |
|
161 |
|
162 // Check that session is open. |
|
163 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
164 EMediatorClientNoSessionActive )); |
|
165 |
|
166 // Send the command (ignore return value) |
|
167 SendReceive( ECancelAll, TIpcArgs() ); |
|
168 } |
|
169 |
|
170 // ============================ REGISTRATION COMMANDS ========================== |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // RMediatorServer::RegisterEventL |
|
174 // Registers event list to MediatorServer |
|
175 // (other items were commented in a header). |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TInt RMediatorServer::RegisterEventList( TUid aDomain, |
|
179 TUid aCategory, |
|
180 const REventList& aEvents ) |
|
181 { |
|
182 LOG(_L("[Mediator Server]\t RMediatorServer::RegisterEventL list\n")); |
|
183 |
|
184 // Check that session is open. |
|
185 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
186 EMediatorClientNoSessionActive )); |
|
187 |
|
188 TInt status = KErrNone; |
|
189 |
|
190 // Check that there's something to register |
|
191 if ( aEvents.Count() > 0 ) |
|
192 { |
|
193 // Fill category |
|
194 TMediatorCategory category; |
|
195 category.iDomain = aDomain; |
|
196 category.iCategory = aCategory; |
|
197 TMediatorCategoryBuffer categoryBuffer( category ); |
|
198 |
|
199 // Create event array write pointer |
|
200 TInt arraySize = ( sizeof(MediatorService::TEvent) ) * aEvents.Count(); |
|
201 TPtr8 arrayPtr( (TUint8*)&aEvents[0], arraySize, arraySize ); |
|
202 |
|
203 // Send the command to server |
|
204 status = SendReceive( ERegisterEventList, |
|
205 TIpcArgs( &categoryBuffer, |
|
206 &arrayPtr ) ); |
|
207 } |
|
208 return status; |
|
209 } |
|
210 |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // RMediatorServer::RegisterCommandListL |
|
214 // Registers command list to MediatorServer |
|
215 // (other items were commented in a header). |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 TInt RMediatorServer::RegisterCommandList( TUid aDomain, |
|
219 TUid aCategory, |
|
220 const RCommandList& aCommands ) |
|
221 { |
|
222 LOG(_L("[Mediator Server]\t RMediatorServer::RegisterEventL list\n")); |
|
223 |
|
224 // Check that session is open. |
|
225 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
226 EMediatorClientNoSessionActive )); |
|
227 TInt status = KErrNone; |
|
228 |
|
229 // Check that there's something to register |
|
230 if ( aCommands.Count() ) |
|
231 { |
|
232 // Fill category |
|
233 TMediatorCategory category; |
|
234 category.iDomain = aDomain; |
|
235 category.iCategory = aCategory; |
|
236 TMediatorCategoryBuffer categoryBuffer( category ); |
|
237 |
|
238 // Create command array write pointer |
|
239 TInt arraySize = ( sizeof(MediatorService::TCommand) ) * aCommands.Count(); |
|
240 TPtr8 arrayPtr( (TUint8*)&aCommands[0], arraySize, arraySize ); |
|
241 |
|
242 // Send the command to server |
|
243 status = SendReceive( ERegisterCommandList, |
|
244 TIpcArgs( &categoryBuffer, |
|
245 &arrayPtr ) ); |
|
246 } |
|
247 |
|
248 return status; |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // RMediatorServer::UnregisterEventL |
|
253 // Unregisters event list. |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 TInt RMediatorServer::UnregisterEventList( TUid aDomain, |
|
257 TUid aCategory, |
|
258 const REventList& aEvents ) |
|
259 { |
|
260 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::UnregisterEventListL\n"))); |
|
261 |
|
262 // Check that session is open. |
|
263 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
264 EMediatorClientNoSessionActive )); |
|
265 |
|
266 TInt status = KErrNone; |
|
267 |
|
268 // Check that there's something to unregister |
|
269 if ( aEvents.Count() ) |
|
270 { |
|
271 // Fill category |
|
272 TMediatorCategory category; |
|
273 category.iDomain = aDomain; |
|
274 category.iCategory = aCategory; |
|
275 TMediatorCategoryBuffer categoryBuffer( category ); |
|
276 |
|
277 // Create event array write pointer |
|
278 TInt arraySize = ( sizeof(MediatorService::TEvent) ) * aEvents.Count(); |
|
279 TPtr8 arrayPtr( (TUint8*)&aEvents[0], arraySize, arraySize ); |
|
280 |
|
281 // Send the command to server |
|
282 status = SendReceive( EUnregisterEventList, |
|
283 TIpcArgs( &categoryBuffer, |
|
284 &arrayPtr ) ); |
|
285 } |
|
286 return status; |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // RMediatorServer::UnregisterCommandL |
|
291 // Unregisters command list. |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 TInt RMediatorServer::UnregisterCommandList( TUid aDomain, |
|
295 TUid aCategory, |
|
296 const RCommandList& aCommands ) |
|
297 { |
|
298 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::UnregisterCommandList\n"))); |
|
299 |
|
300 // Check that session is open. |
|
301 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
302 EMediatorClientNoSessionActive )); |
|
303 |
|
304 TInt status = KErrNone; |
|
305 |
|
306 // Check that there's something to unregister |
|
307 if ( aCommands.Count() ) |
|
308 { |
|
309 /// Fill category |
|
310 TMediatorCategory category; |
|
311 category.iDomain = aDomain; |
|
312 category.iCategory = aCategory; |
|
313 TMediatorCategoryBuffer categoryBuffer( category ); |
|
314 |
|
315 // Create command array write pointer |
|
316 TInt arraySize = ( sizeof(MediatorService::TCommand) ) * aCommands.Count(); |
|
317 TPtr8 arrayPtr( (TUint8*)&aCommands[0], arraySize, arraySize ); |
|
318 |
|
319 // Send the command to server |
|
320 status = SendReceive( EUnregisterCommandList, |
|
321 TIpcArgs( &categoryBuffer, |
|
322 &arrayPtr ) ); |
|
323 |
|
324 } |
|
325 return status; |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // RMediatorServer::RaiseEventL |
|
330 // Raise event to Mediator Server. |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 TInt RMediatorServer::RaiseEvent( TUid aDomain, |
|
334 TUid aCategory, |
|
335 TInt aEventId, |
|
336 TVersion aVersion, |
|
337 const TDesC8& aData ) |
|
338 { |
|
339 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::RaiseEvent\n"))); |
|
340 |
|
341 // Check that session is open. |
|
342 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
343 EMediatorClientNoSessionActive )); |
|
344 |
|
345 // Create a structures for event data |
|
346 TMediatorCategory category; |
|
347 category.iDomain = aDomain; |
|
348 category.iCategory = aCategory; |
|
349 TMediatorCategoryBuffer categoryBuffer( category ); |
|
350 |
|
351 TEvent event; |
|
352 event.iEventId = aEventId; |
|
353 event.iVersion = aVersion; |
|
354 TEventBuffer eventBuffer( event ); |
|
355 |
|
356 // Send the command to server |
|
357 return SendReceive( ERaiseEvent, |
|
358 TIpcArgs( &categoryBuffer, |
|
359 &eventBuffer, |
|
360 &aData ) ); |
|
361 |
|
362 } |
|
363 |
|
364 // ----------------------------------------------------------------------------- |
|
365 // RMediatorServer::SubscribeEvent |
|
366 // Subscribes a list of events |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 TInt RMediatorServer::SubscribeEventList( TUid aDomain, |
|
370 TUid aCategory, |
|
371 const REventList& aEvents ) |
|
372 { |
|
373 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::SubscribeEventList\n"))); |
|
374 |
|
375 // Check that session is open. |
|
376 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
377 EMediatorClientNoSessionActive )); |
|
378 |
|
379 TInt status = KErrNone; |
|
380 |
|
381 // Check that there's something to unregister |
|
382 if ( aEvents.Count() ) |
|
383 { |
|
384 // Fill category |
|
385 TMediatorCategory category; |
|
386 category.iDomain = aDomain; |
|
387 category.iCategory = aCategory; |
|
388 TMediatorCategoryBuffer categoryBuffer( category ); |
|
389 |
|
390 // Create event array write pointer |
|
391 TInt arraySize = ( sizeof(MediatorService::TEvent) ) * aEvents.Count(); |
|
392 TPtr8 arrayPtr( (TUint8*)&aEvents[0], arraySize, arraySize ); |
|
393 |
|
394 // Send the command to server |
|
395 status = SendReceive( ESubscribeEventList, |
|
396 TIpcArgs( &categoryBuffer, |
|
397 &arrayPtr ) ); |
|
398 } |
|
399 return status; |
|
400 } |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // RMediatorServer::UnsubscribeEventListL |
|
404 // Unsubscribes a list of events. |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 TInt RMediatorServer::UnsubscribeEventList( TUid aDomain, |
|
408 TUid aCategory, |
|
409 const REventList& aEvents ) |
|
410 { |
|
411 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::UnsubscribeEventList\n"))); |
|
412 |
|
413 // Check that session is open. |
|
414 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
415 EMediatorClientNoSessionActive )); |
|
416 TInt status = KErrNone; |
|
417 |
|
418 // Check that there's something to unregister |
|
419 if ( aEvents.Count() ) |
|
420 { |
|
421 // Fill category |
|
422 TMediatorCategory category; |
|
423 category.iDomain = aDomain; |
|
424 category.iCategory = aCategory; |
|
425 TMediatorCategoryBuffer categoryBuffer( category ); |
|
426 |
|
427 // Create event array write pointer |
|
428 TInt arraySize = ( sizeof(MediatorService::TEvent) ) * aEvents.Count(); |
|
429 TPtr8 arrayPtr( (TUint8*)&aEvents[0], arraySize, arraySize ); |
|
430 |
|
431 // Send the command to server |
|
432 status = SendReceive( EUnsubscribeEventList, |
|
433 TIpcArgs( &categoryBuffer, |
|
434 &arrayPtr ) ); |
|
435 } |
|
436 return status; |
|
437 } |
|
438 |
|
439 // ----------------------------------------------------------------------------- |
|
440 // RMediatorServer::IssueCommand |
|
441 // Synchronous function to send command request to Mediator Server |
|
442 // (other items were commented in a header). |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 TInt RMediatorServer::IssueCommand( TUid aDomain, |
|
446 TUid aCategory, |
|
447 TInt aCommandId, |
|
448 TVersion aVersion, |
|
449 const TDesC8& aData ) |
|
450 { |
|
451 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::IssueCommand\n"))); |
|
452 |
|
453 // Check that session is open. |
|
454 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
455 EMediatorClientNoSessionActive )); |
|
456 |
|
457 // Fill category |
|
458 TMediatorCategory category; |
|
459 category.iDomain = aDomain; |
|
460 category.iCategory = aCategory; |
|
461 TMediatorCategoryBuffer categoryBuffer( category ); |
|
462 |
|
463 // And command |
|
464 TCommand command; |
|
465 command.iCommandId = aCommandId; |
|
466 command.iVersion = aVersion; |
|
467 //Time out is initiatilized to 0 as its not used on the server side. |
|
468 //this is just to compress the tool warnings. |
|
469 command.iTimeout = 0; |
|
470 TCommandBuffer commandBuffer( command ); |
|
471 |
|
472 // Send the command |
|
473 return SendReceive( EIssueCommand, |
|
474 TIpcArgs( &categoryBuffer, |
|
475 &commandBuffer, |
|
476 &aData ) ); |
|
477 |
|
478 } |
|
479 |
|
480 // ----------------------------------------------------------------------------- |
|
481 // RMediatorServer::IssueResponse |
|
482 // Synchronous function to send command request to Mediator Server |
|
483 // (other items were commented in a header). |
|
484 // ----------------------------------------------------------------------------- |
|
485 // |
|
486 TInt RMediatorServer::IssueResponse( TUid aDomain, |
|
487 TUid aCategory, |
|
488 TInt aCommandId, |
|
489 TInt aStatus, |
|
490 const TDesC8& aData ) |
|
491 { |
|
492 LOG(_L("[Mediator Server]\t RMediatorServer::IssueResponse\n")); |
|
493 |
|
494 // Check that session is open. |
|
495 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
496 EMediatorClientNoSessionActive )); |
|
497 |
|
498 // Fill category |
|
499 TMediatorCategory category; |
|
500 category.iDomain = aDomain; |
|
501 category.iCategory = aCategory; |
|
502 TMediatorCategoryBuffer categoryBuffer( category ); |
|
503 |
|
504 // And command |
|
505 TCommand command; |
|
506 command.iCommandId = aCommandId; |
|
507 TCommandBuffer commandBuffer( command ); |
|
508 |
|
509 // Status |
|
510 TPckgBuf<TInt> statusBuffer( aStatus ); |
|
511 |
|
512 // Send the command |
|
513 return SendReceive( EIssueResponse, |
|
514 TIpcArgs( &categoryBuffer, |
|
515 &commandBuffer, |
|
516 &statusBuffer, |
|
517 &aData ) ); |
|
518 } |
|
519 |
|
520 // ----------------------------------------------------------------------------- |
|
521 // RMediatorServer::CancelCommand |
|
522 // Cancels ongoing command in Mediator |
|
523 // (other items were commented in a header). |
|
524 // ----------------------------------------------------------------------------- |
|
525 // |
|
526 TInt RMediatorServer::CancelCommand( TUid aDomain, |
|
527 TUid aCategory, |
|
528 TInt aCommandId ) |
|
529 { |
|
530 LOG(_L("[Mediator Server]\t RMediatorServer::CancelCommand\n")); |
|
531 |
|
532 // Check that session is open. |
|
533 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
534 EMediatorClientNoSessionActive )); |
|
535 |
|
536 // Fill category |
|
537 TMediatorCategory category; |
|
538 category.iDomain = aDomain; |
|
539 category.iCategory = aCategory; |
|
540 TMediatorCategoryBuffer categoryBuffer( category ); |
|
541 |
|
542 // And command |
|
543 TCommand command; |
|
544 command.iCommandId = aCommandId; |
|
545 TCommandBuffer commandBuffer( command ); |
|
546 |
|
547 // Send the command |
|
548 return SendReceive( ECancelCommand, |
|
549 TIpcArgs( &categoryBuffer, |
|
550 &commandBuffer ) ); |
|
551 } |
|
552 |
|
553 |
|
554 // ----------------------------------------------------------------------------- |
|
555 // RMediatorServer::ReceiveCommands |
|
556 // Asynchronous function to send command request to Mediator Server |
|
557 // (other items were commented in a header). |
|
558 // ----------------------------------------------------------------------------- |
|
559 // |
|
560 void RMediatorServer::ReceiveCommands( TRequestStatus& aStatus, |
|
561 TMediatorCategoryRetBuffer& aCategoryBuffer, |
|
562 TCommandRetBuffer& aCommandBuffer, |
|
563 TPtr8& aCommandData ) |
|
564 { |
|
565 SendReceive( EWaitForCommand, TIpcArgs( &aCategoryBuffer, |
|
566 &aCommandBuffer, |
|
567 &aCommandData ), aStatus ); |
|
568 } |
|
569 |
|
570 // ----------------------------------------------------------------------------- |
|
571 // RMediatorServer::GetDomains |
|
572 // |
|
573 // (other items were commented in a header). |
|
574 // ----------------------------------------------------------------------------- |
|
575 // |
|
576 TInt RMediatorServer::GetDomains( RDomainList& aDomains ) |
|
577 { |
|
578 LOG(_L("[Mediator Server]\t RMediatorServer::GetDomains\n")); |
|
579 |
|
580 // Check that session is open. |
|
581 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
582 EMediatorClientNoSessionActive )); |
|
583 // Cleanup |
|
584 aDomains.Reset(); |
|
585 |
|
586 TInt err; |
|
587 // Reserve default sized array for domain items |
|
588 if ( ( err = aDomains.Reserve( KMediatorMaxDomainCount ) ) != KErrNone ) |
|
589 { |
|
590 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetDomains(ln%d): err=%d\n"), __LINE__, err ) ); |
|
591 return err; |
|
592 } |
|
593 |
|
594 // Append empty items to array to reserver space |
|
595 for ( TInt index = 0; index < KMediatorMaxDomainCount; index++ ) |
|
596 { |
|
597 TUid dummy = TUid::Uid(0); |
|
598 aDomains.Append( dummy ); |
|
599 } |
|
600 |
|
601 // Define data passing pointers |
|
602 TInt arraySize = (sizeof(TUid) ) * KMediatorMaxDomainCount; |
|
603 TPtr8 arrayPtr( (TUint8*)&aDomains[0], arraySize ); |
|
604 |
|
605 // Send the command to server |
|
606 TInt status = SendReceive( EGetDomains, |
|
607 TIpcArgs( &arrayPtr ) ); |
|
608 |
|
609 // If no errors, Mediator Server completes the message with count |
|
610 if ( status > KMediatorMaxDomainCount ) |
|
611 { |
|
612 // Reset array, otherwise Append will not work correctly. |
|
613 // Reserve will perform Reset anyway, so omitting this would just complicate the code below |
|
614 aDomains.Reset(); |
|
615 |
|
616 // We have too much data coming --> need to fetch more. |
|
617 if ( ( err = aDomains.Reserve ( status ) ) != KErrNone ) |
|
618 { |
|
619 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetDomains(ln%d): err=%d\n"), __LINE__, err ) ); |
|
620 return err; |
|
621 } |
|
622 |
|
623 // Append empty items to array to reserver space |
|
624 for ( TInt index = 0; index < status; index++ ) |
|
625 { |
|
626 TUid dummy = TUid::Uid(0); |
|
627 aDomains.Append( dummy ); |
|
628 } |
|
629 |
|
630 TInt bigArraySize = (sizeof(TUid) ) * status; |
|
631 TPtr8 bigArrayPtr( (TUint8*)&aDomains[0], bigArraySize ); |
|
632 status = SendReceive( EGetDomains, |
|
633 TIpcArgs( &bigArrayPtr ) ); |
|
634 } |
|
635 |
|
636 // Remove the unneeded items from the array |
|
637 for ( TInt index = aDomains.Count() - 1; index >= status && index >= 0 ; index-- ) |
|
638 { |
|
639 aDomains.Remove( index ); |
|
640 } |
|
641 |
|
642 if ( status > 0 ) |
|
643 { |
|
644 // No errors |
|
645 status = KErrNone; |
|
646 } |
|
647 return status; |
|
648 } |
|
649 |
|
650 |
|
651 // ----------------------------------------------------------------------------- |
|
652 // RMediatorServer::GetCategories |
|
653 // |
|
654 // (other items were commented in a header). |
|
655 // ----------------------------------------------------------------------------- |
|
656 // |
|
657 TInt RMediatorServer::GetCategories( TUid aDomain, RCategoryList& aCategories ) |
|
658 { |
|
659 LOG(_L("[Mediator Server]\t RMediatorServer::GetCategories\n")); |
|
660 |
|
661 // Check that session is open. |
|
662 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
663 EMediatorClientNoSessionActive )); |
|
664 |
|
665 // Create a structures for fetch data |
|
666 TMediatorCategory category; |
|
667 category.iDomain = aDomain; |
|
668 category.iCategory = TUid::Uid(0); // Not used |
|
669 TMediatorCategoryBuffer categoryBuffer( category ); |
|
670 |
|
671 // cleanup |
|
672 aCategories.Reset(); |
|
673 |
|
674 TInt err; |
|
675 // Reserve default sized array for category items |
|
676 if ( ( err = aCategories.Reserve( KMediatorMaxCategoryCount ) ) != KErrNone ) |
|
677 { |
|
678 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetCategories(ln%d): err=%d\n"), __LINE__, err ) ); |
|
679 return err; |
|
680 } |
|
681 |
|
682 // Append empty items to array to reserver space |
|
683 for ( TInt index = 0; index < KMediatorMaxCategoryCount; index++ ) |
|
684 { |
|
685 TUid dummy = TUid::Uid(0); |
|
686 aCategories.Append( dummy ); |
|
687 } |
|
688 |
|
689 // Define data passing pointers |
|
690 TInt arraySize = (sizeof(TUid) ) * KMediatorMaxCategoryCount; |
|
691 TPtr8 arrayPtr( (TUint8*)&aCategories[0], arraySize ); |
|
692 |
|
693 // Send the command to server |
|
694 TInt status = SendReceive( EGetCategories, |
|
695 TIpcArgs( &categoryBuffer, |
|
696 &arrayPtr ) ); |
|
697 |
|
698 // If no errors, Mediator Server completes the message with count |
|
699 if ( status > KMediatorMaxCategoryCount ) |
|
700 { |
|
701 // We have too much data coming --> need to fetch more. |
|
702 // Cleanup categories |
|
703 aCategories.Reset(); |
|
704 |
|
705 if ( ( err = aCategories.Reserve( status ) ) != KErrNone ) |
|
706 { |
|
707 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetCategories(ln%d): err=%d\n"), __LINE__, err ) ); |
|
708 return err; |
|
709 } |
|
710 |
|
711 // Append empty items to array to reserver space |
|
712 for ( TInt index = 0; index < status; index++ ) |
|
713 { |
|
714 TUid dummy = TUid::Uid(0); |
|
715 aCategories.Append( dummy ); |
|
716 } |
|
717 TInt bigArraySize = (sizeof(TUid) ) * status; |
|
718 TPtr8 bigArrayPtr( (TUint8*)&aCategories[0], bigArraySize ); |
|
719 status = SendReceive( EGetCategories, |
|
720 TIpcArgs( &categoryBuffer, |
|
721 &bigArrayPtr ) ); |
|
722 } |
|
723 |
|
724 // Remove the unneeded items from the array |
|
725 for ( TInt index = aCategories.Count() - 1; index >= status && index >= 0 ; index-- ) |
|
726 { |
|
727 aCategories.Remove( index ); |
|
728 } |
|
729 |
|
730 if ( status > 0 ) |
|
731 { |
|
732 // No errors |
|
733 status = KErrNone; |
|
734 } |
|
735 return status; |
|
736 } |
|
737 |
|
738 // ----------------------------------------------------------------------------- |
|
739 // RMediatorServer::GetEvents |
|
740 // |
|
741 // (other items were commented in a header). |
|
742 // ----------------------------------------------------------------------------- |
|
743 // |
|
744 TInt RMediatorServer::GetEvents( TUid aDomain, |
|
745 TUid aCategory, |
|
746 REventList& aEvents ) |
|
747 { |
|
748 LOG(_L("[Mediator Server]\t RMediatorServer::GetEvents\n")); |
|
749 |
|
750 // Check that session is open. |
|
751 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
752 EMediatorClientNoSessionActive )); |
|
753 |
|
754 // Cleanup |
|
755 aEvents.Reset(); |
|
756 |
|
757 // Create a structures for fetch data |
|
758 TMediatorCategory category; |
|
759 category.iDomain = aDomain; |
|
760 category.iCategory = aCategory; |
|
761 TMediatorCategoryBuffer categoryBuffer( category ); |
|
762 |
|
763 TInt err; |
|
764 // Reserve default sized array for event items |
|
765 if ( ( err = aEvents.Reserve( KMediatorMaxEventCount ) ) != KErrNone ) |
|
766 { |
|
767 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetEvents(ln%d): err=%d\n"), __LINE__, err ) ); |
|
768 return err; |
|
769 } |
|
770 |
|
771 // Append empty items to array to reserver space |
|
772 for ( TInt index = 0; index < KMediatorMaxEventCount; index++ ) |
|
773 { |
|
774 TEvent emptyEvent; |
|
775 aEvents.Append( emptyEvent ); |
|
776 } |
|
777 |
|
778 // Define data return pointers |
|
779 TInt arraySize = ( sizeof(MediatorService::TEvent) ) * KMediatorMaxEventCount; |
|
780 TPtr8 arrayPtr( (TUint8*)&aEvents[0], arraySize ); |
|
781 |
|
782 // Send the command to server |
|
783 TInt status = SendReceive( EGetEvents, |
|
784 TIpcArgs( &categoryBuffer, |
|
785 &arrayPtr ) ); |
|
786 |
|
787 // If no errors, Mediator Server completes the message with count |
|
788 if ( status > KMediatorMaxEventCount ) |
|
789 { |
|
790 // We have too much data coming --> need to fetch more. |
|
791 // Cleanup events |
|
792 aEvents.Reset(); |
|
793 |
|
794 // Reserve default sized array for event items |
|
795 if ( ( err = aEvents.Reserve( status ) ) != KErrNone ) |
|
796 { |
|
797 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetEvents(ln%d): err=%d\n"), __LINE__, err ) ); |
|
798 return err; |
|
799 } |
|
800 |
|
801 // Append empty items to array to reserver space |
|
802 for ( TInt index = 0; index < status; index++ ) |
|
803 { |
|
804 TEvent emptyEvent; |
|
805 aEvents.Append( emptyEvent ); |
|
806 } |
|
807 // Update pointers |
|
808 TInt bigArraySize = ( sizeof(MediatorService::TEvent) ) * status; |
|
809 TPtr8 bigArrayPtr( (TUint8*)&aEvents[0], bigArraySize ); |
|
810 status = SendReceive( EGetEvents, |
|
811 TIpcArgs( &categoryBuffer, |
|
812 &bigArrayPtr ) ); |
|
813 } |
|
814 |
|
815 // Remove the unneeded items from the array |
|
816 for ( TInt index = aEvents.Count() - 1; index >= status && index >= 0 ; index-- ) |
|
817 { |
|
818 aEvents.Remove( index ); |
|
819 } |
|
820 |
|
821 if ( status > 0 ) |
|
822 { |
|
823 // No errors |
|
824 status = KErrNone; |
|
825 } |
|
826 return status; |
|
827 } |
|
828 |
|
829 // ----------------------------------------------------------------------------- |
|
830 // RMediatorServer::GetCommands |
|
831 // |
|
832 // (other items were commented in a header). |
|
833 // ----------------------------------------------------------------------------- |
|
834 // |
|
835 TInt RMediatorServer::GetCommands( TUid aDomain, |
|
836 TUid aCategory, |
|
837 RCommandList& aCommands ) |
|
838 { |
|
839 LOG(_L("[Mediator Server]\t RMediatorServer::GetCommands\n")); |
|
840 |
|
841 // Check that session is open. |
|
842 __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, |
|
843 EMediatorClientNoSessionActive )); |
|
844 |
|
845 // Create a structures for fetch data |
|
846 TMediatorCategory category; |
|
847 category.iDomain = aDomain; |
|
848 category.iCategory = aCategory; |
|
849 TMediatorCategoryBuffer categoryBuffer( category ); |
|
850 |
|
851 // Cleanup |
|
852 aCommands.Reset(); |
|
853 |
|
854 TInt err; |
|
855 // Reserve default sized array for command items |
|
856 if ( ( err = aCommands.Reserve( KMediatorMaxCommandCount ) ) != KErrNone ) |
|
857 { |
|
858 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetCommands(ln%d): err=%d\n"), __LINE__, err ) ); |
|
859 return err; |
|
860 } |
|
861 |
|
862 // Append empty items to array to reserver space |
|
863 for ( TInt index = 0; index < KMediatorMaxCommandCount; index++ ) |
|
864 { |
|
865 TCommand emptyCommand; |
|
866 aCommands.Append( emptyCommand ); |
|
867 } |
|
868 |
|
869 // Define data return pointers |
|
870 TInt arraySize = ( sizeof(MediatorService::TCommand) ) * KMediatorMaxCommandCount; |
|
871 TPtr8 arrayPtr( (TUint8*)&aCommands[0], arraySize ); |
|
872 |
|
873 // Send the command to server |
|
874 TInt status = SendReceive( EGetCommands, |
|
875 TIpcArgs( &categoryBuffer, |
|
876 &arrayPtr ) ); |
|
877 |
|
878 // If no errors, Mediator Server completes the message with count |
|
879 if ( status > KMediatorMaxCommandCount ) |
|
880 { |
|
881 // We have too much data coming --> need to fetch more. |
|
882 // Cleanup commands |
|
883 aCommands.Reset(); |
|
884 |
|
885 if ( ( err = aCommands.Reserve( status ) ) != KErrNone ) |
|
886 { |
|
887 ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetCommands(ln%d): err=%d\n"), __LINE__, err ) ); |
|
888 return err; |
|
889 } |
|
890 |
|
891 // Append empty items to array to reserver space |
|
892 for ( TInt index = 0; index < status; index++ ) |
|
893 { |
|
894 TCommand emptyCommand; |
|
895 aCommands.Append( emptyCommand ); |
|
896 } |
|
897 // Update pointers |
|
898 TInt bigArraySize = ( sizeof(MediatorService::TCommand) ) * status; |
|
899 TPtr8 bigArrayPtr( (TUint8*)&aCommands[0], bigArraySize ); |
|
900 status = SendReceive( EGetCommands, |
|
901 TIpcArgs( &categoryBuffer, |
|
902 &bigArrayPtr ) ); |
|
903 } |
|
904 // Remove the unneeded items from the array |
|
905 for ( TInt index = aCommands.Count() - 1; index >= status && index >= 0 ; index-- ) |
|
906 { |
|
907 aCommands.Remove( index ); |
|
908 } |
|
909 |
|
910 if ( status > 0 ) |
|
911 { |
|
912 // No errors |
|
913 status = KErrNone; |
|
914 } |
|
915 return status; |
|
916 } |
|
917 |
|
918 // ----------------------------------------------------------------------------- |
|
919 // RMediatorServer::ReceiveEvents |
|
920 // |
|
921 // (other items were commented in a header). |
|
922 // ----------------------------------------------------------------------------- |
|
923 // |
|
924 void RMediatorServer::ReceiveEvents( TRequestStatus& aStatus, |
|
925 TMediatorCategoryRetBuffer& aCategoryBuffer, |
|
926 TEventRetBuffer& aEventBuffer, |
|
927 TPtr8& aEventData ) |
|
928 { |
|
929 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::ReceiveEvents\n"))); |
|
930 SendReceive( EWaitForEvent, TIpcArgs( &aCategoryBuffer, |
|
931 &aEventBuffer, |
|
932 &aEventData ), aStatus ); |
|
933 } |
|
934 |
|
935 // ----------------------------------------------------------------------------- |
|
936 // RMediatorServer::ReceiveNotifications |
|
937 // |
|
938 // (other items were commented in a header). |
|
939 // ----------------------------------------------------------------------------- |
|
940 // |
|
941 void RMediatorServer::ReceiveNotifications( TRequestStatus& aStatus, |
|
942 TMediatorCategoryRetBuffer& aCategoryBuffer, |
|
943 TNotificationTypeRetBuffer& aTypeBuffer, |
|
944 TPtr8& aEventArrayPtr, |
|
945 TPtr8& aCommandArrayPtr ) |
|
946 { |
|
947 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::ReceiveNotifications\n"))); |
|
948 SendReceive( EWaitForNotifications, TIpcArgs( &aCategoryBuffer, |
|
949 &aTypeBuffer, |
|
950 &aEventArrayPtr, |
|
951 &aCommandArrayPtr ), aStatus ); |
|
952 } |
|
953 |
|
954 // ----------------------------------------------------------------------------- |
|
955 // RMediatorServer::ReceiveEvents |
|
956 // |
|
957 // (other items were commented in a header). |
|
958 // ----------------------------------------------------------------------------- |
|
959 // |
|
960 TInt RMediatorServer::CancelNotifications( ) |
|
961 { |
|
962 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::CancelNotifications\n"))); |
|
963 return SendReceive( ECancelNotifications, TIpcArgs() ); |
|
964 } |
|
965 |
|
966 // ----------------------------------------------------------------------------- |
|
967 // RMediatorServer::WaitForCommandResponse |
|
968 // |
|
969 // (other items were commented in a header). |
|
970 // ----------------------------------------------------------------------------- |
|
971 // |
|
972 void RMediatorServer::WaitForCommandResponse( |
|
973 TRequestStatus& aStatus, |
|
974 TMediatorCategoryRetBuffer& aCategoryBuffer, |
|
975 TCommandRetBuffer& aCommandBuffer, |
|
976 TPtr8& aCommandData, |
|
977 TPckg<TInt>& aStatusBuffer ) |
|
978 { |
|
979 TRACE(Print(_L("[Mediator Server]\t RMediatorServer::WaitForCommandResponse\n"))); |
|
980 SendReceive( EWaitForCommandResponse, TIpcArgs( &aCategoryBuffer, |
|
981 &aCommandBuffer, |
|
982 &aCommandData, |
|
983 &aStatusBuffer ), aStatus ); |
|
984 } |
|
985 |
|
986 // ----------------------------------------------------------------------------- |
|
987 // RMediatorServer::FetchParameterData |
|
988 // |
|
989 // (other items were commented in a header). |
|
990 // ----------------------------------------------------------------------------- |
|
991 // |
|
992 TInt RMediatorServer::FetchParameterData( TPtr8& aParameterData ) |
|
993 { |
|
994 LOG(_L("[Mediator Server]\t RMediatorServer::FetchParameterData\n")); |
|
995 return SendReceive( EFetchParameterData, TIpcArgs( &aParameterData ) ); |
|
996 } |
|
997 |
|
998 // ----------------------------------------------------------------------------- |
|
999 // RMediatorServer::FetchNotificationEventList |
|
1000 // |
|
1001 // (other items were commented in a header). |
|
1002 // ----------------------------------------------------------------------------- |
|
1003 // |
|
1004 TInt RMediatorServer::FetchNotificationEventList( TPtr8& aEventArrayPtr ) |
|
1005 { |
|
1006 LOG(_L("[Mediator Server]\t RMediatorServer::FetchNotificationEventList\n")); |
|
1007 return SendReceive( EFetchNotificationEventList, TIpcArgs( &aEventArrayPtr ) ); |
|
1008 } |
|
1009 |
|
1010 // ----------------------------------------------------------------------------- |
|
1011 // RMediatorServer::FetchNotificationCommandList |
|
1012 // |
|
1013 // (other items were commented in a header). |
|
1014 // ----------------------------------------------------------------------------- |
|
1015 // |
|
1016 TInt RMediatorServer::FetchNotificationCommandList( TPtr8& aCommandArrayPtr ) |
|
1017 { |
|
1018 LOG(_L("[Mediator Server]\t RMediatorServer::FetchNotificationEventList\n")); |
|
1019 return SendReceive( EFetchNotificationCommandList, TIpcArgs( &aCommandArrayPtr ) ); |
|
1020 } |
|
1021 |
|
1022 // End of file |