7#include "iokitmanager.h"
8#include "iokitdevice.h"
12#include <IOKit/IOKitLib.h>
13#include <IOKit/network/IOEthernetInterface.h>
14#include <IOKit/usb/IOUSBLib.h>
16#include <CoreFoundation/CoreFoundation.h>
24class IOKitManagerPrivate
27 inline IOKitManagerPrivate()
33 IONotificationPortRef port;
34 CFRunLoopSourceRef source;
37 static QStringList devicesFromRegistry(io_iterator_t it);
43QStringList IOKitManagerPrivate::devicesFromRegistry(io_iterator_t it)
47 while ((obj = IOIteratorNext(it))) {
48 CFStringRef pathRef = IORegistryEntryCopyPath(obj, kIOServicePlane);
53 qWarning() << Q_FUNC_INFO <<
"IORegistryEntryCopyPath failed";
57 const kern_return_t ret = IOObjectRelease(obj);
58 if (ret != KERN_SUCCESS) {
61 qDebug() << Q_FUNC_INFO <<
"Unable to release object reference";
72 case Solid::DeviceInterface::Unknown:
74 case Solid::DeviceInterface::Processor:
75 return "AppleACPICPU";
76 case Solid::DeviceInterface::Battery:
77 return "AppleSmartBattery";
81 case Solid::DeviceInterface::StorageAccess:
82 case Solid::DeviceInterface::StorageDrive:
83 case Solid::DeviceInterface::StorageVolume:
85 case Solid::DeviceInterface::OpticalDrive:
86 case Solid::DeviceInterface::OpticalDisc:
95IOKitManager::IOKitManager(
QObject *parent)
96 : Solid::Ifaces::DeviceManager(parent)
97 , d(new IOKitManagerPrivate)
99 d->port = IONotificationPortCreate(kIOMasterPortDefault);
101 qWarning() << Q_FUNC_INFO <<
"Unable to create notification port";
105 d->source = IONotificationPortGetRunLoopSource(d->port);
107 qWarning() << Q_FUNC_INFO <<
"Unable to create notification source";
111 CFRunLoopAddSource(CFRunLoopGetCurrent(), d->source, kCFRunLoopDefaultMode);
113 d->supportedInterfaces << Solid::DeviceInterface::GenericInterface
114 << Solid::DeviceInterface::Processor
115 << Solid::DeviceInterface::Block
116 << Solid::DeviceInterface::StorageAccess
117 << Solid::DeviceInterface::StorageDrive
118 << Solid::DeviceInterface::OpticalDrive
119 << Solid::DeviceInterface::StorageVolume
120 << Solid::DeviceInterface::OpticalDisc
121 << Solid::DeviceInterface::Camera
122 << Solid::DeviceInterface::PortableMediaPlayer
123 << Solid::DeviceInterface::Battery;
127IOKitManager::~IOKitManager()
130 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), d->source, kCFRunLoopDefaultMode);
133 IONotificationPortDestroy(d->port);
139QString IOKitManager::udiPrefix()
const
146 return d->supportedInterfaces;
154 kern_return_t ret = IORegistryCreateIterator(kIOMasterPortDefault, kIOServicePlane, kIORegistryIterateRecursively, &it);
155 if (ret != KERN_SUCCESS) {
156 qWarning() << Q_FUNC_INFO <<
"unable to create iterator";
160 return IOKitManagerPrivate::devicesFromRegistry(it);
167 if (type == Solid::DeviceInterface::Unknown) {
169 result = allDevices();
171 const char *deviceClassName = IOKitManagerPrivate::typeToName(type);
172 if (!deviceClassName) {
176 CFMutableDictionaryRef matchingDict = IOServiceMatching(deviceClassName);
182 io_iterator_t it = 0;
185 kern_return_t ret = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &it);
187 result = IOKitManagerPrivate::devicesFromRegistry(it);
197 for (
const QString &udi : std::as_const(result)) {
198 if (udi.startsWith(parentUdi)) {
209 io_registry_entry_t entry = IORegistryEntryCopyFromPath(kIOMasterPortDefault, path);
216 if (entry == MACH_PORT_NULL) {
220 return new IOKitDevice(udi, entry);
227#include "moc_iokitmanager.cpp"
Type
This enum type defines the type of device interface that a Device can have.
QString path(const QString &relativePath)
QString fromCFString(CFStringRef string)
bool isEmpty() const const
CFStringRef toCFString() const const
QFuture< typename qValueType< Iterator >::value_type > filtered(Iterator begin, Iterator end, KeepFunctor &&filterFunction)