File: Flamethrower.pm

package info (click to toggle)
flamethrower 0.1.8-1%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 140 kB
  • ctags: 31
  • sloc: perl: 809; makefile: 50; sh: 48
file content (123 lines) | stat: -rwxr-xr-x 4,235 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#
#   "Flamethrower"
#
#   Copyright (C) 2002 Bald Guy Software 
#                      Brian Elliott Finley <brian@bgsw.net>
#
#   $Id: Flamethrower.pm 24 2003-06-29 01:04:22Z brianfinley $
#

package Flamethrower;

################################################################################
#
# Subroutines in this module include:
#
#   process_modules
#   read_config
#   which
#
#
################################################################################

use strict;
use AppConfig qw(:argcount :expand);

my $VERSION = 'INS_VERSION';

my $ft_config = AppConfig->new();

# Usage: Flamethrower->read_config($file);
sub read_config {

    my ($class, $file) = (@_);

    my $ft_config = AppConfig->new(
    
        { 
            CREATE => 1,
            GLOBAL => {
                ARGCOUNT => ARGCOUNT_ONE,
                DEFAULT => '',
                EXPAND => EXPAND_VAR,
            },
        },
    
        # No need to define any variables here, unless we come up with one
        # that has attributes, such as ARGCOUNT, that are different from 
        # the GLOBAL default.
        #
        # Ie:
        #'my_other_var' => { ARGCOUNT => 2 },
        
        'modules' => { ARGCOUNT => ARGCOUNT_LIST },

        'start_flamethrower_daemon'         => { ARGCOUNT => ARGCOUNT_ONE },
        'flamethrower_directory_portbase'   => { ARGCOUNT => ARGCOUNT_ONE },
        'flamethrower_directory_dir'        => { ARGCOUNT => ARGCOUNT_ONE },
        'flamethrower_state_dir'            => { ARGCOUNT => ARGCOUNT_ONE },
        'min_clients'                       => { ARGCOUNT => ARGCOUNT_ONE },
        'max_wait'                          => { ARGCOUNT => ARGCOUNT_ONE },
        'min_wait'                          => { ARGCOUNT => ARGCOUNT_ONE },
        'async'                             => { ARGCOUNT => ARGCOUNT_ONE },
        'autostart'                         => { ARGCOUNT => ARGCOUNT_ONE },
        'blocksize'                         => { ARGCOUNT => ARGCOUNT_ONE },
        'broadcast'                         => { ARGCOUNT => ARGCOUNT_ONE },
        'fec'                               => { ARGCOUNT => ARGCOUNT_ONE },
        'interface'                         => { ARGCOUNT => ARGCOUNT_ONE },
        'log'                               => { ARGCOUNT => ARGCOUNT_ONE },
        'max_bitrate'                       => { ARGCOUNT => ARGCOUNT_ONE },
        'full_duplex'                       => { ARGCOUNT => ARGCOUNT_ONE },
        'mcast_addr'                        => { ARGCOUNT => ARGCOUNT_ONE },
        'mcast_all_addr'                    => { ARGCOUNT => ARGCOUNT_ONE },
        'min_slice_size'                    => { ARGCOUNT => ARGCOUNT_ONE },
        'slice_size'                        => { ARGCOUNT => ARGCOUNT_ONE },
        'pointopoint'                       => { ARGCOUNT => ARGCOUNT_ONE },
        'rexmit_hello_interval'             => { ARGCOUNT => ARGCOUNT_ONE },
        'ttl'                               => { ARGCOUNT => ARGCOUNT_ONE },
        'nosync'                            => { ARGCOUNT => ARGCOUNT_ONE },
        
    );

    $ft_config->file($file);
    
    #
    # Get a list of specified modules (don't know how to make appconfig give
    # us this.)
    #
    open(FILE, "<$file") or die("Couldn't open $file");
        while (<FILE>) {
            if (m/^[[:space:]]*\[.*\][[:space:]]*$/) {
                s/[[:space:]]+//g;
                s/\[//g;
                s/\]//g;
                $ft_config->modules($_);
            }
        }

        #
        # Be sure to include the flamethrower_directory in the list.
        # This allows us to make the buid_command subroutine more
        # generic, as $ft_config->get(${module}_dir) will work for
        # flamethrower_directory as well as all the "normal" modules.
        #
        $ft_config->modules('flamethrower_directory');

    close(FILE);
    
    $::main::ft_config = $ft_config;
}

## A pure perl which command
# example: SystemImager::Common->which($file,$ENV{PATH}) || croak "$file not found in your path.";
sub which {
    my ($class, $file, $path) = @_;
    
    foreach my $dir (split(/:/,$path)) {
      if(-x "$dir/$file") {
        return 1;
      }
    }
    return 0;
}