| 1 | # | ||
| 2 | # This file is part of the Perlilog project. | ||
| 3 | # | ||
| 4 | # Copyright (C) 2003, Eli Billauer | ||
| 5 | # | ||
| 6 | # This program is free software; you can redistribute it and/or modify | ||
| 7 | # it under the terms of the GNU General Public License as published by | ||
| 8 | # the Free Software Foundation; either version 2 of the License, or | ||
| 9 | # (at your option) any later version. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License | ||
| 17 | # along with this program; if not, write to the Free Software | ||
| 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | # | ||
| 20 | # A copy of the license can be found in a file named "licence.txt", at the | ||
| 21 | # root directory of this project. | ||
| 22 | # | ||
| 23 | |||
| 24 | # Perlilog's interface class | ||
| 25 | ${__PACKAGE__.'::errorcrawl'}='system'; | ||
| 26 | |||
| 27 | sub sustain { | ||
| 28 | my $self = shift; | ||
| 29 | $self->SUPER::sustain(@_); | ||
| 30 | my @ports=$self->get('perlilog-ports-to-connect'); | ||
| 31 | my ($i, $tmp); | ||
| 32 | |||
| 33 | # We now set the 'mates' property, which is supposed to | ||
| 34 | # point at the closest counterpart that the port is connected | ||
| 35 | # with. Note that we don't care if 'mates' was already set, but | ||
| 36 | # we just set it to our value. This assures that 'mates' | ||
| 37 | # will be set according to the pairing that was made at the | ||
| 38 | # latest stage, hence the closest one. If this gets messed up, | ||
| 39 | # it's probably because some interface class messed up the | ||
| 40 | # order of the returned object list. | ||
| 41 | |||
| 42 | for ($i=0; $i<=$#ports; $i++) { | ||
| 43 | $tmp = shift @ports; | ||
| 44 | $tmp->set('mates', @ports); | ||
| 45 | |||
| 46 | push @ports, $tmp; | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | sub who { | ||
| 51 | my $self = shift; | ||
| 52 | my $sus = $self -> get('perlilog-transient'); | ||
| 53 | |||
| 54 | if (not (defined $sus)) { | ||
| 55 | return "Int. obj. \'".$self->get('name')."\'"; | ||
| 56 | } elsif ($sus eq 'transient') { | ||
| 57 | return "(transient) Int. obj. \'".$self->get('nick')."\'"; | ||
| 58 | } else { | ||
| 59 | return "auto. gen. int. obj. \'".$self->get('name')."\'"; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | sub complete { | ||
| 64 | my $self = shift; | ||
| 65 | $self->SUPER::complete(@_); | ||
| 66 | |||
| 67 | my $papa = $self->get('parent'); | ||
| 68 | # If the interface object doesn't have a parent, its parent is the | ||
| 69 | # first port's owner's parent. | ||
| 70 | unless (ref $papa) { | ||
| 71 | my $port; | ||
| 72 | foreach $port ($self->get('perlilog-ports-to-connect')) { | ||
| 73 | $papa=$port->get('parent')->get('parent'); | ||
| 74 | last if (ref $papa); | ||
| 75 | } | ||
| 76 | $self->setparent($papa); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | # Just a shortcut to core intobjects | ||
| 81 | sub intobjects { | ||
| 82 | my $self = shift; | ||
| 83 | return &Perlilog::intobjects(@_); | ||
| 84 | } | ||
| 85 |