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 server sl@0: * side custom interface extension. sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: // Include files sl@0: #include "ciextnserverplugin.h" sl@0: #include "citraces.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Constructs and returns an application object. sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: MDevSoundCIServerExtension* CCIExtnServerPlugin::NewL() sl@0: { sl@0: DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::NewL")); sl@0: CCIExtnServerPlugin* self = new (ELeave)CCIExtnServerPlugin; sl@0: CleanupStack::PushL( self ); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop( self ); sl@0: MDevSoundCIServerExtension* ptr = static_cast(self); sl@0: return ptr; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Destructor sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: CCIExtnServerPlugin::~CCIExtnServerPlugin() sl@0: { sl@0: DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::~CCIExtnServerPlugin")); sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Called by framework when plugin is constructed sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CCIExtnServerPlugin::Setup( MCustomInterface& aInterface ) sl@0: { sl@0: DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::Setup")); sl@0: TInt status(KErrNone); sl@0: TRAPD(err, iCiExtnServerPluginWrapper = CIExtnServerPluginWrapper::NewL(aInterface)); sl@0: if (err == KErrNone) sl@0: { sl@0: iMCustomInterface = iCiExtnServerPluginWrapper->GetInterface(); sl@0: } sl@0: TRAP_IGNORE(InitializeMsgHndlrPluginsL()); sl@0: return status; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Called by framework forwarding passing aMessage to handle sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: TInt CCIExtnServerPlugin::HandleMessageL(const RMmfIpcMessage& aMessage) sl@0: { sl@0: DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::HandleMessageL")); sl@0: sl@0: TInt status(KErrNotSupported); sl@0: sl@0: // Forward request to each message handler plugin in the list, sl@0: TBool msgHandled(EFalse); sl@0: for ( TInt index = 0; index < iMCIMsgHndlrIntfcList.Count(); index++ ) sl@0: { sl@0: msgHandled = iMCIMsgHndlrIntfcList[index]->HandleMessage( aMessage ); sl@0: // If the plugin handled aMessage, stop forwarding the request to sl@0: // other plugins in the list and break out of loop. sl@0: if ( msgHandled == TBool(ETrue) ) sl@0: { sl@0: status = KErrNone; sl@0: break; sl@0: } 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 CCIExtnServerPlugin::Release() sl@0: { sl@0: DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::Release")); sl@0: sl@0: for ( TInt index = 0; index < iMCIMsgHndlrIntfcList.Count(); index++ ) sl@0: { sl@0: iMCIMsgHndlrIntfcList[index]->Close(); sl@0: } sl@0: sl@0: iMCIMsgHndlrIntfcList.Reset(); sl@0: iMCIMsgHndlrIntfcList.Close(); sl@0: sl@0: iCiExtnServerPluginWrapper->Release(); 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 CCIExtnServerPlugin::PassDestructorKey( TUid aDestructorKey ) sl@0: { sl@0: iDestructorKey = aDestructorKey; sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Constructor sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: CCIExtnServerPlugin::CCIExtnServerPlugin() sl@0: { sl@0: // No impl sl@0: } sl@0: sl@0: // --------------------------------------------------------------------------- sl@0: // Second phase constructor. sl@0: // --------------------------------------------------------------------------- sl@0: // sl@0: void CCIExtnServerPlugin::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 CCIExtnServerPlugin::InitializeMsgHndlrPluginsL() sl@0: { sl@0: // 1. Query the implementation ids of plugins implementing sl@0: // KUidCIMsgHndlrIntfcInterface sl@0: // 2. Instantiate it and add it to the list of plugins sl@0: DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::InitializeMsgHndlrPluginsL")); sl@0: sl@0: iMCIMsgHndlrIntfcList.Reset(); sl@0: sl@0: RImplInfoPtrArray msgHndlrEComUids; sl@0: CleanupResetAndDestroyPushL(msgHndlrEComUids); sl@0: sl@0: sl@0: // List all the factory plugins sl@0: TUid msgHndlrPluginInterfaceUid = {KUidCIMsgHndlrIntfcInterface}; sl@0: TEComResolverParams resParams; sl@0: REComSession::ListImplementationsL( msgHndlrPluginInterfaceUid, resParams, sl@0: KRomOnlyResolverUid, msgHndlrEComUids ); sl@0: sl@0: // Instantiate and add it to the list of factories sl@0: TUid destructorKey; sl@0: MCIMsgHndlrIntfc* msgHndlrPlugin(NULL); sl@0: TInt status(KErrNone); sl@0: sl@0: for ( TInt index = 0; index < msgHndlrEComUids.Count(); index++) sl@0: { sl@0: TRAP( status , sl@0: msgHndlrPlugin = static_cast sl@0: (REComSession::CreateImplementationL( sl@0: msgHndlrEComUids[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* CCIExtnServerPlugin::InitializeMsgHndlrPluginsL creation status=%d"),status); sl@0: continue; sl@0: } sl@0: sl@0: // Initialize the factory plugin sl@0: if ( msgHndlrPlugin->Initialize( *iMCustomInterface, destructorKey ) == KErrNone ) sl@0: { sl@0: status = iMCIMsgHndlrIntfcList.Append(msgHndlrPlugin); 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: msgHndlrPlugin->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: msgHndlrPlugin->Close(); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(&msgHndlrEComUids); sl@0: }