crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianCodeLib/Plugins/CLPluginSymbianOS/Source/ImgSource.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2004-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: 
       
    15 *
       
    16 */
       
    17 
       
    18 using System;
       
    19 using System.IO;
       
    20 using System.Collections.Generic;
       
    21 using System.Text;
       
    22 using System.Threading;
       
    23 using SymbianStructuresLib.Arm;
       
    24 using SymbianStructuresLib.Arm.Instructions;
       
    25 using SymbianStructuresLib.CodeSegments;
       
    26 using SymbianStructuresLib.Debug.Code;
       
    27 using SymbianStructuresLib.Debug.Code.Interfaces;
       
    28 using SymbianCodeLib.SourceManagement.Source;
       
    29 using SymbianCodeLib.SourceManagement.Provisioning;
       
    30 using SymbianUtils;
       
    31 using SymbianUtils.Range;
       
    32 using SymbianUtils.FileTypes;
       
    33 using SymbianImageLib.Common.Image;
       
    34 using SymbianImageLib.Common.Content;
       
    35 using SymbianImageLib.ROM.Image;
       
    36 using CLPluginImg.Provider;
       
    37 using CLPluginImg.Reader;
       
    38 
       
    39 namespace CLPluginImg.Source
       
    40 {
       
    41     internal class ImgSource : CodeSource, ICodeCollectionInstructionConverter
       
    42     {
       
    43         #region Constructors
       
    44         public ImgSource( string aURI, CodeSourceProvider aProvider, CodeCollection aCollection, SIContent aImageContent )
       
    45             : base( aURI, aProvider )
       
    46         {
       
    47             iImageContent = aImageContent;
       
    48 
       
    49             // Make sure we receive any requests from the collection object for code.
       
    50             aCollection.IfaceInstructionConverter = this;
       
    51             aCollection.IsRelocatable = aImageContent.IsRelocationSupported;
       
    52 
       
    53             // XIP content should be read during priming. 
       
    54             TTimeToRead timeToRead = TTimeToRead.EReadWhenPriming;
       
    55             if ( aImageContent.IsRelocationSupported )
       
    56             {
       
    57                 timeToRead = TTimeToRead.EReadWhenNeeded;
       
    58             }
       
    59             else
       
    60             {
       
    61                 // If the image is fixed, then so is the collection base address
       
    62                 aCollection.Relocate( aImageContent.RelocationAddress );
       
    63             }
       
    64 
       
    65             // Must add the collection *after* setting it's properties
       
    66             base.TimeToRead = timeToRead;
       
    67             base.Add( aCollection );
       
    68         }
       
    69         #endregion
       
    70         
       
    71         #region From CodeSource
       
    72         protected override void DoRead( TSynchronicity aSynchronicity )
       
    73         {
       
    74             ImgReader reader = new ImgReader( this, Provider.Tracer );
       
    75             reader.Read( aSynchronicity );
       
    76         }
       
    77 
       
    78         protected override void OnReadComplete()
       
    79         {
       
    80             try
       
    81             {
       
    82                 base.OnReadComplete();
       
    83             }
       
    84             finally
       
    85             {
       
    86                 System.Diagnostics.Debug.Assert( base.Count == 1 );
       
    87                 CodeCollection col = this[ 0 ];
       
    88                 bool codeAvailable = col.IsCodeAvailable;
       
    89                 //
       
    90                 if ( iImageContent != null && codeAvailable == false )
       
    91                 {
       
    92                     // Update the underlying collection with it.
       
    93                     col.Code = iImageContent.GetAllData();
       
    94 
       
    95                     // Don't need this anymore
       
    96                     iImageContent.Dispose();
       
    97                     iImageContent = null;
       
    98                 }
       
    99             }
       
   100         }
       
   101         #endregion
       
   102 
       
   103         #region Properties
       
   104         public SIContent ImageContent
       
   105         {
       
   106             get { return iImageContent; }
       
   107         }
       
   108 
       
   109         public new ImgSourceProvider Provider
       
   110         {
       
   111             get
       
   112             {
       
   113                 ImgSourceProvider provider = (ImgSourceProvider) base.Provider;
       
   114                 return provider;
       
   115             }
       
   116         }
       
   117         #endregion
       
   118 
       
   119         #region From DisposableObject
       
   120         protected override void CleanupManagedResources()
       
   121         {
       
   122             try
       
   123             {
       
   124                 base.CleanupManagedResources();
       
   125             }
       
   126             finally
       
   127             {
       
   128                 if ( iImageContent != null )
       
   129                 {
       
   130                     iImageContent.Dispose();
       
   131                     iImageContent = null;
       
   132                 }
       
   133             }
       
   134         }
       
   135         #endregion
       
   136 
       
   137         #region Internal methods
       
   138         #endregion
       
   139 
       
   140         #region Data members
       
   141         private SIContent iImageContent;
       
   142         #endregion
       
   143     }
       
   144 }