sl@0: /* sl@0: * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: Class definition of plugin implementing devsound client sl@0: * custom interface extension. sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: // Include files sl@0: #include "ciextnclientplugin.h" sl@0: #include "citraces.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #define RET_ERR_IF_ERR(s) if(s!=KErrNone) return s sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Constructs and returns an application object. sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: MDevSoundCIClientExtension* CCIExtnClientPlugin::NewL() sl@0: { sl@0: DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::NewL")); sl@0: CCIExtnClientPlugin* self = new (ELeave)CCIExtnClientPlugin; sl@0: CleanupStack::PushL( self ); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop( self ); sl@0: MDevSoundCIClientExtension* ptr = static_cast(self); sl@0: return ptr; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Destructor sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: CCIExtnClientPlugin::~CCIExtnClientPlugin() sl@0: { sl@0: iMCIFactoryIntfcList.Close(); sl@0: DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::~CCIExtnClientPlugin")); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Called by framework when plugin is constructed sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CCIExtnClientPlugin::Setup( MCustomCommand& aCustomCommand ) sl@0: { sl@0: DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::Setup")); sl@0: TInt status(KErrNone); sl@0: iMCustomCommand = &aCustomCommand; sl@0: TRAP_IGNORE(InitializeFactoryPluginsL()); sl@0: return status; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Called by framework forwarding request to create a custom interface sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CCIExtnClientPlugin::CustomInterfaceExtension( TUid aUid, TAny*& aInterface ) sl@0: { sl@0: DEB_TRACE1(_L("*CI* CCIExtnClientPlugin::CustomInterfaceExtension 0x%x"), aUid.iUid); sl@0: sl@0: TInt status(KErrNotFound); sl@0: aInterface = NULL; sl@0: sl@0: // Forward request to each factory plugin in the list, sl@0: for ( TInt index = 0; index < iMCIFactoryIntfcList.Count(); index++ ) sl@0: { sl@0: status = iMCIFactoryIntfcList[index]->CreateInterface( aUid, aInterface ); sl@0: // The factory tried creating custom interface successfully or otherwise. sl@0: // stop forwarding the request to other factory plugins in the list. sl@0: // If the factory does not support a custom interface with aUid, it will sl@0: // return KErrNotFound sl@0: if ( status != KErrNotFound ) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: return status; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Called by framework when plugin is to be deleted sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: void CCIExtnClientPlugin::Release() sl@0: { sl@0: DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::Release")); sl@0: sl@0: for ( TInt index = 0; index < iMCIFactoryIntfcList.Count(); index++ ) sl@0: { sl@0: iMCIFactoryIntfcList[index]->Close(); sl@0: } sl@0: sl@0: iMCIFactoryIntfcList.Reset(); sl@0: iMCIFactoryIntfcList.Close(); sl@0: sl@0: REComSession::DestroyedImplementation(iDestructorKey); sl@0: sl@0: delete this; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Called by framework after plugin is created sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: void CCIExtnClientPlugin::PassDestructorKey( TUid aDestructorKey ) sl@0: { sl@0: iDestructorKey = aDestructorKey; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Constructor sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: CCIExtnClientPlugin::CCIExtnClientPlugin() sl@0: { sl@0: // No impl sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Second phase constructor. sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: void CCIExtnClientPlugin::ConstructL() sl@0: { sl@0: // No impl sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Initializes factory plugins list. sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: void CCIExtnClientPlugin::InitializeFactoryPluginsL() sl@0: { sl@0: // 1. Query the implementation ids of plugins implementing sl@0: // KUidCIFactoryIntfcInterface sl@0: // 2. Instantiate it and add it to the list of factories sl@0: sl@0: DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::InitializeFactoryPluginsL")); sl@0: sl@0: iMCIFactoryIntfcList.Reset(); sl@0: sl@0: RImplInfoPtrArray factoryEComUids; sl@0: CleanupResetAndDestroyPushL(factoryEComUids); sl@0: sl@0: // List all the factory plugins sl@0: TUid factoryPluginInterfaceUid = {KUidCIFactoryIntfcInterface}; sl@0: TEComResolverParams resParams; sl@0: REComSession::ListImplementationsL( factoryPluginInterfaceUid, resParams, sl@0: KRomOnlyResolverUid, factoryEComUids ); sl@0: sl@0: // Instantiate and add it to the list of factories sl@0: TUid destructorKey; sl@0: MCIFactoryIntfc* factoryPlugin(NULL); sl@0: TInt status(KErrNone); sl@0: for ( TInt index = 0; index < factoryEComUids.Count(); index++) sl@0: { sl@0: //<415-4087> TN: created with ImplementationUid - KRomOnlyResolverUid not used sl@0: TRAP( status , sl@0: factoryPlugin = static_cast sl@0: (REComSession::CreateImplementationL( sl@0: factoryEComUids[index]->ImplementationUid(), sl@0: destructorKey ) ) ); sl@0: // If there was problem instantiating factory plugin, continue trying sl@0: // next one. sl@0: if ( status != KErrNone) sl@0: { sl@0: DEB_TRACE1(_L("*CI* CCIExtnClientPlugin::InitializeFactoryPluginsL create failed status=%d"), status); sl@0: continue; sl@0: } sl@0: sl@0: // Initialize the factory plugin sl@0: if ( factoryPlugin->Initialize( *iMCustomCommand, destructorKey ) == KErrNone ) sl@0: { sl@0: status = iMCIFactoryIntfcList.Append(factoryPlugin); sl@0: if ( status != KErrNone ) sl@0: {// There was problem adding plugin to list, there was a system sl@0: // wide error. Stop trying and return error code. sl@0: factoryPlugin->Close(); sl@0: User::Leave( status ); sl@0: } sl@0: } sl@0: else sl@0: {// There was problem initializing the factory plugin instance, close sl@0: // it and continue instantiating the rest sl@0: factoryPlugin->Close(); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(&factoryEComUids); sl@0: }