|
1 /* |
|
2 * Copyright (c) 2005-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: Publish and subscribe parameter observer implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "caipspropertyobserver.h" |
|
20 |
|
21 // --------------------------------------------------------------------------- |
|
22 // void ConstructL( TCallBack aCallBack, TUid aCategory, TInt aKey ) |
|
23 // --------------------------------------------------------------------------- |
|
24 // |
|
25 void CPSPropertyObserver::ConstructL() |
|
26 { |
|
27 User::LeaveIfError( iProperty.Attach( iCategory, iKey ) ); |
|
28 CActiveScheduler::Add( this ); |
|
29 |
|
30 iProperty.Subscribe( iStatus ); |
|
31 SetActive(); |
|
32 } |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // CPSPropertyObserver() |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CPSPropertyObserver::CPSPropertyObserver( TCallBack aCallBack, |
|
39 TUid aCategory, |
|
40 TInt aKey ) |
|
41 : CActive( EPriorityStandard ), |
|
42 iCallBack( aCallBack ), |
|
43 iCategory( aCategory ), |
|
44 iKey( aKey ) |
|
45 { |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CPSPropertyObserver* NewL( TCallBack aCallBack, TUid aCategory, TInt aKey ) |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CPSPropertyObserver* CPSPropertyObserver::NewL( TCallBack aCallBack, |
|
53 TUid aCategory, |
|
54 TInt aKey ) |
|
55 { |
|
56 CPSPropertyObserver* self = new ( ELeave ) CPSPropertyObserver( aCallBack, |
|
57 aCategory, |
|
58 aKey ); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // ~CPSPropertyObserver() |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CPSPropertyObserver::~CPSPropertyObserver() |
|
70 { |
|
71 if( IsAdded() ) |
|
72 { |
|
73 Deque(); |
|
74 } |
|
75 iProperty.Close(); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // void Release() |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CPSPropertyObserver::Release() |
|
83 { |
|
84 delete this; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // void RunL() |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 void CPSPropertyObserver::RunL() |
|
92 { |
|
93 // resubscribe before processing new value to prevent missing updates. |
|
94 iProperty.Subscribe( iStatus ); |
|
95 SetActive(); |
|
96 |
|
97 // property updated, get new value. |
|
98 TInt propval; |
|
99 if ( iProperty.Get( iCategory, iKey, propval ) != KErrNotFound ) |
|
100 { |
|
101 iCallBack.CallBack(); |
|
102 } |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // void DoCancel() |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void CPSPropertyObserver::DoCancel() |
|
110 { |
|
111 iProperty.Cancel(); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // TInt Get( TInt& aValue ) |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 TInt CPSPropertyObserver::Get( TInt& aValue ) |
|
119 { |
|
120 TInt error = iProperty.Get( iCategory, iKey, aValue ); |
|
121 |
|
122 return error; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // TInt Get( TDes8& aString ) |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 TInt CPSPropertyObserver::Get( TDes8& aString ) |
|
130 { |
|
131 TInt error = iProperty.Get( iCategory, iKey, aString ); |
|
132 return error; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // TInt Get( TDes16& aString ) |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CPSPropertyObserver::Get( TDes16& aString ) |
|
140 { |
|
141 TInt error = iProperty.Get( iCategory, iKey, aString ); |
|
142 return error; |
|
143 } |
|
144 |
|
145 // ========== OTHER EXPORTED FUNCTIONS ======================================== |
|
146 |
|
147 // End of File. |