crashanalysercmd/UI/Common/Engine/Engine/CAEngine.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 using System;
       
    18 using System.Text;
       
    19 using System.IO;
       
    20 using System.Collections.Generic;
       
    21 using System.Reflection;
       
    22 using SymbianUtils;
       
    23 using SymbianUtils.Settings;
       
    24 using SymbianUtils.Tracer;
       
    25 using SymbianUtils.PluginManager;
       
    26 using SymbianDebugLib.Engine;
       
    27 using CrashAnalyserEngine.Plugins;
       
    28 using CrashAnalyserEngine.Interfaces;
       
    29 
       
    30 namespace CrashAnalyserEngine.Engine
       
    31 {
       
    32 	public class CAEngine : DisposableObject, IEnumerable<CAPlugin>, ITracer
       
    33 	{
       
    34 		#region Constructors
       
    35         public CAEngine( string[] aCommandLineArgs )
       
    36 		{
       
    37             iDebugEngine = new DbgEngine( this );
       
    38             iCommandLineArgs = aCommandLineArgs;
       
    39 
       
    40             // Create settings
       
    41             iSettings = new XmlSettings( "CASettings.xml" );
       
    42             iSettings.Restore();
       
    43 		}
       
    44 		#endregion
       
    45 
       
    46 		#region API
       
    47         #endregion
       
    48 
       
    49 		#region Properties
       
    50         public XmlSettings Settings
       
    51         {
       
    52             get { return iSettings; }
       
    53         }
       
    54 
       
    55         public string[] CommandLineArguments
       
    56         {
       
    57             get { return iCommandLineArgs; }
       
    58         }
       
    59 
       
    60         /// <summary>
       
    61         /// The main debug engine instance is owned by the engine and is shared
       
    62         /// amongst all that need it.
       
    63         /// </summary>
       
    64         public DbgEngine DebugEngine
       
    65         {
       
    66             get { return iDebugEngine; }
       
    67         }
       
    68 
       
    69         public IEngineUIManager UIManager
       
    70         {
       
    71             get { return iUIManager; }
       
    72             set
       
    73             {
       
    74                 iUIManager = value;
       
    75 
       
    76                 // Now we can create the sub-engines
       
    77                 LoadPlugins();
       
    78             }
       
    79         }
       
    80 
       
    81         public CAPlugin this[ string aName ]
       
    82         {
       
    83             get
       
    84             {
       
    85                 CAPlugin ret = null;
       
    86                 //
       
    87                 foreach ( CAPlugin plugin in iPlugins )
       
    88                 {
       
    89                     string name = plugin.Name.ToUpper();
       
    90                     if ( name == aName.ToUpper() )
       
    91                     {
       
    92                         ret = plugin;
       
    93                         break;
       
    94                     }
       
    95                 }
       
    96                 //
       
    97                 return ret;
       
    98             }
       
    99         }
       
   100         #endregion
       
   101 
       
   102         #region Internal methods
       
   103         private void LoadPlugins()
       
   104         {
       
   105             object[] parameters = new object[ 1 ];
       
   106             parameters[ 0 ] = this;
       
   107             //
       
   108             iPlugins.Load( parameters );
       
   109             //
       
   110             NotifyAllLoaded();
       
   111         }
       
   112 
       
   113         private void NotifyAllLoaded()
       
   114         {
       
   115             foreach ( CAPlugin plugin in iPlugins )
       
   116             {
       
   117                 plugin.AllPluginsLoaded();
       
   118             }
       
   119         }
       
   120         #endregion
       
   121 
       
   122         #region From IEnumerable<CAPlugin> 
       
   123         public IEnumerator<CAPlugin> GetEnumerator()
       
   124         {
       
   125             return iPlugins.GetEnumerator();
       
   126         }
       
   127 
       
   128         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   129         {
       
   130             return iPlugins.GetEnumerator();
       
   131         }
       
   132         #endregion
       
   133 
       
   134         #region From ITracer
       
   135         public void Trace( string aMessage )
       
   136         {
       
   137             if ( iUIManager != null )
       
   138             {
       
   139                 iUIManager.UITrace( aMessage );
       
   140             }
       
   141         }
       
   142 
       
   143         public void Trace( string aFormat, params object[] aParams )
       
   144         {
       
   145             Trace( string.Format( aFormat, aParams ) );
       
   146         }
       
   147         #endregion
       
   148 
       
   149         #region From DisposableObject
       
   150         protected override void CleanupManagedResources()
       
   151         {
       
   152             try
       
   153             {
       
   154                 base.CleanupManagedResources();
       
   155             }
       
   156             finally
       
   157             {
       
   158                 if ( iPlugins != null )
       
   159                 {
       
   160                     iPlugins.Unload();
       
   161                     iPlugins = null;
       
   162                 }
       
   163                 //
       
   164                 iDebugEngine.Dispose();
       
   165             }
       
   166         }
       
   167         #endregion
       
   168 
       
   169         #region Data members
       
   170         private readonly XmlSettings iSettings;
       
   171         private readonly string[] iCommandLineArgs;
       
   172         private readonly DbgEngine iDebugEngine;
       
   173         private IEngineUIManager iUIManager = null;
       
   174         private PluginManager<CAPlugin> iPlugins = new PluginManager<CAPlugin>(1);
       
   175 		#endregion
       
   176     }
       
   177 }