First public contribution.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "wspluginmanager.h"
17 #include "graphics/WSPLUGIN.H"
20 GLREF_D CDebugLogBase* wsDebugLog;
22 const TInt KPluginInterfaceId = 0x10285A29;
24 /**********************************************************************
26 **********************************************************************/
27 CWsPluginManager::CPluginInfo::CPluginInfo()
31 CWsPluginManager::CPluginInfo::~CPluginInfo()
36 /**********************************************************************
38 **********************************************************************/
39 CWsPluginManager* CWsPluginManager::NewL()
41 CWsPluginManager* self = new (ELeave) CWsPluginManager();
42 CleanupStack::PushL(self);
44 CleanupStack::Pop(self);
48 CWsPluginManager::CWsPluginManager() :
49 iSession(REComSession::OpenL())
53 CWsPluginManager::~CWsPluginManager()
55 iPlugins.ResetAndDestroy();
57 REComSession::FinalClose();
60 void CWsPluginManager::ConstructL()
62 _LIT(KPlugins,"PLUGINS");
65 TBool havePlugins=WsIniFile->FindVar(KPlugins,pluginString);
66 const TDesC * plugins;
67 _LIT(KDefaultPlugins, "FLICKERBUFFER DISPLAY");
69 plugins = &pluginString;
71 plugins = &KDefaultPlugins;
75 TPtrC ptr = lex.NextToken();
78 CWsPlugin * plugin = 0;
80 TRAPD(err, plugin = LoadPluginL(ptr));
87 _LIT(KLoadedPlugin,"Loaded plugin: ");
88 _LIT(KPluginName, " calling itself: ");
89 buf.Append(KLoadedPlugin);
91 buf.Append(KPluginName);
92 buf.Append(plugin->PluginName());
93 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,buf);
97 _LIT(KMissingPlugin,"Failed to load plugin (%d): ");
98 buf.Append(KMissingPlugin);
100 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,buf,err);
105 { //Additionally log to RDebug if error
106 _LIT(KMissingPlugin,"WServ: Failed to load plugin %S (error %d)");
107 RDebug::Print(KMissingPlugin,&ptr,err);
117 CWsPlugin * CWsPluginManager::LoadPluginL(const TDesC& aSection)
126 CWsPlugin * plugin = 0;
127 TBool hasId=WsIniFile->FindVar(aSection,KId,id);
128 TBool hasType=WsIniFile->FindVar(aSection,KType,type);
129 if ((!hasId) && (!hasType))
131 _LIT(KCscStage, "TCSC");
132 _LIT(KFlickerBufferStage, "FLICKERBUFFER");
133 _LIT(KDisplayStage, "DISPLAY");
134 if (!aSection.CompareF(KFlickerBufferStage))
139 else if (!aSection.CompareF(KDisplayStage))
144 else if (!aSection.CompareF(KCscStage))
155 TBool hasData = WsIniFile->FindVar(aSection,KData,data);
162 CPluginInfo* info = new (ELeave) CPluginInfo;
163 CleanupStack::PushL(info);
167 TUid uid = TUid::Uid(id);
168 plugin = reinterpret_cast<CWsPlugin*>(iSession.CreateImplementationL(uid, CWsPlugin::DtorIDKeyOffset(), dataPtr));
172 TEComResolverParams params;
174 buf8.CreateL(type.Length());
175 CleanupClosePushL(buf8);
177 params.SetDataType(buf8);
178 plugin = reinterpret_cast<CWsPlugin*>(iSession.CreateImplementationL(TUid::Uid(KPluginInterfaceId),CWsPlugin::DtorIDKeyOffset(),dataPtr,params));
179 CleanupStack::PopAndDestroy(&buf8);
182 User::LeaveIfNull(plugin);
183 info->iPlugin = plugin;
184 User::LeaveIfError(iPlugins.Append(info));
185 CleanupStack::Pop(info);
189 void CWsPluginManager::InitializePluginsL(MWsGraphicDrawerEnvironment& aEnvironment)
191 TInt nbPlugins=iPlugins.Count();
193 for (TInt k=0;k<nbPlugins;k++)
195 iPlugins[k]->iPlugin->ConstructL(aEnvironment,empty);
199 TAny * CWsPluginManager::ResolveObjectInterface(TUint aId)
201 if (aId == MWsPluginManager::EWsObjectInterfaceId)
202 return static_cast<MWsPluginManager*>(this);
206 TAny * CWsPluginManager::ResolvePluginInterface(TUint aId)
208 for (TInt p = 0; p < iPlugins.Count(); ++p)
210 TAny * interface = iPlugins[p]->iPlugin->ResolveObjectInterface(aId);