source: A2P/a2p/AFPDS/MODCA/IDM.pm @ 14

Last change on this file since 14 was 3, checked in by guillaume, 17 years ago
  • AUTHORS: Ajout des différents contributeurs
  • COPYING: Ajout de la licence GPL v3
  • a2p: Préparation des sources pour leur publication sous GPL
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
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: IDM.pm 3 2007-10-18 16:20:19Z guillaume $
21#
22# Class to export Invoke Data Map (PAGEFORMAT) members
23#
24# cf ref #1, p. 91
25#
26
27package AFPDS::MODCA::IDM ;
28
29use strict ;
30use A2P::Globals ;
31use A2P::Syslog ;
32use AFPDS::MODCA::Common ;
33
34BEGIN {
35    our $VERSION = sprintf "%s", q$Rev: 1007 $ =~ /([0-9.]+)\s+/ ;
36}
37our $VERSION ;
38our @ISA = ("AFPDS::MODCA");
39our $IDENTS ;
40
41sub _ID { 0xD3ABCA }
42
43sub new {
44    my $class = shift ;
45    &Debug("new " . __PACKAGE__ . " v$VERSION object");
46
47    my $self = {
48        FLUX     => 0,        # Associated flux
49        IDENT    => _ID,      # MO:DCA identity
50        FLAG     => 0,        # MO:DCA flags
51        RESERVED => 0,        # MO:DCA reserved
52        LONG     => 0,        # MO:DCA buffer length
53        BUFFER   => ''        # MO:DCA content buffer
54    };
55
56    return bless $self , $class ;
57}
58
59sub validate {
60    my $self = shift ;
61
62    &Debug("Found IDM as PAGEFORMAT");
63    &UPSTAT('GETPAGEFORMAT');
64
65    # Check buffer size
66    if ( $self->{LONG} != 8 ) {
67        &Warn("Found IDM Field value with bad length (" . $self->{LONG} .
68            "), keeping only the first 8 chars");
69        $self->{BUFFER} = substr( $self->{BUFFER} , 0 , 8 );
70    }
71
72    # Check FLUX is a Flux object
73    return ( 251, "IDM needs to be used with Flux object" )
74        unless ( ref($self->{FLUX}) =~ /^AFPDS::Flux$/ );
75
76    # Check PAGEDEF is selected
77    return ( 251, "Can't set PAGEFORMAT withou PAGEDEF selected" )
78        unless ( $self->{FLUX}->pagedef );
79
80    return () ;
81}
82
83sub create {
84    my $self = shift ;
85    my $flux = $self->{FLUX} ;
86
87    # Convert buffer
88    my $pageformat = $self->convert ;
89
90    # Keep information on this use for statistics
91    $flux->{PAGEFORMATs}->{$pageformat} = 1 ;
92    &UPSTAT('USEPAGEFORMAT_' . $pageformat);
93
94    # Load the corresponding Perl module and return
95    my $PageFormatSub = "perllib::p1" . lc( $flux->pagedef ) . "::PAGEFORMAT" ;
96    my $libload = $PageFormatSub . '( "' . $pageformat .
97        '", @{$flux->{PrintLineTab}} )';
98
99    # Before trying to load, we must check sub is available
100    return ( 202, "No PageFormat available with PAGEDEF " . $flux->pagedef )
101        unless (ref( eval '\&' . $PageFormatSub ) =~ /^CODE/ );
102
103    my ( $IfLandScape , $PageFormat ) = eval( $libload );
104
105    return ( 203, "Can't load '$pageformat' Pageformat from 'P1" .
106        $flux->pagedef . "' Pagedef" ) unless (defined($PageFormat));
107
108    &UPSTAT('GETLANDSCAPEPAGE') if $IfLandScape ;
109
110    $flux->updateFlux( {
111        PAGEFORMAT => $PageFormat,
112        LANDSCAPE  => $IfLandScape,
113
114        # This force a new page with the next newline
115        StartNewPage => 1,
116
117        # This force PTCA to be stored in logo array until newline is called
118        LINE => 0,
119
120        # Only used in logging
121        CurrentPAGEFORMAT => $pageformat
122        } );
123
124    # Protect '%' from printf interpretation in syslog debugging
125    $PageFormat =~ s/%/%%/g ;
126    &Debug("PageFormat loaded: eval( $libload ) = $IfLandScape , $PageFormat");
127
128    return () ;
129}
130
131&Debug("Module " . __PACKAGE__ . " v$VERSION loaded");
132
133( $IDENTS->{&_ID} ) = __PACKAGE__ =~ /(\w+)$/ ;
Note: See TracBrowser for help on using the repository browser.