sysresmonitoring/oommonitor/src/oomconfig.cpp
branchRCL_3
changeset 1 0fdb7f6b0309
child 2 7645e9ce10dc
equal deleted inserted replaced
0:2e3d3ce01487 1:0fdb7f6b0309
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Configuration representation classes for Out of Memory Monitor.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <e32hashtab.h>
       
    21 
       
    22 #include "oomconfig.h"
       
    23 #include "oomconstants.hrh"
       
    24 #include "oomapplicationconfig.h"
       
    25 #include "oomrunpluginconfig.h"
       
    26 #include "oomcloseappconfig.h"
       
    27 #include "oomtraces.h"
       
    28 
       
    29 COomConfig* COomConfig::NewL()
       
    30     {
       
    31     FUNC_LOG;
       
    32 
       
    33     COomConfig* self = new (ELeave) COomConfig;
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop(self);
       
    37     return self;
       
    38     }
       
    39 
       
    40 
       
    41 // Add the configuration for an application closure.
       
    42 // This class takes ownership of this action.
       
    43 void COomConfig::SetAppCloseConfigL(COomCloseAppConfig* aActionConfig)
       
    44     {
       
    45     FUNC_LOG;
       
    46 
       
    47     // Find the right application config (if there is one) for the app
       
    48     // The map actually contains pointers for values, so we get pointers to pointers here...
       
    49     COomApplicationConfig** applicationConfigPointer = iApplicationToConfigMapping.Find(aActionConfig->iId);
       
    50     
       
    51     // Used to de-reference the pointer-to-pointer, hopefully making the code more readable
       
    52     COomApplicationConfig* applicationConfig = NULL;
       
    53     
       
    54     // Create a new COomApplicationConfig if there isn't one for this app
       
    55     if (!applicationConfigPointer)
       
    56         {
       
    57         applicationConfig = COomApplicationConfig::NewL(aActionConfig->iId);
       
    58         iApplicationToConfigMapping.InsertL(aActionConfig->iId, applicationConfig);
       
    59         }
       
    60     else
       
    61         {
       
    62         applicationConfig = *applicationConfigPointer;
       
    63         }
       
    64     
       
    65     // Append the action config to the appropriate list (the list for the relevant application)
       
    66     applicationConfig->SetAppCloseConfig(aActionConfig);    
       
    67     }
       
    68 
       
    69 // Add the configuration for a plugin action.
       
    70 // This class takes ownership of the configuration object.
       
    71 void COomConfig::AddPluginConfigL(COomRunPluginConfig* aPluginConfig)
       
    72     {
       
    73     FUNC_LOG;
       
    74 
       
    75     // Check if the plugin has already been added, if so then this is an error in configuration (something is trying to add the same plugin twice)
       
    76     COomRunPluginConfig** runPluginConfig = iPluginToConfigMapping.Find(aPluginConfig->Id());
       
    77     if (runPluginConfig)
       
    78         {
       
    79         OomMonitorPanic(KPluginConfigAddedTwice);
       
    80         }
       
    81     
       
    82     iPluginToConfigMapping.InsertL(aPluginConfig->Id(), aPluginConfig);
       
    83     
       
    84     }
       
    85 
       
    86 // Add a rule
       
    87 // This class takes ownership of the given rule
       
    88 // This rule applies to the specified application (and not a plugin associated with this application)
       
    89 // The rule would usually apply to an "application close" event
       
    90 void COomConfig::AddApplicationRuleL(TUint aTargetAppId, MOomRuleConfig* aRule)
       
    91     {
       
    92     FUNC_LOG;
       
    93 
       
    94     COomApplicationConfig** applicationConfig = iApplicationToConfigMapping.Find(aTargetAppId);
       
    95     
       
    96     if (applicationConfig)
       
    97         {
       
    98         (*applicationConfig)->AddRuleL(aRule);
       
    99         }
       
   100     else
       
   101         {
       
   102         OomMonitorPanic(KRuleConfiguredBeforeApplication);
       
   103         }
       
   104     }
       
   105 
       
   106 // Add a rule for a plugin
       
   107 // This class takes ownership of the given rule
       
   108 // This rule is applied to the plugin with the specified ID
       
   109 void COomConfig::AddPluginRuleL(TUint aPluginId, MOomRuleConfig* aRule)
       
   110     {
       
   111     FUNC_LOG;
       
   112 
       
   113     COomRunPluginConfig** runPluginConfig = iPluginToConfigMapping.Find(aPluginId);
       
   114     
       
   115     if (runPluginConfig)
       
   116         {
       
   117         (*runPluginConfig)->AddRuleL(aRule);
       
   118         }
       
   119     else
       
   120         {
       
   121         OomMonitorPanic(KRuleConfiguredBeforePlugin);
       
   122         }   
       
   123     }
       
   124 
       
   125 // Add this application config - this class takes ownership of it
       
   126 // Application config includes settings for a particular application, e.g. whether or not it can be closed
       
   127 void COomConfig::AddApplicationConfigL(COomApplicationConfig* aApplicationConfig)
       
   128     {
       
   129     FUNC_LOG;
       
   130 
       
   131     // Check if the application has already been added, if so then this is an error in configuration (something is trying to add the same app twice)
       
   132     COomApplicationConfig** applicationConfig = iApplicationToConfigMapping.Find(aApplicationConfig->Id());
       
   133     if (applicationConfig)
       
   134         {
       
   135         OomMonitorPanic(KAppConfigAddedTwice);
       
   136         }
       
   137     
       
   138     iApplicationToConfigMapping.InsertL(aApplicationConfig->Id(), aApplicationConfig);
       
   139     }
       
   140 
       
   141 // Get the list of configured actions for the given app id
       
   142 // If no specific actions have been configured for this application then the default action is returned
       
   143 COomApplicationConfig& COomConfig::GetApplicationConfig(TInt32 aAppId)
       
   144     {
       
   145     FUNC_LOG;
       
   146 
       
   147     COomApplicationConfig** applicationConfig = iApplicationToConfigMapping.Find(aAppId);
       
   148     
       
   149     if (!applicationConfig)
       
   150         applicationConfig = iApplicationToConfigMapping.Find(KOomDefaultAppId);
       
   151     
       
   152     // The default app configuration should always exist
       
   153     __ASSERT_ALWAYS(applicationConfig, OomMonitorPanic(KOomDefaultAppNotConfigured));
       
   154     
       
   155     return *(*applicationConfig);
       
   156     }
       
   157 
       
   158 // Get the plugin configuration for the given plugin id
       
   159 // If no specific actions have been configured for this plugin then the default plugin configuration is returned
       
   160 COomRunPluginConfig& COomConfig::GetPluginConfig(TInt32 aPluginId)
       
   161     {
       
   162     FUNC_LOG;
       
   163 
       
   164     COomRunPluginConfig** runPluginConfig = iPluginToConfigMapping.Find(aPluginId);
       
   165     
       
   166     if (!runPluginConfig)
       
   167         runPluginConfig = iPluginToConfigMapping.Find(KOomDefaultPluginId);
       
   168     
       
   169     // The default app configuration should always exist
       
   170     __ASSERT_ALWAYS(runPluginConfig, OomMonitorPanic(KOomDefaultPluginNotConfigured));
       
   171     
       
   172     return *(*runPluginConfig);
       
   173     }
       
   174 
       
   175 COomConfig::~COomConfig()
       
   176     {
       
   177     FUNC_LOG;
       
   178 
       
   179     // Iterate through the hash map deleting all of the items
       
   180     RHashMap<TInt32, COomApplicationConfig*>::TIter iterator(iApplicationToConfigMapping);
       
   181     while (iterator.NextValue())
       
   182         delete iterator.CurrentValue();
       
   183     
       
   184     // Iterate through the plugiun hash map deleting all of the items
       
   185     RHashMap<TInt32, COomRunPluginConfig*>::TIter pluginIterator(iPluginToConfigMapping);
       
   186     while (pluginIterator.NextValue())
       
   187         delete pluginIterator.CurrentValue();
       
   188     
       
   189     iApplicationToConfigMapping.Close();
       
   190     }
       
   191 
       
   192 void COomConfig::ConstructL()
       
   193     {
       
   194     FUNC_LOG;
       
   195     }