|
1 /* |
|
2 * Copyright (c) 2006-2009 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: Main functionality for Graphics Out of Memory Monitor |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef GOOMMONITORPLUGIN_H |
|
20 #define GOOMMONITORPLUGIN_H |
|
21 |
|
22 #include <e32base.h> |
|
23 |
|
24 class CMemoryMonitor; |
|
25 class RFs; |
|
26 class RWsSession; |
|
27 |
|
28 |
|
29 /** |
|
30 * Panic codes with category "OomMonitorPlugin" |
|
31 */ |
|
32 enum TGOomMonitorPluginPanic |
|
33 { |
|
34 /** |
|
35 * The plugin has been constructed by a thread other than the GOOM monitor. |
|
36 */ |
|
37 EGOomMonitorPluginPanic_PluginConstructedOutsideGOomMonitorThread |
|
38 }; |
|
39 |
|
40 // Message type used to signal an GOOM plug-in to free some memory. |
|
41 const TInt KAppGOomMonitor_FreeRam = 0x10282304; |
|
42 |
|
43 // Message type used to signal an OOM plug-in that there is free memory again. |
|
44 const TInt KAppGOomMonitor_MemoryGood = 0x10282305; |
|
45 |
|
46 class CGOomMonitorPluginBase : public CBase |
|
47 { |
|
48 public: |
|
49 /** |
|
50 * Constructor |
|
51 * Plugins should assume that the system memory is good when |
|
52 * they are created. |
|
53 */ |
|
54 IMPORT_C CGOomMonitorPluginBase(); |
|
55 /** |
|
56 * Destructor |
|
57 */ |
|
58 IMPORT_C ~CGOomMonitorPluginBase(); |
|
59 /** |
|
60 * 2nd stage constructor |
|
61 */ |
|
62 IMPORT_C void ConstructL(); |
|
63 |
|
64 public: |
|
65 /** |
|
66 * FreeRam is called when the system RAM level becomes |
|
67 * low. This plugin is requested to help free some RAM. |
|
68 */ |
|
69 virtual void FreeRam(TInt aBytesToFree) = 0; |
|
70 |
|
71 /** |
|
72 * MemoryGood is called when the system RAM level becomes |
|
73 * good after being low.The plugin may take this opportunity |
|
74 * to start using RAM again. |
|
75 * Nb It is assumed that the plugin will not immediately |
|
76 * cause a large increase in memory use, but that memory may be |
|
77 * used over time, otherwise the plugin may cause oscillation |
|
78 * between low and good memory states. |
|
79 */ |
|
80 virtual void MemoryGood() = 0; |
|
81 |
|
82 public: |
|
83 /** |
|
84 * Get a handle to the file server. |
|
85 * @return a connected file server session. |
|
86 */ |
|
87 IMPORT_C RFs& FsSession(); |
|
88 /** |
|
89 * Get a handle to the window server. |
|
90 * @return a connected window server session. |
|
91 */ |
|
92 IMPORT_C RWsSession& WsSession(); |
|
93 |
|
94 IMPORT_C virtual void ExtensionInterface(TUid aInterfaceId, TAny*& aImplementaion); |
|
95 |
|
96 private: |
|
97 CMemoryMonitor* iMemoryMonitor; |
|
98 }; |
|
99 |
|
100 |
|
101 class CGOomMonitorPlugin : public CGOomMonitorPluginBase |
|
102 { |
|
103 public: // new functions |
|
104 |
|
105 CGOomMonitorPlugin():CGOomMonitorPluginBase(){} |
|
106 |
|
107 public: // From CGOomMonitorPluginBase |
|
108 /** |
|
109 * FreeRam is called when the system graphics memory level becomes |
|
110 * low. This plugin is requested to help free some RAM. |
|
111 * |
|
112 * this version of the function should not need to be implemented. |
|
113 * The definition of this function should change once the alf plugin is stable and finetuned |
|
114 * @param aBytesToFree The minimum number of bytes of free memory that the plugin should try to free. |
|
115 */ |
|
116 |
|
117 virtual void FreeRam(TInt aBytesToFree) = 0; |
|
118 |
|
119 /** |
|
120 * MemoryGood is called when the system RAM level becomes |
|
121 * good after being low.The plugin may take this opportunity |
|
122 * to start using RAM again. |
|
123 * Nb It is assumed that the plugin will not immediately |
|
124 * cause a large increase in memory use, but that memory may be |
|
125 * used over time, otherwise the plugin may cause oscillation |
|
126 * between low and good memory states. |
|
127 */ |
|
128 virtual void MemoryGood() = 0; |
|
129 }; |
|
130 |
|
131 |
|
132 |
|
133 /** |
|
134 * CAppOomMonitorPlugin is a specialised OOM monitor plugin |
|
135 * that sends messages to applications when the memory state |
|
136 * changes. |
|
137 * The target application is specified by the appUid parameter. |
|
138 * the message will be sent to all running instances of this app. |
|
139 * The messages are: |
|
140 * KAppOomMonitor_FreeRam when memory should be released. |
|
141 * KAppOomMonitor_MemoryGood when memory is good again. |
|
142 * |
|
143 * These messages can be picked up in the app UI like this: |
|
144 * void CMyAppUi::HandleApplicationSpecificEventL(TInt aType, const TWsEvent& aEvent) |
|
145 * { |
|
146 * CAknAppUi::HandleApplicationSpecificEventL(aType, aEvent); |
|
147 * if (aType == KAppOomMonitor_FreeRam) |
|
148 * { |
|
149 * // release memory and disable memory use |
|
150 * } |
|
151 * else if (aType == KAppOomMonitor_MemoryGood) |
|
152 * { |
|
153 * // re-enable memory use |
|
154 * } |
|
155 * } |
|
156 * |
|
157 * The plugin can be instantiated in an ECom factory function. |
|
158 * The application does not need to derive from this class. |
|
159 * For example: |
|
160 * TAny* CreateAppPlugin() |
|
161 * { |
|
162 * return CAppOomMonitorPlugin::NewL(KMyAppUid); |
|
163 * } |
|
164 */ |
|
165 NONSHARABLE_CLASS(CAppGOomMonitorPlugin) : public CGOomMonitorPluginBase |
|
166 { |
|
167 public: |
|
168 IMPORT_C static CAppGOomMonitorPlugin* NewL(TUid aAppUid); |
|
169 |
|
170 private: |
|
171 CAppGOomMonitorPlugin(TUid aAppUid); |
|
172 |
|
173 void FreeRam(TInt aFreeMemory); |
|
174 void MemoryGood(); |
|
175 |
|
176 void SendMessageToApp(TInt aMessage); |
|
177 |
|
178 private: |
|
179 TUid iAppUid; |
|
180 }; |
|
181 |
|
182 |
|
183 /** |
|
184 * Sets the CMemoryMonitor object for this DLL. |
|
185 * Only for use by CMemoryMonitor. |
|
186 * @internal |
|
187 */ |
|
188 IMPORT_C void SetGMemoryMonitorTls(CMemoryMonitor* aMonitor); |
|
189 |
|
190 |
|
191 #endif // OOMMONITORPLUGIN_H |