Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
NetworkDeviceModel.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServiceNetwork/phosphorservicenetwork_export.h>
7
10
11#include <QAbstractListModel>
12
13namespace PhosphorServiceNetwork {
14
19class PHOSPHORSERVICENETWORK_EXPORT NetworkDeviceModel : public QAbstractListModel
20{
21 Q_OBJECT
22 Q_DISABLE_COPY_MOVE(NetworkDeviceModel)
24 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
25
26public:
34 Q_ENUM(Roles)
35
36 explicit NetworkDeviceModel(QObject* parent = nullptr);
37 ~NetworkDeviceModel() override;
38
39 [[nodiscard]] NetworkHost* host() const;
41
42 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
43 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
44 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
45
46Q_SIGNALS:
49
50private Q_SLOTS:
51 void onDeviceAdded(PhosphorServiceNetwork::NetworkDevice* device);
52 void onDeviceRemoved(PhosphorServiceNetwork::NetworkDevice* device);
53 void onDeviceDataChanged(PhosphorServiceNetwork::NetworkDevice* device, const QList<int>& roles);
54
55private:
56 void connectDevice(NetworkDevice* device);
57
58 NetworkHost* m_host = nullptr;
59 // Row mirror of host-owned NetworkDevice pointers. rowCount and data
60 // index into this list, never the host's, so the transaction
61 // boundaries always straddle the actual mutation. The model does NOT
62 // own these objects and never deletes them.
63 //
64 // Mirror-safety invariant (relied on instead of a per-device
65 // destroyed watch): NetworkHost only ever destroys a device AFTER
66 // emitting deviceRemoved (see NetworkHost::Private::removeDevice,
67 // which removes the row via onDeviceRemoved before deleteLater), and
68 // on host teardown QObject::destroyed fires before the host's device
69 // children are deleted (so the host-destroyed lambda clears m_rows
70 // while every pointer is still valid). A device pointer can therefore
71 // never dangle in m_rows.
72 QList<NetworkDevice*> m_rows;
73};
74
75} // namespace PhosphorServiceNetwork
Roles
Definition NetworkDeviceModel.h:27
@ DeviceRole
Definition NetworkDeviceModel.h:28
@ ManagedRole
Definition NetworkDeviceModel.h:32
@ InterfaceNameRole
Definition NetworkDeviceModel.h:29
@ DeviceTypeRole
Definition NetworkDeviceModel.h:30
@ StateRole
Definition NetworkDeviceModel.h:31
QVariant data(const QModelIndex &index, int role) const override
QHash< int, QByteArray > roleNames() const override
NetworkDeviceModel(QObject *parent=nullptr)
int rowCount(const QModelIndex &parent={}) const override
One org.freedesktop.NetworkManager.Device object.
Definition NetworkDevice.h:23
Root of the NetworkManager surface.
Definition NetworkHost.h:30
Definition AccessPoint.h:13