File indexing completed on 2024-05-05 05:34:19

0001 /*
0002  *  SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
0003  *  SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.1-or-later
0006  */
0007 
0008 #pragma once
0009 
0010 #include "kscreen_export.h"
0011 #include "types.h"
0012 
0013 #include <QObject>
0014 #include <QString>
0015 
0016 namespace KScreen
0017 {
0018 class Config;
0019 
0020 /**
0021  * Abstract class for backends.
0022  */
0023 class KSCREEN_EXPORT AbstractBackend : public QObject
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     ~AbstractBackend() override
0029     {
0030     }
0031 
0032     /**
0033      * This is where the backend should perform all initialization. This method
0034      * is always called right after the backend is created.
0035      *
0036      * Default implementation does nothing.
0037      *
0038      * @p arguments Optional arguments passed by caller. Used mostly for unit-testing.
0039      */
0040     virtual void init(const QVariantMap &arguments);
0041 
0042     /**
0043      * Returns a user-friendly name of the backend.
0044      */
0045     virtual QString name() const = 0;
0046 
0047     /**
0048      * Returns the name of the DBus service that should be used for this backend.
0049      *
0050      * Each backend must have an unique service name (usually something like
0051      * org.kde.KScreen.Backend.%backendName%) to allow multiple different backends
0052      * running concurrently.
0053      */
0054     virtual QString serviceName() const = 0;
0055 
0056     /**
0057      * Returns a new Config object, holding Screen, Output objects, etc.
0058      *
0059      * @return Config object for the system.
0060      */
0061     virtual KScreen::ConfigPtr config() const = 0;
0062 
0063     /**
0064      * Apply a config object to the system.
0065      *
0066      * @param config Configuration to apply
0067      */
0068     virtual void setConfig(const KScreen::ConfigPtr &config) = 0;
0069 
0070     /**
0071      * Returns whether the backend is in valid state.
0072      *
0073      * Backends should use this to tell BackendLauncher whether they are capable
0074      * of operating on the current platform.
0075      */
0076     virtual bool isValid() const = 0;
0077 
0078     /**
0079      * Returns encoded EDID data for given output
0080      *
0081      * Default implementation does nothing and returns null QByteArray. Backends
0082      * that don't support EDID don't have to reimplement this method.
0083      *
0084      * @param outputd ID of output to return EDID data for
0085      */
0086     virtual QByteArray edid(int outputId) const;
0087 
0088 Q_SIGNALS:
0089     /**
0090      * Emitted when backend detects a change in configuration
0091      *
0092      * It's OK to emit this signal for every single change. The emissions are aggregated
0093      * in the backend launcher, so that the backend does not spam DBus and client
0094      * applications.
0095      *
0096      * @param config New configuration
0097      */
0098     void configChanged(const KScreen::ConfigPtr &config);
0099 };
0100 
0101 } // namespace KScreen