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