uiacceltk/hitchcock/goommonitor/src/goomconfigparser.cpp
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008 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:  The parser for the Graphics OOM configuration file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <xml/parser.h>
       
    21 
       
    22 #include "goomconfigparser.h"
       
    23 #include "goompanic.h"
       
    24 #include "goomtraces.h"
       
    25 #include "goomidletimerule.h"
       
    26 #include "goomforegroundrule.h"
       
    27 #include "goomconstants.hrh"
       
    28 #include "goomapplicationconfig.h"
       
    29 #include "goomcloseappconfig.h"
       
    30 #include "goomconfig.h"
       
    31 #include "goomrunpluginconfig.h"
       
    32 
       
    33 enum
       
    34 {
       
    35 KGOomErrMoreThanOneGOomConfig = 0,
       
    36 KGOomErrGlobalSettingsMustComeAfterRoot,
       
    37 KGOomErrAppSettingsMustComeAfterGlobalSettings,
       
    38 KGOomErrCloseAppSettingsMustComeAfterAppSettings,
       
    39 KGOomErrAppIdleSettingsMustComeAfterAppCloseSettings,
       
    40 KGOomErrLowRamErrorInGlobalSettings,
       
    41 KGOomErrGoodRamErrorInGlobalSettings,
       
    42 KGOomErrMaxCloseErrorInGlobalSettings,
       
    43 KGOomErrDefaultPriorityErrorInGlobalSettings,
       
    44 KGOomErrMissingUidFromAppCloseConfig,
       
    45 KGOomErrMissingPriorityFromAppCloseConfig,
       
    46 KGOomErrMissingSyncModeFromAppCloseConfig,
       
    47 KGOomErrMissingEstimateFromAppCloseConfig,
       
    48 KGOomErrInvalidSyncMode,
       
    49 KGOomErrMissingSyncModeInAppCloseConfig,
       
    50 KGOomErrBadOrMissingPriorityInAppIdleRule,
       
    51 KGOomErrBadOrMissingIdleTimeInAppIdleRule,
       
    52 KGOomErrBadOrMissingUidInAppIdleRule,
       
    53 KGOomErrBadNeverCloseValue,
       
    54 KGOomErrBadOrMissingUidInAppConfig,
       
    55 KGOomErrBadOrMissingPriorityInAppCloseConfig,
       
    56 KGOomErrBadLowThresholdValueForAppConfig,
       
    57 KGOomErrBadGoodThresholdValueForAppConfig,
       
    58 KGOomErrBadTargetFreeValueForAppConfig,
       
    59 KGOomErrSystemPluginSettingsMustComeAfterAppCloseSettings,
       
    60 KGOomErrAppPluginSettingsMustComeAfterSystemPluginSettings,
       
    61 KGOomErrAppPluginIdleTimeRulesMustComeAfterAppPluginSettings,
       
    62 KGOomErrBadOrMissingUidInAppCloseConfig,
       
    63 KGOomErrBadOrMissingUidInSystemPluginConfig,
       
    64 KGOomErrBadOrMissingPriorityInSystemPluginConfig,
       
    65 KGOomErrBadOrMissingTargetAppIdInAppPluginConfig,
       
    66 KGOomErrBadOrMissingUidInAppPluginConfig,
       
    67 KGOomErrBadOrMissingPriorityInAppPluginConfig,
       
    68 KGOomErrBadOrMissingPriorityInPluginIdleRule,
       
    69 KGOomErrBadOrMissingIdleTimeInPluginIdleRule,
       
    70 KGOomErrBadOrMissingUidInPluginIdleRule,
       
    71 KGOomErrBadOrMissingUidInForegroundAppRule,
       
    72 KGOomErrBadOrMissingPriorityInForegroundAppRule,
       
    73 KGOomErrBadOrMissingTargetAppIdInForegroundAppRule,
       
    74 KGOomErrDefaultWaitAfterPluginInGlobalSettings,
       
    75 KGOomErrBadOrMissingPriorityInForceCheck,
       
    76 KGOomErrGOomRulesMustComeLast,
       
    77 KGOomErrBadPluginWaitTime,
       
    78 KGOomErrBadXml,
       
    79 KGOomErrAppCloseIdleRuleOutsideAppCloseElement,
       
    80 KGOomErrForegroundAppRuleOutsideAppCloseElement,
       
    81 KGOomErrPluginIdleRuleOutsideAppPluginElement,
       
    82 KGOomErrPluginForegroundRuleOutsidePluginElement
       
    83 };
       
    84 
       
    85 
       
    86 const TInt KGOomXmlFileBufferSize = 1024;
       
    87 
       
    88 using namespace Xml;
       
    89 
       
    90 // Mime type of the parsed document
       
    91 _LIT8(KXmlMimeType, "text/xml");
       
    92 
       
    93 _LIT(KGOomConfigFilePath, ":\\private\\10207218\\goomconfig.xml");
       
    94 _LIT(KRomDrive, "z");
       
    95 
       
    96 // Element strings
       
    97 // Root
       
    98 _LIT8(KGOomConfigGOomConfig, "goom_config");
       
    99 
       
   100 // Global settings
       
   101 _LIT8(KGOomConfigGlobalSettings, "global_settings");
       
   102 _LIT8(KGOomConfigForceCheckAtPriority, "force_check");
       
   103 
       
   104 // App settings
       
   105 _LIT8(KGOomConfigAppSettings, "app_specific_thresholds");
       
   106 _LIT8(KGOomConfigApp, "app");
       
   107 
       
   108 // App close settings
       
   109 _LIT8(KGOomConfigAppCloseSettings, "app_close_settings");
       
   110 _LIT8(KGOomConfigCloseApp, "close_app");
       
   111 
       
   112 // App close idle time
       
   113 _LIT8(KGOomConfigAppCloseIdlePriority, "app_close_idle_priority");
       
   114 
       
   115 _LIT8(KGOomConfigForegroundAppPriority, "foreground_app_priority");
       
   116 
       
   117 // Global settings attribute names
       
   118 _LIT8(KGOomAttributeLowRamThreshold, "low_ram_threshold");
       
   119 _LIT8(KGOomAttributeGoodRamThreshold, "good_ram_threshold");
       
   120 _LIT8(KGOomAttributeMaxAppCloseBatch, "max_app_close_batch");
       
   121 _LIT8(KGOomAttributeDefaultWaitAfterPlugin, "default_wait_after_plugin");
       
   122 
       
   123 //App specific
       
   124 _LIT8(KGOomAttributeTargetFreeOnStartup, "target_free_on_startup");
       
   125 
       
   126 // System plugins 
       
   127 
       
   128 _LIT8(KGOomAttributeSystemPluginSettings, "system_plugin_settings");
       
   129 _LIT8(KGOomAttributeSystemPlugin, "system_plugin");
       
   130 
       
   131 // Application plugins
       
   132 
       
   133 _LIT8(KGOomAttributeAppPluginSettings, "app_plugin_settings");
       
   134 _LIT8(KGOomAttributeAppPlugin, "app_plugin");
       
   135 
       
   136 // Plugin idle time rules
       
   137 
       
   138 _LIT8(KGOomAttributePluginIdlePriority, "plugin_idle_priority");
       
   139 
       
   140 // Plugin foreground app rules
       
   141 _LIT8(KGOomAttributePluginForegroundAppPriority, "plugin_foreground_app_priority");
       
   142 
       
   143 // Atribute names
       
   144 _LIT8(KGOomAttibuteUid, "uid");
       
   145 _LIT8(KGOomAttibuteSyncMode, "sync_mode");
       
   146 _LIT8(KGOomAttibutePriority, "priority");
       
   147 _LIT8(KGOomAttibuteRamEstimate, "ram_estimate");
       
   148 
       
   149 _LIT8(KGOomConfigSyncModeContinue, "continue");
       
   150 _LIT8(KGOomConfigSyncModeCheck, "check");
       
   151 _LIT8(KGOomConfigSyncModeEstimate, "estimate");
       
   152 
       
   153 _LIT8(KGOomAttibuteIdleTime, "idle_time");
       
   154 _LIT8(KGOomAttibuteIdlePriority, "priority");
       
   155 
       
   156 _LIT8(KGOomAttibuteNeverClose, "NEVER_CLOSE");
       
   157 
       
   158 _LIT8(KGOomAttributeTargetAppId, "target_app_id");
       
   159 
       
   160 _LIT8(KGOomAttributeWait, "wait");
       
   161 
       
   162 _LIT8(KGOomAttributeIfForegroundAppId, "if_foreground_app_id");
       
   163 
       
   164 _LIT8(KGOomConfigDefaultAppUid, "DEFAULT_APP");
       
   165 _LIT8(KGOomConfigDefaultPluginUid, "DEFAULT_PLUGIN");
       
   166 _LIT8(KGOomConfigTargetAppValue, "TARGET_APP");
       
   167 
       
   168 _LIT8(KGOomConfigBusyAppUid, "BUSY_APP");
       
   169 _LIT8(KGOomConfigHighPriorityAppUid, "HIGH_PRIORITY_APP");
       
   170 
       
   171 CGOomConfigParser::CGOomConfigParser(CGOomConfig& aConfig, RFs& aFs) : iConfig(aConfig), iFs(aFs), iState(EGOomParsingStateNone)
       
   172     {
       
   173     }
       
   174 
       
   175 void CGOomConfigParser::ParseL()
       
   176     {
       
   177     FUNC_LOG;
       
   178 
       
   179     TRACES("CGOomConfigParser::ParseL: Parsing Config File");
       
   180     
       
   181     CParser* parser = CParser::NewLC(KXmlMimeType, *this);
       
   182     
       
   183     RFile configFile;
       
   184     TFileName configFileName;
       
   185     TChar driveChar = iFs.GetSystemDriveChar();
       
   186     configFileName.Append(driveChar);
       
   187     configFileName.Append(KGOomConfigFilePath);
       
   188     if (configFile.Open(iFs, configFileName, EFileShareExclusive) != KErrNone)
       
   189         {
       
   190         configFileName.Replace(0,1,KRomDrive); //replace 'c' with 'z'
       
   191         User::LeaveIfError(configFile.Open(iFs, configFileName, EFileShareExclusive));
       
   192         }
       
   193     CleanupClosePushL(configFile);
       
   194     
       
   195     TBuf8<KGOomXmlFileBufferSize> fileBuffer;
       
   196     TInt bytesRead;
       
   197     do
       
   198         {
       
   199         User::LeaveIfError(configFile.Read(fileBuffer));
       
   200         bytesRead = fileBuffer.Size();
       
   201         
       
   202         parser->ParseL(fileBuffer);
       
   203         
       
   204         } while (bytesRead != 0);
       
   205     
       
   206     CleanupStack::PopAndDestroy(2, parser); // config file - automatically closes it
       
   207                                             // parser
       
   208             
       
   209     TRACES("CGOomConfigParser::ParseL: Finished Parsing Config File");    
       
   210     }
       
   211 
       
   212 void CGOomConfigParser::OnStartDocumentL(const RDocumentParameters&, TInt)
       
   213     {
       
   214     FUNC_LOG;
       
   215     }
       
   216 
       
   217 void CGOomConfigParser::OnEndDocumentL(TInt)
       
   218     {
       
   219     FUNC_LOG;
       
   220     }
       
   221 
       
   222 
       
   223 void CGOomConfigParser::OnEndElementL(const RTagInfo&, TInt)
       
   224     {
       
   225     }
       
   226 
       
   227 void CGOomConfigParser::OnContentL(const TDesC8&, TInt)
       
   228     {
       
   229     }
       
   230 
       
   231 void CGOomConfigParser::OnStartPrefixMappingL(const RString&, const RString&, 
       
   232                                    TInt)
       
   233     {
       
   234     }
       
   235 
       
   236 void CGOomConfigParser::OnEndPrefixMappingL(const RString&, TInt)
       
   237     {
       
   238     }
       
   239 
       
   240 void CGOomConfigParser::OnIgnorableWhiteSpaceL(const TDesC8&, TInt)
       
   241     {
       
   242     }
       
   243 
       
   244 void CGOomConfigParser::OnSkippedEntityL(const RString&, TInt)
       
   245     {
       
   246     }
       
   247 
       
   248 void CGOomConfigParser::OnProcessingInstructionL(const TDesC8&, const TDesC8&, 
       
   249                                       TInt)
       
   250     {
       
   251     }
       
   252 
       
   253 void CGOomConfigParser::OnError(TInt)
       
   254     {
       
   255     }
       
   256 
       
   257 TAny* CGOomConfigParser::GetExtendedInterface(const TInt32)
       
   258     {
       
   259     return 0;
       
   260     }
       
   261 
       
   262 void CGOomConfigParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, 
       
   263                              TInt aErrorCode)
       
   264     {
       
   265     if (aErrorCode != KErrNone)
       
   266         ConfigError(KGOomErrBadXml);
       
   267     
       
   268     StartElementL(aElement.LocalName().DesC(), aAttributes);
       
   269     }
       
   270 
       
   271 TInt CGOomConfigParser::StartElementL(const TDesC8& aLocalName,
       
   272                                         const RAttributeArray& aAttributes)
       
   273     {
       
   274     // Root
       
   275     if (aLocalName == KGOomConfigGOomConfig)
       
   276         {
       
   277         if (iState != EGOomParsingStateNone)
       
   278             ConfigError(KGOomErrMoreThanOneGOomConfig);
       
   279         
       
   280         ChangeState(EGOomParsingStateRoot);
       
   281         }
       
   282     // Parse main elements
       
   283     else if (aLocalName == KGOomConfigGlobalSettings)
       
   284         {
       
   285         if (iState != EGOomParsingStateRoot)
       
   286             ConfigError(KGOomErrGlobalSettingsMustComeAfterRoot);
       
   287         
       
   288         SetGlobalSettings(aAttributes);
       
   289         
       
   290         ChangeState(EGOomParsingStateGlobalSettings);
       
   291         }
       
   292     else if (aLocalName == KGOomConfigAppSettings)
       
   293         {
       
   294         ChangeState(EGOomParsingStateAppSettings);
       
   295         }
       
   296     else if (aLocalName == KGOomConfigAppCloseSettings)
       
   297         {
       
   298         ChangeState(EGOomParsingStateAppCloseSettings);
       
   299         }
       
   300     else if (aLocalName == KGOomAttributeSystemPluginSettings)
       
   301         {
       
   302         ChangeState(EGOomParsingStateSystemPluginSettings);
       
   303         }
       
   304     else if (aLocalName == KGOomAttributeAppPluginSettings)
       
   305         {
       
   306         ChangeState(EGOomParsingStateAppPluginSettings);
       
   307         }
       
   308     // Parse actual configuration elements
       
   309     else if (aLocalName == KGOomConfigForceCheckAtPriority)
       
   310         {
       
   311         SetForceCheckConfigL(aAttributes);
       
   312         }
       
   313     else if (aLocalName == KGOomConfigApp)
       
   314         {
       
   315         SetAppConfigL(aAttributes);
       
   316         }
       
   317     else if (aLocalName == KGOomConfigCloseApp)
       
   318         {
       
   319         SetCloseAppConfigL(aAttributes);
       
   320         }
       
   321     else if (aLocalName == KGOomConfigAppCloseIdlePriority)
       
   322         {
       
   323         CheckState(EGOomParsingStateAppCloseSettings, KGOomErrAppCloseIdleRuleOutsideAppCloseElement);
       
   324         SetAppCloseIdlePriorityConfigL(aAttributes);
       
   325         }
       
   326     else if (aLocalName == KGOomConfigForegroundAppPriority)
       
   327         {
       
   328         CheckState(EGOomParsingStateAppCloseSettings, KGOomErrForegroundAppRuleOutsideAppCloseElement);
       
   329         SetForegroundAppPriorityL(aAttributes);
       
   330         }
       
   331     else if (aLocalName == KGOomAttributeSystemPlugin)
       
   332         {
       
   333         SetSystemPluginConfigL(aAttributes);
       
   334         }
       
   335     else if (aLocalName == KGOomAttributeAppPlugin)
       
   336         {
       
   337         SetAppPluginConfigL(aAttributes);
       
   338         }
       
   339     else if (aLocalName == KGOomAttributePluginIdlePriority)
       
   340         {
       
   341         CheckState(EGOomParsingStateAppPluginSettings, KGOomErrPluginIdleRuleOutsideAppPluginElement);
       
   342         SetPluginIdlePriorityL(aAttributes);
       
   343         }
       
   344     else if (aLocalName == KGOomAttributePluginForegroundAppPriority)
       
   345         {
       
   346         CheckState(EGOomParsingStateAppPluginSettings, EGOomParsingStateSystemPluginSettings, KGOomErrPluginForegroundRuleOutsidePluginElement);
       
   347         SetPluginForegroundAppPriorityL(aAttributes);
       
   348         }
       
   349     
       
   350     return KErrNone;
       
   351     }
       
   352 
       
   353 void CGOomConfigParser::ConfigError(TInt aError)
       
   354     {
       
   355     GOomConfigParserPanic(aError);
       
   356     }
       
   357 
       
   358 void CGOomConfigParser::SetGlobalSettings(const RAttributeArray& aAttributes)
       
   359     {
       
   360     TInt defaultLowMemoryThreshold;    
       
   361     TInt err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttributeLowRamThreshold, defaultLowMemoryThreshold);
       
   362 
       
   363     if (err == KErrNone)
       
   364         iConfig.SetDefaultLowRamThreshold(defaultLowMemoryThreshold * 1024);
       
   365     else
       
   366         ConfigError(KGOomErrLowRamErrorInGlobalSettings);
       
   367     
       
   368     if (err == KErrNone)
       
   369         {
       
   370         TInt defaultGoodMemoryThreshold;    
       
   371         TInt err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttributeGoodRamThreshold, defaultGoodMemoryThreshold);
       
   372 
       
   373         if (err == KErrNone)
       
   374             iConfig.SetDefaultGoodRamThreshold(defaultGoodMemoryThreshold * 1024);
       
   375         else
       
   376             ConfigError(KGOomErrGoodRamErrorInGlobalSettings);
       
   377         }
       
   378 
       
   379     if (err == KErrNone)
       
   380         {
       
   381         TInt defaultMaxCloseAppBatch;    
       
   382         TInt err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttributeMaxAppCloseBatch, defaultMaxCloseAppBatch);
       
   383 
       
   384         if (err == KErrNone)
       
   385             iConfig.SetMaxCloseAppBatch(defaultMaxCloseAppBatch);
       
   386         else
       
   387             ConfigError(KGOomErrMaxCloseErrorInGlobalSettings);
       
   388         }
       
   389     
       
   390     if (err == KErrNone)
       
   391         {
       
   392         TInt defaultWaitAfterPlugin;    
       
   393         TInt err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttributeDefaultWaitAfterPlugin, defaultWaitAfterPlugin);
       
   394 
       
   395         if (err == KErrNone)
       
   396             iConfig.SetDefaultWaitAfterPlugin(defaultWaitAfterPlugin);
       
   397         else
       
   398             ConfigError(KGOomErrDefaultWaitAfterPluginInGlobalSettings);
       
   399         }
       
   400     }
       
   401 
       
   402 void CGOomConfigParser::SetForceCheckConfigL(const RAttributeArray& aAttributes)
       
   403     {
       
   404     TUint priority;
       
   405     TInt err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibutePriority, priority);
       
   406     if (err == KErrNone)
       
   407         {
       
   408         iConfig.GlobalConfig().AddForceCheckPriorityL(priority);
       
   409         }
       
   410     else
       
   411         {
       
   412         ConfigError(KGOomErrBadOrMissingPriorityInForceCheck);    
       
   413         }
       
   414     }
       
   415 
       
   416 void CGOomConfigParser::SetAppConfigL(const RAttributeArray& aAttributes)
       
   417     {
       
   418     TUint uid;
       
   419     CGOomApplicationConfig* appConfig = NULL;
       
   420     
       
   421     TInt err = GetValueFromHexAttributeList(aAttributes, KGOomAttibuteUid, uid);
       
   422     
       
   423     if (err != KErrNone)
       
   424         {
       
   425         ConfigError(KGOomErrBadOrMissingUidInAppConfig);
       
   426         }
       
   427     else
       
   428         iParentUid = uid;
       
   429 
       
   430     appConfig = CGOomApplicationConfig::NewL(uid);
       
   431     CleanupStack::PushL(appConfig);    
       
   432         
       
   433     // Set the app specific memory thresholds (if they exist)
       
   434     // Get the app specific low threshold
       
   435     if (err == KErrNone)
       
   436         {
       
   437         TUint lowThreshold;
       
   438         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttributeLowRamThreshold, lowThreshold);
       
   439         if (err == KErrNone)
       
   440             {
       
   441             appConfig->iLowRamThreshold = lowThreshold * 1024; // The config files work in K, so we need to multiply by 1024
       
   442             }
       
   443         else if (err == KErrNotFound)
       
   444             err = KErrNone;
       
   445         
       
   446         if (err != KErrNone)
       
   447             ConfigError(KGOomErrBadLowThresholdValueForAppConfig);
       
   448         }
       
   449 
       
   450     // Get the app specific good threshold
       
   451     if (err == KErrNone)
       
   452         {
       
   453         TUint goodThreshold;
       
   454         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttributeGoodRamThreshold, goodThreshold);
       
   455         if (err == KErrNone)
       
   456             {
       
   457             appConfig->iGoodRamThreshold = goodThreshold * 1024; // The config files work in K, so we need to multiply by 1024
       
   458             }
       
   459         else if (err == KErrNotFound)
       
   460             err = KErrNone;
       
   461         
       
   462         if (err != KErrNone)
       
   463             ConfigError(KGOomErrBadGoodThresholdValueForAppConfig);
       
   464         }
       
   465     
       
   466     // Get the app specific TargetFreeOnStartup
       
   467         if (err == KErrNone)
       
   468             {
       
   469             TUint targetFree;
       
   470             err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttributeTargetFreeOnStartup, targetFree);
       
   471             if (err == KErrNone)
       
   472                 {
       
   473                 appConfig->iTargetFree = targetFree * 1024; // The config files work in K, so we need to multiply by 1024
       
   474                 }
       
   475             else if (err == KErrNotFound)
       
   476                 err = KErrNone;
       
   477             
       
   478             if (err != KErrNone)
       
   479                 ConfigError(KGOomErrBadTargetFreeValueForAppConfig);
       
   480             }
       
   481     
       
   482     // Add the applciation config to the main config
       
   483     if ((err == KErrNone) && (appConfig))
       
   484         {
       
   485         iConfig.AddApplicationConfigL(appConfig);
       
   486         }
       
   487     
       
   488     if (appConfig)
       
   489         CleanupStack::Pop(appConfig);
       
   490     }
       
   491 
       
   492 void CGOomConfigParser::SetCloseAppConfigL(const RAttributeArray& aAttributes)
       
   493     {
       
   494     // Get and convert uid attribute to TInt
       
   495     TInt err = KErrNone;
       
   496     
       
   497     TUint uid;
       
   498     err = GetValueFromHexAttributeList(aAttributes, KGOomAttibuteUid, uid);
       
   499 
       
   500     if (err != KErrNone)
       
   501         {
       
   502         ConfigError(KGOomErrBadOrMissingUidInAppCloseConfig);    
       
   503         return;
       
   504         }
       
   505     else
       
   506         iParentUid = uid;
       
   507     
       
   508     CGOomCloseAppConfig* closeAppConfig = CGOomCloseAppConfig::NewL(uid); // Radio UID
       
   509     CleanupStack::PushL(closeAppConfig);
       
   510 
       
   511      if (err == KErrNone)
       
   512         {
       
   513         // Check that we have a priority for the added app_close event
       
   514         // Specifying a priority is mandatory
       
   515         TUint priority;
       
   516         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibutePriority, priority);
       
   517         if (err == KErrNone)
       
   518             {
       
   519             closeAppConfig->SetDefaultPriority(priority);
       
   520             }
       
   521         else
       
   522             {
       
   523             ConfigError(KGOomErrBadOrMissingPriorityInAppCloseConfig);    
       
   524             }
       
   525         }
       
   526     
       
   527     if (err == KErrNone)
       
   528         {
       
   529         TPtrC8 syncModeString;
       
   530         err = GetValueFromAttributeList(aAttributes, KGOomAttibuteSyncMode, syncModeString);
       
   531         
       
   532         if (err == KErrNone)
       
   533             {
       
   534             TGOomSyncMode syncMode = EContinue;
       
   535             
       
   536             if (syncModeString == KGOomConfigSyncModeContinue)
       
   537                 syncMode = EContinue;
       
   538             else if (syncModeString == KGOomConfigSyncModeCheck)
       
   539                 syncMode = ECheckRam;
       
   540             else if (syncModeString == KGOomConfigSyncModeEstimate)
       
   541                 syncMode = EEstimate;
       
   542             else
       
   543                 ConfigError(KGOomErrInvalidSyncMode);
       
   544             
       
   545             if (err == KErrNone)
       
   546                 {
       
   547                 closeAppConfig->iSyncMode = syncMode;
       
   548                 }
       
   549             }
       
   550         else
       
   551             {
       
   552             ConfigError(KGOomErrMissingSyncModeInAppCloseConfig);
       
   553             }
       
   554         }
       
   555     
       
   556     
       
   557     if (err == KErrNone)
       
   558         {
       
   559         // If we have a default priority attribute then add it, otherwise use the global default priority
       
   560         TInt ramEstimate;
       
   561         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibuteRamEstimate, ramEstimate);
       
   562         if ((err == KErrNotFound) && (closeAppConfig->iSyncMode != EEstimate))
       
   563             {
       
   564             err = KErrNone;
       
   565             }
       
   566         
       
   567         if (err != KErrNone)
       
   568             ConfigError(KGOomErrMissingEstimateFromAppCloseConfig);
       
   569         else
       
   570             closeAppConfig->iRamEstimate = ramEstimate * 1024;
       
   571            }
       
   572 
       
   573     if (err == KErrNone)
       
   574         iConfig.SetAppCloseConfigL(closeAppConfig);
       
   575     
       
   576     CleanupStack::Pop(closeAppConfig);
       
   577     }
       
   578 
       
   579 void CGOomConfigParser::SetAppCloseIdlePriorityConfigL(const RAttributeArray& aAttributes)
       
   580     {
       
   581     TUint uid;
       
   582     TInt idleTime;
       
   583     TUint priority;
       
   584 
       
   585     // Use the UID from the parent scope
       
   586     uid = iParentUid;
       
   587 
       
   588     TInt err = KErrNone;
       
   589     
       
   590     err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibuteIdleTime, idleTime);
       
   591     
       
   592 #ifdef __WINS__
       
   593     // The tick is 5 times slower on the emulator than on the phone
       
   594     idleTime = idleTime / 5;
       
   595 #endif
       
   596     
       
   597     if (err != KErrNone)
       
   598         {
       
   599         ConfigError(KGOomErrBadOrMissingIdleTimeInAppIdleRule);
       
   600         }
       
   601     
       
   602     if (err == KErrNone)
       
   603         {
       
   604         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibuteIdlePriority, priority);
       
   605         
       
   606         if (err != KErrNone)
       
   607             {
       
   608             ConfigError(KGOomErrBadOrMissingPriorityInAppIdleRule);
       
   609             }
       
   610         }
       
   611     
       
   612     if (err == KErrNone)
       
   613         {
       
   614         CGOomIdleTimeRule* idleRule = CGOomIdleTimeRule::NewL(idleTime, priority);
       
   615         CleanupStack::PushL(idleRule);
       
   616         iConfig.AddApplicationRuleL(uid, idleRule);
       
   617         CleanupStack::Pop(idleRule);
       
   618         }
       
   619     }
       
   620 
       
   621 void CGOomConfigParser::SetForegroundAppPriorityL(const RAttributeArray& aAttributes)
       
   622     {
       
   623     TUint appUid;
       
   624     TUint targetAppId;
       
   625     TUint priority;
       
   626 
       
   627     TInt err = KErrNone;
       
   628     
       
   629     // Use the UID from the parent scope
       
   630     appUid = iParentUid;
       
   631 
       
   632     // Check that we have a priority for the added system plugin action
       
   633     // Specifying a priority is mandatory
       
   634     err = GetValueFromHexAttributeList(aAttributes, KGOomAttributeIfForegroundAppId, targetAppId);
       
   635     if (err != KErrNone)
       
   636         {
       
   637         ConfigError(KGOomErrBadOrMissingTargetAppIdInForegroundAppRule);    
       
   638         }
       
   639     
       
   640     if (err == KErrNone)
       
   641         {
       
   642         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibuteIdlePriority, priority);
       
   643         
       
   644         if (err != KErrNone)
       
   645             {
       
   646             ConfigError(KGOomErrBadOrMissingPriorityInForegroundAppRule);
       
   647             }
       
   648         }
       
   649     
       
   650     if (err == KErrNone)
       
   651         {
       
   652         CGOomForegroundRule* foregroundRule = new (ELeave) CGOomForegroundRule(targetAppId, priority);
       
   653         CleanupStack::PushL(foregroundRule);
       
   654         iConfig.AddApplicationRuleL(appUid, foregroundRule);
       
   655         CleanupStack::Pop(foregroundRule);
       
   656         }
       
   657 
       
   658     }
       
   659 
       
   660 void CGOomConfigParser::SetSystemPluginConfigL(const RAttributeArray& aAttributes)
       
   661     {
       
   662     // Get and convert uid attribute to TInt
       
   663     TInt err = KErrNone;
       
   664     
       
   665     TUint uid;
       
   666     err = GetValueFromHexAttributeList(aAttributes, KGOomAttibuteUid, uid);
       
   667 
       
   668     if (err != KErrNone)
       
   669         {
       
   670         ConfigError(KGOomErrBadOrMissingUidInSystemPluginConfig);    
       
   671         return;
       
   672         }
       
   673     else
       
   674         iParentUid = uid;
       
   675     
       
   676     CGOomRunPluginConfig* pluginConfig = CGOomRunPluginConfig::NewL(uid, EGOomSystemPlugin);
       
   677     CleanupStack::PushL(pluginConfig);
       
   678 
       
   679      if (err == KErrNone)
       
   680         {
       
   681         // Check that we have a priority for the added system plugin action
       
   682         // Specifying a priority is mandatory
       
   683         TUint priority;
       
   684         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibutePriority, priority);
       
   685         if (err == KErrNone)
       
   686             {
       
   687             pluginConfig->SetDefaultPriority(priority);
       
   688             }
       
   689         else
       
   690             {
       
   691             ConfigError(KGOomErrBadOrMissingPriorityInSystemPluginConfig);    
       
   692             }
       
   693         }
       
   694      
       
   695      if (err == KErrNone)
       
   696         {
       
   697         TInt wait;
       
   698         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttributeWait, wait);
       
   699         if (err == KErrNone)
       
   700             {
       
   701             pluginConfig->SetWaitAfterPlugin(wait);
       
   702             }
       
   703         else if (err == KErrNotFound)
       
   704             {
       
   705             // If this attribute isn't present then just don't set it, and clear the error
       
   706             err = KErrNone;
       
   707             }
       
   708         else
       
   709             ConfigError(KGOomErrBadPluginWaitTime);
       
   710         }
       
   711      
       
   712      if (err == KErrNone)
       
   713          {
       
   714          // Get the config for the sync mode for this plugin (if one is specified) and set it
       
   715          SetPluginSyncMode(aAttributes, *pluginConfig);
       
   716          }
       
   717 
       
   718      iConfig.AddPluginConfigL(pluginConfig);
       
   719      
       
   720      CleanupStack::Pop(pluginConfig);
       
   721     }
       
   722 
       
   723 void CGOomConfigParser::SetAppPluginConfigL(const RAttributeArray& aAttributes)
       
   724     {
       
   725     // Get and convert uid attribute to TInt
       
   726     TInt err = KErrNone;
       
   727     
       
   728     TUint uid;
       
   729     err = GetValueFromHexAttributeList(aAttributes, KGOomAttibuteUid, uid);
       
   730 
       
   731     if (err != KErrNone)
       
   732         {
       
   733         ConfigError(KGOomErrBadOrMissingUidInAppPluginConfig);    
       
   734         return;
       
   735         }
       
   736     else
       
   737         iParentUid = uid;
       
   738     
       
   739     CGOomRunPluginConfig* pluginConfig = CGOomRunPluginConfig::NewL(uid, EGOomAppPlugin);
       
   740     CleanupStack::PushL(pluginConfig);
       
   741 
       
   742     if (err == KErrNone)
       
   743        {
       
   744        // Check that we have a priority for the added system plugin action
       
   745        // Specifying a priority is mandatory
       
   746         TUint priority;
       
   747         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibutePriority, priority);
       
   748         if (err == KErrNone)
       
   749             {
       
   750             pluginConfig->SetDefaultPriority(priority);
       
   751             }
       
   752         else
       
   753             {
       
   754             ConfigError(KGOomErrBadOrMissingPriorityInAppPluginConfig);    
       
   755             }
       
   756        }
       
   757 
       
   758     if (err == KErrNone)
       
   759        {
       
   760        // Check that we have a priority for the added system plugin action
       
   761        // Specifying a priority is mandatory
       
   762         TUint targetAppId;
       
   763         err = GetValueFromHexAttributeList(aAttributes, KGOomAttributeTargetAppId, targetAppId);
       
   764         if (err == KErrNone)
       
   765             {
       
   766             pluginConfig->SetTargetApp(targetAppId);
       
   767             iParentTargetApp = targetAppId;
       
   768             }
       
   769         else
       
   770             {
       
   771             ConfigError(KGOomErrBadOrMissingTargetAppIdInAppPluginConfig);    
       
   772             }
       
   773        }
       
   774     
       
   775     if (err == KErrNone)
       
   776        {
       
   777        TInt wait;
       
   778         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttributeWait, wait);
       
   779         if (err == KErrNone)
       
   780             {
       
   781             pluginConfig->SetWaitAfterPlugin(wait);
       
   782             }
       
   783         else if (err == KErrNotFound)
       
   784             {
       
   785             // If this attribute isn't present then just don't set it, and clear the error
       
   786             err = KErrNone;
       
   787             }
       
   788         else
       
   789             ConfigError(KGOomErrBadPluginWaitTime);
       
   790        }    
       
   791     
       
   792     if (err == KErrNone)
       
   793         {
       
   794         // Get the config for the sync mode for this plugin (if one is specified) and set it
       
   795         SetPluginSyncMode(aAttributes, *pluginConfig);
       
   796         }
       
   797 
       
   798      iConfig.AddPluginConfigL(pluginConfig);
       
   799      
       
   800      CleanupStack::Pop(pluginConfig);
       
   801 
       
   802     }
       
   803 
       
   804 void CGOomConfigParser::SetPluginIdlePriorityL(const RAttributeArray& aAttributes)
       
   805     {
       
   806     TUint uid;
       
   807     TInt idleTime;
       
   808     TUint priority;
       
   809 
       
   810     TInt err = KErrNone;
       
   811     
       
   812     // Use the UID from the parent scope
       
   813     uid = iParentUid;
       
   814 
       
   815     err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibuteIdleTime, idleTime);
       
   816     
       
   817 #ifdef __WINS__
       
   818     // The tick is 5 times slower on the emulator than on the phone
       
   819     idleTime = idleTime / 5;
       
   820 #endif
       
   821     
       
   822     if (err != KErrNone)
       
   823         {
       
   824         ConfigError(KGOomErrBadOrMissingIdleTimeInPluginIdleRule);
       
   825         }
       
   826     
       
   827     if (err == KErrNone)
       
   828         {
       
   829         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibuteIdlePriority, priority);
       
   830         
       
   831         if (err != KErrNone)
       
   832             {
       
   833             ConfigError(KGOomErrBadOrMissingPriorityInPluginIdleRule);
       
   834             }
       
   835         }
       
   836     
       
   837     if (err == KErrNone)
       
   838         {
       
   839         CGOomIdleTimeRule* idleRule = CGOomIdleTimeRule::NewL(idleTime, priority);
       
   840         CleanupStack::PushL(idleRule);
       
   841         iConfig.AddPluginRuleL(uid, idleRule);
       
   842         CleanupStack::Pop(idleRule);
       
   843         }
       
   844     }
       
   845 
       
   846 void CGOomConfigParser::SetPluginForegroundAppPriorityL(const RAttributeArray& aAttributes)
       
   847     {
       
   848     TUint uid;
       
   849     TUint targetAppId;
       
   850     TUint priority;
       
   851 
       
   852     TInt err = KErrNone;
       
   853     
       
   854     // Use the UID from the parent scope
       
   855     uid = iParentUid;
       
   856 
       
   857         // Check that we have a priority for the added system plugin action
       
   858         // Specifying a priority is mandatory
       
   859         
       
   860     TPtrC8 targetAppString;
       
   861     err = GetValueFromAttributeList(aAttributes, KGOomAttributeTargetAppId, targetAppString);
       
   862     if ((err == KErrNone)
       
   863             && (targetAppString == KGOomConfigTargetAppValue)
       
   864             && (iState == EGOomParsingStateAppPluginSettings))
       
   865         // If the target app is specified as "TARGET_APP" then we use the target app from the parent entry
       
   866         {
       
   867         targetAppId = iParentTargetApp;
       
   868         }
       
   869     else
       
   870         {
       
   871         err = GetValueFromHexAttributeList(aAttributes, KGOomAttributeTargetAppId, targetAppId);
       
   872         if (err != KErrNone)
       
   873             {
       
   874             ConfigError(KGOomErrBadOrMissingTargetAppIdInForegroundAppRule);    
       
   875             }
       
   876         }
       
   877      
       
   878     if (err == KErrNone)
       
   879         {
       
   880         err = GetValueFromDecimalAttributeList(aAttributes, KGOomAttibuteIdlePriority, priority);
       
   881         
       
   882         if (err != KErrNone)
       
   883             {
       
   884             ConfigError(KGOomErrBadOrMissingPriorityInForegroundAppRule);
       
   885             }
       
   886         }
       
   887     
       
   888     if (err == KErrNone)
       
   889         {
       
   890         CGOomForegroundRule* foregroundRule = new (ELeave) CGOomForegroundRule(targetAppId, priority);
       
   891         CleanupStack::PushL(foregroundRule);
       
   892         iConfig.AddPluginRuleL(uid, foregroundRule);
       
   893         CleanupStack::Pop(foregroundRule);
       
   894         }
       
   895     }
       
   896 
       
   897 // Finds an attribute of the given name and gets its value
       
   898 // A value is only valid as long as AAtrributes is valid (and unmodified)
       
   899 // Returns KErrNone if the attribute is present in the list, KErrNotFound otherwise
       
   900 TInt CGOomConfigParser::GetValueFromAttributeList(const RAttributeArray& aAttributes, const TDesC8& aName, TPtrC8& aValue)
       
   901     {
       
   902     TInt index = aAttributes.Count();
       
   903     TBool attributeFound = EFalse;
       
   904     while ((index--) && (!attributeFound))
       
   905         {
       
   906         if (aAttributes[index].Attribute().LocalName().DesC() == aName)
       
   907             {
       
   908             attributeFound = ETrue;
       
   909             aValue.Set(aAttributes[index].Value().DesC());
       
   910             }
       
   911         }
       
   912     
       
   913     TInt err = KErrNone;
       
   914     
       
   915     if (!attributeFound)
       
   916         err = KErrNotFound;
       
   917     
       
   918     return err;
       
   919     }
       
   920 
       
   921 // Finds an attribute of the given name and gets its value (coverting the string hex value to a UInt)
       
   922 // Returns KErrNone if the attribute is present in the list, KErrNotFound otherwise
       
   923 // Returns KErrCorrupt if the string is not a valid hex number
       
   924 TInt CGOomConfigParser::GetValueFromHexAttributeList(const RAttributeArray& aAttributes, const TDesC8& aName, TUint& aValue)
       
   925     {
       
   926     TPtrC8 hexString;
       
   927     TInt err = GetValueFromAttributeList(aAttributes, aName, hexString);
       
   928 
       
   929     if (hexString == KGOomConfigDefaultAppUid)
       
   930         {
       
   931         // This is a special case
       
   932         // When we hit this value in a hex field then we return the default app UID
       
   933         aValue = KGOomDefaultAppId;
       
   934         }
       
   935     else if (hexString == KGOomConfigDefaultPluginUid)
       
   936         {
       
   937         // This is a special case
       
   938         // When we hit this value in a hex field then we return the default app UID
       
   939         aValue = KGOomDefaultPluginId;
       
   940         }
       
   941     else if (hexString == KGOomConfigBusyAppUid)
       
   942         {
       
   943         aValue = KGOomBusyAppId;
       
   944         }
       
   945     else if (hexString == KGOomConfigHighPriorityAppUid)
       
   946         {
       
   947         aValue = KGOomHighPriorityAppId;
       
   948         }
       
   949     else if (err == KErrNone)
       
   950         {
       
   951         TLex8 hexLex(hexString);
       
   952         err = hexLex.Val(aValue, EHex);
       
   953         if (err != KErrNone)
       
   954             err = KErrCorrupt;
       
   955         }
       
   956     
       
   957     return err;
       
   958     }
       
   959 
       
   960 // Finds an attribute of the given name and gets its value (coverting the string decimal value to a UInt)
       
   961 // Returns KErrNone if the attribute is present in the list, KErrNotFound otherwise
       
   962 // Returns KErrCorrupt if the string is not a valid decimal number
       
   963 TInt CGOomConfigParser::GetValueFromDecimalAttributeList(const RAttributeArray& aAttributes, const TDesC8& aName, TUint& aValue)
       
   964     {
       
   965     TPtrC8 decimalString;
       
   966     TInt err = GetValueFromAttributeList(aAttributes, aName, decimalString);
       
   967 
       
   968     if (err == KErrNone)
       
   969         {
       
   970         if (decimalString == KGOomAttibuteNeverClose)
       
   971             aValue = KGOomPriorityInfinate;
       
   972         else
       
   973             {
       
   974             TLex8 decimalLex(decimalString);
       
   975             err = decimalLex.Val(aValue, EDecimal);
       
   976             if (err != KErrNone)
       
   977                 err = KErrCorrupt;
       
   978             }
       
   979         }
       
   980     
       
   981     return err;
       
   982     }
       
   983 
       
   984 TInt CGOomConfigParser::GetValueFromDecimalAttributeList(const RAttributeArray& aAttributes, const TDesC8& aName, TInt& aValue)
       
   985     {
       
   986     TUint uintValue;
       
   987     TInt err = GetValueFromDecimalAttributeList(aAttributes, aName, uintValue);
       
   988     aValue = uintValue;
       
   989     return err;
       
   990     }
       
   991 
       
   992 void CGOomConfigParser::SetPluginSyncMode(const RAttributeArray& aAttributes, CGOomRunPluginConfig& aRunPluginConfig)
       
   993     {
       
   994     TPtrC8 syncModeString;
       
   995     TInt err = GetValueFromAttributeList(aAttributes, KGOomAttibuteSyncMode, syncModeString);
       
   996     
       
   997     if (err == KErrNone)
       
   998         // If there is no specified sync mode then leave it as the default
       
   999         {
       
  1000         TGOomSyncMode syncMode = EContinue;
       
  1001         
       
  1002         if (syncModeString == KGOomConfigSyncModeContinue)
       
  1003             syncMode = EContinueIgnoreMaxBatchSize;
       
  1004         else if (syncModeString == KGOomConfigSyncModeCheck)
       
  1005             syncMode = ECheckRam;
       
  1006         else if (syncModeString == KGOomConfigSyncModeEstimate)
       
  1007             syncMode = EEstimate;
       
  1008         else
       
  1009             ConfigError(KGOomErrInvalidSyncMode);
       
  1010         
       
  1011         if (err == KErrNone)
       
  1012             {
       
  1013             aRunPluginConfig.iSyncMode = syncMode;
       
  1014             }
       
  1015         }
       
  1016     }
       
  1017 
       
  1018 // Check that the current state is as expected
       
  1019 // If not then the specified config error is generated
       
  1020 void CGOomConfigParser::CheckState(TGOomParsingState aExpectedState, TInt aError)
       
  1021     {
       
  1022     if (iState != aExpectedState)
       
  1023         ConfigError(aError);
       
  1024     }
       
  1025 
       
  1026 // Check that the current state is as expected
       
  1027 // If not then the specified config error is generated
       
  1028 // This version checks to ensure that the current state matches either of the passed in states
       
  1029 void CGOomConfigParser::CheckState(TGOomParsingState aExpectedState1, TGOomParsingState aExpectedState2, TInt aError)
       
  1030     {
       
  1031     if ((iState != aExpectedState1)
       
  1032             && (iState != aExpectedState2))
       
  1033         ConfigError(aError);
       
  1034     }
       
  1035 
       
  1036 void CGOomConfigParser::ChangeState(TGOomParsingState aState)
       
  1037     {
       
  1038     iState = aState;
       
  1039     }