Add key device monitoring support

pull/16/head
Timothy Pearson 13 years ago
parent fde8fcb186
commit 632a87af39

@ -94,7 +94,7 @@ TDESensorCluster::TDESensorCluster() {
critical = -1; critical = -1;
} }
TDEGenericDevice::TDEGenericDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) { TDEGenericDevice::TDEGenericDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TQObject() {
m_deviceType = dt; m_deviceType = dt;
m_deviceName = dn; m_deviceName = dn;
@ -1554,6 +1554,7 @@ void TDEMonitorDevice::internalSetPowerLevel(TDEDisplayPowerLevel::TDEDisplayPow
TDEEventDevice::TDEEventDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { TDEEventDevice::TDEEventDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
m_fd = -1; m_fd = -1;
m_fdMonitorActive = false;
} }
TDEEventDevice::~TDEEventDevice() { TDEEventDevice::~TDEEventDevice() {
@ -1639,6 +1640,29 @@ TQStringList TDEEventDevice::friendlySwitchList(TDESwitchType::TDESwitchType swi
return ret; return ret;
} }
void TDEEventDevice::internalStartFdMonitoring(TDEHardwareDevices* hwmanager) {
if (!m_fdMonitorActive) {
// For security and performance reasons, only monitor known ACPI buttons
if (eventType() != TDEEventDeviceType::Unknown) {
m_eventNotifier = new TQSocketNotifier(m_fd, TQSocketNotifier::Read, this);
connect( m_eventNotifier, TQT_SIGNAL(activated(int)), this, TQT_SLOT(eventReceived()) );
connect( this, TQT_SIGNAL(keyPressed(unsigned int, TDEEventDevice*)), hwmanager, TQT_SLOT(processEventDeviceKeyPressed(unsigned int, TDEEventDevice*)) );
}
m_fdMonitorActive = true;
}
}
void TDEEventDevice::eventReceived() {
struct input_event ev;
int r;
r = read(m_fd, &ev, sizeof(struct input_event));
if (r > 0) {
if (ev.type == EV_KEY) {
emit keyPressed(ev.code, this);
}
}
}
TDEInputDevice::TDEInputDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) { TDEInputDevice::TDEInputDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
} }
@ -2073,13 +2097,17 @@ void TDEHardwareDevices::processStatelessDevices() {
// We can't use m_deviceList directly as m_deviceList can only have one iterator active against it at any given time // We can't use m_deviceList directly as m_deviceList can only have one iterator active against it at any given time
TDEGenericHardwareList devList = listAllPhysicalDevices(); TDEGenericHardwareList devList = listAllPhysicalDevices();
for ( hwdevice = devList.first(); hwdevice; hwdevice = devList.next() ) { for ( hwdevice = devList.first(); hwdevice; hwdevice = devList.next() ) {
if ((hwdevice->type() == TDEGenericDeviceType::RootSystem) || (hwdevice->type() == TDEGenericDeviceType::Network) || (hwdevice->type() == TDEGenericDeviceType::OtherSensor) || (hwdevice->type() == TDEGenericDeviceType::Event)) { if ((hwdevice->type() == TDEGenericDeviceType::RootSystem) || (hwdevice->type() == TDEGenericDeviceType::Network) || (hwdevice->type() == TDEGenericDeviceType::OtherSensor) || (hwdevice->type() == TDEGenericDeviceType::Event) || (hwdevice->type() == TDEGenericDeviceType::Battery) || (hwdevice->type() == TDEGenericDeviceType::PowerSupply)) {
rescanDeviceInformation(hwdevice); rescanDeviceInformation(hwdevice);
emit hardwareUpdated(hwdevice); emit hardwareUpdated(hwdevice);
} }
} }
} }
void TDEHardwareDevices::processEventDeviceKeyPressed(unsigned int keycode, TDEEventDevice* edevice) {
emit eventDeviceKeyPressed(keycode, edevice);
}
void TDEHardwareDevices::processModifiedMounts() { void TDEHardwareDevices::processModifiedMounts() {
// Detect what changed between the old mount table and the new one, // Detect what changed between the old mount table and the new one,
// and emit appropriate events // and emit appropriate events
@ -2861,6 +2889,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD
// Pull out all event special devices and stuff them under Event // Pull out all event special devices and stuff them under Event
TQString syspath_tail = systempath.lower(); TQString syspath_tail = systempath.lower();
syspath_tail.truncate(syspath_tail.length()-1);
syspath_tail.remove(0, syspath_tail.findRev("/")+1); syspath_tail.remove(0, syspath_tail.findRev("/")+1);
if (syspath_tail.startsWith("event")) { if (syspath_tail.startsWith("event")) {
if (!device) device = new TDEEventDevice(TDEGenericDeviceType::Event); if (!device) device = new TDEEventDevice(TDEGenericDeviceType::Event);
@ -3713,7 +3742,11 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD
} }
// Calculate time remaining // Calculate time remaining
bdevice->internalSetTimeRemaining(bdevice->energy()*bdevice->dischargeRate()*60); // Discharge rate is in watt-hours
// Energy is in watt-hours
// Therefore, energy/rate = time in hours
// Convert to seconds...
bdevice->internalSetTimeRemaining((bdevice->energy()/bdevice->dischargeRate())*60*60);
} }
if (device->type() == TDEGenericDeviceType::PowerSupply) { if (device->type() == TDEGenericDeviceType::PowerSupply) {
@ -3987,7 +4020,7 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD
else if (edevice->systemPath().contains("PNP0C0E")) { else if (edevice->systemPath().contains("PNP0C0E")) {
edevice->internalSetEventType(TDEEventDeviceType::ACPISleepButton); edevice->internalSetEventType(TDEEventDeviceType::ACPISleepButton);
} }
else if (edevice->systemPath().contains("PNP0C0C")) { else if (edevice->systemPath().contains("PNP0C0C") || edevice->systemPath().contains("/LNXPWRBN")) {
edevice->internalSetEventType(TDEEventDeviceType::ACPIPowerButton); edevice->internalSetEventType(TDEEventDeviceType::ACPIPowerButton);
} }
else { else {
@ -4122,6 +4155,8 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD
#endif #endif
} }
edevice->internalSetActiveSwitches(activeSwitches); edevice->internalSetActiveSwitches(activeSwitches);
edevice->internalStartFdMonitoring(this);
} }
// Root devices are still special // Root devices are still special

@ -191,8 +191,10 @@ class TDECORE_EXPORT TDESensorCluster
double critical; double critical;
}; };
class TDECORE_EXPORT TDEGenericDevice class TDECORE_EXPORT TDEGenericDevice : public TQObject
{ {
Q_OBJECT
public: public:
/** /**
* Constructor. * Constructor.
@ -916,7 +918,7 @@ class TDECORE_EXPORT TDEBatteryDevice : public TDEGenericDevice
double maximumDesignEnergy(); double maximumDesignEnergy();
/** /**
* @return a double with the current battery discharge rate in volt-hours, if available * @return a double with the current battery discharge rate in watt-hours, if available
*/ */
double dischargeRate(); double dischargeRate();
@ -1693,8 +1695,12 @@ inline TDESwitchType operator~(TDESwitchType a)
} }
}; };
class TQSocketNotifier;
class TDECORE_EXPORT TDEEventDevice : public TDEGenericDevice class TDECORE_EXPORT TDEEventDevice : public TDEGenericDevice
{ {
Q_OBJECT
public: public:
/** /**
* Constructor. * Constructor.
@ -1747,12 +1753,31 @@ class TDECORE_EXPORT TDEEventDevice : public TDEGenericDevice
*/ */
void internalSetActiveSwitches(TDESwitchType::TDESwitchType sl); void internalSetActiveSwitches(TDESwitchType::TDESwitchType sl);
/**
* @param hwmanager the master hardware manager
* @internal
*/
void internalStartFdMonitoring(TDEHardwareDevices* hwmanager);
protected slots:
void eventReceived();
signals:
/**
* @param keycode the code of the key that was pressed/released
* See include/linux/input.h for a complete list of keycodes
* @param device a TDEEventDevice* with the device that received the event
*/
void keyPressed(unsigned int keycode, TDEEventDevice* device);
private: private:
TDEEventDeviceType::TDEEventDeviceType m_eventType; TDEEventDeviceType::TDEEventDeviceType m_eventType;
TDESwitchType::TDESwitchType m_providedSwitches; TDESwitchType::TDESwitchType m_providedSwitches;
TDESwitchType::TDESwitchType m_switchActive; TDESwitchType::TDESwitchType m_switchActive;
int m_fd; int m_fd;
bool m_fdMonitorActive;
TQSocketNotifier* m_eventNotifier;
friend class TDEHardwareDevices; friend class TDEHardwareDevices;
}; };
@ -1802,7 +1827,6 @@ class TDECORE_EXPORT TDEInputDevice : public TDEGenericDevice
typedef TQPtrList<TDEGenericDevice> TDEGenericHardwareList; typedef TQPtrList<TDEGenericDevice> TDEGenericHardwareList;
typedef TQMap<TQString, TQString> TDEDeviceIDMap; typedef TQMap<TQString, TQString> TDEDeviceIDMap;
class TQSocketNotifier;
class KSimpleDirWatch; class KSimpleDirWatch;
class TDECORE_EXPORT TDEHardwareDevices : public TQObject class TDECORE_EXPORT TDEHardwareDevices : public TQObject
@ -1944,11 +1968,19 @@ class TDECORE_EXPORT TDEHardwareDevices : public TQObject
void hardwareUpdated(TDEGenericDevice*); void hardwareUpdated(TDEGenericDevice*);
void mountTableModified(); void mountTableModified();
/**
* @param keycode the code of the key that was pressed/released
* See include/linux/input.h for a complete list of keycodes
* @param device a TDEEventDevice* with the device that received the event
*/
void eventDeviceKeyPressed(unsigned int keycode, TDEEventDevice* device);
private slots: private slots:
void processHotPluggedHardware(); void processHotPluggedHardware();
void processModifiedMounts(); void processModifiedMounts();
void processModifiedCPUs(); void processModifiedCPUs();
void processStatelessDevices(); void processStatelessDevices();
void processEventDeviceKeyPressed(unsigned int keycode, TDEEventDevice* edevice);
private: private:
void updateBlacklists(TDEGenericDevice* hwdevice, udev_device* dev); void updateBlacklists(TDEGenericDevice* hwdevice, udev_device* dev);

Loading…
Cancel
Save