idlehomescreen/hscontentcontrol/src/hscontentcontrolfactory.cpp
changeset 1 5315654608de
parent 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
0:f72a12da539e 1:5315654608de
    19 #include <ecom/ecom.h>
    19 #include <ecom/ecom.h>
    20 #include <ecom/implementationinformation.h>
    20 #include <ecom/implementationinformation.h>
    21 
    21 
    22 // User include files
    22 // User include files
    23 #include "hscontentcontrolfactory.h"
    23 #include "hscontentcontrolfactory.h"
       
    24 #include "hscontentcontrolecomlistener.h"
    24 
    25 
    25 // Local constants
    26 // Local constants
    26 
    27 
    27 // TODO: Content controller ECom interface UID
    28 // Content controller ECom interface UID
    28 const TUid KInterfaceUidContentController = { 0x20026F51 };
    29 const TUid KInterfaceUidContentController = { 0x20026F51 };
    29 
    30 
    30 // ======== LOCAL FUNCTIONS ========
    31 // ======== LOCAL FUNCTIONS ========
    31 
    32 
    32 // ----------------------------------------------------------------------------
    33 // ----------------------------------------------------------------------------
    71 // CHsContentControlFactory::ConstructL()
    72 // CHsContentControlFactory::ConstructL()
    72 // ----------------------------------------------------------------------------
    73 // ----------------------------------------------------------------------------
    73 //
    74 //
    74 void CHsContentControlFactory::ConstructL()
    75 void CHsContentControlFactory::ConstructL()
    75     {
    76     {
       
    77     iHsContentControlEComListener = 
       
    78             CHsContentControlEComListener::NewL( *this );
       
    79     REComSession::ListImplementationsL( 
       
    80             KInterfaceUidContentController, iImplArray );
    76     }
    81     }
    77 
    82 
    78 // ----------------------------------------------------------------------------
    83 // ----------------------------------------------------------------------------
    79 // CHsContentControlFactory::CHsContentControlFactory()
    84 // CHsContentControlFactory::CHsContentControlFactory()
    80 // ----------------------------------------------------------------------------
    85 // ----------------------------------------------------------------------------
    87 // CHsContentControlFactory::~CHsContentControlFactory()
    92 // CHsContentControlFactory::~CHsContentControlFactory()
    88 // ----------------------------------------------------------------------------
    93 // ----------------------------------------------------------------------------
    89 //
    94 //
    90 EXPORT_C CHsContentControlFactory::~CHsContentControlFactory()
    95 EXPORT_C CHsContentControlFactory::~CHsContentControlFactory()
    91     {
    96     {
       
    97     iImplArray.ResetAndDestroy();
       
    98     iImplArray.Close();
    92     iHsContentControlUis.ResetAndDestroy();
    99     iHsContentControlUis.ResetAndDestroy();
       
   100 	delete iHsContentControlEComListener;
    93     }
   101     }
    94 
   102 
    95 // ---------------------------------------------------------------------------------
   103 // ---------------------------------------------------------------------------------
    96 // CHsContentControlFactory::GetHsContentController()
   104 // CHsContentControlFactory::GetHsContentController()
    97 // ---------------------------------------------------------------------------------
   105 // ---------------------------------------------------------------------------------
   113             
   121             
   114             for ( TInt i = 0; i < plugins.Count(); i++ )
   122             for ( TInt i = 0; i < plugins.Count(); i++ )
   115                 {
   123                 {
   116                 CImplementationInformation* information( plugins[i] );
   124                 CImplementationInformation* information( plugins[i] );
   117                 
   125                 
   118                 if ( information->OpaqueData().Compare( aControlType ) == 0 )
   126                 if ( information->OpaqueData().CompareF( aControlType ) == 0 )
   119                     {
   127                     {
   120                     CHsContentControlUi* ccUi = CHsContentControlUi::NewL( 
   128                     CHsContentControlUi* ccUi = CHsContentControlUi::NewL( 
   121                         information->ImplementationUid() );
   129                         information->ImplementationUid() );
       
   130                     CleanupStack::PushL( ccUi );
   122                     
   131                     
   123                     ccUi->SetContentControlTypeL( information->OpaqueData() );
   132                     ccUi->SetContentControlTypeL( information->OpaqueData() );
   124                     
       
   125                     iHsContentControlUis.AppendL( ccUi );
   133                     iHsContentControlUis.AppendL( ccUi );
   126                     
   134                     
       
   135                     CleanupStack::Pop(); //ccUi
   127                     retval = ccUi;
   136                     retval = ccUi;
   128                     
       
   129                     // All done
   137                     // All done
   130                     break;
   138                     break;
   131                     }
   139                     }
   132                 }
   140                 }
   133             
   141             
   147     {       
   155     {       
   148     for ( TInt i = 0; i < iHsContentControlUis.Count(); i++ )
   156     for ( TInt i = 0; i < iHsContentControlUis.Count(); i++ )
   149         {
   157         {
   150         CHsContentControlUi* cc( iHsContentControlUis[ i ] );
   158         CHsContentControlUi* cc( iHsContentControlUis[ i ] );
   151         
   159         
   152         if ( cc->ContentControlType().Compare( aControlType ) == 0 )                
   160         if ( cc->ContentControlType().CompareF( aControlType ) == 0 )                
   153             {
   161             {
   154             return cc;
   162             return cc;
   155             } 
   163             } 
   156         }
   164         }
   157     
   165     
   158     return NULL;
   166     return NULL;
   159     }
   167     }
   160 
   168 
       
   169 // ----------------------------------------------------------------------------
       
   170 // CHsContentControlFactory::HandleEComChangeEvent()
       
   171 // ----------------------------------------------------------------------------
       
   172 //
       
   173 void CHsContentControlFactory::HandleEComChangeEvent()
       
   174     {
       
   175     // ignore event if no plugin loaded.
       
   176     if ( iHsContentControlUis.Count() > 0 )
       
   177         {
       
   178         TRAP_IGNORE( CheckPluginChangesL(); );
       
   179         }
       
   180     }
       
   181 
       
   182 // ----------------------------------------------------------------------------
       
   183 // CHsContentControlFactory::CheckPluginChangesL
       
   184 // ----------------------------------------------------------------------------
       
   185 //
       
   186 void CHsContentControlFactory::CheckPluginChangesL()
       
   187     {
       
   188     // Array to return all implementations in an interface
       
   189     RImplInfoPtrArray plugInArray;
       
   190     CleanupResetAndDestroyPushL( plugInArray );
       
   191 
       
   192     // Get the list of all implementations.
       
   193     REComSession::ListImplementationsL( 
       
   194             KInterfaceUidContentController, plugInArray );
       
   195         
       
   196     TUid uid( KNullUid );
       
   197     TBool done( EFalse );
       
   198     
       
   199     // If an implementation is not present in present in the plugInArray then its removed. 
       
   200     for( TInt index( iImplArray.Count() - 1 ); index >= 0 && !done; --index )
       
   201         {
       
   202         uid = plugInArray[ index ]->ImplementationUid();
       
   203         CImplementationInformation* implInfo = 
       
   204                 FindPluginImplInfo( uid, plugInArray );
       
   205         if ( implInfo && PluginUpgradeDowngrade( *implInfo ) )
       
   206             {
       
   207             done = ETrue;
       
   208             }
       
   209         else
       
   210             {
       
   211             // check if ContenControlUi is loaded, unload it
       
   212             for( TInt innerIndex( iHsContentControlUis.Count() - 1 );
       
   213                     innerIndex >= 0 && !done; --innerIndex )
       
   214                 {
       
   215                 CHsContentControlUi* cc( iHsContentControlUis[ innerIndex ] );
       
   216                 if ( cc && cc->ImplUid() == uid )
       
   217                     {
       
   218                     iHsContentControlUis.Remove( innerIndex );
       
   219                     delete cc;
       
   220                     cc = NULL;
       
   221                     done = ETrue;
       
   222                     }
       
   223                 }
       
   224             done = ETrue;
       
   225             }
       
   226         }
       
   227 
       
   228     // Cleanup.
       
   229     CleanupStack::PopAndDestroy(); // plugInArray
       
   230     
       
   231     // Reset the array and refresh the plugin list.
       
   232     iImplArray.ResetAndDestroy();
       
   233     iImplArray.Close();    
       
   234     REComSession::ListImplementationsL( 
       
   235             KInterfaceUidContentController, iImplArray );
       
   236     }
       
   237 
       
   238 // ----------------------------------------------------------------------------
       
   239 // CHsContentControlFactory::FindPluginImplInfo
       
   240 // ----------------------------------------------------------------------------
       
   241 //
       
   242 CImplementationInformation* CHsContentControlFactory::FindPluginImplInfo( 
       
   243         const TUid& aUid, const RImplInfoPtrArray& aPlugInArray )
       
   244     {
       
   245     CImplementationInformation* implInfo( NULL );
       
   246     for( TInt index( aPlugInArray.Count() - 1 ); index >= 0; --index )
       
   247         {
       
   248         implInfo = aPlugInArray[ index ];
       
   249         if( aUid == implInfo->ImplementationUid() )
       
   250             {
       
   251             break;
       
   252             }
       
   253         }
       
   254     return implInfo;
       
   255     }
       
   256 
       
   257 // ----------------------------------------------------------------------------
       
   258 // CHsContentControlFactory::PluginUpgradeDowngrade
       
   259 // ----------------------------------------------------------------------------
       
   260 //
       
   261 TBool CHsContentControlFactory::PluginUpgradeDowngrade( 
       
   262         const CImplementationInformation& aPluginImplInfo )
       
   263     {
       
   264     // Check for each plugin in the array if the version matches with the plugin we have
       
   265     TUid uid = aPluginImplInfo.ImplementationUid();
       
   266     for( TInt outterIndex( iImplArray.Count() - 1 ); outterIndex >= 0; --outterIndex )
       
   267         {
       
   268         if( uid == iImplArray[ outterIndex ]->ImplementationUid() )
       
   269             {
       
   270             if( aPluginImplInfo.Version() != iImplArray[ outterIndex ]->Version() ||
       
   271                aPluginImplInfo.Drive() != iImplArray[ outterIndex ]->Drive() ||
       
   272                aPluginImplInfo.DisplayName() != iImplArray[ outterIndex ]->DisplayName() ||
       
   273                aPluginImplInfo.OpaqueData() != iImplArray[ outterIndex ]->OpaqueData() )
       
   274                 {
       
   275                 // If control reaches here, it means we either have an upgrade or downgrade.
       
   276                 // check if we have loaded this plugin, reload it if found in array.
       
   277                 for( TInt innerIndex( iHsContentControlUis.Count() - 1 ); 
       
   278                         innerIndex >= 0; --innerIndex )
       
   279                     {
       
   280                     CHsContentControlUi* cc( iHsContentControlUis[ innerIndex ] );
       
   281                     if ( cc && cc->ImplUid() == uid )
       
   282                         {
       
   283                         iHsContentControlUis.Remove( innerIndex );
       
   284                         delete cc;
       
   285                         cc = NULL;
       
   286                         innerIndex = KErrNotFound;
       
   287                         }
       
   288                     }                    
       
   289                 return ETrue;
       
   290                 }
       
   291             }
       
   292         }
       
   293     return EFalse;
       
   294     }
       
   295 
   161 // End of file
   296 // End of file