os/mm/devsoundextensions/ciextnfactoryplugins/ciextnclientplugin/src/ciextnclientplugin.cpp
Update contrib.
2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Class definition of plugin implementing devsound client
15 * custom interface extension.
22 #include "ciextnclientplugin.h"
25 #include <cifactoryintfc.h>
26 #include <cifactoryintfc.hrh>
27 #include <mmf/common/mmfcontrollerpluginresolver.h>
29 #define RET_ERR_IF_ERR(s) if(s!=KErrNone) return s
31 // ---------------------------------------------------------------------------
32 // Constructs and returns an application object.
33 // ---------------------------------------------------------------------------
35 MDevSoundCIClientExtension* CCIExtnClientPlugin::NewL()
37 DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::NewL"));
38 CCIExtnClientPlugin* self = new (ELeave)CCIExtnClientPlugin;
39 CleanupStack::PushL( self );
41 CleanupStack::Pop( self );
42 MDevSoundCIClientExtension* ptr = static_cast<MDevSoundCIClientExtension*>(self);
46 // ---------------------------------------------------------------------------
48 // ---------------------------------------------------------------------------
50 CCIExtnClientPlugin::~CCIExtnClientPlugin()
52 iMCIFactoryIntfcList.Close();
53 DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::~CCIExtnClientPlugin"));
56 // ---------------------------------------------------------------------------
57 // Called by framework when plugin is constructed
58 // ---------------------------------------------------------------------------
60 TInt CCIExtnClientPlugin::Setup( MCustomCommand& aCustomCommand )
62 DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::Setup"));
63 TInt status(KErrNone);
64 iMCustomCommand = &aCustomCommand;
65 TRAP_IGNORE(InitializeFactoryPluginsL());
69 // ---------------------------------------------------------------------------
70 // Called by framework forwarding request to create a custom interface
71 // ---------------------------------------------------------------------------
73 TInt CCIExtnClientPlugin::CustomInterfaceExtension( TUid aUid, TAny*& aInterface )
75 DEB_TRACE1(_L("*CI* CCIExtnClientPlugin::CustomInterfaceExtension 0x%x"), aUid.iUid);
77 TInt status(KErrNotFound);
80 // Forward request to each factory plugin in the list,
81 for ( TInt index = 0; index < iMCIFactoryIntfcList.Count(); index++ )
83 status = iMCIFactoryIntfcList[index]->CreateInterface( aUid, aInterface );
84 // The factory tried creating custom interface successfully or otherwise.
85 // stop forwarding the request to other factory plugins in the list.
86 // If the factory does not support a custom interface with aUid, it will
87 // return KErrNotFound
88 if ( status != KErrNotFound )
96 // ---------------------------------------------------------------------------
97 // Called by framework when plugin is to be deleted
98 // ---------------------------------------------------------------------------
100 void CCIExtnClientPlugin::Release()
102 DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::Release"));
104 for ( TInt index = 0; index < iMCIFactoryIntfcList.Count(); index++ )
106 iMCIFactoryIntfcList[index]->Close();
109 iMCIFactoryIntfcList.Reset();
110 iMCIFactoryIntfcList.Close();
112 REComSession::DestroyedImplementation(iDestructorKey);
117 // ---------------------------------------------------------------------------
118 // Called by framework after plugin is created
119 // ---------------------------------------------------------------------------
121 void CCIExtnClientPlugin::PassDestructorKey( TUid aDestructorKey )
123 iDestructorKey = aDestructorKey;
126 // ---------------------------------------------------------------------------
128 // ---------------------------------------------------------------------------
130 CCIExtnClientPlugin::CCIExtnClientPlugin()
135 // ---------------------------------------------------------------------------
136 // Second phase constructor.
137 // ---------------------------------------------------------------------------
139 void CCIExtnClientPlugin::ConstructL()
144 // ---------------------------------------------------------------------------
145 // Initializes factory plugins list.
146 // ---------------------------------------------------------------------------
148 void CCIExtnClientPlugin::InitializeFactoryPluginsL()
150 // 1. Query the implementation ids of plugins implementing
151 // KUidCIFactoryIntfcInterface
152 // 2. Instantiate it and add it to the list of factories
154 DEB_TRACE0(_L("*CI* CCIExtnClientPlugin::InitializeFactoryPluginsL"));
156 iMCIFactoryIntfcList.Reset();
158 RImplInfoPtrArray factoryEComUids;
159 CleanupResetAndDestroyPushL(factoryEComUids);
161 // List all the factory plugins
162 TUid factoryPluginInterfaceUid = {KUidCIFactoryIntfcInterface};
163 TEComResolverParams resParams;
164 REComSession::ListImplementationsL( factoryPluginInterfaceUid, resParams,
165 KRomOnlyResolverUid, factoryEComUids );
167 // Instantiate and add it to the list of factories
169 MCIFactoryIntfc* factoryPlugin(NULL);
170 TInt status(KErrNone);
171 for ( TInt index = 0; index < factoryEComUids.Count(); index++)
173 //<415-4087> TN: created with ImplementationUid - KRomOnlyResolverUid not used
175 factoryPlugin = static_cast<MCIFactoryIntfc*>
176 (REComSession::CreateImplementationL(
177 factoryEComUids[index]->ImplementationUid(),
179 // If there was problem instantiating factory plugin, continue trying
181 if ( status != KErrNone)
183 DEB_TRACE1(_L("*CI* CCIExtnClientPlugin::InitializeFactoryPluginsL create failed status=%d"), status);
187 // Initialize the factory plugin
188 if ( factoryPlugin->Initialize( *iMCustomCommand, destructorKey ) == KErrNone )
190 status = iMCIFactoryIntfcList.Append(factoryPlugin);
191 if ( status != KErrNone )
192 {// There was problem adding plugin to list, there was a system
193 // wide error. Stop trying and return error code.
194 factoryPlugin->Close();
195 User::Leave( status );
199 {// There was problem initializing the factory plugin instance, close
200 // it and continue instantiating the rest
201 factoryPlugin->Close();
204 CleanupStack::PopAndDestroy(&factoryEComUids);