4

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

当我在属性添加期间调用 GetProperty 时,我得到一个 org.freedesktop.Hal.NoSuchProperty 异常。我还担心在更改期间,我会获得旧值。

我应该什么时候调用 GetProperty?涉及哪些竞赛条件?

4

1 回答 1

1

How about DeviceExists method (like here):

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

And PropertyModified signal, (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

于 2009-03-03T10:54:31.747 回答