|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef GSWATCHDOG_H |
|
20 #define GSWATCHDOG_H |
|
21 |
|
22 // System includes |
|
23 #include <e32base.h> |
|
24 #include <mgswatchdog.h> |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 |
|
29 /** |
|
30 * Maximum number of GS runs during which plugin is held in blacklist. After |
|
31 * this plugin is allowed normal execution unless it crashes again. |
|
32 * |
|
33 * Used only in case no CenRep value is defined. |
|
34 */ |
|
35 const TInt KGSDefaultMaxPluginBlackListedRuns = 5; |
|
36 |
|
37 |
|
38 /** |
|
39 * Defines how many crashes are observed before watchdog is activated. The |
|
40 * bigger the value, more tolerant behaviour towards crashing plugins. |
|
41 * |
|
42 * -1 = Watchdog is completely disabled regardless any crash |
|
43 * (KGSWatchdogActivationDisabled). |
|
44 * 1 = In practise, the fastest reaction, meaning watchdog is enabled the next |
|
45 * run GS starts after a crash. |
|
46 * 2 = GS can have 1 crash without watchdog being enabled = 2nd GS crash in a |
|
47 * row will enable watchdog. |
|
48 * n = GS can have n-1 crashes before watchdog being activated etc. |
|
49 * |
|
50 * Used only in case no CenRep value is defined. |
|
51 */ |
|
52 const TInt KGSDefaultWatchdogActivationLimit = 1; |
|
53 |
|
54 /** |
|
55 * Watchdog is completely disabled. |
|
56 */ |
|
57 const TInt KGSWatchdogActivationDisabled = -1; |
|
58 |
|
59 |
|
60 // FORWARD DECLARATIONS |
|
61 class CRepository; |
|
62 class RReadStream; |
|
63 class RWriteStream; |
|
64 |
|
65 // CLASS DECLARATION |
|
66 |
|
67 |
|
68 |
|
69 /** |
|
70 * Container class for quarantined plugin data. |
|
71 */ |
|
72 class TGSPluginQuarantine |
|
73 { |
|
74 public: |
|
75 /** |
|
76 * Read data from aStream. |
|
77 * @param aStream read stream. |
|
78 */ |
|
79 void InternalizeL( RReadStream& aStream ); |
|
80 |
|
81 /** |
|
82 * Write data to aStream. |
|
83 * @param aStream write stream. |
|
84 */ |
|
85 void ExternalizeL( RWriteStream& aStream ) const; |
|
86 |
|
87 public: |
|
88 |
|
89 /** |
|
90 * Uid of the plugin. |
|
91 */ |
|
92 TUid iUid; |
|
93 |
|
94 /** |
|
95 * Counter which is incremented each time GS is started and the plugin |
|
96 * is in blacklist. This is used for removing plugin from blacklist |
|
97 * after certain number of GS runs (iMaxPluginBlackListedRuns). This |
|
98 * means plugins are not in blacklist for ever but it is possible to try |
|
99 * running the plugin after a number of GS runs. This is needed in case |
|
100 * of ramdom crash while some essential plugin is in quarantine. |
|
101 */ |
|
102 TInt iRunsAfterCrash; |
|
103 }; |
|
104 |
|
105 /** |
|
106 * CGSWatchDog is responsible for quarantining plugins and updating blacklist |
|
107 * for crashing GS plugins. This is the class responsible for keeping GS |
|
108 * application functional even if some plugin to panics all the time. |
|
109 * |
|
110 * @since Series60_3.2 |
|
111 */ |
|
112 NONSHARABLE_CLASS( CGSWatchDog ) : public CBase, |
|
113 public MGSWatchDog |
|
114 { |
|
115 public: // Constructor and destructor |
|
116 |
|
117 /** |
|
118 * Symbian OS two-phased constructor |
|
119 * @return CGSWatchDog. |
|
120 */ |
|
121 static CGSWatchDog* NewL(); |
|
122 |
|
123 /** |
|
124 * Destructor. |
|
125 */ |
|
126 ~CGSWatchDog(); |
|
127 |
|
128 public: // From MGSWatchDog |
|
129 |
|
130 /** |
|
131 * Adds plugin to quarantine. In case GS crashes, quarantined plugin |
|
132 * will be blacklisted so it is not loaded in next GS run. Same plugin |
|
133 * can be quarantined multiple times or even have several uid instances |
|
134 * in quarantine if needed as long as all these are removed |
|
135 * correspondingly. |
|
136 * |
|
137 * NOTE: Plugin must ALWAYS be removed from quarantine after plugin's |
|
138 * function execution. |
|
139 * 1. QuarantineL(). |
|
140 * 2. Call quarantined plugin function. |
|
141 * 3. RemoveFromQuarantineL(). |
|
142 * |
|
143 * @param aPluginUid uid of the quarantined plugin. |
|
144 */ |
|
145 void QuarantineL( TUid aPluginUid ); |
|
146 |
|
147 /** |
|
148 * Removes plugin from quarantine. In case plugin is not removed from |
|
149 * quarantine before GS exits, the plugin will be blacklisted during |
|
150 * next GS startup. |
|
151 * |
|
152 * @param aPluginUid uid of the plugin to be removed from quarantine. |
|
153 */ |
|
154 void RemoveFromQuarantineL( TUid aPluginUid ); |
|
155 |
|
156 /** |
|
157 * @return ETrue if GS exited cleanly last time. |
|
158 * EFalse if GS crashed during last execution. |
|
159 */ |
|
160 TBool WasCleanExitL(); |
|
161 |
|
162 /** |
|
163 * This must be called in all the cases GS exits normally. If GS panics, |
|
164 * this will not be called resulting in banning of all quarantined |
|
165 * plugins.Increments iRunsAfterCrash counter for blacklisted plugins. |
|
166 * Sets iGSAppRunning to EFalse. |
|
167 */ |
|
168 void ReportCleanExitL(); |
|
169 |
|
170 /** |
|
171 * Checks if plugin is in blacklist. This can be used to determine if |
|
172 * plugin should be loaded. |
|
173 * |
|
174 * @return ETrue in case plugin is in blacklist and should not be loaded. |
|
175 * EFalse in case plugin should not be loaded |
|
176 */ |
|
177 TBool IsInBlackList( TUid aPluginUid ); |
|
178 |
|
179 protected: // New |
|
180 |
|
181 /** |
|
182 * C++ constructor |
|
183 */ |
|
184 CGSWatchDog(); |
|
185 |
|
186 /** |
|
187 * Second phase constructor |
|
188 */ |
|
189 void ConstructL(); |
|
190 |
|
191 /** |
|
192 * Reads previous state from persistent data storage. |
|
193 */ |
|
194 void ReadStateL(); |
|
195 |
|
196 /** |
|
197 * Stores iGSAppRunning, iQuarantinedPluginUid and iBlackList data to |
|
198 * persistent storage. |
|
199 */ |
|
200 void StoreStateL(); |
|
201 |
|
202 /** |
|
203 * Sets state values to default values and stores these. |
|
204 */ |
|
205 void InitStateL(); |
|
206 |
|
207 /** |
|
208 * Reads quarantine data from persistent storage. |
|
209 */ |
|
210 void ReadQuarantineL(); |
|
211 |
|
212 /** |
|
213 * Stores quarantine data to persistent storage. |
|
214 */ |
|
215 void StoreQuarantineL(); |
|
216 |
|
217 /** |
|
218 * Reads blacklist data from persistent storage. |
|
219 */ |
|
220 void ReadBlackListL(); |
|
221 |
|
222 /** |
|
223 * Stores blacklist data to persistent storage. |
|
224 */ |
|
225 void StoreBlackListL(); |
|
226 |
|
227 /** |
|
228 * Updates run counter of each blacklisted plugin. Removes plugin from |
|
229 * blacklist if it has been there long enough |
|
230 * (KGSDefaultMaxPluginBlackListedRuns). |
|
231 */ |
|
232 void UpdateBlackListedPluginRunCounters(); |
|
233 |
|
234 private: // Data |
|
235 |
|
236 /** |
|
237 * ETrue if WatchDog is active (GS has crashed in previous run). |
|
238 */ |
|
239 TBool iIsActive; |
|
240 |
|
241 /** |
|
242 * Counter for GS crashes in a row. This is used to customize watchdog |
|
243 * behaviour. Defines how many crashes are observed before watchdog is |
|
244 * activated. The bigger the value, more tolerant behaviour towards crashing |
|
245 * plugins. See iWatchdogActivationLimit. |
|
246 * |
|
247 * -1 = Watchdog is completely disabled regardless any crash. |
|
248 * 1 = In paractise the fastest reaction, meaning watchdog is enabled the next |
|
249 * run GS starts after a crash. |
|
250 * 2 = GS can have 1 crash without watchdog being enabled = 2nd GS crash in a |
|
251 * row will enable watchdog. |
|
252 * n = GS can have n-1 crashes before watchdog being activated etc. |
|
253 */ |
|
254 TInt iCrashCounter; |
|
255 |
|
256 /** |
|
257 * Emulates stored data. Set on when GS running, off when GS exits |
|
258 * cleanly. Check this when starting GS to see if last exit was clean. |
|
259 */ |
|
260 TBool iGSAppRunning; |
|
261 |
|
262 /** |
|
263 * Uids for plugins which should be banned. They caused GS crash in |
|
264 * previous runs. |
|
265 */ |
|
266 RArray<TGSPluginQuarantine> iBlackList; |
|
267 |
|
268 /** |
|
269 * Run time quarantine for plugins. |
|
270 */ |
|
271 RArray<TUid> iQuarantine; |
|
272 |
|
273 /** |
|
274 * Persistent storage. |
|
275 */ |
|
276 CRepository* iStore; |
|
277 |
|
278 /** |
|
279 * Defines how long a plugin is held in blacklist. |
|
280 * KGSDefaultMaxPluginBlackListedRuns is used if no CenRep value is defined. |
|
281 */ |
|
282 TInt iMaxPluginBlackListedRuns; |
|
283 |
|
284 /** |
|
285 * Defines how many crashes is needed to activate watchdog. |
|
286 * KGSDefaultWatchdogActivationLimit is used in case no CenRep value is |
|
287 * defined. |
|
288 */ |
|
289 TInt iWatchdogActivationLimit; |
|
290 }; |
|
291 |
|
292 #endif // GSWATCHDOG_H |
|
293 // End of File |