1 /* |
|
2 * Copyright (c) 2009 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 #include "cradioenginelogger.h" |
|
19 |
|
20 #include "cradiopropertyobserver.h" |
|
21 |
|
22 // ============================ MEMBER FUNCTIONS =============================== |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 CRadioPropertyObserver::CRadioPropertyObserver( MRadioPropertyChangeObserver& aObserver, |
|
29 const TUid& aCategory, |
|
30 const TUint aKey, |
|
31 const TRadioPropertyType aPropertyType ) |
|
32 : CActive( CActive::EPriorityStandard ) |
|
33 , iObserver( aObserver ) |
|
34 , iCategory( aCategory ) |
|
35 , iKey( aKey ) |
|
36 , iPropertyType( aPropertyType ) |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 void CRadioPropertyObserver::ConstructL() |
|
45 { |
|
46 switch ( iPropertyType ) |
|
47 { |
|
48 case ERadioPropertyInt: |
|
49 { |
|
50 break; |
|
51 } |
|
52 case ERadioPropertyByteArray: |
|
53 { |
|
54 iValueByteArray = HBufC8::NewL( RProperty::KMaxPropertySize ); |
|
55 break; |
|
56 } |
|
57 case ERadioPropertyText: |
|
58 { |
|
59 // Max size in bytes, length is size / 2 |
|
60 iValueText = HBufC::NewL( RProperty::KMaxPropertySize / 2 ); |
|
61 break; |
|
62 } |
|
63 default: |
|
64 { |
|
65 break; |
|
66 } |
|
67 } |
|
68 |
|
69 User::LeaveIfError( iProperty.Attach( iCategory, iKey ) ); |
|
70 CActiveScheduler::Add( this ); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 EXPORT_C CRadioPropertyObserver* CRadioPropertyObserver::NewL( MRadioPropertyChangeObserver& aObserver, |
|
78 const TUid& aCategory, |
|
79 const TUint aKey, |
|
80 const TRadioPropertyType aPropertyType ) |
|
81 { |
|
82 CRadioPropertyObserver* self = new( ELeave )CRadioPropertyObserver( aObserver, |
|
83 aCategory, aKey, aPropertyType ); |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop( self ); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 CRadioPropertyObserver::~CRadioPropertyObserver() |
|
95 { |
|
96 Cancel(); |
|
97 iProperty.Close(); |
|
98 delete iValueByteArray; |
|
99 delete iValueText; |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Subscribes to a property and reads the value, if not already active. |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C void CRadioPropertyObserver::ActivateL() |
|
107 { |
|
108 if ( !IsActive() ) |
|
109 { |
|
110 RunL(); |
|
111 } |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CRadioPropertyObserver::RunL() |
|
119 { |
|
120 LOG_METHOD_AUTO; |
|
121 |
|
122 iProperty.Subscribe( iStatus ); |
|
123 SetActive(); |
|
124 |
|
125 TInt err( KErrNone ); |
|
126 |
|
127 switch ( iPropertyType ) |
|
128 { |
|
129 case ERadioPropertyInt: |
|
130 { |
|
131 err = iProperty.Get( iValueInt ); |
|
132 if ( !err ) |
|
133 { |
|
134 iObserver.HandlePropertyChangeL( iCategory, iKey, iValueInt ); |
|
135 } |
|
136 break; |
|
137 } |
|
138 case ERadioPropertyByteArray: |
|
139 { |
|
140 TPtr8 ptr8( iValueByteArray->Des() ); |
|
141 err = iProperty.Get( ptr8 ); |
|
142 if ( !err ) |
|
143 { |
|
144 iObserver.HandlePropertyChangeL( iCategory, iKey, *iValueByteArray ); |
|
145 } |
|
146 break; |
|
147 } |
|
148 case ERadioPropertyText: |
|
149 { |
|
150 TPtr ptr( iValueText->Des() ); |
|
151 err = iProperty.Get( ptr ); |
|
152 if ( !err ) |
|
153 { |
|
154 iObserver.HandlePropertyChangeL( iCategory, iKey, *iValueText ); |
|
155 } |
|
156 break; |
|
157 } |
|
158 default: |
|
159 { |
|
160 break; |
|
161 } |
|
162 } |
|
163 |
|
164 if ( err ) |
|
165 { |
|
166 iObserver.HandlePropertyChangeErrorL( iCategory, iKey, err ); |
|
167 } |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // Cancels an outstanding active request |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CRadioPropertyObserver::DoCancel() |
|
175 { |
|
176 iProperty.Cancel(); |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // Getter for integer value |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C TInt CRadioPropertyObserver::ValueInt() const |
|
184 { |
|
185 return iValueInt; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // Getter for byte array value |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 EXPORT_C const TDesC8& CRadioPropertyObserver::ValueDes8() const |
|
193 { |
|
194 return *iValueByteArray; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // Getter for text value |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 EXPORT_C const TDesC& CRadioPropertyObserver::ValueDes() const |
|
202 { |
|
203 return *iValueText; |
|
204 } |
|