Conver TDE hardware library to fully event driven operation

pull/16/head
Timothy Pearson 13 years ago
parent b28ee4be1c
commit 9dff87031a

@ -21,6 +21,7 @@
#include <tqfile.h> #include <tqfile.h>
#include <tqdir.h> #include <tqdir.h>
#include <tqstringlist.h> #include <tqstringlist.h>
#include <tqsocketnotifier.h>
#include <kglobal.h> #include <kglobal.h>
#include <ktempfile.h> #include <ktempfile.h>
@ -382,14 +383,13 @@ TDEHardwareDevices::TDEHardwareDevices() {
udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitorStruct, NULL, NULL); udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitorStruct, NULL, NULL);
udev_monitor_enable_receiving(m_udevMonitorStruct); udev_monitor_enable_receiving(m_udevMonitorStruct);
m_devScanTimer = new TQTimer(); m_devScanNotifier = new TQSocketNotifier(udev_monitor_get_fd(m_udevMonitorStruct), TQSocketNotifier::Read, this);
connect( m_devScanTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(checkForHotPluggedHardware()) ); connect( m_devScanNotifier, TQT_SIGNAL(activated(int)), this, TQT_SLOT(processHotPluggedHardware()) );
m_devScanTimer->start(1, TRUE);
// Monitor for changed mounts // Monitor for changed mounts
m_mountScanTimer = new TQTimer(); m_procMountsFd = open("/proc/mounts", O_RDONLY, 0);
connect( m_mountScanTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(checkForModifiedMounts()) ); m_mountScanNotifier = new TQSocketNotifier(m_procMountsFd, TQSocketNotifier::Exception, this);
m_mountScanTimer->start(1, TRUE); connect( m_mountScanNotifier, TQT_SIGNAL(activated(int)), this, TQT_SLOT(processModifiedMounts()) );
// Update internal device information // Update internal device information
queryHardwareInformation(); queryHardwareInformation();
@ -397,13 +397,8 @@ TDEHardwareDevices::TDEHardwareDevices() {
} }
TDEHardwareDevices::~TDEHardwareDevices() { TDEHardwareDevices::~TDEHardwareDevices() {
// Stop hardware scanning
m_devScanTimer->stop();
delete m_devScanTimer;
// Stop mount scanning // Stop mount scanning
m_mountScanTimer->stop(); close(m_procMountsFd);
delete m_mountScanTimer;
// Tear down udev interface // Tear down udev interface
udev_unref(m_udevStruct); udev_unref(m_udevStruct);
@ -434,11 +429,11 @@ TDEStorageDevice* TDEHardwareDevices::findDiskByUID(TQString uid) {
return 0; return 0;
} }
void TDEHardwareDevices::checkForHotPluggedHardware() { void TDEHardwareDevices::processHotPluggedHardware() {
udev_device* dev = udev_monitor_receive_device(m_udevMonitorStruct); udev_device* dev = udev_monitor_receive_device(m_udevMonitorStruct);
if (dev) { if (dev) {
TQString actionevent(udev_device_get_action(dev)); TQString actionevent(udev_device_get_action(dev));
if (actionevent == "add") { if (actionevent == "add") {
TDEGenericDevice* device = classifyUnknownDevice(dev); TDEGenericDevice* device = classifyUnknownDevice(dev);
// Make sure this device is not a duplicate // Make sure this device is not a duplicate
@ -462,36 +457,21 @@ void TDEHardwareDevices::checkForHotPluggedHardware() {
TDEGenericDevice *hwdevice; TDEGenericDevice *hwdevice;
for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) { for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
if (hwdevice->systemPath() == systempath) { if (hwdevice->systemPath() == systempath) {
emit hardwareRemoved(*hwdevice);
m_deviceList.remove(hwdevice); m_deviceList.remove(hwdevice);
emit hardwareAdded(*hwdevice);
break; break;
} }
} }
} }
} }
// Continue scanning for added/removed hardware
m_devScanTimer->start(1, TRUE);
} }
void TDEHardwareDevices::checkForModifiedMounts() { void TDEHardwareDevices::processModifiedMounts() {
int mfd = open("/proc/mounts", O_RDONLY, 0); // FIXME
struct pollfd pfd; // Detect what changed between the old mount table and the new one,
int rv; // and emit appropriate events
pfd.fd = mfd;
pfd.events = POLLERR | POLLPRI;
pfd.revents = 0;
while ((rv = poll(&pfd, 1, 5)) >= 0) {
if (pfd.revents & POLLERR) {
emit mountTableModified();
}
pfd.revents = 0;
}
// Continue scanning for changed mounts emit mountTableModified();
m_mountScanTimer->start(1, TRUE);
} }
TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) { TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
@ -596,6 +576,13 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
disktype = disktype | TDEDiskDeviceType::Zip; disktype = disktype | TDEDiskDeviceType::Zip;
} }
if ((devicevendor.upper() == "APPLE") && (devicemodel.upper().contains("IPOD"))) {
disktype = disktype | TDEDiskDeviceType::MediaDevice;
}
if ((devicevendor.upper() == "SANDISK") && (devicemodel.upper().contains("SANSA"))) {
disktype = disktype | TDEDiskDeviceType::MediaDevice;
}
if (disktypestring.upper() == "FLOPPY") { if (disktypestring.upper() == "FLOPPY") {
disktype = disktype | TDEDiskDeviceType::Floppy; disktype = disktype | TDEDiskDeviceType::Floppy;
} }
@ -751,13 +738,37 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev) {
sdevice->setDiskType(disktype); sdevice->setDiskType(disktype);
sdevice->setDiskUUID(diskuuid); sdevice->setDiskUUID(diskuuid);
sdevice->setDiskLabel(disklabel);
sdevice->setDiskStatus(diskstatus); sdevice->setDiskStatus(diskstatus);
sdevice->setFileSystemName(filesystemtype); sdevice->setFileSystemName(filesystemtype);
sdevice->setFileSystemUsage(filesystemusage); sdevice->setFileSystemUsage(filesystemusage);
sdevice->setSlaveDevices(slaveDeviceNodes); sdevice->setSlaveDevices(slaveDeviceNodes);
sdevice->setHoldingDevices(holdingDeviceNodes); sdevice->setHoldingDevices(holdingDeviceNodes);
// Clean up disk label
if ((sdevice->isDiskOfType(TDEDiskDeviceType::CDROM))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDRW))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDROM))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDRW))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::BDROM))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::BDRW))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDVideo))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDVideo))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::BDVideo))
) {
if (disklabel == "") {
// Read the volume label in via volname, since udev couldn't be bothered to do this on its own
FILE *exepipe = popen((TQString("volname %1").arg(devicenode).ascii()), "r");
if (exepipe) {
char buffer[8092];
disklabel = fgets(buffer, sizeof(buffer), exepipe);
pclose(exepipe);
}
}
}
sdevice->setDiskLabel(disklabel);
printf("DISK DEVICE name: %s type: %s subsystem: %s vendor: %s model: %s bus: %s label: %s filesystem: %s disk type: %s disk type flags: 0x%08x media inserted: %d [Node Path: %s] [Syspath: %s]\n\r\n\r", devicename.ascii(), devicetype.ascii(), devicesubsystem.ascii(), devicevendor.ascii(), devicemodel.ascii(), devicebus.ascii(), disklabel.ascii(), filesystemtype.ascii(), disktypestring.ascii(), disktype, sdevice->mediaInserted(), devicenode.ascii(), udev_device_get_syspath(dev)); fflush(stdout); printf("DISK DEVICE name: %s type: %s subsystem: %s vendor: %s model: %s bus: %s label: %s filesystem: %s disk type: %s disk type flags: 0x%08x media inserted: %d [Node Path: %s] [Syspath: %s]\n\r\n\r", devicename.ascii(), devicetype.ascii(), devicesubsystem.ascii(), devicevendor.ascii(), devicemodel.ascii(), devicebus.ascii(), disklabel.ascii(), filesystemtype.ascii(), disktypestring.ascii(), disktype, sdevice->mediaInserted(), devicenode.ascii(), udev_device_get_syspath(dev)); fflush(stdout);
} }
else if (devicetype.isNull()) { else if (devicetype.isNull()) {

@ -19,10 +19,10 @@
#define _TDEHARDWAREDEVICES_H #define _TDEHARDWAREDEVICES_H
// TDE includes // TDE includes
#include <tqobject.h>
#include <tqstring.h> #include <tqstring.h>
#include <tqptrlist.h> #include <tqptrlist.h>
#include <tqstringlist.h> #include <tqstringlist.h>
#include <tqtimer.h>
#include "tdelibs_export.h" #include "tdelibs_export.h"
// udev includes // udev includes
@ -419,6 +419,8 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
typedef TQPtrList<TDEGenericDevice> TDEGenericHardwareList; typedef TQPtrList<TDEGenericDevice> TDEGenericHardwareList;
class TQSocketNotifier;
class TDECORE_EXPORT TDEHardwareDevices : TQObject class TDECORE_EXPORT TDEHardwareDevices : TQObject
{ {
Q_OBJECT Q_OBJECT
@ -470,8 +472,8 @@ class TDECORE_EXPORT TDEHardwareDevices : TQObject
void mountTableModified(); void mountTableModified();
private slots: private slots:
void checkForHotPluggedHardware(); void processHotPluggedHardware();
void checkForModifiedMounts(); void processModifiedMounts();
private: private:
TDEGenericDevice *classifyUnknownDevice(udev_device* dev); TDEGenericDevice *classifyUnknownDevice(udev_device* dev);
@ -479,9 +481,10 @@ class TDECORE_EXPORT TDEHardwareDevices : TQObject
struct udev *m_udevStruct; struct udev *m_udevStruct;
struct udev_monitor *m_udevMonitorStruct; struct udev_monitor *m_udevMonitorStruct;
TDEGenericHardwareList m_deviceList; TDEGenericHardwareList m_deviceList;
int m_procMountsFd;
TQTimer* m_devScanTimer; TQSocketNotifier* m_devScanNotifier;
TQTimer* m_mountScanTimer; TQSocketNotifier* m_mountScanNotifier;
}; };
#endif #endif
Loading…
Cancel
Save