|
1 /* |
|
2 * Copyright (c) 2006-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: CCFEcomObserver class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cfecomobserver.h" |
|
20 #include "cftrace.h" |
|
21 #include "cfstateobserver.h" |
|
22 |
|
23 // LOCAL DEFINITIONS |
|
24 |
|
25 #ifdef _DEBUG |
|
26 _LIT( KPanicCat, "CFEcomObs" ); |
|
27 |
|
28 // Panic codes |
|
29 enum TPanicReason |
|
30 { |
|
31 EAlreadyActive, |
|
32 EInvalidObserver |
|
33 }; |
|
34 |
|
35 // LOCAL FUNCTIONS |
|
36 LOCAL_C void Panic( TInt aReason ) |
|
37 { |
|
38 User::Panic( KPanicCat, aReason ); |
|
39 } |
|
40 #endif |
|
41 |
|
42 //----------------------------------------------------------------------------- |
|
43 // CCFEComObserver::CCFEComObserver |
|
44 //----------------------------------------------------------------------------- |
|
45 // |
|
46 CCFEComObserver::CCFEComObserver(): CActive( EPriorityStandard ) |
|
47 { |
|
48 FUNC_LOG; |
|
49 |
|
50 CActiveScheduler::Add( this ); |
|
51 } |
|
52 |
|
53 //----------------------------------------------------------------------------- |
|
54 // CCFEComObserver::NewLC |
|
55 //----------------------------------------------------------------------------- |
|
56 // |
|
57 CCFEComObserver* CCFEComObserver::NewLC() |
|
58 { |
|
59 FUNC_LOG; |
|
60 |
|
61 CCFEComObserver* self = new ( ELeave ) CCFEComObserver(); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 return self; |
|
65 } |
|
66 |
|
67 //----------------------------------------------------------------------------- |
|
68 // CCFEComObserver::NewL |
|
69 //----------------------------------------------------------------------------- |
|
70 // |
|
71 CCFEComObserver* CCFEComObserver::NewL() |
|
72 { |
|
73 FUNC_LOG; |
|
74 |
|
75 CCFEComObserver* self = CCFEComObserver::NewLC(); |
|
76 CleanupStack::Pop(); // self; |
|
77 return self; |
|
78 } |
|
79 |
|
80 //----------------------------------------------------------------------------- |
|
81 // CCFEComObserver::ConstructL |
|
82 //----------------------------------------------------------------------------- |
|
83 // |
|
84 void CCFEComObserver::ConstructL() |
|
85 { |
|
86 FUNC_LOG; |
|
87 |
|
88 iEComSession = &REComSession::OpenL(); |
|
89 StartObserving(); |
|
90 } |
|
91 |
|
92 //----------------------------------------------------------------------------- |
|
93 // CCFEComObserver::~CCFEComObserver |
|
94 //----------------------------------------------------------------------------- |
|
95 // |
|
96 CCFEComObserver::~CCFEComObserver() |
|
97 { |
|
98 FUNC_LOG; |
|
99 |
|
100 // Cancel any request, if outstanding |
|
101 Cancel(); |
|
102 |
|
103 // Clean up memebers |
|
104 iObservers.Close(); |
|
105 if( iEComSession ) |
|
106 { |
|
107 iEComSession->Close(); |
|
108 } |
|
109 } |
|
110 |
|
111 //----------------------------------------------------------------------------- |
|
112 // CCFEComObserver::DoCancel |
|
113 //----------------------------------------------------------------------------- |
|
114 // |
|
115 void CCFEComObserver::DoCancel() |
|
116 { |
|
117 FUNC_LOG; |
|
118 |
|
119 iEComSession->CancelNotifyOnChange( iStatus ); |
|
120 } |
|
121 |
|
122 //----------------------------------------------------------------------------- |
|
123 // CCFEComObserver::StartObserving |
|
124 //----------------------------------------------------------------------------- |
|
125 // |
|
126 void CCFEComObserver::StartObserving() |
|
127 { |
|
128 FUNC_LOG; |
|
129 |
|
130 __ASSERT_DEBUG( !IsActive(), Panic( EAlreadyActive) ); |
|
131 |
|
132 SetActive(); |
|
133 iEComSession->NotifyOnChange( iStatus ); |
|
134 } |
|
135 |
|
136 //----------------------------------------------------------------------------- |
|
137 // CCFEComObserver::AddObserverL |
|
138 //----------------------------------------------------------------------------- |
|
139 // |
|
140 void CCFEComObserver::AddObserverL( MCFStateObserver* aObserver ) |
|
141 { |
|
142 FUNC_LOG; |
|
143 |
|
144 __ASSERT_DEBUG( aObserver, Panic( EInvalidObserver ) ); |
|
145 |
|
146 iObservers.AppendL( aObserver ); |
|
147 } |
|
148 |
|
149 |
|
150 //----------------------------------------------------------------------------- |
|
151 // CCFEComObserver::RunL |
|
152 //----------------------------------------------------------------------------- |
|
153 // |
|
154 void CCFEComObserver::RunL() |
|
155 { |
|
156 FUNC_LOG; |
|
157 |
|
158 // Store completion status |
|
159 TInt status = iStatus.Int(); |
|
160 |
|
161 // Continue request |
|
162 StartObserving(); |
|
163 |
|
164 // Notify observers |
|
165 if( status == KErrNone ) |
|
166 { |
|
167 NotifyObservers(); |
|
168 } |
|
169 } |
|
170 |
|
171 //----------------------------------------------------------------------------- |
|
172 // CCFEComObserver::RunError |
|
173 //----------------------------------------------------------------------------- |
|
174 // |
|
175 TInt CCFEComObserver::RunError( TInt aError ) |
|
176 { |
|
177 return aError; |
|
178 } |
|
179 |
|
180 //------------------------------------------------------------------------------ |
|
181 // CCFEComObserver::NotifyObservers |
|
182 //------------------------------------------------------------------------------ |
|
183 // |
|
184 void CCFEComObserver::NotifyObservers() |
|
185 { |
|
186 FUNC_LOG; |
|
187 |
|
188 INFO( "CCFEComObserver::NotifyObservers - New plug-ins detected, updating" ); |
|
189 |
|
190 TInt count = iObservers.Count(); |
|
191 for( TInt i = 0; i < count; i++ ) |
|
192 { |
|
193 TInt err = KErrNone; |
|
194 TRAP( err, iObservers[i]->UpdatePlugInsL( ) ); |
|
195 ERROR( err, "Failed to update plug-ins" ); |
|
196 } |
|
197 } |
|
198 |
|
199 // End of file |
|
200 |