183 lines
5.5 KiB
C++
183 lines
5.5 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2024 Linux Hello Authors
|
|
|
|
#ifndef LINUX_HELLO_DBUS_CLIENT_H
|
|
#define LINUX_HELLO_DBUS_CLIENT_H
|
|
|
|
#include <QObject>
|
|
#include <QDBusConnection>
|
|
#include <QDBusInterface>
|
|
#include <QDBusPendingCallWatcher>
|
|
#include <QDBusServiceWatcher>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <QVariantMap>
|
|
#include <memory>
|
|
|
|
/**
|
|
* @brief D-Bus client for communicating with the Linux Hello daemon
|
|
*
|
|
* This class provides a Qt-friendly interface to the org.linuxhello.Daemon
|
|
* D-Bus service for managing facial authentication.
|
|
*/
|
|
class LinuxHelloDBusClient : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
// System status properties
|
|
Q_PROPERTY(bool daemonRunning READ daemonRunning NOTIFY daemonRunningChanged)
|
|
Q_PROPERTY(bool cameraAvailable READ cameraAvailable NOTIFY cameraAvailableChanged)
|
|
Q_PROPERTY(bool tpmAvailable READ tpmAvailable NOTIFY tpmAvailableChanged)
|
|
Q_PROPERTY(bool antiSpoofingEnabled READ antiSpoofingEnabled NOTIFY antiSpoofingEnabledChanged)
|
|
Q_PROPERTY(QString daemonVersion READ daemonVersion NOTIFY daemonVersionChanged)
|
|
Q_PROPERTY(int enrolledCount READ enrolledCount NOTIFY enrolledCountChanged)
|
|
|
|
// Enrollment state
|
|
Q_PROPERTY(bool enrollmentInProgress READ enrollmentInProgress NOTIFY enrollmentInProgressChanged)
|
|
Q_PROPERTY(int enrollmentProgress READ enrollmentProgress NOTIFY enrollmentProgressChanged)
|
|
Q_PROPERTY(QString enrollmentMessage READ enrollmentMessage NOTIFY enrollmentMessageChanged)
|
|
|
|
// Templates
|
|
Q_PROPERTY(QStringList templates READ templates NOTIFY templatesChanged)
|
|
|
|
// Error state
|
|
Q_PROPERTY(QString lastError READ lastError NOTIFY errorOccurred)
|
|
|
|
public:
|
|
explicit LinuxHelloDBusClient(QObject *parent = nullptr);
|
|
~LinuxHelloDBusClient() override;
|
|
|
|
// Property getters
|
|
bool daemonRunning() const;
|
|
bool cameraAvailable() const;
|
|
bool tpmAvailable() const;
|
|
bool antiSpoofingEnabled() const;
|
|
QString daemonVersion() const;
|
|
int enrolledCount() const;
|
|
|
|
bool enrollmentInProgress() const;
|
|
int enrollmentProgress() const;
|
|
QString enrollmentMessage() const;
|
|
|
|
QStringList templates() const;
|
|
QString lastError() const;
|
|
|
|
public Q_SLOTS:
|
|
/**
|
|
* @brief Refresh the system status from the daemon
|
|
*/
|
|
void refreshStatus();
|
|
|
|
/**
|
|
* @brief Refresh the list of enrolled templates
|
|
*/
|
|
void refreshTemplates();
|
|
|
|
/**
|
|
* @brief Start enrollment for the current user
|
|
* @param label Human-readable label for the template
|
|
* @param frameCount Number of frames to capture (default: 5)
|
|
*/
|
|
void startEnrollment(const QString &label, int frameCount = 5);
|
|
|
|
/**
|
|
* @brief Cancel an ongoing enrollment
|
|
*/
|
|
void cancelEnrollment();
|
|
|
|
/**
|
|
* @brief Remove a template by label
|
|
* @param label The template label to remove
|
|
*/
|
|
void removeTemplate(const QString &label);
|
|
|
|
/**
|
|
* @brief Remove all templates for the current user
|
|
*/
|
|
void removeAllTemplates();
|
|
|
|
/**
|
|
* @brief Test authentication for the current user
|
|
*/
|
|
void testAuthentication();
|
|
|
|
/**
|
|
* @brief Set anti-spoofing enabled state
|
|
* @param enabled Whether anti-spoofing should be enabled
|
|
* @note This requires writing to the config file with root privileges
|
|
*/
|
|
void setAntiSpoofingEnabled(bool enabled);
|
|
|
|
/**
|
|
* @brief Set the matching threshold
|
|
* @param threshold The threshold value (0.0 - 1.0)
|
|
*/
|
|
void setMatchingThreshold(double threshold);
|
|
|
|
Q_SIGNALS:
|
|
// Property change signals
|
|
void daemonRunningChanged();
|
|
void cameraAvailableChanged();
|
|
void tpmAvailableChanged();
|
|
void antiSpoofingEnabledChanged();
|
|
void daemonVersionChanged();
|
|
void enrolledCountChanged();
|
|
|
|
void enrollmentInProgressChanged();
|
|
void enrollmentProgressChanged();
|
|
void enrollmentMessageChanged();
|
|
|
|
void templatesChanged();
|
|
|
|
// Action result signals
|
|
void enrollmentStarted();
|
|
void enrollmentCompleted(bool success, const QString &message);
|
|
void templateRemoved(const QString &label);
|
|
void authenticationTested(bool success, const QString &message);
|
|
void settingsUpdated();
|
|
|
|
// Error signal
|
|
void errorOccurred(const QString &error);
|
|
|
|
private Q_SLOTS:
|
|
void onServiceRegistered(const QString &serviceName);
|
|
void onServiceUnregistered(const QString &serviceName);
|
|
|
|
// D-Bus signal handlers
|
|
void onEnrollmentProgress(const QString &user, uint progress, const QString &message);
|
|
void onEnrollmentComplete(const QString &user, bool success, const QString &message);
|
|
void onDaemonError(const QString &code, const QString &message);
|
|
|
|
private:
|
|
void connectToService();
|
|
void disconnectFromService();
|
|
void setupSignalConnections();
|
|
QString getCurrentUser() const;
|
|
void setLastError(const QString &error);
|
|
|
|
// D-Bus interface
|
|
static constexpr const char* SERVICE_NAME = "org.linuxhello.Daemon";
|
|
static constexpr const char* OBJECT_PATH = "/org/linuxhello/Manager";
|
|
static constexpr const char* INTERFACE_NAME = "org.linuxhello.Manager";
|
|
|
|
std::unique_ptr<QDBusInterface> m_interface;
|
|
std::unique_ptr<QDBusServiceWatcher> m_serviceWatcher;
|
|
|
|
// Cached state
|
|
bool m_daemonRunning = false;
|
|
bool m_cameraAvailable = false;
|
|
bool m_tpmAvailable = false;
|
|
bool m_antiSpoofingEnabled = true;
|
|
QString m_daemonVersion;
|
|
int m_enrolledCount = 0;
|
|
|
|
bool m_enrollmentInProgress = false;
|
|
int m_enrollmentProgress = 0;
|
|
QString m_enrollmentMessage;
|
|
|
|
QStringList m_templates;
|
|
QString m_lastError;
|
|
};
|
|
|
|
#endif // LINUX_HELLO_DBUS_CLIENT_H
|