harvester/common/src/harvesterplugin.cpp
changeset 0 c53acadfccc6
child 1 acef663c1218
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Base class for harvester plug-ins*
       
    15 */
       
    16 
       
    17 
       
    18 #include <harvesterplugin.h>
       
    19 #include <harvesterdata.h>
       
    20 #include <mdeconstants.h>
       
    21 #include <mdepropertydef.h>
       
    22 #include <mdeobjectdef.h>
       
    23 #include <mdeobject.h>
       
    24 #include "harvesterlog.h"
       
    25 #include "harvestercommon.h"
       
    26 #include "harvesterblacklist.h"
       
    27 #include "mdsutils.h"
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // NewL
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 EXPORT_C CHarvesterPlugin* CHarvesterPlugin::NewL(const TUid& aUid)
       
    34 	{
       
    35 	TAny* harvesterPlugin = REComSession::CreateImplementationL(
       
    36 			aUid, _FOFF( CHarvesterPlugin, iDtor_ID_Key ) );
       
    37 	CHarvesterPlugin* self = reinterpret_cast<CHarvesterPlugin*>(harvesterPlugin);
       
    38 	CleanupStack::PushL( self );
       
    39 	self->ConstructL();
       
    40 	CleanupStack::Pop( self );
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // ConstructL
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CHarvesterPlugin::ConstructL()
       
    49 	{
       
    50 	User::LeaveIfError( iFs.Connect() );
       
    51 	iState = EHarvesterIdle;
       
    52 	CActiveScheduler::Add( this );
       
    53 	}
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // Constructor
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 EXPORT_C CHarvesterPlugin::CHarvesterPlugin() : 
       
    60 	CActive( KHarvesterPriorityHarvestingPlugin ),
       
    61 	iState( EHarvesterIdle ),
       
    62 	iQueue( NULL ),
       
    63 	iBlacklist( NULL ),
       
    64     iDtor_ID_Key( KNullUid ),
       
    65     iOriginPropertyDef( NULL ),
       
    66     iTitlePropertyDef( NULL )
       
    67 	{
       
    68 	
       
    69 	}
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // ListImplementationsL
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 EXPORT_C void CHarvesterPlugin::ListImplementationsL(
       
    76 		RImplInfoPtrArray& aImplInfoArray)
       
    77 	{
       
    78 	REComSession::ListImplementationsL(
       
    79 			KCHarvesterPluginInterfaceUid, aImplInfoArray );
       
    80 	}
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Destructor
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C CHarvesterPlugin::~CHarvesterPlugin() // destruct - virtual
       
    87 	{
       
    88 	Cancel();
       
    89 	
       
    90 	iFs.Close();
       
    91 	REComSession::DestroyedImplementation( iDtor_ID_Key );
       
    92 	}
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // AddQueue
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C void CHarvesterPlugin::SetQueue( RPointerArray<CHarvesterData>& aQueue )
       
    99 	{
       
   100 	iQueue = &aQueue;
       
   101 	}
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // StartHarvest
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C void CHarvesterPlugin::StartHarvest()
       
   108 	{
       
   109 	if( iState == EHarvesterIdle )
       
   110 		{
       
   111 		SetNextRequest( EHarvesterGathering );
       
   112 		}
       
   113 	}
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // GetObjectType
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C void CHarvesterPlugin::GetObjectType( const TDesC& /*aUri*/, TDes& aObjectType )
       
   120 	{
       
   121 	aObjectType.Zero();
       
   122 	}
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // RunL
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C void CHarvesterPlugin::RunL()
       
   129     {
       
   130     switch( iState )
       
   131         {
       
   132         case EHarvesterIdle:
       
   133             {
       
   134             }
       
   135             break;
       
   136             
       
   137         case EHarvesterGathering:
       
   138             {
       
   139             if( iQueue->Count() == 0 )
       
   140                 {
       
   141                 SetNextRequest( EHarvesterIdle );
       
   142                 iQueue->Compress();
       
   143                 }
       
   144             else
       
   145             	{
       
   146             	CHarvesterData* hd = (*iQueue)[0];
       
   147             	iQueue->Remove( 0 );
       
   148             	const TDesC& uri = hd->Uri();
       
   149             	TUint32 mediaId = hd->MdeObject().MediaId();
       
   150             	
       
   151 				if( iBlacklist )
       
   152 					{
       
   153 					WRITELOG( "CHarvesterPlugin::RunL - Adding URI to blacklist" );
       
   154 					TTime modified ( 0 );
       
   155 					
       
   156 					if( hd->IsBinary() )
       
   157 						{
       
   158 						TInt err = iFs.Modified( hd->Uri(), modified );
       
   159 						if ( err != KErrNone )
       
   160 							{
       
   161 							modified = 0;
       
   162 							}
       
   163 						}
       
   164 					iBlacklist->AddFile( uri, mediaId, modified );
       
   165 					}
       
   166 				
       
   167 				TRAP_IGNORE( SetDefaultPropertiesL( *hd ) );
       
   168 				
       
   169 				WRITELOG1("CHarvesterPlugin::RunL - Calling HarvestL for file: %S", &uri);  
       
   170                 TRAPD(err, HarvestL( hd ) );
       
   171                 
       
   172                 if ( iBlacklist )
       
   173                     {
       
   174                     WRITELOG( "CHarvesterPlugin::RunL - Removing URI from blacklist" );
       
   175                     iBlacklist->RemoveFile( uri, mediaId );
       
   176                     }
       
   177                 
       
   178                 if( err )
       
   179                 	{
       
   180                 	WRITELOG1("CHarvesterPlugin::RunL - ERROR: harvesting failed: %d", err); 
       
   181                 	hd->SetErrorCode( err );
       
   182                 	}
       
   183                 
       
   184 	            hd->PluginObserver()->HarvestingCompleted( hd );
       
   185                 SetNextRequest( EHarvesterGathering );
       
   186             	}
       
   187             }
       
   188             break;
       
   189 
       
   190         default:
       
   191             break;
       
   192         }
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // DoCancel
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C void CHarvesterPlugin::DoCancel()
       
   200     {
       
   201     
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // RunError
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C  TInt CHarvesterPlugin::RunError( TInt /*aError*/ )
       
   209 	{
       
   210 	SetNextRequest( EHarvesterGathering );
       
   211 	return KErrNone;
       
   212 	}
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // SetNextRequest
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CHarvesterPlugin::SetNextRequest( THarvesterState aState )
       
   219     {
       
   220     if ( ! IsActive() )
       
   221         {
       
   222         iState = aState;
       
   223         SetActive();
       
   224         TRequestStatus* status = &iStatus;
       
   225         User::RequestComplete( status, KErrNone );
       
   226         }
       
   227     }
       
   228 
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // SetDefaultProperties
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 void CHarvesterPlugin::SetDefaultPropertiesL(CHarvesterData& aData)
       
   235 	{
       
   236 	CMdEObject& mdeObject = aData.MdeObject();
       
   237 	
       
   238 	if( !iOriginPropertyDef )
       
   239 		{
       
   240 		CMdEObjectDef& objDef = mdeObject.Def();
       
   241 		iOriginPropertyDef = &objDef.GetPropertyDefL( MdeConstants::Object::KOriginProperty );
       
   242 		}
       
   243 
       
   244 	CMdEProperty* prop = NULL;
       
   245 	mdeObject.Property( *iOriginPropertyDef, prop );
       
   246     if ( prop )
       
   247     	{
       
   248     	TUint8 val = prop->Uint8ValueL();
       
   249     	if ( val == MdeConstants::Object::EOther )
       
   250     		{
       
   251 #ifdef _DEBUG
       
   252     		WRITELOG2("CHarvesterPlugin::SetDefaultPropertiesL - URI: %S SET Origin: %d", &aData.Uri(), aData.Origin() );
       
   253 #endif
       
   254     		prop->SetUint8ValueL( (TUint8) aData.Origin() );
       
   255     		}
       
   256     	}
       
   257     else
       
   258     	{
       
   259 #ifdef _DEBUG
       
   260 		WRITELOG2("CHarvesterPlugin::SetDefaultPropertiesL - URI: %S ADD Origin: %d", &aData.Uri(), aData.Origin() );
       
   261 #endif
       
   262     	mdeObject.AddUint8PropertyL( *iOriginPropertyDef, (TUint8) aData.Origin() );
       
   263     	}
       
   264     
       
   265 	if( !iTitlePropertyDef )
       
   266 		{
       
   267 		CMdEObjectDef& objDef = mdeObject.Def();
       
   268 		iTitlePropertyDef = &objDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
       
   269 		}
       
   270     
       
   271     prop = NULL;
       
   272     mdeObject.Property( *iTitlePropertyDef, prop );
       
   273     if ( !prop )
       
   274     	{
       
   275     	TPtrC name;
       
   276     	TBool nameFound = MdsUtils::GetName( aData.Uri(), name );
       
   277 
       
   278      	if ( nameFound )
       
   279      		{
       
   280      		mdeObject.AddTextPropertyL( *iTitlePropertyDef, name );
       
   281      		}
       
   282     	}
       
   283 	}
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // SetBlacklist
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 EXPORT_C void CHarvesterPlugin::SetBlacklist( CHarvesterBlacklist& aBlacklist )
       
   290 	{
       
   291 	iBlacklist = &aBlacklist;
       
   292 	}
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // E32Dll
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 GLDEF_C TInt E32Dll()
       
   299 	{
       
   300 	return(KErrNone);
       
   301 	}