1 /* |
|
2 * Copyright (c) 2002-2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "scppropertynotifier.h" |
|
20 #include "scplogger.h" |
|
21 #include "scppropertyobserver.h" |
|
22 |
|
23 // ----------------------------------------------------------------------------- |
|
24 // CScpPropertyNotifier::CCScpPropertyNotifier |
|
25 // ----------------------------------------------------------------------------- |
|
26 // |
|
27 CScpPropertyNotifier::CScpPropertyNotifier( TUid aUid, |
|
28 TInt aType, |
|
29 MScpPropertyObserver& aObserver ) : |
|
30 CActive( CActive::EPriorityStandard ), |
|
31 iUid( aUid ), |
|
32 iType( aType ), |
|
33 iObserver( aObserver ) |
|
34 { |
|
35 SCPLOGSTRING( "CScpPropertyNotifier::CScpPropertyNotifier" ); |
|
36 |
|
37 CActiveScheduler::Add( this ); |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CScpPropertyNotifier::ConstructL |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 void CScpPropertyNotifier::ConstructL() |
|
45 { |
|
46 SCPLOGSTRING( "CScpPropertyNotifier::ConstructL" ); |
|
47 |
|
48 User::LeaveIfError( iProperty.Attach( iUid, iType ) ); |
|
49 |
|
50 Subscribe(); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CScpPropertyNotifier::NewL |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CScpPropertyNotifier* CScpPropertyNotifier::NewL( TUid aUid, |
|
58 TInt aType, |
|
59 MScpPropertyObserver& aObserver ) |
|
60 { |
|
61 SCPLOGSTRING( "CScpPropertyNotifier::NewL" ); |
|
62 |
|
63 CScpPropertyNotifier* self = new(ELeave) CScpPropertyNotifier( aUid, |
|
64 aType, |
|
65 aObserver ); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop( self ); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CScpPropertyNotifier::~CScpPropertyNotifier |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CScpPropertyNotifier::~CScpPropertyNotifier() |
|
77 { |
|
78 SCPLOGSTRING( "CScpPropertyNotifier::~CScpPropertyNotifier" ); |
|
79 |
|
80 Cancel(); |
|
81 iProperty.Close(); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CScpPropertyNotifier::GetValue |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 TInt CScpPropertyNotifier::GetValue( TInt& aValue ) const |
|
89 { |
|
90 SCPLOGSTRING( "CScpPropertyNotifier::GetValue" ); |
|
91 |
|
92 return iProperty.Get( iUid, iType, aValue ); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CScpPropertyNotifier::Subscribe |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CScpPropertyNotifier::Subscribe() |
|
100 { |
|
101 SCPLOGSTRING( "CScpPropertyNotifier::Subscribe" ); |
|
102 __ASSERT_DEBUG(!IsActive(), User::Panic( KNullDesC, KErrGeneral ) ); |
|
103 |
|
104 if ( !IsActive() ) |
|
105 { |
|
106 iProperty.Subscribe( iStatus ); |
|
107 SetActive(); |
|
108 } |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CScpPropertyNotifier::RunL |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void CScpPropertyNotifier::RunL() |
|
116 { |
|
117 SCPLOGSTRING( "CScpPropertyNotifier::RunL" ); |
|
118 |
|
119 if( iStatus.Int() == KErrNone ) |
|
120 { |
|
121 TInt value = 0; |
|
122 GetValue( value ); |
|
123 |
|
124 iObserver.HandlePropertyChanged( value ); |
|
125 } |
|
126 |
|
127 Subscribe(); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CScpPropertyNotifier::NewL |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 #ifdef _DEBUG |
|
135 TInt CScpPropertyNotifier::RunError( TInt aError ) |
|
136 { |
|
137 SCPLOGSTRING2( "CScpPropertyNotifier::RunError: %d", aError ); |
|
138 #else |
|
139 TInt CScpPropertyNotifier::RunError( TInt /*aError*/ ) |
|
140 { |
|
141 #endif |
|
142 // Errors are disarded |
|
143 return KErrNone; |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CScpPropertyNotifier::NewL |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void CScpPropertyNotifier::DoCancel() |
|
151 { |
|
152 SCPLOGSTRING( "CScpPropertyNotifier::DoCancel" ); |
|
153 |
|
154 iProperty.Cancel(); |
|
155 } |
|
156 |
|
157 // End of File |
|