|
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 "ssmstatepolicyframe.h" |
|
18 |
|
19 #include "ssmdebug.h" |
|
20 #include "ssmserverpanic.h" |
|
21 |
|
22 |
|
23 /** |
|
24 */ |
|
25 typedef MSsmStatePolicy* (*TFuncStateNewL)(void); |
|
26 |
|
27 /** |
|
28 */ |
|
29 CSsmStatePolicyFrame::CSsmStatePolicyFrame() |
|
30 { |
|
31 } |
|
32 |
|
33 /** |
|
34 */ |
|
35 CSsmStatePolicyFrame::CSsmStatePolicyFrame(MSsmStatePolicy* aStatePolicy) |
|
36 : iStatePolicy(aStatePolicy) |
|
37 { |
|
38 } |
|
39 |
|
40 /** |
|
41 */ |
|
42 CSsmStatePolicyFrame* CSsmStatePolicyFrame::NewL(TLibraryFunction aNewLFunc) |
|
43 { |
|
44 CSsmStatePolicyFrame* self = new (ELeave) CSsmStatePolicyFrame(); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(aNewLFunc); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 /** |
|
52 */ |
|
53 void CSsmStatePolicyFrame::ConstructL(TLibraryFunction aNewLFunc) |
|
54 { |
|
55 TFuncStateNewL newL = reinterpret_cast<TFuncStateNewL>( aNewLFunc ); |
|
56 iStatePolicy = newL(); |
|
57 #ifdef _DEBUG |
|
58 if(!iStatePolicy) |
|
59 { |
|
60 DEBUGPRINT1(_L("First function in State Policy DLL didn't create a new instance")); |
|
61 } |
|
62 #endif |
|
63 SSMLOGLEAVEIFNULL(iStatePolicy); |
|
64 } |
|
65 |
|
66 /** |
|
67 */ |
|
68 CSsmStatePolicyFrame::~CSsmStatePolicyFrame() |
|
69 { |
|
70 //Let the derived implementation handle its own destruction |
|
71 if(iStatePolicy) |
|
72 { |
|
73 iStatePolicy->Release(); |
|
74 iStatePolicy = NULL; |
|
75 } |
|
76 } |
|
77 |
|
78 /** |
|
79 Returns the major state handled by this DLL. |
|
80 The value returned is read from the DLL filename |
|
81 */ |
|
82 TUint16 CSsmStatePolicyFrame::StatePolicyId() const |
|
83 { |
|
84 return iStatePolicyId; |
|
85 } |
|
86 |
|
87 /** |
|
88 */ |
|
89 void CSsmStatePolicyFrame::SetStatePolicyId(TUint16 aMainState) |
|
90 { |
|
91 iStatePolicyId = aMainState; |
|
92 } |
|
93 |
|
94 /** |
|
95 */ |
|
96 void CSsmStatePolicyFrame::CallInitialize(TRequestStatus& aStatus) |
|
97 { |
|
98 __ASSERT_DEBUG(EInitialize == iNextAction, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError1)); |
|
99 __ASSERT_DEBUG(!iInitializeCalled, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError2)); |
|
100 __ASSERT_DEBUG(iStatePolicy, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError7)); |
|
101 if(iStatePolicy) |
|
102 { |
|
103 iStatePolicy->Initialize(aStatus); |
|
104 iInitializeCalled = ETrue; |
|
105 iNextAction = EPrepare; |
|
106 } |
|
107 } |
|
108 |
|
109 /** |
|
110 */ |
|
111 void CSsmStatePolicyFrame::CallInitializeCancel() |
|
112 { |
|
113 __ASSERT_DEBUG(iStatePolicy, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError8)); |
|
114 if(iStatePolicy) |
|
115 { |
|
116 iStatePolicy->InitializeCancel(); |
|
117 iNextAction = EInitialize; |
|
118 } |
|
119 } |
|
120 |
|
121 /** |
|
122 */ |
|
123 MSsmStatePolicy::TResponse CSsmStatePolicyFrame::CallTransitionAllowed(const TSsmStateTransition& aRequest, TSsmStateTransition const* aCurrent, TSsmStateTransition const* aQueued, const RMessagePtr2& aMessage) |
|
124 { |
|
125 MSsmStatePolicy::TResponse response = MSsmStatePolicy::ENotAllowed; |
|
126 __ASSERT_DEBUG(iStatePolicy, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError10)); |
|
127 if(iStatePolicy) |
|
128 { |
|
129 response = iStatePolicy->TransitionAllowed(aRequest, aCurrent, aQueued, aMessage); |
|
130 } |
|
131 return response; |
|
132 } |
|
133 |
|
134 /** |
|
135 */ |
|
136 void CSsmStatePolicyFrame::CallPrepareCommandList(TSsmState aState, TInt aReason, TRequestStatus& aStatus) |
|
137 { |
|
138 __ASSERT_DEBUG(EPrepare == iNextAction || ENext == iNextAction, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError3)); |
|
139 __ASSERT_DEBUG(aState.MainState() == iStatePolicyId, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError4)); |
|
140 __ASSERT_DEBUG(iStatePolicy, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError11)); |
|
141 if(iStatePolicy) |
|
142 { |
|
143 iStatePolicy->PrepareCommandList(aState, aReason, aStatus); |
|
144 iNextAction = EGet; |
|
145 } |
|
146 } //lint !e1746 Suppress parameter 'aState' could be made const reference |
|
147 |
|
148 /** |
|
149 */ |
|
150 void CSsmStatePolicyFrame::CallPrepareCommandListCancel() |
|
151 { |
|
152 __ASSERT_DEBUG(iStatePolicy, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError12)); |
|
153 if(iStatePolicy) |
|
154 { |
|
155 iStatePolicy->PrepareCommandListCancel(); |
|
156 iNextAction = EPrepare; |
|
157 } |
|
158 } |
|
159 |
|
160 /** |
|
161 */ |
|
162 CSsmCommandList* CSsmStatePolicyFrame::CallCommandList() |
|
163 { |
|
164 __ASSERT_DEBUG(EGet == iNextAction, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError5)); |
|
165 __ASSERT_DEBUG(iStatePolicy, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError13)); |
|
166 CSsmCommandList* list = NULL; |
|
167 if(iStatePolicy) |
|
168 { |
|
169 list = iStatePolicy->CommandList(); |
|
170 iNextAction = ENext; |
|
171 } |
|
172 return list; |
|
173 } |
|
174 |
|
175 /** |
|
176 */ |
|
177 TBool CSsmStatePolicyFrame::CallGetNextState(TSsmState aCurrentTransition, TInt aReason, TInt aError, TInt aSeverity, TSsmState& aNextState) |
|
178 { |
|
179 __ASSERT_DEBUG(ENext == iNextAction, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError6)); |
|
180 __ASSERT_DEBUG(iStatePolicy, PanicNow(KPanicSysStateMgr,ESsmStatePolicyError14)); |
|
181 TBool moreToCome = EFalse; |
|
182 if(iStatePolicy) |
|
183 { |
|
184 moreToCome = iStatePolicy->GetNextState(aCurrentTransition, aReason, aError, aSeverity, aNextState); |
|
185 iNextAction = EPrepare; |
|
186 } |
|
187 return moreToCome; |
|
188 } //lint !e1746 Suppress parameter 'aCurrentTransition' could be made const reference |
|
189 |