idlefw/src/framework/aicontentpluginmanager.cpp
branchRCL_3
changeset 8 d0529222e3f0
parent 4 1a2a00e78665
child 11 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 8:d0529222e3f0
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Content plugin error manager class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ecom/ecom.h>
       
    20 #include <ecom/implementationinformation.h>
       
    21 #include <aiutility.h>
       
    22 #include <aiplugintool.h>
       
    23 
       
    24 #include <centralrepository.h>
       
    25 #include <activeidle2domaincrkeys.h>
       
    26 
       
    27 #include "aicontentpluginmanager.h"
       
    28 #include "aipluginstatemanager.h"
       
    29 #include "aifweventhandler.h"
       
    30 #include "aicontentpublisher.h"
       
    31 #include "aipropertyextension.h"
       
    32 #include <aicontentrequest.h>
       
    33 #include "aieventhandlerextension.h"
       
    34 #include "aiuicontroller.h"
       
    35 #include "aiconsts.h"
       
    36 #include "debug.h"
       
    37 
       
    38 // CONSTANTS
       
    39 const TInt KAILenOfParenthesis( 2 );
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ----------------------------------------------------------------------------
       
    44 // CAiContentPluginManager::NewL()
       
    45 // ----------------------------------------------------------------------------
       
    46 //
       
    47 CAiContentPluginManager* CAiContentPluginManager::NewL()
       
    48     {
       
    49     CAiContentPluginManager* self = new ( ELeave ) CAiContentPluginManager();         
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop( self );
       
    53     return self;
       
    54     }
       
    55   
       
    56 // ----------------------------------------------------------------------------
       
    57 // CAiContentPluginManager::ConstructL()
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void CAiContentPluginManager::ConstructL()
       
    61     {
       
    62     iPluginFactory = CAiPluginFactory::NewL( iPlugins, *this );
       
    63 
       
    64     iStateManager = CAiPluginStateManager::NewL();
       
    65     
       
    66     iPluginFactory->AddLifecycleObserverL( *iStateManager );
       
    67         
       
    68     iPluginTool = AiUtility::CreatePluginToolL();
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CAiContentPluginManager::~CAiContentPluginManager()
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 CAiContentPluginManager::~CAiContentPluginManager()
       
    76     {               
       
    77     iPlugins.ResetAndDestroy();
       
    78     
       
    79     delete iPluginFactory;
       
    80     delete iStateManager;
       
    81     
       
    82     Release( iPluginTool );
       
    83     }
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // CAiContentPluginManager::CAiContentPluginManager()
       
    87 // ----------------------------------------------------------------------------
       
    88 //
       
    89 CAiContentPluginManager::CAiContentPluginManager() 
       
    90     {
       
    91     }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CAiContentPluginManager::HandlePluginEvent()
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 void CAiContentPluginManager::HandlePluginEvent( const TDesC& aParam )    
       
    98     {
       
    99     const TInt separatorPos( aParam.Locate( KPluginEventSeparator ) );
       
   100     
       
   101     if( separatorPos == KErrNotFound )
       
   102         {
       
   103         return;
       
   104         }
       
   105 
       
   106     // Extract plugin name
       
   107     TPtrC pluginName( aParam.Left( separatorPos ) );
       
   108     
       
   109     // Extract event and parameter string
       
   110     TPtrC eventNameAndParams( aParam.Mid( separatorPos + 1 ) );
       
   111 
       
   112     // Find parameter string position
       
   113     const TInt paramsPos( 
       
   114             eventNameAndParams.Locate( KEventParameterSeparator  ) );
       
   115     
       
   116     // Extract event name
       
   117     TPtrC eventName( paramsPos < 0 ? eventNameAndParams : 
       
   118                                      eventNameAndParams.Left( paramsPos ) );
       
   119     
       
   120     // Calculate actual parameter string length by ignoring parenthesis 
       
   121     TInt paramsLength( 
       
   122             eventNameAndParams.Length() - paramsPos - KAILenOfParenthesis );
       
   123     
       
   124     // Extract paramenters
       
   125     TPtrC param( paramsPos < 0 ? KNullDesC()  :             
       
   126             eventNameAndParams.Mid( paramsPos + 1, Max( 0, paramsLength ) ) );
       
   127     
       
   128     // Resolve plugin
       
   129     CAiContentPublisher* target = NULL;
       
   130     
       
   131     __TIME( "FW: Lookup plug-in by name",
       
   132             
       
   133         TRAP_IGNORE( target = iPluginFactory->PluginByNameL( pluginName ) );  
       
   134     
       
   135     );
       
   136 
       
   137     __PRINT( __DBG_FORMAT( 
       
   138             "\t[I]\t Event: %S to plug-in by addr 0x%x" ), &aParam, target );
       
   139     
       
   140     if( target )
       
   141         {
       
   142         // Resolve plugin specific event id
       
   143         TInt eventId( KErrNotFound );
       
   144         
       
   145         TRAP_IGNORE( GetIdL( *target, EAiPublisherEvents, eventName, eventId ) );
       
   146         
       
   147         // Forward event to plugin
       
   148         MAiEventHandlerExtension* ext( 
       
   149                 iPluginTool->EventHandlerExt( *target ) );
       
   150         
       
   151         if( ext )
       
   152             {
       
   153             if( eventId != KErrNotFound )
       
   154                 {
       
   155                 ext->HandleEvent( eventId, param );
       
   156                 }
       
   157             else
       
   158                 {
       
   159                 ext->HandleEvent( eventName, param );
       
   160                 }
       
   161             }
       
   162         }
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CAiContentPluginManager::HandlePluginEventL()
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 void CAiContentPluginManager::HandlePluginEventL( 
       
   170     const TAiPublisherInfo& aPublisherInfo, const TDesC& aParam )
       
   171     {
       
   172     // Resolve plugin
       
   173     CAiContentPublisher* target( 
       
   174             iPluginFactory->PluginByInfoL( aPublisherInfo ) );
       
   175               
       
   176     if( target )    
       
   177         {
       
   178         const TInt separatorPos( aParam.Locate( KPluginEventSeparator ) );
       
   179         
       
   180         // Extract event and parameter string
       
   181         TPtrC eventNameAndParams( aParam.Mid( separatorPos + 1 ) );
       
   182 
       
   183         // Find parameter string position
       
   184         const TInt paramsPos( 
       
   185                 eventNameAndParams.Locate( KEventParameterSeparator  ) );
       
   186         
       
   187         // Extract event name
       
   188         TPtrC eventName( paramsPos < 0 ? 
       
   189             eventNameAndParams : eventNameAndParams.Left( paramsPos ) );
       
   190         
       
   191         // Calculate actual parameter string length by ignoring parenthesis 
       
   192         TInt paramsLength( 
       
   193                 eventNameAndParams.Length() - paramsPos - KAILenOfParenthesis );
       
   194         
       
   195         // Extract paramenters
       
   196         TPtrC param( paramsPos < 0 ? KNullDesC() :
       
   197             eventNameAndParams.Mid( paramsPos + 1, Max( 0, paramsLength ) ) );
       
   198         
       
   199         // Resolve plugin specific event id
       
   200         TInt eventId( KErrNotFound );
       
   201         
       
   202         GetIdL( *target, EAiPublisherEvents, eventName, eventId );
       
   203         
       
   204         // Forward event to plugin
       
   205         MAiEventHandlerExtension* ext( 
       
   206                 iPluginTool->EventHandlerExt( *target ) );
       
   207         
       
   208         if( ext )
       
   209             {
       
   210             if( eventId != KErrNotFound )
       
   211                 {
       
   212                 ext->HandleEvent( eventId, param );
       
   213                 }
       
   214             else
       
   215                 {
       
   216                 ext->HandleEvent( eventName, param );
       
   217                 }
       
   218             }        
       
   219         }
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------------------------------
       
   223 // CAiContentPluginManager::HasMenuItemL()
       
   224 // ----------------------------------------------------------------------------
       
   225 //
       
   226 TBool CAiContentPluginManager::HasMenuItemL( 
       
   227     const TAiPublisherInfo& aPublisherInfo, const TDesC& aMenuItem )
       
   228     {          
       
   229     // Resolve plugin
       
   230     CAiContentPublisher* target( 
       
   231             iPluginFactory->PluginByInfoL( aPublisherInfo ) );
       
   232               
       
   233     if( target )    
       
   234         {
       
   235         // Forward query to plugin
       
   236         MAiEventHandlerExtension* ext( 
       
   237                 iPluginTool->EventHandlerExt( *target ) );                 
       
   238         
       
   239         if ( ext )
       
   240             {
       
   241             return ext->HasMenuItem( aMenuItem );
       
   242             }
       
   243         }
       
   244 
       
   245     return EFalse;
       
   246     }
       
   247 
       
   248 // ----------------------------------------------------------------------------
       
   249 // CAiContentPluginManager::RefreshContentL()
       
   250 // ----------------------------------------------------------------------------
       
   251 //
       
   252 TBool CAiContentPluginManager::RefreshContent( const TDesC& aContentCid )
       
   253     {
       
   254     TRAPD( error, RefreshContentL( aContentCid ) );
       
   255     
       
   256     return ( error == KErrNone );
       
   257     }
       
   258 
       
   259 // ----------------------------------------------------------------------------
       
   260 // CAiFw::ProcessOnlineState()
       
   261 // ----------------------------------------------------------------------------
       
   262 //
       
   263 void CAiContentPluginManager::ProcessOnlineState( TBool aOnline )    
       
   264     {  
       
   265     _LIT( KOnlineOffline, "online_offline" );
       
   266     
       
   267     for( TInt i = 0; i < iPlugins.Count(); i++ )
       
   268         {               
       
   269         MAiEventHandlerExtension* ext( 
       
   270                 iPluginTool->EventHandlerExt( *iPlugins[i] ) );
       
   271         
       
   272         // If plugin understands online/offline run state change
       
   273         if( ext && ext->HasMenuItem( KOnlineOffline ) )
       
   274             {            
       
   275             if( aOnline )
       
   276                 {
       
   277                 iStateManager->ProcessOnlineState( *iPlugins[i] );
       
   278                 }
       
   279             else
       
   280                 {
       
   281                 iStateManager->ProcessOfflineState( *iPlugins[i] );                     
       
   282                 }                                                           
       
   283             }
       
   284         }       
       
   285     }
       
   286 
       
   287 // ----------------------------------------------------------------------------
       
   288 // CAiContentPluginManager::StateManager()
       
   289 // ----------------------------------------------------------------------------
       
   290 //
       
   291 CAiPluginStateManager& CAiContentPluginManager::StateManager() const
       
   292     {
       
   293     return *iStateManager;
       
   294     }
       
   295 
       
   296 // ----------------------------------------------------------------------------
       
   297 // CAiContentPluginManager::PluginFactory()
       
   298 // ----------------------------------------------------------------------------
       
   299 //
       
   300 CAiPluginFactory& CAiContentPluginManager::PluginFactory() const
       
   301     {
       
   302     return *iPluginFactory;
       
   303     }
       
   304 
       
   305 // ----------------------------------------------------------------------------
       
   306 // CAiContentPluginManager::GetIdL()
       
   307 // ----------------------------------------------------------------------------
       
   308 //
       
   309 void CAiContentPluginManager::GetIdL( CAiContentPublisher& aContentPublisher,         
       
   310     TAiPublisherProperty aProperty, const TDesC& aName, TInt& aId )                 
       
   311     {
       
   312     MAiContentItemIterator* iterator = 
       
   313         iPluginTool->ContentItemIteratorL( aContentPublisher, aProperty );
       
   314 
       
   315     if( iterator )
       
   316         {
       
   317         const TAiContentItem& ci( iterator->ItemL( aName ) );
       
   318         aId = ci.id;
       
   319         }
       
   320     else
       
   321         {
       
   322         aId = KErrNotFound;
       
   323         }
       
   324     }
       
   325 
       
   326 // ----------------------------------------------------------------------------
       
   327 // CAiContentPluginManager::RefreshContentL()
       
   328 // ----------------------------------------------------------------------------
       
   329 //
       
   330 TInt CAiContentPluginManager::RefreshContentL( const TDesC& aContentCid )
       
   331     {
       
   332     TInt retval( KErrNotFound );
       
   333     
       
   334     // Look up plug-in and content item and delegate to plug-in's
       
   335     // MAiContentRequest implementation.
       
   336 
       
   337     // Find plugin name
       
   338     TInt pos( aContentCid.Locate( KPluginEventSeparator ) );
       
   339 
       
   340     if( pos == KErrNotFound )
       
   341         {
       
   342         return retval;        
       
   343         }
       
   344     
       
   345     TPtrC pluginName( aContentCid.Left( pos ) );
       
   346            
       
   347     CAiContentPublisher* plugin( iPluginFactory->PluginByNameL( pluginName ) );
       
   348     
       
   349     if( !plugin )
       
   350         {
       
   351         return retval;
       
   352         }
       
   353     
       
   354     MAiPropertyExtension* ext( iPluginTool->PropertyExt( *plugin ) );
       
   355     
       
   356     if( !ext )
       
   357         {
       
   358         return retval;
       
   359         }
       
   360         
       
   361     // Extract content id
       
   362     TPtrC cid( aContentCid.Mid( ++pos ) );
       
   363     TInt id( 0 );
       
   364     
       
   365     MAiContentRequest* handler( NULL );
       
   366     
       
   367     TRAPD( error, GetIdL( *plugin, EAiPublisherContent, cid, id ) );
       
   368     
       
   369     if ( !error )
       
   370         {
       
   371         handler = static_cast< MAiContentRequest* >( 
       
   372                     ext->GetPropertyL( EAiContentRequest ) );            
       
   373         }
       
   374     else
       
   375         {
       
   376         GetIdL( *plugin, EAiPublisherResources, cid, id );
       
   377         
       
   378         handler = static_cast< MAiContentRequest* >( 
       
   379                     ext->GetPropertyL( EAiResourceRequest ) );           
       
   380         }
       
   381 
       
   382     // Forward event to plugin
       
   383     if( handler && handler->RefreshContent( id ) )
       
   384         {               
       
   385         retval = KErrNone;        
       
   386         }
       
   387     
       
   388     return retval;
       
   389     }
       
   390 
       
   391 // End of File.