// ----------------------------------------------------------------------------- // RMediatorServer::UnsubscribeEventListL // Unsubscribes a list of events. // ----------------------------------------------------------------------------- // TInt RMediatorServer::UnsubscribeEventList( TUid aDomain, TUid aCategory, const REventList& aEvents ) { TRACE(Print(_L("[Mediator Server]\t RMediatorServer::UnsubscribeEventList\n"))); // Check that session is open. __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, EMediatorClientNoSessionActive )); TInt status = KErrNone; // Check that there's something to unregister if ( aEvents.Count() ) { // Fill category TMediatorCategory category; category.iDomain = aDomain; category.iCategory = aCategory; TMediatorCategoryBuffer categoryBuffer( category ); // Create event array write pointer TInt arraySize = ( sizeof(MediatorService::TEvent) ) * aEvents.Count(); TPtr8 arrayPtr( (TUint8*)&aEvents[0], arraySize, arraySize ); // Send the command to server status = SendReceive( EUnsubscribeEventList, TIpcArgs( &categoryBuffer, &arrayPtr ) ); } return status; }
// ----------------------------------------------------------------------------- // CHWRMExtendedLightStatusObserver::CurrentStatus // Return Light status // ----------------------------------------------------------------------------- // CHWRMExtendedLight::TLightStatus CHWRMExtendedLightStatusObserver::CurrentStatus(TInt aTarget) const { COMPONENT_TRACE2(_L( "HWRM ExtendedLightClient - CHWRMExtendedLightStatusObserver::CurrentStatus(0x%x)" ), aTarget ); CHWRMExtendedLight::TLightStatus status( CHWRMExtendedLight::ELightStatusUnknown ); RLightStatusArray currentStatus( KHWRMLightMaxTargets ); TInt err = InitializeStatusArray( currentStatus ); if ( err == KErrNone ) { TInt arraySize = sizeof( THWRMStatusInfo ) * KHWRMLightMaxTargets; TPtr8 arrayPtr( ( TUint8* )¤tStatus[0], arraySize, arraySize ); err = RProperty::Get( KPSUidHWResourceNotification, KHWRMLightStatus, arrayPtr ); if( err == KErrNone ) { TInt index = currentStatus.FindInOrder( aTarget, FindByTarget ); if( index >= 0 && index < KHWRMLightMaxTargets ) { status = static_cast<CHWRMExtendedLight::TLightStatus>( currentStatus[index].iStatus ); } } } // Clean up currentStatus.Close(); COMPONENT_TRACE2(_L( "HWRM ExtendedLightClient - CHWRMExtendedLightStatusObserver::CurrentStatus - return 0x%x" ), status ); return status; }
// ----------------------------------------------------------------------------- // CHWRMExtendedLightStatusObserver::RunL // Handle notification from pubsub session. // ----------------------------------------------------------------------------- // void CHWRMExtendedLightStatusObserver::RunL() { COMPONENT_TRACE1(_L( "HWRM ExtendedLightClient - CHWRMExtendedLightStatusObserver::RunL()" )); // Reorder notification OrderNotification(); // get value from pubsub RLightStatusArray statusArray( KHWRMLightMaxTargets ); CleanupClosePushL( statusArray ); TInt err = InitializeStatusArray( statusArray ); if( err == KErrNone ) { TInt arraySize = sizeof( THWRMStatusInfo ) * KHWRMLightMaxTargets; TPtr8 arrayPtr( ( TUint8* )&statusArray[0], arraySize, arraySize ); err = iProperty.Get( arrayPtr ); if ( err == KErrNotFound || err == KErrNone ) { NotifyCallback( statusArray ); } } else { COMPONENT_TRACE2(_L( "HWRM ExtendedLightClient - CHWRMExtendedLightStatusObserver::RunL. Error (%d) in iProperty.Get()" ), err); NotifyCallback(iStatusUnknownList ); } CleanupStack::PopAndDestroy( &statusArray ); User::LeaveIfError( err ); COMPONENT_TRACE1(_L( "HWRM ExtendedLightClient - CHWRMExtendedLightStatusObserver::RunL - return" ) ); }
ArrayPtr<const char> KJ_STRINGIFY(Exception::Durability durability) { static const char* DURABILITY_STRINGS[] = { "permanent", "temporary", "overloaded" }; const char* s = DURABILITY_STRINGS[static_cast<uint>(durability)]; return arrayPtr(s, strlen(s)); }
ArrayPtr<const char> KJ_STRINGIFY(Exception::Nature nature) { static const char* NATURE_STRINGS[] = { "requirement not met", "bug in code", "error from OS", "network failure", "error" }; const char* s = NATURE_STRINGS[static_cast<uint>(nature)]; return arrayPtr(s, strlen(s)); }
HBufC8* AlfGcExternalizeL( const RArray<T>& aArray ) { const TInt itemCount = aArray.Count(); if ( !itemCount) { return HBufC8::NewL(0); } const T* firstItem = &aArray[0]; TPtrC8 arrayPtr( (TUint8*)firstItem, itemCount*sizeof(T) ); HBufC8* buffer = HBufC8::NewL( sizeof(TInt) + arrayPtr.Length() ); TPtr8 ptr = buffer->Des(); ptr.Append( (const TUint8*)&itemCount, sizeof(TInt) ); ptr.Append( arrayPtr ); return buffer; }
// ----------------------------------------------------------------------------- // CPsmSession::ReadConfigArrayL // ----------------------------------------------------------------------------- // void CPsmSession::ReadConfigArrayL( RConfigInfoArray& aArray, const RMessage2& aMessage ) { COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ReadConfigArrayL()" ) ) ); const TInt configCount( aMessage.Int1() ); TInt arrayLength( configCount * sizeof( TPsmsrvConfigInfo ) ); aArray.ReserveL(configCount); //Fill the array with dummy items for(TInt x = 0; x < configCount; ++x ) { // Append empty config infos to array aArray.AppendL( TPsmsrvConfigInfo() ); } TPtr8 arrayPtr( ( TUint8* )&aArray[0], arrayLength, arrayLength ); aMessage.ReadL( 0, arrayPtr, 0 ); COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::ReadConfigArrayL - return" ) ) ); }
void CSleepModeListenerPrivate::RunL() { sleepModeState.Subscribe(iStatus); SetActive(); CHWRMLight::TLightStatus status(CHWRMLight::ELightStatusUnknown); RLightStatusArray currentStatus(KHWRMLightMaxTargets); TInt err = InitializeStatusArray(currentStatus); if (err == KErrNone) { TInt arraySize = sizeof(THWRMStatusInfo) * KHWRMLightMaxTargets; TPtr8 arrayPtr((TUint8 *)¤tStatus[0], arraySize, arraySize); err = sleepModeState.Get(arrayPtr); if (err == KErrNone) { TInt index = currentStatus.FindInOrder(KHWRMLightFirstTarget, FindByTarget); if (index >= 0 && index < KHWRMLightMaxTargets) { status = static_cast<CHWRMLight::TLightStatus>(currentStatus[index].iStatus); if (!lastStatusValid || lastStatus != status) { lastStatusValid = true; lastStatus = status; RProcess process; // If process is something else than themeserver if (process.SecureId().iId != KHbPsHardwareCoarseOrientationCategoryUid.iUid) { QList<HbMainWindow *> mainWindowList = hbInstance->allMainWindows(); for (int i = 0; i < mainWindowList.count(); ++i) { if (status == CHWRMLight::ELightOff) { mainWindowList[i]->broadcastEvent(HbEvent::SleepModeEnter); } else { mainWindowList[i]->broadcastEvent(HbEvent::SleepModeExit); } } } else { HbEvent event(status == CHWRMLight::ELightOff ? HbEvent::SleepModeEnter : HbEvent::SleepModeExit); QCoreApplication::sendEvent(qApp, &event); } } } } } // Clean up currentStatus.Close(); }
// ----------------------------------------------------------------------------- // CPsmSession::HandleSettingsRequestL // ----------------------------------------------------------------------------- // void CPsmSession::HandleSettingsRequestL( const RMessage2& aMessage ) { COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL()" ) ) ); RConfigInfoArray configArray; CleanupClosePushL(configArray); // read config array from message ReadConfigArrayL( configArray, aMessage ); // Get storage UID TUint32 storage = aMessage.Int2(); TInt err( KErrNone ); switch ( aMessage.Function() ) { case EPsmServerBackupSettings: // For server backup settings { iPsmManager.SettingsProvider().BackupSettingsL( configArray, storage ); break; } case EPsmServerGetSettings: // For getting server settingspower save mode change { iPsmManager.SettingsProvider().GetSettingsL( configArray, storage ); // check whether the configArray is empty before writing the value back to message. if(configArray.Count() > 0) { // write changed values back to message TInt arraySize( configArray.Count() * sizeof( TPsmsrvConfigInfo ) ); TPtr8 arrayPtr( reinterpret_cast<TUint8*>(&configArray[0]), arraySize, arraySize ); err = aMessage.Write( 0, arrayPtr ); COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - New data wrote to message: %i" ), err ) ); } else { ERROR_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - Config Array is Empty" )) ); } break; } case EPsmServerChangeSettings: // For changing the settings { // We have to write changed values back to message iPsmManager.SettingsProvider().BackupAndGetSettingsL( configArray, storage ); // We have to write changed values back to message TInt arraySize( configArray.Count() * sizeof( TPsmsrvConfigInfo ) ); TPtr8 arrayPtr( reinterpret_cast<TUint8*>(&configArray[0]), arraySize, arraySize ); err = aMessage.Write( 0, arrayPtr ); ERROR_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - New data wrote to message: %i" ), err ) ); break; } default: { COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL() - unknown request: %i - ERROR" ), aMessage.Function() ) ); User::Leave( KErrUnknown ); } } // Complete message before destroying local config array aMessage.Complete( err ); CleanupStack::PopAndDestroy(&configArray); COMPONENT_TRACE( ( _L( "PSM Server - CPsmSession::HandleSettingsRequestL - return" ) ) ); }
// ----------------------------------------------------------------------------- // RMediatorServer::GetCommands // // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt RMediatorServer::GetCommands( TUid aDomain, TUid aCategory, RCommandList& aCommands ) { LOG(_L("[Mediator Server]\t RMediatorServer::GetCommands\n")); // Check that session is open. __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, EMediatorClientNoSessionActive )); // Create a structures for fetch data TMediatorCategory category; category.iDomain = aDomain; category.iCategory = aCategory; TMediatorCategoryBuffer categoryBuffer( category ); // Cleanup aCommands.Reset(); TInt err; // Reserve default sized array for command items if ( ( err = aCommands.Reserve( KMediatorMaxCommandCount ) ) != KErrNone ) { ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetCommands(ln%d): err=%d\n"), __LINE__, err ) ); return err; } // Append empty items to array to reserver space for ( TInt index = 0; index < KMediatorMaxCommandCount; index++ ) { TCommand emptyCommand; aCommands.Append( emptyCommand ); } // Define data return pointers TInt arraySize = ( sizeof(MediatorService::TCommand) ) * KMediatorMaxCommandCount; TPtr8 arrayPtr( (TUint8*)&aCommands[0], arraySize ); // Send the command to server TInt status = SendReceive( EGetCommands, TIpcArgs( &categoryBuffer, &arrayPtr ) ); // If no errors, Mediator Server completes the message with count if ( status > KMediatorMaxCommandCount ) { // We have too much data coming --> need to fetch more. // Cleanup commands aCommands.Reset(); if ( ( err = aCommands.Reserve( status ) ) != KErrNone ) { ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetCommands(ln%d): err=%d\n"), __LINE__, err ) ); return err; } // Append empty items to array to reserver space for ( TInt index = 0; index < status; index++ ) { TCommand emptyCommand; aCommands.Append( emptyCommand ); } // Update pointers TInt bigArraySize = ( sizeof(MediatorService::TCommand) ) * status; TPtr8 bigArrayPtr( (TUint8*)&aCommands[0], bigArraySize ); status = SendReceive( EGetCommands, TIpcArgs( &categoryBuffer, &bigArrayPtr ) ); } // Remove the unneeded items from the array for ( TInt index = aCommands.Count() - 1; index >= status && index >= 0 ; index-- ) { aCommands.Remove( index ); } if ( status > 0 ) { // No errors status = KErrNone; } return status; }
// ----------------------------------------------------------------------------- // RMediatorServer::GetDomains // // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt RMediatorServer::GetDomains( RDomainList& aDomains ) { LOG(_L("[Mediator Server]\t RMediatorServer::GetDomains\n")); // Check that session is open. __ASSERT_DEBUG( Handle(), User::Panic( KMediatorServerPanic, EMediatorClientNoSessionActive )); // Cleanup aDomains.Reset(); TInt err; // Reserve default sized array for domain items if ( ( err = aDomains.Reserve( KMediatorMaxDomainCount ) ) != KErrNone ) { ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetDomains(ln%d): err=%d\n"), __LINE__, err ) ); return err; } // Append empty items to array to reserver space for ( TInt index = 0; index < KMediatorMaxDomainCount; index++ ) { TUid dummy = TUid::Uid(0); aDomains.Append( dummy ); } // Define data passing pointers TInt arraySize = (sizeof(TUid) ) * KMediatorMaxDomainCount; TPtr8 arrayPtr( (TUint8*)&aDomains[0], arraySize ); // Send the command to server TInt status = SendReceive( EGetDomains, TIpcArgs( &arrayPtr ) ); // If no errors, Mediator Server completes the message with count if ( status > KMediatorMaxDomainCount ) { // Reset array, otherwise Append will not work correctly. // Reserve will perform Reset anyway, so omitting this would just complicate the code below aDomains.Reset(); // We have too much data coming --> need to fetch more. if ( ( err = aDomains.Reserve ( status ) ) != KErrNone ) { ERROR_TRACE(Print(_L("[Mediator] RMediatorServer::GetDomains(ln%d): err=%d\n"), __LINE__, err ) ); return err; } // Append empty items to array to reserver space for ( TInt index = 0; index < status; index++ ) { TUid dummy = TUid::Uid(0); aDomains.Append( dummy ); } TInt bigArraySize = (sizeof(TUid) ) * status; TPtr8 bigArrayPtr( (TUint8*)&aDomains[0], bigArraySize ); status = SendReceive( EGetDomains, TIpcArgs( &bigArrayPtr ) ); } // Remove the unneeded items from the array for ( TInt index = aDomains.Count() - 1; index >= status && index >= 0 ; index-- ) { aDomains.Remove( index ); } if ( status > 0 ) { // No errors status = KErrNone; } return status; }