contentpublishingsrv/contentpublishingutils/pluginvalidator/src/cpluginvalidator.cpp
branchRCL_3
changeset 31 8baec10861af
parent 30 a5a39a295112
equal deleted inserted replaced
30:a5a39a295112 31:8baec10861af
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  
    14 * Description:
    15  *
    15  *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <ecom/ecom.h>
    19 #include <ecom/ecom.h>
    24 
    24 
    25 // ----------------------------------------------------------------------------
    25 // ----------------------------------------------------------------------------
    26 //
    26 //
    27 // ----------------------------------------------------------------------------
    27 // ----------------------------------------------------------------------------
    28 //
    28 //
    29 EXPORT_C CPluginValidator* CPluginValidator::NewL( TUid aUid, 
    29 EXPORT_C CPluginValidator* CPluginValidator::NewL( TUid aUid,
    30                                                    TAny *aParameter )
    30                                                    TAny *aParameter )
    31     {
    31     {
    32     CPluginValidator* self = CPluginValidator::NewLC( aUid , aParameter );
    32     CPluginValidator* self = CPluginValidator::NewLC( aUid , aParameter );
    33     CleanupStack::Pop( self );
    33     CleanupStack::Pop( self );
    34     return self;
    34     return self;
    39 // ----------------------------------------------------------------------------
    39 // ----------------------------------------------------------------------------
    40 //
    40 //
    41 EXPORT_C CPluginValidator* CPluginValidator::NewLC( TUid aUid,
    41 EXPORT_C CPluginValidator* CPluginValidator::NewLC( TUid aUid,
    42                                                     TAny *aParameter )
    42                                                     TAny *aParameter )
    43     {
    43     {
    44     CPluginValidator* self = new( ELeave ) CPluginValidator( aUid, 
    44     CPluginValidator* self = new( ELeave ) CPluginValidator( aUid,
    45                                                              aParameter );
    45                                                              aParameter );
    46     CleanupStack::PushL( self );
    46     CleanupStack::PushL( self );
    47     self->ConstructL();
    47     self->ConstructL();
    48     return self;
    48     return self;
    49     }
    49     }
    54 //
    54 //
    55 EXPORT_C TAny* CPluginValidator::GetImplementation( TUid aUid )
    55 EXPORT_C TAny* CPluginValidator::GetImplementation( TUid aUid )
    56     {
    56     {
    57     TPluginInfo pluginInfo;
    57     TPluginInfo pluginInfo;
    58     pluginInfo.iImplementationUid = aUid;
    58     pluginInfo.iImplementationUid = aUid;
    59     TInt index = iPluginArray.Find( pluginInfo, 
    59     TInt index = iPluginArray.Find( pluginInfo,
    60     			TIdentityRelation< TPluginInfo >(UidMatch) );    
    60           TIdentityRelation< TPluginInfo >(UidMatch) );
    61     return GetImplementation( index );
    61     return GetImplementation( index );
    62     }
    62     }
    63 
    63 
    64 // ----------------------------------------------------------------------------
    64 // ----------------------------------------------------------------------------
    65 //
    65 //
    66 // ----------------------------------------------------------------------------
    66 // ----------------------------------------------------------------------------
    67 //
    67 //
    68 EXPORT_C TAny* CPluginValidator::GetImplementation( TInt aIndex )
    68 EXPORT_C TAny* CPluginValidator::GetImplementation( TInt aIndex )
    69     {
    69     {
    70     TAny* ret( NULL ); 
    70     TAny* ret( NULL );
    71     if (( aIndex != KErrNotFound ) && ( aIndex < iPluginArray.Count() ))
    71     if (( aIndex != KErrNotFound ) && ( aIndex < iPluginArray.Count() ))
    72     	{
    72       {
    73     	ret= iPluginArray[aIndex].iPlugin;
    73       ret= iPluginArray[aIndex].iPlugin;
    74     	}
    74       }
    75     return ret;    
    75     return ret;
    76     }
    76     }
    77 
    77 
    78 // ----------------------------------------------------------------------------
    78 // ----------------------------------------------------------------------------
    79 //
    79 //
    80 // ----------------------------------------------------------------------------
    80 // ----------------------------------------------------------------------------
    96         {
    96         {
    97         iSession->Close();
    97         iSession->Close();
    98         }
    98         }
    99     REComSession::FinalClose( );
    99     REComSession::FinalClose( );
   100     }
   100     }
   101     
   101 
   102 // ----------------------------------------------------------------------------
   102 // ----------------------------------------------------------------------------
   103 //
   103 //
   104 // ----------------------------------------------------------------------------
   104 // ----------------------------------------------------------------------------
   105 //
   105 //
   106 void CPluginValidator::RunL()
   106 void CPluginValidator::RunL()
   107     {
   107     {
       
   108     iSession->NotifyOnChange( iStatus );
       
   109     SetActive();
   108     ManagePluginsL();
   110     ManagePluginsL();
   109     iSession->NotifyOnChange( iStatus );
       
   110     SetActive();    
       
   111     }
   111     }
   112 
   112 
   113 // ----------------------------------------------------------------------------
   113 // ----------------------------------------------------------------------------
   114 //
   114 //
   115 // ----------------------------------------------------------------------------
   115 // ----------------------------------------------------------------------------
   129     }
   129     }
   130 // ----------------------------------------------------------------------------
   130 // ----------------------------------------------------------------------------
   131 //
   131 //
   132 // ----------------------------------------------------------------------------
   132 // ----------------------------------------------------------------------------
   133 //
   133 //
   134 CPluginValidator::CPluginValidator( TUid aUid, TAny* aParameter ): 
   134 CPluginValidator::CPluginValidator( TUid aUid, TAny* aParameter ):
   135                                                   CActive(EPriorityStandard),
   135                                                   CActive(EPriorityStandard),
   136                                                   iUid( aUid ),
   136                                                   iUid( aUid ),
   137                                                   iParameter( aParameter )
   137                                                   iParameter( aParameter )
   138     {
   138     {
   139     
   139 
   140     }
   140     }
   141 
   141 
   142 // ----------------------------------------------------------------------------
   142 // ----------------------------------------------------------------------------
   143 //
   143 //
   144 // ----------------------------------------------------------------------------
   144 // ----------------------------------------------------------------------------
   154 
   154 
   155 // ----------------------------------------------------------------------------
   155 // ----------------------------------------------------------------------------
   156 //
   156 //
   157 // ----------------------------------------------------------------------------
   157 // ----------------------------------------------------------------------------
   158 //
   158 //
   159 TBool CPluginValidator::PresentInArrayL( TPluginInfo aPluginInfo, 
   159 TBool CPluginValidator::PresentInArrayL( TPluginInfo aPluginInfo,
   160 		const RImplInfoPtrArray& aInfoArray )
   160         const RImplInfoPtrArray& aInfoArray )
   161 	{
   161     {
   162 	TBool result(EFalse);
   162     TBool result( EFalse );
   163 	for ( TInt i = 0; i< aInfoArray.Count(); i++ )
   163     for( TInt i = 0; i < aInfoArray.Count(); i++ )
   164 		{
   164         {
   165 		if ( aPluginInfo.iImplementationUid.iUid == 
   165         if( aPluginInfo.iImplementationUid.iUid
   166 						aInfoArray[i]->ImplementationUid().iUid)
   166                 == aInfoArray[i]->ImplementationUid().iUid )
   167 			{
   167             {
   168 			result = ETrue;
   168             result = ETrue;
   169 			break;
   169             break;
   170 			}
   170             }
   171 		}
   171         }
   172 	return result;
   172     return result;
   173 	}
   173     }
   174 
   174 
   175 // ----------------------------------------------------------------------------
   175 // ----------------------------------------------------------------------------
   176 //
   176 //
   177 // ----------------------------------------------------------------------------
   177 // ----------------------------------------------------------------------------
   178 //        
   178 //
   179 void CPluginValidator::DestroyPlugin( TInt aIndex )    
   179 void CPluginValidator::DestroyPlugin( TInt aIndex )
   180     {
   180     {
   181     CBase* plugin = static_cast<CBase*>( iPluginArray[aIndex].iPlugin );
   181     CBase* plugin = static_cast<CBase*>( iPluginArray[aIndex].iPlugin );
   182     delete plugin;
   182     delete plugin;
   183     REComSession::DestroyedImplementation( 
   183     REComSession::DestroyedImplementation(
   184     		iPluginArray[aIndex].iDtor_ID_Key );
   184             iPluginArray[aIndex].iDtor_ID_Key );
   185     }
   185     }
   186 
   186 
   187 // ----------------------------------------------------------------------------
   187 // ----------------------------------------------------------------------------
   188 //
   188 //
   189 // ----------------------------------------------------------------------------
   189 // ----------------------------------------------------------------------------
   190 //        
   190 //
   191 void CPluginValidator::CleanPluginsTable()    
   191 void CPluginValidator::CleanPluginsTable()
   192     {
   192     {
   193     for ( TInt i = 0; i < iPluginArray.Count(); i++ )
   193     for( TInt i = 0; i < iPluginArray.Count(); i++ )
   194     	{
   194         {
   195     	DestroyPlugin( i );
   195         DestroyPlugin( i );
   196     	}
   196         }
   197     }
   197     }
   198 
   198 
   199 // ----------------------------------------------------------------------------
   199 // ----------------------------------------------------------------------------
   200 //
   200 //
   201 // ----------------------------------------------------------------------------
   201 // ----------------------------------------------------------------------------
   202 //
   202 //
   203 void CPluginValidator::ManagePluginsL()    
   203 void CPluginValidator::ManagePluginsL()
   204     {
   204     {
   205     // Read info about all implementations into infoArray
   205     // Read info about all implementations into infoArray
   206     RImplInfoPtrArray infoArray;
   206     RImplInfoPtrArray infoArray;
   207     CleanupResetAndDestroyPushL( infoArray );
   207     CleanupResetAndDestroyPushL( infoArray );
   208 	
   208 
   209     REComSession::ListImplementationsL( iUid , infoArray );
   209     REComSession::ListImplementationsL( iUid , infoArray );
   210     TPluginInfo pluginInfo;   
   210     TPluginInfo pluginInfo;
   211     //Load new plugins
   211     //Load new plugins
   212     for ( TInt i = 0; i < infoArray.Count( ); i++ )
   212     for ( TInt i = 0; i < infoArray.Count( ); i++ )
   213         {
   213         {
   214         pluginInfo.iImplementationUid = infoArray[i]->ImplementationUid( );
   214         pluginInfo.iImplementationUid = infoArray[i]->ImplementationUid( );
   215         pluginInfo.iVersion = infoArray[i]->Version();
   215         pluginInfo.iVersion = infoArray[i]->Version();
   216         
   216 
   217         TInt index = iPluginArray.Find( pluginInfo, 
   217         TInt index = iPluginArray.Find( pluginInfo,
   218         			TIdentityRelation< TPluginInfo >(UidMatch) );
   218               TIdentityRelation< TPluginInfo >(UidMatch) );
   219         
   219 
   220         if ( index == KErrNotFound )
   220         if( index == KErrNotFound )
   221         	{
   221             {
   222         	//plugin wasn't present, we load it now
   222             //plugin wasn't present, we load it now
   223 			LoadPluginL( pluginInfo );
   223             LoadPluginL( pluginInfo );
   224         	}
   224             }
   225         else if ( pluginInfo.iVersion > iPluginArray[index].iVersion )
   225         else if( pluginInfo.iVersion > iPluginArray[index].iVersion )
   226         	{
   226             {
   227         	//plugin was present but it is a newer version, 
   227             //plugin was present but it is a newer version,
   228         	//remove old and load a new one
   228             //remove old and load a new one
   229 			DestroyPlugin( index );
   229             DestroyPlugin( index );
   230 			iPluginArray.Remove( index );
   230             iPluginArray.Remove( index );
   231 			LoadPluginL( pluginInfo );
   231             LoadPluginL( pluginInfo );
   232         	}
   232             }
   233         }
   233         }
   234     //Remove old plugins
   234     //Remove old plugins
   235     for ( TInt i = iPluginArray.Count() - 1 ; i >= 0; i-- )
   235     for( TInt i = iPluginArray.Count() - 1; i >= 0; i-- )
   236     	{
   236         {
   237     	pluginInfo = iPluginArray[i];
   237         pluginInfo = iPluginArray[i];
   238     	if ( !PresentInArrayL( pluginInfo, infoArray ) )
   238         if ( !PresentInArrayL( pluginInfo, infoArray ) )
   239     		{
   239             {
   240     		DestroyPlugin( i );
   240             DestroyPlugin( i );
   241     	    iPluginArray.Remove( i );
   241             iPluginArray.Remove( i );
   242     		}
   242             }
   243     	}
   243         }
   244     CleanupStack::PopAndDestroy( &infoArray );    
   244         CleanupStack::PopAndDestroy( &infoArray );
   245     }
   245     }
   246 
   246 
   247 // ----------------------------------------------------------------------------
   247 // ----------------------------------------------------------------------------
   248 //
   248 //
   249 // ----------------------------------------------------------------------------
   249 // ----------------------------------------------------------------------------
   250 //
   250 //
   251 void CPluginValidator::LoadPluginL( TPluginInfo& aPluginInfo )    
   251 void CPluginValidator::LoadPluginL( TPluginInfo& aPluginInfo )
   252     {
   252     {
   253 	TAny* plug ( NULL );
   253     TAny* plug( NULL );
   254 	TInt err( KErrNone );
   254     TInt err( KErrNone );
   255 	TRAP( err, plug = REComSession::CreateImplementationL( 
   255     TRAP( err, plug = REComSession::CreateImplementationL(
   256 										aPluginInfo.iImplementationUid, 
   256                     aPluginInfo.iImplementationUid,
   257 										aPluginInfo.iDtor_ID_Key, iParameter ) );
   257                     aPluginInfo.iDtor_ID_Key, iParameter ) );
   258 	if( err==KErrNone && plug ) 
   258     if( err == KErrNone && plug )
   259 		{
   259         {
   260 		CleanupStack::PushL( plug );
   260         CleanupStack::PushL( plug );
   261 		aPluginInfo.iPlugin = plug;
   261         aPluginInfo.iPlugin = plug;
   262 		iPluginArray.AppendL( aPluginInfo );
   262         iPluginArray.AppendL( aPluginInfo );
   263 		CleanupStack::Pop( plug );
   263         CleanupStack::Pop( plug );
   264 		}
   264         }
   265    	}
   265     }
   266