/* Copyright 2012 Patrick von Reth Copyright 2005,2006 Kevin Ottens 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 . */ #include "wmimanager.h" #include #include "wmidevice.h" #include "wmideviceinterface.h" #include "wmiquery.h" using namespace Solid::Backends::Wmi; class Solid::Backends::Wmi::WmiManagerPrivate { public: WmiManagerPrivate(WmiManager *parent) :m_parent(parent) { supportedInterfaces << Solid::DeviceInterface::GenericInterface << Solid::DeviceInterface::Processor // << Solid::DeviceInterface::Block << Solid::DeviceInterface::StorageAccess << Solid::DeviceInterface::StorageDrive << Solid::DeviceInterface::OpticalDrive << Solid::DeviceInterface::StorageVolume << Solid::DeviceInterface::OpticalDisc // << Solid::DeviceInterface::Camera // << Solid::DeviceInterface::PortableMediaPlayer // << Solid::DeviceInterface::NetworkInterface << Solid::DeviceInterface::AcAdapter << Solid::DeviceInterface::Battery // << Solid::DeviceInterface::Button // << Solid::DeviceInterface::AudioInterface // << Solid::DeviceInterface::DvbInterface // << Solid::DeviceInterface::Video // << Solid::DeviceInterface::SerialInterface // << Solid::DeviceInterface::SmartCardReader ; update(); } ~WmiManagerPrivate() { } void update(){ init(); } void init(){ if(m_deviceCache.isEmpty()) { foreach(const Solid::DeviceInterface::Type &dev, supportedInterfaces){ updateDeviceCache(dev); } } } void updateDeviceCache(const Solid::DeviceInterface::Type & type){ QSet devSet = m_parent->findDeviceByDeviceInterface(type).toSet(); if(m_deviceCache.contains(type)){ QSet added = devSet - m_deviceCache[type]; foreach(const QString & s,added){ m_parent->slotDeviceAdded(s); } QSet removed = m_deviceCache[type] - devSet; foreach(const QString & s,removed){ m_parent->slotDeviceRemoved(s); } } m_deviceCache[type] = devSet; } WmiQuery::ItemList sendQuery( const QString &wql ) { return WmiQuery::instance().sendQuery( wql ); } WmiManager *m_parent; QSet supportedInterfaces; QMap > m_deviceCache; }; WmiManager::WmiManager(QObject *parent) : DeviceManager(parent) { d = new WmiManagerPrivate(this); QList types; types< WmiManager::supportedInterfaces() const { return d->supportedInterfaces; } QStringList WmiManager::allDevices() { QStringList list; foreach(const Solid::DeviceInterface::Type &type,d->supportedInterfaces){ list<m_deviceCache[type].toList(); } return list; } bool WmiManager::deviceExists(const QString &udi) { return WmiDevice::exists(udi); } QStringList WmiManager::devicesFromQuery(const QString &parentUdi, Solid::DeviceInterface::Type type) { QStringList result; if (!parentUdi.isEmpty()) { foreach(const QString &udi,allDevices()){ WmiDevice device(udi); if(device.type() == type && device.parentUdi() == parentUdi ){ result< &types): m_parent(parent), m_query(query), m_types(types), m_count(0) {} WmiManager::WmiEventSink::~WmiEventSink() {} ulong STDMETHODCALLTYPE WmiManager::WmiEventSink::AddRef() { return InterlockedIncrement(&m_count); } ulong STDMETHODCALLTYPE WmiManager::WmiEventSink::Release() { long lRef = InterlockedDecrement(&m_count); if(lRef == 0) delete this; return lRef; } HRESULT STDMETHODCALLTYPE WmiManager::WmiEventSink::QueryInterface(REFIID riid, void** ppv) { if (riid == IID_IUnknown || riid == IID_IWbemObjectSink) { *ppv = (IWbemObjectSink *) this; AddRef(); return WBEM_S_NO_ERROR; } else return E_NOINTERFACE; } HRESULT STDMETHODCALLTYPE WmiManager::WmiEventSink::Indicate(long lObjectCount,IWbemClassObject **apObjArray) { foreach(const Solid::DeviceInterface::Type &type,m_types){ m_parent->d->updateDeviceCache(type); } return WBEM_S_NO_ERROR; } HRESULT STDMETHODCALLTYPE WmiManager::WmiEventSink::SetStatus(long lFlags,HRESULT hResult,BSTR strParam,IWbemClassObject *pObjParam) { return WBEM_S_NO_ERROR; } const QString& WmiManager::WmiEventSink::query() const { return m_query; } //#include "backends/wmi/wmimanager.moc"