File indexing completed on 2024-06-16 04:50:00

0001 /*
0002     SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "agentpluginloader.h"
0008 #include "akonadiagentserver_debug.h"
0009 
0010 #include <QApplication>
0011 #include <QPluginLoader>
0012 
0013 int main(int argc, char *argv[])
0014 {
0015     QApplication app(argc, argv);
0016     app.setQuitOnLastWindowClosed(false);
0017 
0018     if (app.arguments().size() != 3) { // Expected usage: ./agent_launcher ${plugin_name} ${identifier}
0019         qCDebug(AKONADIAGENTSERVER_LOG) << "Invalid usage: expected: ./agent_launcher pluginName agentIdentifier";
0020         return 1;
0021     }
0022 
0023     const QString agentPluginName = app.arguments().at(1);
0024     const QString agentIdentifier = app.arguments().at(2);
0025 
0026     AgentPluginLoader loader;
0027     QPluginLoader *factory = loader.load(agentPluginName);
0028     if (!factory) {
0029         return 1;
0030     }
0031 
0032     QObject *instance = nullptr;
0033     // clang-format off
0034     const bool invokeSucceeded = QMetaObject::invokeMethod(factory->instance(),
0035                                                            "createInstance",
0036                                                            Qt::DirectConnection,
0037                                                            Q_RETURN_ARG(QObject *, instance),
0038                                                            Q_ARG(QString, agentIdentifier));
0039     // clang-format on
0040     if (invokeSucceeded) {
0041         qCDebug(AKONADIAGENTSERVER_LOG) << "Agent instance created in separate process.";
0042     } else {
0043         qCDebug(AKONADIAGENTSERVER_LOG) << "Agent instance creation in separate process failed";
0044         return 2;
0045     }
0046 
0047     const int rv = app.exec();
0048     delete instance;
0049     return rv;
0050 }