| 1 | #! /bin/perl | ||
| 2 | ############################################################################# | ||
| 3 | # | ||
| 4 | # NOTE: This file under revision control using RCS | ||
| 5 | # Any changes made without RCS will be lost | ||
| 6 | # | ||
| 7 | # $Source: /usr/local/cvsroot/vbtk/VBTK/Objects/ChangeActions.pm,v $ | ||
| 8 | # $Revision: 1.5 $ | ||
| 9 | # $Date: 2002/03/04 20:53:07 $ | ||
| 10 | # $Author: bhenry $ | ||
| 11 | # $Locker: $ | ||
| 12 | # $State: Exp $ | ||
| 13 | # | ||
| 14 | # Purpose: A perl library used to manage VBObject status | ||
| 15 | # change actions. | ||
| 16 | # | ||
| 17 | # Copyright (C) 1996 - 2002 Brent Henry | ||
| 18 | # | ||
| 19 | # This program is free software; you can redistribute it and/or | ||
| 20 | # modify it under the terms of version 2 of the GNU General Public | ||
| 21 | # License as published by the Free Software Foundation available at: | ||
| 22 | # http://http://www.gnu.org/copyleft/gpl.html | ||
| 23 | # | ||
| 24 | # This program is distributed in the hope that it will be useful, | ||
| 25 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 27 | # GNU General Public License for more details. | ||
| 28 | # | ||
| 29 | ############################################################################# | ||
| 30 | # | ||
| 31 | # | ||
| 32 | # REVISION HISTORY: | ||
| 33 | # | ||
| 34 | # $Log: ChangeActions.pm,v $ | ||
| 35 | # Revision 1.5 2002/03/04 20:53:07 bhenry | ||
| 36 | # *** empty log message *** | ||
| 37 | # | ||
| 38 | # Revision 1.4 2002/03/04 16:49:10 bhenry | ||
| 39 | # Changed requirement back to perl 5.6.0 | ||
| 40 | # | ||
| 41 | # Revision 1.3 2002/03/02 00:53:55 bhenry | ||
| 42 | # Documentation updates | ||
| 43 | # | ||
| 44 | # Revision 1.2 2002/01/21 17:07:50 bhenry | ||
| 45 | # Disabled 'uninitialized' warnings | ||
| 46 | # | ||
| 47 | # Revision 1.1.1.1 2002/01/17 18:05:57 bhenry | ||
| 48 | # VBTK Project | ||
| 49 | # | ||
| 50 | |||
| 51 | package VBTK::Objects::ChangeActions; | ||
| 52 | |||
| 53 | use 5.6.0; | ||
| 54 | use strict; | ||
| 55 | use warnings; | ||
| 56 | # I like using undef as a value so I'm turning off the uninitialized warnings | ||
| 57 | no warnings qw(uninitialized); | ||
| 58 | |||
| 59 | use VBTK::Common; | ||
| 60 | |||
| 61 | our $VERBOSE=$ENV{'VERBOSE'}; | ||
| 62 | |||
| 63 | #------------------------------------------------------------------------------- | ||
| 64 | # Function: new | ||
| 65 | # Description: Object constructor. Allocates memory for all class members | ||
| 66 | # Input Parms: Configuration filename | ||
| 67 | # Output Parms: Pointer to class | ||
| 68 | #------------------------------------------------------------------------------- | ||
| 69 | sub new | ||
| 70 | { | ||
| 71 | my $type = shift; | ||
| 72 | my $self = {}; | ||
| 73 | bless $self, $type; | ||
| 74 | |||
| 75 | $self->set(@_); | ||
| 76 | |||
| 77 | # Setup a hash of default parameters | ||
| 78 | my $defaultParms = { | ||
| 79 | TestStatus => $::REQUIRED, | ||
| 80 | ActionList => $::REQUIRED | ||
| 81 | }; | ||
| 82 | |||
| 83 | # Run a validation on the passed parms, using the default parms | ||
| 84 | $self->validateParms($defaultParms) || return undef; | ||
| 85 | |||
| 86 | my ($temp,$key); | ||
| 87 | |||
| 88 | # Check the status text and map it | ||
| 89 | foreach $key ('TestStatus') | ||
| 90 | { | ||
| 91 | $temp = &map_status($self->{$key}); | ||
| 92 | if ($temp eq undef) | ||
| 93 | { | ||
| 94 | &error("Invalid status '$self->{$key}' in StatusChangeActions"); | ||
| 95 | return undef; | ||
| 96 | } | ||
| 97 | $self->{$key} = $temp; | ||
| 98 | } | ||
| 99 | |||
| 100 | return $self; | ||
| 101 | } | ||
| 102 | |||
| 103 | #------------------------------------------------------------------------------- | ||
| 104 | # Function: validateActionNames | ||
| 105 | # Description: Check to see if the passed action names are valid action objects. | ||
| 106 | # Input Parms: None | ||
| 107 | # Output Parms: True | False | ||
| 108 | #------------------------------------------------------------------------------- | ||
| 109 | sub validateActionNames | ||
| 110 | { | ||
| 111 | my $self = shift; | ||
| 112 | my $ActionList = $self->{ActionList}; | ||
| 113 | my $validatedFlag = $self->{validatedFlag}; | ||
| 114 | |||
| 115 | return 1 if ($validatedFlag); | ||
| 116 | |||
| 117 | my ($actionName,$actionObj); | ||
| 118 | |||
| 119 | # Split up the actionlist string | ||
| 120 | my @actionNameList = split(/,/,$ActionList); | ||
| 121 | |||
| 122 | # Check each action | ||
| 123 | foreach $actionName (@actionNameList) | ||
| 124 | { | ||
| 125 | $actionObj = &VBTK::Actions::getAction($actionName); | ||
| 126 | |||
| 127 | if ($actionObj eq undef) | ||
| 128 | { | ||
| 129 | &error("Invalid status change action '$actionName'"); | ||
| 130 | return undef; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | # If we made it this far, then all the action names are valid | ||
| 135 | $self->{validatedFlag} = 1; | ||
| 136 | |||
| 137 | (1); | ||
| 138 | } | ||
| 139 | |||
| 140 | #------------------------------------------------------------------------------- | ||
| 141 | # Function: checkForActions | ||
| 142 | # Description: Check to see if the passed status matches the test status on this | ||
| 143 | # object and if so, then trigger it. | ||
| 144 | # Input Parms: New status | ||
| 145 | # Output Parms: None | ||
| 146 | #------------------------------------------------------------------------------- | ||
| 147 | sub checkForActions | ||
| 148 | { | ||
| 149 | my $self = shift; | ||
| 150 | my ($status,$name,$msgText) = @_; | ||
| 151 | |||
| 152 | my $TestStatus = $self->{TestStatus}; | ||
| 153 | my $ActionList = $self->{ActionList}; | ||
| 154 | |||
| 155 | # If the status does not equal the test status then we're done. | ||
| 156 | return 0 if ($TestStatus ne $status); | ||
| 157 | |||
| 158 | my @actionList = split(/,/,$ActionList); | ||
| 159 | my ($actionObj,$actionName); | ||
| 160 | |||
| 161 | foreach $actionName (@actionList) | ||
| 162 | { | ||
| 163 | $actionObj = &VBTK::Actions::getAction($actionName); | ||
| 164 | |||
| 165 | if($actionObj eq undef) | ||
| 166 | { | ||
| 167 | &error("Invalid action '$actionName' specified for object '$name'"); | ||
| 168 | next; | ||
| 169 | } | ||
| 170 | |||
| 171 | $actionObj->add_message($name,$status,$msgText); | ||
| 172 | } | ||
| 173 | (0); | ||
| 174 | } | ||
| 175 | |||
| 176 | #------------------------------------------------------------------------------- | ||
| 177 | # Function: getRuleText | ||
| 178 | # Description: Construct text to describe the rule | ||
| 179 | # Input Parms: | ||
| 180 | # Output Parms: Rule text | ||
| 181 | #------------------------------------------------------------------------------- | ||
| 182 | sub getRuleText | ||
| 183 | { | ||
| 184 | my $self = shift; | ||
| 185 | |||
| 186 | "If status changes to '$self->{TestStatus}' then execute '$self->{ActionList}'"; | ||
| 187 | } | ||
| 188 | |||
| 189 | # Simple Get Methods | ||
| 190 | sub getTestStatus { $_[0]->{TestStatus}; } | ||
| 191 | sub getActionList { $_[0]->{ActionList}; } | ||
| 192 | |||
| 193 | 1; | ||
| 194 | __END__ |