我在 PropertyNotified 信号期间从我的处理程序调用 org.freedesktop.Hal.Device 上的 GetProperty。我只在已添加或更改的属性上调用 GetProperty。
当我在属性添加期间调用 GetProperty 时,我收到 org.freedesktop.Hal.NoSuchProperty 异常。我还担心在更改期间,我会得到旧值。
我应该什么时候调用 GetProperty?涉及哪些竞争条件?
最佳答案
DeviceExists 方法如何(如 here ):
if device.PropertyExists('info.product'):
return device.GetProperty('info.product')
return "unknown"
和 PropertyModified 信号,( ex from real world ):
#
# _CBHalDeviceConnected
#
# INTERNAL
#
# Callback triggered when a device is connected through Hal.
#
def _CBHalDeviceConnected(self, obj_path):
...
self.device.connect_to_signal("PropertyModified",
self._CBHalDeviceAuthStateChanged)
...
#
# _CBHalDeviceAuthStateChanged
#
# INTERNAL
#
# Callback triggered when a Hal device property is changed,
# for checking authorization state changes
#
def _CBHalDeviceAuthStateChanged(self,num_changes,properties):
for property in properties:
property_name, added, removed = property
if property_name == "pda.pocketpc.password":
self.logger.info("_CBHalDeviceAuthStateChanged:
device authorization state changed: reauthorizing")
self._ProcessAuth()
HAL 0.5.10 Specification
D-Bus Specification
D-Bus Tutorial
关于dbus - hal 属性什么时候更新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/69744/