85
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
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".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: HsRuntime factory.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "hsruntimefactory.h"
|
|
20 |
#include "hsruntimefactory_p.h"
|
|
21 |
#include "hsruntimeprovidermanifest.h"
|
|
22 |
#include "hstest_global.h"
|
|
23 |
|
|
24 |
#include <QStringList>
|
|
25 |
#include <QDir>
|
|
26 |
#include <QPluginLoader>
|
|
27 |
|
|
28 |
|
|
29 |
HsRuntimeFactoryPrivate::HsRuntimeFactoryPrivate(HsRuntimeFactory* aPublic)
|
|
30 |
: QObject(aPublic),
|
|
31 |
mQ(aPublic)
|
|
32 |
{
|
|
33 |
|
|
34 |
}
|
|
35 |
|
|
36 |
|
|
37 |
HsRuntimeFactoryPrivate::~HsRuntimeFactoryPrivate()
|
|
38 |
{
|
|
39 |
|
|
40 |
}
|
|
41 |
|
|
42 |
QList<HsRuntimeToken> HsRuntimeFactoryPrivate::runtimes()
|
|
43 |
{
|
|
44 |
QStringList pluginPaths;
|
|
45 |
|
|
46 |
//Check plugin dirs from root of different drives
|
|
47 |
QFileInfoList drives = QDir::drives();
|
|
48 |
for(int i=0; i < drives.count(); i++)
|
|
49 |
{
|
|
50 |
QFileInfo drive = drives.at(i);
|
|
51 |
QString driveLetter = drive.absolutePath();
|
|
52 |
QString path = driveLetter + mPluginManifestDirectory;
|
|
53 |
if(QDir(path).exists())
|
|
54 |
{
|
|
55 |
pluginPaths << path;
|
|
56 |
}
|
|
57 |
}
|
|
58 |
|
|
59 |
//Check plugin dir relative to current dir
|
|
60 |
if(QDir(mPluginManifestDirectory).exists() && !pluginPaths.contains(QDir(mPluginManifestDirectory).absolutePath()))
|
|
61 |
{
|
|
62 |
pluginPaths << mPluginManifestDirectory;
|
|
63 |
}
|
|
64 |
|
|
65 |
QList<HsRuntimeToken> runtimes;
|
|
66 |
|
|
67 |
for(int h=0; h < pluginPaths.count(); h++)
|
|
68 |
{
|
|
69 |
QString path = pluginPaths.at(h);
|
|
70 |
QDir dir(path);
|
|
71 |
QStringList filters("*.manifest");
|
|
72 |
|
|
73 |
for(int i=0; i < dir.entryList(filters, QDir::Files).count(); ++i)
|
|
74 |
{
|
|
75 |
QString fileName = dir.entryList(filters, QDir::Files).at(i);
|
|
76 |
|
|
77 |
HsRuntimeProviderManifest manifest;
|
|
78 |
manifest.loadFromXml(dir.absoluteFilePath(fileName));
|
|
79 |
|
|
80 |
if(manifest.loadOnQuery())
|
|
81 |
{
|
|
82 |
QList<HsRuntimeToken> tokens = manifest.runtimes();
|
|
83 |
for(int j=0; j < tokens.count(); ++j)
|
|
84 |
{
|
|
85 |
HsRuntimeToken token = tokens.at(j);
|
|
86 |
IHsRuntimeProvider* provider = loadProviderFromPlugin(token.mLibrary);
|
|
87 |
if(provider)
|
|
88 |
{
|
|
89 |
runtimes << provider->runtimes();
|
|
90 |
delete provider;
|
|
91 |
}
|
|
92 |
}
|
|
93 |
}
|
|
94 |
else
|
|
95 |
{
|
|
96 |
runtimes << manifest.runtimes();
|
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
return runtimes;
|
|
101 |
}
|
|
102 |
|
|
103 |
HsRuntime* HsRuntimeFactoryPrivate::createRuntime(const HsRuntimeToken& aToken)
|
|
104 |
{
|
|
105 |
IHsRuntimeProvider* provider = loadProviderFromPlugin(aToken.mLibrary);
|
|
106 |
if(!provider)
|
|
107 |
{
|
|
108 |
HSDEBUG("Runtime creation failed - No provider.")
|
|
109 |
return 0;
|
|
110 |
}
|
|
111 |
|
|
112 |
HsRuntime* runtime = provider->createRuntime(aToken);
|
|
113 |
delete provider;
|
|
114 |
if(!runtime)
|
|
115 |
{
|
|
116 |
HSDEBUG("Runtime creation failed.")
|
|
117 |
}
|
|
118 |
return runtime;
|
|
119 |
}
|
|
120 |
|
|
121 |
IHsRuntimeProvider* HsRuntimeFactoryPrivate::loadProviderFromPlugin(const QString& aPluginName)
|
|
122 |
{
|
|
123 |
QStringList pluginPaths;
|
|
124 |
|
|
125 |
//Check plugin dirs from root of different drives
|
|
126 |
QFileInfoList drives = QDir::drives();
|
|
127 |
for(int i=0; i < drives.count(); i++)
|
|
128 |
{
|
|
129 |
QFileInfo drive = drives.at(i);
|
|
130 |
QString driveLetter = drive.absolutePath();
|
|
131 |
QString path = driveLetter + mPluginDirectory;
|
|
132 |
if(QDir(path).exists())
|
|
133 |
{
|
|
134 |
pluginPaths << path;
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
|
|
139 |
//Check plugin dir relative to current dir
|
|
140 |
if(QDir(mPluginManifestDirectory).exists() && !pluginPaths.contains(QDir(mPluginDirectory).absolutePath()))
|
|
141 |
{
|
|
142 |
pluginPaths << mPluginDirectory;
|
|
143 |
}
|
|
144 |
|
|
145 |
IHsRuntimeProvider* provider = 0;
|
|
146 |
QPluginLoader loader;
|
|
147 |
QObject* plugin = 0;
|
|
148 |
|
|
149 |
for(int i=0; i < pluginPaths.count(); i++)
|
|
150 |
{
|
|
151 |
QString path = pluginPaths.at(i);
|
|
152 |
QString fileName = QDir(path).absoluteFilePath(aPluginName);
|
|
153 |
|
|
154 |
loader.setFileName(fileName);
|
|
155 |
plugin = loader.instance();
|
|
156 |
provider = qobject_cast<IHsRuntimeProvider*>(plugin);
|
|
157 |
if(provider)
|
|
158 |
{
|
|
159 |
return provider;
|
|
160 |
}
|
|
161 |
|
|
162 |
//Don't leak memory if provider not IHsRuntimeProvider
|
|
163 |
if(plugin)
|
|
164 |
{
|
|
165 |
HSDEBUG("Runtime provider load - !provider, deleting plugin.")
|
|
166 |
delete plugin;
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
HSDEBUG("Runtime provider load failed - Not found.")
|
|
171 |
return 0;
|
|
172 |
}
|
|
173 |
|
|
174 |
/*!
|
|
175 |
\class HsRuntimeFactory
|
|
176 |
\ingroup group_hsruntimemodel
|
|
177 |
\brief Finds and creates home screen runtimes.
|
|
178 |
|
|
179 |
HsRuntime factory finds home screen runtimes from HsRuntime provider
|
|
180 |
plugins. The search is done based on given plugin manifest
|
|
181 |
and plugin binary directories. Found runtimes are returned as
|
|
182 |
a list of HsRuntime tokens. HsRuntime factory creates an instance of
|
|
183 |
a HsRuntime base on a HsRuntime token that is given to it.
|
|
184 |
*/
|
|
185 |
|
|
186 |
/*!
|
|
187 |
Constructor.
|
|
188 |
|
|
189 |
\a aPluginManifestDirectory Directory that contains plugin manifests.
|
|
190 |
\a aPluginDirectory Directory that contains plugin binaries.
|
|
191 |
\a aParent Parent object.
|
|
192 |
*/
|
|
193 |
HsRuntimeFactory::HsRuntimeFactory(const QString& aPluginManifestDirectory,
|
|
194 |
const QString& aPluginDirectory,
|
|
195 |
QObject* aParent)
|
|
196 |
: QObject(aParent)
|
|
197 |
{
|
|
198 |
mD = new HsRuntimeFactoryPrivate(this);
|
|
199 |
mD->mPluginManifestDirectory = aPluginManifestDirectory;
|
|
200 |
mD->mPluginDirectory = aPluginDirectory;
|
|
201 |
}
|
|
202 |
|
|
203 |
/*!
|
|
204 |
Destructor.
|
|
205 |
*/
|
|
206 |
HsRuntimeFactory::~HsRuntimeFactory()
|
|
207 |
{
|
|
208 |
|
|
209 |
}
|
|
210 |
|
|
211 |
/*!
|
|
212 |
Returns found runtimes as a list of HsRuntime tokens.
|
|
213 |
*/
|
|
214 |
QList<HsRuntimeToken> HsRuntimeFactory::runtimes()
|
|
215 |
{
|
|
216 |
return mD->runtimes();
|
|
217 |
}
|
|
218 |
|
|
219 |
/*!
|
|
220 |
Creates and returns a HsRuntime based on the given token.
|
|
221 |
\a aToken Identifies the HsRuntime to be created.
|
|
222 |
|
|
223 |
Return The created HsRuntime.
|
|
224 |
*/
|
|
225 |
HsRuntime* HsRuntimeFactory::createRuntime(const HsRuntimeToken& aToken)
|
|
226 |
{
|
|
227 |
return mD->createRuntime(aToken);
|
|
228 |
}
|