[3] | 1 | # |
---|
| 2 | # Copyright (c) 2004-2007 - Consultas, PKG.fr |
---|
| 3 | # |
---|
| 4 | # This file is part of A2P. |
---|
| 5 | # |
---|
| 6 | # A2P 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 | # A2P 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 A2P; if not, write to the Free Software |
---|
| 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 19 | # |
---|
| 20 | # $Id: EOC.pm 3 2007-10-18 16:20:19Z g $ |
---|
| 21 | # |
---|
| 22 | # Class to export End Object Container members |
---|
| 23 | # |
---|
| 24 | # cf ref #2, p. 164 |
---|
| 25 | # |
---|
| 26 | |
---|
| 27 | package AFPDS::MODCA::EOC ; |
---|
| 28 | |
---|
| 29 | use strict ; |
---|
| 30 | use A2P::Globals ; |
---|
| 31 | use A2P::Syslog ; |
---|
| 32 | use AFPDS::MODCA::Common ; |
---|
| 33 | |
---|
| 34 | BEGIN { |
---|
| 35 | our $VERSION = sprintf "%s", q$Rev: 1007 $ =~ /([0-9.]+)\s+/ ; |
---|
| 36 | } |
---|
| 37 | our $VERSION ; |
---|
| 38 | our @ISA = ("AFPDS::MODCA"); |
---|
| 39 | our $IDENTS ; |
---|
| 40 | |
---|
| 41 | sub _ID { 0xD3A992 } |
---|
| 42 | |
---|
| 43 | sub _supported_triplets { |
---|
| 44 | return [], [ |
---|
| 45 | # 0x02 # Only X'02' FQN triplet should be supported |
---|
| 46 | ]; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | sub new { |
---|
| 50 | my $class = shift ; |
---|
| 51 | &Debug("new " . __PACKAGE__ . " v$VERSION object"); |
---|
| 52 | |
---|
| 53 | my $self = { |
---|
| 54 | FLUX => 0, # Associated flux |
---|
| 55 | IDENT => _ID, # MO:DCA identity |
---|
| 56 | FLAG => 0, # MO:DCA flags |
---|
| 57 | RESERVED => 0, # MO:DCA reserved |
---|
| 58 | LONG => 0, # MO:DCA buffer length |
---|
| 59 | BUFFER => '' # MO:DCA content buffer |
---|
| 60 | }; |
---|
| 61 | |
---|
| 62 | return bless $self , $class ; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | sub validate { |
---|
| 66 | my $self = shift ; |
---|
| 67 | |
---|
| 68 | &Debug("Found EOC to close integrated resource"); |
---|
| 69 | &UPSTAT('GET-COMPLETED-RESOURCE'); |
---|
| 70 | |
---|
| 71 | # Check FLUX is a Flux object |
---|
| 72 | return ( 251, "EOC needs to be used with Flux object" ) |
---|
| 73 | unless ( ref($self->{FLUX}) =~ /^AFPDS::Flux$/ ); |
---|
| 74 | |
---|
| 75 | return () ; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | sub create { |
---|
| 79 | my $self = shift ; |
---|
| 80 | my $resname = "" ; |
---|
| 81 | my @err = () ; |
---|
| 82 | |
---|
| 83 | if ( $self->{LONG} ) { |
---|
| 84 | # Set resource name |
---|
| 85 | $resname = substr( $self->{BUFFER}, 0, 8 ); |
---|
| 86 | $resname = $self->convert( $resname ); |
---|
| 87 | |
---|
| 88 | # Analyse authorized triplets if needed |
---|
| 89 | @err = $self->check_triplets(substr( $self->{BUFFER}, 8 )) |
---|
| 90 | if ( $self->{LONG} > 8 ); |
---|
| 91 | |
---|
| 92 | return @err if @err ; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | # Check container is opened in flux |
---|
| 96 | my $flux = $self->{FLUX} ; |
---|
| 97 | my $container = $flux->get_resource($resname); |
---|
| 98 | return ( 252, $resname ? |
---|
| 99 | "Resource '$resname' not available" : "No resource available to close" ) |
---|
| 100 | unless ( $container and ref($container) =~ /^AFPDS::MODCA/ ); |
---|
| 101 | |
---|
| 102 | # Validate the expected structure, see BOC |
---|
| 103 | my $struct = $container->{STRUCT} || 0 ; |
---|
| 104 | return ( 253, "Unexpected '$struct' structure found for BOC object" ) |
---|
| 105 | unless ( $struct == 0xDC00 ); |
---|
| 106 | |
---|
| 107 | # At that time, just initialize a resource using counter |
---|
| 108 | $container->{USED} = 0 ; |
---|
| 109 | |
---|
| 110 | # Unselect resource in flux |
---|
| 111 | $flux->set_resource(undef); |
---|
| 112 | |
---|
| 113 | return @err ; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | &Debug("Module " . __PACKAGE__ . " v$VERSION loaded"); |
---|
| 117 | |
---|
| 118 | ( $IDENTS->{&_ID} ) = __PACKAGE__ =~ /(\w+)$/ ; |
---|