28 #include "ifaces/devicemanager.h" 29 #include "ifaces/device.h" 40 QList<QObject*> backends = managerBackends();
41 foreach (
QObject *backend, backends) {
42 connect(backend, SIGNAL(deviceAdded(QString)),
43 this, SLOT(_k_deviceAdded(QString)));
44 connect(backend, SIGNAL(deviceRemoved(QString)),
45 this, SLOT(_k_deviceRemoved(QString)));
52 foreach (
QObject *backend, backends) {
53 disconnect(backend, 0,
this, 0);
56 foreach (QWeakPointer<DevicePrivate> dev, m_devicesMap) {
57 if (!dev.data()->ref.deref()) {
68 QList<QObject*> backends = globalDeviceStorage->managerBackends();
70 foreach (
QObject *backendObj, backends) {
71 Ifaces::DeviceManager *backend = qobject_cast<Ifaces::DeviceManager *>(backendObj);
73 if (backend == 0)
continue;
75 QStringList udis = backend->allDevices();
77 foreach (
const QString &udi, udis) {
86 const QString &parentUdi)
96 return QList<Device>();
101 const QString &parentUdi)
104 QList<QObject*> backends = globalDeviceStorage->managerBackends();
106 foreach (
QObject *backendObj, backends) {
107 Ifaces::DeviceManager *backend = qobject_cast<Ifaces::DeviceManager *>(backendObj);
109 if (backend == 0)
continue;
110 if (!backend->supportedInterfaces().contains(type))
continue;
112 QStringList udis = backend->devicesFromQuery(parentUdi, type);
114 foreach (
const QString &udi, udis) {
123 const QString &parentUdi)
126 QList<QObject*> backends = globalDeviceStorage->managerBackends();
127 QSet<DeviceInterface::Type> usedTypes = predicate.
usedTypes();
129 foreach (
QObject *backendObj, backends) {
130 Ifaces::DeviceManager *backend = qobject_cast<Ifaces::DeviceManager *>(backendObj);
132 if (backend == 0)
continue;
136 QSet<DeviceInterface::Type> supportedTypes = backend->supportedInterfaces();
137 if (supportedTypes.intersect(usedTypes).isEmpty()) {
142 udis+= QSet<QString>::fromList(backend->devicesFromQuery(parentUdi, type));
145 udis+= QSet<QString>::fromList(backend->allDevices());
148 foreach (
const QString &udi, udis)
152 bool matches =
false;
157 matches = predicate.
matches(dev);
172 return globalDeviceStorage->notifier();
175 void Solid::DeviceManagerPrivate::_k_deviceAdded(
const QString &udi)
177 if (m_devicesMap.contains(udi)) {
189 emit deviceAdded(udi);
192 void Solid::DeviceManagerPrivate::_k_deviceRemoved(
const QString &udi)
194 if (m_devicesMap.contains(udi)) {
195 DevicePrivate *dev = m_devicesMap[udi].data();
201 Q_ASSERT(dev->backendObject()!=0);
203 Q_ASSERT(dev->backendObject()==0);
207 emit deviceRemoved(udi);
210 void Solid::DeviceManagerPrivate::_k_destroyed(
QObject *
object)
212 QString udi = m_reverseMap.take(
object);
214 if (!udi.isEmpty()) {
215 m_devicesMap.remove(udi);
222 return m_nullDevice.data();
223 }
else if (m_devicesMap.contains(udi)) {
224 return m_devicesMap[udi].data();
226 Ifaces::Device *iface = createBackendObject(udi);
231 QWeakPointer<DevicePrivate> ptr(devData);
232 m_devicesMap[udi] = ptr;
233 m_reverseMap[devData] = udi;
235 connect(devData, SIGNAL(destroyed(
QObject*)),
236 this, SLOT(_k_destroyed(
QObject*)));
242 Solid::Ifaces::Device *Solid::DeviceManagerPrivate::createBackendObject(
const QString &udi)
244 QList<QObject*> backends = globalDeviceStorage->managerBackends();
246 foreach (
QObject *backendObj, backends) {
247 Ifaces::DeviceManager *backend = qobject_cast<Ifaces::DeviceManager *>(backendObj);
249 if (backend == 0)
continue;
250 if (!udi.startsWith(backend->udiPrefix()))
continue;
252 Ifaces::Device *iface = 0;
254 QObject *
object = backend->createDevice(udi);
255 iface = qobject_cast<Ifaces::Device *>(object);
274 ensureManagerCreated();
275 return m_storage.localData()->managerBackends();
280 ensureManagerCreated();
281 return m_storage.localData();
284 void Solid::DeviceManagerStorage::ensureManagerCreated()
286 if (!m_storage.hasLocalData()) {
291 #include "devicenotifier.moc" 292 #include "devicemanager_p.moc"
bool isValid() const
Indicates if the predicate is valid.
This class allows applications to deal with devices available in the underlying system.
#define SOLID_GLOBAL_STATIC(TYPE, NAME)
QList< QObject * > managerBackends() const
static QList< Device > listFromQuery(const QString &predicate, const QString &parentUdi=QString())
Convenience function see above.
Type
This enum type defines the type of device interface that a Device can have.
static DeviceNotifier * instance()
bool matches(const Device &device) const
Checks if a device matches the predicate.
static QList< Device > listFromQuery(const Predicate &predicate, const QString &parentUdi=QString())
Retrieves a list of devices of the system given matching the given constraints (parent and predicate)...
static Predicate fromString(const QString &predicate)
Converts a string to a predicate.
QList< QObject * > managerBackends()
DevicePrivate * findRegisteredDevice(const QString &udi)
Ifaces::Device * backendObject() const
static QList< Device > listFromType(const DeviceInterface::Type &type, const QString &parentUdi=QString())
Retrieves a list of devices of the system given matching the given constraints (parent and device int...
QSet< DeviceInterface::Type > usedTypes() const
Retrieves the device interface types used in this predicate.
static QList< Device > allDevices()
Retrieves all the devices available in the underlying system.
This class allow to query the underlying system to obtain information about the hardware available...
This class implements predicates for devices.
DeviceNotifier * notifier()
void setBackendObject(Ifaces::Device *object)