|
1 /* |
|
2 * Copyright (c) 2006-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: This is the MAlarmObserver I/F implementation instantiated and used directly by EIkAlert. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "pim_trace.h" |
|
22 #include "AlarmWrapper.h" |
|
23 |
|
24 #include <asshdalarm.h> |
|
25 #include <uikon/eikalsup.h> |
|
26 #include <AknSgcc.h> |
|
27 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
28 #include <uiklaf/private/pluginuid.hrh> |
|
29 #endif |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // DLL entry point |
|
33 // --------------------------------------------------------------------------- |
|
34 EXPORT_C MAlarmObserver* NewAlarm() |
|
35 { |
|
36 TRACE_ENTRY_POINT; |
|
37 CAknAlarmWrapper* alarmWrapper = new CAknAlarmWrapper; |
|
38 TRACE_EXIT_POINT; |
|
39 return alarmWrapper; |
|
40 } |
|
41 |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // RAknAlarmClient |
|
45 // --------------------------------------------------------------------------- |
|
46 |
|
47 // Client for AknCapServer |
|
48 RAknAlarmClient::RAknAlarmClient(CAknDataFetcher** aFetcher) |
|
49 : iFetcher( aFetcher ) |
|
50 { |
|
51 TRACE_ENTRY_POINT; |
|
52 TRACE_EXIT_POINT; |
|
53 } |
|
54 |
|
55 // In fact we don't need this, next method with dummy parameter is enough |
|
56 TInt RAknAlarmClient::SendSynch(TInt aOpcode) |
|
57 { |
|
58 TRACE_ENTRY_POINT; |
|
59 TInt ret = CheckConnection(); |
|
60 |
|
61 if (ret == KErrNone) |
|
62 { |
|
63 (*iFetcher)->Start(); // does nothing if already active |
|
64 ret = SendReceive( aOpcode ); |
|
65 } |
|
66 TRACE_EXIT_POINT; |
|
67 return ret; |
|
68 } |
|
69 |
|
70 // ?description |
|
71 TInt RAknAlarmClient::SendSynch(TInt aOpcode, TInt& aParam) |
|
72 { |
|
73 TRACE_ENTRY_POINT; |
|
74 TInt ret = CheckConnection(); |
|
75 |
|
76 if( ret == KErrNone ) |
|
77 { |
|
78 (*iFetcher)->Start(); // does nothing if already active |
|
79 |
|
80 TPckg<TInt> pckg( aParam ); |
|
81 ret = SendReceive( aOpcode, TIpcArgs( &pckg ) ); |
|
82 } |
|
83 TRACE_EXIT_POINT; |
|
84 return ret; |
|
85 } |
|
86 |
|
87 // Used currently only by cmd fetcher |
|
88 void RAknAlarmClient::SendAsync(TInt aOpcode, TRequestStatus& aStatus, TIpcArgs& aArgs) |
|
89 { |
|
90 TRACE_ENTRY_POINT; |
|
91 // we currently assume that only this client will initiate asynch messages, and |
|
92 // does it only when connection exists -> we don't check our connection before trying to send data |
|
93 SendReceive( aOpcode, aArgs, aStatus ); |
|
94 TRACE_EXIT_POINT; |
|
95 } |
|
96 |
|
97 // ?description |
|
98 TInt RAknAlarmClient::SetAlarm(const TASShdAlarm& aAlarm, const TFullName& aOwner, const TDesC8& aAlarmData) |
|
99 { |
|
100 TRACE_ENTRY_POINT; |
|
101 TInt ret = CheckConnection(); |
|
102 |
|
103 if( ret == KErrNone ) |
|
104 { |
|
105 (*iFetcher)->Start(); // does nothing if already active |
|
106 TPckgC<TASShdAlarm> pAlarm( aAlarm ); |
|
107 TIpcArgs args( &pAlarm, &aOwner, &aAlarmData ); |
|
108 ret = SendReceive( EASAltOpCodeSetAlarm, args ); |
|
109 } |
|
110 TRACE_EXIT_POINT; |
|
111 return ret; |
|
112 } |
|
113 |
|
114 // connect on demand, returns KErrNotReady if akncapserver is not available yet |
|
115 TInt RAknAlarmClient::CheckConnection() |
|
116 { |
|
117 TRACE_ENTRY_POINT; |
|
118 if( !Handle() ) |
|
119 { |
|
120 RAknUiServer& client = *(CAknSgcClient::AknSrv()); |
|
121 TInt err = KErrNotReady; |
|
122 |
|
123 if( client.Handle() != 0 ) // akncapserver running |
|
124 { |
|
125 _LIT( KServerNameFormat, "%08x_%08x_AppServer" ); |
|
126 TFullName serverName; |
|
127 serverName.Format( KServerNameFormat, KUikonUidPluginInterfaceNotifiers, KAknCapServerUid.iUid ); |
|
128 TRAP( err, ConnectExistingByNameL( serverName ); ) |
|
129 } |
|
130 TRACE_EXIT_POINT; |
|
131 return err; |
|
132 } |
|
133 TRACE_EXIT_POINT; |
|
134 return KErrNone; |
|
135 } |
|
136 |
|
137 // Just to prevent direct calling Connect, private |
|
138 TInt RAknAlarmClient::Connect() |
|
139 { |
|
140 TRACE_ENTRY_POINT; |
|
141 TInt retVal = RAknUiServer::Connect(); |
|
142 TRACE_EXIT_POINT; |
|
143 return retVal; |
|
144 } |
|
145 |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // CAknDataFetcher |
|
149 // --------------------------------------------------------------------------- |
|
150 |
|
151 // Active object used as callback channel from akncapserver (Stop, Snooze), |
|
152 // basically always active after connection to akncapserver has been formed |
|
153 CAknDataFetcher::CAknDataFetcher( TInt aPriority, |
|
154 CEikAlmControlSupervisor* aSupervisor, |
|
155 RAknAlarmClient& aClient ) |
|
156 : CActive( aPriority ), |
|
157 iSupervisor( aSupervisor ), |
|
158 iClient( aClient ), |
|
159 iPckg( 0 ), |
|
160 iArgs( &iPckg ) |
|
161 { |
|
162 TRACE_ENTRY_POINT; |
|
163 CActiveScheduler::Add( this ); |
|
164 TRACE_EXIT_POINT; |
|
165 } |
|
166 |
|
167 // ?description |
|
168 void CAknDataFetcher::Start() |
|
169 { |
|
170 TRACE_ENTRY_POINT; |
|
171 if( !IsActive() ) |
|
172 { |
|
173 SetActive(); |
|
174 iClient.SendAsync( EASAltOpCodeNotify, iStatus, iArgs ); |
|
175 } |
|
176 TRACE_EXIT_POINT; |
|
177 } |
|
178 |
|
179 // Handle ie. deliver commands to real alarm supervisor (ie. Alarm Session) |
|
180 void CAknDataFetcher::RunL() |
|
181 { |
|
182 TRACE_ENTRY_POINT; |
|
183 __ASSERT_DEBUG( iSupervisor != 0, User::Invariant() ); |
|
184 |
|
185 switch( iStatus.Int() ) |
|
186 { |
|
187 case ECmdAcknowledgedAlarm: |
|
188 iSupervisor->CmdAcknowledgeAlarm(); |
|
189 break; |
|
190 |
|
191 case ECmdTaskAwayFromAlarm: |
|
192 { |
|
193 PIM_TRAPD_ASSERT( iSupervisor->CmdTaskAwayFromAlarmL(); ) |
|
194 } |
|
195 break; |
|
196 |
|
197 case ECmdTaskAwayFromAlarmWTime: |
|
198 { |
|
199 PIM_TRAPD_ASSERT( iSupervisor->CmdTaskAwayFromAlarmL( iPckg() ); ) |
|
200 } |
|
201 break; |
|
202 |
|
203 default: |
|
204 // just omit error, dont set us active until next real message is being sent |
|
205 TRACE_EXIT_POINT; |
|
206 return; |
|
207 } |
|
208 |
|
209 Start(); // restart |
|
210 TRACE_EXIT_POINT; |
|
211 } |
|
212 |
|
213 // ?description |
|
214 void CAknDataFetcher::DoCancel() |
|
215 { |
|
216 TRACE_ENTRY_POINT; |
|
217 // we cannot be active unless connetion is valid |
|
218 iClient.SendSynch( EASAltOpCodeNotifyCancel ); |
|
219 TRACE_EXIT_POINT; |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CAknAlarmWrapper |
|
224 // --------------------------------------------------------------------------- |
|
225 |
|
226 // ?description |
|
227 CAknAlarmWrapper::CAknAlarmWrapper() |
|
228 : iClient( &iActive ) |
|
229 { |
|
230 TRACE_ENTRY_POINT; |
|
231 TRACE_EXIT_POINT; |
|
232 } |
|
233 |
|
234 // Main class, owns client and command fetcher, implements entrypoint and methods of MAlarmObserver |
|
235 void CAknAlarmWrapper::ConstructL( CEikAlmControlSupervisor* aSupervisor, |
|
236 CEikServAppUiBase* aAppUi ) |
|
237 { |
|
238 TRACE_ENTRY_POINT; |
|
239 iAppUi = aAppUi; |
|
240 iActive = new( ELeave )CAknDataFetcher( CActive::EPriorityHigh, aSupervisor, iClient ); |
|
241 TRACE_EXIT_POINT; |
|
242 } |
|
243 |
|
244 // ?description |
|
245 CAknAlarmWrapper::~CAknAlarmWrapper() |
|
246 { |
|
247 TRACE_ENTRY_POINT; |
|
248 delete iActive; |
|
249 iClient.Close(); // if iActive was active, it could need the connection for cancellation |
|
250 TRACE_EXIT_POINT; |
|
251 } |
|
252 |
|
253 // ?description |
|
254 void CAknAlarmWrapper::Release() |
|
255 { |
|
256 TRACE_ENTRY_POINT; |
|
257 delete this; |
|
258 TRACE_EXIT_POINT; |
|
259 } |
|
260 |
|
261 // ?description |
|
262 void CAknAlarmWrapper::ShowAlarm() |
|
263 { |
|
264 TRACE_ENTRY_POINT; |
|
265 // ignore possible error |
|
266 TInt dummy = ETrue; |
|
267 iClient.SendSynch( EASAltOpCodeVisible, dummy ); |
|
268 TRACE_EXIT_POINT; |
|
269 } |
|
270 |
|
271 // ?description |
|
272 void CAknAlarmWrapper::HideAlarm() |
|
273 { |
|
274 TRACE_ENTRY_POINT; |
|
275 // ignore possible error |
|
276 TInt dummy = EFalse; |
|
277 iClient.SendSynch( EASAltOpCodeVisible, dummy ); |
|
278 TRACE_EXIT_POINT; |
|
279 } |
|
280 |
|
281 // ?description |
|
282 TInt CAknAlarmWrapper::CurrentServerState() const |
|
283 { |
|
284 TRACE_ENTRY_POINT; |
|
285 RAknAlarmClient& client = MUTABLE_CAST( RAknAlarmClient&, iClient ); |
|
286 TInt ret( 0 ), err( 0 ); |
|
287 err = client.SendSynch( EAknSAltOpCodeAskServerState, ret ); |
|
288 |
|
289 if( err == KErrNotReady ) // special case |
|
290 { |
|
291 TRACE_EXIT_POINT; |
|
292 return 0; // as alarm control is CBase derived, state will be null until updated otherwise |
|
293 } |
|
294 |
|
295 TRACE_EXIT_POINT; |
|
296 return ( err != KErrNone ? err : ret ); |
|
297 } |
|
298 |
|
299 // ?description |
|
300 void CAknAlarmWrapper::UpdateSoundPauseTimeInterval(TInt /*aMinutes*/) |
|
301 { |
|
302 TRACE_ENTRY_POINT; |
|
303 // empty |
|
304 TRACE_EXIT_POINT; |
|
305 } |
|
306 |
|
307 // ?description |
|
308 void CAknAlarmWrapper::UpdateForAlarmServerState(TInt aNewAlarmServerState) |
|
309 { |
|
310 TRACE_ENTRY_POINT; |
|
311 // ignore possible error |
|
312 iClient.SendSynch( EASAltOpCodeSetState, aNewAlarmServerState ); |
|
313 TRACE_EXIT_POINT; |
|
314 } |
|
315 |
|
316 // ?description |
|
317 void CAknAlarmWrapper::UpdateAlarmInfo(const TASShdAlarm& aAlarm,const TFullName& aOwner) |
|
318 { |
|
319 TRACE_ENTRY_POINT; |
|
320 TInt err = iClient.SetAlarm( aAlarm, aOwner, KNullDesC8 ); |
|
321 |
|
322 if( err == KErrNotReady ) |
|
323 { |
|
324 TRAP( err, iActive->iSupervisor->CmdTaskAwayFromAlarmL( 1 ); ) // snooze to one minute |
|
325 } |
|
326 ASSERT( !err ); |
|
327 TRACE_EXIT_POINT; |
|
328 } |
|
329 |
|
330 // ?description |
|
331 void CAknAlarmWrapper::StartPlayAlarmL(const TDesC& /*aAlarmName*/) |
|
332 { |
|
333 TRACE_ENTRY_POINT; |
|
334 // empty |
|
335 TRACE_EXIT_POINT; |
|
336 } |
|
337 |
|
338 // ?description |
|
339 void CAknAlarmWrapper::StopPlayAlarm() |
|
340 { |
|
341 TRACE_ENTRY_POINT; |
|
342 // empty |
|
343 TRACE_EXIT_POINT; |
|
344 } |
|
345 |
|
346 |
|
347 // End of File |