-
Notifications
You must be signed in to change notification settings - Fork 2
/
DBusBridge.h
67 lines (56 loc) · 2.33 KB
/
DBusBridge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Copyright (C) 2020 Pino Toscano
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Authors: Pino Toscano <[email protected]>
//
#pragma once
#include "DBusTypes.h"
#include "LibUsbguard.h"
#include <QDBusPendingReply>
#include <QDBusReply>
#include <QObject>
#include <QTimer>
class QDBusServiceWatcher;
class OrgUsbguardDevices1Interface;
class DBusBridge : public QObject
{
Q_OBJECT
public:
explicit DBusBridge(QObject* parent = nullptr);
~DBusBridge();
QDBusReply<bool> tryConnect();
bool isConnected() const;
QDBusPendingReply<DBusRules> listDevices(const QString& query);
QDBusPendingReply<uint> applyDevicePolicy(uint id, Rule::Target target, bool permanent);
Q_SIGNALS:
void serviceAvailable();
void serviceUnavailable();
void devicePolicyApplied(uint id, Rule::Target target_new, const QString& device_rule, uint rule_id);
void devicePolicyChanged(uint id, Rule::Target target_old, Rule::Target target_new, const QString& device_rule, uint rule_id);
void devicePresenceChanged(uint id, DeviceManager::EventType event, Rule::Target target, const QString& device_rule);
private Q_SLOTS:
void createInterfaces();
void destroyInterfaces();
void dbusServiceRegistered();
void dbusDevicePolicyApplied(uint id, uint target_new, const QString& device_rule, uint rule_id, DBusAttributes attributes);
void dbusDevicePolicyChanged(uint id, uint target_old, uint target_new, const QString& device_rule, uint rule_id, DBusAttributes attributes);
void dbusDevicePresenceChanged(uint id, uint event, uint target, const QString& device_rule, DBusAttributes attributes);
private:
QTimer _reconnect_timer;
QDBusServiceWatcher* _watcher;
OrgUsbguardDevices1Interface* _devices_interface;
static const QString service;
};