1 /* |
1 /* |
2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
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 |
|
27 COomRunPlugin* COomRunPlugin::NewL(TUint aPluginId, COomRunPluginConfig& aConfig, MOomActionObserver& aStateChangeObserver, COomMonitorPlugin& aPlugin, COomMonitorPluginV2* aV2Plugin) |
24 COomRunPlugin* COomRunPlugin::NewL(TUint aPluginId, COomRunPluginConfig& aConfig, MOomActionObserver& aStateChangeObserver, COomMonitorPlugin& aPlugin, COomMonitorPluginV2* aV2Plugin) |
28 { |
25 { |
29 FUNC_LOG; |
26 FUNC_LOG; |
30 |
27 |
31 COomRunPlugin* self = new (ELeave) COomRunPlugin(aPluginId, aConfig, aStateChangeObserver, aPlugin, aV2Plugin); |
28 COomRunPlugin* self = new (ELeave) COomRunPlugin(aPluginId, aConfig, aStateChangeObserver, aPlugin, aV2Plugin); |
35 return self; |
32 return self; |
36 } |
33 } |
37 |
34 |
38 // Run the OOM plugin in order to free memory |
35 // Run the OOM plugin in order to free memory |
39 // Call the COomAction::MemoryFreed when it is done |
36 // Call the COomAction::MemoryFreed when it is done |
40 void COomRunPlugin::FreeMemory(TInt aBytesRequested, TBool aIsDataPaged) |
37 void COomRunPlugin::FreeMemory(TInt aBytesRequested) |
41 { |
38 { |
42 FUNC_LOG; |
39 FUNC_LOG; |
43 iFreeMemoryCalled = ETrue; |
40 TRACES1("COomRunPlugin::FreeMemory: iPluginId = %x", iPluginId); |
44 |
41 |
|
42 // Ask the plugin to free some memory |
|
43 |
45 // Do we have a V2 plugin, if so then use it |
44 // Do we have a V2 plugin, if so then use it |
46 if (iV2Plugin) |
45 if (iV2Plugin) |
47 { |
|
48 //RDebug::Printf("COomRunPlugin::FreeMemory: Requesting to free the RAM iV2Plugin->FreeRam(%d) \n",aBytesRequested); |
|
49 iV2Plugin->FreeRam(aBytesRequested); |
46 iV2Plugin->FreeRam(aBytesRequested); |
50 } |
47 else |
51 else if( aIsDataPaged ) |
48 // If we only have a V1 plugin then use that |
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"); |
|
72 iPlugin.FreeRam(); |
49 iPlugin.FreeRam(); |
73 } |
50 |
|
51 iFreeMemoryCalled = ETrue; |
74 |
52 |
75 // Wait for the required time before we signal completion. |
53 // Wait for the required time before we signal completion. |
76 __ASSERT_DEBUG(!iPluginWaiter->IsActive(), OomMonitorPanic(KStartingActivePluginWaiter)); |
54 __ASSERT_DEBUG(!iPluginWaiter->IsActive(), OomMonitorPanic(KStartingActivePluginWaiter)); |
77 iPluginWaiter->Start(); |
55 iPluginWaiter->Start(); |
78 } |
56 } |
114 waitDuration = aPluginConfig.WaitAfterPlugin(); |
92 waitDuration = aPluginConfig.WaitAfterPlugin(); |
115 } |
93 } |
116 |
94 |
117 iPluginWaiter = COomPluginWaiter::NewL(waitDuration, *this); |
95 iPluginWaiter = COomPluginWaiter::NewL(waitDuration, *this); |
118 } |
96 } |
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 } |
|