|
1 /* |
|
2 * Copyright (c) 2004 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 the License "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: |
|
15 * Implementation of CActiveFavouritesDbNotifier. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "ActiveFavouritesDbNotifier.h" |
|
24 #include "FavouritesDbObserver.h" |
|
25 |
|
26 // ================= MEMBER FUNCTIONS ======================= |
|
27 |
|
28 // --------------------------------------------------------- |
|
29 // CActiveFavouritesDbNotifier::CActiveFavouritesDbNotifier |
|
30 // --------------------------------------------------------- |
|
31 // |
|
32 EXPORT_C CActiveFavouritesDbNotifier::CActiveFavouritesDbNotifier |
|
33 ( RFavouritesDb& aDb, MFavouritesDbObserver& aObserver ) |
|
34 : CActive( EPriorityStandard ), iDb( aDb ), iObserver( &aObserver ) |
|
35 { |
|
36 CActiveScheduler::Add( this ); |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------- |
|
40 // CActiveFavouritesDbNotifier::~CActiveFavouritesDbNotifier |
|
41 // --------------------------------------------------------- |
|
42 // |
|
43 EXPORT_C CActiveFavouritesDbNotifier::~CActiveFavouritesDbNotifier() |
|
44 { |
|
45 iNotifier.Close(); |
|
46 Cancel(); |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CActiveFavouritesDbNotifier::RunL |
|
51 // --------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C void CActiveFavouritesDbNotifier::RunL() |
|
54 { |
|
55 if ( iStatus == KErrCancel ) |
|
56 { |
|
57 // Cancelled, do nothing. |
|
58 } |
|
59 else |
|
60 { |
|
61 // Otherwise, the event must be one of RDbNotifier::TEvent. |
|
62 RDbNotifier::TEvent event = |
|
63 STATIC_CAST( RDbNotifier::TEvent, iStatus.Int() ); |
|
64 if ( iStatus == RDbNotifier::EClose ) |
|
65 { |
|
66 // Finish if the database is closed. |
|
67 iNotifier.Close(); |
|
68 } |
|
69 else |
|
70 { |
|
71 // Reschedule automatically (as long as the database is open). |
|
72 NotifyChange(); |
|
73 } |
|
74 // Call observer *after* the notifier is rescheduled: this way |
|
75 // the notifier stays alive even if observer leaves. |
|
76 iObserver->HandleFavouritesDbEventL( event ); |
|
77 } |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CActiveFavouritesDbNotifier::DoCancel |
|
82 // --------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C void CActiveFavouritesDbNotifier::DoCancel() |
|
85 { |
|
86 iNotifier.Close(); |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------- |
|
90 // CActiveFavouritesDbNotifier::Start |
|
91 // --------------------------------------------------------- |
|
92 // |
|
93 EXPORT_C TInt CActiveFavouritesDbNotifier::Start() |
|
94 { |
|
95 TInt err = iNotifier.Open( iDb ); |
|
96 if ( !err ) |
|
97 { |
|
98 NotifyChange(); |
|
99 } |
|
100 return err; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CActiveFavouritesDbNotifier::NotifyChange |
|
105 // --------------------------------------------------------- |
|
106 // |
|
107 void CActiveFavouritesDbNotifier::NotifyChange() |
|
108 { |
|
109 if ( !IsActive() ) |
|
110 { |
|
111 iNotifier.NotifyChange( iStatus ); |
|
112 SetActive(); |
|
113 } |
|
114 } |
|
115 |
|
116 // End of File |