summaryrefslogtreecommitdiff
path: root/XOrg
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-07-27 20:45:53 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-08-02 15:09:32 +1000
commite6f3d8fd9bb770a428bdd1310af8f86f9ca392b9 (patch)
tree37e478ba5a0dd915917157a5bee9252d6e9c84e9 /XOrg
parente53ce3e6f590bc575a732c97acafdc7803bacae3 (diff)
XOrg: add a basic HAL module to control HAL from test scripts.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'XOrg')
-rw-r--r--XOrg/HAL.pm180
1 files changed, 180 insertions, 0 deletions
diff --git a/XOrg/HAL.pm b/XOrg/HAL.pm
new file mode 100644
index 0000000..ce24d84
--- /dev/null
+++ b/XOrg/HAL.pm
@@ -0,0 +1,180 @@
+#!/usr/bin/perl
+
+# Copyright © 2011 by Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Authors: Peter Hutterer <peter.hutterer@redhat.com>
+
+
+=head1 NAME
+
+XOrg::HAL - HAL control module
+
+=head1 DESCRIPTION
+
+This module is a basic control module for the HAL daemon for the purpose of
+adding X.Org-specific configuration.
+
+=cut
+
+package XOrg::HAL;
+
+use warnings;
+use strict;
+use Carp;
+use XOrg::ConfigGenerator;
+use XOrg::InputDevice;
+
+our @ISA = qw(XOrg::ConfigGenerator);
+
+
+my $fdi_template = '
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<deviceinfo version="0.2">
+ <device>
+ <match key="info.category" contains="input">
+ <match key="info.product" contains_outof="→product←">
+ <merge key="input.x11_driver" type="string">→driver←</merge>
+ →option←
+ </match>
+ </match>
+ </device>
+</deviceinfo>
+
+';
+
+sub new {
+ my $class = shift;
+ my $self = {@_};
+ bless ($self, $class);
+
+ $self->parse_lshal;
+
+ return $self;
+}
+
+=head2 B<$hal-E<gt>stop>
+
+Stop the HAL process.
+=cut
+sub stop {
+ my $self = shift;
+ my @args = ("service", "haldaemon", "stop");
+ return (system(@args) == 0);
+}
+
+=head2 B<$hal-E<gt>start>
+
+Start the HAL process.
+=cut
+sub start {
+ my $self = shift;
+ my @args = ("service", "haldaemon", "start");
+ return (system(@args) == 0);
+}
+
+=head2 B<$hal-E<gt>restart>
+
+Restart the HAL process.
+=cut
+sub restart {
+ my $self = shift;
+ $self->stop;
+ return $self->start;
+}
+
+=head2 B<$hal-E<gt>parse_lshal>
+Parse the lshal output and update the internal state.
+=cut
+sub parse_lshal {
+ my $self = shift;
+ my @output;
+ my $current_device;
+
+ $self->{hal_devices} = [()];
+
+ open LSHAL, "lshal |";
+ @output = <LSHAL>;
+
+ for my $line (@output) {
+ if ($line =~ /^udi = '(.*)'/) {
+ $current_device = XOrg::InputDevice->new();
+ } elsif ($line =~ /^$/) {
+ undef $current_device;
+ } elsif ($line =~ /info\.capabilities = {.*'input\..*'/) {
+ push @{$self->{hal_devices}}, $current_device;
+ } elsif ($line =~ /info\.product = '(.*)'\s+\(string\)/) {
+ $current_device->name($1);
+ } elsif ($line =~ /input\.x11_driver = '(.*)'/) {
+ $current_device->module($1);
+ } elsif ($line =~ /input\.x11_options\.(.*) = '(.*)'/) {
+ $current_device->add_option($1, $2);
+ } elsif ($line =~ /input\.device = '(.*)'/) {
+ $current_device->devicenode($1);
+ }
+ }
+}
+
+=head2 B<$hal-E<gt>hal_devices>
+Return a refernce to the list of input devices found in lshal.
+
+Each item is a hashmap.
+=cut
+sub devices {
+ my $self = shift;
+
+ if (not $self->{hal_devices}) {
+ $self->parse_lshal;
+ }
+
+ return $self->{hal_devices};
+}
+
+=head2 B<$hal-E<gt>add_fdi($match, $driver, \%options)>
+
+Add an fdi configuration snippet matching on the info.product = $match. The
+snippet assigns $driver as driver and any options.
+
+=cut
+sub set_fdi {
+ my $self = shift;
+ my $match = shift;
+ my $driver = shift;
+ my $optref = shift;
+
+ my $template = $fdi_template;
+ $template = $self->replace($template, { "product" => $match,
+ "driver" => $driver });
+ for (keys %{$optref}) {
+ my $mergeline = "
+ <merge key=\"input.x11_options.$_\" type=\"string\">$optref->{$_}</merge>
+ ";
+ $template = $self->add_to_placeholder($template, "option", $mergeline);
+ }
+
+ $self->{fdi} = $template;
+}
+
+sub print {
+ my $self = shift;
+
+ return $self->{fdi};
+}
+
+
+1;
+
+# vim: set noexpandtab shiftwidth=8 tabstop=8: