]> mj.ucw.cz Git - pciids.git/blob - PciIds/Address/Toplevel.pm
Always jump to list
[pciids.git] / PciIds / Address / Toplevel.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::Toplevel;
20 use strict;
21 use warnings;
22 use base 'PciIds::Address::Base';
23
24 sub new( $ ) {
25         my( $value ) = @_;
26         if( $value =~ /^P[CD]\/?/ ) {
27                 return bless PciIds::Address::Base::new( $value );
28         } else {
29                 return undef;
30         }
31 }
32
33 sub pretty( $ ) {
34         my $self = shift;
35         if( $self->{'value'} =~ /^PC/ ) {
36                 return 'PCI Devices';
37         } else {
38                 return 'PCI Device Classes';
39         }
40 }
41
42 sub fullPretty( $ ) {
43         return pretty( shift );
44 }
45
46 sub restrictRex( $$ ) {
47         my( $self, $restrict ) = @_;
48         return PciIds::Address::new( $self->get().'/0000' )->restrictRex( $restrict );#Nasty trick, get the right address of any subnode and try it there
49 }
50
51 sub leaf( $ ) {
52         return 0;
53 }
54
55 sub append( $$ ) {
56         my( $self, $suffix ) = @_;
57         $suffix = lc $suffix;
58         if( $self->{'value'} =~ /^PC/ ) {#PCI
59                 return ( undef, "Invalid ID syntax" ) unless ( $suffix =~ /^[0-9a-f]{4,4}$/ );
60         } else {#PCI Device Class
61                 return ( undef, "Invalid ID syntax" ) unless ( $suffix =~ /^[0-9a-f]{2,2}$/ );
62         }
63         return ( PciIds::Address::new( $self->{'value'} . ( ( $self->{'value'} =~ /\/$/ ) ? '' : '/' ) . $suffix ), undef );
64 }
65
66 sub canDiscuss( $ ) { return 0; }
67
68 sub defaultRestrict( $ ) {
69         my( $self ) = @_;
70         if( $self->get() =~ /^PC/ ) {
71                 return "0";
72         } else {
73                 return "";
74         }
75 }
76
77 sub defaultRestrictList( $ ) {
78         my( $self ) = @_;
79         if( $self->get() =~ /^PC/ ) {
80                 my @result;
81                 for(my $i = '0'; $i < '10'; ++ $i ) {
82                         push @result, $i;
83                 }
84                 push @result, ( 'a', 'b', 'c', 'd', 'e', 'f' );
85                 my @final;
86                 push @final, [ $_, $_ ] foreach( @result );
87                 push @final, [ "", "all" ];
88                 return \@final;
89         } else {
90                 return [];
91         }
92 }
93
94 sub parent( $ ) {
95         return undef;
96 }
97
98 sub helpName( $ ) {
99         my( $self ) = @_;
100         if( $self->{'value'} =~ /^PC/ ) {
101                 return 'pci';
102         } else {
103                 return 'pci_class';
104         }
105 }
106
107 sub subName( $ ) {
108         my( $self ) = @_;
109         if( $self->get() =~ /^PC/ ) {
110                 return 'Vendors';
111         } else {
112                 return 'Device classes';
113         }
114 }
115
116 sub subIdSize( $ ) {
117         my( $self ) = @_;
118         if( $self->get() =~ /^PC/ ) {
119                 return 4;
120         } else {
121                 return 2;
122         }
123 }
124
125 1;