1 | /* |
2 | Copyright (c) 2010 Bertjan Broeksema <broeksema@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "agentpluginloader.h" |
21 | |
22 | #include <QtCore/QDebug> |
23 | #include <QtCore/QStringList> |
24 | #include <QApplication> |
25 | |
26 | int main(int argc, char *argv[]) |
27 | { |
28 | QApplication app(argc, argv); |
29 | app.setQuitOnLastWindowClosed(false); |
30 | |
31 | if (app.arguments().size() != 3) { // Expected usage: ./agent_launcher ${plugin_name} ${identifier} |
32 | qDebug() << "Invalid usage: expected: ./agent_launcher pluginName agentIdentifier" ; |
33 | return 1; |
34 | } |
35 | |
36 | const QString agentPluginName = app.arguments().at(1); |
37 | const QString agentIdentifier = app.arguments().at(2); |
38 | |
39 | AgentPluginLoader loader; |
40 | QPluginLoader *factory = loader.load(agentPluginName); |
41 | if (factory == 0) { |
42 | return 1; |
43 | } |
44 | |
45 | QObject *instance = 0; |
46 | const bool invokeSucceeded = QMetaObject::invokeMethod(factory->instance(), |
47 | "createInstance" , |
48 | Qt::DirectConnection, |
49 | Q_RETURN_ARG(QObject *, instance), |
50 | Q_ARG(QString, agentIdentifier)); |
51 | if (invokeSucceeded) { |
52 | qDebug() << "Agent instance created in separate process." ; |
53 | } else { |
54 | qDebug() << "Agent instance creation in separate process failed" ; |
55 | return 2; |
56 | } |
57 | |
58 | const int rv = app.exec(); |
59 | delete instance; |
60 | return rv; |
61 | } |
62 | |