|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <ssm/ssmstate.h> |
|
17 #include "cmnpanic.h" |
|
18 |
|
19 /** |
|
20 Default constructor. Initialise this object to 0. |
|
21 */ |
|
22 EXPORT_C TSsmState::TSsmState() |
|
23 : iMainState(0), iSubState(0) |
|
24 { |
|
25 } |
|
26 |
|
27 /** |
|
28 Constructor taking aMainState and aSubState as two separate arguments. |
|
29 @param aMainState The main state to be assigned to this object. |
|
30 @param aSubState The sub state to be assigned to this object. |
|
31 */ |
|
32 EXPORT_C TSsmState::TSsmState(TSsmMainSystemStates aMainState, TUint16 aSubState) |
|
33 : iMainState(aMainState), iSubState(aSubState) |
|
34 { |
|
35 __ASSERT_DEBUG(aMainState <= ESsmMainSystemStateMax, User::Panic(KPanicSsmCmn, ECmnStateMaxValue1)); |
|
36 } |
|
37 |
|
38 /** |
|
39 Constructor taking aMainState and aSubState as two separate arguments. |
|
40 @param aMainState The main state to be assigned to this object. |
|
41 @param aSubState The sub state to be assigned to this object. |
|
42 */ |
|
43 EXPORT_C TSsmState::TSsmState(TUint16 aMainState, TUint16 aSubState) |
|
44 : iMainState(aMainState), iSubState(aSubState) |
|
45 { |
|
46 __ASSERT_DEBUG(aMainState <= ESsmMainSystemStateMax, User::Panic(KPanicSsmCmn, ECmnStateMaxValue2)); |
|
47 } |
|
48 |
|
49 /** |
|
50 Copy constructor. |
|
51 @param aState The value to be assigned to this object. |
|
52 */ |
|
53 EXPORT_C TSsmState::TSsmState(const TSsmState& aState) |
|
54 : iMainState(aState.iMainState), iSubState(aState.iSubState) |
|
55 { |
|
56 } |
|
57 |
|
58 /** |
|
59 @return The state as an unsigned integer |
|
60 */ |
|
61 EXPORT_C TUint16 TSsmState::MainState() const |
|
62 { |
|
63 return iMainState; |
|
64 } |
|
65 |
|
66 /** |
|
67 @return The substate as an unsigned integer |
|
68 */ |
|
69 EXPORT_C TUint16 TSsmState::SubState() const |
|
70 { |
|
71 return iSubState; |
|
72 } |
|
73 |
|
74 /** |
|
75 Set member data. |
|
76 @param aMainState The major state to be assigned to this object. |
|
77 @param aSubState The sub state to be assigned to this object. |
|
78 */ |
|
79 EXPORT_C void TSsmState::Set(TUint16 aMainState, TUint16 aSubState) |
|
80 { |
|
81 __ASSERT_DEBUG(aMainState <= ESsmMainSystemStateMax, User::Panic(KPanicSsmCmn, ECmnStateMaxValue3)); |
|
82 iMainState = aMainState; |
|
83 iSubState = aSubState; |
|
84 } |
|
85 |
|
86 /** |
|
87 @return An integer representing the value of this object. MainState is held in the upper 16 bits |
|
88 and SubState in the lower 16 bits. |
|
89 */ |
|
90 EXPORT_C TUint32 TSsmState::Int() const |
|
91 { |
|
92 return (iMainState<<16 | iSubState); |
|
93 } |
|
94 |
|
95 /** |
|
96 Set member data using a 32-bit unsigned integer. |
|
97 @param aState The composite value to be assigned to this object. |
|
98 */ |
|
99 EXPORT_C void TSsmState::SetFromInt(TUint32 aValue) |
|
100 { |
|
101 __ASSERT_DEBUG(((aValue & 0xFFFF0000)>>16) <= ESsmMainSystemStateMax, User::Panic(KPanicSsmCmn, ECmnStateMaxValue4)); |
|
102 iMainState = ((aValue & 0xFFFF0000)>>16); |
|
103 iSubState = (aValue & 0x0000FFFF); |
|
104 } |
|
105 |
|
106 /** |
|
107 Gives a textual description of the values assigned to this object. |
|
108 E.g. ESsmStartup.KSsmAnySubState is formated as 0000.FFFF |
|
109 @return A descriptor describing the TSsmState on the format XXXX.XXXX |
|
110 */ |
|
111 EXPORT_C TSsmStateName TSsmState::Name() const |
|
112 { |
|
113 TSsmStateName buf; |
|
114 buf.AppendNumFixedWidth(iMainState,EHex,4); |
|
115 buf.Append(TChar('.')); |
|
116 buf.AppendNumFixedWidth(iSubState,EHex,4); |
|
117 return(buf); |
|
118 } |
|
119 |
|
120 /** |
|
121 @param aState The value to be assigned to this object. |
|
122 @return A reference to this object. |
|
123 */ |
|
124 EXPORT_C TSsmState& TSsmState::operator=(const TSsmState& aState) |
|
125 { |
|
126 // protect against self assignment |
|
127 if( &aState == this) |
|
128 { |
|
129 return(*this); |
|
130 } |
|
131 |
|
132 // do assigment |
|
133 iMainState = aState.iMainState; |
|
134 iSubState = aState.iSubState; |
|
135 return(*this); |
|
136 } |
|
137 |
|
138 /** |
|
139 @param aState The value to be compared. |
|
140 @return True, if the values are equal; false otherwise. |
|
141 */ |
|
142 EXPORT_C TBool TSsmState::operator==(const TSsmState& aState) const |
|
143 { |
|
144 if(iSubState == KSsmAnySubState || aState.iSubState == KSsmAnySubState) |
|
145 { |
|
146 return (iMainState == aState.iMainState); |
|
147 } |
|
148 else |
|
149 { |
|
150 return ((iMainState == aState.iMainState) && (iSubState == aState.iSubState)); |
|
151 } |
|
152 } |
|
153 |
|
154 /** |
|
155 @param aState The value to be compared. |
|
156 @return True, if the values are not equal; false otherwise. |
|
157 */ |
|
158 EXPORT_C TBool TSsmState::operator!=(const TSsmState& aState) const |
|
159 { |
|
160 return !(*this == aState); |
|
161 } |