|
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 // |
|
15 |
|
16 #include "StartupState.h" |
|
17 #include <domainmanager.h> |
|
18 #include <startup.hrh> |
|
19 #include "StartupStateInfo.h" |
|
20 #include "StartupCommand.h" |
|
21 #include "startupdomaindefs.h" |
|
22 |
|
23 #include "SysStartDebug.h" |
|
24 |
|
25 #include "sysstartpanic.h" |
|
26 #include "restartsys.h" |
|
27 |
|
28 // |
|
29 // Standard Symbian factory functions |
|
30 // |
|
31 |
|
32 CStartupState* CStartupState::NewL(const MStartupStateInfo& aInfo) |
|
33 { |
|
34 CStartupState* self = CStartupState::NewLC(aInfo); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 CStartupState* CStartupState::NewLC(const MStartupStateInfo& aInfo) |
|
40 { |
|
41 CStartupState* self = new (ELeave) CStartupState(aInfo); |
|
42 CleanupStack::PushL(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // |
|
47 // Public functions |
|
48 // |
|
49 |
|
50 void CStartupState::Start() |
|
51 { |
|
52 TPtrC stateName = iStateInfo.Name(); |
|
53 |
|
54 // Connect to the domain manager in order to notify state transition |
|
55 RDmDomainManager notifier; |
|
56 TInt r = notifier.Connect(KDmHierarchyIdStartup); |
|
57 if (r == KErrNone) |
|
58 { |
|
59 //TRequestStatus is used in the while-loop and the loop should be run for the first time, |
|
60 //so its intial value is set to KErrGeneral.. |
|
61 TRequestStatus stateNotifyStatus = KErrGeneral; |
|
62 |
|
63 // Find out from the value provisioned in the startup configuration file (SSC) |
|
64 // how many times to re-attempt state change following a state transition failure. |
|
65 TInt attemptsRequired = iStateInfo.NoOfRetries() + 1; |
|
66 |
|
67 while ((stateNotifyStatus != KErrNone) && (attemptsRequired-- >0)) |
|
68 { |
|
69 // Request a state change from the domain manager |
|
70 DEBUGPRINT2(_L("SysStart: Send state transition request (move to %S) to domain manager"), &stateName); |
|
71 notifier.RequestSystemTransition(iStateInfo.StateId(), |
|
72 ETraverseParentsFirst, stateNotifyStatus); |
|
73 |
|
74 // Wait for result of the state change |
|
75 User::WaitForRequest(stateNotifyStatus); |
|
76 DEBUGPRINT2(_L("SysStart: Result of state transition request is %d"), stateNotifyStatus.Int() ); |
|
77 } |
|
78 |
|
79 // If state transition has failed after the specified no of retries, |
|
80 // take action as specified in the SSC |
|
81 if (stateNotifyStatus != KErrNone) |
|
82 { |
|
83 // Value in configuration file can be set to panic or ignore. |
|
84 if (iStateInfo.ActionOnStateTransitionFailure() == EPanicOnFailure) |
|
85 { |
|
86 DEBUGPRINT2(_L("SysStart: State transition to %S failed"), &stateName); |
|
87 |
|
88 // RestartSys will be used to trigger system restart. |
|
89 TInt ret = RestartSys::RestartSystem(); |
|
90 if (ret != KErrNone) |
|
91 { |
|
92 DEBUGPRINT2(_L("SysStart: RestartSystem failed with error %d"), ret); |
|
93 PanicNow(KPanicStartupState, ERestartSystemCallFailed); |
|
94 } |
|
95 |
|
96 User::After(5000000); // required by RestartSys API, see comments in RestartSys::RestartSystem() |
|
97 } |
|
98 else |
|
99 { |
|
100 DEBUGPRINT2(_L("SysStart: State transition to %S failed. Ignoring as specified in the SSC"), &stateName); |
|
101 } |
|
102 } |
|
103 |
|
104 notifier.Close(); |
|
105 } |
|
106 else // Domain manager connection failed. |
|
107 { |
|
108 DEBUGPRINT2(_L("SysStart: Domain manager connection failed with error %d"), r); |
|
109 PanicNow(KPanicStartupState, EDomainManagerConnectionFailure); |
|
110 } |
|
111 |
|
112 // Execute the commands relevant to this state |
|
113 for (TInt i = 0; i < iStateInfo.Count(); ++i) |
|
114 { |
|
115 DoCommand(*(iStateInfo.GetCommand(i))); |
|
116 } |
|
117 } |
|
118 |
|
119 // |
|
120 // Private functions |
|
121 // |
|
122 |
|
123 CStartupState::CStartupState(const MStartupStateInfo& aInfo) : |
|
124 iStateInfo(aInfo) |
|
125 { |
|
126 } |
|
127 |
|
128 void CStartupState::DoCommand(MStartupCommand& aCommand) |
|
129 { |
|
130 TRequestStatus status; |
|
131 aCommand.Execute(status); |
|
132 User::WaitForRequest(status); |
|
133 |
|
134 if (status!=KErrNone) |
|
135 { |
|
136 DEBUGPRINT2(_L("SSC command failed with error %d"), status.Int()); |
|
137 } |
|
138 } |