harvesterplugins/media/image/src/imageplugin.cpp
changeset 2 208a4ba3894c
parent 0 ccd0fd43f247
child 13 0a2ec6860a93
equal deleted inserted replaced
0:ccd0fd43f247 2:208a4ba3894c
    29 #include "cpixmediaimagedoc.h"
    29 #include "cpixmediaimagedoc.h"
    30 #include "cpixindexerutils.h"
    30 #include "cpixindexerutils.h"
    31 #include "mmcmonitor.h"
    31 #include "mmcmonitor.h"
    32 #include "cpixmdedbmanager.h"
    32 #include "cpixmdedbmanager.h"
    33 #include "mdsitementity.h"
    33 #include "mdsitementity.h"
       
    34 #include "OstTraceDefinitions.h"
       
    35 #ifdef OST_TRACE_COMPILER_IN_USE
       
    36 #include "imagepluginTraces.h"
       
    37 #endif
       
    38 
    34 
    39 
    35 //Constants
    40 //Constants
    36 _LIT(KPathTrailer, "\\root\\media\\image");
    41 _LIT(KPathTrailer, "\\root\\media\\image");
    37 
    42 
    38 //***** MEDAI AUDIO*****
    43 //***** MEDAI AUDIO*****
    94 	}
    99 	}
    95 
   100 
    96 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
    97 void CImagePlugin::StartPluginL()
   102 void CImagePlugin::StartPluginL()
    98 	{
   103 	{
       
   104     OstTraceFunctionEntry0( CIMAGEPLUGIN_STARTPLUGINL_ENTRY );
    99     CPIXLOGSTRING("CImagePlugin::StartPluginL");
   105     CPIXLOGSTRING("CImagePlugin::StartPluginL");
   100 	// Define this base application class, use default location
   106 	// Define this base application class, use default location
   101 	iIndexerUtil = CCPixIndexerUtils::NewL(iSearchSession);
   107 	iIndexerUtil = CCPixIndexerUtils::NewL(iSearchSession);
   102 	//Test well before use
   108 	//Test well before use
   103 	TBuf<KMaxFileName> databasePathTemp;
   109 	TBuf<KMaxFileName> databasePathTemp;
   118 	// Start harvester for this plugin
   124 	// Start harvester for this plugin
   119 	iObserver->AddHarvestingQueue(this, _L(MEDIA_QBASEAPPCLASS) );
   125 	iObserver->AddHarvestingQueue(this, _L(MEDIA_QBASEAPPCLASS) );
   120 	TUid uidOfPlugin = {0x20029ABB};
   126 	TUid uidOfPlugin = {0x20029ABB};
   121 	iDBManager = CCPIXMDEDbManager::NewL(uidOfPlugin);
   127 	iDBManager = CCPIXMDEDbManager::NewL(uidOfPlugin);
   122 	iMdsItem = CMDSEntity::NewL();
   128 	iMdsItem = CMDSEntity::NewL();
       
   129 	OstTraceFunctionExit0( CIMAGEPLUGIN_STARTPLUGINL_EXIT );
   123 	}
   130 	}
   124 
   131 
   125 void CImagePlugin::HarvestingCompletedL()
   132 void CImagePlugin::HarvestingCompletedL()
   126     {
   133     {
   127 #ifdef __PERFORMANCE_DATA
   134 #ifdef __PERFORMANCE_DATA
   130     iObserver->HarvestingCompleted(this, _L(MEDIA_QBASEAPPCLASS), KErrNone);
   137     iObserver->HarvestingCompleted(this, _L(MEDIA_QBASEAPPCLASS), KErrNone);
   131     }
   138     }
   132 // -----------------------------------------------------------------------------
   139 // -----------------------------------------------------------------------------
   133 void CImagePlugin::StartHarvestingL( const TDesC& /*aMedia*/ )
   140 void CImagePlugin::StartHarvestingL( const TDesC& /*aMedia*/ )
   134     {
   141     {
       
   142     OstTraceFunctionEntry0( CIMAGEPLUGIN_STARTHARVESTINGL_ENTRY );
   135     //iIndexer->ResetL();//reset any indexes if exist already
   143     //iIndexer->ResetL();//reset any indexes if exist already
   136     CPIXLOGSTRING("CImagePlugin::StartHarvestingL");
   144     CPIXLOGSTRING("CImagePlugin::StartHarvestingL");
   137     iDBManager->ResetL();
   145     iDBManager->ResetL();
   138     iIndexerUtil->ResetAllL();
   146     iIndexerUtil->ResetAllL();
   139     //Start Media harvesting here
   147     //Start Media harvesting here
   140 #ifdef __PERFORMANCE_DATA  
   148 #ifdef __PERFORMANCE_DATA  
   141     iStartTime.UniversalTime();
   149     iStartTime.UniversalTime();
   142 #endif  
   150 #endif  
   143     iMdeHarvester->DoHarvesetL(MdeConstants::Image::KImageObject);//Start Harvesting
   151     iMdeHarvester->DoHarvesetL(MdeConstants::Image::KImageObject);//Start Harvesting
       
   152     OstTraceFunctionExit0( CIMAGEPLUGIN_STARTHARVESTINGL_EXIT );
   144     }
   153     }
   145 
   154 
   146 //handle MMC event for the Drive
   155 //handle MMC event for the Drive
   147 void CImagePlugin::HandleMMCEventL(const TDriveNumber aDrive,const TBool aMMCInsertRemoval)
   156 void CImagePlugin::HandleMMCEventL(const TDriveNumber aDrive,const TBool aMMCInsertRemoval)
   148     {
   157     {
   166     }
   175     }
   167 
   176 
   168 void CImagePlugin::HandleMdeItemL( TItemId aObjId, TCPixActionType aActionType)
   177 void CImagePlugin::HandleMdeItemL( TItemId aObjId, TCPixActionType aActionType)
   169     {
   178     {
   170     //Get the object from object utils and get the CPIX document and add delete or update
   179     //Get the object from object utils and get the CPIX document and add delete or update
       
   180     OstTrace1( TRACE_NORMAL, CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL;aObjId=%d", aObjId );
   171     CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): aObjId = %d ", aObjId );
   181     CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): aObjId = %d ", aObjId );
   172     // creating CSearchDocument object with unique ID for this application
   182     // creating CSearchDocument object with unique ID for this application
   173     TBuf<KMaxFileName> docid_str;
   183     TBuf<KMaxFileName> docid_str;
   174     if (aActionType == ECPixAddAction || aActionType == ECPixUpdateAction )
   184     if (aActionType == ECPixAddAction || aActionType == ECPixUpdateAction )
   175         {
   185         {
   176         //The caller should always handle leave of HandleMdeItemL
   186         //The caller should always handle leave of HandleMdeItemL
   177         if(iDBManager->IsAlreadyExistL(aObjId) && aActionType == ECPixAddAction)//Avoid reharvesting
   187         if(iDBManager->IsAlreadyExistL(aObjId) && aActionType == ECPixAddAction)//Avoid reharvesting
   178             {
   188             {
       
   189             OstTrace0( TRACE_NORMAL, DUP1_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL(): Already harvested returning" );
   179             CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Already harvested returning");
   190             CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Already harvested returning");
   180             return;
   191             return;
   181             }
   192             }
   182         CMdEObject& object= iMdsUtils->GetObjectL(aObjId,MdeConstants::Image::KImageObject);
   193         CMdEObject& object= iMdsUtils->GetObjectL(aObjId,MdeConstants::Image::KImageObject);
   183         CMdENamespaceDef& defaultNamespaceDef = iMdsUtils->GetSession()->GetDefaultNamespaceDefL();
   194         CMdENamespaceDef& defaultNamespaceDef = iMdsUtils->GetSession()->GetDefaultNamespaceDefL();
   185         CSearchDocument* index_item = iImageDocument->GetCpixDocumentL(object,_L(MEDIAAPPCLASS),audioObjDef);
   196         CSearchDocument* index_item = iImageDocument->GetCpixDocumentL(object,_L(MEDIAAPPCLASS),audioObjDef);
   186         iIndexer = iIndexerUtil->GetIndexerFromMediaId(object.MediaId());
   197         iIndexer = iIndexerUtil->GetIndexerFromMediaId(object.MediaId());
   187         if(!iIndexer)
   198         if(!iIndexer)
   188             {
   199             {
   189             delete index_item;
   200             delete index_item;
       
   201             OstTrace0( TRACE_NORMAL, DUP2_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL(): Indexer not found" );
   190             CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Indexer not found");
   202             CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Indexer not found");
   191             return;
   203             return;
   192             }
   204             }
   193         // Send for indexing
   205         // Send for indexing
   194         if (aActionType == ECPixAddAction)
   206         if (aActionType == ECPixAddAction)
   195             {
   207             {
   196 #ifdef __PERFORMANCE_DATA
   208 #ifdef __PERFORMANCE_DATA
   197             ++count;
   209             ++count;
   198 # endif
   210 # endif
       
   211             OstTrace0( TRACE_NORMAL, DUP3_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL(): Indexer found calling AddL" );
   199             CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Indexer found calling AddL");
   212             CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Indexer found calling AddL");
   200             //First check if it already exist in database
   213             //First check if it already exist in database
   201             TRAPD(err, iIndexer->UpdateL(*index_item)); //Always Update to avoid reharvesting
   214             TRAPD(err, iIndexer->UpdateL(*index_item)); //Always Update to avoid reharvesting
   202             if (err == KErrNone)
   215             if (err == KErrNone)
   203                 {
   216                 {
   207                     iMdsItem->SetUri(iImageDocument->GetUri());
   220                     iMdsItem->SetUri(iImageDocument->GetUri());
   208                     TDriveNumber drive;
   221                     TDriveNumber drive;
   209                     iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive);
   222                     iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive);
   210                     iMdsItem->SetDrive(drive);
   223                     iMdsItem->SetDrive(drive);
   211                     iDBManager->AddL(aObjId,*iMdsItem);//Add to SyncDB
   224                     iDBManager->AddL(aObjId,*iMdsItem);//Add to SyncDB
       
   225                 OstTrace0( TRACE_NORMAL, DUP4_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL(): Added." );
   212                 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Added.");
   226                 CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Added.");
   213                 }
   227                 }
   214             else
   228             else
   215                 {
   229                 {
       
   230                 OstTrace1( TRACE_NORMAL, DUP5_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL;Error %d in adding", err );
   216                 CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): Error %d in adding.", err);
   231                 CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): Error %d in adding.", err);
   217                 }
   232                 }
   218             }
   233             }
   219         else if (aActionType == ECPixUpdateAction)
   234         else if (aActionType == ECPixUpdateAction)
   220             {
   235             {
   231                 if(iMdsItem->GetPath().Compare(object.Uri()) != 0)
   246                 if(iMdsItem->GetPath().Compare(object.Uri()) != 0)
   232                     {
   247                     {
   233                     CCPixIndexer *tempIndexer;            
   248                     CCPixIndexer *tempIndexer;            
   234                     tempIndexer = iIndexerUtil->GetIndexerFromDrive(iMdsItem->DriveNumber());
   249                     tempIndexer = iIndexerUtil->GetIndexerFromDrive(iMdsItem->DriveNumber());
   235                     tempIndexer->DeleteL(iMdsItem->Uri());
   250                     tempIndexer->DeleteL(iMdsItem->Uri());
       
   251                     OstTrace0( TRACE_NORMAL, DUP6_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL(): Deleted existing URI for update" );
   236                     CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Deleted existing URI for update");
   252                     CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Deleted existing URI for update");
   237                     }
   253                     }
   238                 TRAPD(error, iIndexer->UpdateL(*index_item));
   254                 TRAPD(error, iIndexer->UpdateL(*index_item));
   239                 if (error == KErrNone)
   255                 if (error == KErrNone)
   240                     {
   256                     {
   242                     iMdsItem->Reset();//reset existing values
   258                     iMdsItem->Reset();//reset existing values
   243                     TDriveNumber drive;
   259                     TDriveNumber drive;
   244                     iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive);
   260                     iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive);
   245                     iMdsItem->Set(aObjId,iImageDocument->GetUri(),drive);
   261                     iMdsItem->Set(aObjId,iImageDocument->GetUri(),drive);
   246                     iDBManager->UpdateL(aObjId,*iMdsItem);//Add to SyncDB
   262                     iDBManager->UpdateL(aObjId,*iMdsItem);//Add to SyncDB
       
   263                     OstTrace0( TRACE_NORMAL, DUP7_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL(): Updated." );
   247                     CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Updated.");
   264                     CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Updated.");
   248                     }
   265                     }
   249                 else
   266                 else
   250                     {
   267                     {
       
   268                     OstTrace1( TRACE_NORMAL, DUP8_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL;Error %d in updating", err );
   251                     CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): Error %d in updating.", error);
   269                     CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): Error %d in updating.", error);
   252                     }
   270                     }
   253                 }
   271                 }
   254             //If a media item is added when downloading or streaming begins, add event is surpassed
   272             //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
   273             //by update or delete event because of delay introduced on monitered object by objectqueue manager
   265                     iMdsItem->SetUri(iImageDocument->GetUri());//Use the Absolute URI
   283                     iMdsItem->SetUri(iImageDocument->GetUri());//Use the Absolute URI
   266                     TDriveNumber drive;
   284                     TDriveNumber drive;
   267                     iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive);
   285                     iIndexerUtil->GetDriveFromMediaId(object.MediaId(),drive);
   268                     iMdsItem->SetDrive(drive);
   286                     iMdsItem->SetDrive(drive);
   269                     iDBManager->AddL(aObjId,*iMdsItem);//Add to SyncDB
   287                     iDBManager->AddL(aObjId,*iMdsItem);//Add to SyncDB
       
   288                     OstTrace0( TRACE_NORMAL, DUP9_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL(): Added Item before Update." );
   270                     CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Added Item before Update.");
   289                     CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Added Item before Update.");
   271                     }
   290                     }
   272                 }                       
   291                 }                       
   273             }
   292             }
   274         delete index_item;
   293         delete index_item;
   289                {
   308                {
   290                docid_str.Copy(iMdsItem->Uri());
   309                docid_str.Copy(iMdsItem->Uri());
   291                TRAPD(err, iIndexer->DeleteL(docid_str));//Delete it
   310                TRAPD(err, iIndexer->DeleteL(docid_str));//Delete it
   292                if (err == KErrNone)
   311                if (err == KErrNone)
   293                    {
   312                    {
       
   313                     OstTrace0( TRACE_NORMAL, DUP10_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL(): Deleted." );
   294                     CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Deleted.");
   314                     CPIXLOGSTRING("CImagePlugin::HandleMdeItemL(): Deleted.");
   295                    }
   315                    }
   296                else
   316                else
   297                    {
   317                    {
       
   318                     OstTrace1( TRACE_NORMAL, DUP11_CIMAGEPLUGIN_HANDLEMDEITEML, "CImagePlugin::HandleMdeItemL;Error %d in deleting", err );
   298                     CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): Error %d in deleting.", err);
   319                     CPIXLOGSTRING2("CImagePlugin::HandleMdeItemL(): Error %d in deleting.", err);
   299                    }
   320                    }
   300                }
   321                }
   301             //delete entry from database
   322             //delete entry from database
   302             iDBManager->RemoveL(iMdsItem->Key());
   323             iDBManager->RemoveL(iMdsItem->Key());