File indexing completed on 2024-04-28 11:44:24

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2003 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #ifndef KDBUSSERVICESTARTER_H
0009 #define KDBUSSERVICESTARTER_H
0010 
0011 #include <kservice_export.h>
0012 
0013 #include <QString>
0014 
0015 class KDBusServiceStarterPrivate;
0016 
0017 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 61)
0018 /**
0019  * @class KDBusServiceStarter kdbusservicestarter.h <KDBusServiceStarter>
0020  *
0021  * A generic D-Bus service starter, using KServiceTypeTrader.
0022  * The default implementation starts new processes, but this interface can
0023  * also be reimplemented by specific applications to provide dlopened in-process D-Bus objects.
0024  * This interface is similar to the startService() function found in QDBusConnectionInterface, but
0025  * with the added benefit of using KServiceTypeTrader (and, therefore, additional constraints and the
0026  * ability to search the standard KDE dirs).
0027  * @author David Faure <faure@kde.org>
0028  *
0029  * @deprecated since 5.61, use D-Bus activation instead
0030  */
0031 class KSERVICE_EXPORT KDBusServiceStarter // krazy:exclude=dpointer (uses Q_GLOBAL_STATIC)
0032 {
0033 public:
0034     KSERVICE_DEPRECATED_VERSION(5, 61, "Use D-Bus activation")
0035     static KDBusServiceStarter *self();
0036 
0037     /**
0038      * Check if a given D-Bus service is available - from the serviceType it's supposed to implement.
0039      *
0040      * The trader is queried to find the preferred application for this serviceType,
0041      * with the constraint that its X-DBus-ServiceName property must be defined.
0042      * Then the D-Bus server is checked. If the service is not available,
0043      * this method will call startServiceFor to start it.
0044      *
0045      * @param serviceType the type of service we're looking for
0046      * @param constraint see KServiceTypeTrader
0047      * @param error On failure, @p error contains a description of the error
0048      *         that occurred. If the pointer is 0, the argument will be
0049      *         ignored
0050      * @param dbusService On success, @p dbusService contains the D-Bus service name
0051      *         under which this service is available. If the pointer is 0 the argument
0052      *         will be ignored
0053      * @param flags for future extensions (currently unused)
0054      *
0055      * @return an error code indicating success (== 0) or failure (> 0).
0056      */
0057     int
0058     findServiceFor(const QString &serviceType, const QString &constraint = QString(), QString *error = nullptr, QString *dbusService = nullptr, int flags = 0);
0059 
0060     /**
0061      * Find an implementation of the given @p serviceType,
0062      * and start it, to use its D-Bus interface.
0063      * The default implementation uses KServiceTypeTrader to find the preferred Application,
0064      * and then starts it using KToolInvocation::startService...
0065      *
0066      * However applications (like kontact) can reimplement this method, to provide
0067      * an in-process way of loading the implementation for this service type.
0068      *
0069      * @param serviceType the type of service we're looking for
0070      * @param constraint see KServiceTypeTrader
0071      * @param error On failure, @p error contains a description of the error
0072      *         that occurred. If the pointer is 0, the argument will be
0073      *         ignored
0074      * @param dbusService On success, @p dbusService contains the D-Bus service name
0075      *         under which this service is available. If the pointer is 0 the argument
0076      *         will be ignored
0077      * @param flags for future extensions (currently unused)
0078      *
0079      * @return an error code indicating success (== 0) or failure (> 0).
0080      */
0081     virtual int
0082     startServiceFor(const QString &serviceType, const QString &constraint = QString(), QString *error = nullptr, QString *dbusService = nullptr, int flags = 0);
0083 
0084 protected:
0085     friend class KDBusServiceStarterPrivate;
0086     KDBusServiceStarter();
0087     virtual ~KDBusServiceStarter();
0088 };
0089 #endif
0090 
0091 #endif