summaryrefslogtreecommitdiff
path: root/XOrg
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-07-25 16:33:50 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-07-30 11:17:05 +1000
commitb06011145a780026633321eca7eed54df668b9ca (patch)
treec588d2c4f91f5da8c99549f6f525da8e92fe824f /XOrg
parent3e6f95ef2e8c3032452c8537b922c42a787afd61 (diff)
XOrg: Move X Server stuff from log parser to XServer.pm
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'XOrg')
-rw-r--r--XOrg/XServer.pm113
-rwxr-xr-xXOrg/xorglog.pm70
2 files changed, 130 insertions, 53 deletions
diff --git a/XOrg/XServer.pm b/XOrg/XServer.pm
new file mode 100644
index 0000000..66af73c
--- /dev/null
+++ b/XOrg/XServer.pm
@@ -0,0 +1,113 @@
+#!/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>
+
+
+# XServer representation, after using the Xorg.log parser
+
+package XServer;
+
+use Module;
+use InputDevice;
+use warnings;
+use strict;
+use Carp;
+
+# Instance methods
+sub new {
+ my $class = shift;
+ my $self = {@_};
+ bless ($self, $class);
+
+ $self->{modules} = {};
+ $self->{devices} = ();
+
+ return $self;
+}
+
+sub logfile {
+ my $self = shift;
+ my $logfile = shift;
+
+ $self->{logfile} = $logfile if defined $logfile;
+ return $self->{logfile};
+}
+
+sub version {
+ my $self = shift;
+ my $major = shift;
+ my $minor = shift;
+ my $patchlevel = shift;
+
+ if (defined $major) {
+ if (not defined $minor or not defined $patchlevel) {
+ croak "Invalid version number. Need 3 components.\n";
+ return;
+ }
+ $self->{version} = [($major, $minor, $patchlevel)];
+ }
+
+ return $self->{version};
+}
+
+sub build_id {
+ my $self = shift;
+ my $build_id = shift;
+
+ $self->{build_id} = $build_id if defined $build_id;
+ return $self->{build_id};
+}
+
+sub config_backend {
+ my $self = shift;
+ my $config_backend = shift;
+
+ $self->{config_backend} = $config_backend if defined $config_backend;
+ return $self->{config_backend};
+}
+
+sub modules {
+ my $self = shift;
+ return $self->{modules};
+}
+
+# Returns 1/0 if AutoAddDevices is on/off.
+sub auto_add_devices {
+ my $self = shift;
+ my $auto_add_devices = shift;
+
+ $self->{auto_add_devices} = $auto_add_devices if defined $auto_add_devices;
+ return $self->{auto_add_devices};
+}
+
+sub devices {
+ my $self = shift;
+ return $self->{devices};
+}
+
+sub add_device {
+ my $self = shift;
+ my $device = shift;
+
+ push @{$self->{devices}}, $device;
+}
+
+1;
+
+# vim: set noexpandtab shiftwidth=8 tabstop=8:
diff --git a/XOrg/xorglog.pm b/XOrg/xorglog.pm
index 17ad23d..42b5ca8 100755
--- a/XOrg/xorglog.pm
+++ b/XOrg/xorglog.pm
@@ -25,6 +25,7 @@ package xorglog;
use Module;
use InputDevice;
+use XServer;
use warnings;
use strict;
use Carp;
@@ -50,57 +51,20 @@ sub new {
croak "File '$file' doesn't exist.\n";
}
- $self->{modules} = {};
+ $self->server(XServer->new(logfile => $file));
+
$self->_parse($file);
return $self;
}
-sub version {
+sub server {
my $self = shift;
- my $major = shift;
- my $minor = shift;
- my $patchlevel = shift;
-
- if (defined $major) {
- if (not defined $minor or not defined $patchlevel) {
- croak "Invalid version number. Need 3 components.\n";
- return;
- }
- $self->{version} = [($major, $minor, $patchlevel)];
- }
-
- return $self->{version};
-}
-
-sub build_id {
- my $self = shift;
- my $build_id = shift;
-
- $self->{build_id} = $build_id if defined $build_id;
- return $self->{build_id};
-}
+ my $server = shift;
-sub config_backend {
- my $self = shift;
- my $config_backend = shift;
-
- $self->{config_backend} = $config_backend if defined $config_backend;
- return $self->{config_backend};
-}
-
-sub modules {
- my $self = shift;
- return $self->{modules};
-}
-
-# Returns 1/0 if AutoAddDevices is on/off.
-sub auto_add_devices {
- my $self = shift;
- my $auto_add_devices = shift;
+ $self->{server} = $server if defined $server;
- $self->{auto_add_devices} = $auto_add_devices if defined $auto_add_devices;
- return $self->{auto_add_devices};
+ return $self->{server};
}
# Internal functions
@@ -109,7 +73,7 @@ sub _parse_version {
my $line = shift;
if ($line =~ /^X.Org X Server (\d+)\.(\d+)\.(\d+)/) {
- $self->version($1, $2, $3);
+ $self->server->version($1, $2, $3);
return 1;
}
return 0;
@@ -120,7 +84,7 @@ sub _parse_build_id {
my $line = shift;
if ($line =~ /$time_regex Build ID: (.*)[ ]+/) {
- $self->build_id($1);
+ $self->server->build_id($1);
return 1;
}
return 0;
@@ -131,7 +95,7 @@ sub _parse_auto_add_devices {
my $line = shift;
if ($line =~ /$time_regex \(==\) (Not a|A)utomatically adding devices/) {
- $self->auto_add_devices(($1 cmp "A") == 0);
+ $self->server->auto_add_devices(($1 cmp "A") == 0);
return 1;
}
return 0;
@@ -143,7 +107,7 @@ sub _parse_config_backend {
for (@{$log}) {
if ($_ =~ /$time_regex \(II\) The server relies on (udev|hal) to provide .*/) {
- $self->config_backend($1);
+ $self->server->config_backend($1);
last;
}
}
@@ -161,7 +125,7 @@ sub _parse_modules {
my $line = $log->[$i++];
if ($line =~ /$time_regex \(II\) LoadModule: \"(.*)\"/) {
$current_module = Module->new(name => $1);
- $self->{modules}->{$1} = $current_module;
+ $self->server->modules->{$1} = $current_module;
my $j = 4; # 4 extra module lines after the LoadModule output
while ($j-- > 0) {
@@ -195,9 +159,9 @@ sub _parse_input_drivers {
devicenode => $3
);
- push @{$self->{devices}}, $dev;
+ $self->server->add_device($dev);
} elsif ($_ =~ /$time_regex \(II\) Using input driver '(.*)' for '(.*)'/) {
- my $module = $self->modules->{$1};
+ my $module = $self->server->modules->{$1};
if ($2 eq $dev->name) {
$dev->module($module);
} else {
@@ -206,7 +170,7 @@ sub _parse_input_drivers {
source => "xorg.conf",
module => $module
);
- push @{$self->{devices}}, $dev;
+ $self->server->add_device($dev);
}
}
@@ -222,7 +186,7 @@ sub _parse_input_drivers {
name => $1,
source => "internal"
);
- push @{$self->{devices}}, $dev;
+ $self->server->add_device($dev);
}
} elsif ($_ =~ /$time_regex \(\*\*\) Option "(.*)" "(.*)"/) {
$dev->add_option($1, $2);
@@ -264,7 +228,7 @@ sub _parse {
}
my $xlog = xorglog->new(file => "/var/log/Xorg.0.log");
-print Dumper($xlog);
+print Dumper($xlog->server);
1;