2008-09-16 166 views
4

我在PropertyNotified信號期間從我的處理函數調用org.freedesktop.Hal.Device上的GetProperty。我只調用已添加或更改的屬性的GetProperty。何時更新hal屬性

當我在屬性添加過程中調用GetProperty時,我得到一個org.freedesktop.Hal.NoSuchProperty異常。我也擔心在變化過程中,我會獲得舊的價值觀。

什麼時候應該調用GetProperty?涉及哪些競賽條件?

回答

1

如何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