hal属性何时更新

时间:2020-03-05 18:55:14  来源:igfitidea点击:

我在PropertyNotified信号期间从处理程序在org.freedesktop.Hal.Device上调用GetProperty。我只在已添加或者更改的属性上调用GetProperty。

在属性添加过程中调用GetProperty时,出现了org.freedesktop.Hal.NoSuchProperty异常。我还担心在更改期间,我会获得旧的价值观。

我什么时候应该打电话给GetProperty?涉及哪些比赛条件?

解决方案

回答

关于DeviceExists方法(如此处)如何:

if device.PropertyExists('info.product'):
        return device.GetProperty('info.product')
    return "unknown"

和PropertyModified信号,(来自现实世界):

#
 # _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规格
D-Bus规格
D-Bus教程