|
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 "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: Publish & Subscribe property change observer implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CIMPSCenrepObserver.h" |
|
22 #include "MIMPSPropertyNotificationObserver.h" |
|
23 |
|
24 #include <bautils.h> |
|
25 #include <barsc.h> |
|
26 #include <centralrepository.h> |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CIMPSCenrepObserver::CIMPSCenrepObserver |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CIMPSCenrepObserver::CIMPSCenrepObserver( MIMPSPropertyNotificationObserver& aObserver ) |
|
37 : CActive( CActive::EPriorityLow ), |
|
38 iObserver( aObserver ) |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CIMPSCenrepObserver::ConstructL |
|
44 // Symbian 2nd phase constructor can leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CIMPSCenrepObserver::ConstructL() |
|
48 { |
|
49 CActiveScheduler::Add( this ); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CIMPSPropertyObserver::NewL |
|
54 // Two-phased constructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CIMPSCenrepObserver* CIMPSCenrepObserver::NewL( MIMPSPropertyNotificationObserver& aObserver ) |
|
58 { |
|
59 CIMPSCenrepObserver* self = new( ELeave ) CIMPSCenrepObserver( aObserver ); |
|
60 |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop(); |
|
64 |
|
65 return self; |
|
66 } |
|
67 |
|
68 |
|
69 // Destructor |
|
70 CIMPSCenrepObserver::~CIMPSCenrepObserver() |
|
71 { |
|
72 if ( IsActive() ) |
|
73 { |
|
74 Cancel(); |
|
75 } |
|
76 delete iRepository; |
|
77 } |
|
78 |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CIMPSCenrepObserver::ObservePropertyChangeL |
|
82 // (other items were commented in a header). |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void CIMPSCenrepObserver::ObservePropertyChangeL( TUid aCategory, TUint aKey ) |
|
86 { |
|
87 if ( IsActive() ) |
|
88 { |
|
89 return; |
|
90 } |
|
91 |
|
92 CRepository* tempRepository = CRepository::NewL( aCategory ); |
|
93 delete iRepository; |
|
94 iRepository = tempRepository; |
|
95 |
|
96 User::LeaveIfError( iRepository->NotifyRequest( aKey, iStatus ) ); |
|
97 |
|
98 iKey = aKey; |
|
99 iCategory = aCategory; |
|
100 |
|
101 SetActive(); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CIMPSCenrepObserver::CancelObserve |
|
106 // (other items were commented in a header). |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CIMPSCenrepObserver::CancelObserve() |
|
110 { |
|
111 if ( IsActive() ) |
|
112 { |
|
113 Cancel(); |
|
114 } |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CIMPSCenrepObserver::RunL |
|
119 // (other items were commented in a header). |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CIMPSCenrepObserver::RunL() |
|
123 { |
|
124 // subscribe to a new notification |
|
125 User::LeaveIfError( iRepository->NotifyRequest( iKey, iStatus ) ); |
|
126 SetActive(); |
|
127 // notify observer |
|
128 iObserver.HandlePropertyNotificationEventL( iCategory, iKey ); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CIMPSCenrepObserver::DoCancel |
|
133 // (other items were commented in a header). |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CIMPSCenrepObserver::DoCancel() |
|
137 { |
|
138 iRepository->NotifyCancel( iKey ); |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CIMPSCenrepObserver::Category |
|
143 // (other items were commented in a header). |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TUid CIMPSCenrepObserver::Category() |
|
147 { |
|
148 return iCategory; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CIMPSCenrepObserver::Key |
|
153 // (other items were commented in a header). |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 TUint CIMPSCenrepObserver::Key() |
|
157 { |
|
158 return iKey; |
|
159 } |
|
160 |
|
161 // End of File |