|
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: An observer and I/F class to observe Publish and Subscribe key changes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "pim_trace.h" |
|
22 #include "PropertyObserver.h" |
|
23 |
|
24 |
|
25 // ============================ MEMBER FUNCTIONS =============================== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CPropertyObserver::CPropertyObserver |
|
29 // C++ default constructor can NOT contain any code, that |
|
30 // might leave. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CPropertyObserver::CPropertyObserver(MPropertyChangeHandler& aHandler, TUid aCategory, TUint aKey) |
|
34 : CActive( CActive::EPriorityStandard ), |
|
35 iCategory( aCategory ), |
|
36 iKey( aKey ), |
|
37 iHandler( aHandler ) |
|
38 { |
|
39 TRACE_ENTRY_POINT; |
|
40 TRACE_EXIT_POINT; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CPropertyObserver::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CPropertyObserver::ConstructL(void) |
|
49 { |
|
50 TRACE_ENTRY_POINT; |
|
51 CActiveScheduler::Add( this ); |
|
52 |
|
53 User::LeaveIfError( iProperty.Attach( iCategory, iKey ) ); |
|
54 |
|
55 NotifyCurrentValue(); // for initial value |
|
56 |
|
57 // Start observing... |
|
58 Subscribe(); |
|
59 TRACE_EXIT_POINT; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CPropertyObserver::NewL |
|
64 // Two-phased constructor. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CPropertyObserver* CPropertyObserver::NewL(MPropertyChangeHandler& aHandler, TUid aCategory, TUint aKey) |
|
68 { |
|
69 TRACE_ENTRY_POINT; |
|
70 CPropertyObserver* self = new( ELeave )CPropertyObserver( aHandler, aCategory, aKey ); |
|
71 CleanupStack::PushL( self ); |
|
72 self->ConstructL(); |
|
73 CleanupStack::Pop( self ); |
|
74 TRACE_EXIT_POINT; |
|
75 return self; |
|
76 } |
|
77 |
|
78 // Destructor |
|
79 CPropertyObserver::~CPropertyObserver() |
|
80 { |
|
81 TRACE_ENTRY_POINT; |
|
82 Deque(); |
|
83 iProperty.Cancel(); |
|
84 iProperty.Close(); |
|
85 TRACE_EXIT_POINT; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CPropertyObserver::RunL |
|
90 // ?implementation_description |
|
91 // (other items were commented in a header). |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CPropertyObserver::RunL(void) |
|
95 { |
|
96 TRACE_ENTRY_POINT; |
|
97 ASSERT( !(iStatus.Int()) ); |
|
98 if( iStatus.Int() == KErrNone ) |
|
99 { |
|
100 Subscribe(); |
|
101 NotifyCurrentValue(); |
|
102 } |
|
103 TRACE_EXIT_POINT; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CPropertyObserver::DoCancel |
|
108 // ?implementation_description |
|
109 // (other items were commented in a header). |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CPropertyObserver::DoCancel(void) |
|
113 { |
|
114 TRACE_ENTRY_POINT; |
|
115 iProperty.Cancel(); |
|
116 TRACE_EXIT_POINT; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CPropertyObserver::Subscribe |
|
121 // ?implementation_description |
|
122 // (other items were commented in a header). |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CPropertyObserver::Subscribe(void) |
|
126 { |
|
127 TRACE_ENTRY_POINT; |
|
128 iProperty.Subscribe( iStatus ); |
|
129 SetActive(); |
|
130 TRACE_EXIT_POINT; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CPropertyObserver::NotifyCurrentValue |
|
135 // ?implementation_description |
|
136 // (other items were commented in a header). |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void CPropertyObserver::NotifyCurrentValue(void) |
|
140 { |
|
141 TRACE_ENTRY_POINT; |
|
142 TInt value; |
|
143 |
|
144 if( iProperty.Get( iCategory, iKey, value ) == KErrNone ) |
|
145 { |
|
146 iHandler.HandlePropertyChange( iCategory, iKey, value ); |
|
147 } |
|
148 TRACE_EXIT_POINT; |
|
149 } |
|
150 |
|
151 |
|
152 // End of File |