crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianDebugLib/Entity/DbgEntity.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.Collections.Generic;
       
    19 using System.Text;
       
    20 using System.IO;
       
    21 using SymbianUtils;
       
    22 using SymbianUtils.Settings;
       
    23 using SymbianUtils.FileSystem;
       
    24 using SymbianDebugLib.Engine;
       
    25 using SymbianDebugLib.Entity.Primer;
       
    26 using SymbianDebugLib.Entity.Descriptors;
       
    27 using SymbianDebugLib.PluginAPI;
       
    28 
       
    29 namespace SymbianDebugLib.Entity
       
    30 {
       
    31     public abstract class DbgEntity : DisposableObject
       
    32     {
       
    33         #region Enumerations
       
    34         public enum TEvent
       
    35         {
       
    36             EEventPrimingStarted = 0,
       
    37             EEventPrimingProgress,
       
    38             EEventPrimingComplete,
       
    39             EEventRemoved
       
    40         }
       
    41 
       
    42         public enum TConfigurationSuccess
       
    43         {
       
    44             ESuccessful = 0, 
       
    45             EFailed
       
    46         }
       
    47         #endregion
       
    48 
       
    49         #region Delegates & events
       
    50         public delegate void EventHandler( DbgEntity aEntity, string aCategory, TEvent aEvent, object aContext1, object aContext2 );
       
    51         public event EventHandler EventObserver;
       
    52         #endregion
       
    53 
       
    54         #region Constructors
       
    55         protected DbgEntity( DbgEntityDescriptor aDescriptor, FSEntity aFSEntity )
       
    56         {
       
    57             iDescriptor = aDescriptor;
       
    58             iEntity = aFSEntity;
       
    59             iResult = new DbgEntityPrimerResult( this );
       
    60         }
       
    61         #endregion
       
    62 
       
    63         #region API
       
    64         internal void Prime( TSynchronicity aSynchronicity )
       
    65         {
       
    66             iIsPrimed = false;
       
    67             iDescriptor.Prime( this, aSynchronicity );
       
    68         }
       
    69         #endregion
       
    70 
       
    71         #region Framework API
       
    72         public virtual bool Exists
       
    73         {
       
    74             get
       
    75             {
       
    76                 bool ret = false;
       
    77                 //
       
    78                 if ( iEntity != null )
       
    79                 {
       
    80                     ret = iEntity.Exists;
       
    81                 }
       
    82                 //
       
    83                 return ret;
       
    84             }
       
    85         }
       
    86 
       
    87         public virtual bool IsConfigurable
       
    88         {
       
    89             get { return false; }
       
    90         }
       
    91 
       
    92         public virtual bool IsReadyToPrime( out string aErrorList )
       
    93         {
       
    94             aErrorList = string.Empty;
       
    95             return true;
       
    96         }
       
    97 
       
    98         public virtual TConfigurationSuccess Configure()
       
    99         {
       
   100             return TConfigurationSuccess.ESuccessful;
       
   101         }
       
   102 
       
   103         public virtual object CustomOperation( string aName, object aParam1, object aParam2 )
       
   104         {
       
   105             throw new NotSupportedException();
       
   106         }
       
   107 
       
   108         public virtual void Save( XmlSettingCategory aCategory )
       
   109         {
       
   110         }
       
   111 
       
   112         public virtual void Load( XmlSettingCategory aCategory )
       
   113         {
       
   114         }
       
   115 
       
   116         public virtual string FullName
       
   117         {
       
   118             get { return FSEntity.FullName; }
       
   119         }
       
   120 
       
   121         public virtual void OnRemoved()
       
   122         {
       
   123         }
       
   124 
       
   125         public virtual DbgPluginEngine PluginEngine
       
   126         {
       
   127             get
       
   128             {
       
   129                 return null;
       
   130             }
       
   131         }
       
   132         #endregion
       
   133 
       
   134         #region Properties
       
   135         public object Tag
       
   136         {
       
   137             get { return iTag; }
       
   138             set { iTag = value; }
       
   139         }
       
   140 
       
   141         public bool IsPrimed
       
   142         {
       
   143             get { return iIsPrimed; }
       
   144          }
       
   145 
       
   146         public FSEntity FSEntity
       
   147         {
       
   148             get { return iEntity; }
       
   149         }
       
   150 
       
   151         public bool IsUnsupported
       
   152         {
       
   153             get
       
   154             {
       
   155                 return ( this is SymbianDebugLib.Entity.BuiltIn.Unsupported.UnsupportedEntity );
       
   156             }
       
   157         }
       
   158 
       
   159         public bool WasAddedExplicitly
       
   160         {
       
   161             get { return iWasAddedExplicitly; }
       
   162             set { iWasAddedExplicitly = value; }
       
   163         }
       
   164 
       
   165         public string CategoryName
       
   166         {
       
   167             get { return iDescriptor.CategoryName; }
       
   168         }
       
   169 
       
   170         public DbgEntityDescriptor Descriptor
       
   171         {
       
   172             get { return iDescriptor; }
       
   173         }
       
   174 
       
   175         public DbgEntityPrimerResult PrimerResult
       
   176         {
       
   177             get { return iResult; }
       
   178             internal set { iResult = value; }
       
   179         }
       
   180 
       
   181         public TDbgUiMode UiMode
       
   182         {
       
   183             get { return Descriptor.UiMode; }
       
   184         }
       
   185         #endregion
       
   186 
       
   187         #region Priming event propgation
       
   188         internal void OnPrimeStart( IDbgEntityPrimer aPrimer )
       
   189         {
       
   190             // First tell engine
       
   191             Descriptor.Engine.OnPrimingStarted( this );
       
   192             try
       
   193             {
       
   194                 // Next, tell observer
       
   195                 if ( EventObserver != null )
       
   196                 {
       
   197                     EventObserver( this, this.CategoryName, TEvent.EEventPrimingStarted, null, null );
       
   198                 }
       
   199             }
       
   200             catch ( Exception )
       
   201             {
       
   202             }
       
   203         }
       
   204 
       
   205         internal void OnPrimeProgress( IDbgEntityPrimer aPrimer, int aValue )
       
   206         {
       
   207             // First tell engine
       
   208             Descriptor.Engine.OnPrimingProgress( this, aValue );
       
   209             try
       
   210             {
       
   211                 if ( EventObserver != null )
       
   212                 {
       
   213                     EventObserver( this, this.CategoryName, TEvent.EEventPrimingProgress, aValue, null );
       
   214                 }
       
   215             }
       
   216             catch ( Exception )
       
   217             {
       
   218             }
       
   219         }
       
   220 
       
   221         internal void OnPrimeComplete( IDbgEntityPrimer aPrimer )
       
   222         {
       
   223             // We are now considered "primed"
       
   224             iIsPrimed = true;
       
   225 
       
   226             // Next tell engine
       
   227             Descriptor.Engine.OnPrimingComplete( this );
       
   228             try
       
   229             {
       
   230                 // Next, tell observer
       
   231                 if ( EventObserver != null )
       
   232                 {
       
   233                     EventObserver( this, this.CategoryName, TEvent.EEventPrimingComplete, aPrimer.PrimeErrorMessage, aPrimer.PrimeException );
       
   234                 }
       
   235             }
       
   236             catch ( Exception )
       
   237             {
       
   238             }
       
   239         }
       
   240         #endregion
       
   241 
       
   242         #region Operators
       
   243         public static implicit operator FSEntity( DbgEntity aEntity )
       
   244         {
       
   245             FSEntity ret = null;
       
   246             //
       
   247             if ( aEntity.FSEntity != null )
       
   248             {
       
   249                 ret = aEntity.FSEntity;
       
   250             }
       
   251             //
       
   252             return ret;
       
   253         }
       
   254         #endregion
       
   255 
       
   256         #region Internal properties
       
   257         protected DbgEngine Engine
       
   258         {
       
   259             get { return Descriptor.Engine; }
       
   260         }
       
   261         #endregion
       
   262 
       
   263         #region Internal methods
       
   264         #endregion
       
   265 
       
   266         #region From System.Object
       
   267         public override int GetHashCode()
       
   268         {
       
   269             return this.FSEntity.GetHashCode();
       
   270         }
       
   271 
       
   272         public override bool Equals( object aObject )
       
   273         {
       
   274             if ( aObject != null )
       
   275             {
       
   276                 if ( aObject is DbgEntity )
       
   277                 {
       
   278                     DbgEntity other = (DbgEntity) aObject;
       
   279                     //
       
   280                     return ( other.FSEntity == this.FSEntity );
       
   281                 }
       
   282             }
       
   283             //
       
   284             return base.Equals( aObject );
       
   285         }
       
   286 
       
   287         public override string ToString()
       
   288         {
       
   289             return this.FSEntity.FullName;
       
   290         }
       
   291         #endregion
       
   292 
       
   293         #region Data members
       
   294         private readonly DbgEntityDescriptor iDescriptor;
       
   295         private DbgEntityPrimerResult iResult;
       
   296         private object iTag = null;
       
   297         private FSEntity iEntity = null;
       
   298         private bool iIsPrimed = false;
       
   299         private bool iWasAddedExplicitly = true;
       
   300         #endregion
       
   301     }
       
   302 }