sysresmonitoring/oommonitor/src/oomconfigparser.cpp
changeset 35 13fd6fd25fe7
equal deleted inserted replaced
29:6a787171e1de 35:13fd6fd25fe7
       
     1 /*
       
     2 * Copyright (c) 2006-2010 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 OOM configuration file.
       
    15 *
       
    16 */
       
    17 #include <e32base.h>
       
    18 #include <xml/parser.h>
       
    19 
       
    20 #include "oomconfigparser.h"
       
    21 #include "oompanic.h"
       
    22 #include "OomTraces.h"
       
    23 #include "oomidletimerule.h"
       
    24 #include "oomforegroundrule.h"
       
    25 #include "oomconstants.hrh"
       
    26 #include "oomapplicationconfig.h"
       
    27 #include "oomcloseappconfig.h"
       
    28 #include "oomconfig.h"
       
    29 #include "oomrunpluginconfig.h"
       
    30 
       
    31 enum TOomConfigParserPanic
       
    32 {
       
    33 KOomErrMoreThanOneOomConfig = 0,
       
    34 KOomErrGlobalSettingsMustComeAfterRoot,
       
    35 KOomErrAppSettingsMustComeAfterGlobalSettings,
       
    36 KOomErrCloseAppSettingsMustComeAfterAppSettings,
       
    37 KOomErrAppIdleSettingsMustComeAfterAppCloseSettings,
       
    38 KOomErrLowRamErrorInGlobalSettings,
       
    39 KOomErrGoodRamErrorInGlobalSettings,
       
    40 KOomErrSwapUsageMonitoredErrorInGlobalSettings,
       
    41 KOomErrLowSwapErrorInGlobalSettings,
       
    42 KOomErrGoodSwapErrorInGlobalSettings,
       
    43 KOomErrMaxCloseErrorInGlobalSettings,
       
    44 KOomErrDefaultPriorityErrorInGlobalSettings,
       
    45 KOomErrMissingUidFromAppCloseConfig,
       
    46 KOomErrMissingPriorityFromAppCloseConfig,
       
    47 KOomErrMissingSyncModeFromAppCloseConfig,
       
    48 KOomErrMissingEstimateFromAppCloseConfig,
       
    49 KOomErrInvalidSyncMode,
       
    50 KOomErrMissingSyncModeInAppCloseConfig,
       
    51 KOomErrBadOrMissingPriorityInAppIdleRule,
       
    52 KOomErrBadOrMissingIdleTimeInAppIdleRule,
       
    53 KOomErrBadOrMissingUidInAppIdleRule,
       
    54 KOomErrBadNeverCloseValue,
       
    55 KOomErrBadOrMissingUidInAppConfig,
       
    56 KOomErrBadOrMissingPriorityInAppCloseConfig,
       
    57 KOomErrBadLowThresholdValueForAppConfig,
       
    58 KOomErrBadGoodThresholdValueForAppConfig,
       
    59 KOomErrSystemPluginSettingsMustComeAfterAppCloseSettings,
       
    60 KOomErrAppPluginSettingsMustComeAfterSystemPluginSettings,
       
    61 KOomErrAppPluginIdleTimeRulesMustComeAfterAppPluginSettings,
       
    62 KOomErrBadOrMissingUidInAppCloseConfig,
       
    63 KOomErrBadOrMissingUidInSystemPluginConfig,
       
    64 KOomErrBadOrMissingPriorityInSystemPluginConfig,
       
    65 KOomErrBadOrMissingTargetAppIdInAppPluginConfig,
       
    66 KOomErrBadOrMissingUidInAppPluginConfig,
       
    67 KOomErrBadOrMissingPriorityInAppPluginConfig,
       
    68 KOomErrBadOrMissingPriorityInPluginIdleRule,
       
    69 KOomErrBadOrMissingIdleTimeInPluginIdleRule,
       
    70 KOomErrBadOrMissingUidInPluginIdleRule,
       
    71 KOomErrBadOrMissingUidInForegroundAppRule,
       
    72 KOomErrBadOrMissingPriorityInForegroundAppRule,
       
    73 KOomErrBadOrMissingTargetAppIdInForegroundAppRule,
       
    74 KOomErrDefaultWaitAfterPluginInGlobalSettings,
       
    75 KOomErrBadOrMissingPriorityInForceCheck,
       
    76 KOomErrOomRulesMustComeLast,
       
    77 KOomErrBadPluginWaitTime,
       
    78 KOomErrBadXml,
       
    79 KOomErrAppCloseIdleRuleOutsideAppCloseElement,
       
    80 KOomErrForegroundAppRuleOutsideAppCloseElement,
       
    81 KOomErrPluginIdleRuleOutsideAppPluginElement,
       
    82 KOomErrPluginForegroundRuleOutsidePluginElement,
       
    83 KOomErrBadCallIfTargetAppNotRunning
       
    84 };
       
    85 
       
    86 const TInt KOomXmlFileBufferSize = 1024;
       
    87 const TInt KOomMaxAppExitTime = 2000;
       
    88 const TInt KBytesInMegabyte = 1024;
       
    89 #ifdef __WINS__
       
    90 const TInt KEmulatorTickDivisor = 5; // The tick is 5 times slower on the emulator than on the phone
       
    91 #endif
       
    92 using namespace Xml;
       
    93 
       
    94 // Mime type of the parsed document
       
    95 _LIT8(KXmlMimeType, "text/xml");
       
    96 
       
    97 _LIT(KOomConfigFilePath, ":\\private\\10207218\\oomconfig.xml");
       
    98 _LIT(KRomDrive, "z");
       
    99 
       
   100 // Element strings
       
   101 // Root
       
   102 _LIT8(KOomConfigOomConfig, "oom_config");
       
   103 
       
   104 // Global settings
       
   105 _LIT8(KOomConfigGlobalSettings, "global_settings");
       
   106 _LIT8(KOomConfigForceCheckAtPriority, "force_check");
       
   107 
       
   108 // App settings
       
   109 _LIT8(KOomConfigAppSettings, "app_specific_thresholds");
       
   110 _LIT8(KOomConfigApp, "app");
       
   111 
       
   112 // App close settings
       
   113 _LIT8(KOomConfigAppCloseSettings, "app_close_settings");
       
   114 _LIT8(KOomConfigCloseApp, "close_app");
       
   115 
       
   116 // App close idle time
       
   117 _LIT8(KOomConfigAppCloseIdlePriority, "app_close_idle_priority");
       
   118 
       
   119 _LIT8(KOomConfigForegroundAppPriority, "foreground_app_priority");
       
   120 
       
   121 // Global settings attribute names
       
   122 _LIT8(KOomAttributeLowRamThreshold, "low_ram_threshold");
       
   123 _LIT8(KOomAttributeGoodRamThreshold, "good_ram_threshold");
       
   124 _LIT8(KOomAttributeSwapUsageMonitored, "swap_usage_monitored");
       
   125 _LIT8(KOomAttributeLowSwapThreshold, "low_swap_threshold");
       
   126 _LIT8(KOomAttributeGoodSwapThreshold, "good_swap_threshold");
       
   127 _LIT8(KOomAttributeMaxAppCloseBatch, "max_app_close_batch");
       
   128 _LIT8(KOomAttributeDefaultWaitAfterPlugin, "default_wait_after_plugin");
       
   129 _LIT8(KOomAttributeMaxAppExitTime , "max_app_exit_time");
       
   130 
       
   131 // System plugins 
       
   132 
       
   133 _LIT8(KOomAttributeSystemPluginSettings, "system_plugin_settings");
       
   134 _LIT8(KOomAttributeSystemPlugin, "system_plugin");
       
   135 
       
   136 // Application plugins
       
   137 
       
   138 _LIT8(KOomAttributeAppPluginSettings, "app_plugin_settings");
       
   139 _LIT8(KOomAttributeAppPlugin, "app_plugin");
       
   140 
       
   141 // Plugin idle time rules
       
   142 
       
   143 _LIT8(KOomAttributePluginIdlePriority, "plugin_idle_priority");
       
   144 
       
   145 // Plugin foreground app rules
       
   146 _LIT8(KOomAttributePluginForegroundAppPriority, "plugin_foreground_app_priority");
       
   147 
       
   148 // Atribute names
       
   149 _LIT8(KOomAttibuteUid, "uid");
       
   150 _LIT8(KOomAttibuteSyncMode, "sync_mode");
       
   151 _LIT8(KOomAttibutePriority, "priority");
       
   152 _LIT8(KOomAttibuteRamEstimate, "ram_estimate");
       
   153 
       
   154 _LIT8(KOomConfigSyncModeContinue, "continue");
       
   155 _LIT8(KOomConfigSyncModeCheck, "check");
       
   156 _LIT8(KOomConfigSyncModeEstimate, "estimate");
       
   157 
       
   158 _LIT8(KOomAttibuteIdleTime, "idle_time");
       
   159 _LIT8(KOomAttibuteIdlePriority, "priority");
       
   160 
       
   161 _LIT8(KOomAttibuteNeverClose, "NEVER_CLOSE");
       
   162 
       
   163 _LIT8(KOomAttributeTargetAppId, "target_app_id");
       
   164 
       
   165 _LIT8(KOomAttributeWait, "wait");
       
   166 
       
   167 _LIT8(KOomAttributeIfForegroundAppId, "if_foreground_app_id");
       
   168 
       
   169 _LIT8(KOomAttributeCallIfTargetAppNotRunning, "call_if_target_app_not_running");
       
   170 _LIT8(KOomAttributeTrue, "true");
       
   171 _LIT8(KOomAttributeFalse, "false");
       
   172 _LIT8(KOomAttribute0, "0");
       
   173 _LIT8(KOomAttribute1, "1");
       
   174 
       
   175 
       
   176 _LIT8(KOomConfigDefaultAppUid, "DEFAULT_APP");
       
   177 _LIT8(KOomConfigDefaultPluginUid, "DEFAULT_PLUGIN");
       
   178 _LIT8(KOomConfigTargetAppValue, "TARGET_APP");
       
   179 
       
   180 _LIT8(KOomConfigBusyAppUid, "BUSY_APP");
       
   181 _LIT8(KOomConfigHighPriorityAppUid, "HIGH_PRIORITY_APP");
       
   182 
       
   183 COomConfigParser::COomConfigParser(COomConfig& aConfig, RFs& aFs) : iConfig(aConfig), iFs(aFs), iState(EOomParsingStateNone)
       
   184     {
       
   185     }
       
   186 
       
   187 void COomConfigParser::ParseL()
       
   188     {
       
   189     FUNC_LOG;
       
   190 
       
   191     TRACES("COomConfigParser::ParseL: Parsing Config File");
       
   192     
       
   193     CParser* parser = CParser::NewLC(KXmlMimeType, *this);
       
   194     
       
   195     RFile configFile;
       
   196     TFileName configFileName;
       
   197     TChar driveChar = iFs.GetSystemDriveChar();
       
   198     configFileName.Append(driveChar);
       
   199     configFileName.Append(KOomConfigFilePath);
       
   200     if (configFile.Open(iFs, configFileName, EFileShareExclusive) != KErrNone)
       
   201         {
       
   202         configFileName.Replace(0,1,KRomDrive); //replace 'c' with 'z'
       
   203         User::LeaveIfError(configFile.Open(iFs, configFileName, EFileShareExclusive));
       
   204         }
       
   205     CleanupClosePushL(configFile);
       
   206     
       
   207     TBuf8<KOomXmlFileBufferSize> fileBuffer;
       
   208     TInt bytesRead;
       
   209     do
       
   210         {
       
   211         User::LeaveIfError(configFile.Read(fileBuffer));
       
   212         bytesRead = fileBuffer.Size();
       
   213         
       
   214         parser->ParseL(fileBuffer);
       
   215         
       
   216         } while (bytesRead != 0);
       
   217     
       
   218     CleanupStack::PopAndDestroy(2, parser); // config file - automatically closes it
       
   219                                             // parser
       
   220             
       
   221     TRACES("COomConfigParser::ParseL: Finished Parsing Config File");    
       
   222     }
       
   223 
       
   224 void COomConfigParser::OnStartDocumentL(const RDocumentParameters&, TInt)
       
   225     {
       
   226     FUNC_LOG;
       
   227     }
       
   228 
       
   229 void COomConfigParser::OnEndDocumentL(TInt)
       
   230     {
       
   231     FUNC_LOG;
       
   232     }
       
   233 
       
   234 
       
   235 void COomConfigParser::OnEndElementL(const RTagInfo&, TInt)
       
   236     {
       
   237     }
       
   238 
       
   239 void COomConfigParser::OnContentL(const TDesC8&, TInt)
       
   240     {
       
   241     }
       
   242 
       
   243 void COomConfigParser::OnStartPrefixMappingL(const RString&, const RString&, 
       
   244                                    TInt)
       
   245     {
       
   246     }
       
   247 
       
   248 void COomConfigParser::OnEndPrefixMappingL(const RString&, TInt)
       
   249     {
       
   250     }
       
   251 
       
   252 void COomConfigParser::OnIgnorableWhiteSpaceL(const TDesC8&, TInt)
       
   253     {
       
   254     }
       
   255 
       
   256 void COomConfigParser::OnSkippedEntityL(const RString&, TInt)
       
   257     {
       
   258     }
       
   259 
       
   260 void COomConfigParser::OnProcessingInstructionL(const TDesC8&, const TDesC8&, 
       
   261                                       TInt)
       
   262     {
       
   263     }
       
   264 
       
   265 void COomConfigParser::OnError(TInt)
       
   266     {
       
   267     }
       
   268 
       
   269 TAny* COomConfigParser::GetExtendedInterface(const TInt32)
       
   270     {
       
   271     return 0;
       
   272     }
       
   273 
       
   274 void COomConfigParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, 
       
   275                              TInt aErrorCode)
       
   276     {
       
   277     if (aErrorCode != KErrNone)
       
   278         ConfigError(KOomErrBadXml);
       
   279     
       
   280     StartElementL(aElement.LocalName().DesC(), aAttributes);
       
   281     }
       
   282 
       
   283 void COomConfigParser::StartElementL(const TDesC8& aLocalName,
       
   284                                         const RAttributeArray& aAttributes)
       
   285     {
       
   286     // Root
       
   287     if (aLocalName == KOomConfigOomConfig)
       
   288         {
       
   289         if (iState != EOomParsingStateNone)
       
   290             ConfigError(KOomErrMoreThanOneOomConfig);
       
   291         
       
   292         ChangeState(EOomParsingStateRoot);
       
   293         }
       
   294     // Parse main elements
       
   295     else if (aLocalName == KOomConfigGlobalSettings)
       
   296         {
       
   297         if (iState != EOomParsingStateRoot)
       
   298             ConfigError(KOomErrGlobalSettingsMustComeAfterRoot);
       
   299         
       
   300         SetGlobalSettings(aAttributes);
       
   301         
       
   302         ChangeState(EOomParsingStateGlobalSettings);
       
   303         }
       
   304     else if (aLocalName == KOomConfigAppSettings)
       
   305         {
       
   306         ChangeState(EOomParsingStateAppSettings);
       
   307         }
       
   308     else if (aLocalName == KOomConfigAppCloseSettings)
       
   309         {
       
   310         ChangeState(EOomParsingStateAppCloseSettings);
       
   311         }
       
   312     else if (aLocalName == KOomAttributeSystemPluginSettings)
       
   313         {
       
   314         ChangeState(EOomParsingStateSystemPluginSettings);
       
   315         }
       
   316     else if (aLocalName == KOomAttributeAppPluginSettings)
       
   317         {
       
   318         ChangeState(EOomParsingStateAppPluginSettings);
       
   319         }
       
   320     // Parse actual configuration elements
       
   321     else if (aLocalName == KOomConfigForceCheckAtPriority)
       
   322         {
       
   323         SetForceCheckConfigL(aAttributes);
       
   324         }
       
   325     else if (aLocalName == KOomConfigApp)
       
   326         {
       
   327         SetAppConfigL(aAttributes);
       
   328         }
       
   329     else if (aLocalName == KOomConfigCloseApp)
       
   330         {
       
   331         SetCloseAppConfigL(aAttributes);
       
   332         }
       
   333     else if (aLocalName == KOomConfigAppCloseIdlePriority)
       
   334         {
       
   335         CheckState(EOomParsingStateAppCloseSettings, KOomErrAppCloseIdleRuleOutsideAppCloseElement);
       
   336         SetAppCloseIdlePriorityConfigL(aAttributes);
       
   337         }
       
   338     else if (aLocalName == KOomConfigForegroundAppPriority)
       
   339         {
       
   340         CheckState(EOomParsingStateAppCloseSettings, KOomErrForegroundAppRuleOutsideAppCloseElement);
       
   341         SetForegroundAppPriorityL(aAttributes);
       
   342         }
       
   343     else if (aLocalName == KOomAttributeSystemPlugin)
       
   344         {
       
   345         SetSystemPluginConfigL(aAttributes);
       
   346         }
       
   347     else if (aLocalName == KOomAttributeAppPlugin)
       
   348         {
       
   349         SetAppPluginConfigL(aAttributes);
       
   350         }
       
   351     else if (aLocalName == KOomAttributePluginIdlePriority)
       
   352         {
       
   353         CheckState(EOomParsingStateAppPluginSettings, KOomErrPluginIdleRuleOutsideAppPluginElement);
       
   354         SetPluginIdlePriorityL(aAttributes);
       
   355         }
       
   356     else if (aLocalName == KOomAttributePluginForegroundAppPriority)
       
   357         {
       
   358         CheckState(EOomParsingStateAppPluginSettings, EOomParsingStateSystemPluginSettings, KOomErrPluginForegroundRuleOutsidePluginElement);
       
   359         SetPluginForegroundAppPriorityL(aAttributes);
       
   360         }
       
   361     
       
   362     }
       
   363 
       
   364 void COomConfigParser::ConfigError(TInt aError)
       
   365     {
       
   366     OomConfigParserPanic(aError);
       
   367     }
       
   368 
       
   369 void COomConfigParser::SetGlobalSettings(const RAttributeArray& aAttributes)
       
   370     {
       
   371     TInt defaultLowMemoryThreshold;    
       
   372     TInt err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeLowRamThreshold, defaultLowMemoryThreshold);
       
   373 
       
   374     if (err == KErrNone)
       
   375         iConfig.SetDefaultLowRamThreshold(defaultLowMemoryThreshold * KBytesInMegabyte);
       
   376     else
       
   377         ConfigError(KOomErrLowRamErrorInGlobalSettings);
       
   378     
       
   379     if (err == KErrNone)
       
   380         {
       
   381         TInt defaultGoodMemoryThreshold;    
       
   382         TInt err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeGoodRamThreshold, defaultGoodMemoryThreshold);
       
   383 
       
   384         if (err == KErrNone)
       
   385             iConfig.SetDefaultGoodRamThreshold(defaultGoodMemoryThreshold * KBytesInMegabyte);
       
   386         else
       
   387             ConfigError(KOomErrGoodRamErrorInGlobalSettings);
       
   388         }
       
   389 
       
   390     if (err == KErrNone)
       
   391         {
       
   392         TInt swapUsageMonitored;
       
   393         TInt err = GetValueFromBooleanAttributeList(aAttributes, KOomAttributeSwapUsageMonitored, swapUsageMonitored);
       
   394         
       
   395         if (err == KErrNone)
       
   396             iConfig.SetSwapUsageMonitored(swapUsageMonitored);
       
   397         else
       
   398             ConfigError(KOomErrSwapUsageMonitoredErrorInGlobalSettings);
       
   399         }
       
   400     
       
   401     if (err == KErrNone)
       
   402         {
       
   403         TInt defaultLowSwapThreshold;    
       
   404         TInt err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeLowSwapThreshold, defaultLowSwapThreshold);
       
   405 
       
   406         if (err == KErrNone)
       
   407             iConfig.SetDefaultLowSwapThreshold(defaultLowSwapThreshold * KBytesInMegabyte);
       
   408         else
       
   409             ConfigError(KOomErrLowSwapErrorInGlobalSettings);
       
   410         }
       
   411 
       
   412     if (err == KErrNone)
       
   413         {
       
   414         TInt defaultGoodSwapThreshold;    
       
   415         TInt err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeGoodSwapThreshold, defaultGoodSwapThreshold);
       
   416 
       
   417         if (err == KErrNone)
       
   418             iConfig.SetDefaultGoodSwapThreshold(defaultGoodSwapThreshold * KBytesInMegabyte);
       
   419         else
       
   420             ConfigError(KOomErrGoodSwapErrorInGlobalSettings);
       
   421         }
       
   422     
       
   423     if (err == KErrNone)
       
   424         {
       
   425         TInt defaultMaxCloseAppBatch;    
       
   426         TInt err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeMaxAppCloseBatch, defaultMaxCloseAppBatch);
       
   427 
       
   428         if (err == KErrNone)
       
   429             iConfig.SetMaxCloseAppBatch(defaultMaxCloseAppBatch);
       
   430         else
       
   431             ConfigError(KOomErrMaxCloseErrorInGlobalSettings);
       
   432         }
       
   433     
       
   434     if (err == KErrNone)
       
   435         {
       
   436         TInt defaultWaitAfterPlugin;    
       
   437         TInt err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeDefaultWaitAfterPlugin, defaultWaitAfterPlugin);
       
   438 
       
   439         if (err == KErrNone)
       
   440             iConfig.SetDefaultWaitAfterPlugin(defaultWaitAfterPlugin);
       
   441         else
       
   442             ConfigError(KOomErrDefaultWaitAfterPluginInGlobalSettings);
       
   443         }
       
   444     
       
   445     if (err == KErrNone)
       
   446         {
       
   447         TInt maxAppExitTime;    
       
   448         TInt err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeMaxAppExitTime, maxAppExitTime);
       
   449 
       
   450         if (err == KErrNone)
       
   451             iConfig.SetMaxAppExitTime(maxAppExitTime);
       
   452         else
       
   453             iConfig.SetMaxAppExitTime(KOomMaxAppExitTime);
       
   454         }
       
   455     }
       
   456 
       
   457 void COomConfigParser::SetForceCheckConfigL(const RAttributeArray& aAttributes)
       
   458     {
       
   459     TUint priority;
       
   460     TInt err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibutePriority, priority);
       
   461     if (err == KErrNone)
       
   462         {
       
   463         iConfig.GlobalConfig().AddForceCheckPriorityL(priority);
       
   464         }
       
   465     else
       
   466         {
       
   467         ConfigError(KOomErrBadOrMissingPriorityInForceCheck);    
       
   468         }
       
   469     }
       
   470 
       
   471 void COomConfigParser::SetAppConfigL(const RAttributeArray& aAttributes)
       
   472     {
       
   473     TUint uid;
       
   474     COomApplicationConfig* appConfig = NULL;
       
   475     
       
   476     TInt err = GetValueFromHexAttributeList(aAttributes, KOomAttibuteUid, uid);
       
   477     
       
   478     if (err != KErrNone)
       
   479         {
       
   480         ConfigError(KOomErrBadOrMissingUidInAppConfig);
       
   481         }
       
   482     else
       
   483         iParentUid = uid;
       
   484 
       
   485     appConfig = COomApplicationConfig::NewL(uid);
       
   486     CleanupStack::PushL(appConfig);    
       
   487         
       
   488     // Set the app specific memory thresholds (if they exist)
       
   489     // Get the app specific low threshold
       
   490     if (err == KErrNone)
       
   491         {
       
   492         TUint lowThreshold;
       
   493         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeLowRamThreshold, lowThreshold);
       
   494         if (err == KErrNone)
       
   495             {
       
   496             appConfig->iLowRamThreshold = lowThreshold * KBytesInMegabyte;
       
   497             }
       
   498         else if (err == KErrNotFound)
       
   499             err = KErrNone;
       
   500         
       
   501         if (err != KErrNone)
       
   502             ConfigError(KOomErrBadLowThresholdValueForAppConfig);
       
   503         }
       
   504 
       
   505     // Get the app specific good threshold
       
   506     if (err == KErrNone)
       
   507         {
       
   508         TUint goodThreshold;
       
   509         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeGoodRamThreshold, goodThreshold);
       
   510         if (err == KErrNone)
       
   511             {
       
   512             appConfig->iGoodRamThreshold = goodThreshold * KBytesInMegabyte;
       
   513             }
       
   514         else if (err == KErrNotFound)
       
   515             err = KErrNone;
       
   516         
       
   517         if (err != KErrNone)
       
   518             ConfigError(KOomErrBadGoodThresholdValueForAppConfig);
       
   519         }
       
   520     
       
   521     // Set the app specific swap thresholds (if they exist)
       
   522     // Get the app specific low swap threshold
       
   523     if (err == KErrNone)
       
   524         {
       
   525         TUint lowThreshold;
       
   526         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeLowSwapThreshold, lowThreshold);
       
   527         if (err == KErrNone)
       
   528             {
       
   529             appConfig->iLowSwapThreshold = lowThreshold * KBytesInMegabyte;
       
   530             }
       
   531         else if (err == KErrNotFound)
       
   532             err = KErrNone;
       
   533             
       
   534         if (err != KErrNone)
       
   535             ConfigError(KOomErrBadLowThresholdValueForAppConfig);
       
   536         }
       
   537 
       
   538     // Get the app specific good swapthreshold
       
   539     if (err == KErrNone)
       
   540         {
       
   541         TUint goodThreshold;
       
   542         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeGoodSwapThreshold, goodThreshold);
       
   543         if (err == KErrNone)
       
   544             {
       
   545             appConfig->iGoodSwapThreshold = goodThreshold * KBytesInMegabyte;
       
   546             }
       
   547         else if (err == KErrNotFound)
       
   548             err = KErrNone;
       
   549             
       
   550         if (err != KErrNone)
       
   551             ConfigError(KOomErrBadGoodThresholdValueForAppConfig);
       
   552         }  
       
   553         
       
   554     // Add the applciation config to the main config
       
   555     if ((err == KErrNone) && (appConfig))
       
   556         {
       
   557         iConfig.AddApplicationConfigL(appConfig);
       
   558         }
       
   559     
       
   560     if (appConfig)
       
   561         CleanupStack::Pop(appConfig);
       
   562     }
       
   563 
       
   564 void COomConfigParser::SetCloseAppConfigL(const RAttributeArray& aAttributes)
       
   565     {
       
   566     // Get and convert uid attribute to TInt
       
   567     TInt err = KErrNone;
       
   568     
       
   569     TUint uid;
       
   570     err = GetValueFromHexAttributeList(aAttributes, KOomAttibuteUid, uid);
       
   571 
       
   572     if (err != KErrNone)
       
   573         {
       
   574         ConfigError(KOomErrBadOrMissingUidInAppCloseConfig);    
       
   575         return;
       
   576         }
       
   577     else
       
   578         iParentUid = uid;
       
   579     
       
   580     COomCloseAppConfig* closeAppConfig = COomCloseAppConfig::NewL(uid); // Radio UID
       
   581     CleanupStack::PushL(closeAppConfig);
       
   582 
       
   583      if (err == KErrNone)
       
   584         {
       
   585         // Check that we have a priority for the added app_close event
       
   586         // Specifying a priority is mandatory
       
   587         TUint priority;
       
   588         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibutePriority, priority);
       
   589         if (err == KErrNone)
       
   590             {
       
   591             closeAppConfig->SetDefaultPriority(priority);
       
   592             }
       
   593         else
       
   594             {
       
   595             ConfigError(KOomErrBadOrMissingPriorityInAppCloseConfig);    
       
   596             }
       
   597         }
       
   598     
       
   599     if (err == KErrNone)
       
   600         {
       
   601         TPtrC8 syncModeString;
       
   602         err = GetValueFromAttributeList(aAttributes, KOomAttibuteSyncMode, syncModeString);
       
   603         
       
   604         if (err == KErrNone)
       
   605             {
       
   606             TOomSyncMode syncMode = EContinue;
       
   607             
       
   608             if (syncModeString == KOomConfigSyncModeContinue)
       
   609                 syncMode = EContinue;
       
   610             else if (syncModeString == KOomConfigSyncModeCheck)
       
   611                 syncMode = ECheckRam;
       
   612             else if (syncModeString == KOomConfigSyncModeEstimate)
       
   613                 syncMode = EEstimate;
       
   614             else
       
   615                 ConfigError(KOomErrInvalidSyncMode);
       
   616             
       
   617             if (err == KErrNone)
       
   618                 {
       
   619                 closeAppConfig->iSyncMode = syncMode;
       
   620                 }
       
   621             }
       
   622         else
       
   623             {
       
   624             ConfigError(KOomErrMissingSyncModeInAppCloseConfig);
       
   625             }
       
   626         }
       
   627     
       
   628     
       
   629     if (err == KErrNone)
       
   630         {
       
   631         // If we have a default priority attribute then add it, otherwise use the global default priority
       
   632         TInt ramEstimate;
       
   633         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibuteRamEstimate, ramEstimate);
       
   634         if ((err == KErrNotFound) && (closeAppConfig->iSyncMode != EEstimate))
       
   635             {
       
   636             err = KErrNone;
       
   637             }
       
   638         
       
   639         if (err != KErrNone)
       
   640             ConfigError(KOomErrMissingEstimateFromAppCloseConfig);
       
   641         else
       
   642             closeAppConfig->iRamEstimate = ramEstimate * KBytesInMegabyte;
       
   643            }
       
   644 
       
   645     if (err == KErrNone)
       
   646         iConfig.SetAppCloseConfigL(closeAppConfig);
       
   647     
       
   648     CleanupStack::Pop(closeAppConfig);
       
   649     }
       
   650 
       
   651 void COomConfigParser::SetAppCloseIdlePriorityConfigL(const RAttributeArray& aAttributes)
       
   652     {
       
   653     TUint uid;
       
   654     TInt idleTime;
       
   655     TUint priority;
       
   656 
       
   657     // Use the UID from the parent scope
       
   658     uid = iParentUid;
       
   659 
       
   660     TInt err = KErrNone;
       
   661     
       
   662     err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibuteIdleTime, idleTime);
       
   663     
       
   664 #ifdef __WINS__
       
   665     // The tick is 5 times slower on the emulator than on the phone
       
   666     idleTime = idleTime / KEmulatorTickDivisor;
       
   667 #endif
       
   668     
       
   669     if (err != KErrNone)
       
   670         {
       
   671         ConfigError(KOomErrBadOrMissingIdleTimeInAppIdleRule);
       
   672         }
       
   673     
       
   674     if (err == KErrNone)
       
   675         {
       
   676         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibuteIdlePriority, priority);
       
   677         
       
   678         if (err != KErrNone)
       
   679             {
       
   680             ConfigError(KOomErrBadOrMissingPriorityInAppIdleRule);
       
   681             }
       
   682         }
       
   683     
       
   684     if (err == KErrNone)
       
   685         {
       
   686         COomIdleTimeRule* idleRule = COomIdleTimeRule::NewL(idleTime, priority);
       
   687         CleanupStack::PushL(idleRule);
       
   688         iConfig.AddApplicationRuleL(uid, idleRule);
       
   689         CleanupStack::Pop(idleRule);
       
   690         }
       
   691     }
       
   692 
       
   693 void COomConfigParser::SetForegroundAppPriorityL(const RAttributeArray& aAttributes)
       
   694     {
       
   695     TUint appUid;
       
   696     TUint targetAppId;
       
   697     TUint priority;
       
   698 
       
   699     TInt err = KErrNone;
       
   700     
       
   701     // Use the UID from the parent scope
       
   702     appUid = iParentUid;
       
   703 
       
   704     // Check that we have a priority for the added system plugin action
       
   705     // Specifying a priority is mandatory
       
   706     err = GetValueFromHexAttributeList(aAttributes, KOomAttributeIfForegroundAppId, targetAppId);
       
   707     if (err != KErrNone)
       
   708         {
       
   709         ConfigError(KOomErrBadOrMissingTargetAppIdInForegroundAppRule);    
       
   710         }
       
   711     
       
   712     if (err == KErrNone)
       
   713         {
       
   714         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibuteIdlePriority, priority);
       
   715         
       
   716         if (err != KErrNone)
       
   717             {
       
   718             ConfigError(KOomErrBadOrMissingPriorityInForegroundAppRule);
       
   719             }
       
   720         }
       
   721     
       
   722     if (err == KErrNone)
       
   723         {
       
   724         COomForegroundRule* foregroundRule = new (ELeave) COomForegroundRule(targetAppId, priority);
       
   725         CleanupStack::PushL(foregroundRule);
       
   726         iConfig.AddApplicationRuleL(appUid, foregroundRule);
       
   727         CleanupStack::Pop(foregroundRule);
       
   728         }
       
   729 
       
   730     }
       
   731 
       
   732 void COomConfigParser::SetSystemPluginConfigL(const RAttributeArray& aAttributes)
       
   733     {
       
   734     // Get and convert uid attribute to TInt
       
   735     TInt err = KErrNone;
       
   736     
       
   737     TUint uid;
       
   738     err = GetValueFromHexAttributeList(aAttributes, KOomAttibuteUid, uid);
       
   739 
       
   740     if (err != KErrNone)
       
   741         {
       
   742         ConfigError(KOomErrBadOrMissingUidInSystemPluginConfig);    
       
   743         return;
       
   744         }
       
   745     else
       
   746         iParentUid = uid;
       
   747     
       
   748     COomRunPluginConfig* pluginConfig = COomRunPluginConfig::NewL(uid, EOomSystemPlugin);
       
   749     CleanupStack::PushL(pluginConfig);
       
   750 
       
   751      if (err == KErrNone)
       
   752         {
       
   753         // Check that we have a priority for the added system plugin action
       
   754         // Specifying a priority is mandatory
       
   755         TUint priority;
       
   756         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibutePriority, priority);
       
   757         if (err == KErrNone)
       
   758             {
       
   759             pluginConfig->SetDefaultPriority(priority);
       
   760             }
       
   761         else
       
   762             {
       
   763             ConfigError(KOomErrBadOrMissingPriorityInSystemPluginConfig);    
       
   764             }
       
   765         }
       
   766      
       
   767      if (err == KErrNone)
       
   768         {
       
   769         TInt wait;
       
   770         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeWait, wait);
       
   771         if (err == KErrNone)
       
   772             {
       
   773             pluginConfig->SetWaitAfterPlugin(wait);
       
   774             }
       
   775         else if (err == KErrNotFound)
       
   776             {
       
   777             // If this attribute isn't present then just don't set it, and clear the error
       
   778             err = KErrNone;
       
   779             }
       
   780         else
       
   781             ConfigError(KOomErrBadPluginWaitTime);
       
   782         }
       
   783      
       
   784      if (err == KErrNone)
       
   785          {
       
   786          // Get the config for the sync mode for this plugin (if one is specified) and set it
       
   787          SetPluginSyncMode(aAttributes, *pluginConfig);
       
   788          }
       
   789 
       
   790      iConfig.AddPluginConfigL(pluginConfig);
       
   791      
       
   792      CleanupStack::Pop(pluginConfig);
       
   793     }
       
   794 
       
   795 void COomConfigParser::SetAppPluginConfigL(const RAttributeArray& aAttributes)
       
   796     {
       
   797     // Get and convert uid attribute to TInt
       
   798     TInt err = KErrNone;
       
   799     
       
   800     TUint uid;
       
   801     err = GetValueFromHexAttributeList(aAttributes, KOomAttibuteUid, uid);
       
   802 
       
   803     if (err != KErrNone)
       
   804         {
       
   805         ConfigError(KOomErrBadOrMissingUidInAppPluginConfig);    
       
   806         return;
       
   807         }
       
   808     else
       
   809         iParentUid = uid;
       
   810     
       
   811     COomRunPluginConfig* pluginConfig = COomRunPluginConfig::NewL(uid, EOomAppPlugin);
       
   812     CleanupStack::PushL(pluginConfig);
       
   813 
       
   814     if (err == KErrNone)
       
   815        {
       
   816        // Check that we have a priority for the added system plugin action
       
   817        // Specifying a priority is mandatory
       
   818         TUint priority;
       
   819         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibutePriority, priority);
       
   820         if (err == KErrNone)
       
   821             {
       
   822             pluginConfig->SetDefaultPriority(priority);
       
   823             }
       
   824         else
       
   825             {
       
   826             ConfigError(KOomErrBadOrMissingPriorityInAppPluginConfig);    
       
   827             }
       
   828        }
       
   829 
       
   830     if (err == KErrNone)
       
   831        {
       
   832        // Check that we have a priority for the added system plugin action
       
   833        // Specifying a priority is mandatory
       
   834         TUint targetAppId;
       
   835         err = GetValueFromHexAttributeList(aAttributes, KOomAttributeTargetAppId, targetAppId);
       
   836         if (err == KErrNone)
       
   837             {
       
   838             pluginConfig->SetTargetApp(targetAppId);
       
   839             iParentTargetApp = targetAppId;
       
   840             }
       
   841         else
       
   842             {
       
   843             ConfigError(KOomErrBadOrMissingTargetAppIdInAppPluginConfig);    
       
   844             }
       
   845        }
       
   846     
       
   847     if (err == KErrNone)
       
   848        {
       
   849        TInt wait;
       
   850         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttributeWait, wait);
       
   851         if (err == KErrNone)
       
   852             {
       
   853             pluginConfig->SetWaitAfterPlugin(wait);
       
   854             }
       
   855         else if (err == KErrNotFound)
       
   856             {
       
   857             // If this attribute isn't present then just don't set it, and clear the error
       
   858             err = KErrNone;
       
   859             }
       
   860         else
       
   861             ConfigError(KOomErrBadPluginWaitTime);
       
   862        }    
       
   863     
       
   864     if (err == KErrNone)
       
   865         {
       
   866         // Get the config for the sync mode for this plugin (if one is specified) and set it
       
   867         SetPluginSyncMode(aAttributes, *pluginConfig);
       
   868         
       
   869         TBool targetAppNotRunning;
       
   870         err = GetValueFromBooleanAttributeList(aAttributes, KOomAttributeCallIfTargetAppNotRunning, targetAppNotRunning);
       
   871         if (err == KErrNone)
       
   872             {
       
   873             pluginConfig->SetCallIfTargetAppNotRunning(targetAppNotRunning);
       
   874             }
       
   875         else if (err == KErrNotFound)
       
   876             {
       
   877             // If this attribute isn't present then just don't set it, and clear the error
       
   878             err = KErrNone;
       
   879             }
       
   880         else
       
   881             {
       
   882             ConfigError(KOomErrBadCallIfTargetAppNotRunning);
       
   883             }
       
   884         }
       
   885 
       
   886      iConfig.AddPluginConfigL(pluginConfig);
       
   887      
       
   888      CleanupStack::Pop(pluginConfig);
       
   889 
       
   890     }
       
   891 
       
   892 void COomConfigParser::SetPluginIdlePriorityL(const RAttributeArray& aAttributes)
       
   893     {
       
   894     TUint uid;
       
   895     TInt idleTime;
       
   896     TUint priority;
       
   897 
       
   898     TInt err = KErrNone;
       
   899     
       
   900     // Use the UID from the parent scope
       
   901     uid = iParentUid;
       
   902 
       
   903     err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibuteIdleTime, idleTime);
       
   904     
       
   905 #ifdef __WINS__
       
   906     // The tick is 5 times slower on the emulator than on the phone
       
   907     idleTime = idleTime / KEmulatorTickDivisor;
       
   908 #endif
       
   909     
       
   910     if (err != KErrNone)
       
   911         {
       
   912         ConfigError(KOomErrBadOrMissingIdleTimeInPluginIdleRule);
       
   913         }
       
   914     
       
   915     if (err == KErrNone)
       
   916         {
       
   917         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibuteIdlePriority, priority);
       
   918         
       
   919         if (err != KErrNone)
       
   920             {
       
   921             ConfigError(KOomErrBadOrMissingPriorityInPluginIdleRule);
       
   922             }
       
   923         }
       
   924     
       
   925     if (err == KErrNone)
       
   926         {
       
   927         COomIdleTimeRule* idleRule = COomIdleTimeRule::NewL(idleTime, priority);
       
   928         CleanupStack::PushL(idleRule);
       
   929         iConfig.AddPluginRuleL(uid, idleRule);
       
   930         CleanupStack::Pop(idleRule);
       
   931         }
       
   932     }
       
   933 
       
   934 void COomConfigParser::SetPluginForegroundAppPriorityL(const RAttributeArray& aAttributes)
       
   935     {
       
   936     TUint uid;
       
   937     TUint targetAppId;
       
   938     TUint priority;
       
   939 
       
   940     TInt err = KErrNone;
       
   941     
       
   942     // Use the UID from the parent scope
       
   943     uid = iParentUid;
       
   944 
       
   945         // Check that we have a priority for the added system plugin action
       
   946         // Specifying a priority is mandatory
       
   947         
       
   948     TPtrC8 targetAppString;
       
   949     err = GetValueFromAttributeList(aAttributes, KOomAttributeTargetAppId, targetAppString);
       
   950     if ((err == KErrNone)
       
   951             && (targetAppString == KOomConfigTargetAppValue)
       
   952             && (iState == EOomParsingStateAppPluginSettings))
       
   953         // If the target app is specified as "TARGET_APP" then we use the target app from the parent entry
       
   954         {
       
   955         targetAppId = iParentTargetApp;
       
   956         }
       
   957     else
       
   958         {
       
   959         err = GetValueFromHexAttributeList(aAttributes, KOomAttributeTargetAppId, targetAppId);
       
   960         if (err != KErrNone)
       
   961             {
       
   962             ConfigError(KOomErrBadOrMissingTargetAppIdInForegroundAppRule);    
       
   963             }
       
   964         }
       
   965      
       
   966     if (err == KErrNone)
       
   967         {
       
   968         err = GetValueFromDecimalAttributeList(aAttributes, KOomAttibuteIdlePriority, priority);
       
   969         
       
   970         if (err != KErrNone)
       
   971             {
       
   972             ConfigError(KOomErrBadOrMissingPriorityInForegroundAppRule);
       
   973             }
       
   974         }
       
   975     
       
   976     if (err == KErrNone)
       
   977         {
       
   978         COomForegroundRule* foregroundRule = new (ELeave) COomForegroundRule(targetAppId, priority);
       
   979         CleanupStack::PushL(foregroundRule);
       
   980         iConfig.AddPluginRuleL(uid, foregroundRule);
       
   981         CleanupStack::Pop(foregroundRule);
       
   982         }
       
   983     }
       
   984 
       
   985 // Finds an attribute of the given name and gets its value
       
   986 // A value is only valid as long as AAtrributes is valid (and unmodified)
       
   987 // Returns KErrNone if the attribute is present in the list, KErrNotFound otherwise
       
   988 TInt COomConfigParser::GetValueFromAttributeList(const RAttributeArray& aAttributes, const TDesC8& aName, TPtrC8& aValue)
       
   989     {
       
   990     TInt index = aAttributes.Count();
       
   991     TBool attributeFound = EFalse;
       
   992     while ((index--) && (!attributeFound))
       
   993         {
       
   994         if (aAttributes[index].Attribute().LocalName().DesC() == aName)
       
   995             {
       
   996             attributeFound = ETrue;
       
   997             aValue.Set(aAttributes[index].Value().DesC());
       
   998             }
       
   999         }
       
  1000     
       
  1001     TInt err = KErrNone;
       
  1002     
       
  1003     if (!attributeFound)
       
  1004         err = KErrNotFound;
       
  1005     
       
  1006     return err;
       
  1007     }
       
  1008 
       
  1009 // Finds an attribute of the given name and gets its value (coverting the string hex value to a UInt)
       
  1010 // Returns KErrNone if the attribute is present in the list, KErrNotFound otherwise
       
  1011 // Returns KErrCorrupt if the string is not a valid hex number
       
  1012 TInt COomConfigParser::GetValueFromHexAttributeList(const RAttributeArray& aAttributes, const TDesC8& aName, TUint& aValue)
       
  1013     {
       
  1014     TPtrC8 hexString;
       
  1015     TInt err = GetValueFromAttributeList(aAttributes, aName, hexString);
       
  1016 
       
  1017     if (hexString == KOomConfigDefaultAppUid)
       
  1018         {
       
  1019         // This is a special case
       
  1020         // When we hit this value in a hex field then we return the default app UID
       
  1021         aValue = KOomDefaultAppId;
       
  1022         }
       
  1023     else if (hexString == KOomConfigDefaultPluginUid)
       
  1024         {
       
  1025         // This is a special case
       
  1026         // When we hit this value in a hex field then we return the default app UID
       
  1027         aValue = KOomDefaultPluginId;
       
  1028         }
       
  1029     else if (hexString == KOomConfigBusyAppUid)
       
  1030         {
       
  1031         aValue = KOomBusyAppId;
       
  1032         }
       
  1033     else if (hexString == KOomConfigHighPriorityAppUid)
       
  1034         {
       
  1035         aValue = KOomHighPriorityAppId;
       
  1036         }
       
  1037     else if (err == KErrNone)
       
  1038         {
       
  1039         TLex8 hexLex(hexString);
       
  1040         err = hexLex.Val(aValue, EHex);
       
  1041         if (err != KErrNone)
       
  1042             err = KErrCorrupt;
       
  1043         }
       
  1044     
       
  1045     return err;
       
  1046     }
       
  1047 
       
  1048 // Finds an attribute of the given name and gets its value (coverting the string decimal value to a UInt)
       
  1049 // Returns KErrNone if the attribute is present in the list, KErrNotFound otherwise
       
  1050 // Returns KErrCorrupt if the string is not a valid decimal number
       
  1051 TInt COomConfigParser::GetValueFromDecimalAttributeList(const RAttributeArray& aAttributes, const TDesC8& aName, TUint& aValue)
       
  1052     {
       
  1053     TPtrC8 decimalString;
       
  1054     TInt err = GetValueFromAttributeList(aAttributes, aName, decimalString);
       
  1055 
       
  1056     if (err == KErrNone)
       
  1057         {
       
  1058         if (decimalString == KOomAttibuteNeverClose)
       
  1059             aValue = KOomPriorityInfinate;
       
  1060         else
       
  1061             {
       
  1062             TLex8 decimalLex(decimalString);
       
  1063             err = decimalLex.Val(aValue, EDecimal);
       
  1064             if (err != KErrNone)
       
  1065                 err = KErrCorrupt;
       
  1066             }
       
  1067         }
       
  1068     
       
  1069     return err;
       
  1070     }
       
  1071 
       
  1072 TInt COomConfigParser::GetValueFromDecimalAttributeList(const RAttributeArray& aAttributes, const TDesC8& aName, TInt& aValue)
       
  1073     {
       
  1074     TUint uintValue;
       
  1075     TInt err = GetValueFromDecimalAttributeList(aAttributes, aName, uintValue);
       
  1076     aValue = uintValue;
       
  1077     return err;
       
  1078     }
       
  1079 
       
  1080 TInt COomConfigParser::GetValueFromBooleanAttributeList(const RAttributeArray& aAttributes, const TDesC8& aName, TBool& aValue)
       
  1081     {
       
  1082     TPtrC8 ptrValue;
       
  1083     TInt err = GetValueFromAttributeList(aAttributes, aName, ptrValue);
       
  1084     if (err == KErrNone)
       
  1085         {
       
  1086         if (ptrValue == KOomAttributeTrue || ptrValue == KOomAttribute1)
       
  1087             {
       
  1088             aValue = ETrue;
       
  1089             }
       
  1090         else if (ptrValue == KOomAttributeFalse || ptrValue == KOomAttribute0)
       
  1091             {
       
  1092             aValue = EFalse;
       
  1093             }
       
  1094         else
       
  1095             {
       
  1096             err = KErrCorrupt;
       
  1097             }
       
  1098         }
       
  1099     return err;
       
  1100     }
       
  1101 
       
  1102 void COomConfigParser::SetPluginSyncMode(const RAttributeArray& aAttributes, COomRunPluginConfig& aRunPluginConfig)
       
  1103     {
       
  1104     TPtrC8 syncModeString;
       
  1105     TInt err = GetValueFromAttributeList(aAttributes, KOomAttibuteSyncMode, syncModeString);
       
  1106     
       
  1107     if (err == KErrNone)
       
  1108         // If there is no specified sync mode then leave it as the default
       
  1109         {
       
  1110         TOomSyncMode syncMode = EContinue;
       
  1111         
       
  1112         if (syncModeString == KOomConfigSyncModeContinue)
       
  1113             syncMode = EContinueIgnoreMaxBatchSize;
       
  1114         else if (syncModeString == KOomConfigSyncModeCheck)
       
  1115             syncMode = ECheckRam;
       
  1116         else if (syncModeString == KOomConfigSyncModeEstimate)
       
  1117             syncMode = EEstimate;
       
  1118         else
       
  1119             ConfigError(KOomErrInvalidSyncMode);
       
  1120         
       
  1121         if (err == KErrNone)
       
  1122             {
       
  1123             aRunPluginConfig.iSyncMode = syncMode;
       
  1124             }
       
  1125         }
       
  1126     }
       
  1127 
       
  1128 // Check that the current state is as expected
       
  1129 // If not then the specified config error is generated
       
  1130 void COomConfigParser::CheckState(TOomParsingState aExpectedState, TInt aError)
       
  1131     {
       
  1132     if (iState != aExpectedState)
       
  1133         ConfigError(aError);
       
  1134     }
       
  1135 
       
  1136 // Check that the current state is as expected
       
  1137 // If not then the specified config error is generated
       
  1138 // This version checks to ensure that the current state matches either of the passed in states
       
  1139 void COomConfigParser::CheckState(TOomParsingState aExpectedState1, TOomParsingState aExpectedState2, TInt aError)
       
  1140     {
       
  1141     if ((iState != aExpectedState1)
       
  1142             && (iState != aExpectedState2))
       
  1143         ConfigError(aError);
       
  1144     }
       
  1145 
       
  1146 void COomConfigParser::ChangeState(TOomParsingState aState)
       
  1147     {
       
  1148     iState = aState;
       
  1149     }