|
1 /* |
|
2 * Copyright (c) 2007-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: Monitors file creations, modifications and deletions.* |
|
15 */ |
|
16 |
|
17 |
|
18 #include <mdeobject.h> |
|
19 |
|
20 #include "harvestercommon.h" |
|
21 #include "filemonitorao.h" |
|
22 #include "harvesterlog.h" |
|
23 #include "fsutil.h" |
|
24 #include "mdeharvestersession.h" |
|
25 #include "processoriginmapper.h" |
|
26 #include "fileeventhandlerao.h" |
|
27 #include "harvesterpluginfactory.h" |
|
28 |
|
29 using namespace MdeConstants; |
|
30 |
|
31 _LIT( KMdsFSPluginFile, "mdsfileserverplugin" ); |
|
32 _LIT( KMdsFSPluginName, "MdsFileServerPlugin" ); |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // CFileMonitorAO::NewL() |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CFileMonitorAO* CFileMonitorAO::NewL() |
|
39 { |
|
40 WRITELOG( "CFileMonitorAO::NewL" ); |
|
41 |
|
42 CFileMonitorAO* self = new (ELeave) CFileMonitorAO; |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CFileMonitorAO::ConstructL() |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 void CFileMonitorAO::ConstructL() |
|
54 { |
|
55 WRITELOG( "CFileMonitorAO::ConstructL" ); |
|
56 |
|
57 CActiveScheduler::Add( this ); |
|
58 iFsConnectOk = EFalse; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CFileMonitorAO::~CFileMonitorAO() |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CFileMonitorAO::~CFileMonitorAO() |
|
66 { |
|
67 WRITELOG( "CFileMonitorAO::~CFileMonitorAO" ); |
|
68 |
|
69 Cancel(); |
|
70 |
|
71 StopMonitoring(); |
|
72 |
|
73 iIgnoreList.ResetAndDestroy(); |
|
74 iIgnoreList.Close(); |
|
75 |
|
76 |
|
77 delete iMdeSession; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // CFileMonitorAO::StartMonitoring() |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 TBool CFileMonitorAO::StartMonitoring( MMonitorPluginObserver& aObserver, |
|
85 CMdESession* aMdeSession, const TDesC& aPath, CHarvesterPluginFactory* aHarvesterPluginFactory ) |
|
86 { |
|
87 WRITELOG( "CFileMonitorAO::StartMonitoring" ); |
|
88 |
|
89 iObserver = &aObserver; |
|
90 iHarvesterPluginFactory = aHarvesterPluginFactory; |
|
91 TRAPD( err, iMdeSession = CMdEHarvesterSession::NewL( *aMdeSession ) ); |
|
92 if ( err != KErrNone ) |
|
93 { |
|
94 return EFalse; |
|
95 } |
|
96 |
|
97 TRAP( err, iFileEventHandler = CFileEventHandlerAO::NewL( aObserver, iMdeSession, aHarvesterPluginFactory )); |
|
98 if ( err != KErrNone ) |
|
99 { |
|
100 return EFalse; |
|
101 } |
|
102 |
|
103 TInt error = iFs.Connect(); |
|
104 if ( error != KErrNone ) |
|
105 { |
|
106 iFs.Close(); |
|
107 return EFalse; |
|
108 } |
|
109 iFsConnectOk = ETrue; |
|
110 |
|
111 // add mds fileserver plugin |
|
112 error = iFs.AddPlugin( KMdsFSPluginFile ); |
|
113 if ( error != KErrAlreadyExists ) |
|
114 { |
|
115 error = iFs.MountPlugin( KMdsFSPluginName ); |
|
116 if ( error != KErrNone ) |
|
117 { |
|
118 return EFalse; |
|
119 } |
|
120 } |
|
121 |
|
122 error = iEngine.Open( iFs, KMdsFSPluginPosition ); |
|
123 if ( error != KErrNone ) |
|
124 { |
|
125 return EFalse; |
|
126 } |
|
127 |
|
128 iEngine.Enable(); |
|
129 iEngine.AddNotificationPath( aPath ); |
|
130 |
|
131 StartNotify(); |
|
132 return ETrue; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // CFileMonitorAO::StartNotify() |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CFileMonitorAO::StartNotify() |
|
140 { |
|
141 WRITELOG( "CFileMonitorAO::StartNotify" ); |
|
142 |
|
143 ResetMdsFSPStatus(); |
|
144 |
|
145 iEngine.RegisterNotification( iStatusPckg, iStatus ); |
|
146 |
|
147 SetActive(); |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CFileMonitorAO::StopMonitoring() |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 TBool CFileMonitorAO::StopMonitoring() |
|
155 { |
|
156 WRITELOG( "CFileMonitorAO::StopMonitoring" ); |
|
157 |
|
158 if ( iFsConnectOk == EFalse ) |
|
159 { |
|
160 return ETrue; |
|
161 } |
|
162 |
|
163 Cancel(); |
|
164 |
|
165 // remove mds fileserver plugin |
|
166 iEngine.Disable(); |
|
167 iEngine.Close(); |
|
168 |
|
169 iFs.DismountPlugin( KMdsFSPluginName ); |
|
170 iFs.RemovePlugin( KMdsFSPluginName ); |
|
171 |
|
172 iFs.Close(); |
|
173 iFsConnectOk = EFalse; |
|
174 |
|
175 return ETrue; |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CFileMonitorAO::RunL() |
|
180 // From CActive |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 void CFileMonitorAO::RunL() |
|
184 { |
|
185 WRITELOG( "CFileMonitorAO::RunL" ); |
|
186 |
|
187 User::LeaveIfError( iStatus.Int() ); |
|
188 TMdsFSPStatus& status = iStatusPckg(); |
|
189 |
|
190 iFileEventHandler->AddToQueueL(status); |
|
191 |
|
192 StartNotify(); |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CFileMonitorAO::ResetMdsFSPStatus() |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void CFileMonitorAO::ResetMdsFSPStatus() |
|
200 { |
|
201 WRITELOG( "CFileMonitorAO::ResetMdsFSPStatus" ); |
|
202 |
|
203 TMdsFSPStatus& status = iStatusPckg(); |
|
204 |
|
205 status.iDriveNumber = 0; |
|
206 status.iFileEventType = EMdsFileUnknown; |
|
207 status.iFileName.Zero(); |
|
208 status.iNewFileName.Zero(); |
|
209 status.iProcessId = TUid::Null(); |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CFileMonitorAO::RunError() |
|
214 // From CActive |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 TInt CFileMonitorAO::RunError( TInt aError ) |
|
218 { |
|
219 WRITELOG1( "CFileMonitorAO::RunError %d", aError ); |
|
220 |
|
221 if ( aError == KErrInUse ) |
|
222 { |
|
223 iEngine.NotificationCancel(); |
|
224 } |
|
225 else |
|
226 { |
|
227 StartNotify(); |
|
228 } |
|
229 |
|
230 return KErrNone; |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CFileMonitorAO::DoCancel() |
|
235 // From CActive |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 void CFileMonitorAO::DoCancel() |
|
239 { |
|
240 WRITELOG( "CFileMonitorAO::DoCancel" ); |
|
241 iEngine.Disable(); |
|
242 iEngine.NotificationCancel(); |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // CFileMonitorAO::CFileMonitorAO() |
|
247 // Constructor |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 CFileMonitorAO::CFileMonitorAO() : CActive( KHarvesterPriorityMonitorPlugin ) |
|
251 { |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // CFileMonitorAO::Mapper() |
|
256 // Returns a handle to CProcessOriginMapper. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 CProcessOriginMapper& CFileMonitorAO::Mapper() |
|
260 { |
|
261 return iFileEventHandler->Mapper(); |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // CFileMonitorAO::Mapper() |
|
266 // Set event caching status |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 void CFileMonitorAO::SetCachingStatus( TBool aCachingStatus ) |
|
270 { |
|
271 iFileEventHandler->SetCachingStatus( aCachingStatus ); |
|
272 } |
|
273 |