|
1 /* |
|
2 * Copyright (c) 2006 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: Client/server interface for GOOM Monitor. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <coemain.h> |
|
20 #include <goommonitorsession.h> |
|
21 #include "goommonitorclientserver.h" |
|
22 #include "goompanic.h" |
|
23 #include "goomtraces.h" |
|
24 |
|
25 enum TGoomClientInternalFlags{ |
|
26 EGoonCFlagsNone, |
|
27 EGoonCFlagsConnected = 1 |
|
28 }; |
|
29 |
|
30 #define ASYNCH_NOTIFICATION_ONLY |
|
31 |
|
32 EXPORT_C TInt RGOomMonitorSession::Connect() |
|
33 { |
|
34 FUNC_LOG; |
|
35 iFlags = EGoonCFlagsNone; // initialization |
|
36 if (CreateSession(KGraphicsMemoryMonitorServerName, TVersion(0,0,0)) == KErrNone) |
|
37 { |
|
38 iFlags = EGoonCFlagsConnected; |
|
39 } |
|
40 |
|
41 // always return KErrNone for now |
|
42 return KErrNone; |
|
43 } |
|
44 |
|
45 EXPORT_C TBool RGOomMonitorSession::IsConnected() |
|
46 { |
|
47 FUNC_LOG; |
|
48 return iFlags&EGoonCFlagsConnected; |
|
49 } |
|
50 |
|
51 EXPORT_C TInt RGOomMonitorSession::RequestFreeMemory(TInt aBytesRequested) |
|
52 { |
|
53 FUNC_LOG; |
|
54 if (IsConnected()) |
|
55 { |
|
56 TIpcArgs p(aBytesRequested,0); |
|
57 return SendReceive(EGOomMonitorRequestFreeMemory, p); |
|
58 } |
|
59 return KErrNone; |
|
60 } |
|
61 |
|
62 EXPORT_C TInt RGOomMonitorSession::RequestOptionalRam(TInt aBytesRequested, TInt aMinimumBytesNeeded, TInt aPluginId, TInt& aBytesAvailable) |
|
63 { |
|
64 FUNC_LOG; |
|
65 if (IsConnected()) |
|
66 { |
|
67 TIpcArgs p(aBytesRequested, aMinimumBytesNeeded, aPluginId, aBytesAvailable); |
|
68 TInt ret = SendReceive(EGOomMonitorRequestOptionalRam, p); |
|
69 if (ret >= 0) |
|
70 { |
|
71 aBytesAvailable = ret; |
|
72 ret = KErrNone; |
|
73 } |
|
74 |
|
75 return ret; |
|
76 } |
|
77 return KErrNone; |
|
78 } |
|
79 |
|
80 EXPORT_C void RGOomMonitorSession::RequestOptionalRam(TInt aBytesRequested, TInt aMinimumBytesNeeded, TInt aPluginId, TRequestStatus& aStatus) |
|
81 { |
|
82 FUNC_LOG; |
|
83 |
|
84 if (IsConnected()) |
|
85 { |
|
86 TIpcArgs p(aBytesRequested, aMinimumBytesNeeded, aPluginId); |
|
87 SendReceive(EGOomMonitorRequestOptionalRam, p, aStatus); |
|
88 } |
|
89 else |
|
90 { |
|
91 TRequestStatus* sptr = &aStatus; |
|
92 User::RequestComplete(sptr, KErrNone); |
|
93 } |
|
94 } |
|
95 |
|
96 EXPORT_C void RGOomMonitorSession::RequestFreeMemory(TInt aBytesRequested, TRequestStatus& aStatus) |
|
97 { |
|
98 FUNC_LOG; |
|
99 |
|
100 if (IsConnected()) |
|
101 { |
|
102 TIpcArgs p(aBytesRequested,0); |
|
103 SendReceive(EGOomMonitorRequestFreeMemory, p, aStatus); |
|
104 } |
|
105 else |
|
106 { |
|
107 TRequestStatus* sptr = &aStatus; |
|
108 User::RequestComplete(sptr, KErrNone); |
|
109 } |
|
110 } |
|
111 |
|
112 EXPORT_C void RGOomMonitorSession::CancelRequestFreeMemory() |
|
113 { |
|
114 FUNC_LOG; |
|
115 if (IsConnected()) |
|
116 { |
|
117 SendReceive(EGOomMonitorCancelRequestFreeMemory, TIpcArgs()); |
|
118 } |
|
119 } |
|
120 |
|
121 EXPORT_C void RGOomMonitorSession::ThisAppIsNotExiting(TInt aWgId) |
|
122 { |
|
123 FUNC_LOG; |
|
124 if (IsConnected()) |
|
125 { |
|
126 TIpcArgs p(aWgId); |
|
127 SendReceive(EGOomMonitorThisAppIsNotExiting, p); |
|
128 } |
|
129 } |
|
130 |
|
131 |
|
132 EXPORT_C void RGOomMonitorSession::SetGOomPriority(TGOomPriority aPriority) |
|
133 { |
|
134 FUNC_LOG; |
|
135 if (!IsConnected()) |
|
136 { |
|
137 return; |
|
138 } |
|
139 |
|
140 CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
141 |
|
142 __ASSERT_DEBUG(coeEnv, GOomMonitorPanic(KNoCoeEnvFound)); |
|
143 |
|
144 if (coeEnv) |
|
145 { |
|
146 TInt wgId = coeEnv->RootWin().Identifier(); |
|
147 TIpcArgs p(wgId); |
|
148 switch (aPriority) |
|
149 { |
|
150 case EGOomPriorityNormal: |
|
151 SendReceive(EGOomMonitorSetPriorityNormal, p); |
|
152 break; |
|
153 case EGOomPriorityHigh: |
|
154 SendReceive(EGOomMonitorSetPriorityHigh, p); |
|
155 break; |
|
156 case EGOomPriorityBusy: |
|
157 SendReceive(EGOomMonitorSetPriorityBusy, p); |
|
158 break; |
|
159 default: |
|
160 GOomMonitorPanic(KGOomInvalidPriority); |
|
161 break; |
|
162 } |
|
163 } |
|
164 } |
|
165 |
|
166 EXPORT_C void RGOomMonitorSession::ApplicationAboutToStart(const TUid& aAppUid) |
|
167 { |
|
168 FUNC_LOG; |
|
169 if (IsConnected()) |
|
170 { |
|
171 #ifdef ASYNCH_NOTIFICATION_ONLY |
|
172 SendReceive(EGoomMonitorAppAboutToStart, TIpcArgs(aAppUid.iUid)); |
|
173 #else |
|
174 SendReceive(EGOomMonitorRequestFreeMemory, TIpcArgs(0,aAppUid.iUid)); |
|
175 #endif |
|
176 } |
|
177 } |
|
178 |
|
179 |
|
180 EXPORT_C void RGOomMonitorSession::UsesAbsoluteMemTargets(TBool aUseAbsoluteAmount) |
|
181 { |
|
182 FUNC_LOG; |
|
183 if (IsConnected()) |
|
184 { |
|
185 SendReceive(EGoomMonitorAppUsesAbsoluteMemTargets, TIpcArgs(aUseAbsoluteAmount)); |
|
186 } |
|
187 } |
|
188 |
|
189 EXPORT_C TInt RGOomMonitorSession::Connect(TRequestStatus& aStatus) |
|
190 { |
|
191 FUNC_LOG; |
|
192 iFlags = EGoonCFlagsNone; // initialization |
|
193 |
|
194 TInt err = CreateSession( KGraphicsMemoryMonitorServerName, |
|
195 TVersion( 0, 0, 0 ), 1, EIpcSession_Unsharable, 0, &aStatus ); |
|
196 |
|
197 if ( err == KErrNone ) |
|
198 { |
|
199 iFlags = EGoonCFlagsConnected; |
|
200 } |
|
201 |
|
202 return err; |
|
203 } |
|
204 |
|
205 EXPORT_C void RGOomMonitorSession::AppAboutToStart(TRequestStatus& aStatus, const TUid& aAppUid) |
|
206 { |
|
207 FUNC_LOG; |
|
208 if (IsConnected()) |
|
209 { |
|
210 #ifdef ASYNCH_NOTIFICATION_ONLY |
|
211 SendReceive(EGoomMonitorAppAboutToStart, TIpcArgs(aAppUid.iUid), aStatus); |
|
212 #else |
|
213 SendReceive(EGOomMonitorRequestFreeMemory, TIpcArgs(0,aAppUid.iUid), aStatus); |
|
214 #endif |
|
215 } |
|
216 } |