menufw/menufwui/mmextensions/mmextensionmanager/src/mmextensionmanager.cpp
branchRCL_3
changeset 83 5456b4e8b3a8
equal deleted inserted replaced
82:5f0182e07bfb 83:5456b4e8b3a8
       
     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 // ---------------------------------------------------------------------------
       
    51 // 
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CMMExtensionManager* CMMExtensionManager::NewLC( MMmActionRequest& aActionRequest )
       
    55 	{
       
    56 	CMMExtensionManager* self = new (ELeave) CMMExtensionManager( aActionRequest );
       
    57 	CleanupStack::PushL( self );
       
    58 	self->ConstructL();
       
    59 	return self;
       
    60 	}
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // 
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CMMExtensionManager* CMMExtensionManager::NewL( 
       
    67                                                    MMmActionRequest& aActionRequest )
       
    68 	{
       
    69 	CMMExtensionManager* self = CMMExtensionManager::NewLC( aActionRequest );
       
    70 	CleanupStack::Pop (); // self;
       
    71 	return self;
       
    72 	}
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // 
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CMMExtensionManager::ConstructL()
       
    79 	{
       
    80 	LoadPluginsL();
       
    81 	}
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CASpaPluginManager::LoadPluginsL
       
    85 // Load plugins implementations
       
    86 // ---------------------------------------------------------------------------
       
    87 //    
       
    88 void CMMExtensionManager::LoadPluginsL()
       
    89     {	
       
    90 	DEBUG16(("\t_MM_: CMMExtensionManager::LoadPluginsL()") );
       
    91 	
       
    92 	// Read info about all implementations into infoArray
       
    93 	RImplInfoPtrArray infoArray;
       
    94 	
       
    95 	// Note that a special cleanup function is required to reset and destroy
       
    96 	// all items in the array, and then close it.
       
    97 	CleanupResetAndDestroyPushL( infoArray );
       
    98 	CMMExtensionPlugin::ListAllImplementationsL( infoArray );
       
    99 	
       
   100 	// Loop through each info for each implementation
       
   101 	// and create and use each in turn
       
   102 	CMMExtensionPlugin* plug;
       
   103 	for ( TInt i = 0; i < infoArray.Count(); i++ )
       
   104 		{
       
   105 		// Slice off first sub-section in the data section
       
   106 	    TUid current_plugin = infoArray[i]->ImplementationUid();
       
   107 		plug = CMMExtensionPlugin::NewL( current_plugin , &iActionRequest );
       
   108 		CleanupStack::PushL( plug );
       
   109 		TInt32 key = current_plugin.iUid;
       
   110 	    iPluginMap.InsertL( key, plug );
       
   111 	    CleanupStack::Pop( plug );
       
   112 		plug = NULL;
       
   113 		}
       
   114     CleanupStack::PopAndDestroy( &infoArray );
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // 
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 TInt CMMExtensionManager::ExecuteActionL( 
       
   122 	    const TUid aUid,
       
   123         const TDesC& aCommand,
       
   124 	    CLiwGenericParamList* aEventParamList )
       
   125 	{
       
   126     TInt result = KErrNotFound;
       
   127 	if( aUid.iUid != KNullUidValue )
       
   128 	    {
       
   129 	    CMMExtensionPlugin* pluginInstance = GetImplementationL( aUid );
       
   130 	    if( pluginInstance ) 
       
   131 	        {
       
   132 	        result = pluginInstance->ExecuteActionL(
       
   133 	                aCommand, aEventParamList );
       
   134 	        }
       
   135 	    }
       
   136 	else
       
   137 	    {
       
   138 	    THashMapIter<TInt32, CMMExtensionPlugin*> plugins( iPluginMap );
       
   139 	    CMMExtensionPlugin* const* plugin = NULL;
       
   140 	    for( plugin = plugins.NextValue(); plugin;
       
   141 	            plugin = plugins.NextValue() )
       
   142 	        {
       
   143 	        (*plugin)->ExecuteActionL( aCommand, aEventParamList );
       
   144 	        }
       
   145 	    result = KErrNone;
       
   146 	    }
       
   147 	return result;
       
   148 	}
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // 
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 CMMExtensionPlugin* CMMExtensionManager::GetImplementationL(
       
   155     const TUid aUid )
       
   156     {
       
   157     CMMExtensionPlugin* ret = NULL;
       
   158     CMMExtensionPlugin **imp = NULL;
       
   159 
       
   160     TInt pluginId ( aUid.iUid );
       
   161     
       
   162     imp = iPluginMap.Find( pluginId );
       
   163     if( imp )
       
   164         {
       
   165         ret = *imp;
       
   166         }
       
   167     return ret;
       
   168     }
       
   169 
       
   170 // End of file