menufw/menufwui/mmextensions/mmextensionmanager/src/mmextensionmanager.cpp
changeset 0 f72a12da539e
child 54 1b758917cafc
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2007 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:   Menu Framework Extension Manager
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL
       
    19 
       
    20 #include "mmextensionplugin.h"
       
    21 #include "mmextensionmanager.h"
       
    22 #include "menudebug.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // 
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CMMExtensionManager::CMMExtensionManager( MMmActionRequest& aActionRequest ):
       
    29     iActionRequest( aActionRequest )
       
    30 	{
       
    31 	// No implementation required
       
    32 	}
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // 
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CMMExtensionManager::~CMMExtensionManager()
       
    39 	{
       
    40 	THashMapIter< TInt32, CMMExtensionPlugin* > iter( iPluginMap);	
       
    41     for (CMMExtensionPlugin* const* ptr =
       
    42                                 ( CMMExtensionPlugin* const* ) iter.NextValue();
       
    43         ptr; ptr = ( CMMExtensionPlugin* const* ) iter.NextValue())
       
    44         {
       
    45             delete (CMMExtensionPlugin*)(*ptr);
       
    46         }    
       
    47 	iPluginMap.Close ();
       
    48 	
       
    49 	
       
    50     //delete iPluginNameMap
       
    51     /*THashMapIter< HBufC*, TInt32 > iter1( iPluginNameMap );
       
    52     while ( HBufC*const* ptrHbuf = iter1.NextKey() )
       
    53         {		
       
    54         delete *ptrHbuf;
       
    55         }  
       
    56     iPluginNameMap.Close();*/
       
    57 	
       
    58     delete iEcomObserver;
       
    59 	}
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // 
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CMMExtensionManager* CMMExtensionManager::NewLC( MMmActionRequest& aActionRequest )
       
    66 	{
       
    67 	CMMExtensionManager* self = new (ELeave) CMMExtensionManager( aActionRequest );
       
    68 	CleanupStack::PushL( self );
       
    69 	self->ConstructL();
       
    70 	return self;
       
    71 	}
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // 
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C CMMExtensionManager* CMMExtensionManager::NewL( 
       
    78                                                    MMmActionRequest& aActionRequest )
       
    79 	{
       
    80 	CMMExtensionManager* self = CMMExtensionManager::NewLC( aActionRequest );
       
    81 	CleanupStack::Pop (); // self;
       
    82 	return self;
       
    83 	}
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // 
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CMMExtensionManager::ConstructL()
       
    90 	{
       
    91     iEcomObserver = CMMEcomObserver::NewL( this );
       
    92 	LoadPluginsL();
       
    93 	}
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CASpaPluginManager::LoadPluginsL
       
    97 // Load plugins implementations
       
    98 // ---------------------------------------------------------------------------
       
    99 //    
       
   100 void CMMExtensionManager::LoadPluginsL()
       
   101     {	
       
   102 	DEBUG16(("\t_MM_: CMMExtensionManager::LoadPluginsL()") );
       
   103 	
       
   104 	// Read info about all implementations into infoArray
       
   105 	RImplInfoPtrArray infoArray;
       
   106 	
       
   107 	// Note that a special cleanup function is required to reset and destroy
       
   108 	// all items in the array, and then close it.
       
   109 	CleanupResetAndDestroyPushL( infoArray );
       
   110 	CMMExtensionPlugin::ListAllImplementationsL( infoArray );
       
   111 	
       
   112 	// Loop through each info for each implementation
       
   113 	// and create and use each in turn
       
   114 	CMMExtensionPlugin* plug;
       
   115 	for ( TInt i = 0; i < infoArray.Count(); i++ )
       
   116 		{
       
   117 		// Slice off first sub-section in the data section
       
   118 	    TUid current_plugin = infoArray[i]->ImplementationUid();
       
   119 		plug = CMMExtensionPlugin::NewL( current_plugin , &iActionRequest );
       
   120 		CleanupStack::PushL( plug );
       
   121 		TInt32 key = current_plugin.iUid;
       
   122 	    iPluginMap.InsertL( key, plug );
       
   123 	    CleanupStack::Pop( plug );
       
   124 		plug = NULL;
       
   125 		}
       
   126     CleanupStack::PopAndDestroy( &infoArray );
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // 
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 TInt CMMExtensionManager::ExecuteActionL( 
       
   134 	    const TUid aUid,
       
   135         const TDesC& aCommand,
       
   136 	    CLiwGenericParamList* aEventParamList )
       
   137 	{
       
   138     TInt result = KErrNotFound;
       
   139 	if( aUid.iUid != KNullUidValue )
       
   140 	    {
       
   141 	    CMMExtensionPlugin* pluginInstance = GetImplementationL( aUid );
       
   142 	    if( pluginInstance ) 
       
   143 	        {
       
   144 	        result = pluginInstance->ExecuteActionL(
       
   145 	                aCommand, aEventParamList );
       
   146 	        }
       
   147 	    }
       
   148 	else
       
   149 	    {
       
   150 	    THashMapIter<TInt32, CMMExtensionPlugin*> plugins( iPluginMap );
       
   151 	    CMMExtensionPlugin* const* plugin = NULL;
       
   152 	    for( plugin = plugins.NextValue(); plugin;
       
   153 	            plugin = plugins.NextValue() )
       
   154 	        {
       
   155 	        (*plugin)->ExecuteActionL( aCommand, aEventParamList );
       
   156 	        }
       
   157 	    result = KErrNone;
       
   158 	    }
       
   159 	return result;
       
   160 	}
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // 
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 CMMExtensionPlugin* CMMExtensionManager::GetImplementationL(
       
   167     const TUid aUid )
       
   168     {
       
   169     CMMExtensionPlugin* ret = NULL;
       
   170     CMMExtensionPlugin **imp = NULL;
       
   171 
       
   172     TInt pluginId ( aUid.iUid );
       
   173     
       
   174     imp = iPluginMap.Find( pluginId );
       
   175     if( imp )
       
   176         {
       
   177         ret = *imp;
       
   178         }
       
   179     return ret;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // 
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CMMExtensionManager::EcomChangedL()
       
   187     {
       
   188     THashMapIter< TInt32, CMMExtensionPlugin* > iter( iPluginMap );
       
   189     for (CMMExtensionPlugin* const* ptr =
       
   190                                 ( CMMExtensionPlugin* const* ) iter.NextValue();
       
   191         ptr; ptr = ( CMMExtensionPlugin* const* ) iter.NextValue())
       
   192         {
       
   193             delete (CMMExtensionPlugin*)(*ptr);
       
   194         }
       
   195     iPluginMap.Close();
       
   196     LoadPluginsL();
       
   197     }
       
   198 
       
   199 // End of file