aboutsummaryrefslogtreecommitdiff
path: root/smartpenmanager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'smartpenmanager.cc')
-rw-r--r--smartpenmanager.cc23
1 files changed, 17 insertions, 6 deletions
diff --git a/smartpenmanager.cc b/smartpenmanager.cc
index 1eeb685..d375fea 100644
--- a/smartpenmanager.cc
+++ b/smartpenmanager.cc
@@ -197,9 +197,8 @@ void SmartpenManager::handleTimerNextTry()
void SmartpenManager::processDeviceAdded(udev_device *dev)
{
- uint busnum = atol(udev_device_get_sysattr_value(dev, "busnum"));
- uint devnum = atol(udev_device_get_sysattr_value(dev, "devnum"));
- Smartpen::Address addr(busnum, devnum);
+ Smartpen::Address addr = getDeviceAddress(dev);
+ if (!addr.first && !addr.second) return;
QString name = parseUdevEscapedString(udev_device_get_property_value(dev, "ID_MODEL_ENC"));
@@ -223,9 +222,8 @@ void SmartpenManager::processDeviceAdded(udev_device *dev)
void SmartpenManager::processDeviceRemoved(udev_device *dev)
{
- uint busnum = atol(udev_device_get_sysattr_value(dev, "busnum"));
- uint devnum = atol(udev_device_get_sysattr_value(dev, "devnum"));
- Smartpen::Address addr(busnum, devnum);
+ Smartpen::Address addr = getDeviceAddress(dev);
+ if (!addr.first && !addr.second) return;
qDebug() << "Device removed with address:" << addr;
@@ -325,3 +323,16 @@ QString SmartpenManager::parseUdevEscapedString(const char *s)
}
return r;
}
+
+Smartpen::Address SmartpenManager::getDeviceAddress(udev_device *dev)
+{
+ const char *busnumS = udev_device_get_property_value(dev, "BUSNUM");
+ const char *devnumS = udev_device_get_property_value(dev, "DEVNUM");
+ if (!busnumS || !devnumS) {
+ qWarning() << "Cannot find busnum/devnum env var for udev device";
+ return Smartpen::Address();
+ }
+ uint busnum = atol(busnumS);
+ uint devnum = atol(devnumS);
+ return Smartpen::Address(busnum, devnum);
+}