crashanalysercmd/Libraries/Engine/CrashItemLib/Crash/Utils/CIFullNameUtils.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.Text.RegularExpressions;
       
    20 using System.Collections.Generic;
       
    21 using CrashItemLib.Crash;
       
    22 using CrashItemLib.Crash.Processes;
       
    23 using CrashItemLib.Crash.Threads;
       
    24 using SymbianStructuresLib.Uids;
       
    25 
       
    26 namespace CrashItemLib.Crash.Utils
       
    27 {
       
    28 	public sealed class CIFullNameUtils
       
    29 	{
       
    30         #region Constructors
       
    31         public CIFullNameUtils( string aFullName )
       
    32         {
       
    33             iMatch = KFullNameRegEx.Match( aFullName );
       
    34         }
       
    35         #endregion
       
    36 
       
    37         #region API
       
    38         public void GetProcessInfo( CIProcess aProcess )
       
    39         {
       
    40             if ( IsValid )
       
    41             {
       
    42                 aProcess.Name = Process;
       
    43                 aProcess.Generation = Generation;
       
    44                 aProcess.SID = SID;
       
    45             }
       
    46         }
       
    47 
       
    48         public void GetThreadInfo( CIThread aThread )
       
    49         {
       
    50             if ( IsValid )
       
    51             {
       
    52                 aThread.Name = Thread;
       
    53             }
       
    54         }
       
    55         #endregion
       
    56 
       
    57         #region Properties
       
    58         public bool IsValid
       
    59         {
       
    60             get { return iMatch.Success; }
       
    61         }
       
    62 
       
    63         public string Process
       
    64         {
       
    65             get
       
    66             {
       
    67                 string ret = string.Empty;
       
    68                 //
       
    69                 if ( IsValid )
       
    70                 {
       
    71                     ret = iMatch.Groups[ "ProcessName" ].Value;
       
    72                 }
       
    73                 //
       
    74                 return ret;
       
    75             }
       
    76         }
       
    77 
       
    78         public string Thread
       
    79         {
       
    80             get
       
    81             {
       
    82                 string ret = string.Empty;
       
    83                 //
       
    84                 if ( IsValid )
       
    85                 {
       
    86                     ret = iMatch.Groups[ "ThreadName" ].Value;
       
    87                 }
       
    88                 //
       
    89                 return ret;
       
    90             }
       
    91         }
       
    92 
       
    93         public uint SID
       
    94         {
       
    95             get
       
    96             {
       
    97                 uint ret = 0;
       
    98                 //
       
    99                 if ( IsValid )
       
   100                 {
       
   101                     ret = uint.Parse( iMatch.Groups[ "SID" ].Value, System.Globalization.NumberStyles.AllowHexSpecifier );
       
   102                 }
       
   103                 //
       
   104                 return ret;
       
   105             }
       
   106         }
       
   107 
       
   108         public int Generation
       
   109         {
       
   110             get
       
   111             {
       
   112                 int ret = 0;
       
   113                 //
       
   114                 if ( IsValid )
       
   115                 {
       
   116                     ret = int.Parse( iMatch.Groups[ "Generation" ].Value );
       
   117                 }
       
   118                 //
       
   119                 return ret;
       
   120             }
       
   121         }
       
   122         #endregion
       
   123 
       
   124         #region Internal methods
       
   125         #endregion
       
   126 
       
   127         #region Internal constants
       
   128         #endregion
       
   129 
       
   130         #region Internal regular expressions
       
   131         private static readonly Regex KFullNameRegEx = new Regex(
       
   132               "(?<ProcessName>.+)\\[(?<SID>[A-Fa-f0-9]{8})\\](?<Generation>" +
       
   133               "\\p{N}{4})\\:\\:(?<ThreadName>.+)",
       
   134             RegexOptions.CultureInvariant
       
   135             | RegexOptions.Compiled
       
   136             );
       
   137         #endregion
       
   138 
       
   139         #region Data members
       
   140         private readonly Match iMatch;
       
   141         #endregion
       
   142     }
       
   143 }