00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "device.h"
00021 #include "device_p.h"
00022 #include "devicenotifier.h"
00023 #include "devicemanager_p.h"
00024
00025 #include "deviceinterface_p.h"
00026 #include "soliddefs_p.h"
00027
00028 #include <solid/ifaces/device.h>
00029
00030 #include <solid/genericinterface.h>
00031 #include <solid/ifaces/genericinterface.h>
00032 #include <solid/processor.h>
00033 #include <solid/ifaces/processor.h>
00034 #include <solid/block.h>
00035 #include <solid/ifaces/block.h>
00036 #include <solid/storageaccess.h>
00037 #include <solid/ifaces/storageaccess.h>
00038 #include <solid/storagedrive.h>
00039 #include <solid/ifaces/storagedrive.h>
00040 #include <solid/opticaldrive.h>
00041 #include <solid/ifaces/opticaldrive.h>
00042 #include <solid/storagevolume.h>
00043 #include <solid/ifaces/storagevolume.h>
00044 #include <solid/opticaldisc.h>
00045 #include <solid/ifaces/opticaldisc.h>
00046 #include <solid/camera.h>
00047 #include <solid/ifaces/camera.h>
00048 #include <solid/portablemediaplayer.h>
00049 #include <solid/ifaces/portablemediaplayer.h>
00050 #include <solid/networkinterface.h>
00051 #include <solid/ifaces/networkinterface.h>
00052 #include <solid/acadapter.h>
00053 #include <solid/ifaces/acadapter.h>
00054 #include <solid/battery.h>
00055 #include <solid/ifaces/battery.h>
00056 #include <solid/button.h>
00057 #include <solid/ifaces/button.h>
00058 #include <solid/audiointerface.h>
00059 #include <solid/ifaces/audiointerface.h>
00060 #include <solid/dvbinterface.h>
00061 #include <solid/ifaces/dvbinterface.h>
00062 #include <solid/video.h>
00063 #include <solid/ifaces/video.h>
00064
00065
00066 Solid::Device::Device(const QString &udi)
00067 {
00068 DeviceManagerPrivate *manager
00069 = static_cast<DeviceManagerPrivate *>(Solid::DeviceNotifier::instance());
00070 d = manager->findRegisteredDevice(udi);
00071 }
00072
00073 Solid::Device::Device(const Device &device)
00074 : d(device.d)
00075 {
00076 }
00077
00078 Solid::Device::~Device()
00079 {
00080 }
00081
00082 Solid::Device &Solid::Device::operator=(const Solid::Device &device)
00083 {
00084 d = device.d;
00085 return *this;
00086 }
00087
00088 bool Solid::Device::isValid() const
00089 {
00090 return d->backendObject()!=0;
00091 }
00092
00093 QString Solid::Device::udi() const
00094 {
00095 return d->udi();
00096 }
00097
00098 QString Solid::Device::parentUdi() const
00099 {
00100 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), parentUdi());
00101 }
00102
00103 Solid::Device Solid::Device::parent() const
00104 {
00105 QString udi = parentUdi();
00106
00107 if (udi.isEmpty())
00108 {
00109 return Device();
00110 }
00111 else
00112 {
00113 return Device(udi);
00114 }
00115 }
00116
00117 QString Solid::Device::vendor() const
00118 {
00119 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), vendor());
00120 }
00121
00122 QString Solid::Device::product() const
00123 {
00124 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), product());
00125 }
00126
00127 QString Solid::Device::icon() const
00128 {
00129 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), icon());
00130 }
00131
00132 bool Solid::Device::isDeviceInterface(const DeviceInterface::Type &type) const
00133 {
00134 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), false, queryDeviceInterface(type));
00135 }
00136
00137 #define deviceinterface_cast(IfaceType, DevType, backendObject) \
00138 (qobject_cast<IfaceType *>(backendObject) ? new DevType(backendObject) : 0)
00139
00140 Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type)
00141 {
00142 const Solid::DeviceInterface *interface = const_cast<const Device *>(this)->asDeviceInterface(type);
00143 return const_cast<Solid::DeviceInterface *>(interface);
00144 }
00145
00146 const Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type) const
00147 {
00148 Ifaces::Device *device = qobject_cast<Ifaces::Device *>(d->backendObject());
00149
00150 if (device!=0)
00151 {
00152 DeviceInterface *iface = d->interface(type);
00153
00154 if (iface!=0) {
00155 return iface;
00156 }
00157
00158 QObject *dev_iface = device->createDeviceInterface(type);
00159
00160 if (dev_iface!=0)
00161 {
00162 switch (type)
00163 {
00164 case DeviceInterface::GenericInterface:
00165 iface = deviceinterface_cast(Ifaces::GenericInterface, GenericInterface, dev_iface);
00166 break;
00167 case DeviceInterface::Processor:
00168 iface = deviceinterface_cast(Ifaces::Processor, Processor, dev_iface);
00169 break;
00170 case DeviceInterface::Block:
00171 iface = deviceinterface_cast(Ifaces::Block, Block, dev_iface);
00172 break;
00173 case DeviceInterface::StorageAccess:
00174 iface = deviceinterface_cast(Ifaces::StorageAccess, StorageAccess, dev_iface);
00175 break;
00176 case DeviceInterface::StorageDrive:
00177 iface = deviceinterface_cast(Ifaces::StorageDrive, StorageDrive, dev_iface);
00178 break;
00179 case DeviceInterface::OpticalDrive:
00180 iface = deviceinterface_cast(Ifaces::OpticalDrive, OpticalDrive, dev_iface);
00181 break;
00182 case DeviceInterface::StorageVolume:
00183 iface = deviceinterface_cast(Ifaces::StorageVolume, StorageVolume, dev_iface);
00184 break;
00185 case DeviceInterface::OpticalDisc:
00186 iface = deviceinterface_cast(Ifaces::OpticalDisc, OpticalDisc, dev_iface);
00187 break;
00188 case DeviceInterface::Camera:
00189 iface = deviceinterface_cast(Ifaces::Camera, Camera, dev_iface);
00190 break;
00191 case DeviceInterface::PortableMediaPlayer:
00192 iface = deviceinterface_cast(Ifaces::PortableMediaPlayer, PortableMediaPlayer, dev_iface);
00193 break;
00194 case DeviceInterface::NetworkInterface:
00195 iface = deviceinterface_cast(Ifaces::NetworkInterface, NetworkInterface, dev_iface);
00196 break;
00197 case DeviceInterface::AcAdapter:
00198 iface = deviceinterface_cast(Ifaces::AcAdapter, AcAdapter, dev_iface);
00199 break;
00200 case DeviceInterface::Battery:
00201 iface = deviceinterface_cast(Ifaces::Battery, Battery, dev_iface);
00202 break;
00203 case DeviceInterface::Button:
00204 iface = deviceinterface_cast(Ifaces::Button, Button, dev_iface);
00205 break;
00206 case DeviceInterface::AudioInterface:
00207 iface = deviceinterface_cast(Ifaces::AudioInterface, AudioInterface, dev_iface);
00208 break;
00209 case DeviceInterface::DvbInterface:
00210 iface = deviceinterface_cast(Ifaces::DvbInterface, DvbInterface, dev_iface);
00211 break;
00212 case DeviceInterface::Video:
00213 iface = deviceinterface_cast(Ifaces::Video, Video, dev_iface);
00214 break;
00215 case DeviceInterface::Unknown:
00216 break;
00217 }
00218 }
00219
00220 if (iface!=0)
00221 {
00222
00223 const_cast<Device *>(this)->d->setInterface(type, iface);
00224 }
00225
00226 return iface;
00227 }
00228 else
00229 {
00230 return 0;
00231 }
00232 }
00233
00234
00236
00237
00238 Solid::DevicePrivate::DevicePrivate(const QString &udi)
00239 : QObject(), QSharedData(), m_udi(udi)
00240 {
00241 }
00242
00243 Solid::DevicePrivate::~DevicePrivate()
00244 {
00245 qDeleteAll(m_ifaces.values());
00246 }
00247
00248 void Solid::DevicePrivate::_k_destroyed(QObject *object)
00249 {
00250 Q_UNUSED(object);
00251 setBackendObject(0);
00252 }
00253
00254 void Solid::DevicePrivate::setBackendObject(Ifaces::Device *object)
00255 {
00256 m_backendObject = object;
00257
00258 if (m_backendObject) {
00259 connect(m_backendObject, SIGNAL(destroyed(QObject *)),
00260 this, SLOT(_k_destroyed(QObject *)));
00261 }
00262
00263 if (!m_ifaces.isEmpty()) {
00264 foreach (DeviceInterface *iface, m_ifaces) {
00265 delete iface->d_ptr->backendObject();
00266 delete iface;
00267 }
00268
00269 m_ifaces.clear();
00270
00271 if (!ref.deref()) deleteLater();
00272 }
00273 }
00274
00275 Solid::DeviceInterface *Solid::DevicePrivate::interface(const DeviceInterface::Type &type) const
00276 {
00277 return m_ifaces[type];
00278 }
00279
00280 void Solid::DevicePrivate::setInterface(const DeviceInterface::Type &type, DeviceInterface *interface)
00281 {
00282 ref.ref();
00283 m_ifaces[type] = interface;
00284 }
00285
00286 #include "device_p.moc"