sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "wspluginmanager.h"
|
sl@0
|
17 |
#include "graphics/WSPLUGIN.H"
|
sl@0
|
18 |
#include "inifile.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
GLREF_D CDebugLogBase* wsDebugLog;
|
sl@0
|
21 |
|
sl@0
|
22 |
const TInt KPluginInterfaceId = 0x10285A29;
|
sl@0
|
23 |
|
sl@0
|
24 |
/**********************************************************************
|
sl@0
|
25 |
Plugin Info
|
sl@0
|
26 |
**********************************************************************/
|
sl@0
|
27 |
CWsPluginManager::CPluginInfo::CPluginInfo()
|
sl@0
|
28 |
{
|
sl@0
|
29 |
}
|
sl@0
|
30 |
|
sl@0
|
31 |
CWsPluginManager::CPluginInfo::~CPluginInfo()
|
sl@0
|
32 |
{
|
sl@0
|
33 |
delete iPlugin;
|
sl@0
|
34 |
}
|
sl@0
|
35 |
|
sl@0
|
36 |
/**********************************************************************
|
sl@0
|
37 |
Plugin Manager
|
sl@0
|
38 |
**********************************************************************/
|
sl@0
|
39 |
CWsPluginManager* CWsPluginManager::NewL()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
CWsPluginManager* self = new (ELeave) CWsPluginManager();
|
sl@0
|
42 |
CleanupStack::PushL(self);
|
sl@0
|
43 |
self->ConstructL();
|
sl@0
|
44 |
CleanupStack::Pop(self);
|
sl@0
|
45 |
return self;
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
CWsPluginManager::CWsPluginManager() :
|
sl@0
|
49 |
iSession(REComSession::OpenL())
|
sl@0
|
50 |
{
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
CWsPluginManager::~CWsPluginManager()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
iPlugins.ResetAndDestroy();
|
sl@0
|
56 |
iSession.Close();
|
sl@0
|
57 |
REComSession::FinalClose();
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
void CWsPluginManager::ConstructL()
|
sl@0
|
61 |
{
|
sl@0
|
62 |
_LIT(KPlugins,"PLUGINS");
|
sl@0
|
63 |
|
sl@0
|
64 |
TPtrC pluginString;
|
sl@0
|
65 |
TBool havePlugins=WsIniFile->FindVar(KPlugins,pluginString);
|
sl@0
|
66 |
const TDesC * plugins;
|
sl@0
|
67 |
_LIT(KDefaultPlugins, "FLICKERBUFFER DISPLAY");
|
sl@0
|
68 |
if (havePlugins)
|
sl@0
|
69 |
plugins = &pluginString;
|
sl@0
|
70 |
else
|
sl@0
|
71 |
plugins = &KDefaultPlugins;
|
sl@0
|
72 |
TLex lex(*plugins);
|
sl@0
|
73 |
while(true)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
TPtrC ptr = lex.NextToken();
|
sl@0
|
76 |
if (ptr.Length() > 0)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
CWsPlugin * plugin = 0;
|
sl@0
|
79 |
|
sl@0
|
80 |
TRAPD(err, plugin = LoadPluginL(ptr));
|
sl@0
|
81 |
|
sl@0
|
82 |
if (wsDebugLog)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
TBuf<80> buf;
|
sl@0
|
85 |
if (err == KErrNone)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
_LIT(KLoadedPlugin,"Loaded plugin: ");
|
sl@0
|
88 |
_LIT(KPluginName, " calling itself: ");
|
sl@0
|
89 |
buf.Append(KLoadedPlugin);
|
sl@0
|
90 |
buf.Append(ptr);
|
sl@0
|
91 |
buf.Append(KPluginName);
|
sl@0
|
92 |
buf.Append(plugin->PluginName());
|
sl@0
|
93 |
wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,buf);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
else
|
sl@0
|
96 |
{
|
sl@0
|
97 |
_LIT(KMissingPlugin,"Failed to load plugin (%d): ");
|
sl@0
|
98 |
buf.Append(KMissingPlugin);
|
sl@0
|
99 |
buf.Append(ptr);
|
sl@0
|
100 |
wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,buf,err);
|
sl@0
|
101 |
}
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
if (err<KErrNone)
|
sl@0
|
105 |
{ //Additionally log to RDebug if error
|
sl@0
|
106 |
_LIT(KMissingPlugin,"WServ: Failed to load plugin %S (error %d)");
|
sl@0
|
107 |
RDebug::Print(KMissingPlugin,&ptr,err);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
}
|
sl@0
|
110 |
else
|
sl@0
|
111 |
{
|
sl@0
|
112 |
break;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
}
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
CWsPlugin * CWsPluginManager::LoadPluginL(const TDesC& aSection)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
_LIT(KId, "ID");
|
sl@0
|
120 |
_LIT(KData, "DATA");
|
sl@0
|
121 |
_LIT(KType, "TYPE");
|
sl@0
|
122 |
TInt id;
|
sl@0
|
123 |
TPtrC data;
|
sl@0
|
124 |
TPtrC type;
|
sl@0
|
125 |
TAny * dataPtr;
|
sl@0
|
126 |
CWsPlugin * plugin = 0;
|
sl@0
|
127 |
TBool hasId=WsIniFile->FindVar(aSection,KId,id);
|
sl@0
|
128 |
TBool hasType=WsIniFile->FindVar(aSection,KType,type);
|
sl@0
|
129 |
if ((!hasId) && (!hasType))
|
sl@0
|
130 |
{
|
sl@0
|
131 |
_LIT(KCscStage, "TCSC");
|
sl@0
|
132 |
_LIT(KFlickerBufferStage, "FLICKERBUFFER");
|
sl@0
|
133 |
_LIT(KDisplayStage, "DISPLAY");
|
sl@0
|
134 |
if (!aSection.CompareF(KFlickerBufferStage))
|
sl@0
|
135 |
{
|
sl@0
|
136 |
hasId = ETrue;
|
sl@0
|
137 |
id = 0x1028637B;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
else if (!aSection.CompareF(KDisplayStage))
|
sl@0
|
140 |
{
|
sl@0
|
141 |
hasId = ETrue;
|
sl@0
|
142 |
id = 0x1028637A;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
else if (!aSection.CompareF(KCscStage))
|
sl@0
|
145 |
{
|
sl@0
|
146 |
hasId = ETrue;
|
sl@0
|
147 |
id = 0x10286507;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
else
|
sl@0
|
150 |
{
|
sl@0
|
151 |
hasType = ETrue;
|
sl@0
|
152 |
type.Set(aSection);
|
sl@0
|
153 |
}
|
sl@0
|
154 |
}
|
sl@0
|
155 |
TBool hasData = WsIniFile->FindVar(aSection,KData,data);
|
sl@0
|
156 |
|
sl@0
|
157 |
if (hasData)
|
sl@0
|
158 |
dataPtr = &data;
|
sl@0
|
159 |
else
|
sl@0
|
160 |
dataPtr = NULL;
|
sl@0
|
161 |
|
sl@0
|
162 |
CPluginInfo* info = new (ELeave) CPluginInfo;
|
sl@0
|
163 |
CleanupStack::PushL(info);
|
sl@0
|
164 |
|
sl@0
|
165 |
if (hasId)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
TUid uid = TUid::Uid(id);
|
sl@0
|
168 |
plugin = reinterpret_cast<CWsPlugin*>(iSession.CreateImplementationL(uid, CWsPlugin::DtorIDKeyOffset(), dataPtr));
|
sl@0
|
169 |
}
|
sl@0
|
170 |
else
|
sl@0
|
171 |
{
|
sl@0
|
172 |
TEComResolverParams params;
|
sl@0
|
173 |
RBuf8 buf8;
|
sl@0
|
174 |
buf8.CreateL(type.Length());
|
sl@0
|
175 |
CleanupClosePushL(buf8);
|
sl@0
|
176 |
buf8.Copy(type);
|
sl@0
|
177 |
params.SetDataType(buf8);
|
sl@0
|
178 |
plugin = reinterpret_cast<CWsPlugin*>(iSession.CreateImplementationL(TUid::Uid(KPluginInterfaceId),CWsPlugin::DtorIDKeyOffset(),dataPtr,params));
|
sl@0
|
179 |
CleanupStack::PopAndDestroy(&buf8);
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
User::LeaveIfNull(plugin);
|
sl@0
|
183 |
info->iPlugin = plugin;
|
sl@0
|
184 |
User::LeaveIfError(iPlugins.Append(info));
|
sl@0
|
185 |
CleanupStack::Pop(info);
|
sl@0
|
186 |
return plugin;
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
void CWsPluginManager::InitializePluginsL(MWsGraphicDrawerEnvironment& aEnvironment)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
TInt nbPlugins=iPlugins.Count();
|
sl@0
|
192 |
RBuf8 empty;
|
sl@0
|
193 |
for (TInt k=0;k<nbPlugins;k++)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
iPlugins[k]->iPlugin->ConstructL(aEnvironment,empty);
|
sl@0
|
196 |
}
|
sl@0
|
197 |
}
|
sl@0
|
198 |
|
sl@0
|
199 |
TAny * CWsPluginManager::ResolveObjectInterface(TUint aId)
|
sl@0
|
200 |
{
|
sl@0
|
201 |
if (aId == MWsPluginManager::EWsObjectInterfaceId)
|
sl@0
|
202 |
return static_cast<MWsPluginManager*>(this);
|
sl@0
|
203 |
return NULL;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
TAny * CWsPluginManager::ResolvePluginInterface(TUint aId)
|
sl@0
|
207 |
{
|
sl@0
|
208 |
for (TInt p = 0; p < iPlugins.Count(); ++p)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
TAny * interface = iPlugins[p]->iPlugin->ResolveObjectInterface(aId);
|
sl@0
|
211 |
if (interface)
|
sl@0
|
212 |
return interface;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
return NULL;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|