mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
solid: devinfo and geom backends
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
c35e7f76f3
commit
4967b54e6f
29 changed files with 1995 additions and 0 deletions
|
@ -224,6 +224,22 @@ set_package_properties(UDev PROPERTIES
|
|||
TYPE OPTIONAL
|
||||
)
|
||||
|
||||
macro_optional_find_package(Devinfo)
|
||||
set_package_properties(Devinfo PROPERTIES
|
||||
DESCRIPTION "Devinfo support for Solid"
|
||||
URL "https://www.freebsd.org/cgi/man.cgi?query=devinfo&sektion=3"
|
||||
PURPOSE "Allows Solid to use Devinfo to provide information about devices on FreeBSD"
|
||||
TYPE OPTIONAL
|
||||
)
|
||||
|
||||
macro_optional_find_package(Geom)
|
||||
set_package_properties(Geom PROPERTIES
|
||||
DESCRIPTION "Geom support for Solid"
|
||||
URL "https://www.freebsd.org/cgi/man.cgi?query=gctl_free"
|
||||
PURPOSE "Allows Solid to use Geom to provide information about devices on FreeBSD"
|
||||
TYPE OPTIONAL
|
||||
)
|
||||
|
||||
macro_optional_find_package(LibCDIO)
|
||||
set_package_properties(LibCDIO PROPERTIES
|
||||
DESCRIPTION "GNU Compact Disc Input and Control Library"
|
||||
|
|
|
@ -15,6 +15,8 @@ set(cmakeFilesDontInstall
|
|||
FindENCHANT.cmake
|
||||
FindACL.cmake
|
||||
FindLibCDIO.cmake
|
||||
FindDevinfo.cmake
|
||||
FindGeom.cmake
|
||||
)
|
||||
|
||||
# Explicitly list all files which will be installed.
|
||||
|
|
27
cmake/modules/FindDevinfo.cmake
Normal file
27
cmake/modules/FindDevinfo.cmake
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Try to find devinfo, once done this will define:
|
||||
#
|
||||
# DEVINFO_FOUND - system has devinfo
|
||||
# DEVINFO_INCLUDES - the devinfo include directory
|
||||
# DEVINFO_LIBRARIES - the libraries needed to use devinfo
|
||||
#
|
||||
# Copyright (c) 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
find_path(DEVINFO_INCLUDES
|
||||
NAMES devinfo.h
|
||||
HINTS $ENV{DEVINFODIR}/include
|
||||
)
|
||||
|
||||
find_library(DEVINFO_LIBRARIES
|
||||
NAMES devinfo
|
||||
HINTS $ENV{DEVINFODIR}/lib
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Devinfo
|
||||
REQUIRED_VARS DEVINFO_LIBRARIES DEVINFO_INCLUDES
|
||||
)
|
||||
|
||||
mark_as_advanced(DEVINFO_INCLUDES DEVINFO_LIBRARIES)
|
27
cmake/modules/FindGeom.cmake
Normal file
27
cmake/modules/FindGeom.cmake
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Try to find geom, once done this will define:
|
||||
#
|
||||
# GEOM_FOUND - system has geom
|
||||
# GEOM_INCLUDES - the geom include directory
|
||||
# GEOM_LIBRARIES - the libraries needed to use geom
|
||||
#
|
||||
# Copyright (c) 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
find_path(GEOM_INCLUDES
|
||||
NAMES libgeom.h
|
||||
HINTS $ENV{GEOMDIR}/include
|
||||
)
|
||||
|
||||
find_library(GEOM_LIBRARIES
|
||||
NAMES geom
|
||||
HINTS $ENV{GEOMDIR}/lib
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Geom
|
||||
REQUIRED_VARS GEOM_LIBRARIES GEOM_INCLUDES
|
||||
)
|
||||
|
||||
mark_as_advanced(GEOM_INCLUDES GEOM_LIBRARIES)
|
|
@ -184,6 +184,35 @@ if(UDEV_FOUND)
|
|||
set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} ${KDE4_KDECORE_LIBS} ${UDEV_LIBRARIES})
|
||||
endif(UDEV_FOUND)
|
||||
|
||||
if(DEVINFO_FOUND)
|
||||
include_directories(${DEVINFO_INCLUDES})
|
||||
message(STATUS "Building Solid Devinfo backend.")
|
||||
set(solid_LIB_SRCS ${solid_LIB_SRCS}
|
||||
backends/devinfo/devinfodevice.cpp
|
||||
backends/devinfo/devinfomanager.cpp
|
||||
backends/devinfo/devinfodeviceinterface.cpp
|
||||
backends/devinfo/devinfoprocessor.cpp
|
||||
backends/devinfo/devinfonetworkinterface.cpp
|
||||
)
|
||||
|
||||
set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} ${DEVINFO_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(GEOM_FOUND)
|
||||
include_directories(${GEOM_INCLUDES})
|
||||
message(STATUS "Building Solid Geom backend.")
|
||||
set(solid_LIB_SRCS ${solid_LIB_SRCS}
|
||||
backends/geom/geomdevice.cpp
|
||||
backends/geom/geommanager.cpp
|
||||
backends/geom/geomdeviceinterface.cpp
|
||||
backends/geom/geomblock.cpp
|
||||
backends/geom/geomstoragedrive.cpp
|
||||
backends/geom/geomstoragevolume.cpp
|
||||
)
|
||||
|
||||
set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} ${GEOM_LIBRARIES})
|
||||
endif()
|
||||
|
||||
set_source_files_properties(
|
||||
org.freedesktop.PowerManagement.xml
|
||||
org.freedesktop.PowerManagement.Inhibit.xml
|
||||
|
|
270
solid/solid/backends/devinfo/devinfodevice.cpp
Normal file
270
solid/solid/backends/devinfo/devinfodevice.cpp
Normal file
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "devinfomanager.h"
|
||||
#include "devinfodevice.h"
|
||||
#include "devinfoprocessor.h"
|
||||
#include "devinfonetworkinterface.h"
|
||||
#include "../shared/pciidstables.h"
|
||||
#include "../shared/usbidstables.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <devinfo.h>
|
||||
|
||||
using namespace Solid::Backends::Devinfo;
|
||||
|
||||
typedef QMap<DevinfoDevice::DeviceProperty, QByteArray> DevicePropertiesType;
|
||||
typedef QPair<QByteArray, DevicePropertiesType> DeviceArgumentType;
|
||||
|
||||
int getDeviceProperties(struct devinfo_dev *dev, void *arg)
|
||||
{
|
||||
DeviceArgumentType* typedarg = reinterpret_cast<DeviceArgumentType*>(arg);
|
||||
const QByteArray devname(dev->dd_name);
|
||||
if (!devname.isEmpty() && devname == typedarg->first) {
|
||||
DevicePropertiesType properties;
|
||||
properties[DevinfoDevice::DeviceName] = devname;
|
||||
struct devinfo_dev *parentdev = devinfo_handle_to_device(dev->dd_parent);
|
||||
if (parentdev) {
|
||||
properties[DevinfoDevice::DeviceParent] = parentdev->dd_name;
|
||||
}
|
||||
properties[DevinfoDevice::DeviceDescription] = dev->dd_desc;
|
||||
properties[DevinfoDevice::DeviceDriver] = dev->dd_drivername;
|
||||
properties[DevinfoDevice::DevicePnPInfo] = dev->dd_pnpinfo;
|
||||
typedarg->second = properties;
|
||||
// device found, abort scan
|
||||
return -1;
|
||||
}
|
||||
return devinfo_foreach_device_child(dev, getDeviceProperties, arg);
|
||||
}
|
||||
|
||||
static QByteArray getPnPInfo(const QByteArray &pnpinfo, const char* field)
|
||||
{
|
||||
foreach (const QByteArray &subinfo, pnpinfo.split(' ')) {
|
||||
if (subinfo.startsWith(field)) {
|
||||
return subinfo.right(subinfo.size() - qstrlen(field) - 1);
|
||||
}
|
||||
}
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
DevinfoDevice::DevinfoDevice(const QString &device)
|
||||
: Solid::Ifaces::Device()
|
||||
, m_device(device)
|
||||
{
|
||||
if (devinfo_init() != 0) {
|
||||
qWarning() << "could not initialize devinfo";
|
||||
return;
|
||||
}
|
||||
|
||||
const QByteArray devicename = m_device.right(m_device.size() - qstrlen(DEVINFO_UDI_PREFIX) - 1).toLatin1();
|
||||
DeviceArgumentType* getDeviceArg = new DeviceArgumentType(devicename, m_properties);
|
||||
|
||||
struct devinfo_dev *root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE);
|
||||
if (root) {
|
||||
devinfo_foreach_device_child(root, getDeviceProperties, getDeviceArg);
|
||||
} else {
|
||||
qWarning() << "no root device";
|
||||
return;
|
||||
}
|
||||
m_properties = getDeviceArg->second;
|
||||
delete getDeviceArg;
|
||||
|
||||
const QByteArray pnpinfo = m_properties[DevinfoDevice::DevicePnPInfo];
|
||||
m_pnpinfo[DevinfoDevice::PnPVendor] = getPnPInfo(pnpinfo, "vendor");
|
||||
m_pnpinfo[DevinfoDevice::PnPDevice] = getPnPInfo(pnpinfo, "device");
|
||||
m_pnpinfo[DevinfoDevice::PnPSubVendor] = getPnPInfo(pnpinfo, "subvendor");
|
||||
m_pnpinfo[DevinfoDevice::PnPSubDevice] = getPnPInfo(pnpinfo, "subdevice");
|
||||
m_pnpinfo[DevinfoDevice::PnPClass] = getPnPInfo(pnpinfo, "class");
|
||||
|
||||
devinfo_free();
|
||||
}
|
||||
|
||||
DevinfoDevice::~DevinfoDevice()
|
||||
{
|
||||
}
|
||||
|
||||
QString DevinfoDevice::udi() const
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
QString DevinfoDevice::parentUdi() const
|
||||
{
|
||||
if (m_device == DEVINFO_ROOT_UDI) {
|
||||
// root0
|
||||
return QString();
|
||||
}
|
||||
const QByteArray parent = deviceProperty(DevinfoDevice::DeviceParent);
|
||||
if (parent.isEmpty()) {
|
||||
return QString(DEVINFO_ROOT_UDI);
|
||||
}
|
||||
return QString::fromLatin1("%1/%2").arg(DEVINFO_UDI_PREFIX, parent.constData());
|
||||
}
|
||||
|
||||
QString DevinfoDevice::vendor() const
|
||||
{
|
||||
// TODO: lookup either PCI or USB table depending on bus type
|
||||
const QByteArray pnpvendor = devicePnP(DevinfoDevice::PnPVendor);
|
||||
for (size_t i = 0; i < pciVendorTblSize; i++) {
|
||||
if (pnpvendor == pciVendorTbl[i].vendorid) {
|
||||
return QString::fromLatin1(pciVendorTbl[i].vendorname);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < usbVendorTblSize; i++) {
|
||||
if (pnpvendor == usbVendorTbl[i].vendorid) {
|
||||
return QString::fromLatin1(usbVendorTbl[i].vendorname);
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString DevinfoDevice::product() const
|
||||
{
|
||||
if (m_device == DEVINFO_ROOT_UDI) {
|
||||
return QLatin1String("Devices");
|
||||
} else if(queryDeviceInterface(Solid::DeviceInterface::NetworkInterface)) {
|
||||
const NetworkInterface netIface(const_cast<DevinfoDevice *>(this));
|
||||
if (netIface.isLoopback()) {
|
||||
return QLatin1String("Loopback device Interface");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: lookup either PCI or USB table depending on bus type
|
||||
const QByteArray pnpdevice = devicePnP(DevinfoDevice::PnPDevice);
|
||||
for (size_t i = 0; i < pciDeviceTblSize; i++) {
|
||||
if (pnpdevice == pciDeviceTbl[i].deviceid) {
|
||||
return QString::fromLatin1(pciDeviceTbl[i].devicename);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < usbDeviceTblSize; i++) {
|
||||
if (pnpdevice == usbDeviceTbl[i].deviceid) {
|
||||
return QString::fromLatin1(usbDeviceTbl[i].devicename);
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString DevinfoDevice::icon() const
|
||||
{
|
||||
if (m_device == DEVINFO_ROOT_UDI) {
|
||||
return QString("computer");
|
||||
} else if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
|
||||
return QLatin1String("cpu");
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QStringList DevinfoDevice::emblems() const
|
||||
{
|
||||
// no implemented interface requires emblems
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QString DevinfoDevice::description() const
|
||||
{
|
||||
if (m_device == DEVINFO_ROOT_UDI || parentUdi().isEmpty()) {
|
||||
return QObject::tr("Computer");
|
||||
} else if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
|
||||
return QObject::tr("Processor");
|
||||
} else if (queryDeviceInterface(Solid::DeviceInterface::NetworkInterface)) {
|
||||
const NetworkInterface networkIface(const_cast<DevinfoDevice *>(this));
|
||||
if (networkIface.isWireless()) {
|
||||
return QObject::tr("WLAN Interface");
|
||||
}
|
||||
return QObject::tr("Networking Interface");
|
||||
}
|
||||
return deviceProperty(DevinfoDevice::DeviceDescription);
|
||||
}
|
||||
|
||||
bool DevinfoDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) const
|
||||
{
|
||||
switch (type) {
|
||||
case Solid::DeviceInterface::Processor:
|
||||
return (m_device.indexOf("/cpu") >= 0);
|
||||
case Solid::DeviceInterface::NetworkInterface:
|
||||
return (m_device.indexOf("/em") >= 0 || m_device.indexOf("/wlan") >= 0);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QObject *DevinfoDevice::createDeviceInterface(const Solid::DeviceInterface::Type &type)
|
||||
{
|
||||
if (!queryDeviceInterface(type)) {
|
||||
return 0;
|
||||
}
|
||||
switch (type) {
|
||||
case Solid::DeviceInterface::Processor: {
|
||||
return new Processor(this);
|
||||
case Solid::DeviceInterface::NetworkInterface:
|
||||
return new NetworkInterface(this);
|
||||
}
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray DevinfoDevice::deviceProperty(const DeviceProperty property) const
|
||||
{
|
||||
return m_properties.value(property);
|
||||
}
|
||||
|
||||
QByteArray DevinfoDevice::devicePnP(const PnPInfo pnp) const
|
||||
{
|
||||
return m_pnpinfo.value(pnp);
|
||||
}
|
||||
|
||||
QByteArray DevinfoDevice::deviceCtl(const char* field) const
|
||||
{
|
||||
const QByteArray devicename = deviceProperty(DevinfoDevice::DeviceName);
|
||||
int devicenumberpos = 0;
|
||||
const char* devicedata = devicename.constData();
|
||||
while (*devicedata) {
|
||||
if (::isdigit(*devicedata)) {
|
||||
break;
|
||||
}
|
||||
devicedata++;
|
||||
devicenumberpos++;
|
||||
}
|
||||
QByteArray sysctldevicename = "dev.";
|
||||
sysctldevicename += QByteArray(devicename.constData(), devicenumberpos);
|
||||
sysctldevicename += '.';
|
||||
sysctldevicename += devicedata;
|
||||
sysctldevicename += '.';
|
||||
sysctldevicename += field;
|
||||
|
||||
size_t sysctlbuffsize = 200;
|
||||
char sysctlbuff[sysctlbuffsize];
|
||||
::memset(sysctlbuff, '\0', sysctlbuffsize * sizeof(char));
|
||||
const int sysctlresult = ::sysctlbyname(sysctldevicename.constData(), sysctlbuff, &sysctlbuffsize, NULL, 0);
|
||||
if (sysctlresult == -1) {
|
||||
qWarning() << "sysctlbyname" << sysctldevicename << "failed for" << devicename;
|
||||
return QByteArray();
|
||||
}
|
||||
return QByteArray(sysctlbuff, sysctlbuffsize);
|
||||
}
|
81
solid/solid/backends/devinfo/devinfodevice.h
Normal file
81
solid/solid/backends/devinfo/devinfodevice.h
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_DEVINFO_DEVINFODEVICE_H
|
||||
#define SOLID_BACKENDS_DEVINFO_DEVINFODEVICE_H
|
||||
|
||||
#include <solid/ifaces/device.h>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Devinfo
|
||||
{
|
||||
|
||||
class DevinfoDevice : public Solid::Ifaces::Device
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum DeviceProperty {
|
||||
DeviceParent = 0,
|
||||
DeviceName = 1,
|
||||
DeviceDescription = 2,
|
||||
DeviceDriver = 3,
|
||||
DevicePnPInfo = 4
|
||||
};
|
||||
|
||||
enum PnPInfo {
|
||||
PnPVendor = 0,
|
||||
PnPDevice = 1,
|
||||
PnPSubVendor = 2,
|
||||
PnPSubDevice = 3,
|
||||
PnPClass = 4
|
||||
};
|
||||
|
||||
DevinfoDevice(const QString &device);
|
||||
virtual ~DevinfoDevice();
|
||||
|
||||
virtual QString udi() const;
|
||||
virtual QString parentUdi() const;
|
||||
virtual QString vendor() const;
|
||||
virtual QString product() const;
|
||||
virtual QString icon() const;
|
||||
virtual QStringList emblems() const;
|
||||
virtual QString description() const;
|
||||
virtual bool queryDeviceInterface(const Solid::DeviceInterface::Type &type) const;
|
||||
virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type);
|
||||
|
||||
QByteArray deviceProperty(const DeviceProperty property) const;
|
||||
QByteArray devicePnP(const PnPInfo pnp) const;
|
||||
QByteArray deviceCtl(const char* field) const;
|
||||
|
||||
private:
|
||||
QString m_device;
|
||||
QMap<DeviceProperty, QByteArray> m_properties;
|
||||
QMap<PnPInfo, QByteArray> m_pnpinfo;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // SOLID_BACKENDS_DEVINFO_DEVINFODEVICE_H
|
34
solid/solid/backends/devinfo/devinfodeviceinterface.cpp
Normal file
34
solid/solid/backends/devinfo/devinfodeviceinterface.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "devinfodeviceinterface.h"
|
||||
|
||||
using namespace Solid::Backends::Devinfo;
|
||||
|
||||
DeviceInterface::DeviceInterface(DevinfoDevice *device)
|
||||
: QObject(device), m_device(device)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceInterface::~DeviceInterface()
|
||||
{
|
||||
}
|
||||
|
||||
#include "backends/devinfo/moc_devinfodeviceinterface.cpp"
|
51
solid/solid/backends/devinfo/devinfodeviceinterface.h
Normal file
51
solid/solid/backends/devinfo/devinfodeviceinterface.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_DEVINFO_DEVICEINTERFACE_H
|
||||
#define SOLID_BACKENDS_DEVINFO_DEVICEINTERFACE_H
|
||||
|
||||
#include <solid/ifaces/deviceinterface.h>
|
||||
#include "devinfodevice.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Devinfo
|
||||
{
|
||||
class DeviceInterface : public QObject, virtual public Solid::Ifaces::DeviceInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Solid::Ifaces::DeviceInterface)
|
||||
public:
|
||||
DeviceInterface(DevinfoDevice *device);
|
||||
virtual ~DeviceInterface();
|
||||
|
||||
protected:
|
||||
DevinfoDevice *m_device;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
138
solid/solid/backends/devinfo/devinfomanager.cpp
Normal file
138
solid/solid/backends/devinfo/devinfomanager.cpp
Normal file
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "devinfomanager.h"
|
||||
#include "devinfodevice.h"
|
||||
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <devinfo.h>
|
||||
|
||||
using namespace Solid::Backends::Devinfo;
|
||||
|
||||
int getDeviceList(struct devinfo_dev *dev, void *arg)
|
||||
{
|
||||
const QString devname = QString::fromLatin1(dev->dd_name);
|
||||
if (!devname.isEmpty()) {
|
||||
const QString devudi = QString::fromLatin1("%1/%2").arg(DEVINFO_UDI_PREFIX, devname);
|
||||
reinterpret_cast<QStringList*>(arg)->append(devudi);
|
||||
}
|
||||
return devinfo_foreach_device_child(dev, getDeviceList, arg);
|
||||
}
|
||||
|
||||
class DevinfoManager::Private
|
||||
{
|
||||
public:
|
||||
Private();
|
||||
~Private();
|
||||
|
||||
QSet<Solid::DeviceInterface::Type> m_supportedInterfaces;
|
||||
};
|
||||
|
||||
DevinfoManager::Private::Private()
|
||||
{
|
||||
}
|
||||
|
||||
DevinfoManager::Private::~Private()
|
||||
{
|
||||
}
|
||||
|
||||
DevinfoManager::DevinfoManager(QObject *parent)
|
||||
: Solid::Ifaces::DeviceManager(parent),
|
||||
d(new Private)
|
||||
{
|
||||
d->m_supportedInterfaces
|
||||
<< Solid::DeviceInterface::Processor
|
||||
<< Solid::DeviceInterface::NetworkInterface;
|
||||
}
|
||||
|
||||
DevinfoManager::~DevinfoManager()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
QString DevinfoManager::udiPrefix() const
|
||||
{
|
||||
return QString(DEVINFO_UDI_PREFIX);
|
||||
}
|
||||
|
||||
QSet<Solid::DeviceInterface::Type> DevinfoManager::supportedInterfaces() const
|
||||
{
|
||||
return d->m_supportedInterfaces;
|
||||
}
|
||||
|
||||
QStringList DevinfoManager::allDevices()
|
||||
{
|
||||
QStringList result;
|
||||
if (devinfo_init() != 0) {
|
||||
qWarning() << "could not initialize devinfo";
|
||||
return result;
|
||||
}
|
||||
struct devinfo_dev *root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE);
|
||||
if (root) {
|
||||
devinfo_foreach_device_child(root, getDeviceList, &result);
|
||||
} else {
|
||||
qWarning() << "no root device";
|
||||
}
|
||||
devinfo_free();
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList DevinfoManager::devicesFromQuery(const QString &parentUdi,
|
||||
Solid::DeviceInterface::Type type)
|
||||
{
|
||||
QStringList allDev = allDevices();
|
||||
QStringList result;
|
||||
|
||||
if (!parentUdi.isEmpty()) {
|
||||
foreach (const QString &udi, allDev) {
|
||||
DevinfoDevice device(udi);
|
||||
if (device.queryDeviceInterface(type) && device.parentUdi() == parentUdi) {
|
||||
result << udi;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else if (type != Solid::DeviceInterface::Unknown) {
|
||||
foreach (const QString &udi, allDev) {
|
||||
DevinfoDevice device(udi);
|
||||
if (device.queryDeviceInterface(type)) {
|
||||
result << udi;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return allDev;
|
||||
}
|
||||
}
|
||||
|
||||
QObject *DevinfoManager::createDevice(const QString &udi)
|
||||
{
|
||||
if (udi == udiPrefix()) {
|
||||
return new DevinfoDevice(DEVINFO_ROOT_UDI);
|
||||
}
|
||||
|
||||
if (!udi.isEmpty()) {
|
||||
return new DevinfoDevice(udi);
|
||||
}
|
||||
|
||||
qWarning() << "cannot create device for UDI" << udi;
|
||||
return 0;
|
||||
}
|
58
solid/solid/backends/devinfo/devinfomanager.h
Normal file
58
solid/solid/backends/devinfo/devinfomanager.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_DEVINFO_DEVINFOMANAGER_H
|
||||
#define SOLID_BACKENDS_DEVINFO_DEVINFOMANAGER_H
|
||||
|
||||
#define DEVINFO_ROOT_UDI "/org/kde/devinfo/nexus0"
|
||||
#define DEVINFO_UDI_PREFIX "/org/kde/devinfo"
|
||||
|
||||
#include <solid/ifaces/devicemanager.h>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Devinfo
|
||||
{
|
||||
class DevinfoManager : public Solid::Ifaces::DeviceManager
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DevinfoManager(QObject *parent);
|
||||
virtual ~DevinfoManager();
|
||||
|
||||
virtual QString udiPrefix() const;
|
||||
virtual QSet<Solid::DeviceInterface::Type> supportedInterfaces() const;
|
||||
virtual QStringList allDevices();
|
||||
virtual QStringList devicesFromQuery(const QString &parentUdi,
|
||||
Solid::DeviceInterface::Type type);
|
||||
virtual QObject *createDevice(const QString &udi);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *const d;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SOLID_BACKENDS_DEVINFO_DEVINFOMANAGER_H
|
74
solid/solid/backends/devinfo/devinfonetworkinterface.cpp
Normal file
74
solid/solid/backends/devinfo/devinfonetworkinterface.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "devinfonetworkinterface.h"
|
||||
#include "devinfodevice.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Solid::Backends::Devinfo;
|
||||
|
||||
NetworkInterface::NetworkInterface(DevinfoDevice *device)
|
||||
: DeviceInterface(device)
|
||||
{
|
||||
m_iface = QNetworkInterface::interfaceFromName(device->deviceProperty(DevinfoDevice::DeviceName));
|
||||
}
|
||||
|
||||
NetworkInterface::~NetworkInterface()
|
||||
{
|
||||
}
|
||||
|
||||
QString NetworkInterface::ifaceName() const
|
||||
{
|
||||
return m_iface.name();
|
||||
}
|
||||
|
||||
bool NetworkInterface::isWireless() const
|
||||
{
|
||||
// for reference:
|
||||
// freebsd-src/sbin/ifconfig/ifconfig.8
|
||||
return ifaceName().startsWith("wlan");
|
||||
}
|
||||
|
||||
bool NetworkInterface::isLoopback() const
|
||||
{
|
||||
return (m_iface.flags() & QNetworkInterface::IsLoopBack);
|
||||
}
|
||||
|
||||
QString NetworkInterface::hwAddress() const
|
||||
{
|
||||
const QString result = m_iface.hardwareAddress();
|
||||
if (result.isEmpty()) {
|
||||
return QLatin1String("00:00:00:00:00:00");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
qulonglong NetworkInterface::macAddress() const
|
||||
{
|
||||
const QString hwAddr(hwAddress());
|
||||
if (hwAddr != QLatin1String("00:00:00:00:00:00")) {
|
||||
// there is no documentation on what the return value should be
|
||||
return qHash(hwAddr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "backends/devinfo/moc_devinfonetworkinterface.cpp"
|
59
solid/solid/backends/devinfo/devinfonetworkinterface.h
Normal file
59
solid/solid/backends/devinfo/devinfonetworkinterface.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_DEVINFO_DEVINFONETWORKINTERFACE_H
|
||||
#define SOLID_BACKENDS_DEVINFO_DEVINFONETWORKINTERFACE_H
|
||||
|
||||
#include <solid/ifaces/networkinterface.h>
|
||||
#include "devinfodeviceinterface.h"
|
||||
|
||||
#include <QNetworkInterface>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Devinfo
|
||||
{
|
||||
class DevinfoDevice;
|
||||
|
||||
class NetworkInterface : public DeviceInterface, virtual public Solid::Ifaces::NetworkInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Solid::Ifaces::NetworkInterface)
|
||||
|
||||
public:
|
||||
NetworkInterface(DevinfoDevice *device);
|
||||
virtual ~NetworkInterface();
|
||||
|
||||
virtual QString ifaceName() const;
|
||||
virtual bool isWireless() const;
|
||||
virtual bool isLoopback() const;
|
||||
virtual QString hwAddress() const;
|
||||
virtual qulonglong macAddress() const;
|
||||
|
||||
private:
|
||||
QNetworkInterface m_iface;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SOLID_BACKENDS_DEVINFO_DEVINFONETWORKINTERFACE_H
|
63
solid/solid/backends/devinfo/devinfoprocessor.cpp
Normal file
63
solid/solid/backends/devinfo/devinfoprocessor.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "devinfoprocessor.h"
|
||||
#include "devinfodevice.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
using namespace Solid::Backends::Devinfo;
|
||||
|
||||
// for reference:
|
||||
// freebsd-src/usr.sbin/powerd/powerd.c
|
||||
|
||||
Processor::Processor(DevinfoDevice *device)
|
||||
: DeviceInterface(device)
|
||||
{
|
||||
}
|
||||
|
||||
Processor::~Processor()
|
||||
{
|
||||
}
|
||||
|
||||
int Processor::number() const
|
||||
{
|
||||
return m_device->deviceProperty(DevinfoDevice::DeviceName).right(1).toInt();
|
||||
}
|
||||
|
||||
int Processor::maxSpeed() const
|
||||
{
|
||||
// TODO: parse freq_levels instead
|
||||
return m_device->deviceCtl("freq").toInt();
|
||||
}
|
||||
|
||||
bool Processor::canChangeFrequency() const
|
||||
{
|
||||
return !m_device->deviceCtl("freq").isEmpty();
|
||||
}
|
||||
|
||||
Solid::Processor::InstructionSets Processor::instructionSets() const
|
||||
{
|
||||
// TODO:
|
||||
Solid::Processor::InstructionSets cpuinstructions = Solid::Processor::NoExtensions;
|
||||
return cpuinstructions;
|
||||
}
|
||||
|
||||
#include "backends/devinfo/moc_devinfoprocessor.cpp"
|
53
solid/solid/backends/devinfo/devinfoprocessor.h
Normal file
53
solid/solid/backends/devinfo/devinfoprocessor.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_DEVINFO_PROCESSOR_H
|
||||
#define SOLID_BACKENDS_DEVINFO_PROCESSOR_H
|
||||
|
||||
#include <solid/ifaces/processor.h>
|
||||
#include "devinfodeviceinterface.h"
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Devinfo
|
||||
{
|
||||
class DevinfoDevice;
|
||||
|
||||
class Processor : public DeviceInterface, virtual public Solid::Ifaces::Processor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Solid::Ifaces::Processor)
|
||||
|
||||
public:
|
||||
Processor(DevinfoDevice *device);
|
||||
virtual ~Processor();
|
||||
|
||||
virtual int number() const;
|
||||
virtual int maxSpeed() const;
|
||||
virtual bool canChangeFrequency() const;
|
||||
virtual Solid::Processor::InstructionSets instructionSets() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SOLID_BACKENDS_DEVINFO_PROCESSOR_H
|
49
solid/solid/backends/geom/geomblock.cpp
Normal file
49
solid/solid/backends/geom/geomblock.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "geomblock.h"
|
||||
|
||||
using namespace Solid::Backends::Geom;
|
||||
|
||||
Block::Block(GeomDevice *device)
|
||||
: DeviceInterface(device)
|
||||
{
|
||||
}
|
||||
|
||||
Block::~Block()
|
||||
{
|
||||
}
|
||||
|
||||
int Block::deviceMajor() const
|
||||
{
|
||||
return m_device->m_major;
|
||||
}
|
||||
|
||||
int Block::deviceMinor() const
|
||||
{
|
||||
return m_device->m_minor;
|
||||
}
|
||||
|
||||
QString Block::device() const
|
||||
{
|
||||
return m_device->m_realdevice;
|
||||
}
|
||||
|
||||
#include "backends/geom/moc_geomblock.cpp"
|
51
solid/solid/backends/geom/geomblock.h
Normal file
51
solid/solid/backends/geom/geomblock.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_GEOM_GEOMBLOCK_H
|
||||
#define SOLID_BACKENDS_GEOM_GEOMBLOCK_H
|
||||
|
||||
#include <solid/ifaces/block.h>
|
||||
|
||||
#include "geomdeviceinterface.h"
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Geom
|
||||
{
|
||||
class Block : public DeviceInterface, virtual public Solid::Ifaces::Block
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Solid::Ifaces::Block)
|
||||
|
||||
public:
|
||||
Block(GeomDevice *device);
|
||||
virtual ~Block();
|
||||
|
||||
virtual int deviceMajor() const;
|
||||
virtual int deviceMinor() const;
|
||||
virtual QString device() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SOLID_BACKENDS_GEOM_GEOMBLOCK_H
|
261
solid/solid/backends/geom/geomdevice.cpp
Normal file
261
solid/solid/backends/geom/geomdevice.cpp
Normal file
|
@ -0,0 +1,261 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "geommanager.h"
|
||||
#include "geomdevice.h"
|
||||
#include "geomblock.h"
|
||||
#include "geomstoragedrive.h"
|
||||
#include "geomstoragevolume.h"
|
||||
#include "kglobal.h"
|
||||
#include "klocale.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <libgeom.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace Solid::Backends::Geom;
|
||||
|
||||
GeomDevice::GeomDevice(const QString &device)
|
||||
: Solid::Ifaces::Device()
|
||||
, m_size(0)
|
||||
, m_device(device)
|
||||
, m_major(0)
|
||||
, m_minor(0)
|
||||
{
|
||||
m_realdevice = m_device.right(m_device.size() - qstrlen(GEOM_UDI_PREFIX) - 1).toLatin1();
|
||||
// assume devices which are named like path do not have major/minor (e.g. gpt/swapfs or
|
||||
// gptid/9d7008c3-990e-11eb-bf4c-002590ec5bf2)
|
||||
if (!m_realdevice.contains('/')) {
|
||||
int datapos = 0;
|
||||
int majornumberpos = 0;
|
||||
int minornumberpos = 0;
|
||||
const char* devicedata = m_realdevice.constData();
|
||||
while (*devicedata) {
|
||||
if (::isdigit(*devicedata)) {
|
||||
if (!majornumberpos) {
|
||||
majornumberpos = datapos;
|
||||
} else {
|
||||
minornumberpos = datapos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
devicedata++;
|
||||
datapos++;
|
||||
}
|
||||
m_parent = QByteArray(m_realdevice.constData(), majornumberpos);
|
||||
m_major = QByteArray(m_realdevice.constData() + majornumberpos, minornumberpos - majornumberpos).toInt();
|
||||
m_minor = QByteArray(m_realdevice.constData() + minornumberpos, m_realdevice.size() - majornumberpos).toInt();
|
||||
}
|
||||
|
||||
struct gmesh tree;
|
||||
::memset(&tree, 0, sizeof(gmesh));
|
||||
const int geomresult = geom_gettree(&tree);
|
||||
struct gclass* geomclass = Q_NULLPTR;
|
||||
struct ggeom* geomgeom = Q_NULLPTR;
|
||||
struct gprovider* geomprovider = Q_NULLPTR;
|
||||
struct gconfig* geomconfig = Q_NULLPTR;
|
||||
LIST_FOREACH(geomclass, &tree.lg_class, lg_class) {
|
||||
LIST_FOREACH(geomgeom, &geomclass->lg_geom, lg_geom) {
|
||||
LIST_FOREACH(geomprovider, &geomgeom->lg_provider, lg_provider) {
|
||||
// qDebug() << geomgeom->lg_name << m_realdevice;
|
||||
if (qstrcmp(geomprovider->lg_name, m_realdevice.constData()) != 0) {
|
||||
continue;
|
||||
}
|
||||
m_class = QByteArray(geomclass->lg_name).toLower();
|
||||
LIST_FOREACH(geomconfig, &geomprovider->lg_config, lg_config) {
|
||||
// qDebug() << geomprovider->lg_name << geomconfig->lg_name << geomconfig->lg_val;
|
||||
if (qstrcmp(geomconfig->lg_name, "length") == 0) {
|
||||
m_size = QByteArray(geomconfig->lg_val).toULongLong();
|
||||
} else if (qstrcmp(geomconfig->lg_name, "type") == 0) {
|
||||
m_type = geomconfig->lg_val;
|
||||
} else if (qstrcmp(geomconfig->lg_name, "label") == 0) {
|
||||
m_label = geomconfig->lg_val;
|
||||
} else if (qstrcmp(geomconfig->lg_name, "rawuuid") == 0) {
|
||||
m_uuid = geomconfig->lg_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// re-iterate to assign class other than DEV if possible
|
||||
LIST_FOREACH(geomclass, &tree.lg_class, lg_class) {
|
||||
if (qstrcmp(geomclass->lg_name, "PART") != 0 && qstrcmp(geomclass->lg_name, "DISK") != 0
|
||||
&& qstrcmp(geomclass->lg_name, "SWAP") != 0) {
|
||||
continue;
|
||||
}
|
||||
LIST_FOREACH(geomgeom, &geomclass->lg_geom, lg_geom) {
|
||||
LIST_FOREACH(geomprovider, &geomgeom->lg_provider, lg_provider) {
|
||||
if (qstrcmp(geomprovider->lg_name, m_realdevice.constData()) != 0) {
|
||||
continue;
|
||||
}
|
||||
m_class = QByteArray(geomclass->lg_name).toLower();
|
||||
// qDebug() << geomgeom->lg_name << m_class;
|
||||
}
|
||||
}
|
||||
}
|
||||
geom_deletetree(&tree);
|
||||
|
||||
// qDebug() << Q_FUNC_INFO << m_device << m_realdevice << m_parent << m_major << m_minor;
|
||||
}
|
||||
|
||||
GeomDevice::~GeomDevice()
|
||||
{
|
||||
}
|
||||
|
||||
QString GeomDevice::udi() const
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
QString GeomDevice::parentUdi() const
|
||||
{
|
||||
if (m_parent.isEmpty()) {
|
||||
return QString(GEOM_ROOT_UDI);
|
||||
}
|
||||
return QString::fromLatin1("%1/%2").arg(GEOM_UDI_PREFIX, m_parent.constData());
|
||||
}
|
||||
|
||||
QString GeomDevice::vendor() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString GeomDevice::product() const
|
||||
{
|
||||
if (m_device == GEOM_ROOT_UDI) {
|
||||
return QLatin1String("Devices");
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString GeomDevice::icon() const
|
||||
{
|
||||
if (m_device == GEOM_ROOT_UDI) {
|
||||
return QString("computer");
|
||||
} else if (queryDeviceInterface(Solid::DeviceInterface::StorageDrive)) {
|
||||
const StorageDrive storageIface(const_cast<GeomDevice *>(this));
|
||||
Solid::StorageDrive::DriveType drivetype = storageIface.driveType();
|
||||
|
||||
if (drivetype == Solid::StorageDrive::HardDisk) {
|
||||
return QLatin1String("drive-harddisk");
|
||||
} else if (drivetype == Solid::StorageDrive::CdromDrive) {
|
||||
return QLatin1String("drive-optical");
|
||||
} else if (drivetype == Solid::StorageDrive::Floppy) {
|
||||
return QLatin1String("media-floppy");
|
||||
} else if (drivetype == Solid::StorageDrive::Tape) {
|
||||
return QLatin1String("media-tape");
|
||||
} else if (drivetype == Solid::StorageDrive::CompactFlash) {
|
||||
return QLatin1String("drive-removable-media");
|
||||
} else if (drivetype == Solid::StorageDrive::MemoryStick) {
|
||||
return QLatin1String("media-flash-memory-stick");
|
||||
} else if (drivetype == Solid::StorageDrive::SmartMedia) {
|
||||
return QLatin1String("media-flash-smart-media");
|
||||
} else if (drivetype == Solid::StorageDrive::SdMmc) {
|
||||
return QLatin1String("media-flash-sd-mmc");
|
||||
} else if (drivetype == Solid::StorageDrive::Xd) {
|
||||
return QLatin1String("drive-removable-media");
|
||||
}
|
||||
} else if (queryDeviceInterface(Solid::DeviceInterface::StorageVolume)) {
|
||||
return QLatin1String("drive-harddisk");
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QStringList GeomDevice::emblems() const
|
||||
{
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QString GeomDevice::description() const
|
||||
{
|
||||
if (m_device == GEOM_ROOT_UDI || parentUdi().isEmpty()) {
|
||||
return QObject::tr("Computer");
|
||||
} else if (queryDeviceInterface(Solid::DeviceInterface::StorageDrive)) {
|
||||
const StorageDrive storageIface(const_cast<GeomDevice *>(this));
|
||||
Solid::StorageDrive::DriveType drivetype = storageIface.driveType();
|
||||
const QString storagesize = KGlobal::locale()->formatByteSize(storageIface.size());
|
||||
|
||||
if (drivetype == Solid::StorageDrive::HardDisk) {
|
||||
return QObject::tr("%1 Hard Drive").arg(storagesize);
|
||||
} else if (drivetype == Solid::StorageDrive::CdromDrive) {
|
||||
return QObject::tr("%1 CD-ROM Drive").arg(storagesize);
|
||||
} else if (drivetype == Solid::StorageDrive::Floppy) {
|
||||
return QObject::tr("%1 Floppy Drive").arg(storagesize);
|
||||
} else if (drivetype == Solid::StorageDrive::Tape) {
|
||||
return QObject::tr("%1 Tape Drive").arg(storagesize);
|
||||
} else if (drivetype == Solid::StorageDrive::CompactFlash) {
|
||||
return QObject::tr("%1 Compact Flash Drive").arg(storagesize);
|
||||
} else if (drivetype == Solid::StorageDrive::MemoryStick) {
|
||||
return QObject::tr("%1 Memory Stick Drive").arg(storagesize);
|
||||
} else if (drivetype == Solid::StorageDrive::SmartMedia) {
|
||||
return QObject::tr("%1 Smart Media Drive").arg(storagesize);
|
||||
} else if (drivetype == Solid::StorageDrive::SdMmc) {
|
||||
return QObject::tr("%1 SD/MMC Drive").arg(storagesize);
|
||||
} else if (drivetype == Solid::StorageDrive::Xd) {
|
||||
return QObject::tr("%1 Xd Drive").arg(storagesize);
|
||||
}
|
||||
} else if (queryDeviceInterface(Solid::DeviceInterface::StorageVolume)) {
|
||||
const StorageVolume storageIface(const_cast<GeomDevice *>(this));
|
||||
QString desc = storageIface.label();
|
||||
if (desc.isEmpty()) {
|
||||
desc = storageIface.uuid();
|
||||
}
|
||||
if (desc.isEmpty()) {
|
||||
desc = this->m_realdevice;
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool GeomDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) const
|
||||
{
|
||||
switch (type) {
|
||||
case Solid::DeviceInterface::Block:
|
||||
return (m_major != 0);
|
||||
case Solid::DeviceInterface::StorageDrive:
|
||||
case Solid::DeviceInterface::StorageVolume:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QObject *GeomDevice::createDeviceInterface(const Solid::DeviceInterface::Type &type)
|
||||
{
|
||||
if (!queryDeviceInterface(type)) {
|
||||
return 0;
|
||||
}
|
||||
switch (type) {
|
||||
case Solid::DeviceInterface::Block: {
|
||||
return new Block(this);
|
||||
}
|
||||
case Solid::DeviceInterface::StorageDrive: {
|
||||
return new StorageDrive(this);
|
||||
}
|
||||
case Solid::DeviceInterface::StorageVolume: {
|
||||
return new StorageVolume(this);
|
||||
}
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
}
|
70
solid/solid/backends/geom/geomdevice.h
Normal file
70
solid/solid/backends/geom/geomdevice.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_GEOM_GEOMDEVICE_H
|
||||
#define SOLID_BACKENDS_GEOM_GEOMDEVICE_H
|
||||
|
||||
#include <solid/ifaces/device.h>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Geom
|
||||
{
|
||||
|
||||
class GeomDevice : public Solid::Ifaces::Device
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GeomDevice(const QString &device);
|
||||
virtual ~GeomDevice();
|
||||
|
||||
virtual QString udi() const;
|
||||
virtual QString parentUdi() const;
|
||||
virtual QString vendor() const;
|
||||
virtual QString product() const;
|
||||
virtual QString icon() const;
|
||||
virtual QStringList emblems() const;
|
||||
virtual QString description() const;
|
||||
virtual bool queryDeviceInterface(const Solid::DeviceInterface::Type &type) const;
|
||||
virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type);
|
||||
|
||||
public:
|
||||
// populated from geom providers
|
||||
qulonglong m_size;
|
||||
QByteArray m_type;
|
||||
QByteArray m_label;
|
||||
QByteArray m_uuid;
|
||||
QByteArray m_class;
|
||||
// synthetized
|
||||
QString m_device;
|
||||
QByteArray m_realdevice;
|
||||
QByteArray m_parent;
|
||||
int m_major;
|
||||
int m_minor;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // SOLID_BACKENDS_GEOM_GEOMDEVICE_H
|
34
solid/solid/backends/geom/geomdeviceinterface.cpp
Normal file
34
solid/solid/backends/geom/geomdeviceinterface.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "geomdeviceinterface.h"
|
||||
|
||||
using namespace Solid::Backends::Geom;
|
||||
|
||||
DeviceInterface::DeviceInterface(GeomDevice *device)
|
||||
: QObject(device), m_device(device)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceInterface::~DeviceInterface()
|
||||
{
|
||||
}
|
||||
|
||||
#include "backends/geom/moc_geomdeviceinterface.cpp"
|
51
solid/solid/backends/geom/geomdeviceinterface.h
Normal file
51
solid/solid/backends/geom/geomdeviceinterface.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_GEOM_DEVICEINTERFACE_H
|
||||
#define SOLID_BACKENDS_GEOM_DEVICEINTERFACE_H
|
||||
|
||||
#include <solid/ifaces/deviceinterface.h>
|
||||
#include "geomdevice.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Geom
|
||||
{
|
||||
class DeviceInterface : public QObject, virtual public Solid::Ifaces::DeviceInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Solid::Ifaces::DeviceInterface)
|
||||
public:
|
||||
DeviceInterface(GeomDevice *device);
|
||||
virtual ~DeviceInterface();
|
||||
|
||||
protected:
|
||||
GeomDevice *m_device;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
140
solid/solid/backends/geom/geommanager.cpp
Normal file
140
solid/solid/backends/geom/geommanager.cpp
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "geommanager.h"
|
||||
#include "geomdevice.h"
|
||||
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <libgeom.h>
|
||||
|
||||
using namespace Solid::Backends::Geom;
|
||||
|
||||
class GeomManager::Private
|
||||
{
|
||||
public:
|
||||
Private();
|
||||
~Private();
|
||||
|
||||
QSet<Solid::DeviceInterface::Type> m_supportedInterfaces;
|
||||
};
|
||||
|
||||
GeomManager::Private::Private()
|
||||
{
|
||||
}
|
||||
|
||||
GeomManager::Private::~Private()
|
||||
{
|
||||
}
|
||||
|
||||
GeomManager::GeomManager(QObject *parent)
|
||||
: Solid::Ifaces::DeviceManager(parent),
|
||||
d(new Private)
|
||||
{
|
||||
d->m_supportedInterfaces
|
||||
<< Solid::DeviceInterface::Block
|
||||
<< Solid::DeviceInterface::StorageDrive
|
||||
<< Solid::DeviceInterface::StorageVolume;
|
||||
}
|
||||
|
||||
GeomManager::~GeomManager()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
QString GeomManager::udiPrefix() const
|
||||
{
|
||||
return QString(GEOM_UDI_PREFIX);
|
||||
}
|
||||
|
||||
QSet<Solid::DeviceInterface::Type> GeomManager::supportedInterfaces() const
|
||||
{
|
||||
return d->m_supportedInterfaces;
|
||||
}
|
||||
|
||||
QStringList GeomManager::allDevices()
|
||||
{
|
||||
QStringList result;
|
||||
|
||||
struct gmesh tree;
|
||||
::memset(&tree, 0, sizeof(gmesh));
|
||||
const int geomresult = geom_gettree(&tree);
|
||||
struct gclass* geomclass = Q_NULLPTR;
|
||||
struct ggeom* geomgeom = Q_NULLPTR;
|
||||
struct gprovider* geomprovider = Q_NULLPTR;
|
||||
struct gconfig* geomconfig = Q_NULLPTR;
|
||||
LIST_FOREACH(geomclass, &tree.lg_class, lg_class) {
|
||||
// DEV class includes all devices of interest (e.g. swap, disk and partitions)
|
||||
if (qstrcmp(geomclass->lg_name, "DEV") != 0) {
|
||||
continue;
|
||||
}
|
||||
LIST_FOREACH(geomgeom, &geomclass->lg_geom, lg_geom) {
|
||||
// qDebug() << geomclass->lg_name << geomgeom->lg_name;
|
||||
const QString devudi = QString::fromLatin1("%1/%2").arg(GEOM_UDI_PREFIX, geomgeom->lg_name);
|
||||
result << devudi;
|
||||
}
|
||||
}
|
||||
geom_deletetree(&tree);
|
||||
|
||||
// qDebug() << Q_FUNC_INFO << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList GeomManager::devicesFromQuery(const QString &parentUdi,
|
||||
Solid::DeviceInterface::Type type)
|
||||
{
|
||||
QStringList allDev = allDevices();
|
||||
QStringList result;
|
||||
|
||||
if (!parentUdi.isEmpty()) {
|
||||
foreach (const QString &udi, allDev) {
|
||||
GeomDevice device(udi);
|
||||
if (device.queryDeviceInterface(type) && device.parentUdi() == parentUdi) {
|
||||
result << udi;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else if (type != Solid::DeviceInterface::Unknown) {
|
||||
foreach (const QString &udi, allDev) {
|
||||
GeomDevice device(udi);
|
||||
if (device.queryDeviceInterface(type)) {
|
||||
result << udi;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return allDev;
|
||||
}
|
||||
}
|
||||
|
||||
QObject *GeomManager::createDevice(const QString &udi)
|
||||
{
|
||||
if (udi == udiPrefix()) {
|
||||
return new GeomDevice(GEOM_ROOT_UDI);
|
||||
}
|
||||
|
||||
if (!udi.isEmpty()) {
|
||||
return new GeomDevice(udi);
|
||||
}
|
||||
|
||||
qWarning() << "cannot create device for UDI" << udi;
|
||||
return 0;
|
||||
}
|
58
solid/solid/backends/geom/geommanager.h
Normal file
58
solid/solid/backends/geom/geommanager.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SOLID_BACKENDS_GEOM_GEOMMANAGER_H
|
||||
#define SOLID_BACKENDS_GEOM_GEOMMANAGER_H
|
||||
|
||||
#define GEOM_ROOT_UDI "/org/kde/geom/geom0"
|
||||
#define GEOM_UDI_PREFIX "/org/kde/geom"
|
||||
|
||||
#include <solid/ifaces/devicemanager.h>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Geom
|
||||
{
|
||||
class GeomManager : public Solid::Ifaces::DeviceManager
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GeomManager(QObject *parent);
|
||||
virtual ~GeomManager();
|
||||
|
||||
virtual QString udiPrefix() const;
|
||||
virtual QSet<Solid::DeviceInterface::Type> supportedInterfaces() const;
|
||||
virtual QStringList allDevices();
|
||||
virtual QStringList devicesFromQuery(const QString &parentUdi,
|
||||
Solid::DeviceInterface::Type type);
|
||||
virtual QObject *createDevice(const QString &udi);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *const d;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SOLID_BACKENDS_GEOM_GEOMMANAGER_H
|
88
solid/solid/backends/geom/geomstoragedrive.cpp
Normal file
88
solid/solid/backends/geom/geomstoragedrive.cpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "geomstoragedrive.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <libgeom.h>
|
||||
|
||||
using namespace Solid::Backends::Geom;
|
||||
|
||||
StorageDrive::StorageDrive(GeomDevice *device)
|
||||
: Block(device)
|
||||
{
|
||||
}
|
||||
|
||||
StorageDrive::~StorageDrive()
|
||||
{
|
||||
}
|
||||
|
||||
qulonglong StorageDrive::size() const
|
||||
{
|
||||
return m_device->m_size;
|
||||
}
|
||||
|
||||
bool StorageDrive::isHotpluggable() const
|
||||
{
|
||||
const Solid::StorageDrive::Bus storagebus = bus();
|
||||
return (storagebus == Solid::StorageDrive::Usb || storagebus == Solid::StorageDrive::Ieee1394);
|
||||
}
|
||||
|
||||
bool StorageDrive::isRemovable() const
|
||||
{
|
||||
const Solid::StorageDrive::Bus storagebus = bus();
|
||||
return (storagebus == Solid::StorageDrive::Usb);
|
||||
}
|
||||
|
||||
Solid::StorageDrive::DriveType StorageDrive::driveType() const
|
||||
{
|
||||
// for reference:
|
||||
// https://docs.freebsd.org/doc/6.0-RELEASE/usr/share/doc/handbook/disks-naming.html
|
||||
// TODO: not implementd: MemoryStick, SmartMedia, SdMmc, Xd
|
||||
if (m_device->m_realdevice.startsWith("acd") || m_device->m_realdevice.startsWith("cd")
|
||||
|| m_device->m_realdevice.startsWith("mcd")) {
|
||||
return Solid::StorageDrive::CdromDrive;
|
||||
} else if (m_device->m_realdevice.startsWith("fd")) {
|
||||
return Solid::StorageDrive::Floppy;
|
||||
} else if (m_device->m_realdevice.startsWith("sa") || m_device->m_realdevice.startsWith("ast")) {
|
||||
return Solid::StorageDrive::Tape;
|
||||
} else if (m_device->m_realdevice.startsWith("da") || m_device->m_realdevice.startsWith("fla")) {
|
||||
return Solid::StorageDrive::CompactFlash;
|
||||
} else {
|
||||
return Solid::StorageDrive::HardDisk;
|
||||
}
|
||||
}
|
||||
|
||||
Solid::StorageDrive::Bus StorageDrive::bus() const
|
||||
{
|
||||
// TODO: not implemented: Sata, Ieee1394
|
||||
if (m_device->m_realdevice.startsWith("ad") || m_device->m_realdevice.startsWith("acd")
|
||||
|| m_device->m_realdevice.startsWith("ast")) {
|
||||
return Solid::StorageDrive::Ide;
|
||||
} else if (m_device->m_realdevice.startsWith("fla")) {
|
||||
return Solid::StorageDrive::Usb;
|
||||
} else if (m_device->m_realdevice.startsWith("da") || m_device->m_realdevice.startsWith("cd")
|
||||
|| m_device->m_realdevice.startsWith("sa")) {
|
||||
return Solid::StorageDrive::Scsi;
|
||||
} else {
|
||||
return Solid::StorageDrive::Platform;
|
||||
}
|
||||
}
|
55
solid/solid/backends/geom/geomstoragedrive.h
Normal file
55
solid/solid/backends/geom/geomstoragedrive.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GEOMSTORAGEDRIVE_H
|
||||
#define GEOMSTORAGEDRIVE_H
|
||||
|
||||
#include <ifaces/storagedrive.h>
|
||||
|
||||
#include "geomblock.h"
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Geom
|
||||
{
|
||||
|
||||
class StorageDrive: public Block, virtual public Solid::Ifaces::StorageDrive
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Solid::Ifaces::StorageDrive)
|
||||
|
||||
public:
|
||||
StorageDrive(GeomDevice *device);
|
||||
virtual ~StorageDrive();
|
||||
|
||||
virtual qulonglong size() const;
|
||||
virtual bool isHotpluggable() const;
|
||||
virtual bool isRemovable() const;
|
||||
virtual Solid::StorageDrive::DriveType driveType() const;
|
||||
virtual Solid::StorageDrive::Bus bus() const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // GEOMSTORAGEDRIVE_H
|
81
solid/solid/backends/geom/geomstoragevolume.cpp
Normal file
81
solid/solid/backends/geom/geomstoragevolume.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "geomstoragevolume.h"
|
||||
#include "geomdevice.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Solid::Backends::Geom;
|
||||
|
||||
StorageVolume::StorageVolume(GeomDevice *device)
|
||||
: Block(device)
|
||||
{
|
||||
}
|
||||
|
||||
StorageVolume::~StorageVolume()
|
||||
{
|
||||
}
|
||||
|
||||
QString StorageVolume::encryptedContainerUdi() const
|
||||
{
|
||||
// encrypted devices are not support
|
||||
return QString();
|
||||
}
|
||||
|
||||
qulonglong StorageVolume::size() const
|
||||
{
|
||||
return m_device->m_size;
|
||||
}
|
||||
|
||||
QString StorageVolume::uuid() const
|
||||
{
|
||||
return m_device->m_uuid;
|
||||
}
|
||||
|
||||
QString StorageVolume::label() const
|
||||
{
|
||||
return m_device->m_label;
|
||||
}
|
||||
|
||||
QString StorageVolume::fsType() const
|
||||
{
|
||||
return m_device->m_type;
|
||||
}
|
||||
|
||||
Solid::StorageVolume::UsageType StorageVolume::usage() const
|
||||
{
|
||||
// TODO: not implemented: Encrypted, Raid
|
||||
if (m_device->m_class == "swap") {
|
||||
return Solid::StorageVolume::Other;
|
||||
} else if (!m_device->m_type.isEmpty()) {
|
||||
return Solid::StorageVolume::FileSystem;
|
||||
} else if (m_device->m_class == "disk" || m_device->m_class == "part") {
|
||||
return Solid::StorageVolume::PartitionTable;
|
||||
} else {
|
||||
return Solid::StorageVolume::Unused;
|
||||
}
|
||||
}
|
||||
|
||||
bool StorageVolume::isIgnored() const
|
||||
{
|
||||
const Solid::StorageVolume::UsageType volumeusage = usage();
|
||||
return (volumeusage != Solid::StorageVolume::FileSystem);
|
||||
}
|
57
solid/solid/backends/geom/geomstoragevolume.h
Normal file
57
solid/solid/backends/geom/geomstoragevolume.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Copyright 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) version 3, or any
|
||||
later version accepted by the membership of KDE e.V. (or its
|
||||
successor approved by the membership of KDE e.V.), which shall
|
||||
act as a proxy defined in Section 6 of version 3 of the license.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GEOMSTORAGEVOLUME_H
|
||||
#define GEOMSTORAGEVOLUME_H
|
||||
|
||||
#include <ifaces/storagevolume.h>
|
||||
|
||||
#include "geomblock.h"
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
namespace Backends
|
||||
{
|
||||
namespace Geom
|
||||
{
|
||||
|
||||
class StorageVolume: public Block, virtual public Solid::Ifaces::StorageVolume
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Solid::Ifaces::StorageVolume)
|
||||
|
||||
public:
|
||||
StorageVolume(GeomDevice *device);
|
||||
virtual ~StorageVolume();
|
||||
|
||||
virtual QString encryptedContainerUdi() const;
|
||||
virtual qulonglong size() const;
|
||||
virtual QString uuid() const;
|
||||
virtual QString label() const;
|
||||
virtual QString fsType() const;
|
||||
virtual Solid::StorageVolume::UsageType usage() const;
|
||||
virtual bool isIgnored() const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // GEOMSTORAGEVOLUME_H
|
|
@ -21,4 +21,6 @@
|
|||
#cmakedefine ENABLE_TESTING
|
||||
|
||||
#cmakedefine UDEV_FOUND
|
||||
#cmakedefine DEVINFO_FOUND
|
||||
#cmakedefine GEOM_FOUND
|
||||
#cmakedefine LIBCDIO_FOUND
|
||||
|
|
|
@ -29,6 +29,14 @@
|
|||
#include "backends/fakehw/fakemanager.h"
|
||||
#endif
|
||||
|
||||
#if defined (DEVINFO_FOUND)
|
||||
#include "backends/devinfo/devinfomanager.h"
|
||||
#endif
|
||||
|
||||
#if defined (GEOM_FOUND)
|
||||
#include "backends/geom/geommanager.h"
|
||||
#endif
|
||||
|
||||
#if defined(UDEV_FOUND)
|
||||
#include "backends/udev/udevmanager.h"
|
||||
#endif
|
||||
|
@ -57,6 +65,14 @@ void Solid::ManagerBasePrivate::loadBackends()
|
|||
#if defined(UDEV_FOUND)
|
||||
m_backends << new Solid::Backends::UDev::UDevManager(0);
|
||||
#endif
|
||||
|
||||
#if defined(DEVINFO_FOUND)
|
||||
m_backends << new Solid::Backends::Devinfo::DevinfoManager(0);
|
||||
#endif
|
||||
|
||||
#if defined(GEOM_FOUND)
|
||||
m_backends << new Solid::Backends::Geom::GeomManager(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
QList<QObject*> Solid::ManagerBasePrivate::managerBackends() const
|
||||
|
|
Loading…
Add table
Reference in a new issue