|
1 /* |
|
2 * Copyright (c) 2005-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: Source file for IRControlEventObserver. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ircontroleventobserver.h" |
|
20 #include "irdebug.h" |
|
21 #include "irpubsubkeys.h" |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS =============================== |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // C++ default constructor can NOT contain any code, that might leave. |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CIRControlEventObserver::CIRControlEventObserver(CIRUi& aObserver, const TUid& aCategory, |
|
30 const TUint aKey, const RProperty::TType aPropertyType) |
|
31 : CActive( CActive::EPriorityStandard ), |
|
32 iObserver( aObserver ), |
|
33 iCategory( aCategory ), |
|
34 iKey( aKey ), |
|
35 iPropertyType( aPropertyType ) |
|
36 { |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // Symbian 2nd phase constructor can leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 void CIRControlEventObserver::ConstructL() |
|
44 { |
|
45 User::LeaveIfError( iProperty.Attach( iCategory, iKey ) ); |
|
46 CActiveScheduler::Add( this ); |
|
47 |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // Two-phased constructor. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C CIRControlEventObserver* CIRControlEventObserver::NewL(CIRUi& aObserver, |
|
55 const TUid& aCategory, |
|
56 const TUint aKey, const RProperty::TType aPropertyType) |
|
57 { |
|
58 CIRControlEventObserver* self = new( ELeave )CIRControlEventObserver( aObserver, aCategory, |
|
59 aKey, aPropertyType ); |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // Destructor |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CIRControlEventObserver::~CIRControlEventObserver() |
|
71 { |
|
72 Cancel(); |
|
73 iProperty.Close(); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // Subscribes to a property and reads the value, if not already active. |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 EXPORT_C void CIRControlEventObserver::SecondConstructL() |
|
81 { |
|
82 if ( !IsActive() ) |
|
83 { |
|
84 iProperty.Subscribe( iStatus ); |
|
85 SetActive(); |
|
86 } |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CIRControlEventObserver::RunL |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 void CIRControlEventObserver::RunL() |
|
94 { |
|
95 IRRDEBUG2("CIRControlEventObserver:RunL entering",KNullDesC); |
|
96 iProperty.Subscribe( iStatus ); |
|
97 SetActive(); |
|
98 TInt err(KErrNone); |
|
99 |
|
100 IRRDEBUG2("CIRControlEventObserver:RunL iKey = %d",iKey); |
|
101 |
|
102 if(iKey == KIRPSControlSetPlayState) |
|
103 { |
|
104 IRRDEBUG2("CIRControlEventObserver:RunL KIRPSControlSetPlayState = %d",iKey); |
|
105 |
|
106 } |
|
107 |
|
108 switch (iPropertyType) |
|
109 { |
|
110 // Subscribes the property of interger type |
|
111 case RProperty::EInt: |
|
112 { |
|
113 err = iProperty.Get( iValue ); |
|
114 IRRDEBUG2("CIRControlEventObserver:RunL Error in get of property = %d",err); |
|
115 |
|
116 if (!err) |
|
117 { |
|
118 if(iKey == KIRPSControlSetPlayState) |
|
119 { |
|
120 iObserver.PlayerStateChangedL(static_cast<TIRStopPlayState> (iValue)); |
|
121 } |
|
122 |
|
123 } |
|
124 break; |
|
125 } |
|
126 // Subscribes the property of text type |
|
127 case RProperty::ELargeText: |
|
128 { |
|
129 break; |
|
130 } |
|
131 default: |
|
132 { |
|
133 break; |
|
134 } |
|
135 } |
|
136 |
|
137 if (err) |
|
138 { |
|
139 //iObserver.HandlePropertyChangeErrorL(iCategory, iKey, err) |
|
140 } |
|
141 IRRDEBUG2("CIRControlEventObserver:RunL exiting",KNullDesC); |
|
142 |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // Cancels an outstanding active request |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CIRControlEventObserver::DoCancel() |
|
150 { |
|
151 iProperty.Cancel(); |
|
152 } |
|
153 |
|
154 |