|
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: hsps FileChangeListener listens to given file folder and notifies it observer |
|
15 * if there is any file change. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 #include "hsps_builds_cfg.hrh" |
|
21 #include "hspsfilechangelistener.h" |
|
22 |
|
23 #ifdef _hsps_EMULATOR_SUPPORT_ |
|
24 #include "hspsfilechangelisteneremu.h" |
|
25 #endif |
|
26 |
|
27 #ifdef HSPS_LOG_ACTIVE |
|
28 #include <hspslogbus.h> |
|
29 #endif |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // ChspsFileChangeListener::ChspsFileChangeListener |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 |
|
40 ChspsFileChangeListener::ChspsFileChangeListener( RFs& aFs, |
|
41 MhspsFileChangeObserver& aObserver, |
|
42 TNotifyType aNotifyType, |
|
43 TListenerType aListenerType) : |
|
44 CActive( EPriorityStandard ), |
|
45 iFs( aFs ), |
|
46 iObserver( aObserver), |
|
47 iNotifyType( aNotifyType ), |
|
48 iListenerType( aListenerType ) |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // ChspsFileChangeListener::ConstructL |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void ChspsFileChangeListener::ConstructL( const TDesC& aFullPath ) |
|
58 { |
|
59 if ( aFullPath.Length() > 0 ) |
|
60 { |
|
61 iFullPath.Append( aFullPath ); |
|
62 } |
|
63 CActiveScheduler::Add( this ); |
|
64 // should not make file change listener active yet because server must let |
|
65 // start fully first. See ChspsThemeServer constructor. |
|
66 #ifdef _hsps_EMULATOR_SUPPORT_ |
|
67 iFileChange = ChspsFileChangeListenerEmu::NewL( iFs, *this, EEmuNotifyAll, aFullPath); |
|
68 #endif |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // ChspsFileChangeListener::NewL |
|
73 // Two-phased constructor. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 ChspsFileChangeListener* ChspsFileChangeListener::NewL( RFs& aFs, |
|
77 MhspsFileChangeObserver& aObserver, |
|
78 TNotifyType aNotifyType, |
|
79 const TDesC& aFullPath, |
|
80 TListenerType aListenerType ) |
|
81 { |
|
82 ChspsFileChangeListener* self = new(ELeave) ChspsFileChangeListener( aFs, |
|
83 aObserver, |
|
84 aNotifyType, |
|
85 aListenerType ); |
|
86 CleanupStack::PushL( self ); |
|
87 self->ConstructL( aFullPath ); |
|
88 CleanupStack::Pop( self ); |
|
89 |
|
90 return self; |
|
91 } |
|
92 |
|
93 |
|
94 // ------------------------------------------------------------------------------ |
|
95 // ChspsFileChangeListener::~ChspsFileChangeListener |
|
96 // |
|
97 // ------------------------------------------------------------------------------ |
|
98 ChspsFileChangeListener::~ChspsFileChangeListener() |
|
99 { |
|
100 iFs.NotifyChangeCancel(iStatus); |
|
101 Cancel(); |
|
102 #ifdef _hsps_EMULATOR_SUPPORT_ |
|
103 if (iFileChange) |
|
104 { |
|
105 delete iFileChange; |
|
106 iFileChange = NULL; |
|
107 } |
|
108 #endif |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // ChspsFileChangeListener::RunL |
|
113 // From CActive. Called when asynchronous request is completed. |
|
114 // Notifies the observer |
|
115 // (other items were commented in a header). |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void ChspsFileChangeListener::RunL() |
|
119 { |
|
120 if ( iStatus.Int() == KErrNone ) |
|
121 { |
|
122 InformObserver(); |
|
123 } |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // ChspsFileChangeListener::RunError |
|
128 // From CActive. Called when error occurred in asynchronous request |
|
129 // Notifies the observer |
|
130 // (other items were commented in a header). |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 TInt ChspsFileChangeListener::RunError( TInt /*aError*/ ) |
|
134 { |
|
135 return KErrNone; |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // ChspsFileChangeListener::DoCancel |
|
140 // From CActive. Called when asynchronous request is canceled |
|
141 // (other items were commented in a header). |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void ChspsFileChangeListener::DoCancel() |
|
145 { |
|
146 iFs.NotifyChangeCancel(iStatus); |
|
147 } |
|
148 |
|
149 // ------------------------------------------------------------------------------ |
|
150 // ChspsFileChangeListener::Setup |
|
151 // |
|
152 // ------------------------------------------------------------------------------ |
|
153 // |
|
154 void ChspsFileChangeListener::Setup() |
|
155 { |
|
156 if( !IsActive() ) |
|
157 { |
|
158 iFs.NotifyChangeCancel(iStatus); |
|
159 if( iFullPath.Length() > 0 && !IsActive() ) |
|
160 { |
|
161 iStatus = KRequestPending; |
|
162 SetActive(); |
|
163 iFs.NotifyChange( ENotifyAll, iStatus, iFullPath ); |
|
164 } |
|
165 } |
|
166 #ifdef _hsps_EMULATOR_SUPPORT_ |
|
167 TInt errCode = KErrNone; |
|
168 TRAP(errCode,iFileChange->StartL();) |
|
169 if (errCode) |
|
170 { |
|
171 #ifdef HSPS_LOG_ACTIVE |
|
172 if( iLogBus ) |
|
173 { |
|
174 iLogBus->LogText( _L( "ChspsFileChangeListener::Setup() errCode=%d" ), |
|
175 errCode ); |
|
176 } |
|
177 #endif |
|
178 } |
|
179 #endif |
|
180 } |
|
181 |
|
182 // ------------------------------------------------------------------------------ |
|
183 // ChspsFileChangeListener::InformObserver |
|
184 // |
|
185 // ------------------------------------------------------------------------------ |
|
186 // |
|
187 void ChspsFileChangeListener::InformObserver() |
|
188 { |
|
189 |
|
190 switch (iListenerType) |
|
191 { |
|
192 case TImportDirListener: |
|
193 { |
|
194 iObserver.HandleFileSystemChange(); |
|
195 } |
|
196 break; |
|
197 |
|
198 case TRepositoryListener: |
|
199 { |
|
200 iObserver.HandleRepositoryChange(); |
|
201 } |
|
202 break; |
|
203 |
|
204 default: |
|
205 { |
|
206 #ifdef HSPS_LOG_ACTIVE |
|
207 if( iLogBus ) |
|
208 { |
|
209 iLogBus->LogText( _L( "ChspsFileChangeListener::RunL(): - Invalid listener type(%d)" ), |
|
210 iListenerType ); |
|
211 } |
|
212 #endif |
|
213 } |
|
214 break; |
|
215 } |
|
216 } |
|
217 |
|
218 #ifdef _hsps_EMULATOR_SUPPORT_ |
|
219 |
|
220 // ------------------------------------------------------------------------------ |
|
221 // ChspsFileChangeListener::HandleEmuFileSystemChange |
|
222 // |
|
223 // ------------------------------------------------------------------------------ |
|
224 // |
|
225 void ChspsFileChangeListener::HandleEmuFileSystemChange() |
|
226 { |
|
227 InformObserver(); |
|
228 } |
|
229 #endif |
|
230 |
|
231 #ifdef HSPS_LOG_ACTIVE |
|
232 // ------------------------------------------------------------------------------ |
|
233 // ChspsFileChangeListener::SetLogBus |
|
234 // Set log bus to be used. |
|
235 // ------------------------------------------------------------------------------ |
|
236 // |
|
237 void ChspsFileChangeListener::SetLogBus( ChspsLogBus* aLogBus ) |
|
238 { |
|
239 iLogBus = aLogBus; |
|
240 |
|
241 #ifdef _hsps_EMULATOR_SUPPORT_ |
|
242 if( iFileChange ) |
|
243 { |
|
244 iFileChange->SetLogBus( aLogBus ); |
|
245 } |
|
246 #endif |
|
247 |
|
248 } |
|
249 #endif |
|
250 |
|
251 // End of File |