|
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.Xml; |
|
20 using System.Collections.Generic; |
|
21 using CrashItemLib.Crash.Base; |
|
22 using CrashItemLib.Crash.Registers; |
|
23 using CrashItemLib.Crash.Registers.Visualization; |
|
24 using CrashItemLib.Crash.Registers.Visualization.Bits; |
|
25 using CrashXmlPlugin.FileFormat.Node; |
|
26 |
|
27 namespace CrashXmlPlugin.FileFormat.Segment.Entries.ValueInterpretations |
|
28 { |
|
29 internal class CXmlValueInterpretation : CXmlNode |
|
30 { |
|
31 #region Constructors |
|
32 public CXmlValueInterpretation( CIRegisterVisualization aValue ) |
|
33 : base( SegConstants.ValueInterpretation_Entry ) |
|
34 { |
|
35 iValue = aValue; |
|
36 } |
|
37 #endregion |
|
38 |
|
39 #region From CXmlNode |
|
40 protected override void XmlSerializeContent( CrashXmlPlugin.FileFormat.Document.CXmlDocumentSerializationParameters aParameters ) |
|
41 { |
|
42 CXmlNode.WriteId( iValue, aParameters.Writer ); |
|
43 |
|
44 aParameters.Writer.WriteElementString( SegConstants.ValueInterpretation_Entry_Hex, iValue.Value.ToString("x8") ); |
|
45 aParameters.Writer.WriteElementString( SegConstants.ValueInterpretation_Entry_Binary, iValue.Binary ); |
|
46 aParameters.Writer.WriteElementString( SegConstants.CmnSize, iValue.Size.ToString() ); |
|
47 |
|
48 // Endianness |
|
49 aParameters.Writer.WriteStartElement( SegConstants.ValueInterpretation_Entry_Endianness ); |
|
50 aParameters.Writer.WriteAttributeString( SegConstants.CmnType, SegConstants.ValueInterpretation_Entry_Endianness_Little ); |
|
51 aParameters.Writer.WriteAttributeString( SegConstants.ValueInterpretation_Entry_Endianness_Bit0, SegConstants.ValueInterpretation_Entry_Endianness_Bit0_Right ); |
|
52 aParameters.Writer.WriteEndElement(); |
|
53 |
|
54 // Associated register |
|
55 CXmlNode.WriteLink( iValue.Register.Id, SegConstants.Registers, aParameters.Writer ); |
|
56 |
|
57 // Description |
|
58 aParameters.Writer.WriteElementString( SegConstants.ValueInterpretation_Entry_Description, iValue.Description ); |
|
59 } |
|
60 |
|
61 protected override void XmlSerializeChildren( CrashXmlPlugin.FileFormat.Document.CXmlDocumentSerializationParameters aParameters ) |
|
62 { |
|
63 aParameters.Writer.WriteStartElement( SegConstants.ValueInterpretation_Entry_Interpretation ); |
|
64 |
|
65 foreach ( CIElement child in iValue ) |
|
66 { |
|
67 if ( child is CIRegisterVisBit ) |
|
68 { |
|
69 WriteBit( aParameters.Writer, child as CIRegisterVisBit ); |
|
70 } |
|
71 else if ( child is CIRegisterVisBitGroup ) |
|
72 { |
|
73 WriteBitGroup( aParameters.Writer, child as CIRegisterVisBitGroup ); |
|
74 } |
|
75 else if ( child is CIRegisterVisBitRange ) |
|
76 { |
|
77 WriteBitRange( aParameters.Writer, child as CIRegisterVisBitRange ); |
|
78 } |
|
79 } |
|
80 |
|
81 aParameters.Writer.WriteEndElement(); |
|
82 } |
|
83 #endregion |
|
84 |
|
85 #region Properties |
|
86 #endregion |
|
87 |
|
88 #region Internal methods |
|
89 private void WriteBit( XmlWriter aWriter, CIRegisterVisBit aItem ) |
|
90 { |
|
91 aWriter.WriteStartElement( SegConstants.ValueInterpretation_Entry_Interpretation_Bit ); |
|
92 |
|
93 // Index |
|
94 aWriter.WriteAttributeString( SegConstants.CmnIndex, aItem.Index.ToString() ); |
|
95 |
|
96 // Value |
|
97 aWriter.WriteAttributeString( SegConstants.CmnValue, aItem.ToString() ); |
|
98 |
|
99 // Category |
|
100 aWriter.WriteAttributeString( SegConstants.ValueInterpretation_Entry_Category, aItem.Category ); |
|
101 |
|
102 // Reserved |
|
103 if ( aItem.IsReserved ) |
|
104 { |
|
105 aWriter.WriteAttributeString( SegConstants.CmnType, SegConstants.ValueInterpretation_Entry_Reserved ); |
|
106 } |
|
107 |
|
108 // Single character interpretation |
|
109 aWriter.WriteAttributeString( SegConstants.ValueInterpretation_Entry_Interpretation_Bit_Char, aItem.ValueCharacter ); |
|
110 |
|
111 // Interpretation |
|
112 if ( !string.IsNullOrEmpty( aItem.Interpretation ) ) |
|
113 { |
|
114 aWriter.WriteAttributeString( SegConstants.ValueInterpretation_Entry_Interpretation, aItem.Interpretation ); |
|
115 } |
|
116 |
|
117 aWriter.WriteEndElement(); |
|
118 } |
|
119 |
|
120 private void WriteBitGroup( XmlWriter aWriter, CIRegisterVisBitGroup aItem ) |
|
121 { |
|
122 aWriter.WriteStartElement( SegConstants.ValueInterpretation_Entry_Interpretation_BitGroup ); |
|
123 |
|
124 foreach ( CIRegisterVisBit bit in aItem ) |
|
125 { |
|
126 WriteBit( aWriter, bit ); |
|
127 } |
|
128 |
|
129 aWriter.WriteEndElement(); |
|
130 } |
|
131 |
|
132 private void WriteBitRange( XmlWriter aWriter, CIRegisterVisBitRange aItem ) |
|
133 { |
|
134 aWriter.WriteStartElement( SegConstants.ValueInterpretation_Entry_Interpretation_BitRange ); |
|
135 |
|
136 // Start & end |
|
137 aWriter.WriteAttributeString( SegConstants.CmnStart, aItem.Range.Min.ToString() ); |
|
138 aWriter.WriteAttributeString( SegConstants.CmnEnd, aItem.Range.Max.ToString() ); |
|
139 |
|
140 // Value |
|
141 aWriter.WriteAttributeString( SegConstants.CmnValue, aItem.ToString() ); |
|
142 |
|
143 // Category |
|
144 aWriter.WriteAttributeString( SegConstants.ValueInterpretation_Entry_Category, aItem.Category ); |
|
145 |
|
146 // Reserved |
|
147 if ( aItem.IsReserved ) |
|
148 { |
|
149 aWriter.WriteAttributeString( SegConstants.CmnType, SegConstants.ValueInterpretation_Entry_Reserved ); |
|
150 } |
|
151 |
|
152 // Interpretation |
|
153 string interpretation = aItem.Interpretation; |
|
154 if ( !string.IsNullOrEmpty( interpretation ) ) |
|
155 { |
|
156 aWriter.WriteAttributeString( SegConstants.ValueInterpretation_Entry_Interpretation, interpretation ); |
|
157 } |
|
158 |
|
159 aWriter.WriteEndElement(); |
|
160 } |
|
161 #endregion |
|
162 |
|
163 #region Data members |
|
164 private readonly CIRegisterVisualization iValue; |
|
165 #endregion |
|
166 } |
|
167 } |