|
1 // Copyright (c) 2005-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 // Implementation of CSchStartupStateMgr class which connects to |
|
15 // the Domain manager to keep aware of the current start-up |
|
16 // state and distributes the state changes to registered observers. |
|
17 // |
|
18 // |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 */ |
|
24 |
|
25 #include "SchSSAMan.h" |
|
26 #include "SchLogger.h" |
|
27 |
|
28 /** |
|
29 constructor of CSchStartupStateMgr |
|
30 @internalComponent |
|
31 */ |
|
32 CSchStartupStateMgr::CSchStartupStateMgr(TDmHierarchyId aHierarchyId, TDmDomainId aDomainId) : |
|
33 CDmDomain(aHierarchyId,aDomainId), |
|
34 iCurrentStartupState(EStartupStateUndefined) |
|
35 { |
|
36 } |
|
37 |
|
38 /** |
|
39 destructor of CSchStartupStateMgr |
|
40 @internalComponent |
|
41 */ |
|
42 CSchStartupStateMgr::~CSchStartupStateMgr() |
|
43 { |
|
44 Cancel(); |
|
45 iObserverList.Reset(); |
|
46 } |
|
47 |
|
48 /** |
|
49 Getter |
|
50 @internalComponent |
|
51 @return the current startup state |
|
52 */ |
|
53 TStartupStateIdentifier CSchStartupStateMgr::CurrentStartupState() |
|
54 { |
|
55 return iCurrentStartupState; |
|
56 } |
|
57 |
|
58 /** |
|
59 updates the MSchStartupStateObserver objects. |
|
60 @internalComponent |
|
61 */ |
|
62 void CSchStartupStateMgr::UpdateStateAwareObjectsL(TStartupStateIdentifier aKnownState) |
|
63 { |
|
64 for (TInt i = 0; i < iObserverList.Count(); i++) |
|
65 { |
|
66 iObserverList[i]->ProcessSSAEventL(aKnownState); |
|
67 } |
|
68 } |
|
69 |
|
70 /** |
|
71 This method takes a a startup state which can be user defined |
|
72 state and maps it to a known startup state (KSS). KSS are |
|
73 Symbian defined states: undefined, critical static, critical dynamic, |
|
74 and non-critical. |
|
75 User defined states are refered to as USS - unknown startup state. |
|
76 |
|
77 @internalComponent |
|
78 */ |
|
79 TStartupStateIdentifier CSchStartupStateMgr::GetKnownStartupState(TDmDomainState aStartupState) |
|
80 { |
|
81 TStartupStateIdentifier knownStartupState = iCurrentStartupState; |
|
82 |
|
83 if (aStartupState >= EStartupStateNonCritical) |
|
84 { |
|
85 knownStartupState = EStartupStateNonCritical; |
|
86 } |
|
87 else if(aStartupState >= EStartupStateCriticalDynamic) |
|
88 { |
|
89 knownStartupState = EStartupStateCriticalDynamic; |
|
90 } |
|
91 else if(aStartupState >= EStartupStateCriticalStatic) |
|
92 { |
|
93 knownStartupState = EStartupStateCriticalStatic; |
|
94 } |
|
95 else |
|
96 { |
|
97 knownStartupState = EStartupStateUndefined; |
|
98 } |
|
99 |
|
100 return knownStartupState; |
|
101 } |
|
102 |
|
103 /** |
|
104 Register the MSchStartupStateObserver object with the CServerStartupMgr. |
|
105 @internalComponent |
|
106 @param aObs the pointer to the MStartupStateObserver object to be registered with CServerStartupMgr. |
|
107 */ |
|
108 void CSchStartupStateMgr::RegisterObserverL(const MSchStartupStateObserver* aObs) |
|
109 { |
|
110 User::LeaveIfError(iObserverList.Append(aObs)); |
|
111 } |
|
112 |
|
113 /** |
|
114 Handle the error if RunL leaves. Just tell the observers that |
|
115 we have reached the final state. |
|
116 |
|
117 @internalComponent |
|
118 @param aError error code generated by the RunL(), not used here. |
|
119 @return KErrNone to avoid CActiveScheduler to panic. |
|
120 */ |
|
121 TInt CSchStartupStateMgr::RunError(TInt /*aError*/) |
|
122 { |
|
123 LOGSTRING("CSchStartupStateMgr::RunL() leaves, set SS to final state."); |
|
124 TRAP_IGNORE(UpdateStateAwareObjectsL(KSchFinalStartupState)); |
|
125 return KErrNone; |
|
126 } |
|
127 |
|
128 /** |
|
129 Finsish constructing the CSchStartupStateMgr and start |
|
130 interacting with Domain Manager to receive startup state |
|
131 changes. |
|
132 All observers should have been registered before calling this method |
|
133 |
|
134 @internalComponent |
|
135 */ |
|
136 void CSchStartupStateMgr::InitialiseL() |
|
137 { |
|
138 TRAPD(err, CDmDomain::ConstructL()); |
|
139 if (err != KErrNone) |
|
140 { |
|
141 // the ConstructL leaves, go to final state |
|
142 LOGSTRING2("CDmDomain::ConstructL leaves with %d. Goto final state", err); |
|
143 UpdateStateAwareObjectsL(KSchFinalStartupState); |
|
144 iCurrentStartupState = KSchFinalStartupState; |
|
145 return; |
|
146 } |
|
147 |
|
148 // Typical pattern of using P&S is to subscribe first then get |
|
149 // current state. Example implementation given |
|
150 // in SSA Adaptation How-to also does it this way. |
|
151 RequestTransitionNotification(); |
|
152 |
|
153 // get the start up state from the Domain Manager. |
|
154 TDmDomainState rawstate = GetState(); |
|
155 |
|
156 // rawstate may be user defined. Map to known states. |
|
157 TStartupStateIdentifier nextKnownState = GetKnownStartupState(rawstate); |
|
158 |
|
159 // NB: nextKnownState can be KStartupStateUndefined for 2 reasons. |
|
160 // One is rawstate == 0 which we must check first. Second: |
|
161 // rawstate is user defined values lower than critical static. In |
|
162 // the second case we must wait for next state change. |
|
163 if (rawstate == EStartupStateUndefined || |
|
164 nextKnownState == KSchFinalStartupState) |
|
165 { |
|
166 // If either something wrong with DM or final state is reached, |
|
167 // go to final state |
|
168 iCurrentStartupState = KSchFinalStartupState; |
|
169 UpdateStateAwareObjectsL(KSchFinalStartupState); |
|
170 Cancel(); |
|
171 return; |
|
172 } |
|
173 |
|
174 iCurrentStartupState = nextKnownState; |
|
175 } |
|
176 |
|
177 /** |
|
178 Executed when the startup state change is done, it does the |
|
179 same thing as the method InitialiseL() does |
|
180 @internalComponent |
|
181 */ |
|
182 void CSchStartupStateMgr::RunL() |
|
183 { |
|
184 if(iStatus != KErrNone) // something wrong with the RequestTransitionNotification(). |
|
185 { |
|
186 AcknowledgeLastState(iStatus.Int()); //Acknowledge the domainmanager in case of leaving, this to avoid the acknowledgement in RunError() |
|
187 User::LeaveIfError(iStatus.Int()); //RunError will handle this. |
|
188 } |
|
189 |
|
190 RequestTransitionNotification(); |
|
191 |
|
192 TDmDomainState rawstate = GetState(); |
|
193 |
|
194 // Must first check the case rawstate == undefined and deal with it here. |
|
195 // GetKnowStartupState maps 1 to 15 to EStartupStateUndefined |
|
196 // which means a SS before critical static. It does not mean go |
|
197 // to final state. |
|
198 |
|
199 //If the rawstate is EStartupStateUndefined there must be sth wrong. |
|
200 if(rawstate == EStartupStateUndefined) |
|
201 { |
|
202 Cancel(); |
|
203 AcknowledgeLastState(KErrBadHandle); |
|
204 User::Leave(KErrBadHandle); //RunError will handle this. |
|
205 } |
|
206 |
|
207 // get the known state |
|
208 TStartupStateIdentifier nextKnownState = GetKnownStartupState(rawstate); |
|
209 |
|
210 //Tell domain manager that we have processed the last state change before starting any time consuming work. |
|
211 AcknowledgeLastState(KErrNone); |
|
212 |
|
213 //Sleep 2 tickperiods this allows the acknowledgement reach the domain manager. |
|
214 TTimeIntervalMicroSeconds32 tickPeriod; |
|
215 UserHal::TickPeriod(tickPeriod); |
|
216 User::After(2*tickPeriod.Int()); |
|
217 |
|
218 // Schsvr only want to know transition to non-critical. |
|
219 // Ignore all states below that level. |
|
220 if (iCurrentStartupState < KSchFinalStartupState && nextKnownState == KSchFinalStartupState) |
|
221 { |
|
222 UpdateStateAwareObjectsL(nextKnownState); |
|
223 } |
|
224 |
|
225 iCurrentStartupState = nextKnownState; |
|
226 |
|
227 //do not request transition notification if we have reached the last state |
|
228 if(iCurrentStartupState == KSchFinalStartupState) |
|
229 { |
|
230 Cancel(); |
|
231 } |
|
232 } |