|
1 // Copyright (c) 2000-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 // MsvSysAgentCondAction.CPP |
|
15 // |
|
16 // |
|
17 |
|
18 #ifdef _DEBUG |
|
19 #undef _MSG_NO_LOGGING |
|
20 #endif |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <e32std.h> |
|
24 |
|
25 #include <e32property.h> |
|
26 |
|
27 #include <msvsenderroraction.h> |
|
28 #include <msvschedulesend.h> |
|
29 #include <msvsysagentaction.h> |
|
30 #include <schsend_panic.h> |
|
31 |
|
32 #ifndef _MSG_NO_LOGGING |
|
33 #include <flogger.h> |
|
34 _LIT(KSysAgentActionsLog, "sysagent.txt"); |
|
35 #endif |
|
36 |
|
37 |
|
38 /** |
|
39 Default constructor. |
|
40 */ |
|
41 |
|
42 EXPORT_C TMsvSysAgentConditionAction::TMsvSysAgentConditionAction() |
|
43 { |
|
44 iUseDefaultSysAgentAction = ETrue; |
|
45 } |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 /** |
|
51 Constructor. |
|
52 */ |
|
53 |
|
54 |
|
55 EXPORT_C CMsvSysAgentActions::CMsvSysAgentActions() |
|
56 : CArrayFixFlat<TMsvSysAgentConditionAction>(KMsvSchsendArrayGrowth) |
|
57 |
|
58 { |
|
59 } |
|
60 |
|
61 |
|
62 /** |
|
63 Destructor. |
|
64 */ |
|
65 |
|
66 |
|
67 EXPORT_C CMsvSysAgentActions::~CMsvSysAgentActions() |
|
68 { |
|
69 } |
|
70 |
|
71 |
|
72 /** |
|
73 Tests if system agent conditions are met. |
|
74 |
|
75 @param aErrorAction |
|
76 On return, error action to use. |
|
77 |
|
78 @return True if conditions are met, else false. |
|
79 |
|
80 @leave One of the system-wide error codes |
|
81 RSystemAgent::Connect() returned an error. |
|
82 */ |
|
83 |
|
84 EXPORT_C TBool CMsvSysAgentActions::ConditionsMetL(TMsvSendErrorAction& aErrorAction) |
|
85 { |
|
86 aErrorAction = iDefault; |
|
87 TBool retVal = ETrue; |
|
88 |
|
89 |
|
90 CArrayFixFlat<TUid>* uids = new (ELeave) CArrayFixFlat<TUid>(KMsvSchsendArrayGrowth); |
|
91 CleanupStack::PushL(uids); |
|
92 |
|
93 CArrayFixFlat<TInt>* states = new (ELeave) CArrayFixFlat<TInt>(KMsvSchsendArrayGrowth); |
|
94 CleanupStack::PushL(states); |
|
95 |
|
96 GetConditionVariablesL(*uids); |
|
97 |
|
98 TInt count = uids->Count(); |
|
99 |
|
100 states->ResizeL(count); |
|
101 for(TInt i = 0; i < count; ++i) |
|
102 { |
|
103 TInt val = 0; |
|
104 TInt uid = (*uids)[i].iUid; |
|
105 |
|
106 User::LeaveIfError(RProperty::Get(KUidSystemCategory, uid, val)); |
|
107 |
|
108 states->At(i) = val; |
|
109 } |
|
110 |
|
111 retVal = CheckStates(*states, aErrorAction); |
|
112 |
|
113 CleanupStack::PopAndDestroy(2); |
|
114 |
|
115 return retVal; |
|
116 } |
|
117 |
|
118 |
|
119 void CMsvSysAgentActions::GetConditionVariablesL(CArrayFix<TUid>& aUids) const |
|
120 { |
|
121 TInt count = Count(); |
|
122 |
|
123 for (TInt curCond = 0; curCond < count; curCond++) //order important, therefore not a while loop |
|
124 { |
|
125 TMsvSysAgentConditionAction condAction = At(curCond); |
|
126 aUids.AppendL(condAction.iCondition.iVariable); |
|
127 } |
|
128 } |
|
129 |
|
130 |
|
131 TBool CMsvSysAgentActions::CheckStates(const CArrayFix<TInt>& aStates, TMsvSendErrorAction& aErrorAction) const |
|
132 { |
|
133 aErrorAction = iDefault; |
|
134 TBool retVal = ETrue; |
|
135 TBool useDefault = ETrue; |
|
136 TInt count = Count(); |
|
137 |
|
138 for (TInt curCond = 0; curCond < count; curCond++) //order important, therefore not a while loop |
|
139 { |
|
140 TMsvSysAgentConditionAction condAction = At(curCond); |
|
141 TInt state = aStates.At(curCond); |
|
142 |
|
143 #ifndef _MSG_NO_LOGGING |
|
144 RFileLogger::WriteFormat(KSchSendLogDir, KSysAgentActionsLog, EFileLoggingModeAppend, _L("Cond: %d, Type %d, Expected %d, Actual %d"), condAction.iCondition.iVariable.iUid, condAction.iCondition.iType, condAction.iCondition.iState, state); |
|
145 #endif |
|
146 |
|
147 if (!ConditionOK(condAction, state)) |
|
148 { |
|
149 retVal = EFalse; |
|
150 |
|
151 if (useDefault && !condAction.iUseDefaultSysAgentAction) |
|
152 { |
|
153 aErrorAction = condAction.iErrorAction; |
|
154 } |
|
155 else if (!useDefault && !condAction.iUseDefaultSysAgentAction) |
|
156 { |
|
157 if (condAction.iErrorAction.iAction == ESendActionFail) |
|
158 { |
|
159 aErrorAction = condAction.iErrorAction; |
|
160 } |
|
161 else if (condAction.iErrorAction.iAction == ESendActionRetryLater && aErrorAction.iAction == ESendActionRetryImmediately) |
|
162 { |
|
163 aErrorAction = condAction.iErrorAction; |
|
164 } |
|
165 else if (condAction.iErrorAction.iRetries == ESendRetriesFixed && aErrorAction.iRetries == ESendRetriesInfinite) |
|
166 { |
|
167 aErrorAction = condAction.iErrorAction; |
|
168 } |
|
169 else |
|
170 { |
|
171 //use the current aErrorAction |
|
172 } |
|
173 } |
|
174 else |
|
175 { |
|
176 //use the default error action (iDefault) |
|
177 } |
|
178 |
|
179 useDefault &= condAction.iUseDefaultSysAgentAction; |
|
180 } |
|
181 } //end for |
|
182 |
|
183 return retVal; |
|
184 } |
|
185 |
|
186 |
|
187 TBool CMsvSysAgentActions::ConditionOK(const TMsvSysAgentConditionAction& aCondAction, const TInt aState) const |
|
188 { |
|
189 // If system agent hasn't defined the variable the condition should be satisfied |
|
190 if (aState == KErrUnknown) |
|
191 return ETrue; |
|
192 |
|
193 switch (aCondAction.iCondition.iType) |
|
194 { |
|
195 case TMsvCondition::EMsvSchSendEquals: |
|
196 { |
|
197 return (aState == aCondAction.iCondition.iState); |
|
198 } |
|
199 case TMsvCondition::EMsvSchSendNotEquals: |
|
200 { |
|
201 return (aState != aCondAction.iCondition.iState); |
|
202 } |
|
203 case TMsvCondition::EMsvSchSendGreaterThan: |
|
204 { |
|
205 return (aState > aCondAction.iCondition.iState); |
|
206 } |
|
207 case TMsvCondition::EMsvSchSendLessThan: |
|
208 { |
|
209 return (aState < aCondAction.iCondition.iState); |
|
210 } |
|
211 |
|
212 |
|
213 default: |
|
214 gPanic(ESysAgentConditionTypeNotSupported); |
|
215 break; |
|
216 } //end switch |
|
217 |
|
218 return ETrue; //should not be reached |
|
219 } |