| 1 | # |
|---|
| 2 | # Manages Plugins for CasparBuster |
|---|
| 3 | # |
|---|
| 4 | # $Id$ |
|---|
| 5 | # |
|---|
| 6 | # |
|---|
| 7 | package CasparBuster::Plugin; |
|---|
| 8 | |
|---|
| 9 | use strict; |
|---|
| 10 | use warnings; |
|---|
| 11 | use CasparBuster::Env; |
|---|
| 12 | use ProjectBuilder::Base; |
|---|
| 13 | use ProjectBuilder::Conf; |
|---|
| 14 | use Data::Dumper; |
|---|
| 15 | |
|---|
| 16 | # Global vars |
|---|
| 17 | # Inherit from the "Exporter" module which handles exporting functions. |
|---|
| 18 | # |
|---|
| 19 | use vars qw($VERSION $REVISION @ISA @EXPORT); |
|---|
| 20 | use Exporter; |
|---|
| 21 | # |
|---|
| 22 | # Export, by default, all the functions into the namespace of |
|---|
| 23 | # any code which uses this module. |
|---|
| 24 | |
|---|
| 25 | our @ISA = qw(Exporter); |
|---|
| 26 | our @EXPORT = qw(cb_plugin_load cb_plugin_get); |
|---|
| 27 | |
|---|
| 28 | =pod |
|---|
| 29 | |
|---|
| 30 | =head1 NAME |
|---|
| 31 | |
|---|
| 32 | CasparBuster::Plugin - module dealing with CasparBuster plugin management |
|---|
| 33 | |
|---|
| 34 | =head1 DESCRIPTION |
|---|
| 35 | |
|---|
| 36 | This modules provides functions to allow the management of CasparBuster plugins |
|---|
| 37 | |
|---|
| 38 | =head1 SYNOPSIS |
|---|
| 39 | |
|---|
| 40 | use CasparBuster::Plugin; |
|---|
| 41 | |
|---|
| 42 | =head1 USAGE |
|---|
| 43 | |
|---|
| 44 | =over 4 |
|---|
| 45 | |
|---|
| 46 | =item B<cb_plugin_load> |
|---|
| 47 | |
|---|
| 48 | This function loads all the plugins defined for this CasparBuster environement |
|---|
| 49 | |
|---|
| 50 | =cut |
|---|
| 51 | |
|---|
| 52 | sub cb_plugin_load { |
|---|
| 53 | |
|---|
| 54 | my ($pluginsdir) = pb_conf_get("cbpluginssubdir"); |
|---|
| 55 | my $cbconfdir = cb_env_confdir()."/$pluginsdir->{$ENV{'PBPROJ'}}"; |
|---|
| 56 | opendir(DIR,$cbconfdir) || die "Unable to open $cbconfdir: $!"; |
|---|
| 57 | foreach my $f (readdir(DIR)) { |
|---|
| 58 | next if ($f =~ /^\./); |
|---|
| 59 | # Add on plugins files |
|---|
| 60 | if ($f =~ /\.conf$/) { |
|---|
| 61 | pb_conf_add("$cbconfdir/$f") if (-f "$cbconfdir/$f"); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | closedir(DIR); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | =item B<cb_plugin_get> |
|---|
| 69 | |
|---|
| 70 | This function adds into the plugin hash, passed as second parameter, the new plugin content based on its name, passed as first parameter. |
|---|
| 71 | |
|---|
| 72 | =cut |
|---|
| 73 | |
|---|
| 74 | sub cb_plugin_get { |
|---|
| 75 | |
|---|
| 76 | my $plugin = shift; |
|---|
| 77 | my $cbp = shift; |
|---|
| 78 | |
|---|
| 79 | my ($flist,$dlist,$slist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbpluginreload"); |
|---|
| 80 | if ((defined $flist) && (defined $flist->{$plugin}) && ($flist->{$plugin} !~ /^\s*$/)) { |
|---|
| 81 | foreach my $block (split(/;/,$flist->{$plugin})) { |
|---|
| 82 | pb_log(3,"block : $block\n"); |
|---|
| 83 | my ($name,$tmp) = split(/\|/,$block); |
|---|
| 84 | ($cbp->{$plugin}->{'files'}->{$name}->{'uid'},$cbp->{$plugin}->{'files'}->{$name}->{'gid'},$cbp->{$plugin}->{'files'}->{$name}->{'mode'}) = split(/\,/,$tmp); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | if ((defined $dlist) && (defined $dlist->{$plugin}) && ($dlist->{$plugin} !~ /^\s*$/)) { |
|---|
| 88 | foreach my $block (split(/;/,$dlist->{$plugin})) { |
|---|
| 89 | pb_log(3,"block : $block\n"); |
|---|
| 90 | ($name,$tmp) = split(/\|/,$block); |
|---|
| 91 | ($cbp->{$plugin}->{'dirs'}->{$name}->{'uid'},$cbp->{$plugin}->{'dirs'}->{$name}->{'gid'},$cbp->{$plugin}->{'dirs'}->{$name}->{'mode'}) = split(/\,/,$tmp); |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | if ((defined $slist) && (defined $slist->{$plugin})) { |
|---|
| 95 | $cbp->{$plugin}->{'reloadscript'} = $slist->{$plugin}; |
|---|
| 96 | } |
|---|
| 97 | pb_log(2,"cbp: ".Dumper($cbp)."\n"); |
|---|
| 98 | return($cbp); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | 1; |
|---|