<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://alteeve.com/w/index.php?action=history&amp;feed=atom&amp;title=Sample_Script%3A_client.pl</id>
	<title>Sample Script: client.pl - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://alteeve.com/w/index.php?action=history&amp;feed=atom&amp;title=Sample_Script%3A_client.pl"/>
	<link rel="alternate" type="text/html" href="https://alteeve.com/w/index.php?title=Sample_Script:_client.pl&amp;action=history"/>
	<updated>2026-05-14T04:32:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://alteeve.com/w/index.php?title=Sample_Script:_client.pl&amp;diff=421&amp;oldid=prev</id>
		<title>Digimer at 01:36, 12 October 2009</title>
		<link rel="alternate" type="text/html" href="https://alteeve.com/w/index.php?title=Sample_Script:_client.pl&amp;diff=421&amp;oldid=prev"/>
		<updated>2009-10-12T01:36:32Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:36, 12 October 2009&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l7&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# connect to a bus and interact with existing methods and catch signals.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# connect to a bus and interact with existing methods and catch signals.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Author: Madison Kelly (&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;digimer&lt;/del&gt;@&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tle-bu&lt;/del&gt;.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;org&lt;/del&gt;).&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Author: Madison Kelly (&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;mkelly&lt;/ins&gt;@&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;alteeve&lt;/ins&gt;.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;com&lt;/ins&gt;).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key an_wiki-mediawiki-:diff:1.41:old-420:rev-421:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Digimer</name></author>
	</entry>
	<entry>
		<id>https://alteeve.com/w/index.php?title=Sample_Script:_client.pl&amp;diff=420&amp;oldid=prev</id>
		<title>Digimer: Created page with &#039;{{dbtut_header}}  &lt;source lang=&quot;perl&quot;&gt; #!/usr/bin/perl # # This is a sample script that shows how to use the Net::DBus bindings to # connect to a bus and interact with existing m…&#039;</title>
		<link rel="alternate" type="text/html" href="https://alteeve.com/w/index.php?title=Sample_Script:_client.pl&amp;diff=420&amp;oldid=prev"/>
		<updated>2009-10-12T01:28:58Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;{{dbtut_header}}  &amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt; #!/usr/bin/perl # # This is a sample script that shows how to use the Net::DBus bindings to # connect to a bus and interact with existing m…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Páàjì titun&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{dbtut_header}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/perl&lt;br /&gt;
#&lt;br /&gt;
# This is a sample script that shows how to use the Net::DBus bindings to&lt;br /&gt;
# connect to a bus and interact with existing methods and catch signals.&lt;br /&gt;
#&lt;br /&gt;
# Author: Madison Kelly (digimer@tle-bu.org).&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
use utf8;&lt;br /&gt;
use Net::DBus;&lt;br /&gt;
use Net::DBus::Reactor;&lt;br /&gt;
&lt;br /&gt;
print &amp;quot;Starting the client.\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# Connect to the system bus.&lt;br /&gt;
my $bus = Net::DBus-&amp;gt;system;&lt;br /&gt;
&lt;br /&gt;
# Connect to the &amp;#039;Hal&amp;#039; service on the system bus.&lt;br /&gt;
my $hal=$bus-&amp;gt;get_service(&amp;quot;org.freedesktop.Hal&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
# Connect to the interface &amp;#039;/org/freedesktop/Hal/Manager&amp;#039; and create a handle&lt;br /&gt;
# to the remote method &amp;#039;org.freedesktop.Hal.Manager&amp;#039;. This is *sort* of like&lt;br /&gt;
# creating a handle to a normal perl module where you would say something like&lt;br /&gt;
# &amp;#039;my $hal_manager=Some::Module-&amp;gt;new();&amp;quot;.&lt;br /&gt;
my $hal_manager = $hal-&amp;gt;get_object(&amp;quot;/org/freedesktop/Hal/Manager&amp;quot;, &amp;quot;org.freedesktop.Hal.Manager&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
# This calls a special method that asks HAL to list all the devices it already&lt;br /&gt;
# knows about. In a real world example, I would process these devices and&lt;br /&gt;
# update their status in a database. For now though, we will just print a line&lt;br /&gt;
# to the screen. Continuing the above analogy, this would now be like calling&lt;br /&gt;
# &amp;#039;my @devices=$hal_manager-&amp;gt;GetAllDevices(); foreach my $dev...&amp;#039; if this had&lt;br /&gt;
# been a normal perl module.&lt;br /&gt;
foreach my $dev (@{$hal_manager-&amp;gt;GetAllDevices})&lt;br /&gt;
{&lt;br /&gt;
	if ( $dev =~ /^\/org\/freedesktop\/Hal\/devices\/volume_/ )&lt;br /&gt;
	{&lt;br /&gt;
		# For this example, I am looking for devices that start with&lt;br /&gt;
		# &amp;#039;volume_*&amp;#039;, as I know these to be storage devices. You can&lt;br /&gt;
		# change this to match whatever you are interested in.&lt;br /&gt;
		print &amp;quot;Adding a listener for the pre-existing device: [$dev]\n&amp;quot;;&lt;br /&gt;
		&amp;amp;add_listener($hal, $dev);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Now I will add a handler that will react to signals with the name&lt;br /&gt;
# &amp;#039;DeviceAdded&amp;#039;, which I know is what HAL reports when a new device is added to&lt;br /&gt;
# the system.&lt;br /&gt;
$hal_manager-&amp;gt;connect_to_signal(&amp;#039;DeviceAdded&amp;#039;, sub&lt;br /&gt;
{&lt;br /&gt;
	my ($callid) = @_;&lt;br /&gt;
	if ( $callid =~ /^\/org\/freedesktop\/Hal\/devices\/volume_/ )&lt;br /&gt;
	{&lt;br /&gt;
		# I saw that a device was added, and it matches my criteria for&lt;br /&gt;
		# what I am interested in, so I will add a listener for this&lt;br /&gt;
		# new device.&lt;br /&gt;
		print &amp;quot;Adding a listener for the newly connected device: [$callid]\n&amp;quot;;&lt;br /&gt;
		&amp;amp;add_listener($hal, $callid);&lt;br /&gt;
	}&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
# And next I will add a second handler that will react to signals with the name&lt;br /&gt;
# &amp;#039;DeviceRemoved&amp;#039;, which I know is what HAL reports when a new device is&lt;br /&gt;
# removed from the system.&lt;br /&gt;
$hal_manager-&amp;gt;connect_to_signal(&amp;#039;DeviceRemoved&amp;#039;, sub&lt;br /&gt;
{&lt;br /&gt;
	my ($callid) = @_;&lt;br /&gt;
	print &amp;quot;Device removed: [$callid]\n&amp;quot;;&lt;br /&gt;
	# If I needed to, I could do cleanup here to see what has been removed.&lt;br /&gt;
	#&amp;amp;scan_devices();&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
# Lastly, now that my handlers are in place for the bus -&amp;gt; service -&amp;gt; object I&lt;br /&gt;
# am interested, I will connect to the main event loop using the Reactor&lt;br /&gt;
# module. This will do the dirty work of analyzing messages and triggering&lt;br /&gt;
# appropriate handlers as needed.&lt;br /&gt;
my $reactor = Net::DBus::Reactor-&amp;gt;main();&lt;br /&gt;
$reactor-&amp;gt;run();&lt;br /&gt;
&lt;br /&gt;
# This is here mainly out of best practices. In the real world, this script&lt;br /&gt;
# will exit until it is sent an appropriate signal or is killed outright. For&lt;br /&gt;
# this reason, you will likely want to write out this process&amp;#039; PID to a file,&lt;br /&gt;
# generally somewhere in &amp;#039;/var/run&amp;#039; and add a system for catching signals and&lt;br /&gt;
# gracefully exiting.&lt;br /&gt;
print &amp;quot;Exiting the client.\n&amp;quot;;&lt;br /&gt;
exit(0);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
### Local Subroutines&lt;br /&gt;
&lt;br /&gt;
# This adds a listener for a DBus object that Net::DBus::Reactor will report on.&lt;br /&gt;
sub add_listener&lt;br /&gt;
{&lt;br /&gt;
	my ($hal, $object)=@_;&lt;br /&gt;
	print &amp;quot;Adding a listener for object: [$object]\n&amp;quot;;&lt;br /&gt;
	&lt;br /&gt;
	# Connect to the &amp;#039;$object&amp;#039; on the HAL device.&lt;br /&gt;
	my $hal_device = $hal-&amp;gt;get_object(&amp;quot;$object&amp;quot;, &amp;quot;org.freedesktop.Hal.Device&amp;quot;);&lt;br /&gt;
	$hal_device-&amp;gt;connect_to_signal(&amp;#039;PropertyModified&amp;#039;, sub {&lt;br /&gt;
		my ($callid) = @_;&lt;br /&gt;
		# This could be any subroutine you want to call when the signal&lt;br /&gt;
		# &amp;#039;PropertyModified&amp;#039; is emitted for this object. In a&lt;br /&gt;
		# real-world program, this could do a more extensive scan of&lt;br /&gt;
		# the device to see what all has changed.&lt;br /&gt;
		#&amp;amp;scan_devices();&lt;br /&gt;
	});&lt;br /&gt;
	&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{footer}}&lt;/div&gt;</summary>
		<author><name>Digimer</name></author>
	</entry>
</feed>