19 #include "OomTraces.h" |
19 #include "OomTraces.h" |
20 #include "oommemorymonitor.h" |
20 #include "oommemorymonitor.h" |
21 #include "oommonitorplugin.h" |
21 #include "oommonitorplugin.h" |
22 #include "oompanic.h" |
22 #include "oompanic.h" |
23 |
23 |
|
24 #include <apgtask.h> |
|
25 #include <w32std.h> |
|
26 |
24 COomRunPlugin* COomRunPlugin::NewL(TUint aPluginId, COomRunPluginConfig& aConfig, MOomActionObserver& aStateChangeObserver, COomMonitorPlugin& aPlugin, COomMonitorPluginV2* aV2Plugin) |
27 COomRunPlugin* COomRunPlugin::NewL(TUint aPluginId, COomRunPluginConfig& aConfig, MOomActionObserver& aStateChangeObserver, COomMonitorPlugin& aPlugin, COomMonitorPluginV2* aV2Plugin) |
25 { |
28 { |
26 FUNC_LOG; |
29 FUNC_LOG; |
27 |
30 |
28 COomRunPlugin* self = new (ELeave) COomRunPlugin(aPluginId, aConfig, aStateChangeObserver, aPlugin, aV2Plugin); |
31 COomRunPlugin* self = new (ELeave) COomRunPlugin(aPluginId, aConfig, aStateChangeObserver, aPlugin, aV2Plugin); |
32 return self; |
35 return self; |
33 } |
36 } |
34 |
37 |
35 // Run the OOM plugin in order to free memory |
38 // Run the OOM plugin in order to free memory |
36 // Call the COomAction::MemoryFreed when it is done |
39 // Call the COomAction::MemoryFreed when it is done |
37 void COomRunPlugin::FreeMemory(TInt aBytesRequested, TBool) |
40 void COomRunPlugin::FreeMemory(TInt aBytesRequested, TBool aIsDataPaged) |
38 { |
41 { |
39 FUNC_LOG; |
42 FUNC_LOG; |
40 TRACES1("COomRunPlugin::FreeMemory: iPluginId = %x", iPluginId); |
43 iFreeMemoryCalled = ETrue; |
41 |
44 |
42 // Ask the plugin to free some memory |
|
43 |
|
44 // Do we have a V2 plugin, if so then use it |
45 // Do we have a V2 plugin, if so then use it |
45 if (iV2Plugin) |
46 if (iV2Plugin) |
|
47 { |
|
48 //RDebug::Printf("COomRunPlugin::FreeMemory: Requesting to free the RAM iV2Plugin->FreeRam(%d) \n",aBytesRequested); |
46 iV2Plugin->FreeRam(aBytesRequested); |
49 iV2Plugin->FreeRam(aBytesRequested); |
47 else |
50 } |
48 // If we only have a V1 plugin then use that |
51 else if( aIsDataPaged ) |
|
52 { |
|
53 if (IsAppDataPaged(iPlugin) ) |
|
54 { |
|
55 //the plugins implemented by the application which are WDP enabled |
|
56 //are notified. |
|
57 //RDebug::Printf("COomRunPlugin::FreeMemory: Requesting to free the RAM to Data paged app \n"); |
|
58 iPlugin.FreeRam(); |
|
59 } |
|
60 else |
|
61 { |
|
62 //Request is for freeing the paged memory(swap) but the App(iPlugin belongs to) |
|
63 //is non WDP no need to notify; as it can't free the swap memory |
|
64 iFreeMemoryCalled = EFalse; |
|
65 return; |
|
66 } |
|
67 } |
|
68 else |
|
69 { |
|
70 //Unpaged memory will be freed in case of non WDP app |
|
71 //RDebug::Printf("COomRunPlugin::FreeMemory: Requesting to free the RAM \n"); |
49 iPlugin.FreeRam(); |
72 iPlugin.FreeRam(); |
50 |
73 } |
51 iFreeMemoryCalled = ETrue; |
|
52 |
74 |
53 // Wait for the required time before we signal completion. |
75 // Wait for the required time before we signal completion. |
54 __ASSERT_DEBUG(!iPluginWaiter->IsActive(), OomMonitorPanic(KStartingActivePluginWaiter)); |
76 __ASSERT_DEBUG(!iPluginWaiter->IsActive(), OomMonitorPanic(KStartingActivePluginWaiter)); |
55 iPluginWaiter->Start(); |
77 iPluginWaiter->Start(); |
56 } |
78 } |
92 waitDuration = aPluginConfig.WaitAfterPlugin(); |
114 waitDuration = aPluginConfig.WaitAfterPlugin(); |
93 } |
115 } |
94 |
116 |
95 iPluginWaiter = COomPluginWaiter::NewL(waitDuration, *this); |
117 iPluginWaiter = COomPluginWaiter::NewL(waitDuration, *this); |
96 } |
118 } |
|
119 |
|
120 //----------------------------------------------------------------------------- |
|
121 // Function: IsAppDataPaged |
|
122 // Checks whether the application which implements the given |
|
123 // COomMonitorPlugin is data paged |
|
124 //----------------------------------------------------------------------------- |
|
125 // |
|
126 TBool COomRunPlugin::IsAppDataPaged |
|
127 ( COomMonitorPlugin& aPlugin ) const |
|
128 { |
|
129 FUNC_LOG; |
|
130 /* |
|
131 /TRACES1("COomRunPlugin::IsAppDataPaged: aPlugin.AppId() = %x ", aPlugin.AppId() ); |
|
132 //RDebug::Printf("COomRunPlugin::IsAppDataPaged: aPlugin.AppId() = %x ", aPlugin.AppId() ); |
|
133 */ |
|
134 //the function find the process with given appid and check |
|
135 //application supports the data paging. |
|
136 RProcess clientprocess; |
|
137 TApaTaskList taskList(aPlugin.WsSession()); |
|
138 RThread clientthread; |
|
139 TInt err = clientthread.Open |
|
140 (taskList.FindApp(aPlugin.AppId()).ThreadId()); |
|
141 |
|
142 //RDebug::Printf("COomRunPlugin::IsAppDataPaged: clientthread.Open() err = %d ", err ); |
|
143 |
|
144 if( !err ) |
|
145 { |
|
146 //getting the process which provides the plugin |
|
147 err = clientthread.Process(clientprocess); |
|
148 RDebug::Printf("COomRunPlugin::IsAppDataPaged: clientthread.Process() err = %d ", err ); |
|
149 |
|
150 if( !err ) |
|
151 { |
|
152 //checking whether the process is Data paged or not |
|
153 TBool isdatapaged = clientprocess.DefaultDataPaged(); |
|
154 clientprocess.Close(); |
|
155 clientthread.Close(); |
|
156 //RDebug::Printf("COomRunPlugin::IsAppDataPaged: isdatapaged = %d ", isdatapaged ); |
|
157 |
|
158 return isdatapaged; |
|
159 } |
|
160 clientthread.Close(); |
|
161 } |
|
162 //could not successfully open the handle of process or thread, |
|
163 //the return EFalse |
|
164 return EFalse; |
|
165 } |