os/mm/devsoundextensions/ciextnfactoryplugins/ciextnserverplugin/src/ciextnserverplugin.cpp
First public contribution.
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 server
15 * side custom interface extension.
22 #include "ciextnserverplugin.h"
25 #include <mmf/common/mmfcontrollerpluginresolver.h>
26 #include <cimsghndlrintfc.h>
27 #include <cimsghndlrintfc.hrh>
30 // ---------------------------------------------------------------------------
31 // Constructs and returns an application object.
32 // ---------------------------------------------------------------------------
34 MDevSoundCIServerExtension* CCIExtnServerPlugin::NewL()
36 DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::NewL"));
37 CCIExtnServerPlugin* self = new (ELeave)CCIExtnServerPlugin;
38 CleanupStack::PushL( self );
40 CleanupStack::Pop( self );
41 MDevSoundCIServerExtension* ptr = static_cast<MDevSoundCIServerExtension*>(self);
45 // ---------------------------------------------------------------------------
47 // ---------------------------------------------------------------------------
49 CCIExtnServerPlugin::~CCIExtnServerPlugin()
51 DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::~CCIExtnServerPlugin"));
54 // ---------------------------------------------------------------------------
55 // Called by framework when plugin is constructed
56 // ---------------------------------------------------------------------------
58 TInt CCIExtnServerPlugin::Setup( MCustomInterface& aInterface )
60 DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::Setup"));
61 TInt status(KErrNone);
62 TRAPD(err, iCiExtnServerPluginWrapper = CIExtnServerPluginWrapper::NewL(aInterface));
65 iMCustomInterface = iCiExtnServerPluginWrapper->GetInterface();
67 TRAP_IGNORE(InitializeMsgHndlrPluginsL());
71 // ---------------------------------------------------------------------------
72 // Called by framework forwarding passing aMessage to handle
73 // ---------------------------------------------------------------------------
75 TInt CCIExtnServerPlugin::HandleMessageL(const RMmfIpcMessage& aMessage)
77 DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::HandleMessageL"));
79 TInt status(KErrNotSupported);
81 // Forward request to each message handler plugin in the list,
82 TBool msgHandled(EFalse);
83 for ( TInt index = 0; index < iMCIMsgHndlrIntfcList.Count(); index++ )
85 msgHandled = iMCIMsgHndlrIntfcList[index]->HandleMessage( aMessage );
86 // If the plugin handled aMessage, stop forwarding the request to
87 // other plugins in the list and break out of loop.
88 if ( msgHandled == TBool(ETrue) )
98 // ---------------------------------------------------------------------------
99 // Called by framework when plugin is to be deleted
100 // ---------------------------------------------------------------------------
102 void CCIExtnServerPlugin::Release()
104 DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::Release"));
106 for ( TInt index = 0; index < iMCIMsgHndlrIntfcList.Count(); index++ )
108 iMCIMsgHndlrIntfcList[index]->Close();
111 iMCIMsgHndlrIntfcList.Reset();
112 iMCIMsgHndlrIntfcList.Close();
114 iCiExtnServerPluginWrapper->Release();
116 REComSession::DestroyedImplementation(iDestructorKey);
121 // ---------------------------------------------------------------------------
122 // Called by framework after plugin is created
123 // ---------------------------------------------------------------------------
125 void CCIExtnServerPlugin::PassDestructorKey( TUid aDestructorKey )
127 iDestructorKey = aDestructorKey;
130 // ---------------------------------------------------------------------------
132 // ---------------------------------------------------------------------------
134 CCIExtnServerPlugin::CCIExtnServerPlugin()
139 // ---------------------------------------------------------------------------
140 // Second phase constructor.
141 // ---------------------------------------------------------------------------
143 void CCIExtnServerPlugin::ConstructL()
148 // ---------------------------------------------------------------------------
149 // Initializes factory plugins list.
150 // ---------------------------------------------------------------------------
152 void CCIExtnServerPlugin::InitializeMsgHndlrPluginsL()
154 // 1. Query the implementation ids of plugins implementing
155 // KUidCIMsgHndlrIntfcInterface
156 // 2. Instantiate it and add it to the list of plugins
157 DEB_TRACE0(_L("*CI* CCIExtnServerPlugin::InitializeMsgHndlrPluginsL"));
159 iMCIMsgHndlrIntfcList.Reset();
161 RImplInfoPtrArray msgHndlrEComUids;
162 CleanupResetAndDestroyPushL(msgHndlrEComUids);
165 // List all the factory plugins
166 TUid msgHndlrPluginInterfaceUid = {KUidCIMsgHndlrIntfcInterface};
167 TEComResolverParams resParams;
168 REComSession::ListImplementationsL( msgHndlrPluginInterfaceUid, resParams,
169 KRomOnlyResolverUid, msgHndlrEComUids );
171 // Instantiate and add it to the list of factories
173 MCIMsgHndlrIntfc* msgHndlrPlugin(NULL);
174 TInt status(KErrNone);
176 for ( TInt index = 0; index < msgHndlrEComUids.Count(); index++)
179 msgHndlrPlugin = static_cast<MCIMsgHndlrIntfc*>
180 (REComSession::CreateImplementationL(
181 msgHndlrEComUids[index]->ImplementationUid(),
183 // If there was problem instantiating factory plugin, continue trying
185 if ( status != KErrNone)
187 DEB_TRACE1(_L("*CI* CCIExtnServerPlugin::InitializeMsgHndlrPluginsL creation status=%d"),status);
191 // Initialize the factory plugin
192 if ( msgHndlrPlugin->Initialize( *iMCustomInterface, destructorKey ) == KErrNone )
194 status = iMCIMsgHndlrIntfcList.Append(msgHndlrPlugin);
195 if ( status != KErrNone )
196 {// There was problem adding plugin to list, there was a system
197 // wide error. Stop trying and return error code.
198 msgHndlrPlugin->Close();
199 User::Leave( status );
203 {// There was problem initializing the factory plugin instance, close
204 // it and continue instantiating the rest
205 msgHndlrPlugin->Close();
208 CleanupStack::PopAndDestroy(&msgHndlrEComUids);