|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions are met: |
|
7 * |
|
8 * - Redistributions of source code must retain the above copyright notice, |
|
9 * this list of conditions and the following disclaimer. |
|
10 * - Redistributions in binary form must reproduce the above copyright notice, |
|
11 * this list of conditions and the following disclaimer in the documentation |
|
12 * and/or other materials provided with the distribution. |
|
13 * - Neither the name of Nokia Corporation nor the names of its contributors |
|
14 * may be used to endorse or promote products derived from this software |
|
15 * without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 * POSSIBILITY OF SUCH DAMAGE. |
|
28 * |
|
29 * Initial Contributors: |
|
30 * Nokia Corporation - initial contribution. |
|
31 * |
|
32 * Contributors: |
|
33 * |
|
34 * Description: |
|
35 * |
|
36 */ |
|
37 |
|
38 using System; |
|
39 using System.Collections.Generic; |
|
40 using System.Text; |
|
41 using SymbianUtils.RawItems; |
|
42 using HeapLib.Statistics; |
|
43 |
|
44 namespace HeapLib.Cells.Descriptors |
|
45 { |
|
46 public abstract class DescriptorAlgorithmBase |
|
47 { |
|
48 #region Constructors & destructor |
|
49 protected DescriptorAlgorithmBase( HeapStatistics aStats ) |
|
50 { |
|
51 iStats = aStats; |
|
52 } |
|
53 #endregion |
|
54 |
|
55 #region Framework API |
|
56 internal virtual bool IsDescriptor( HeapCell aCell, out DescriptorInfo aInfo ) |
|
57 { |
|
58 aInfo = null; |
|
59 iCell = aCell; |
|
60 // |
|
61 bool couldBeDescriptor = ( aCell.Symbol == null && RawItems.Count > 1 ); |
|
62 if ( couldBeDescriptor ) |
|
63 { |
|
64 int payloadLength = PayloadLengthWhenCellIsDescriptor; |
|
65 int possibleDescriptorLength = CalculatedDescriptorLength; |
|
66 // |
|
67 couldBeDescriptor = ( possibleDescriptorLength <= payloadLength ); |
|
68 // |
|
69 if ( couldBeDescriptor ) |
|
70 { |
|
71 // Need to make a descriptor info object just to get the type... |
|
72 DescriptorInfo info = new DescriptorInfo( aCell ); |
|
73 couldBeDescriptor = ( info.Type != HeapCell.TDescriptorType.EUnknown ); |
|
74 } |
|
75 } |
|
76 // |
|
77 return couldBeDescriptor; |
|
78 } |
|
79 #endregion |
|
80 |
|
81 #region Properties |
|
82 protected HeapCell Cell |
|
83 { |
|
84 get { return iCell; } |
|
85 } |
|
86 |
|
87 protected RawItemCollection RawItems |
|
88 { |
|
89 get { return Cell.RawItems; } |
|
90 } |
|
91 |
|
92 protected HeapStatistics Statistics |
|
93 { |
|
94 get { return iStats; } |
|
95 } |
|
96 |
|
97 protected int PayloadLengthWhenCellIsDescriptor |
|
98 { |
|
99 get |
|
100 { |
|
101 // Layout is: |
|
102 // |
|
103 // First DWORD: |
|
104 // |
|
105 // < 4 bits> Type |
|
106 // <28 bits> Length |
|
107 // |
|
108 // Second DWORD: |
|
109 // |
|
110 // Max Length |
|
111 // |
|
112 // Reduce the size by 4 since we discard the descriptor length |
|
113 int payloadLength = (int) Cell.PayloadLength - 4; |
|
114 return payloadLength; |
|
115 } |
|
116 } |
|
117 |
|
118 protected int CalculatedDescriptorLength |
|
119 { |
|
120 get |
|
121 { |
|
122 uint vTable = Cell.PossibleVTableAddress; |
|
123 uint len = vTable & KDescriptorLengthMask; |
|
124 return (int) len; |
|
125 } |
|
126 } |
|
127 |
|
128 protected int CalculatedDescriptorMaxLength |
|
129 { |
|
130 get |
|
131 { |
|
132 System.Diagnostics.Debug.Assert( RawItems.Count >= 2 ); |
|
133 RawItem maxLenRI = Cell.RawItems[ 1 ]; |
|
134 int maxLength = (int) maxLenRI.Data; |
|
135 return maxLength; |
|
136 } |
|
137 } |
|
138 #endregion |
|
139 |
|
140 #region Shared constants |
|
141 protected const int KDescriptorRawItemOffsetAfterLengthAndType = 1; |
|
142 protected const int KDescriptorTextMaxLength = 256; |
|
143 protected const byte KDescriptorPaddingMagicCharacterValue = 0xa5; |
|
144 protected const uint KDescriptorLengthMask = 0x00FFFFFF; |
|
145 #endregion |
|
146 |
|
147 #region Data members |
|
148 private readonly HeapStatistics iStats; |
|
149 private HeapCell iCell = new HeapCell(); |
|
150 #endregion |
|
151 } |
|
152 } |