uiacceltk/hitchcock/ServerCore/Src/alfsrvsettingshandler.cpp
changeset 0 15bf7259bb7c
child 10 7c5dd702d6d3
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2007 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:   Settings handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "alfsrvsettingshandler.h"
       
    21 #include "uiacceltkdomaincrkeys.h"
       
    22 #include "alf/alfappui.h"
       
    23 
       
    24 #include <centralrepository.h>
       
    25 
       
    26 const TInt KAlfSrvDefaultRenderer = EHuiRendererBitgdi;
       
    27 const TInt KAlfSrvDefaultFrameRate = 22;
       
    28 const TInt KAlfSrvDefaultCpuUsage = 75;
       
    29 const TInt KAlfSrvDefaultResourceCacheSize = 1000;
       
    30 const TInt KAlfSrvDefaultComplexityFactor = 7;
       
    31 const TInt KAlfSrvDefaultHwConfiguration = 0;
       
    32 
       
    33 const TUint KAlfSrvRndBitMask = 0x00ff; // the lowest 8 bits are for the complexity factor
       
    34 
       
    35 // ======== MEMBER FUNCTIONS ========
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // ?description_if_needed
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CAlfSrvSettingsHandler::CAlfSrvSettingsHandler( MAlfSrvSettingsObserver& aObserver )
       
    42  : CActive( EPriorityStandard ), iObserver( aObserver )
       
    43     {
       
    44     CActiveScheduler::Add( this );
       
    45     }
       
    46 
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // ?description_if_needed
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 void CAlfSrvSettingsHandler::ConstructL()
       
    53     {
       
    54     // TRAP before the cenrep key exists in builds
       
    55     TRAP_IGNORE( iCentralRepository = CRepository::NewL( KCRUidUIAccelTK ) )
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // ?description_if_needed
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CAlfSrvSettingsHandler* CAlfSrvSettingsHandler::NewL( MAlfSrvSettingsObserver& aObserver )
       
    63     {
       
    64     CAlfSrvSettingsHandler* self = new( ELeave ) CAlfSrvSettingsHandler( aObserver );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // ?description_if_needed
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CAlfSrvSettingsHandler::~CAlfSrvSettingsHandler()
       
    77     {
       
    78     Cancel();
       
    79     delete iCentralRepository;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // ?implementation_description
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CAlfSrvSettingsHandler::StartObserving()
       
    87     {
       
    88     if ( !IsActive() )
       
    89         {
       
    90         // order notification for all keys in repository  
       
    91         iCentralRepository->NotifyRequest(0x00000000, 0x00000000, iStatus);
       
    92         SetActive();
       
    93         }
       
    94     }
       
    95 
       
    96 THuiRenderer CAlfSrvSettingsHandler::Renderer()
       
    97     {
       
    98     TInt result = KAlfSrvDefaultRenderer;
       
    99     if ( !iCentralRepository ) 
       
   100         {
       
   101         return static_cast<THuiRenderer>(result);
       
   102         }
       
   103         
       
   104     if ( iCentralRepository->Get( KUIAccelTKRenderer,result ) == KErrNone )
       
   105         {
       
   106         StartObserving();
       
   107         }
       
   108     
       
   109     return static_cast<THuiRenderer>(result);
       
   110     }
       
   111     
       
   112 TUint CAlfSrvSettingsHandler::DefaultFramerate()
       
   113     {
       
   114     TInt result = KAlfSrvDefaultFrameRate;
       
   115     if ( !iCentralRepository ) 
       
   116         {
       
   117         return result;
       
   118         }
       
   119         
       
   120     if ( iCentralRepository->Get( KUIAccelTKDefaultFrameRate,result ) == KErrNone )
       
   121         {
       
   122         StartObserving();
       
   123         }
       
   124     
       
   125     return result;
       
   126     }
       
   127     
       
   128 TUint CAlfSrvSettingsHandler::MaxCpuUsage()
       
   129     {
       
   130     // Update cached value only if it is not initialized
       
   131     TInt result = KAlfSrvDefaultCpuUsage;
       
   132     if (iMaxCpuUsage == 0)
       
   133     	{    	
       
   134     	if ( !iCentralRepository ) 
       
   135         	{
       
   136     		iMaxCpuUsage = result;
       
   137         	return result;
       
   138         	}
       
   139         	
       
   140     	if ( iCentralRepository->Get( KUIAccelTKMaxCpuUsage, result ) == KErrNone )
       
   141         	{
       
   142         	// Store value to cache (iMaxCpuUsage)
       
   143         	iMaxCpuUsage = result;
       
   144         	StartObserving();
       
   145         	}
       
   146     	}
       
   147     else
       
   148         {
       
   149         // Use cached value
       
   150         result = iMaxCpuUsage;    
       
   151         }	
       
   152     	
       
   153     return result;
       
   154     }
       
   155     
       
   156 TUint CAlfSrvSettingsHandler::MaxResourceCacheSize()
       
   157     {
       
   158     TInt result = KAlfSrvDefaultResourceCacheSize;
       
   159     if ( !iCentralRepository ) 
       
   160         {
       
   161         return result;
       
   162         }
       
   163         
       
   164     if ( iCentralRepository->Get( KUIAccelTKMaxResourceCache,result ) == KErrNone )
       
   165         {
       
   166         StartObserving();
       
   167         }
       
   168     
       
   169     return result;
       
   170     }
       
   171     
       
   172 TUint CAlfSrvSettingsHandler::EffectsComplexityFactor()
       
   173     {
       
   174     TInt result = KAlfSrvDefaultComplexityFactor;
       
   175     if ( !iCentralRepository ) 
       
   176         {
       
   177         return result;
       
   178         }
       
   179         
       
   180     if ( iCentralRepository->Get( KUIAccelTKEffectsComplexityFactor,result ) == KErrNone )
       
   181         {
       
   182         result = result&KAlfSrvRndBitMask; // remove Rnd flags
       
   183         
       
   184         StartObserving();
       
   185         }
       
   186     
       
   187     return result;
       
   188     }
       
   189     
       
   190 TUint CAlfSrvSettingsHandler::HWDriverConfiguration()
       
   191     {
       
   192     TInt result = KAlfSrvDefaultHwConfiguration;
       
   193     if ( !iCentralRepository ) 
       
   194         {
       
   195         return result;
       
   196         }
       
   197         
       
   198     if ( iCentralRepository->Get( KUIAccelTKHWConfigurationFlags,result ) == KErrNone )
       
   199         {
       
   200         StartObserving();
       
   201         }
       
   202     
       
   203     return result;
       
   204     }
       
   205     
       
   206 TUint CAlfSrvSettingsHandler::RndFlags()
       
   207     {
       
   208     TInt result = 0;
       
   209     if ( !iCentralRepository ) 
       
   210         {
       
   211         return result;
       
   212         }
       
   213         
       
   214     if ( iCentralRepository->Get( KUIAccelTKEffectsComplexityFactor,result ) == KErrNone )
       
   215         {
       
   216         result = result&~KAlfSrvRndBitMask; // remove complexity factor flags.
       
   217         
       
   218         StartObserving();
       
   219         }
       
   220     
       
   221     return result;
       
   222     }
       
   223     
       
   224 // ---------------------------------------------------------------------------
       
   225 // From class CActive 
       
   226 // Active object RunL
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CAlfSrvSettingsHandler::RunL()
       
   230     {
       
   231     TInt newValue = KAlfSrvDefaultComplexityFactor;
       
   232     TAlfSrvSetting settingChanged = EAlfSrvSettingEffectsComplexityFactor;
       
   233     
       
   234     // iStatus should hold the information about the changed key. Get the new value.    
       
   235     switch ( iStatus.Int() )
       
   236         {
       
   237         case KUIAccelTKRenderer: // flow through
       
   238         case KUIAccelTKHWConfigurationFlags:
       
   239             // do not do anything
       
   240             return;
       
   241             
       
   242         case KUIAccelTKDefaultFrameRate:
       
   243             settingChanged = EAlfSrvSettingDefaultFramerate;
       
   244     		User::LeaveIfError( iCentralRepository->Get( iStatus.Int(), newValue ) );
       
   245             break;
       
   246         case KUIAccelTKMaxCpuUsage:
       
   247             settingChanged = EAlfSrvSettingMaxCpuUsage;
       
   248     		User::LeaveIfError( iCentralRepository->Get( iStatus.Int(), newValue ) );
       
   249     		iMaxCpuUsage = (TUint)newValue;
       
   250             break;
       
   251         case KUIAccelTKMaxResourceCache:
       
   252             settingChanged = EAlfSrvSettingMaxResourceCacheSize;
       
   253     		User::LeaveIfError( iCentralRepository->Get( iStatus.Int(), newValue ) );
       
   254             break;
       
   255         case KUIAccelTKEffectsComplexityFactor:
       
   256             settingChanged = EAlfSrvSettingEffectsComplexityFactor;
       
   257     		// get the new value    
       
   258     		User::LeaveIfError( iCentralRepository->Get( iStatus.Int(), newValue ) );
       
   259             newValue = newValue&KAlfSrvRndBitMask; // remove Rnd flags
       
   260             break;
       
   261         
       
   262         default:
       
   263             // Error?
       
   264             User::LeaveIfError( iStatus.Int() );
       
   265             return; 
       
   266         }
       
   267             
       
   268     StartObserving();
       
   269     iObserver.MAlfSrvUintSettingChangedL( settingChanged, newValue );
       
   270     }
       
   271 
       
   272     
       
   273 void CAlfSrvSettingsHandler::DoCancel()
       
   274     {
       
   275     iCentralRepository->NotifyCancelAll();
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // From class CActive 
       
   280 // Error handler for RunL
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 TInt CAlfSrvSettingsHandler::RunError(TInt aError)
       
   284     {
       
   285     return aError;    
       
   286     }