]> mj.ucw.cz Git - pciids.git/blob - PciIds/Address/PciClass.pm
Always jump to list
[pciids.git] / PciIds / Address / PciClass.pm
1 #       PciIds web database
2 #       Copyright (C) 2008 Michal Vaner (vorner@ucw.cz)
3 #
4 #       This program is free software; you can redistribute it and/or modify
5 #       it under the terms of the GNU General Public License as published by
6 #       he Free Software Foundation; either version 2 of the License, or
7 #       (at your option) any later version.
8 #
9 #       This program is distributed in the hope that it will be useful,
10 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #
13 #       GNU General Public License for more details.
14 #
15 #       You should have received a copy of the GNU General Public License
16 #       along with this program; if not, write to the Free Software
17 #       Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19 package PciIds::Address::PciClass;
20 use strict;
21 use warnings;
22 use PciIds::Address::Toplevel;
23 use base 'PciIds::Address::Base';
24
25 sub new( $ ) {
26         my( $address ) = @_;
27         return PciIds::Address::Toplevel::new( $address ) if( $address =~ /^PD\/?$/ );
28         return bless PciIds::Address::Base::new( $address );
29 }
30
31 sub fullPretty( $ ) {
32         $_ = shift->get();
33         s/^PC\/?//;
34         s/\//:/g;
35         if( /:.*:/ ) {
36                 s/^/Program interface /;
37         } elsif( /:/ ) {
38                 s/^/PCI device subclass /;
39         } else {
40                 s/^/PCI device class /;
41         }
42         return $_;
43 }
44 sub pretty( $ ) {
45         my $self = shift;
46         $_ = $self->get();
47         s/^PD\/?//;
48         s/\//:/g;
49         my $prefix;
50         if( /:.*:/ ) {
51                 $prefix = 'Program interface';
52         } elsif( /:/ ) {
53                 $prefix = 'Device subclass';
54         } else {
55                 $prefix = 'Device class';
56         }
57         return $prefix.' '.$_;
58 }
59
60 sub restrictRex( $$ ) {
61         my( $self, $restrict ) = @_;
62         my( $result ) = ( $restrict =~ /^([a-f0-9]{1,2})/ );#TODO every time?
63         return $result;
64 }
65
66 sub leaf( $ ) {
67         return shift->get() =~ /\/.*\/.*\//;
68 }
69
70 sub append( $$ ) {
71         my( $self, $suffix ) = @_;
72         return ( undef, 'You can not add to leaf node' ) if( $self->leaf() );
73         return ( undef, "Invalid ID syntax" ) unless ( $suffix =~ /^[0-9a-f]{2,2}$/ );
74         return ( PciIds::Address::new( $self->{'value'} . ( ( $self->{'value'} =~ /\/$/ ) ? '' : '/' ) . $suffix ), undef );
75 }
76
77 sub helpName( $ ) {
78         return 'pci_class';
79 }
80
81 sub subName( $ ) {
82         my( $self ) = @_;
83         return 'Program interfaces' if $self->get() =~ /PD\/..\/../;
84         return 'Device subclasses' if $self->get() =~ /PD\/../;
85         die "Can not happen\n";
86 }
87
88 sub subIdSize( $ ) {
89         my( $self ) = @_;
90         return 2;
91 }
92
93 1;