hal/examples locking.py,NONE,1.1

David Zeuthen david at freedesktop.org
Sun Sep 19 09:32:17 PDT 2004


Update of /cvs/hal/hal/examples
In directory gabe:/tmp/cvs-serv15910/examples

Added Files:
	locking.py 
Log Message:
2004-09-19  David Zeuthen  <david at fubar.dk>

	* hald/hald_dbus.c (agent_device_matches): Removed
	(agent_merge_properties): Removed
	(agent_manager_remove): Removed
	(agent_manager_commit_to_gdl): Removed
	(agent_manager_new_device): Removed
	(filter_function): Removed all the AgentManager methods
	(raise_udi_in_use): Removed

	* doc/spec/hal-spec.xml.in: Add docs for info.locked. Remove section
	about HAL agents as they are now gone. Fixed up renaming of scsi_device
	to scsi.

	* doc/spec/hal-arch.dia: Remove HAL Agents

	* doc/spec/hal-linux26.dia: Update diagram since we now use a local
	socket from hal.hotplug and hal.dev helpers.

	* examples/locking.py: New file; shows how to use locking



--- NEW FILE: locking.py ---
#!/usr/bin/python

# Simple program to test locking; will acquire a lock on the hal device
# object representing the computer.
#
# usage: locking.py <numsecs>

import dbus
import sys
import time
import os

dev_udi = "/org/freedesktop/Hal/devices/computer"
duration = int(sys.argv[1])
pid = os.getpid()
reason = "locking.py pid %d"%pid

bus = dbus.Bus(dbus.Bus.TYPE_SYSTEM)
hal_service = bus.get_service("org.freedesktop.Hal")

print "I am %s with pid %d"%(bus.get_connection().get_base_service(), pid)
print

dev = hal_service.get_object (dev_udi, "org.freedesktop.Hal.Device")

print "Attempting to lock %s for %d secs"%(dev_udi, duration)
print "with reason '%s'"%reason
print

try:
    dev.Lock(reason)
except Exception, e:
    print "Locking failed"
    reason =   dev.GetProperty("info.locked.reason")
    lock_svc = dev.GetProperty("info.locked.dbus_service")
    print "Reason:                   '%s'"%reason
    print "Locked by D-BUS basesvc:  '%s'"%lock_svc
    sys.exit(1)

print "Lock acquired; sleeping %d seconds"%duration    
time.sleep(duration)
print "Releasing lock"
dev.Unlock()
print "Lock released"




More information about the hal-commit mailing list