|
1 /* |
|
2 * Copyright (c) 2006-2010 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 classes for Out of Memory Monitor. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "oommonitorclientserver.h" |
|
20 #include "oommemorymonitorsession.h" |
|
21 #include "oommemorymonitor.h" |
|
22 #include "oommemorymonitorserver.h" |
|
23 #include "OomTraces.h" |
|
24 #include "oomclientrequestqueue.h" |
|
25 |
|
26 CMemoryMonitorSession::CMemoryMonitorSession() |
|
27 { |
|
28 FUNC_LOG; |
|
29 } |
|
30 |
|
31 |
|
32 CMemoryMonitorSession::~CMemoryMonitorSession() |
|
33 { |
|
34 FUNC_LOG; |
|
35 } |
|
36 |
|
37 CMemoryMonitorServer& CMemoryMonitorSession::Server() |
|
38 { |
|
39 FUNC_LOG; |
|
40 |
|
41 return *static_cast<CMemoryMonitorServer*>(const_cast<CServer2*>(CSession2::Server())); |
|
42 } |
|
43 |
|
44 #ifdef CLIENT_REQUEST_QUEUE |
|
45 COomClientRequestQueue& CMemoryMonitorSession::ClientRequestQueue() |
|
46 { |
|
47 FUNC_LOG; |
|
48 |
|
49 return Server().ClientRequestQueue(); |
|
50 } |
|
51 #endif |
|
52 |
|
53 CMemoryMonitor& CMemoryMonitorSession::Monitor() |
|
54 { |
|
55 FUNC_LOG; |
|
56 |
|
57 #ifdef CLIENT_REQUEST_QUEUE |
|
58 return ClientRequestQueue().Monitor(); |
|
59 #else |
|
60 return Server().Monitor(); |
|
61 #endif |
|
62 } |
|
63 |
|
64 TBool CMemoryMonitorSession::IsDataPaged(const RMessage2& aMessage) |
|
65 { |
|
66 RThread clientThread; |
|
67 TInt err = aMessage.Client(clientThread); |
|
68 TBool dataPaged = EFalse; |
|
69 if(err == KErrNone) |
|
70 { |
|
71 RProcess processName; |
|
72 err = clientThread.Process(processName); |
|
73 if(err == KErrNone) |
|
74 { |
|
75 dataPaged = processName.DefaultDataPaged(); |
|
76 } |
|
77 else |
|
78 { |
|
79 PanicClient(aMessage, EPanicIllegalFunction); |
|
80 } |
|
81 } |
|
82 else |
|
83 { |
|
84 PanicClient(aMessage, EPanicIllegalFunction); |
|
85 } |
|
86 return dataPaged; |
|
87 } |
|
88 |
|
89 void CMemoryMonitorSession::ServiceL(const RMessage2& aMessage) |
|
90 { |
|
91 FUNC_LOG; |
|
92 |
|
93 #ifndef CLIENT_REQUEST_QUEUE |
|
94 iFunction = aMessage.Function(); |
|
95 #endif |
|
96 |
|
97 switch (aMessage.Function()) |
|
98 { |
|
99 case EOomMonitorRequestFreeMemory: |
|
100 if (!iRequestFreeRam.IsNull()) |
|
101 PanicClient(aMessage, EPanicRequestActive); |
|
102 // message will be completed when CloseAppsFinished() is called. |
|
103 |
|
104 #ifdef CLIENT_REQUEST_QUEUE |
|
105 ClientRequestQueue().RequestFreeMemoryL(aMessage); |
|
106 #else |
|
107 iRequestFreeRam = aMessage; |
|
108 Monitor().RequestFreeMemoryL(aMessage.Int0(), IsDataPaged(aMessage)); |
|
109 #endif |
|
110 break; |
|
111 |
|
112 case EOomMonitorCancelRequestFreeMemory: |
|
113 if (!iRequestFreeRam.IsNull()) |
|
114 iRequestFreeRam.Complete(KErrCancel); |
|
115 aMessage.Complete(KErrNone); |
|
116 break; |
|
117 |
|
118 case EOomMonitorThisAppIsNotExiting: |
|
119 Monitor().AppNotExiting(aMessage.Int0()); |
|
120 aMessage.Complete(KErrNone); |
|
121 break; |
|
122 |
|
123 case EOomMonitorRequestOptionalRam: |
|
124 if (!iRequestFreeRam.IsNull()) |
|
125 PanicClient(aMessage, EPanicRequestActive); |
|
126 // message will be completed when CloseAppsFinished() is called. |
|
127 |
|
128 #ifdef CLIENT_REQUEST_QUEUE |
|
129 ClientRequestQueue().RequestOptionalRamL(aMessage); |
|
130 #else |
|
131 iRequestFreeRam = aMessage; |
|
132 iMinimumMemoryRequested = aMessage.Int1(); |
|
133 Monitor().FreeOptionalRamL(aMessage.Int0(), aMessage.Int2(), IsDataPaged(aMessage)); |
|
134 #endif |
|
135 break; |
|
136 |
|
137 case EOomMonitorSetPriorityBusy: |
|
138 Monitor().SetPriorityBusy(aMessage.Int0()); |
|
139 aMessage.Complete(KErrNone); |
|
140 break; |
|
141 |
|
142 case EOomMonitorSetPriorityNormal: |
|
143 Monitor().SetPriorityNormal(aMessage.Int0()); |
|
144 aMessage.Complete(KErrNone); |
|
145 break; |
|
146 |
|
147 case EOomMonitorSetPriorityHigh: |
|
148 Monitor().SetPriorityHigh(aMessage.Int0()); |
|
149 aMessage.Complete(KErrNone); |
|
150 break; |
|
151 |
|
152 default: |
|
153 PanicClient(aMessage, EPanicIllegalFunction); |
|
154 break; |
|
155 } |
|
156 } |
|
157 |
|
158 #ifndef CLIENT_REQUEST_QUEUE |
|
159 void CMemoryMonitorSession::CloseAppsFinished(TInt aBytesFree, TBool aMemoryGood) |
|
160 { |
|
161 FUNC_LOG; |
|
162 |
|
163 if (!iRequestFreeRam.IsNull()) |
|
164 { |
|
165 if (iFunction == EOomMonitorRequestOptionalRam) |
|
166 { |
|
167 TInt memoryAvailable = aBytesFree - CMemoryMonitor::GlobalConfig().iGoodRamThreshold; |
|
168 |
|
169 // If memory available is greater than the requested RAM then complete with the amount of free memory, otherwise complete with KErrNoMemory |
|
170 if (memoryAvailable >= iMinimumMemoryRequested) |
|
171 { |
|
172 iRequestFreeRam.Complete(memoryAvailable); |
|
173 } |
|
174 else |
|
175 { |
|
176 iRequestFreeRam.Complete(KErrNoMemory); |
|
177 } |
|
178 } |
|
179 else |
|
180 iRequestFreeRam.Complete(aMemoryGood ? KErrNone : KErrNoMemory); |
|
181 } |
|
182 } |
|
183 #endif |