Update contrib.
1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include "featmgrclient.h"
23 #include "featmgrconfiguration.h"
24 #include "featmgrdebug.h"
25 #include "featmgrclientserver.h"
28 const TInt KRetry( 2 );
30 // ============================= LOCAL FUNCTIONS ===============================
32 // ============================ MEMBER FUNCTIONS ===============================
34 // -----------------------------------------------------------------------------
35 // RFeatMgrClient::RFeatMgrClient
36 // C++ default constructor can NOT contain any code, that
38 // -----------------------------------------------------------------------------
40 RFeatMgrClient::RFeatMgrClient()
41 : RSessionBase(), iFeaturePckg( NULL, 0, 0 )
45 // -----------------------------------------------------------------------------
46 // RFeatMgrClient::Connect
48 // -----------------------------------------------------------------------------
50 TInt RFeatMgrClient::Connect()
60 // Try to create a FeatMgr Server session
61 err = CreateSession( KServerProcessName,
65 LOG_IF_ERROR1( err, "RFeatMgrClient::Connect - CreateSession returned: %d", err );
67 if ( err != KErrNotFound && err != KErrServerTerminated )
69 // KErrNone or unrecoverable error
74 // Return code was KErrNotFound or KErrServerTerminated.
75 // Try to start a new FeatMgr Server
78 LOG_IF_ERROR1( err, "RFeatMgrClient::Connect - StartServer returned: %d", err );
80 if ( err != KErrNone && err != KErrAlreadyExists )
82 // Unrecoverable error
93 // -----------------------------------------------------------------------------
94 // RFeatMgrClient::StartServer
96 // -----------------------------------------------------------------------------
98 TInt RFeatMgrClient::StartServer()
101 TIMESTAMP( "StartServer start: " )
104 const TUidType serverUid( KNullUid, KServerUid2, KNullUid );
105 TInt err = server.Create( KServerExeName, // FeatMgrServer.exe
106 KNullDesC, // A descriptor containing data passed as
107 // an argument to the thread function of
108 // the new process's main thread, when it
109 // is first scheduled.
110 serverUid, // FeatMgr server UID
111 EOwnerProcess ); // Ownership of this process handle
113 // Return error code if we couldn't create a process
114 if ( err == KErrNone )
116 // Rendezvous is used to detect server start
118 server.Rendezvous( stat );
120 if ( stat != KRequestPending )
122 server.Kill( KErrNone ); // Abort startup
126 server.Resume(); // Logon OK - start the server
129 INFO_LOG( "RFeatMgrClient::StartServer - Waiting server startup" );
131 User::WaitForRequest( stat ); // Wait for start or death
133 INFO_LOG( "RFeatMgrClient::StartServer - Server startup wait finished" );
135 // We can't use the 'exit reason' if the server paniced as this
136 // is the panic 'reason' and may be '0' which cannot be distinguished
138 err = (server.ExitType() == EExitPanic)? KErrGeneral : stat.Int();
140 // We can close the handle now
144 TIMESTAMP( "StartServer end: " )
150 // -----------------------------------------------------------------------------
151 // RFeatMgrClient::ServerVersion
152 // Return version of server
153 // -----------------------------------------------------------------------------
155 TVersion RFeatMgrClient::ServerVersion() const
157 return TVersion( KServerVersionMajor, KServerVersionMinor, KServerVersionBuild );
161 // -----------------------------------------------------------------------------
162 // RFeatMgrClient::FeatureSupported()
163 // -----------------------------------------------------------------------------
165 TInt RFeatMgrClient::FeatureSupported( TFeatureEntry& aFeature ) const
167 TPckg<TFeatureEntry> pckg( aFeature );
168 TPckgBuf<TInt> pckgRet;
170 TInt retval = SendReceive(EFeatMgrFeatureSupported, TIpcArgs( &pckg, &pckgRet ));
172 if ( retval != KErrNone )
174 ERROR_LOG1( "RFeatMgrClient::FeatureSupported - SendReceive error %d", retval );
178 INFO_LOG2( "RFeatMgrClient::FeatureSupported - uid %d, supported %d",
179 aFeature.FeatureUid().iUid, pckgRet() );
183 // -----------------------------------------------------------------------------
184 // RFeatMgrClient::FeaturesSupported()
185 // -----------------------------------------------------------------------------
187 TInt RFeatMgrClient::FeaturesSupported( RFeatureArray& aFeatures )
191 TInt retval( KErrNone );
193 TRAP( retval, SendRcvFeatureArrayL( aFeatures, pckg() ) );
195 if ( retval != KErrNone )
197 ERROR_LOG1( "RFeatMgrClient::FeaturesSupported - SendReceive error %d", retval );
201 INFO_LOG1( "RFeatMgrClient::FeaturesSupported - return %d", pckg() );
205 // -----------------------------------------------------------------------------
206 // RFeatMgrClient::EnableFeature()
207 // -----------------------------------------------------------------------------
209 TInt RFeatMgrClient::EnableFeature( TUid aFeature ) const
213 TInt retval = SendReceive(EFeatMgrEnableFeature, TIpcArgs(aFeature.iUid, &pckg));
215 if ( retval != KErrNone )
217 ERROR_LOG1( "RFeatMgrClient::EnableFeature - SendReceive error %d", retval );
221 INFO_LOG1( "RFeatMgrClient::EnableFeature - return %d", pckg() );
225 // -----------------------------------------------------------------------------
226 // RFeatMgrClient::DisableFeature()
227 // -----------------------------------------------------------------------------
229 TInt RFeatMgrClient::DisableFeature( TUid aFeature ) const
233 TInt retval = SendReceive(EFeatMgrDisableFeature, TIpcArgs(aFeature.iUid, &pckg));
235 if ( retval != KErrNone )
237 ERROR_LOG1( "RFeatMgrClient::DisableFeature - SendReceive error %d", retval );
241 INFO_LOG1( "RFeatMgrClient::DisableFeature - return %d", pckg() );
245 // -----------------------------------------------------------------------------
246 // RFeatMgrClient::SetFeature()
247 // -----------------------------------------------------------------------------
249 TInt RFeatMgrClient::SetFeature( TUid aFeature, TBool aEnable, TInt aData ) const
253 TInt retval = SendReceive(EFeatMgrSetFeatureAndData, TIpcArgs(
254 aFeature.iUid, aEnable, aData, &pckg));
256 if ( retval != KErrNone )
258 ERROR_LOG1( "RFeatMgrClient::SetFeature - SendReceive error %d", retval );
262 INFO_LOG1( "RFeatMgrClient::SetFeature - return %d", pckg() );
266 // -----------------------------------------------------------------------------
267 // RFeatMgrClient::SetFeature()
268 // -----------------------------------------------------------------------------
270 TInt RFeatMgrClient::SetFeature( TUid aFeature, TInt aData ) const
274 TInt retval = SendReceive(EFeatMgrSetFeatureData, TIpcArgs(
275 aFeature.iUid, aData, &pckg));
277 if ( retval != KErrNone )
279 ERROR_LOG1( "RFeatMgrClient::SetFeature - SendReceive error %d", retval );
283 INFO_LOG1( "RFeatMgrClient::SetFeature - return %d", pckg() );
287 // -----------------------------------------------------------------------------
288 // RFeatMgrClient::AddFeature()
289 // -----------------------------------------------------------------------------
291 TInt RFeatMgrClient::AddFeature( TFeatureEntry aFeature ) const
293 TPckg<TFeatureEntry> pckg( aFeature );
294 TPckgBuf<TInt> pckgRet;
296 TInt retval = SendReceive(EFeatMgrAddFeature, TIpcArgs(&pckg, &pckgRet));
298 if ( retval != KErrNone )
300 ERROR_LOG1( "RFeatMgrClient::AddFeature - SendReceive error %d", retval );
304 INFO_LOG1( "RFeatMgrClient::AddFeature - return %d", pckgRet() );
308 // -----------------------------------------------------------------------------
309 // RFeatMgrClient::DeleteFeature()
310 // -----------------------------------------------------------------------------
312 TInt RFeatMgrClient::DeleteFeature( TUid aFeature ) const
316 TInt retval = SendReceive(EFeatMgrDeleteFeature, TIpcArgs(aFeature.iUid, &pckg));
318 if ( retval != KErrNone )
320 ERROR_LOG1( "RFeatMgrClient::DeleteFeature - SendReceive error %d", retval );
324 INFO_LOG1( "RFeatMgrClient::DeleteFeature - return %d", pckg() );
328 // -----------------------------------------------------------------------------
329 // RFeatMgrClient::ListSupportedFeaturesL()
330 // -----------------------------------------------------------------------------
332 void RFeatMgrClient::ListSupportedFeaturesL( RFeatureUidArray& aSupportedFeatures )
334 // Reset as array might contain old data.
335 aSupportedFeatures.Reset();
337 TInt err( KErrNone );
339 TPckg<TInt> sizePckg( count );
343 User::LeaveIfError( SendReceive( EFeatMgrNumberOfSupportedFeatures,
344 TIpcArgs( &sizePckg ) ) );
346 HBufC8* buf = HBufC8::NewLC( count * sizeof( TInt ) );
347 TPtr8 ptr = buf->Des();
349 err = SendReceive( EFeatMgrListSupportedFeatures, TIpcArgs( count, &ptr ) );
350 LOG_IF_ERROR1( err, "RFeatMgrClient::ListSupportedFeaturesL - SendReceive error %d", err );
351 INFO_LOG1( "RFeatMgrClient::ListSupportedFeaturesL - count %d", count );
353 if ( err == KErrNone )
355 aSupportedFeatures.ReserveL( count );
357 for ( TInt i = 0; i < count; i++ )
359 TPtrC8 featurePtr = ptr.Mid( i * sizeof( TUid ), sizeof( TUid ) );
360 TUid featureId = TUid::Uid( 0 );
361 TPckg<TUid> feature( featureId );
362 feature.Copy( featurePtr );
363 aSupportedFeatures.AppendL( featureId );
368 else if ( err == KErrServerBusy )
376 CleanupStack::PopAndDestroy( buf );
379 User::LeaveIfError( err );
383 // -----------------------------------------------------------------------------
384 // RFeatMgrClient::ReRequestNotification(TUid&, TRequestStatus&)
385 // -----------------------------------------------------------------------------
387 void RFeatMgrClient::ReRequestNotification( TUid& aFeatUid, TRequestStatus& aStatus )
390 iFeaturePckg.Set( (TUint8*) &aFeatUid.iUid, sizeof(TUid), sizeof(TUid) );
391 TIpcArgs args( &iFeaturePckg );
392 SendReceive( EFeatMgrReqNotify, args, aStatus );
395 // -----------------------------------------------------------------------------
396 // RFeatMgrClient::RequestNotification(RFeatureUidArray&, TUid&, TRequestStatus&)
397 // -----------------------------------------------------------------------------
399 TInt RFeatMgrClient::RequestNotification( RFeatureUidArray& aFeatures,
400 TUid& aFeatUid, TRequestStatus& aStatus )
404 TInt retval( KErrNone );
406 TRAP( retval, SendUidArrayL( aFeatures, pckg() ) );
408 if ( retval == KErrNone )
410 iFeaturePckg.Set( (TUint8*) &aFeatUid.iUid, sizeof(TUid), sizeof(TUid) );
411 TIpcArgs args( &iFeaturePckg );
412 SendReceive( EFeatMgrReqNotify, args, aStatus );
416 ERROR_LOG1( "RFeatMgrClient::RequestNotification - SendReceive error %d", retval );
420 INFO_LOG1( "RFeatMgrClient::RequestNotification - return %d", pckg() );
424 // -----------------------------------------------------------------------------
425 // RFeatMgrClient::RequestNotifyCancel(TUid)
426 // -----------------------------------------------------------------------------
428 TInt RFeatMgrClient::RequestNotifyCancel( TUid aFeature ) const
432 TInt retval = SendReceive(EFeatMgrReqNotifyCancel, TIpcArgs(aFeature.iUid, &pckg));
434 if ( retval != KErrNone )
436 ERROR_LOG1( "RFeatMgrClient::RequestNotifyCancel - SendReceive error %d", retval );
440 INFO_LOG1( "RFeatMgrClient::RequestNotifyCancel - return %d", pckg() );
444 // -----------------------------------------------------------------------------
445 // RFeatMgrClient::RequestNotifyCancelAll()
446 // -----------------------------------------------------------------------------
448 TInt RFeatMgrClient::RequestNotifyCancelAll() const
452 TInt retval = SendReceive(EFeatMgrReqNotifyCancelAll, TIpcArgs(&pckg));
454 if ( retval != KErrNone )
456 ERROR_LOG1( "RFeatMgrClient::RequestNotifyCancelAll - SendReceive error %d", retval );
460 INFO_LOG1( "RFeatMgrClient::RequestNotifyCancelAll - return %d", pckg() );
464 // -----------------------------------------------------------------------------
465 // RFeatMgrClient::SendUidArrayL()
466 // -----------------------------------------------------------------------------
468 void RFeatMgrClient::SendUidArrayL( RFeatureUidArray& aFeatures, TInt &retval)
472 INFO_LOG1( "RFeatMgrClient::SendUidArrayL - Send %d features", aFeatures.Count() );
474 TInt size = aFeatures.Count() * sizeof(TUid);
475 CBufBase* buffer = CBufFlat::NewL( size );
476 CleanupStack::PushL( buffer );
477 buffer->ResizeL( size );
479 RBufWriteStream stream( *buffer );
480 CleanupClosePushL( stream );
482 TInt count = aFeatures.Count();
483 // Write each field in array to stream
484 for(TInt i = 0; i < count; i++)
486 stream.WriteUint32L( aFeatures[i].iUid );
491 // Write transfer buffer to server
492 TPtr8 pBuffer(buffer->Ptr(0));
494 TIpcArgs args( count, &pBuffer, &pckg );
495 TInt sendErr = SendReceive( EFeatMgrReqNotifyUids, args );
499 CleanupStack::PopAndDestroy( &stream );
500 CleanupStack::PopAndDestroy( buffer );
501 User::LeaveIfError( sendErr );
504 // -----------------------------------------------------------------------------
505 // RFeatMgrClient::SendRcvFeatureArrayL()
506 // -----------------------------------------------------------------------------
508 void RFeatMgrClient::SendRcvFeatureArrayL( RFeatureArray& aFeatures, TInt &retval)
512 INFO_LOG1( "RFeatMgrClient::SendRcvFeatureArrayL - Send %d features", aFeatures.Count() );
514 TInt size = aFeatures.Count() * sizeof(TFeatureEntry);
515 CBufBase* buffer = CBufFlat::NewL( size );
516 CleanupStack::PushL( buffer );
517 buffer->ResizeL( size );
519 RBufWriteStream stream( *buffer );
520 CleanupClosePushL( stream );
522 TInt count = aFeatures.Count();
523 // Write each field in array to stream
524 for(TInt i = 0; i < count; i++)
526 TFeatureEntry entry( aFeatures[i].FeatureUid(), aFeatures[i].FeatureFlags(),
527 aFeatures[i].FeatureData() );
528 stream.WriteUint32L( aFeatures[i].FeatureUid().iUid );
529 stream.WriteUint32L( aFeatures[i].FeatureFlags().iFlags );
530 stream.WriteUint32L( aFeatures[i].FeatureData() );
531 stream.WriteUint32L( 0 ); // reserved
536 // Write transfer buffer to server
537 TPtr8 pBuffer(buffer->Ptr(0));
539 TIpcArgs args( count, &pBuffer, &pckg );
540 TInt sendErr = SendReceive( EFeatMgrFeaturesSupported, args );
542 if ( sendErr == KErrNone )
544 TInt responseCount = pckg();
545 // Read modified feature entries back to array
546 RBufReadStream readStream( *buffer );
547 CleanupClosePushL( readStream );
549 aFeatures.ReserveL( responseCount );
551 for ( TInt i = 0; i < responseCount; i++ )
553 TUid uid = TUid::Uid( readStream.ReadUint32L() );
554 TBitFlags32 flags = readStream.ReadUint32L();
555 TUint32 data = readStream.ReadUint32L();
556 readStream.ReadUint32L(); // reserved
557 TFeatureEntry entry( uid, flags, data );
558 aFeatures.AppendL( entry );
561 CleanupStack::PopAndDestroy( &readStream );
564 retval = KErrNone; // Currently no error response exist.
566 CleanupStack::PopAndDestroy( &stream );
567 CleanupStack::PopAndDestroy( buffer );
568 User::LeaveIfError( sendErr );
571 // -----------------------------------------------------------------------------
572 // RFeatMgrClient::SWIStart()
573 // -----------------------------------------------------------------------------
575 TInt RFeatMgrClient::SWIStart() const
579 TInt retval = SendReceive(EFeatMgrSWIStart, TIpcArgs(&pckg));
581 if ( retval != KErrNone )
583 ERROR_LOG1( "RFeatMgrClient::SWIStart - SendReceive error %d", retval );
587 INFO_LOG1( "RFeatMgrClient::SWIStart - return %d", pckg() );
591 // -----------------------------------------------------------------------------
592 // RFeatMgrClient::SWIEnd()
593 // -----------------------------------------------------------------------------
595 TInt RFeatMgrClient::SWIEnd() const
599 TInt retval = SendReceive(EFeatMgrSWIEnd, TIpcArgs(&pckg));
601 if ( retval != KErrNone )
603 ERROR_LOG1( "RFeatMgrClient::SWIEnd - SendReceive error %d", retval );
607 INFO_LOG1( "RFeatMgrClient::SWIEnd - return %d", pckg() );
611 // ========================== OTHER EXPORTED FUNCTIONS =========================
613 // DEBUG only API functions
615 #ifdef EXTENDED_FEATURE_MANAGER_TEST
617 #pragma BullseyeCoverage off
621 void RFeatMgrClient::ResourceMark()
623 (void)SendReceive(EFeatMgrResourceMark);
628 void RFeatMgrClient::ResourceCheck()
630 (void)SendReceive(EFeatMgrResourceCheck);
635 TInt RFeatMgrClient::ResourceCount()
637 return SendReceive(EFeatMgrResourceCount);
642 void RFeatMgrClient::SetHeapFailure(TInt aAllocFailType, TInt aRate)
644 (void)SendReceive(EFeatMgrSetHeapFailure, TIpcArgs(aAllocFailType, aRate));
647 // -----------------------------------------------------------------------------
648 // RFeatMgrClient::NumberOfNotifyFeatures()
649 // -----------------------------------------------------------------------------
651 TInt RFeatMgrClient::NumberOfNotifyFeatures( void ) const
654 TPckg<TInt> sizePckg( count );
656 TInt retval = SendReceive( EFeatMgrNumberOfNotifyFeatures, TIpcArgs( &sizePckg ) );
657 if ( KErrNone != retval )
659 ERROR_LOG1( "RFeatMgrClient::NumberOfNotifyFeatures - SendReceive error %d", retval );
663 INFO_LOG1( "RFeatMgrClient::NumberOfNotifyFeatures - return %d", sizePckg() );
667 // -----------------------------------------------------------------------------
668 // RFeatMgrClient::CountAllocCells()
669 // -----------------------------------------------------------------------------
671 TInt RFeatMgrClient::CountAllocCells( void ) const
674 TPckg<TInt> sizePckg( count );
676 TInt retval = SendReceive( EFeatMgrCountAllocCells, TIpcArgs( &sizePckg ) );
677 if ( KErrNone != retval )
679 ERROR_LOG1( "RFeatMgrClient::CountAllocCells - SendReceive error %d", retval );
683 INFO_LOG1( "RFeatMgrClient::CountAllocCells - return %d", sizePckg() );
687 #pragma BullseyeCoverage on