|
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.Collections.Generic; |
|
20 using System.Text; |
|
21 using CrashDebuggerLib.Structures.KernelObjects; |
|
22 |
|
23 namespace CrashDebuggerLib.Structures.Common |
|
24 { |
|
25 public class Capability |
|
26 { |
|
27 #region Enumerations |
|
28 [Flags, System.ComponentModel.TypeConverter( typeof( SymbianParserLib.TypeConverters.SymbianEnumConverter ) )] |
|
29 public enum TCapability : ulong |
|
30 { |
|
31 ECapabilityNone = 0x00000000000, |
|
32 ECapabilityTCB = 0x00000000001, |
|
33 ECapabilityCommDD = 0x00000000002, |
|
34 ECapabilityPowerMgmt = 0x00000000004, |
|
35 ECapabilityMultimediaDD = 0x00000000008, |
|
36 ECapabilityReadDeviceData = 0x00000000010, |
|
37 ECapabilityWriteDeviceData = 0x00000000020, |
|
38 ECapabilityDRM = 0x00000000040, |
|
39 ECapabilityTrustedUI = 0x00000000080, |
|
40 ECapabilityProtServ = 0x00000000100, |
|
41 ECapabilityDiskAdmin = 0x00000000200, |
|
42 ECapabilityNetworkControl = 0x00000000400, |
|
43 ECapabilityAllFiles = 0x00000000800, |
|
44 ECapabilitySwEvent = 0x00000001000, |
|
45 ECapabilityNetworkServices = 0x00000002000, |
|
46 ECapabilityLocalServices = 0x00000004000, |
|
47 ECapabilityReadUserData = 0x00000008000, |
|
48 ECapabilityLocation = 0x00000010000, |
|
49 ECapabilityWriteUserData = 0x00000020000, |
|
50 ECapabilitySurroundingsDD = 0x00000040000, |
|
51 ECapabilityUserEnvironment = 0x00000080000, |
|
52 } |
|
53 #endregion |
|
54 |
|
55 #region Constructors |
|
56 public Capability() |
|
57 : this( TCapability.ECapabilityNone ) |
|
58 { |
|
59 } |
|
60 |
|
61 public Capability( TCapability aCapability ) |
|
62 { |
|
63 iCaps = aCapability; |
|
64 } |
|
65 |
|
66 public Capability( long aValue ) |
|
67 { |
|
68 TCapability cap = (TCapability) aValue; |
|
69 iCaps = cap; |
|
70 } |
|
71 #endregion |
|
72 |
|
73 #region API |
|
74 public void Add( TCapability aCapability ) |
|
75 { |
|
76 ulong addVal = (ulong) aCapability; |
|
77 ulong curVal = (ulong) iCaps; |
|
78 ulong combin = addVal | curVal; |
|
79 // |
|
80 iCaps = (TCapability) combin; |
|
81 } |
|
82 |
|
83 public void Remove( TCapability aCapability ) |
|
84 { |
|
85 ulong remVal = (ulong) aCapability; |
|
86 ulong combin = (ulong) iCaps; |
|
87 combin &= remVal; |
|
88 // |
|
89 iCaps = (TCapability) combin; |
|
90 } |
|
91 |
|
92 /* |
|
93 public static string ToString( TCapability aCapability ) |
|
94 { |
|
95 |
|
96 string ret = KCapabilityNames[ (int) aCapability ]; |
|
97 return ret; |
|
98 }*/ |
|
99 #endregion |
|
100 |
|
101 #region Properties |
|
102 public uint LowDWord |
|
103 { |
|
104 get |
|
105 { |
|
106 ulong val = (ulong) iCaps; |
|
107 ulong masked = val & 0x00000000FFFFFFFF; |
|
108 uint ret = (uint) masked; |
|
109 return ret; |
|
110 } |
|
111 set |
|
112 { |
|
113 ulong val = HighDWord | value; |
|
114 iCaps = (TCapability) val; |
|
115 } |
|
116 } |
|
117 |
|
118 public uint HighDWord |
|
119 { |
|
120 get |
|
121 { |
|
122 ulong val = (ulong) iCaps; |
|
123 ulong masked = val & 0xFFFFFFFF00000000; |
|
124 uint ret = (uint) ( masked >> 8 ); |
|
125 return ret; |
|
126 } |
|
127 set |
|
128 { |
|
129 ulong val = ( value << 8 ) | LowDWord; |
|
130 iCaps = (TCapability) val; |
|
131 } |
|
132 } |
|
133 |
|
134 public ulong RawValue |
|
135 { |
|
136 get { return (ulong) iCaps; } |
|
137 set { iCaps = (TCapability) value; } |
|
138 } |
|
139 |
|
140 public TCapability Value |
|
141 { |
|
142 get { return iCaps; } |
|
143 set { iCaps = value; } |
|
144 } |
|
145 #endregion |
|
146 |
|
147 #region Internal methods |
|
148 /*private static long MakeValue( TCapability aCapability ) |
|
149 { |
|
150 int shiftAmount = (int) aCapability; |
|
151 long ret = 1L << shiftAmount; |
|
152 return ret; |
|
153 } |
|
154 |
|
155 private static void ValidateCapability( TCapability aCapability ) |
|
156 { |
|
157 if ( aCapability < 0 || aCapability >= TCapability.ECapability_Limit ) |
|
158 { |
|
159 throw new ArgumentException( "Capability is out of range: " + aCapability.ToString() ); |
|
160 } |
|
161 }*/ |
|
162 #endregion |
|
163 |
|
164 #region Internal constants |
|
165 private const int KMaxBitIndex = 64; |
|
166 private static readonly string[] KCapabilityNames = new string[] |
|
167 { |
|
168 "TCB", |
|
169 "CommDD", |
|
170 "PowerMgmt", |
|
171 "MultimediaDD", |
|
172 "ReadDeviceData", |
|
173 "WriteDeviceData", |
|
174 "DRM", |
|
175 "TrustedUI", |
|
176 "ProtServ", |
|
177 "DiskAdmin", |
|
178 "NetworkControl", |
|
179 "AllFiles", |
|
180 "SwEvent", |
|
181 "NetworkServices", |
|
182 "LocalServices", |
|
183 "ReadUserData", |
|
184 "WriteUserData", |
|
185 "Location", |
|
186 "SurroundingsDD", |
|
187 "UserEnvironment", |
|
188 }; |
|
189 #endregion |
|
190 |
|
191 #region From System.Object |
|
192 public override string ToString() |
|
193 { |
|
194 StringBuilder ret = new StringBuilder(); |
|
195 // |
|
196 for( int i=0; i<KMaxBitIndex; i++ ) |
|
197 { |
|
198 ulong checkVal = (ulong) 1 << i; |
|
199 if ( ( checkVal & RawValue ) == checkVal ) |
|
200 { |
|
201 string name = KCapabilityNames[ i ]; |
|
202 // |
|
203 if ( ret.Length > 0 ) |
|
204 { |
|
205 ret.Append( ", " ); |
|
206 } |
|
207 // |
|
208 ret.Append( name ); |
|
209 } |
|
210 |
|
211 /* |
|
212 TCapability cap = (TCapability) i; |
|
213 long mask = MakeValue( cap ); |
|
214 long remainder = ( iValue & mask ); |
|
215 if ( remainder != 0 ) |
|
216 { |
|
217 string name = ToString( cap ); |
|
218 } |
|
219 */ |
|
220 } |
|
221 // |
|
222 return ret.ToString(); |
|
223 } |
|
224 #endregion |
|
225 |
|
226 #region Data members |
|
227 private TCapability iCaps = TCapability.ECapabilityNone; |
|
228 #endregion |
|
229 } |
|
230 } |