|
1 /* |
|
2 * Copyright (c) 2008 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: Subscribes properties from P&S |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "xnpropertysubscriber.h" |
|
19 |
|
20 // ----------------------------------------------------------------------------- |
|
21 // ----------------------------------------------------------------------------- |
|
22 // |
|
23 CXnPropertySubscriber::CXnPropertySubscriber( |
|
24 MXnPropertyChangeObserver& aObserver, |
|
25 const TUint32 aKey ) |
|
26 : CActive( EPriorityStandard ), |
|
27 iPropertyChangeObserver( aObserver ), |
|
28 iKey( aKey ) |
|
29 { |
|
30 } |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CXnPropertySubscriber* CXnPropertySubscriber::NewLC( |
|
36 const TUid aUid, |
|
37 const TUint32 aKey, |
|
38 MXnPropertyChangeObserver& aObserver ) |
|
39 { |
|
40 CXnPropertySubscriber* self = |
|
41 new ( ELeave ) CXnPropertySubscriber( aObserver, aKey ); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL( aUid, aKey ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CXnPropertySubscriber* CXnPropertySubscriber::NewL( |
|
51 const TUid aUid, |
|
52 const TUint32 aKey, |
|
53 MXnPropertyChangeObserver& aObserver ) |
|
54 { |
|
55 CXnPropertySubscriber* self = CXnPropertySubscriber::NewLC( |
|
56 aUid, aKey, aObserver ); |
|
57 CleanupStack::Pop(); // self; |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CXnPropertySubscriber::ConstructL( |
|
65 const TUid aUid, |
|
66 const TUint32 aKey ) |
|
67 { |
|
68 User::LeaveIfError( iProperty.Attach( aUid, aKey ) ); |
|
69 CActiveScheduler::Add( this ); // Add to scheduler |
|
70 // initial subscription and process current property value |
|
71 RunL(); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CXnPropertySubscriber::~CXnPropertySubscriber() |
|
78 { |
|
79 Cancel(); // Cancel any request, if outstanding |
|
80 iProperty.Close(); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CXnPropertySubscriber::DoCancel() |
|
87 { |
|
88 iProperty.Close(); |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CXnPropertySubscriber::RunL() |
|
95 { |
|
96 // resubscribe before processing new value to prevent missing updates |
|
97 iProperty.Subscribe( iStatus ); |
|
98 SetActive(); |
|
99 |
|
100 TInt intValue; |
|
101 if ( iProperty.Get( intValue ) != KErrNotFound ) |
|
102 { |
|
103 iPropertyChangeObserver.PropertyChangedL( iKey, intValue ); |
|
104 } |
|
105 } |