|
1 /* |
|
2 * Copyright (c) 2010 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: Media Image harvester plugin implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "imageplugin.h" |
|
20 #include <e32base.h> |
|
21 #include "harvesterserverlogger.h" |
|
22 #include "common.h" |
|
23 #include "csearchdocument.h" |
|
24 #include "ccpixindexer.h" |
|
25 #include "mdeharvester.h" |
|
26 #include "mdeobjectqueuemanager.h" |
|
27 #include "mdsmediamonitor.h" |
|
28 #include "mdssessionobjectutils.h" |
|
29 #include "cpixmediaimagedoc.h" |
|
30 #include "cpixindexerutils.h" |
|
31 #include "mmcmonitor.h" |
|
32 #include "cpixmdedbmanager.h" |
|
33 #include "mdsitementity.h" |
|
34 |
|
35 //Constants |
|
36 _LIT(KPathTrailer, "\\root\\media\\image"); |
|
37 |
|
38 //***** MEDAI AUDIO***** |
|
39 #define MEDIA_QBASEAPPCLASS "@0:root media image" |
|
40 #define LMEDIA_QBASEAPPCLASS L"@0:root media image" |
|
41 #define MEDIAAPPCLASS "root media image" |
|
42 #define LMEDIAAPPCLASS L"root media image" |
|
43 |
|
44 #define MEDIAGENERICAPPCLASS ":root media image" |
|
45 #define LMEDIAGENERICAPPCLASS L":root media image" |
|
46 #define DATABASEPATH "\\root\\media\\image" |
|
47 #define LDATABASEPATH "\\root\\media\\image" |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 CImagePlugin* CImagePlugin::NewL() |
|
51 { |
|
52 CImagePlugin* instance = CImagePlugin::NewLC(); |
|
53 CleanupStack::Pop(instance); |
|
54 return instance; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 CImagePlugin* CImagePlugin::NewLC() |
|
59 { |
|
60 CImagePlugin* instance = new (ELeave) CImagePlugin(); |
|
61 CleanupStack::PushL(instance); |
|
62 instance->ConstructL(); |
|
63 return instance; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 CImagePlugin::CImagePlugin() |
|
68 { |
|
69 //No implementation required. |
|
70 //Necessary things done in ConstructL() |
|
71 #ifdef __PERFORMANCE_DATA |
|
72 count = 0; |
|
73 # endif |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 CImagePlugin::~CImagePlugin() |
|
78 { |
|
79 delete iMdeHarvester; |
|
80 delete iMdsMonitor; |
|
81 delete iObjectJobQueueManager; |
|
82 delete iMdsUtils; |
|
83 delete iImageDocument; |
|
84 delete iIndexerUtil; |
|
85 delete iMMcMonitor; |
|
86 delete iDBManager; |
|
87 delete iMdsItem; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 void CImagePlugin::ConstructL() |
|
92 { |
|
93 |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 void CImagePlugin::StartPluginL() |
|
98 { |
|
99 CPIXLOGSTRING("CImagePlugin::StartPluginL"); |
|
100 // Define this base application class, use default location |
|
101 iIndexerUtil = CCPixIndexerUtils::NewL(iSearchSession); |
|
102 //Test well before use |
|
103 TBuf<KMaxFileName> databasePathTemp; |
|
104 databasePathTemp.Append(KPathTrailer); |
|
105 iIndexerUtil->MountAllAvailableDriveL(_L(MEDIAGENERICAPPCLASS),databasePathTemp); |
|
106 //Instantiate all monitoring and harvesting class here |
|
107 iMdsUtils = CMdsSessionObjectUtils::NewL(); |
|
108 iMdsUtils->InitializeL(); //Create valid session in it |
|
109 iObjectJobQueueManager = CMdeObjectQueueManager::NewL(this); |
|
110 iMdeHarvester = CMdeHarvester::NewL(iMdsUtils->GetSession(), |
|
111 this,iObjectJobQueueManager); |
|
112 iMdsMonitor = CMdsMediaMonitor::NewL(iMdsUtils->GetSession(),iObjectJobQueueManager); |
|
113 iMMcMonitor = CMMCMonitorUtil::NewL(this);//Observer is self |
|
114 iMMcMonitor->StartMonitoring(); |
|
115 //Start Monitoring now |
|
116 iMdsMonitor->StartMonitoringL(MdeConstants::Image::KImageObject);//Start monitoring Image objects |
|
117 iImageDocument = CCPIXMediaImageDoc::NewL(); //Doc fetcher |
|
118 // Start harvester for this plugin |
|
119 iObserver->AddHarvestingQueue(this, _L(MEDIA_QBASEAPPCLASS) ); |
|
120 TUid uidOfPlugin = {0x20029ABB}; |
|
121 iDBManager = CCPIXMDEDbManager::NewL(uidOfPlugin); |
|
122 iMdsItem = CMDSEntity::NewL(); |
|
123 } |
|
124 |
|
125 void CImagePlugin::HarvestingCompletedL() |
|
126 { |
|
127 #ifdef __PERFORMANCE_DATA |
|
128 UpdatePerformaceDataL(); |
|
129 #endif |
|
130 iObserver->HarvestingCompleted(this, _L(MEDIA_QBASEAPPCLASS), KErrNone); |
|
131 } |
|
132 // ----------------------------------------------------------------------------- |
|
133 void CImagePlugin::StartHarvestingL( const TDesC& /*aMedia*/ ) |
|
134 { |
|
135 //iIndexer->ResetL();//reset any indexes if exist already |
|
136 CPIXLOGSTRING("CImagePlugin::StartHarvestingL"); |
|
137 iDBManager->ResetL(); |
|
138 iIndexerUtil->ResetAllL(); |
|
139 //Start Media harvesting here |
|
140 #ifdef __PERFORMANCE_DATA |
|
141 iStartTime.UniversalTime(); |
|
142 #endif |
|
143 iMdeHarvester->DoHarvesetL(MdeConstants::Image::KImageObject);//Start Harvesting |
|
144 } |
|
145 |
|
146 //handle MMC event for the Drive |
|
147 void CImagePlugin::HandleMMCEventL(const TDriveNumber aDrive,const TBool aMMCInsertRemoval) |
|
148 { |
|
149 TBuf<KMaxFileName> databasePathTemp; |
|
150 databasePathTemp.Append(KPathTrailer); |
|
151 if(aMMCInsertRemoval) //MMC inserted |
|
152 { |
|
153 //Test well before use |
|
154 iIndexerUtil->MountDriveL(aDrive,_L(MEDIAGENERICAPPCLASS),databasePathTemp); |
|
155 //reset indexes existing first |
|
156 //With new Implementation no need to reset |
|
157 //iIndexerUtil->GetIndexerFromDrive(aDrive)->ResetL(); |
|
158 } |
|
159 else |
|
160 { |
|
161 //MMC is removed but we can not reset index here as Media physically not avilable so |
|
162 // we have to do at the time of insertion only |
|
163 //Unmount drive and also reset the index as we anyhow has to reindex on insertion back |
|
164 iIndexerUtil->UnMountDriveL(aDrive,_L(MEDIAGENERICAPPCLASS),ETrue); |
|
165 } |
|
166 } |
|
167 |
|
168 void CImagePlugin::HandleMdeItemL( TItemId aObjId, TCPixActionType aActionType) |
|
169 { |
|
170 //Get the object from object utils and get the CPIX document and add delete or update |
|
171 CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): aObjId = %d ", aObjId ); |
|
172 // creating CSearchDocument object with unique ID for this application |
|
173 TBuf<KMaxFileName> docid_str; |
|
174 if (aActionType == ECPixAddAction || aActionType == ECPixUpdateAction ) |
|
175 { |
|
176 //The caller should always handle leave of HandleMdeItemL |
|
177 if(iDBManager->IsAlreadyExistL(aObjId) && aActionType == ECPixAddAction)//Avoid reharvesting |
|
178 { |
|
179 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Already harvested returning"); |
|
180 return; |
|
181 } |
|
182 CMdEObject& object= iMdsUtils->GetObjectL(aObjId,MdeConstants::Image::KImageObject); |
|
183 CMdENamespaceDef& defaultNamespaceDef = iMdsUtils->GetSession()->GetDefaultNamespaceDefL(); |
|
184 CMdEObjectDef& audioObjDef = defaultNamespaceDef.GetObjectDefL(MdeConstants::Image::KImageObject); |
|
185 CSearchDocument* index_item = iImageDocument->GetCpixDocumentL(object,_L(MEDIAAPPCLASS),audioObjDef); |
|
186 iIndexer = iIndexerUtil->GetIndexerFromMediaId(object.MediaId()); |
|
187 if(!iIndexer) |
|
188 { |
|
189 delete index_item; |
|
190 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Indexer not found"); |
|
191 return; |
|
192 } |
|
193 // Send for indexing |
|
194 if (aActionType == ECPixAddAction) |
|
195 { |
|
196 #ifdef __PERFORMANCE_DATA |
|
197 ++count; |
|
198 # endif |
|
199 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Indexer found calling AddL"); |
|
200 //First check if it already exist in database |
|
201 TRAPD(err, iIndexer->UpdateL(*index_item)); //Always Update to avoid reharvesting |
|
202 if (err == KErrNone) |
|
203 { |
|
204 //Add entity to database for later use |
|
205 iMdsItem->Reset();//reset existing values |
|
206 iMdsItem->Setkey(aObjId); |
|
207 iMdsItem->SetUri(iImageDocument->GetUri()); |
|
208 TDriveNumber drive; |
|
209 iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive); |
|
210 iMdsItem->SetDrive(drive); |
|
211 iDBManager->AddL(aObjId,*iMdsItem);//Add to SyncDB |
|
212 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Added."); |
|
213 } |
|
214 else |
|
215 { |
|
216 CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): Error %d in adding.", err); |
|
217 } |
|
218 } |
|
219 else if (aActionType == ECPixUpdateAction) |
|
220 { |
|
221 //If DocID for e.g \image\something.jpeg itself changes the we have to compare |
|
222 //existing URI with new one and Remove that first and Update to avoid |
|
223 //Duplicate entries |
|
224 iMdsItem->Reset();//reset existing values |
|
225 TRAPD(err, iDBManager->GetItemL(aObjId,*iMdsItem)); |
|
226 if (err == KErrNone) |
|
227 { |
|
228 //Get the drivenumber from the syncDB to delete the appropriate docId |
|
229 //in case an item is moved to different drive, delete from the old drive first and later update. |
|
230 //comparing the absolute paths along with the root drives |
|
231 if(iMdsItem->GetPath().Compare(object.Uri()) != 0) |
|
232 { |
|
233 CCPixIndexer *tempIndexer; |
|
234 tempIndexer = iIndexerUtil->GetIndexerFromDrive(iMdsItem->DriveNumber()); |
|
235 tempIndexer->DeleteL(iMdsItem->Uri()); |
|
236 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Deleted existing URI for update"); |
|
237 } |
|
238 TRAPD(error, iIndexer->UpdateL(*index_item)); |
|
239 if (error == KErrNone) |
|
240 { |
|
241 //Add as new |
|
242 iMdsItem->Reset();//reset existing values |
|
243 TDriveNumber drive; |
|
244 iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive); |
|
245 iMdsItem->Set(aObjId,iImageDocument->GetUri(),drive); |
|
246 iDBManager->UpdateL(aObjId,*iMdsItem);//Add to SyncDB |
|
247 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Updated."); |
|
248 } |
|
249 else |
|
250 { |
|
251 CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): Error %d in updating.", error); |
|
252 } |
|
253 } |
|
254 //If a media item is added when downloading or streaming begins, add event is surpassed |
|
255 //by update or delete event because of delay introduced on monitered object by objectqueue manager |
|
256 //So add the Item first, when GetItemL() leaves with item not found |
|
257 else if(err == KErrNotFound) |
|
258 { |
|
259 TRAPD(error, iIndexer->UpdateL(*index_item)); |
|
260 if (error == KErrNone) |
|
261 { |
|
262 //Add entity to database for later use |
|
263 iMdsItem->Reset();//reset existing values |
|
264 iMdsItem->Setkey(aObjId); |
|
265 iMdsItem->SetUri(iImageDocument->GetUri());//Use the Absolute URI |
|
266 TDriveNumber drive; |
|
267 iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive); |
|
268 iMdsItem->SetDrive(drive); |
|
269 iDBManager->AddL(aObjId,*iMdsItem);//Add to SyncDB |
|
270 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Added Item before Update."); |
|
271 } |
|
272 } |
|
273 } |
|
274 delete index_item; |
|
275 iIndexer = NULL;//Assign to null not pointing to any memory |
|
276 } |
|
277 else if (aActionType == ECPixRemoveAction) |
|
278 { |
|
279 //We can not get media id of removed doc from MDS as it is deleed so we have to remove from |
|
280 //all available Indexers |
|
281 // Remove the document |
|
282 //Get the Item from SyncDB for removed Item |
|
283 iMdsItem->Reset();//reset existing values |
|
284 TRAPD(error, iDBManager->GetItemL(aObjId,*iMdsItem)); |
|
285 if (error == KErrNone) |
|
286 { |
|
287 iIndexer = iIndexerUtil->GetIndexerFromDrive(iMdsItem->DriveNumber());//Get Indexer from drive |
|
288 if(iIndexer) //If indexer found delete |
|
289 { |
|
290 docid_str.Copy(iMdsItem->Uri()); |
|
291 TRAPD(err, iIndexer->DeleteL(docid_str));//Delete it |
|
292 if (err == KErrNone) |
|
293 { |
|
294 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Deleted."); |
|
295 } |
|
296 else |
|
297 { |
|
298 CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): Error %d in deleting.", err); |
|
299 } |
|
300 } |
|
301 //delete entry from database |
|
302 iDBManager->RemoveL(iMdsItem->Key()); |
|
303 } |
|
304 iIndexer = NULL;//Assign to null not pointing to any memory |
|
305 } |
|
306 } |
|
307 |
|
308 #ifdef __PERFORMANCE_DATA |
|
309 void CImagePlugin::UpdateLogL() |
|
310 { |
|
311 UpdatePerformaceDataL(); |
|
312 } |
|
313 |
|
314 void CImagePlugin::UpdatePerformaceDataL() |
|
315 { |
|
316 TTime now; |
|
317 |
|
318 |
|
319 iCompleteTime.UniversalTime(); |
|
320 TTimeIntervalMicroSeconds timeDiff = iCompleteTime.MicroSecondsFrom(iStartTime); |
|
321 |
|
322 RFs fileSession; |
|
323 RFile perfFile; |
|
324 User::LeaveIfError(fileSession.Connect ()); |
|
325 |
|
326 |
|
327 /* Open file if it exists, otherwise create it and write content in it */ |
|
328 |
|
329 if(perfFile.Open(fileSession, _L("c:\\data\\ImagePerf.txt"), EFileWrite)) |
|
330 User::LeaveIfError(perfFile.Create (fileSession, _L("c:\\data\\ImagePerf.txt"), EFileWrite)); |
|
331 |
|
332 HBufC8 *heap = HBufC8::NewL(100); |
|
333 TPtr8 ptr = heap->Des(); |
|
334 now.HomeTime(); |
|
335 TBuf<100> timeString; |
|
336 |
|
337 _LIT(KOwnTimeFormat,"%:0%H%:1%T%:2%S"); |
|
338 now.FormatL(timeString,KOwnTimeFormat); |
|
339 ptr.AppendNum(now.DateTime().Day()); |
|
340 ptr.Append(_L("/")); |
|
341 ptr.AppendNum(now.DateTime().Month()); |
|
342 ptr.Append(_L("/")); |
|
343 ptr.AppendNum(now.DateTime().Year()); |
|
344 ptr.Append(_L(":")); |
|
345 ptr.Append(timeString); |
|
346 ptr.Append(_L("--")); |
|
347 ptr.AppendNum(count); |
|
348 ptr.Append( _L(" :Time took for Harvesting Image is : ")); |
|
349 ptr.AppendNum(timeDiff.Int64()/1000) ; |
|
350 ptr.Append(_L(" MilliSeonds \n")); |
|
351 TInt myInt = 0; |
|
352 perfFile.Seek(ESeekEnd,myInt); |
|
353 perfFile.Write (ptr); |
|
354 perfFile.Close (); |
|
355 fileSession.Close (); |
|
356 delete heap; |
|
357 } |
|
358 #endif |
|
359 |
|
360 // End of file |